Skip to content

Commit a7df3ae

Browse files
committed
Use GUID v7 for new profile IDs
1 parent 00e9a9c commit a7df3ae

4 files changed

Lines changed: 8 additions & 31 deletions

File tree

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,13 @@ protected Instance createInstance() {
120120
public static final class Preset extends GameSettings {
121121
/// Creates a preset with the given identity.
122122
public Preset(GUID id) {
123-
this(id, true);
123+
register();
124+
this.id.setValue(Objects.requireNonNull(id));
124125
}
125126

126127
/// Creates a preset with the given identity.
127-
private Preset(GUID id, boolean checkNonNil) {
128+
private Preset() {
128129
register();
129-
this.id.setValue(checkNonNil ? requireNonNilId(id) : Objects.requireNonNull(id));
130130
}
131131

132132
/// The stable preset ID.
@@ -138,15 +138,6 @@ public SettingProperty<GUID> idProperty() {
138138
return id;
139139
}
140140

141-
/// Returns a non-nil preset ID or throws when the value is not usable.
142-
private static GUID requireNonNilId(GUID id) {
143-
Objects.requireNonNull(id);
144-
if (GUID.NIL.equals(id)) {
145-
throw new IllegalArgumentException("Preset ID cannot be nil");
146-
}
147-
return id;
148-
}
149-
150141
/// The display name of this preset.
151142
@SerializedName("name")
152143
private final SettingProperty<String> name = newSettingProperty("name", "");
@@ -169,7 +160,7 @@ public SettingProperty<DefaultIsolationType> defaultIsolationTypeProperty() {
169160
public static final class Adapter extends ObservableSetting.Adapter<@Nullable Preset> {
170161
@Override
171162
protected Preset createInstance() {
172-
return new Preset(GUID.NIL, false);
163+
return new Preset();
173164
}
174165

175166
@Override

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public GUID getId() {
7575

7676
/// Sets the stable profile ID.
7777
public void setId(GUID id) {
78-
this.id.set(requireNonNilId(id));
78+
this.id.set(Objects.requireNonNull(id));
7979
}
8080

8181
private final StringProperty selectedVersion = new SimpleStringProperty();
@@ -136,7 +136,7 @@ public Profile(GUID id, String name, PortablePath path) {
136136

137137
/// Creates a profile with an explicit stable ID.
138138
Profile(GUID id, String name, PortablePath path, @Nullable String selectedVersion) {
139-
this.id.set(requireNonNilId(id));
139+
this.id.set(Objects.requireNonNull(id));
140140
this.name = new SimpleStringProperty(this, "name", name);
141141
this.path = new SimpleObjectProperty<>(this, "path", Objects.requireNonNull(path));
142142
repository = new HMCLGameRepository(this, path.toPath());
@@ -149,15 +149,6 @@ public Profile(GUID id, String name, PortablePath path) {
149149
addPropertyChangedListener(onInvalidating(this::invalidate));
150150
}
151151

152-
/// Returns a non-nil profile ID or throws when the value is not usable.
153-
private static GUID requireNonNilId(GUID id) {
154-
Objects.requireNonNull(id);
155-
if (GUID.NIL.equals(id)) {
156-
throw new IllegalArgumentException("Profile ID cannot be nil");
157-
}
158-
return id;
159-
}
160-
161152
private void checkSelectedVersion() {
162153
runInFX(() -> {
163154
if (!repository.isLoaded()) return;

HMCL/src/test/java/org/jackhuang/hmcl/setting/GameDirectoriesTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,9 @@ public void storesProfilePath() {
8686
assertFalse(deserialized.getPath().isAbsolute());
8787
}
8888

89-
/// Tests that profiles must be initialized with a non-nil ID.
89+
/// Tests that profiles must be deserialized with a non-nil ID.
9090
@Test
9191
public void rejectsNilProfileId() {
92-
assertThrows(IllegalArgumentException.class,
93-
() -> new Profile(GUID.NIL, "Dev", PortablePath.of("versions/Dev")));
94-
9592
assertThrows(JsonParseException.class, () -> JsonUtils.GSON.fromJson("""
9693
{
9794
"id": "00000000-0000-0000-0000-000000000000",

HMCL/src/test/java/org/jackhuang/hmcl/setting/GameSettingsPresetsTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@ public void storesDefaultGameSettingsPresetInConfig() {
4343
assertEquals(id.toString(), serialized.get(Config.DEFAULT_GAME_SETTINGS_PRESET_MEMBER_NAME).getAsString());
4444
}
4545

46-
/// Tests that presets must be initialized with a non-nil ID.
46+
/// Tests that presets must be deserialized with a non-nil ID.
4747
@Test
4848
public void rejectsNilPresetId() {
49-
assertThrows(IllegalArgumentException.class, () -> new GameSettings.Preset(GUID.NIL));
50-
5149
assertThrows(JsonParseException.class, () -> JsonUtils.GSON.fromJson("""
5250
{
5351
"id": "00000000-0000-0000-0000-000000000000"

0 commit comments

Comments
 (0)