Add functionnality openning in finder

pull/1/head
Louis Royer 5 years ago
parent db3796c384
commit de96d7b661

@ -1,16 +1,28 @@
package clientP2P;
import clientP2P.ClientManagementUDP;
import tools.Directories;
import java.util.Scanner;
public class ClientP2P {
private String host;
private int port;
private String dataHomeDirectory;
public ClientP2P() {
Directories d = new Directories("P2P_JAVA_PROJECT_CLIENT");
String os = System.getProperty("os.name");
host = "localhost";
port = 40000;
dataHomeDirectory = new Directories("P2P_JAVA_PROJECT_CLIENT").getDataHomeDirectory();
System.out.println("Client will try to contact server at " + host + " on port " + port + ". It will save files in " + dataHomeDirectory);
dataHomeDirectory = d.getDataHomeDirectory();
System.out.println("Client will try to contact server at " + host + " on port " + port + ". It will save files in " + dataHomeDirectory);
if (os.equals("Linux")||os.equals("Mac")||os.equals("Mac OS X")) {
System.out.println("Do you want to open this directory? (y/N)");
Scanner scanner = new Scanner(System.in);
String resp = scanner.nextLine();
if (resp == "y" || resp == "Y") {
d.openDataHomeDirectory();
}
}
}
public static void main(String [] args) {

@ -1,5 +1,8 @@
package tools;
import java.io.File;
import java.lang.Runtime;
import java.io.IOException;
/** Helper to get application directories.
* @author Louis Royer
@ -51,7 +54,20 @@ public class Directories {
public String getDataHomeDirectory() {
return dataHomeDirectory;
}
public void openDataHomeDirectory() {
try {
String os = System.getProperty("os.name");
if (os.equals("Linux")) {
Runtime runtime = Runtime.getRuntime();
runtime.exec(new String[] { "xdg-open", dataHomeDirectory });
} else if (os.equals("Mac")||os.equals("Mac OS X")) {
Runtime runtime = Runtime.getRuntime();
runtime.exec(new String[] { "open", dataHomeDirectory });
}
} catch (IOException e) {}
}
}

Loading…
Cancel
Save