Fix #112 Fix #107
All checks were successful
flavien's git/Projet_JAVA_P2P_STRI2A/pipeline/head This commit looks good
flavien's git/Projet_JAVA_P2P_STRI2A/pipeline/pr-master This commit looks good

This commit is contained in:
Louis Royer 2020-04-03 22:02:55 +02:00
parent aae25fbd99
commit f3591f0af1
2 changed files with 24 additions and 21 deletions

View File

@ -271,12 +271,13 @@ public abstract class ClientManagement extends ServeErrors implements Runnable {
/** Implementation of Runnable /** Implementation of Runnable
*/ */
public void run() { public void run() {
boolean isrunning = true; boolean isRunning = true;
while (isrunning){ while (isRunning) {
try { try {
int i = 1; int i = 1;
String[] list = listDirectory(); String[] list = listDirectory();
System.out.println("Files present on the server:"); System.out.println("Files present on the server:");
System.out.println("R: Refresh file list");
System.out.println("0: Exit the program"); System.out.println("0: Exit the program");
for(String listItem: list) { for(String listItem: list) {
System.out.println(i + ": " + listItem); System.out.println(i + ": " + listItem);
@ -285,19 +286,21 @@ public abstract class ClientManagement extends ServeErrors implements Runnable {
System.out.println("Type the number associated with the file to download:"); System.out.println("Type the number associated with the file to download:");
String f = scanner.nextLine(); String f = scanner.nextLine();
if (f.equals("0")) { if (f.equals("0")) {
isrunning = false; isRunning = false;
} } else if (f.equals("R") || f.equals("r")) {
else{ writeLog("File list refresh.", LogLevel.Info);
} else {
try {
int j = Integer.parseInt(f); int j = Integer.parseInt(f);
if (j <= list.length) { if (j <= list.length) {
j--; j--;
download(list[j]); download(list[j]);
System.out.println("File " + f + " sucessfully downloaded");
writeLog("File " + f + " sucessfully downloaded", LogLevel.Info); writeLog("File " + f + " sucessfully downloaded", LogLevel.Info);
} else {
writeLog("File " + f + " unsucessfully downloaded, wrong number", LogLevel.Error);
} }
else{ } catch (NumberFormatException e) {
System.out.println("File " + f + " unsucessfully downloaded, wrong number"); writeLog("File " + f + " unsucessfully downloaded, wrong number", LogLevel.Error);
writeLog("File " + f + " unsucessfully downloaded, wrong number", LogLevel.Info);
} }
} }
} catch (EmptyDirectory e) { } catch (EmptyDirectory e) {

View File

@ -67,7 +67,7 @@ public class ClientP2P {
System.out.println("usage :"); System.out.println("usage :");
System.out.println("\tjava clientP2P.ClientP2P"); System.out.println("\tjava clientP2P.ClientP2P");
System.out.println("or"); System.out.println("or");
System.out.println("java clientP2P.ClientP2P -- " + System.out.println("\tjava clientP2P.ClientP2P -- " +
"<clientTransportProtocol> " + "<clientTransportProtocol> " +
"<integratedServerHOSTNAME> <integratedServerPORT> " + "<integratedServerHOSTNAME> <integratedServerPORT> " +
"<trackerHOSTNAME> <trackerPORT> "); "<trackerHOSTNAME> <trackerPORT> ");