Browse Source

Small changes

Fixes, cleanups
master
Sogomn 9 years ago
parent
commit
f8bcfe2cf0
  1. 2
      Ratty/src/de/sogomn/rat/Ratty.java
  2. 18
      Ratty/src/de/sogomn/rat/packet/CreateFolderPacket.java
  3. 34
      Ratty/src/de/sogomn/rat/packet/UploadFilePacket.java
  4. 2
      Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java
  5. 6
      Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java

2
Ratty/src/de/sogomn/rat/Ratty.java

@ -123,8 +123,10 @@ public final class Ratty {
final int input = JOptionPane.showOptionDialog(null, "Server or client?", null, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, null);
if (input == JOptionPane.YES_OPTION) {
System.out.println("Server");
startServer(23456);
} else if (input == JOptionPane.NO_OPTION) {
System.out.println("Client");
connectToHost("localhost", 23456);
}
} else if (client) {

18
Ratty/src/de/sogomn/rat/packet/CreateFolderPacket.java

@ -32,9 +32,23 @@ public final class CreateFolderPacket implements IPacket {
@Override
public void execute(final ActiveClient client) {
final String fullPath = path + File.separator + name;
final File folder = new File(path);
FileUtils.createFolder(fullPath);
String fullPath = null;
if (folder.isDirectory()) {
fullPath = path + File.separator + name;
} else {
final File parent = folder.getParentFile();
if (parent != null) {
fullPath = parent.getAbsolutePath() + File.separator + name;
}
}
if (fullPath != null) {
FileUtils.createFolder(fullPath);
}
}
public String getPath() {

34
Ratty/src/de/sogomn/rat/packet/UploadFilePacket.java

@ -8,10 +8,10 @@ import de.sogomn.rat.ActiveClient;
public final class UploadFilePacket implements IPacket {
private byte[] data;
private String folder, fileName;
private String folderPath, fileName;
public UploadFilePacket(final String filePath, final String folder) {
this.folder = folder;
public UploadFilePacket(final String filePath, final String folderPath) {
this.folderPath = folderPath;
final File file = new File(filePath);
@ -19,15 +19,19 @@ public final class UploadFilePacket implements IPacket {
fileName = file.getName();
}
public UploadFilePacket(final File file, final String folderPath) {
this(file.getAbsolutePath(), folderPath);
}
public UploadFilePacket() {
folder = fileName = "";
folderPath = fileName = "";
}
@Override
public void send(final ActiveClient client) {
client.writeInt(data.length);
client.write(data);
client.writeUTF(folder);
client.writeUTF(folderPath);
client.writeUTF(fileName);
}
@ -39,15 +43,29 @@ public final class UploadFilePacket implements IPacket {
client.read(data);
folder = client.readUTF();
folderPath = client.readUTF();
fileName = client.readUTF();
}
@Override
public void execute(final ActiveClient client) {
final String path = folder + fileName;
final File folder = new File(folderPath);
String path = null;
if (folder.isDirectory()) {
path = folderPath + File.separator + fileName;
} else {
final File parent = folder.getParentFile();
if (parent != null) {
path = parent.getAbsolutePath() + File.separator + fileName;
}
}
FileUtils.writeData(path, data);
if (path != null) {
FileUtils.writeData(path, data);
}
}
}

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

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

6
Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java

@ -104,7 +104,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.getLastNodePathFolder();
final String path = treePanel.getLastPathClicked();
packet = new UploadFilePacket(localPath, path);
}
@ -115,7 +115,7 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
packet = new ExecuteFilePacket(path);
} else if (command == FileTreePanel.NEW_FOLDER) {
final FileTreePanel treePanel = serverClient.getTreePanel();
final String path = treePanel.getLastNodePathFolder();
final String path = treePanel.getLastPathClicked();
final String name = JOptionPane.showInputDialog(null);
if (name != null && !name.isEmpty()) {
@ -126,8 +126,6 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
final String path = treePanel.getLastPathClicked();
packet = new DeleteFilePacket(path);
treePanel.removeFile(path);
} else if (command == DisplayPanel.KEY_PRESSED && serverClient.isStreamingDesktop()) {
final DisplayPanel displayPanel = serverClient.getDisplayPanel();
final int key = displayPanel.getLastKeyHit();

Loading…
Cancel
Save