From f0f18d64b5b1d2663036ccdbeedd87699df4af85 Mon Sep 17 00:00:00 2001 From: Louis Royer Date: Fri, 3 Apr 2020 22:04:20 +0200 Subject: [PATCH] Fix #112 Fix #107 (#113) Fix #112 Fix #107 --- src/clientP2P/ClientManagement.java | 43 +++++++++++++++-------------- src/clientP2P/ClientP2P.java | 2 +- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/clientP2P/ClientManagement.java b/src/clientP2P/ClientManagement.java index f10d51d..2cb4455 100644 --- a/src/clientP2P/ClientManagement.java +++ b/src/clientP2P/ClientManagement.java @@ -128,7 +128,7 @@ public abstract class ClientManagement extends ServeErrors implements Runnable { hostList = ((DiscoverResponse)p).getHostList(); } closeTrackerSocket(); - } catch (SocketClosed e){ + } catch (SocketClosed e) { writeLog("listDirectory : SocketClosed", LogLevel.Error); throw new ProtocolError(); } catch (NotATracker e) { @@ -202,7 +202,7 @@ public abstract class ClientManagement extends ServeErrors implements Runnable { } catch (EmptyFile e) { writeLog(e, LogLevel.Error); throw new ProtocolError(); - } catch (SocketClosed e){ + } catch (SocketClosed e) { writeLog("listDirectory : SocketClosed", LogLevel.Error); throw new ProtocolError(); } catch (NotATracker e) { @@ -271,33 +271,36 @@ public abstract class ClientManagement extends ServeErrors implements Runnable { /** Implementation of Runnable */ public void run() { - boolean isrunning = true; - while (isrunning){ + boolean isRunning = true; + while (isRunning) { try { int i = 1; String[] list = listDirectory(); System.out.println("Files present on the server:"); - System.out.println("0 : Exit the program"); + System.out.println("R: Refresh file list"); + System.out.println("0: Exit the program"); for(String listItem: list) { - System.out.println(i + " : " + listItem); + System.out.println(i + ": " + listItem); i++; } System.out.println("Type the number associated with the file to download:"); String f = scanner.nextLine(); - if(f.equals("0")){ - isrunning = false; - } - else{ - int j = Integer.parseInt(f); - if(j <= list.length){ - j--; - download(list[j]); - System.out.println("File " + f + " sucessfully downloaded"); - writeLog("File " + f + " sucessfully downloaded", LogLevel.Info); - } - else{ - System.out.println("File " + f + " unsucessfully downloaded, wrong number"); - writeLog("File " + f + " unsucessfully downloaded, wrong number", LogLevel.Info); + if (f.equals("0")) { + isRunning = false; + } else if (f.equals("R") || f.equals("r")) { + writeLog("File list refresh.", LogLevel.Info); + } else { + try { + int j = Integer.parseInt(f); + if (j <= list.length) { + j--; + download(list[j]); + writeLog("File " + f + " sucessfully downloaded", LogLevel.Info); + } else { + writeLog("File " + f + " unsucessfully downloaded, wrong number", LogLevel.Error); + } + } catch (NumberFormatException e) { + writeLog("File " + f + " unsucessfully downloaded, wrong number", LogLevel.Error); } } } catch (EmptyDirectory e) { diff --git a/src/clientP2P/ClientP2P.java b/src/clientP2P/ClientP2P.java index 1e4a210..0129169 100644 --- a/src/clientP2P/ClientP2P.java +++ b/src/clientP2P/ClientP2P.java @@ -67,7 +67,7 @@ public class ClientP2P { System.out.println("usage :"); System.out.println("\tjava clientP2P.ClientP2P"); System.out.println("or"); - System.out.println("java clientP2P.ClientP2P -- " + + System.out.println("\tjava clientP2P.ClientP2P -- " + " " + " " + " ");