2020import com .google .gson .*;
2121import org .jackhuang .hmcl .Metadata ;
2222import org .jackhuang .hmcl .util .StringUtils ;
23+ import org .jackhuang .hmcl .util .gson .JsonUtils ;
2324import org .jackhuang .hmcl .util .io .JarUtils ;
2425import org .jetbrains .annotations .Contract ;
2526import org .jetbrains .annotations .NotNullByDefault ;
@@ -57,7 +58,7 @@ private LegacyConfigMigrator() {
5758
5859 /// Loads a legacy config file and applies legacy schema upgrades in memory.
5960 private static @ Nullable LoadedConfig loadLegacyConfig (Path path ) throws IOException , JsonParseException {
60- JsonObject jsonObject = readJsonObject (path );
61+ JsonObject jsonObject = JsonUtils . fromJsonFile (path , JsonObject . class );
6162 if (jsonObject == null ) {
6263 return null ;
6364 }
@@ -71,7 +72,6 @@ private LegacyConfigMigrator() {
7172 : 0 ;
7273
7374 if (configVersion > LEGACY_CURRENT_CONFIG_VERSION ) {
74- LOG .warning (String .format ("Current HMCL only support the legacy configuration version up to %d. However, the version now is %d." , LEGACY_CURRENT_CONFIG_VERSION , configVersion ));
7575 Config deserialized = Config .fromJson (jsonObject );
7676 if (deserialized == null ) {
7777 return null ;
@@ -103,13 +103,13 @@ private LegacyConfigMigrator() {
103103 try {
104104 @ Nullable LoadedConfig loadedConfig = loadLegacyConfig (path );
105105 if (loadedConfig == null ) {
106- LOG .info ("Legacy config is empty: " + path );
106+ LOG .info ("Legacy config is empty" );
107107 return null ;
108108 }
109109
110110 return new MigrationResult (path , loadedConfig );
111111 } catch (JsonParseException e ) {
112- LOG .warning ("Malformed legacy config: " + path , e );
112+ LOG .warning ("Malformed legacy config file : " + path , e );
113113 return null ;
114114 }
115115 }
@@ -296,7 +296,6 @@ record LoadedConfig(Config config, String contentForMigration, boolean unsupport
296296
297297 /// Result of locating and loading a legacy config file without modifying it.
298298 ///
299- /// @param path The legacy config path.
300299 /// @param loadedConfig The loaded config data.
301300 record MigrationResult (Path path , LoadedConfig loadedConfig ) {
302301 }
0 commit comments