@@ -2,11 +2,13 @@ module libmodpm.inventory.Config;
22
33import std.json ;
44
5+ import libmodpm.registry.ReleaseChannel;
6+
57/**
68 * Represents the package manager configuration for a given scope.
79 */
810public final class Config {
9- /**
11+ /**
1012 * Configuration schema version.
1113 */
1214 public static const enum CONFIG_VERSION = 0 ;
@@ -154,8 +156,13 @@ public final class Config {
154156 * Game version supported by the loader in this scope.
155157 */
156158 public immutable string gameVersion;
157-
158- /**
159+
160+ /**
161+ * Release channel specifying the minimum stability of versions chosen automatically in this scope.
162+ */
163+ public immutable ReleaseChannel minimumReleaseChannel;
164+
165+ /**
159166 * Path to the directory in which packages will be installed. The path must be on the same filesystem as the modpm
160167 * scope. If the path is relative, it is resolved from the modpm scope path.
161168 */
@@ -169,13 +176,19 @@ public final class Config {
169176 * environment = Type of environment of this scope.
170177 * loader = Package loader used in this scope.
171178 * gameVersion = Game version supported by the loader in this scope.
179+ * minimumReleaseChannel = Release channel specifying the minimum stability of versions chosen automatically in
180+ * this scope.
181+ * path = Path to the directory in which packages will be installed.
172182 */
173- public this (immutable Type type, immutable Environment environment, immutable Loader loader,
174- immutable string gameVersion, immutable string path) immutable {
183+ public this (
184+ immutable Type type, immutable Environment environment, immutable Loader loader, immutable string gameVersion,
185+ immutable ReleaseChannel minimumReleaseChannel, immutable string path
186+ ) immutable {
175187 this .type = type;
176188 this .environment = environment;
177189 this .loader = loader;
178190 this .gameVersion = gameVersion;
191+ this .minimumReleaseChannel = minimumReleaseChannel;
179192 this .path = path;
180193 }
181194
@@ -188,6 +201,18 @@ public final class Config {
188201 j.object[" environment" ] = JSONValue(environment);
189202 j.object[" loader" ] = JSONValue(loader);
190203 j.object[" gameVersion" ] = JSONValue(gameVersion);
204+
205+ final switch (minimumReleaseChannel) {
206+ case ReleaseChannel.RELEASE :
207+ j.object[" releaseChannel" ] = JSONValue(" release" );
208+ break ;
209+ case ReleaseChannel.BETA :
210+ j.object[" releaseChannel" ] = JSONValue(" beta" );
211+ break ;
212+ case ReleaseChannel.ALPHA :
213+ j.object[" releaseChannel" ] = JSONValue(" alpha" );
214+ break ;
215+ }
191216 j.object[" path" ] = JSONValue(path);
192217
193218 return j.toJSON(pretty: true );
@@ -209,11 +234,28 @@ public final class Config {
209234 throw new Exception (" Incompatible config version " ~ j[" configVersion" ].integer().stringof ~ " . "
210235 ~ " This version of libmodpm only recognizes version " ~ CONFIG_VERSION ~ " ." );
211236
237+ string releaseChannel = j[" releaseChannel" ].str();
238+ ReleaseChannel rc;
239+
240+ switch (releaseChannel) {
241+ case " release" :
242+ rc = ReleaseChannel.RELEASE ;
243+ break ;
244+ case " beta" :
245+ rc = ReleaseChannel.BETA ;
246+ break ;
247+ case " alpha" :
248+ rc = ReleaseChannel.ALPHA ;
249+ break ;
250+ default : assert (0 );
251+ }
252+
212253 return new immutable (Config)(
213254 cast (Type) j[" type" ].str(),
214255 cast (Environment ) j[" environment" ].str(),
215256 cast (Loader) j[" loader" ].str(),
216257 j[" gameVersion" ].str(),
258+ rc,
217259 j[" path" ].str(),
218260 );
219261 }
0 commit comments