Skip to content

Commit 8088213

Browse files
committed
refactor: rename Config to LauncherSettings and update related references
1 parent d7cc36d commit 8088213

13 files changed

Lines changed: 96 additions & 96 deletions

HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import org.jackhuang.hmcl.mod.Modpack;
3131
import org.jackhuang.hmcl.mod.ModpackConfiguration;
3232
import org.jackhuang.hmcl.mod.ModpackProvider;
33-
import org.jackhuang.hmcl.setting.Config;
33+
import org.jackhuang.hmcl.setting.LauncherSettings;
3434
import org.jackhuang.hmcl.setting.ConfigHolder;
3535
import org.jackhuang.hmcl.setting.DefaultIsolationType;
3636
import org.jackhuang.hmcl.setting.GameSettings;
@@ -220,7 +220,7 @@ public void duplicateVersion(String srcId, String dstId, boolean copySaves) thro
220220
private GameSettings.Instance copyLocalGameSettings(String id) {
221221
GameSettings.Instance setting = getLocalGameSettings(id);
222222
if (setting != null) {
223-
return JsonUtils.clone(Config.CONFIG_GSON, setting, TypeToken.get(GameSettings.Instance.class));
223+
return JsonUtils.clone(LauncherSettings.GSON, setting, TypeToken.get(GameSettings.Instance.class));
224224
}
225225

226226
GameSettings.Instance copied = new GameSettings.Instance();
@@ -267,7 +267,7 @@ private void loadLocalGameSettings(String id) {
267267

268268
try {
269269
try (var reader = Files.newBufferedReader(file)) {
270-
return Config.CONFIG_GSON.fromJson(reader, GameSettings.Instance.class);
270+
return LauncherSettings.GSON.fromJson(reader, GameSettings.Instance.class);
271271
}
272272
} catch (Exception ex) {
273273
LOG.warning("Failed to load game setting " + file, ex);
@@ -457,7 +457,7 @@ public void saveGameSettings(String id) {
457457
LOG.warning("Failed to create directory: " + file.getParent(), e);
458458
}
459459

460-
FileSaver.save(file, Config.CONFIG_GSON.toJson(localGameSettings.get(id)));
460+
FileSaver.save(file, LauncherSettings.GSON.toJson(localGameSettings.get(id)));
461461
}
462462

463463
public LaunchOptions.Builder getLaunchOptions(String version, JavaRuntime javaVersion, Path gameDir, List<String> javaAgents, List<String> javaArguments, boolean makeLaunchScript) {

HMCL/src/main/java/org/jackhuang/hmcl/setting/Accounts.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private static void loadGlobalAccountStorages() {
207207

208208
try (Reader reader = Files.newBufferedReader(LEGACY_GLOBAL_ACCOUNTS_LOCATION)) {
209209
List<Map<Object, Object>> accounts =
210-
Config.CONFIG_GSON.fromJson(reader, listTypeOf(mapTypeOf(Object.class, Object.class)));
210+
LauncherSettings.GSON.fromJson(reader, listTypeOf(mapTypeOf(Object.class, Object.class)));
211211
return accounts != null ? AccountStorages.fromAccounts(accounts) : null;
212212
} catch (Throwable e) {
213213
LOG.warning("Failed to load legacy global accounts", e);

HMCL/src/main/java/org/jackhuang/hmcl/setting/ConfigHolder.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ private ConfigHolder() {
116116
AuthlibInjectorServerList::createDefault);
117117

118118
/// The loaded per-workspace config instance.
119-
private static @UnknownNullability Config configInstance;
119+
private static @UnknownNullability LauncherSettings configInstance;
120120

121121
/// The loaded user-global config instance.
122122
private static @UnknownNullability GlobalConfig globalConfigInstance;
@@ -168,7 +168,7 @@ private ConfigHolder() {
168168
private static @Nullable AccountStorages migratedGameAccounts;
169169

170170
/// Returns the loaded per-workspace config.
171-
public static Config config() {
171+
public static LauncherSettings config() {
172172
if (configInstance == null) {
173173
throw new IllegalStateException("Configuration hasn't been loaded");
174174
}
@@ -369,7 +369,7 @@ public static void init() throws IOException {
369369
throw new IllegalStateException("Configuration is already loaded");
370370
}
371371

372-
LOG.info("Config location: " + SETTINGS_LOCATION);
372+
LOG.info("Launcher settings location: " + SETTINGS_LOCATION);
373373

374374
configInstance = loadConfig();
375375
if (!unsupportedVersion) {
@@ -405,7 +405,7 @@ public static void init() throws IOException {
405405
}
406406

407407
/// Loads the current per-workspace config or migrates a legacy config when needed.
408-
private static Config loadConfig() throws IOException {
408+
private static LauncherSettings loadConfig() throws IOException {
409409
if (Files.exists(SETTINGS_LOCATION)) {
410410
checkOwner(SETTINGS_LOCATION);
411411

@@ -415,21 +415,21 @@ private static Config loadConfig() throws IOException {
415415
} catch (Exception e) {
416416
needBackupSettings = true;
417417
LOG.warning("Failed to read settings file: " + SETTINGS_LOCATION, e);
418-
return new Config();
418+
return new LauncherSettings();
419419
}
420420

421421
if (jsonObject == null) {
422422
LOG.warning("Settings file is empty: " + SETTINGS_LOCATION);
423-
return new Config();
423+
return new LauncherSettings();
424424
}
425425

426426
JsonSchemaPolicy.Result schema =
427-
JsonSchemaPolicy.check(SETTINGS_LOCATION, "settings file", jsonObject, Config.CURRENT_SCHEMA);
427+
JsonSchemaPolicy.check(SETTINGS_LOCATION, "settings file", jsonObject, LauncherSettings.CURRENT_SCHEMA);
428428
if (!schema.allowSave()) {
429429
unsupportedVersion = true;
430430
}
431431
if (!schema.readable()) {
432-
return new Config();
432+
return new LauncherSettings();
433433
}
434434

435435
migratedGameAccounts = LegacyConfigMigrator.extractAccountStorages(jsonObject);
@@ -438,20 +438,20 @@ private static Config loadConfig() throws IOException {
438438
}
439439

440440
try {
441-
Config settings = Config.fromJson(jsonObject);
441+
LauncherSettings settings = LauncherSettings.fromJson(jsonObject);
442442
if (settings == null) {
443-
return new Config();
443+
return new LauncherSettings();
444444
}
445445

446-
if (!schema.preserveSchema() && !Config.CURRENT_SCHEMA.equals(settings.schemaProperty().get())) {
447-
settings.schemaProperty().set(Config.CURRENT_SCHEMA);
446+
if (!schema.preserveSchema() && !LauncherSettings.CURRENT_SCHEMA.equals(settings.schemaProperty().get())) {
447+
settings.schemaProperty().set(LauncherSettings.CURRENT_SCHEMA);
448448
}
449449

450450
return settings;
451451
} catch (JsonParseException e) {
452452
needBackupSettings = true;
453453
LOG.warning("Failed to parse settings file: " + SETTINGS_LOCATION, e);
454-
return new Config();
454+
return new LauncherSettings();
455455
}
456456
} else {
457457
LegacyConfigMigrator.MigrationResult migrationResult = LegacyConfigMigrator.migrateLegacyConfig();
@@ -463,11 +463,11 @@ private static Config loadConfig() throws IOException {
463463
migratedAuthlibInjectorServers = migrationResult.authlibInjectorServers();
464464
migratedGameAccounts = migrationResult.accountStorages();
465465
FileUtils.saveSafely(SETTINGS_LOCATION, migrationResult.contentForMigration());
466-
return migrationResult.config();
466+
return migrationResult.launcherSettings();
467467
}
468468
}
469469

470-
var newSettings = new Config();
470+
var newSettings = new LauncherSettings();
471471
newlyCreated = true;
472472
return newSettings;
473473
}
@@ -654,13 +654,13 @@ private static void checkWritable(Path location) throws IOException {
654654
if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS
655655
&& location.getFileSystem() == FileSystems.getDefault()
656656
&& location.toFile().canWrite()) {
657-
LOG.warning("Config at " + location + " is not writable, but it seems to be a Samba share or OpenJDK bug");
657+
LOG.warning("Launcher settings at " + location + " is not writable, but it seems to be a Samba share or OpenJDK bug");
658658
// There are some serious problems with the implementation of Samba or OpenJDK
659659
throw new SambaException();
660660
} else {
661661
// the config cannot be saved
662662
// throw up the error now to prevent further data loss
663-
throw new IOException("Config at " + location + " is not writable");
663+
throw new IOException("Launcher settings at " + location + " is not writable");
664664
}
665665
}
666666
}
@@ -672,7 +672,7 @@ private static GlobalConfig loadGlobalConfig() throws IOException {
672672
String content = Files.readString(GLOBAL_CONFIG_PATH);
673673
GlobalConfig deserialized = GlobalConfig.fromJson(content);
674674
if (deserialized == null) {
675-
LOG.info("Config is empty");
675+
LOG.info("Global config is empty");
676676
} else {
677677
return deserialized;
678678
}

HMCL/src/main/java/org/jackhuang/hmcl/setting/GameDirectories.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ protected GameDirectories createInstance() {
9999
JsonDeserializationContext context) throws JsonParseException {
100100
@Nullable GameDirectories result = super.deserialize(json, typeOfT, context);
101101
if (result != null) {
102-
result.unknownFields.remove(Config.SELECTED_GAME_DIRECTORY_MEMBER_NAME);
102+
result.unknownFields.remove(LauncherSettings.SELECTED_GAME_DIRECTORY_MEMBER_NAME);
103103
}
104104
return result;
105105
}

HMCL/src/main/java/org/jackhuang/hmcl/setting/GameSettingsPresets.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ protected GameSettingsPresets createInstance() {
134134
JsonDeserializationContext context) throws JsonParseException {
135135
@Nullable GameSettingsPresets result = super.deserialize(json, typeOfT, context);
136136
if (result != null) {
137-
result.unknownFields.remove(Config.DEFAULT_GAME_SETTINGS_PRESET_MEMBER_NAME);
137+
result.unknownFields.remove(LauncherSettings.DEFAULT_GAME_SETTINGS_PRESET_MEMBER_NAME);
138138
}
139139
return result;
140140
}

HMCL/src/main/java/org/jackhuang/hmcl/setting/GlobalConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ public final class GlobalConfig extends ObservableSetting {
3333

3434
@Nullable
3535
public static GlobalConfig fromJson(String json) throws JsonParseException {
36-
return Config.CONFIG_GSON.fromJson(json, GlobalConfig.class);
36+
return LauncherSettings.GSON.fromJson(json, GlobalConfig.class);
3737
}
3838

3939
public GlobalConfig() {
4040
register();
4141
}
4242

4343
public String toJson() {
44-
return Config.CONFIG_GSON.toJson(this);
44+
return LauncherSettings.GSON.toJson(this);
4545
}
4646

4747
@SerializedName("agreementVersion")

HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java renamed to HMCL/src/main/java/org/jackhuang/hmcl/setting/LauncherSettings.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@
5151
/// selected instances, and account selection. Larger domain-specific stores, such as game directories,
5252
/// game settings presets, accounts, launcher state, and authlib-injector servers, are persisted in detached
5353
/// JSON files managed by [ConfigHolder].
54-
@JsonAdapter(value = Config.Adapter.class)
55-
public final class Config extends ObservableSetting {
54+
@JsonAdapter(value = LauncherSettings.Adapter.class)
55+
public final class LauncherSettings extends ObservableSetting {
5656

57-
/// The JSON schema supported by this config class.
57+
/// The JSON schema supported by this launcher settings class.
5858
public static final JsonSchema CURRENT_SCHEMA = new JsonSchema("settings", new JsonSchema.Version(1, 0, 0));
5959

6060
/// The JSON member name for the default game setting preset ID.
@@ -66,8 +66,8 @@ public final class Config extends ObservableSetting {
6666
/// The JSON member name for selected instance IDs keyed by game directory ID.
6767
static final String SELECTED_INSTANCE_MEMBER_NAME = "selectedInstance";
6868

69-
/// Gson instance used for main config and related settings objects that depend on JavaFX properties.
70-
public static final Gson CONFIG_GSON = new GsonBuilder()
69+
/// Gson instance used for launcher settings and related settings objects that depend on JavaFX properties.
70+
public static final Gson GSON = new GsonBuilder()
7171
.registerTypeAdapter(Path.class, PathTypeAdapter.INSTANCE)
7272
.registerTypeAdapter(UUID.class, UUIDTypeAdapter.INSTANCE)
7373
.registerTypeAdapter(GUID.class, GUIDTypeAdapter.INSTANCE)
@@ -82,30 +82,30 @@ public final class Config extends ObservableSetting {
8282
.setObjectToNumberStrategy(ToNumberPolicy.LONG_OR_DOUBLE)
8383
.create();
8484

85-
/// Deserializes a config object from JSON.
85+
/// Deserializes launcher settings from JSON.
8686
///
8787
/// @param json the JSON object to read
88-
/// @return the deserialized config, or `null` if the JSON represents `null`
89-
/// @throws JsonParseException if the JSON cannot be deserialized as a config
88+
/// @return the deserialized launcher settings, or `null` if the JSON represents `null`
89+
/// @throws JsonParseException if the JSON cannot be deserialized as launcher settings
9090
@Nullable
91-
public static Config fromJson(JsonObject json) throws JsonParseException {
92-
return CONFIG_GSON.fromJson(json, Config.class);
91+
public static LauncherSettings fromJson(JsonObject json) throws JsonParseException {
92+
return GSON.fromJson(json, LauncherSettings.class);
9393
}
9494

95-
/// Creates an empty config using current defaults.
96-
public Config() {
95+
/// Creates empty launcher settings using current defaults.
96+
public LauncherSettings() {
9797
tracker.markDirty(schema);
9898
register();
9999
}
100100

101-
/// Serializes this config to formatted JSON.
101+
/// Serializes these launcher settings to formatted JSON.
102102
public String toJson() {
103-
return CONFIG_GSON.toJson(this);
103+
return GSON.toJson(this);
104104
}
105105

106106
// Properties
107107

108-
/// The schema used by this config file.
108+
/// The schema used by this launcher settings file.
109109
@SerializedName(JsonSchema.DEFAULT_MEMBER_NAME)
110110
private final ObjectProperty<JsonSchema> schema = new SimpleObjectProperty<>(CURRENT_SCHEMA);
111111

@@ -477,17 +477,17 @@ public StringProperty selectedAccountProperty() {
477477
return selectedAccount;
478478
}
479479

480-
/// JSON adapter for [Config].
481-
public static final class Adapter extends ObservableSetting.Adapter<Config> {
482-
/// Creates an empty config for deserialization.
480+
/// JSON adapter for [LauncherSettings].
481+
public static final class Adapter extends ObservableSetting.Adapter<LauncherSettings> {
482+
/// Creates empty launcher settings for deserialization.
483483
@Override
484-
protected Config createInstance() {
485-
return new Config();
484+
protected LauncherSettings createInstance() {
485+
return new LauncherSettings();
486486
}
487487

488-
/// Serializes the main config with its stored schema.
488+
/// Serializes the main launcher settings with their stored schema.
489489
@Override
490-
public JsonElement serialize(Config src, Type typeOfSrc, JsonSerializationContext context) {
490+
public JsonElement serialize(LauncherSettings src, Type typeOfSrc, JsonSerializationContext context) {
491491
if (src == null) {
492492
return JsonNull.INSTANCE;
493493
}

0 commit comments

Comments
 (0)