diff --git a/app/src/main/java/lightcontainer/domains/client/Context.java b/app/src/main/java/lightcontainer/domains/client/Context.java index a87ef6a..089474e 100644 --- a/app/src/main/java/lightcontainer/domains/client/Context.java +++ b/app/src/main/java/lightcontainer/domains/client/Context.java @@ -9,6 +9,7 @@ import lightcontainer.utils.ShaHasher; import java.security.NoSuchAlgorithmException; import java.util.LinkedList; +import java.util.List; import java.util.Set; /** @@ -171,6 +172,10 @@ public class Context { return this.repository.addFileFor(new File(fileName, fileNameSalt, size, iv, Set.of(domain)), getLogin()); } + public List getStringifiedFilesOf() { + return repository.load().getStringifiedFilesOf(login); + } + public boolean canAddFile() { return repository.canAddFile(login); } diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java index 920b6a9..a1c1da9 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java @@ -5,6 +5,8 @@ import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.writer.FilesRule; +import java.util.List; + /** * Règle permettant de récupérer la liste des fichiers d'un utilisateur */ @@ -30,12 +32,18 @@ public class FilelistRule extends ProtocolReader { /** * Cette méthode est appelée lors de l'exécution de la règle + * * @param data Paramètres pour créer la commande. */ @Override protected FilelistRule.Result onExecuted(Context context, String... data) { FilelistRule.Result result = new Result(context); - result.setResultCommand(this.protocolRep.executeWriter(context, FilesRule.NAME, "endbenja.txt!500"), ResultCmdReceiver.CLIENT); + List files = context.getStringifiedFilesOf(); + if (files != null) { + result.setResultCommand(this.protocolRep.executeWriter(context, FilesRule.NAME, files.toArray(new String[0])), ResultCmdReceiver.CLIENT); + } else { + result.setResultCommand(this.protocolRep.executeWriter(context, FilesRule.NAME), ResultCmdReceiver.CLIENT); + } return result; } } diff --git a/app/src/main/java/lightcontainer/storage/AppData.java b/app/src/main/java/lightcontainer/storage/AppData.java index 474c53b..1a712b6 100644 --- a/app/src/main/java/lightcontainer/storage/AppData.java +++ b/app/src/main/java/lightcontainer/storage/AppData.java @@ -2,6 +2,7 @@ package lightcontainer.storage; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; /** @@ -67,6 +68,14 @@ public class AppData { return this.users.get(userName); } + public List getStringifiedFilesOf(String login) { + User user = users.get(login); + if (user != null) { + return user.getFilesWithSize(); + } + return null; + } + /** * Use this method when a user signs up. diff --git a/app/src/main/java/lightcontainer/storage/User.java b/app/src/main/java/lightcontainer/storage/User.java index 4b1c1d0..0db77b0 100644 --- a/app/src/main/java/lightcontainer/storage/User.java +++ b/app/src/main/java/lightcontainer/storage/User.java @@ -1,6 +1,8 @@ package lightcontainer.storage; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import java.util.Map; /** @@ -46,6 +48,17 @@ public class User { return files.values().iterator(); } + public List getFilesWithSize() { + Iterator fileIterator = fileIterator(); + List result = new ArrayList<>(); + while (fileIterator.hasNext()) { + File file = fileIterator.next(); + String stringify = " " + file.getName() + "!" + file.getSize(); + result.add(stringify); + } + return result; + } + public File getFile(String fileName) { return this.files.get(fileName); } @@ -63,7 +76,7 @@ public class User { } public boolean canAddFile() { - return this.files.size() < 50; + return this.files.size() <= 50; } /**