File tree Expand file tree Collapse file tree
main/java/org/jackhuang/hmcl/setting
test/java/org/jackhuang/hmcl/setting Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -159,7 +159,7 @@ public ObjectProperty<EnumCommonDirectory> commonDirTypeProperty() {
159159 }
160160
161161 /// The custom common Minecraft directory path.
162- @ SerializedName ("commonpath " )
162+ @ SerializedName ("commonDirectory " )
163163 private final StringProperty commonDirectory = new SimpleStringProperty ();
164164
165165 /// Returns the custom common Minecraft directory property.
Original file line number Diff line number Diff line change @@ -108,6 +108,7 @@ public static GUID getLegacyProfileId(String profileName) {
108108 AccountStorages ::new );
109109 JsonElement legacyAllowAutoAgent = jsonObject .remove ("allowAutoAgent" );
110110 JsonElement legacyDisableAutoGameOptions = jsonObject .remove ("disableAutoGameOptions" );
111+ migrateLegacyCommonDirectory (jsonObject );
111112 migrateLegacyLanguage (jsonObject );
112113 migrateLegacySelectedVersions (jsonObject );
113114 @ Nullable GameDirectories migratedGameDirectories = extractGameDirectoriesFromConfigJson (jsonObject );
@@ -220,6 +221,20 @@ static void migrateLegacyLanguage(JsonObject json) {
220221 });
221222 }
222223
224+ /// Migrates the legacy `commonpath` field into the current `commonDirectory` field.
225+ static void migrateLegacyCommonDirectory (JsonObject json ) {
226+ Objects .requireNonNull (json );
227+
228+ JsonElement legacyCommonDirectory = json .remove ("commonpath" );
229+ if (json .has ("commonDirectory" )
230+ || !(legacyCommonDirectory instanceof JsonPrimitive primitive )
231+ || !primitive .isString ()) {
232+ return ;
233+ }
234+
235+ json .addProperty ("commonDirectory" , primitive .getAsString ());
236+ }
237+
223238 /// Migrates the legacy workspace-wide automatic Java agent permission into game setting presets.
224239 static void migrateLegacyAllowAutoAgent (
225240 LauncherSettings launcherSettings ,
Original file line number Diff line number Diff line change @@ -67,6 +67,26 @@ public void migratesLegacyTraditionalChineseLanguage() {
6767 assertEquals ("zh-Hant" , launcherSettings .languageProperty ().get ().getName ());
6868 }
6969
70+ /// Tests migrating the legacy common directory field into the current launcher settings field.
71+ @ Test
72+ public void migratesLegacyCommonPathToCommonDirectory () {
73+ JsonObject settings = JsonParser .parseString ("""
74+ {
75+ "commonpath": "/home/user/.minecraft"
76+ }
77+ """ ).getAsJsonObject ();
78+
79+ LegacyConfigMigrator .migrateLegacyCommonDirectory (settings );
80+ LauncherSettings launcherSettings = Objects .requireNonNull (LauncherSettings .fromJson (settings ));
81+ JsonObject serialized = JsonParser .parseString (launcherSettings .toJson ()).getAsJsonObject ();
82+
83+ assertFalse (settings .has ("commonpath" ));
84+ assertEquals ("/home/user/.minecraft" , settings .get ("commonDirectory" ).getAsString ());
85+ assertEquals ("/home/user/.minecraft" , launcherSettings .commonDirectoryProperty ().get ());
86+ assertFalse (serialized .has ("commonpath" ));
87+ assertEquals ("/home/user/.minecraft" , serialized .get ("commonDirectory" ).getAsString ());
88+ }
89+
7090 /// Tests that launcher settings serialization preserves a patch-version schema and unknown fields.
7191 @ Test
7292 public void preservesPatchSchemaAndUnknownFields () {
You can’t perform that action at this time.
0 commit comments