From a21f51932ad45e929864edcb58db90b4998dbf16 Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Wed, 14 Feb 2024 17:37:37 +0000 Subject: [PATCH 01/24] add install config definitions --- ThunderstoreCLI/Configuration/Config.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ThunderstoreCLI/Configuration/Config.cs b/ThunderstoreCLI/Configuration/Config.cs index ff35a83..7bb33b7 100644 --- a/ThunderstoreCLI/Configuration/Config.cs +++ b/ThunderstoreCLI/Configuration/Config.cs @@ -218,6 +218,21 @@ public class PublishConfig public Dictionary? Categories { get; set; } } +public struct InstallerDeclaration +{ + public readonly string Identifier; + + public InstallerDeclaration(string identifier) + { + Identifier = identifier; + } +} + +public class InstallConfig +{ + public List? InstallerDeclarations { get; set; } +} + public class AuthConfig { public string? AuthToken { get; set; } From 5133b24c7f2bcaf122cbee78edcc2bf45c4b56cc Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Wed, 14 Feb 2024 17:38:11 +0000 Subject: [PATCH 02/24] add install config to encompassing config --- ThunderstoreCLI/Configuration/Config.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ThunderstoreCLI/Configuration/Config.cs b/ThunderstoreCLI/Configuration/Config.cs index 7bb33b7..100457c 100644 --- a/ThunderstoreCLI/Configuration/Config.cs +++ b/ThunderstoreCLI/Configuration/Config.cs @@ -13,6 +13,7 @@ public class Config public required InitConfig InitConfig { get; init; } public required BuildConfig BuildConfig { get; init; } public required PublishConfig PublishConfig { get; init; } + public required InstallConfig InstallConfig { get; init; } public required AuthConfig AuthConfig { get; init; } public required ModManagementConfig ModManagementConfig { get; init; } public required GameImportConfig GameImportConfig { get; init; } @@ -121,6 +122,7 @@ public static Config Parse(IConfigProvider[] configProviders) InitConfig = new InitConfig(), BuildConfig = new BuildConfig(), PublishConfig = new PublishConfig(), + InstallConfig = new InstallConfig(), AuthConfig = new AuthConfig(), ModManagementConfig = new ModManagementConfig(), GameImportConfig = new GameImportConfig(), From d5386ae727f5b427ffd1cf202532f7e616361fbe Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Wed, 14 Feb 2024 17:38:32 +0000 Subject: [PATCH 03/24] allow config providers to provide install config --- ThunderstoreCLI/Configuration/Config.cs | 1 + ThunderstoreCLI/Configuration/IConfigProvider.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/ThunderstoreCLI/Configuration/Config.cs b/ThunderstoreCLI/Configuration/Config.cs index 100457c..cd3de93 100644 --- a/ThunderstoreCLI/Configuration/Config.cs +++ b/ThunderstoreCLI/Configuration/Config.cs @@ -136,6 +136,7 @@ public static Config Parse(IConfigProvider[] configProviders) Merge(result.InitConfig, provider.GetInitConfig(), false); Merge(result.BuildConfig, provider.GetBuildConfig(), false); Merge(result.PublishConfig, provider.GetPublishConfig(), false); + Merge(result.InstallConfig, provider.GetInstallConfig(), false); Merge(result.AuthConfig, provider.GetAuthConfig(), false); Merge(result.ModManagementConfig, provider.GetModManagementConfig(), false); Merge(result.GameImportConfig, provider.GetGameImportConfig(), false); diff --git a/ThunderstoreCLI/Configuration/IConfigProvider.cs b/ThunderstoreCLI/Configuration/IConfigProvider.cs index 89b2e70..956275a 100644 --- a/ThunderstoreCLI/Configuration/IConfigProvider.cs +++ b/ThunderstoreCLI/Configuration/IConfigProvider.cs @@ -9,6 +9,7 @@ public interface IConfigProvider InitConfig? GetInitConfig(); BuildConfig? GetBuildConfig(); PublishConfig? GetPublishConfig(); + InstallConfig? GetInstallConfig(); AuthConfig? GetAuthConfig(); ModManagementConfig? GetModManagementConfig(); GameImportConfig? GetGameImportConfig(); From f482371314c9d48c02881a5d1cd7722fe9ba82e1 Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Wed, 14 Feb 2024 18:00:10 +0000 Subject: [PATCH 04/24] add base implementation of GetInstallConfig --- ThunderstoreCLI/Configuration/EmptyConfig.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ThunderstoreCLI/Configuration/EmptyConfig.cs b/ThunderstoreCLI/Configuration/EmptyConfig.cs index c3074b5..f059533 100644 --- a/ThunderstoreCLI/Configuration/EmptyConfig.cs +++ b/ThunderstoreCLI/Configuration/EmptyConfig.cs @@ -29,6 +29,11 @@ public virtual void Parse(Config currentConfig) { } return null; } + public virtual InstallConfig? GetInstallConfig() + { + return null; + } + public virtual AuthConfig? GetAuthConfig() { return null; From fa553fad1dcb51495d4bf5df56fa534877f4143f Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Wed, 14 Feb 2024 18:02:21 +0000 Subject: [PATCH 05/24] add InstallData member to ThunderstoreProject --- ThunderstoreCLI/Models/ThunderstoreProject.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ThunderstoreCLI/Models/ThunderstoreProject.cs b/ThunderstoreCLI/Models/ThunderstoreProject.cs index 6b09b7a..0717a31 100644 --- a/ThunderstoreCLI/Models/ThunderstoreProject.cs +++ b/ThunderstoreCLI/Models/ThunderstoreProject.cs @@ -112,6 +112,22 @@ public class PublishData [TomlProperty("publish")] public PublishData? Publish { get; set; } + [TomlDoNotInlineObject] + public class InstallData + { + [TomlDoNotInlineObject] + public class InstallerDeclaration + { + [TomlProperty("identifier")] + public string Identifier { get; set; } = "foo-installer"; + } + + [TomlProperty("installers")] + public InstallerDeclaration[] InstallerDeclarations { get; set; } = new InstallerDeclaration[] { new InstallerDeclaration() }; + } + [TomlProperty("install")] + public InstallData? Install { get; set; } + public ThunderstoreProject() { } public ThunderstoreProject(bool initialize) From e78e7381e751523eae66b4cd25519a0868efc2d1 Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Wed, 14 Feb 2024 18:02:36 +0000 Subject: [PATCH 06/24] initialize Install data from parameterless ctor --- ThunderstoreCLI/Models/ThunderstoreProject.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/ThunderstoreCLI/Models/ThunderstoreProject.cs b/ThunderstoreCLI/Models/ThunderstoreProject.cs index 0717a31..c5e693e 100644 --- a/ThunderstoreCLI/Models/ThunderstoreProject.cs +++ b/ThunderstoreCLI/Models/ThunderstoreProject.cs @@ -138,6 +138,7 @@ public ThunderstoreProject(bool initialize) Package = new PackageData(); Build = new BuildData(); Publish = new PublishData(); + Install = new InstallData(); } public ThunderstoreProject(Config config) From 2f480282b0cc3c50d872468e09b13852d26c8e97 Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Wed, 14 Feb 2024 18:02:51 +0000 Subject: [PATCH 07/24] Initialize Install data from Config instance --- ThunderstoreCLI/Models/ThunderstoreProject.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ThunderstoreCLI/Models/ThunderstoreProject.cs b/ThunderstoreCLI/Models/ThunderstoreProject.cs index c5e693e..6e64b40 100644 --- a/ThunderstoreCLI/Models/ThunderstoreProject.cs +++ b/ThunderstoreCLI/Models/ThunderstoreProject.cs @@ -161,5 +161,11 @@ public ThunderstoreProject(Config config) Communities = config.PublishConfig.Communities!, Repository = config.GeneralConfig.Repository }; + Install = new InstallData() + { + InstallerDeclarations = config.InstallConfig.InstallerDeclarations! + .Select(x => new InstallData.InstallerDeclaration { Identifier = x.Identifier }) + .ToArray() + }; } } From 477927e3e49539fb552f05555755642135e57566 Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Wed, 14 Feb 2024 18:03:11 +0000 Subject: [PATCH 08/24] override GetInstallConfig in ProjectFileConfig (provider) --- ThunderstoreCLI/Configuration/ProjectFileConfig.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ThunderstoreCLI/Configuration/ProjectFileConfig.cs b/ThunderstoreCLI/Configuration/ProjectFileConfig.cs index 33323a3..241f9f4 100644 --- a/ThunderstoreCLI/Configuration/ProjectFileConfig.cs +++ b/ThunderstoreCLI/Configuration/ProjectFileConfig.cs @@ -67,6 +67,16 @@ public override void Parse(Config currentConfig) }; } + public override InstallConfig? GetInstallConfig() + { + return new InstallConfig + { + InstallerDeclarations = Project.Install?.InstallerDeclarations + .Select(static path => new InstallerDeclaration(path.Identifier)) + .ToList() + }; + } + public static void Write(Config config, string path) { File.WriteAllText(path, new ThunderstoreProject(config).Serialize()); From a579ec7e42f72ff23f29a7c158fe702fc765a096 Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Wed, 14 Feb 2024 18:11:25 +0000 Subject: [PATCH 09/24] add installer declarations field to package manifest definition --- ThunderstoreCLI/PackageManifestV1.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ThunderstoreCLI/PackageManifestV1.cs b/ThunderstoreCLI/PackageManifestV1.cs index 3ea2b1b..2bf6189 100644 --- a/ThunderstoreCLI/PackageManifestV1.cs +++ b/ThunderstoreCLI/PackageManifestV1.cs @@ -23,9 +23,18 @@ public class PackageManifestV1 : BaseJson [JsonProperty("website_url")] public string? WebsiteUrl { get; set; } + [JsonProperty("installers")] + public InstallerDeclaration[]? Installers { get; set; } + private string? fullName; public string FullName => fullName ??= $"{Namespace}-{Name}"; + public class InstallerDeclaration + { + [JsonProperty("identifier")] + public string? Identifier { get; set; } + } + public PackageManifestV1() { } public PackageManifestV1(PackageVersionData version) From 33442023caf5a7272929caad5bc495db08ed01c8 Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Wed, 14 Feb 2024 18:12:37 +0000 Subject: [PATCH 10/24] Write install config from `Config` instance to `PackageManifestV1` when building packages --- ThunderstoreCLI/Commands/BuildCommand.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ThunderstoreCLI/Commands/BuildCommand.cs b/ThunderstoreCLI/Commands/BuildCommand.cs index 3cdbeac..74aed9b 100644 --- a/ThunderstoreCLI/Commands/BuildCommand.cs +++ b/ThunderstoreCLI/Commands/BuildCommand.cs @@ -294,6 +294,8 @@ public static string FormatArchivePath(string path, bool validate = true) public static string SerializeManifest(Config config) { var dependencies = config.PackageConfig.Dependencies ?? new Dictionary(); + IEnumerable? installerDeclarations = config.InstallConfig.InstallerDeclarations; + installerDeclarations ??= Array.Empty(); var manifest = new PackageManifestV1() { Namespace = config.PackageConfig.Namespace, @@ -301,7 +303,10 @@ public static string SerializeManifest(Config config) Description = config.PackageConfig.Description, VersionNumber = config.PackageConfig.VersionNumber, WebsiteUrl = config.PackageConfig.WebsiteUrl, - Dependencies = dependencies.Select(x => $"{x.Key}-{x.Value}").ToArray() + Dependencies = dependencies.Select(x => $"{x.Key}-{x.Value}").ToArray(), + Installers = installerDeclarations + .Select(x => new PackageManifestV1.InstallerDeclaration { Identifier = x.Identifier }) + .ToArray() }; return manifest.Serialize(BaseJson.IndentedSettings); From 9b61bc438d88939d6b1a5c33b07792a99814c6ab Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Wed, 14 Feb 2024 18:41:47 +0000 Subject: [PATCH 11/24] remove unused 'using' directives --- ThunderstoreCLI/Commands/InstallCommand.cs | 1 - ThunderstoreCLI/Commands/RunCommand.cs | 1 - ThunderstoreCLI/Configuration/ProjectFileConfig.cs | 1 - ThunderstoreCLI/Game/ModProfile.cs | 2 -- ThunderstoreCLI/Models/SchemaResponse.cs | 1 - ThunderstoreCLI/Program.cs | 1 - ThunderstoreCLI/Utils/SteamUtils.cs | 1 - 7 files changed, 8 deletions(-) diff --git a/ThunderstoreCLI/Commands/InstallCommand.cs b/ThunderstoreCLI/Commands/InstallCommand.cs index 1d7bb28..0b76ce4 100644 --- a/ThunderstoreCLI/Commands/InstallCommand.cs +++ b/ThunderstoreCLI/Commands/InstallCommand.cs @@ -1,6 +1,5 @@ using System.Diagnostics; using System.IO.Compression; -using System.Net.Http.Headers; using System.Runtime.InteropServices; using System.Text.RegularExpressions; using ThunderstoreCLI.Configuration; diff --git a/ThunderstoreCLI/Commands/RunCommand.cs b/ThunderstoreCLI/Commands/RunCommand.cs index d3b7de2..48899b2 100644 --- a/ThunderstoreCLI/Commands/RunCommand.cs +++ b/ThunderstoreCLI/Commands/RunCommand.cs @@ -1,6 +1,5 @@ using System.Diagnostics; using System.Runtime.InteropServices; -using System.Text; using ThunderstoreCLI.Configuration; using ThunderstoreCLI.Game; using ThunderstoreCLI.Utils; diff --git a/ThunderstoreCLI/Configuration/ProjectFileConfig.cs b/ThunderstoreCLI/Configuration/ProjectFileConfig.cs index 241f9f4..de052d8 100644 --- a/ThunderstoreCLI/Configuration/ProjectFileConfig.cs +++ b/ThunderstoreCLI/Configuration/ProjectFileConfig.cs @@ -1,5 +1,4 @@ using ThunderstoreCLI.Models; -using ThunderstoreCLI.Utils; using static Crayon.Output; namespace ThunderstoreCLI.Configuration; diff --git a/ThunderstoreCLI/Game/ModProfile.cs b/ThunderstoreCLI/Game/ModProfile.cs index 5a43fb0..86d52f5 100644 --- a/ThunderstoreCLI/Game/ModProfile.cs +++ b/ThunderstoreCLI/Game/ModProfile.cs @@ -1,5 +1,3 @@ -using System.Diagnostics.CodeAnalysis; -using System.Text.Json.Serialization; using ThunderstoreCLI.Models; namespace ThunderstoreCLI.Game; diff --git a/ThunderstoreCLI/Models/SchemaResponse.cs b/ThunderstoreCLI/Models/SchemaResponse.cs index ab607d8..8376a3b 100644 --- a/ThunderstoreCLI/Models/SchemaResponse.cs +++ b/ThunderstoreCLI/Models/SchemaResponse.cs @@ -1,6 +1,5 @@ using ThunderstoreCLI.Configuration; using ThunderstoreCLI.Game; -using ThunderstoreCLI.Utils; namespace ThunderstoreCLI.Models; diff --git a/ThunderstoreCLI/Program.cs b/ThunderstoreCLI/Program.cs index 3b5d9a4..d99679d 100644 --- a/ThunderstoreCLI/Program.cs +++ b/ThunderstoreCLI/Program.cs @@ -1,6 +1,5 @@ using System.Diagnostics; using CommandLine; -using ThunderstoreCLI.Models; using ThunderstoreCLI.Utils; namespace ThunderstoreCLI; diff --git a/ThunderstoreCLI/Utils/SteamUtils.cs b/ThunderstoreCLI/Utils/SteamUtils.cs index d7f703b..4114bea 100644 --- a/ThunderstoreCLI/Utils/SteamUtils.cs +++ b/ThunderstoreCLI/Utils/SteamUtils.cs @@ -1,6 +1,5 @@ using System.Runtime.InteropServices; using System.Runtime.Versioning; -using System.Security.AccessControl; using System.Text.RegularExpressions; using Microsoft.Win32; From 577b6af477e5e4a2cbf91b34cbfc27d26d1bac4c Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Wed, 14 Feb 2024 18:42:35 +0000 Subject: [PATCH 12/24] to expression-bodied properties --- ThunderstoreCLI/Configuration/EmptyConfig.cs | 68 ++++++-------------- 1 file changed, 19 insertions(+), 49 deletions(-) diff --git a/ThunderstoreCLI/Configuration/EmptyConfig.cs b/ThunderstoreCLI/Configuration/EmptyConfig.cs index f059533..20839e9 100644 --- a/ThunderstoreCLI/Configuration/EmptyConfig.cs +++ b/ThunderstoreCLI/Configuration/EmptyConfig.cs @@ -4,53 +4,23 @@ namespace ThunderstoreCLI.Configuration; public abstract class EmptyConfig : IConfigProvider { public virtual void Parse(Config currentConfig) { } - public virtual GeneralConfig? GetGeneralConfig() - { - return null; - } - - public virtual PackageConfig? GetPackageMeta() - { - return null; - } - - public virtual InitConfig? GetInitConfig() - { - return null; - } - - public virtual BuildConfig? GetBuildConfig() - { - return null; - } - - public virtual PublishConfig? GetPublishConfig() - { - return null; - } - - public virtual InstallConfig? GetInstallConfig() - { - return null; - } - - public virtual AuthConfig? GetAuthConfig() - { - return null; - } - - public virtual ModManagementConfig? GetModManagementConfig() - { - return null; - } - - public virtual GameImportConfig? GetGameImportConfig() - { - return null; - } - - public virtual RunGameConfig? GetRunGameConfig() - { - return null; - } + public virtual GeneralConfig? GetGeneralConfig() => null; + + public virtual PackageConfig? GetPackageMeta() => null; + + public virtual InitConfig? GetInitConfig() => null; + + public virtual BuildConfig? GetBuildConfig() => null; + + public virtual PublishConfig? GetPublishConfig() => null; + + public virtual InstallConfig? GetInstallConfig() => null; + + public virtual AuthConfig? GetAuthConfig() => null; + + public virtual ModManagementConfig? GetModManagementConfig() => null; + + public virtual GameImportConfig? GetGameImportConfig() => null; + + public virtual RunGameConfig? GetRunGameConfig() => null; } From bb8f07ca5988a0824910b2159f86264526ee2206 Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Wed, 14 Feb 2024 18:45:19 +0000 Subject: [PATCH 13/24] implement GetInstallConfig for default config provider --- ThunderstoreCLI/Configuration/DefaultConfig.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ThunderstoreCLI/Configuration/DefaultConfig.cs b/ThunderstoreCLI/Configuration/DefaultConfig.cs index c78cef7..394f262 100644 --- a/ThunderstoreCLI/Configuration/DefaultConfig.cs +++ b/ThunderstoreCLI/Configuration/DefaultConfig.cs @@ -57,4 +57,12 @@ public override PublishConfig GetPublishConfig() File = null }; } + + public override InstallConfig GetInstallConfig() + { + return new InstallConfig + { + InstallerDeclarations = new() { new InstallerDeclaration("foo-installer") } + }; + } } From 6f57fbc8a7d305432db1cda602761759d3a32c21 Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Wed, 14 Feb 2024 18:45:53 +0000 Subject: [PATCH 14/24] update to language version 12 --- ThunderstoreCLI/ThunderstoreCLI.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ThunderstoreCLI/ThunderstoreCLI.csproj b/ThunderstoreCLI/ThunderstoreCLI.csproj index 7fdeeb0..ba326b1 100644 --- a/ThunderstoreCLI/ThunderstoreCLI.csproj +++ b/ThunderstoreCLI/ThunderstoreCLI.csproj @@ -3,7 +3,7 @@ Exe net7.0;net6.0 - 11 + 12 Major ThunderstoreCLI tcli From a7ec3190929a3c50f71c02aa99de1b072a7b9d69 Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Wed, 14 Feb 2024 18:48:00 +0000 Subject: [PATCH 15/24] use collection expressions --- ThunderstoreCLI/Configuration/DefaultConfig.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/ThunderstoreCLI/Configuration/DefaultConfig.cs b/ThunderstoreCLI/Configuration/DefaultConfig.cs index 394f262..575d79a 100644 --- a/ThunderstoreCLI/Configuration/DefaultConfig.cs +++ b/ThunderstoreCLI/Configuration/DefaultConfig.cs @@ -43,10 +43,7 @@ public override BuildConfig GetBuildConfig() IconPath = "./icon.png", ReadmePath = "./README.md", OutDir = "./build", - CopyPaths = new() - { - { new("./dist", "") } - } + CopyPaths = [new("./dist", "")] }; } @@ -62,7 +59,7 @@ public override InstallConfig GetInstallConfig() { return new InstallConfig { - InstallerDeclarations = new() { new InstallerDeclaration("foo-installer") } + InstallerDeclarations = [new InstallerDeclaration("foo-installer")] }; } } From 96b29692580cdc9c39690b3d8e3bba5043512863 Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Wed, 14 Feb 2024 18:48:33 +0000 Subject: [PATCH 16/24] standardise fluent-chaining newlines --- ThunderstoreCLI/Configuration/ProjectFileConfig.cs | 4 +++- ThunderstoreCLI/Models/ThunderstoreProject.cs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ThunderstoreCLI/Configuration/ProjectFileConfig.cs b/ThunderstoreCLI/Configuration/ProjectFileConfig.cs index de052d8..4654f60 100644 --- a/ThunderstoreCLI/Configuration/ProjectFileConfig.cs +++ b/ThunderstoreCLI/Configuration/ProjectFileConfig.cs @@ -50,7 +50,9 @@ public override void Parse(Config currentConfig) { return new BuildConfig() { - CopyPaths = Project.Build?.CopyPaths.Select(static path => new CopyPathMap(path.Source, path.Target)).ToList(), + CopyPaths = Project.Build?.CopyPaths + .Select(static path => new CopyPathMap(path.Source, path.Target)) + .ToList(), IconPath = Project.Build?.Icon, OutDir = Project.Build?.OutDir, ReadmePath = Project.Build?.Readme diff --git a/ThunderstoreCLI/Models/ThunderstoreProject.cs b/ThunderstoreCLI/Models/ThunderstoreProject.cs index 6e64b40..9953b6c 100644 --- a/ThunderstoreCLI/Models/ThunderstoreProject.cs +++ b/ThunderstoreCLI/Models/ThunderstoreProject.cs @@ -153,7 +153,9 @@ public ThunderstoreProject(Config config) Icon = config.GetPackageIconPath(), OutDir = config.GetBuildOutputDir(), Readme = config.GetPackageReadmePath(), - CopyPaths = config.BuildConfig.CopyPaths!.Select(x => new BuildData.CopyPath { Source = x.From, Target = x.To }).ToArray()! + CopyPaths = config.BuildConfig.CopyPaths! + .Select(x => new BuildData.CopyPath { Source = x.From, Target = x.To }) + .ToArray()! }; Publish = new PublishData() { From 88997480b1f18aff0644785e5cd79251876825dd Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Wed, 14 Feb 2024 18:50:03 +0000 Subject: [PATCH 17/24] remove redundant empty parameters `()` --- ThunderstoreCLI/API/ApiHelper.cs | 2 +- ThunderstoreCLI/Commands/BuildCommand.cs | 2 +- ThunderstoreCLI/Commands/PublishCommand.cs | 2 +- .../Configuration/CLIParameterConfig.cs | 16 ++++++++-------- ThunderstoreCLI/Configuration/Config.cs | 2 +- ThunderstoreCLI/Configuration/DefaultConfig.cs | 10 +++++----- .../Configuration/EnvironmentConfig.cs | 2 +- .../Configuration/ProjectFileConfig.cs | 8 ++++---- ThunderstoreCLI/Models/ThunderstoreProject.cs | 8 ++++---- 9 files changed, 26 insertions(+), 26 deletions(-) diff --git a/ThunderstoreCLI/API/ApiHelper.cs b/ThunderstoreCLI/API/ApiHelper.cs index afd05ef..2c1f1fa 100644 --- a/ThunderstoreCLI/API/ApiHelper.cs +++ b/ThunderstoreCLI/API/ApiHelper.cs @@ -108,7 +108,7 @@ public HttpRequestMessage GetPackagesV1(string community) private static string SerializeFileData(string filePath) { - return new FileData() + return new FileData { Filename = Path.GetFileName(filePath), Filesize = new FileInfo(filePath).Length diff --git a/ThunderstoreCLI/Commands/BuildCommand.cs b/ThunderstoreCLI/Commands/BuildCommand.cs index 74aed9b..ba58a67 100644 --- a/ThunderstoreCLI/Commands/BuildCommand.cs +++ b/ThunderstoreCLI/Commands/BuildCommand.cs @@ -296,7 +296,7 @@ public static string SerializeManifest(Config config) var dependencies = config.PackageConfig.Dependencies ?? new Dictionary(); IEnumerable? installerDeclarations = config.InstallConfig.InstallerDeclarations; installerDeclarations ??= Array.Empty(); - var manifest = new PackageManifestV1() + var manifest = new PackageManifestV1 { Namespace = config.PackageConfig.Namespace, Name = config.PackageConfig.Name, diff --git a/ThunderstoreCLI/Commands/PublishCommand.cs b/ThunderstoreCLI/Commands/PublishCommand.cs index de07e9b..2b5e437 100644 --- a/ThunderstoreCLI/Commands/PublishCommand.cs +++ b/ThunderstoreCLI/Commands/PublishCommand.cs @@ -253,7 +253,7 @@ private static void PublishPackageRequest(Config config, string uploadUuid) throw new PublishCommandException(); } - return new CompletedUpload.CompletedPartData() + return new CompletedUpload.CompletedPartData { ETag = response.Headers.ETag.Tag, PartNumber = part.PartNumber diff --git a/ThunderstoreCLI/Configuration/CLIParameterConfig.cs b/ThunderstoreCLI/Configuration/CLIParameterConfig.cs index 759873e..1e39e6d 100644 --- a/ThunderstoreCLI/Configuration/CLIParameterConfig.cs +++ b/ThunderstoreCLI/Configuration/CLIParameterConfig.cs @@ -11,7 +11,7 @@ public BaseConfig(T options) public override GeneralConfig GetGeneralConfig() { - return new GeneralConfig() + return new GeneralConfig { TcliConfig = options.TcliDirectory, Repository = options.Repository @@ -29,7 +29,7 @@ public CLIParameterConfig(T opts) : base(opts) { } { if (options == null) return null; - return new PackageConfig() + return new PackageConfig { ProjectConfigPath = options.ConfigPath, Namespace = options.Namespace, @@ -45,7 +45,7 @@ public CLIInitCommandConfig(InitOptions options) : base(options) { } public override InitConfig GetInitConfig() { - return new InitConfig() + return new InitConfig { Overwrite = options.Overwrite }; @@ -63,7 +63,7 @@ public CLIPublishCommandConfig(PublishOptions options) : base(options) { } public override PublishConfig GetPublishConfig() { - return new PublishConfig() + return new PublishConfig { File = options.File }; @@ -71,7 +71,7 @@ public override PublishConfig GetPublishConfig() public override AuthConfig GetAuthConfig() { - return new AuthConfig() + return new AuthConfig { AuthToken = options.Token }; @@ -84,7 +84,7 @@ public ModManagementCommandConfig(ModManagementOptions options) : base(options) public override ModManagementConfig? GetModManagementConfig() { - return new ModManagementConfig() + return new ModManagementConfig { GameIdentifer = options.GameName, ProfileName = options.Profile, @@ -99,7 +99,7 @@ public GameImportCommandConfig(GameImportOptions options) : base(options) { } public override GameImportConfig? GetGameImportConfig() { - return new GameImportConfig() + return new GameImportConfig { ExePath = options.ExePath, GameId = options.GameId, @@ -113,7 +113,7 @@ public RunGameCommandConfig(RunGameOptions options) : base(options) { } public override RunGameConfig? GetRunGameConfig() { - return new RunGameConfig() + return new RunGameConfig { GameName = options.GameName, ProfileName = options.Profile, diff --git a/ThunderstoreCLI/Configuration/Config.cs b/ThunderstoreCLI/Configuration/Config.cs index cd3de93..ee4f0f5 100644 --- a/ThunderstoreCLI/Configuration/Config.cs +++ b/ThunderstoreCLI/Configuration/Config.cs @@ -100,7 +100,7 @@ public string GetBuildOutputFile() public PackageUploadMetadata GetUploadMetadata(string fileUuid) { - return new PackageUploadMetadata() + return new PackageUploadMetadata { AuthorName = PackageConfig.Namespace, Categories = PublishConfig.Categories!.GetOrDefault("") ?? Array.Empty(), diff --git a/ThunderstoreCLI/Configuration/DefaultConfig.cs b/ThunderstoreCLI/Configuration/DefaultConfig.cs index 575d79a..0d97b43 100644 --- a/ThunderstoreCLI/Configuration/DefaultConfig.cs +++ b/ThunderstoreCLI/Configuration/DefaultConfig.cs @@ -4,7 +4,7 @@ class DefaultConfig : EmptyConfig { public override GeneralConfig? GetGeneralConfig() { - return new GeneralConfig() + return new GeneralConfig { Repository = Defaults.REPOSITORY_URL }; @@ -12,7 +12,7 @@ class DefaultConfig : EmptyConfig public override PackageConfig GetPackageMeta() { - return new PackageConfig() + return new PackageConfig { ProjectConfigPath = Defaults.PROJECT_CONFIG_PATH, Namespace = "AuthorName", @@ -30,7 +30,7 @@ public override PackageConfig GetPackageMeta() public override InitConfig GetInitConfig() { - return new InitConfig() + return new InitConfig { Overwrite = false }; @@ -38,7 +38,7 @@ public override InitConfig GetInitConfig() public override BuildConfig GetBuildConfig() { - return new BuildConfig() + return new BuildConfig { IconPath = "./icon.png", ReadmePath = "./README.md", @@ -49,7 +49,7 @@ public override BuildConfig GetBuildConfig() public override PublishConfig GetPublishConfig() { - return new PublishConfig() + return new PublishConfig { File = null }; diff --git a/ThunderstoreCLI/Configuration/EnvironmentConfig.cs b/ThunderstoreCLI/Configuration/EnvironmentConfig.cs index 3d64dbf..e1d571e 100644 --- a/ThunderstoreCLI/Configuration/EnvironmentConfig.cs +++ b/ThunderstoreCLI/Configuration/EnvironmentConfig.cs @@ -8,7 +8,7 @@ class EnvironmentConfig : EmptyConfig public override AuthConfig GetAuthConfig() { - return new AuthConfig() + return new AuthConfig { AuthToken = ReadEnv(AUTH_TOKEN) }; diff --git a/ThunderstoreCLI/Configuration/ProjectFileConfig.cs b/ThunderstoreCLI/Configuration/ProjectFileConfig.cs index 4654f60..7112914 100644 --- a/ThunderstoreCLI/Configuration/ProjectFileConfig.cs +++ b/ThunderstoreCLI/Configuration/ProjectFileConfig.cs @@ -25,7 +25,7 @@ public override void Parse(Config currentConfig) public override GeneralConfig? GetGeneralConfig() { - return new GeneralConfig() + return new GeneralConfig { Repository = Project.Publish?.Repository! }; @@ -33,7 +33,7 @@ public override void Parse(Config currentConfig) public override PackageConfig? GetPackageMeta() { - return new PackageConfig() + return new PackageConfig { Namespace = Project.Package?.Namespace, Name = Project.Package?.Name, @@ -48,7 +48,7 @@ public override void Parse(Config currentConfig) public override BuildConfig? GetBuildConfig() { - return new BuildConfig() + return new BuildConfig { CopyPaths = Project.Build?.CopyPaths .Select(static path => new CopyPathMap(path.Source, path.Target)) @@ -61,7 +61,7 @@ public override void Parse(Config currentConfig) public override PublishConfig? GetPublishConfig() { - return new PublishConfig() + return new PublishConfig { Categories = Project.Publish?.Categories.Categories, Communities = Project.Publish?.Communities diff --git a/ThunderstoreCLI/Models/ThunderstoreProject.cs b/ThunderstoreCLI/Models/ThunderstoreProject.cs index 9953b6c..3d57cfb 100644 --- a/ThunderstoreCLI/Models/ThunderstoreProject.cs +++ b/ThunderstoreCLI/Models/ThunderstoreProject.cs @@ -143,12 +143,12 @@ public ThunderstoreProject(bool initialize) public ThunderstoreProject(Config config) { - Package = new PackageData() + Package = new PackageData { Namespace = config.PackageConfig.Namespace!, Name = config.PackageConfig.Name! }; - Build = new BuildData() + Build = new BuildData { Icon = config.GetPackageIconPath(), OutDir = config.GetBuildOutputDir(), @@ -157,13 +157,13 @@ public ThunderstoreProject(Config config) .Select(x => new BuildData.CopyPath { Source = x.From, Target = x.To }) .ToArray()! }; - Publish = new PublishData() + Publish = new PublishData { Categories = new CategoryDictionary { Categories = config.PublishConfig.Categories! }, Communities = config.PublishConfig.Communities!, Repository = config.GeneralConfig.Repository }; - Install = new InstallData() + Install = new InstallData { InstallerDeclarations = config.InstallConfig.InstallerDeclarations! .Select(x => new InstallData.InstallerDeclaration { Identifier = x.Identifier }) From cd9a6d1c74fc149d4f0859af80ee1c8384137976 Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Wed, 14 Feb 2024 18:50:31 +0000 Subject: [PATCH 18/24] remove redundant null-forgiving --- ThunderstoreCLI/Models/ThunderstoreProject.cs | 2 +- ThunderstoreCLI/Options.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ThunderstoreCLI/Models/ThunderstoreProject.cs b/ThunderstoreCLI/Models/ThunderstoreProject.cs index 3d57cfb..7117652 100644 --- a/ThunderstoreCLI/Models/ThunderstoreProject.cs +++ b/ThunderstoreCLI/Models/ThunderstoreProject.cs @@ -155,7 +155,7 @@ public ThunderstoreProject(Config config) Readme = config.GetPackageReadmePath(), CopyPaths = config.BuildConfig.CopyPaths! .Select(x => new BuildData.CopyPath { Source = x.From, Target = x.To }) - .ToArray()! + .ToArray() }; Publish = new PublishData { diff --git a/ThunderstoreCLI/Options.cs b/ThunderstoreCLI/Options.cs index 9a3a14f..f476bbe 100644 --- a/ThunderstoreCLI/Options.cs +++ b/ThunderstoreCLI/Options.cs @@ -30,7 +30,7 @@ public virtual bool Validate() { if (!Directory.Exists(TcliDirectory)) { - Directory.CreateDirectory(TcliDirectory!); + Directory.CreateDirectory(TcliDirectory); } return true; From 1b3bcb615d122499eef7ce14df0c1990b7cd140e Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Wed, 14 Feb 2024 18:51:20 +0000 Subject: [PATCH 19/24] remove inaccurate nullable return type annotations --- ThunderstoreCLI/Configuration/CLIParameterConfig.cs | 6 +++--- ThunderstoreCLI/Configuration/DefaultConfig.cs | 2 +- ThunderstoreCLI/Configuration/ProjectFileConfig.cs | 10 +++++----- ThunderstoreCLI/Models/BaseToml.cs | 2 +- ThunderstoreCLI/Utils/SteamUtils.cs | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ThunderstoreCLI/Configuration/CLIParameterConfig.cs b/ThunderstoreCLI/Configuration/CLIParameterConfig.cs index 1e39e6d..04d5750 100644 --- a/ThunderstoreCLI/Configuration/CLIParameterConfig.cs +++ b/ThunderstoreCLI/Configuration/CLIParameterConfig.cs @@ -82,7 +82,7 @@ public class ModManagementCommandConfig : BaseConfig { public ModManagementCommandConfig(ModManagementOptions options) : base(options) { } - public override ModManagementConfig? GetModManagementConfig() + public override ModManagementConfig GetModManagementConfig() { return new ModManagementConfig { @@ -97,7 +97,7 @@ public class GameImportCommandConfig : BaseConfig { public GameImportCommandConfig(GameImportOptions options) : base(options) { } - public override GameImportConfig? GetGameImportConfig() + public override GameImportConfig GetGameImportConfig() { return new GameImportConfig { @@ -111,7 +111,7 @@ public class RunGameCommandConfig : BaseConfig { public RunGameCommandConfig(RunGameOptions options) : base(options) { } - public override RunGameConfig? GetRunGameConfig() + public override RunGameConfig GetRunGameConfig() { return new RunGameConfig { diff --git a/ThunderstoreCLI/Configuration/DefaultConfig.cs b/ThunderstoreCLI/Configuration/DefaultConfig.cs index 0d97b43..87e0f79 100644 --- a/ThunderstoreCLI/Configuration/DefaultConfig.cs +++ b/ThunderstoreCLI/Configuration/DefaultConfig.cs @@ -2,7 +2,7 @@ namespace ThunderstoreCLI.Configuration; class DefaultConfig : EmptyConfig { - public override GeneralConfig? GetGeneralConfig() + public override GeneralConfig GetGeneralConfig() { return new GeneralConfig { diff --git a/ThunderstoreCLI/Configuration/ProjectFileConfig.cs b/ThunderstoreCLI/Configuration/ProjectFileConfig.cs index 7112914..872e634 100644 --- a/ThunderstoreCLI/Configuration/ProjectFileConfig.cs +++ b/ThunderstoreCLI/Configuration/ProjectFileConfig.cs @@ -23,7 +23,7 @@ public override void Parse(Config currentConfig) Project = ThunderstoreProject.Deserialize(File.ReadAllText(SourcePath))!; } - public override GeneralConfig? GetGeneralConfig() + public override GeneralConfig GetGeneralConfig() { return new GeneralConfig { @@ -31,7 +31,7 @@ public override void Parse(Config currentConfig) }; } - public override PackageConfig? GetPackageMeta() + public override PackageConfig GetPackageMeta() { return new PackageConfig { @@ -46,7 +46,7 @@ public override void Parse(Config currentConfig) }; } - public override BuildConfig? GetBuildConfig() + public override BuildConfig GetBuildConfig() { return new BuildConfig { @@ -59,7 +59,7 @@ public override void Parse(Config currentConfig) }; } - public override PublishConfig? GetPublishConfig() + public override PublishConfig GetPublishConfig() { return new PublishConfig { @@ -68,7 +68,7 @@ public override void Parse(Config currentConfig) }; } - public override InstallConfig? GetInstallConfig() + public override InstallConfig GetInstallConfig() { return new InstallConfig { diff --git a/ThunderstoreCLI/Models/BaseToml.cs b/ThunderstoreCLI/Models/BaseToml.cs index b69d16c..644e0ab 100644 --- a/ThunderstoreCLI/Models/BaseToml.cs +++ b/ThunderstoreCLI/Models/BaseToml.cs @@ -8,5 +8,5 @@ public abstract class BaseToml<[DynamicallyAccessedMembers(DynamicallyAccessedMe { public string Serialize() => TomletMain.TomlStringFrom(this); - public static T? Deserialize(string toml) => TomletMain.To(toml); + public static T Deserialize(string toml) => TomletMain.To(toml); } diff --git a/ThunderstoreCLI/Utils/SteamUtils.cs b/ThunderstoreCLI/Utils/SteamUtils.cs index 4114bea..990b468 100644 --- a/ThunderstoreCLI/Utils/SteamUtils.cs +++ b/ThunderstoreCLI/Utils/SteamUtils.cs @@ -153,7 +153,7 @@ public static bool IsProtonGame(string steamAppId) return Path.Combine(steamDir, "steamapps"); } - private static string? FindSteamDirectoryOsx() + private static string FindSteamDirectoryOsx() { return Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), From 9dddd68dd98c4464ab21e322a5d53a2c84e24891 Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Thu, 15 Feb 2024 03:37:55 +0000 Subject: [PATCH 20/24] add JsonIgnore attribute to computed FullName property --- ThunderstoreCLI/PackageManifestV1.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/ThunderstoreCLI/PackageManifestV1.cs b/ThunderstoreCLI/PackageManifestV1.cs index 2bf6189..858769a 100644 --- a/ThunderstoreCLI/PackageManifestV1.cs +++ b/ThunderstoreCLI/PackageManifestV1.cs @@ -27,6 +27,7 @@ public class PackageManifestV1 : BaseJson public InstallerDeclaration[]? Installers { get; set; } private string? fullName; + [JsonIgnore] public string FullName => fullName ??= $"{Namespace}-{Name}"; public class InstallerDeclaration From 05a142e36443ae08b4c6889150999de1d11dd99a Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Thu, 15 Feb 2024 04:08:35 +0000 Subject: [PATCH 21/24] extract MergeConfigFromProvider method --- ThunderstoreCLI/Configuration/Config.cs | 27 +++++++++++++++---------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/ThunderstoreCLI/Configuration/Config.cs b/ThunderstoreCLI/Configuration/Config.cs index ee4f0f5..c07e4cc 100644 --- a/ThunderstoreCLI/Configuration/Config.cs +++ b/ThunderstoreCLI/Configuration/Config.cs @@ -130,21 +130,26 @@ public static Config Parse(IConfigProvider[] configProviders) }; foreach (var provider in configProviders) { - provider.Parse(result); - Merge(result.GeneralConfig, provider.GetGeneralConfig(), false); - Merge(result.PackageConfig, provider.GetPackageMeta(), false); - Merge(result.InitConfig, provider.GetInitConfig(), false); - Merge(result.BuildConfig, provider.GetBuildConfig(), false); - Merge(result.PublishConfig, provider.GetPublishConfig(), false); - Merge(result.InstallConfig, provider.GetInstallConfig(), false); - Merge(result.AuthConfig, provider.GetAuthConfig(), false); - Merge(result.ModManagementConfig, provider.GetModManagementConfig(), false); - Merge(result.GameImportConfig, provider.GetGameImportConfig(), false); - Merge(result.RunGameConfig, provider.GetRunGameConfig(), false); + MergeConfigFromProvider(result, provider, false); } return result; } + public static void MergeConfigFromProvider(Config target, IConfigProvider provider, bool overwrite) + { + provider.Parse(target); + Merge(target.GeneralConfig, provider.GetGeneralConfig(), overwrite); + Merge(target.PackageConfig, provider.GetPackageMeta(), overwrite); + Merge(target.InitConfig, provider.GetInitConfig(), overwrite); + Merge(target.BuildConfig, provider.GetBuildConfig(), overwrite); + Merge(target.PublishConfig, provider.GetPublishConfig(), overwrite); + Merge(target.InstallConfig, provider.GetInstallConfig(), overwrite); + Merge(target.AuthConfig, provider.GetAuthConfig(), overwrite); + Merge(target.ModManagementConfig, provider.GetModManagementConfig(), overwrite); + Merge(target.GameImportConfig, provider.GetGameImportConfig(), overwrite); + Merge(target.RunGameConfig, provider.GetRunGameConfig(), overwrite); + } + public static void Merge<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(T target, T source, bool overwrite) { if (source == null) From 7010ed5fb7f9299dc5ccc3b1f453d60b28c6b382 Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Thu, 15 Feb 2024 04:39:36 +0000 Subject: [PATCH 22/24] add BlankConfig and DefaultConfig getters --- ThunderstoreCLI/Configuration/Config.cs | 34 +++++++++++++++---------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/ThunderstoreCLI/Configuration/Config.cs b/ThunderstoreCLI/Configuration/Config.cs index c07e4cc..d561891 100644 --- a/ThunderstoreCLI/Configuration/Config.cs +++ b/ThunderstoreCLI/Configuration/Config.cs @@ -31,6 +31,23 @@ private Config() api = new Lazy(() => new ApiHelper(this)); cache = new Lazy(() => new DownloadCache(Path.Combine(GeneralConfig!.TcliConfig, "ModCache"))); } + + private static Config BlankConfig => new() + { + GeneralConfig = new GeneralConfig(), + PackageConfig = new PackageConfig(), + InitConfig = new InitConfig(), + BuildConfig = new BuildConfig(), + PublishConfig = new PublishConfig(), + InstallConfig = new InstallConfig(), + AuthConfig = new AuthConfig(), + ModManagementConfig = new ModManagementConfig(), + GameImportConfig = new GameImportConfig(), + RunGameConfig = new RunGameConfig(), + }; + + public static Config DefaultConfig => MergeConfigFromProvider(BlankConfig, new DefaultConfig(), true); + public static Config FromCLI(IConfigProvider cliConfig) { List providers = new(); @@ -115,19 +132,7 @@ public PackageUploadMetadata GetUploadMetadata(string fileUuid) public static Config Parse(IConfigProvider[] configProviders) { - Config result = new() - { - GeneralConfig = new GeneralConfig(), - PackageConfig = new PackageConfig(), - InitConfig = new InitConfig(), - BuildConfig = new BuildConfig(), - PublishConfig = new PublishConfig(), - InstallConfig = new InstallConfig(), - AuthConfig = new AuthConfig(), - ModManagementConfig = new ModManagementConfig(), - GameImportConfig = new GameImportConfig(), - RunGameConfig = new RunGameConfig(), - }; + var result = BlankConfig; foreach (var provider in configProviders) { MergeConfigFromProvider(result, provider, false); @@ -135,7 +140,7 @@ public static Config Parse(IConfigProvider[] configProviders) return result; } - public static void MergeConfigFromProvider(Config target, IConfigProvider provider, bool overwrite) + public static Config MergeConfigFromProvider(Config target, IConfigProvider provider, bool overwrite) { provider.Parse(target); Merge(target.GeneralConfig, provider.GetGeneralConfig(), overwrite); @@ -148,6 +153,7 @@ public static void MergeConfigFromProvider(Config target, IConfigProvider provid Merge(target.ModManagementConfig, provider.GetModManagementConfig(), overwrite); Merge(target.GameImportConfig, provider.GetGameImportConfig(), overwrite); Merge(target.RunGameConfig, provider.GetRunGameConfig(), overwrite); + return target; } public static void Merge<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(T target, T source, bool overwrite) From db7ed25d8c40040fa7890c35a59941df246ab7a1 Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Thu, 15 Feb 2024 04:40:07 +0000 Subject: [PATCH 23/24] use default config for `tcli init` command --- ThunderstoreCLI/Commands/InitCommand.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ThunderstoreCLI/Commands/InitCommand.cs b/ThunderstoreCLI/Commands/InitCommand.cs index a63bb57..bdb5f21 100644 --- a/ThunderstoreCLI/Commands/InitCommand.cs +++ b/ThunderstoreCLI/Commands/InitCommand.cs @@ -38,7 +38,7 @@ public static int Run(Config config) { Write.Line($"Project configuration already exists, overwriting"); } - File.WriteAllText(path, new ThunderstoreProject(true).Serialize()); + File.WriteAllText(path, new ThunderstoreProject(Config.DefaultConfig).Serialize()); var iconPath = config.GetPackageIconPath(); if (File.Exists(iconPath)) From 20e6bcc6790f292e3666645fe23c8a96499303bc Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Thu, 15 Feb 2024 04:40:28 +0000 Subject: [PATCH 24/24] move default values out of ThunderstoreProject into DefaultConfig --- .../Configuration/DefaultConfig.cs | 10 +++- ThunderstoreCLI/Models/ThunderstoreProject.cs | 55 ++++++++++--------- 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/ThunderstoreCLI/Configuration/DefaultConfig.cs b/ThunderstoreCLI/Configuration/DefaultConfig.cs index 87e0f79..64cd744 100644 --- a/ThunderstoreCLI/Configuration/DefaultConfig.cs +++ b/ThunderstoreCLI/Configuration/DefaultConfig.cs @@ -19,11 +19,11 @@ public override PackageConfig GetPackageMeta() Name = "PackageName", VersionNumber = "0.0.1", Description = "Example mod description", - WebsiteUrl = "", + WebsiteUrl = "https://thunderstore.io", ContainsNsfwContent = false, Dependencies = new() { - { "Example-Dependency", "1.0.0" } + { "AuthorName-PackageName", "0.0.1" } } }; } @@ -51,7 +51,11 @@ public override PublishConfig GetPublishConfig() { return new PublishConfig { - File = null + File = null, + Communities = ["riskofrain2"], + Categories = new Dictionary { + { "riskofrain2", ["items", "skills", ] }, + } }; } diff --git a/ThunderstoreCLI/Models/ThunderstoreProject.cs b/ThunderstoreCLI/Models/ThunderstoreProject.cs index 7117652..f26e4b5 100644 --- a/ThunderstoreCLI/Models/ThunderstoreProject.cs +++ b/ThunderstoreCLI/Models/ThunderstoreProject.cs @@ -45,20 +45,21 @@ public class ConfigData public class PackageData { [TomlProperty("namespace")] - public string Namespace { get; set; } = "AuthorName"; + public string? Namespace { get; set; } [TomlProperty("name")] - public string Name { get; set; } = "PackageName"; + public string? Name { get; set; } [TomlProperty("versionNumber")] - public string VersionNumber { get; set; } = "0.0.1"; + public string? VersionNumber { get; set; } [TomlProperty("description")] - public string Description { get; set; } = "Example mod description"; + public string? Description { get; set; } [TomlProperty("websiteUrl")] - public string WebsiteUrl { get; set; } = "https://thunderstore.io"; + public string? WebsiteUrl { get; set; } [TomlProperty("containsNsfwContent")] public bool ContainsNsfwContent { get; set; } = false; + [TomlProperty("dependencies")] [TomlDoNotInlineObject] - public Dictionary Dependencies { get; set; } = new() { { "AuthorName-PackageName", "0.0.1" } }; + public Dictionary Dependencies { get; set; } = new(); } [TomlProperty("package")] public PackageData? Package { get; set; } @@ -67,23 +68,23 @@ public class PackageData public class BuildData { [TomlProperty("icon")] - public string Icon { get; set; } = "./icon.png"; + public string? Icon { get; set; } [TomlProperty("readme")] - public string Readme { get; set; } = "./README.md"; + public string? Readme { get; set; } [TomlProperty("outdir")] - public string OutDir { get; set; } = "./build"; + public string? OutDir { get; set; } [TomlDoNotInlineObject] public class CopyPath { [TomlProperty("source")] - public string Source { get; set; } = "./dist"; + public string? Source { get; set; } [TomlProperty("target")] - public string Target { get; set; } = ""; + public string? Target { get; set; } } [TomlProperty("copy")] - public CopyPath[] CopyPaths { get; set; } = new CopyPath[] { new CopyPath() }; + public CopyPath[] CopyPaths { get; set; } = Array.Empty(); } [TomlProperty("build")] public BuildData? Build { get; set; } @@ -92,21 +93,16 @@ public class CopyPath public class PublishData { [TomlProperty("repository")] - public string Repository { get; set; } = "https://thunderstore.io"; + public string? Repository { get; set; } + [TomlProperty("communities")] - public string[] Communities { get; set; } = - { - "riskofrain2" - }; + public string[] Communities { get; set; } = Array.Empty(); [TomlProperty("categories")] [TomlDoNotInlineObject] public CategoryDictionary Categories { get; set; } = new() { - Categories = new Dictionary - { - { "riskofrain2", new[] { "items", "skills" } } - } + Categories = new Dictionary(), }; } [TomlProperty("publish")] @@ -119,11 +115,11 @@ public class InstallData public class InstallerDeclaration { [TomlProperty("identifier")] - public string Identifier { get; set; } = "foo-installer"; + public string? Identifier { get; set; } } [TomlProperty("installers")] - public InstallerDeclaration[] InstallerDeclarations { get; set; } = new InstallerDeclaration[] { new InstallerDeclaration() }; + public InstallerDeclaration[] InstallerDeclarations { get; set; } = Array.Empty(); } [TomlProperty("install")] public InstallData? Install { get; set; } @@ -146,13 +142,18 @@ public ThunderstoreProject(Config config) Package = new PackageData { Namespace = config.PackageConfig.Namespace!, - Name = config.PackageConfig.Name! + Name = config.PackageConfig.Name!, + VersionNumber = config.PackageConfig.VersionNumber!, + Description = config.PackageConfig.Description!, + WebsiteUrl = config.PackageConfig.WebsiteUrl!, + ContainsNsfwContent = config.PackageConfig.ContainsNsfwContent.GetValueOrDefault(false), + Dependencies = config.PackageConfig.Dependencies! }; Build = new BuildData { - Icon = config.GetPackageIconPath(), - OutDir = config.GetBuildOutputDir(), - Readme = config.GetPackageReadmePath(), + Icon = config.BuildConfig.IconPath!, + OutDir = config.BuildConfig.OutDir!, + Readme = config.BuildConfig.ReadmePath!, CopyPaths = config.BuildConfig.CopyPaths! .Select(x => new BuildData.CopyPath { Source = x.From, Target = x.To }) .ToArray()