@@ -57,7 +57,7 @@ public class UiService {
5757 private final ObservableList <LogMessage > USER_LOG ;
5858
5959 @ Getter
60- private final ObservableList <ModlistProfile > MOD_PROFILES ;
60+ private final ObservableList <ModlistProfile > MODLIST_PROFILES ;
6161
6262 @ Getter
6363 private final ObservableList <SaveProfile > SAVE_PROFILES ;
@@ -93,13 +93,13 @@ public class UiService {
9393 private final String MOD_DATE_FORMAT ;
9494
9595 public UiService (Logger LOGGER , @ NotNull ObservableList <LogMessage > USER_LOG ,
96- @ NotNull ObservableList <ModlistProfile > MOD_PROFILES , @ NotNull ObservableList <SaveProfile > SAVE_PROFILES ,
96+ @ NotNull ObservableList <ModlistProfile > MODLIST_PROFILES , @ NotNull ObservableList <SaveProfile > SAVE_PROFILES ,
9797 StorageController storageController , ModInfoController modInfoController , UserConfiguration USER_CONFIGURATION , @ NotNull Properties properties ) {
9898
9999 this .LOGGER = LOGGER ;
100100 this .MOD_INFO_CONTROLLER = modInfoController ;
101101 this .USER_LOG = USER_LOG ;
102- this .MOD_PROFILES = MOD_PROFILES ;
102+ this .MODLIST_PROFILES = MODLIST_PROFILES ;
103103 this .SAVE_PROFILES = SAVE_PROFILES ;
104104 this .STORAGE_CONTROLLER = storageController ;
105105 this .USER_CONFIGURATION = USER_CONFIGURATION ;
@@ -112,14 +112,14 @@ public UiService(Logger LOGGER, @NotNull ObservableList<LogMessage> USER_LOG,
112112 .findFirst ();
113113 if (lastUsedSaveProfile .isPresent ()) {
114114 currentSaveProfile = lastUsedSaveProfile .get ();
115- Optional <ModlistProfile > lastUsedModProfile = MOD_PROFILES .stream ()
115+ Optional <ModlistProfile > lastUsedModProfile = MODLIST_PROFILES .stream ()
116116 .filter (modProfile -> modProfile .getID ().equals (currentSaveProfile .getLastUsedModProfile ()))
117117 .findFirst ();
118- currentModlistProfile = lastUsedModProfile .orElseGet (MOD_PROFILES ::getFirst );
118+ currentModlistProfile = lastUsedModProfile .orElseGet (MODLIST_PROFILES ::getFirst );
119119 } else {
120120 log ("No previously applied save profile detected." , MessageType .INFO );
121121 currentSaveProfile = SAVE_PROFILES .getFirst ();
122- currentModlistProfile = MOD_PROFILES .getFirst ();
122+ currentModlistProfile = MODLIST_PROFILES .getFirst ();
123123 }
124124
125125 //A little bit of duplication, but the order of construction is a big different from setCurrentModProfile
@@ -459,9 +459,9 @@ protected List<Result<String>> call() throws ExecutionException, InterruptedExce
459459 } else {
460460 idResult = getModIoModIdFromUrlName (modUrl );
461461 }
462- if (idResult .isSuccess ()) {
462+ if (idResult .isSuccess ()) {
463463 Result <Void > duplicateIdResult = ModlistManagerHelper .checkForDuplicateModIoMod (idResult .getPayload (), UiService .this );
464- if (!duplicateIdResult .isSuccess ()) {
464+ if (!duplicateIdResult .isSuccess ()) {
465465 idResult .addMessage (duplicateIdResult .getCurrentMessage (), duplicateIdResult .getType ());
466466 }
467467 }
@@ -496,7 +496,7 @@ public Task<Result<String>> convertModIoUrlToId(String modUrl) {
496496 @ Override
497497 protected Result <String > call () {
498498 Result <String > urltoIdConversionResult = getModIoModIdFromUrlName (modUrl );
499- if (urltoIdConversionResult .isSuccess ()) {
499+ if (urltoIdConversionResult .isSuccess ()) {
500500 Result <Void > duplicateIdResult = ModlistManagerHelper .checkForDuplicateModIoMod (modUrl , UiService .this );
501501 if (!duplicateIdResult .isSuccess ()) {
502502 urltoIdConversionResult .addMessage (duplicateIdResult .getCurrentMessage (), duplicateIdResult .getType ());
@@ -537,6 +537,20 @@ public Result<Void> exportModlist(ModlistProfile modlistProfile, File exportLoca
537537 }
538538
539539 public Result <ModlistProfile > importModlist (File saveLocation ) {
540- return STORAGE_CONTROLLER .importModlist (saveLocation );
540+ Result <ModlistProfile > modlistProfileResult = STORAGE_CONTROLLER .importModlist (saveLocation );
541+ if (modlistProfileResult .isSuccess ()) {
542+ ModlistProfile importModlistProfile = modlistProfileResult .getPayload ();
543+ boolean duplicateProfileExists = MODLIST_PROFILES
544+ .stream ()
545+ .anyMatch (modlistProfile -> modlistProfile .getProfileName ().toLowerCase ().trim ().equals (importModlistProfile .getProfileName ().toLowerCase ().trim ()));
546+ if (!duplicateProfileExists ) {
547+ for (int i = 0 ; i < importModlistProfile .getModList ().size (); i ++) {
548+ importModlistProfile .getModList ().get (i ).setLoadPriority (i + 1 );
549+ }
550+ MODLIST_PROFILES .add (modlistProfileResult .getPayload ());
551+ } else
552+ modlistProfileResult .addMessage (String .format ("Mod profile \" %s\" already exists!" , modlistProfileResult .getPayload ().getProfileName ()), ResultType .INVALID );
553+ }
554+ return modlistProfileResult ;
541555 }
542556}
0 commit comments