|
|
|
@ -6,7 +6,6 @@ import clientP2P.ClientManagement;
|
|
|
|
|
import tools.SearchFile;
|
|
|
|
|
import tools.LogLevel;
|
|
|
|
|
import tools.Logger;
|
|
|
|
|
import java.util.Scanner;
|
|
|
|
|
import localException.ProtocolError;
|
|
|
|
|
import localException.InternalError;
|
|
|
|
|
import localException.ProtocolError;
|
|
|
|
@ -33,17 +32,19 @@ import javax.swing.JFrame;
|
|
|
|
|
* @author JS Auge
|
|
|
|
|
* @version 1.0
|
|
|
|
|
*/
|
|
|
|
|
public class ClientInterfaceCLI extends ClientInterface {
|
|
|
|
|
private Scanner scanner;
|
|
|
|
|
public class ClientInterfaceGUI extends ClientInterface {
|
|
|
|
|
|
|
|
|
|
/** Constructor with clientManagement, logger and scanner.
|
|
|
|
|
* @param clientManagement ClientManagement used
|
|
|
|
|
* @param logger Logger used
|
|
|
|
|
* @param scanner Scanner used to read input
|
|
|
|
|
*/
|
|
|
|
|
public ClientInterfaceGUI(ClientManagement clientManagement, Logger logger, Scanner scanner) {
|
|
|
|
|
|
|
|
|
|
Logger loggerC;
|
|
|
|
|
|
|
|
|
|
public ClientInterfaceGUI(ClientManagement clientManagement, Logger logger) {
|
|
|
|
|
super(clientManagement, logger);
|
|
|
|
|
this.scanner = scanner;
|
|
|
|
|
this.loggerC = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Implementation of Runnable
|
|
|
|
@ -59,12 +60,34 @@ public class ClientInterfaceCLI extends ClientInterface {
|
|
|
|
|
int optionSearch = 0;
|
|
|
|
|
String searchInput = "";
|
|
|
|
|
String[] list = clientManagement.listDirectory();
|
|
|
|
|
//String[] resultArray = {};
|
|
|
|
|
|
|
|
|
|
MainWindow win = new MainWindow();
|
|
|
|
|
win.add(new DownloadSelectionGen(list, clientManagement, loggerC));
|
|
|
|
|
} catch (EmptyDirectory e) {
|
|
|
|
|
writeLog("Server has no file in directory", LogLevel.Error);
|
|
|
|
|
}
|
|
|
|
|
catch (InternalError e) {
|
|
|
|
|
writeLog("Client internal error", LogLevel.Error);
|
|
|
|
|
} catch (UnknownHostException e) {
|
|
|
|
|
writeLog("Server host is unknown", LogLevel.Error);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
writeLog("Request cannot be send or response cannot be received", LogLevel.Error);
|
|
|
|
|
} catch (TransmissionError e) {
|
|
|
|
|
writeLog("Message received is too big", LogLevel.Error);
|
|
|
|
|
} catch (ProtocolError e) {
|
|
|
|
|
writeLog("Cannot decode server’s response", LogLevel.Error);
|
|
|
|
|
} catch (VersionError e) {
|
|
|
|
|
writeLog("Server’s response use bad version of the protocol", LogLevel.Error);
|
|
|
|
|
} catch (SizeError e) {
|
|
|
|
|
writeLog("Cannot handle this packets because of internal representation limitations of numbers on the client", LogLevel.Error);
|
|
|
|
|
} catch (InternalRemoteError e) {
|
|
|
|
|
writeLog("Server internal error", LogLevel.Error);
|
|
|
|
|
} catch (ProtocolRemoteError e) {
|
|
|
|
|
writeLog("Server cannot decode client’s request", LogLevel.Error);
|
|
|
|
|
} catch (VersionRemoteError e) {
|
|
|
|
|
writeLog("Server cannot decode this version of the protocol", LogLevel.Error);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MainWindow win = new MainWindow();
|
|
|
|
|
win.add(new DownloadSelectionGen(list, clientManagement, logger, scanner));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -79,11 +102,7 @@ public class ClientInterfaceCLI extends ClientInterface {
|
|
|
|
|
while (!contacted && !stop) {
|
|
|
|
|
try {
|
|
|
|
|
if (!firstLoop) {
|
|
|
|
|
writeLog("Cannot contact tracker. Try again [Y/n] ?", LogLevel.Error);
|
|
|
|
|
String tryAgain = scanner.nextLine();
|
|
|
|
|
if (tryAgain.equals("n") || tryAgain.equals("N")) {
|
|
|
|
|
stop = true;
|
|
|
|
|
}
|
|
|
|
|
writeLog("Cannot contact tracker... ", LogLevel.Error);
|
|
|
|
|
}
|
|
|
|
|
firstLoop = false;
|
|
|
|
|
clientManagement.initHostList();
|
|
|
|
@ -97,4 +116,6 @@ public class ClientInterfaceCLI extends ClientInterface {
|
|
|
|
|
}
|
|
|
|
|
return !stop;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|