diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/profiles/LocalProfileProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/profiles/LocalProfileProvider.java index 6fe18d54..5c3725ea 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/profiles/LocalProfileProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/profiles/LocalProfileProvider.java @@ -9,10 +9,7 @@ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; +import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.util.*; @@ -40,8 +37,21 @@ public Set getProfiles() { @Override public void addProfile(ClientProfile profile) throws IOException { Path profilesDirPath = Path.of(profilesDir); - Path target = IOHelper.resolveIncremental(profilesDirPath, - profile.getDir(), "json"); + ClientProfile oldProfile; + Path target = null; + for(var e : profilesMap.entrySet()) { + if(e.getValue().getUUID().equals(profile.getUUID())) { + target = e.getKey(); + } + } + if(target == null) { + target = IOHelper.resolveIncremental(profilesDirPath, + profile.getTitle(), "json"); + oldProfile = profilesMap.get(target); + if(oldProfile != null && !oldProfile.getUUID().equals(profile.getUUID())) { + throw new FileAlreadyExistsException(target.toString()); + } + } try (BufferedWriter writer = IOHelper.newWriter(target)) { Launcher.gsonManager.configGson.toJson(profile, writer); } @@ -61,6 +71,13 @@ public void deleteProfile(ClientProfile profile) throws IOException { } private void addProfile(Path path, ClientProfile profile) { + for(var e : profilesMap.entrySet()) { + if(e.getValue().getUUID().equals(profile.getUUID())) { + profilesMap.remove(e.getKey()); + profilesList.remove(e.getValue()); + break; + } + } profilesMap.put(path, profile); profilesList.add(profile); } @@ -83,10 +100,9 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO profile = Launcher.gsonManager.gson.fromJson(reader, ClientProfile.class); } profile.verify(); - profile.setProfileFilePath(file); // Add SIGNED profile to result list - result.put(file, profile); + result.put(file.toAbsolutePath(), profile); return super.visitFile(file, attrs); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/SaveProfilesCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/SaveProfilesCommand.java index ab677c9c..9d796c1e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/SaveProfilesCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/SaveProfilesCommand.java @@ -44,7 +44,6 @@ public void invoke(String... args) throws Exception { } catch (IllegalArgumentException ex) { profile = server.config.profileProvider.getProfile(profileName); } - server.config.profileProvider.deleteProfile(profile); server.config.profileProvider.addProfile(profile); } server.syncProfilesDir(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfile.java index 5d55896d..0e4bab59 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfile.java @@ -18,7 +18,6 @@ public final class ClientProfile implements Comparable { private static final FileNameMatcher ASSET_MATCHER = new FileNameMatcher( new String[0], new String[]{"indexes", "objects"}, new String[0]); - private transient Path profileFilePath; @LauncherNetworkAPI private String title; @LauncherNetworkAPI @@ -392,14 +391,6 @@ public List getFlags() { return flags; } - public Path getProfileFilePath() { - return profileFilePath; - } - - public void setProfileFilePath(Path profileFilePath) { - this.profileFilePath = profileFilePath; - } - public enum ClassLoaderConfig { AGENT, LAUNCHER, MODULE, SYSTEM_ARGS }