Skip to content

Commit

Permalink
Store raw config values to allow resetting back to default values
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianeicher committed May 2, 2024
1 parent 4769ec4 commit 5f32d82
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
42 changes: 27 additions & 15 deletions src/BootstrapCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Globalization;
using IniParser;
using IniParser.Model;
using NanoByte.Common;
using NanoByte.Common.Info;
using NanoByte.Common.Storage;
Expand Down Expand Up @@ -80,7 +81,7 @@ public BootstrapCommand(IEnumerable<string> args, ITaskHandler handler)
private int? _estimatedRequiredSpace;

/// <summary>Set Zero Install configuration options. Only overrides existing config files if Zero Install is not already deployed.</summary>
private readonly Config _config = new();
private readonly KeyDataCollection _config = new();

/// <summary>A directory containing additional content to be embedded in the bootstrapper.</summary>
private DirectoryInfo? _contentDir;
Expand Down Expand Up @@ -112,7 +113,12 @@ private OptionSet BuildOptions()
_estimatedRequiredSpace = x;
}
},
{"c|config==", () => Resources.OptionConfig, (key, value) => _config.SetOption(key, value) },
{"c|config==", () => Resources.OptionConfig, (key, value) =>
{
new Config().SetOption(key, value); // Ensure key-value combination is valid
_config[key] = value; // Store raw input to allow resetting back to default values
}
},
{"content=", () => Resources.OptionContent, x => _contentDir = new(x)},
{"template=", () => Resources.OptionTemplate, (Uri x) => _template = x}
};
Expand Down Expand Up @@ -176,22 +182,28 @@ private Uri GetDefaultTemplate(bool needsTerminal)

private Stream BuildBootstrapConfig(Feed feed, string? keyFingerprint, bool customSplashScreen)
{
var iniData = _config.ToIniData();
iniData.Sections.Add(new("bootstrap")
var iniData = new IniData
{
Keys =
Sections =
{
["key_fingerprint"] = keyFingerprint ?? "",
["app_uri"] = _feedUri.ToStringRfc(),
["app_name"] = feed.Name,
["app_args"] = _appArgs ?? "",
["integrate_args"] = _integrateArgs ?? "",
["catalog_uri"] = _catalogUri?.ToStringRfc() ?? "",
["show_app_name_below_splash_screen"] = (!customSplashScreen).ToString().ToLowerInvariant(),
["customizable_store_path"] = _customizableStorePath.ToString().ToLowerInvariant(),
["estimated_required_space"] = _estimatedRequiredSpace?.ToString(CultureInfo.InvariantCulture) ?? ""
new("global") {Keys = _config},
new("bootstrap")
{
Keys =
{
["key_fingerprint"] = keyFingerprint ?? "",
["app_uri"] = _feedUri.ToStringRfc(),
["app_name"] = feed.Name,
["app_args"] = _appArgs ?? "",
["integrate_args"] = _integrateArgs ?? "",
["catalog_uri"] = _catalogUri?.ToStringRfc() ?? "",
["show_app_name_below_splash_screen"] = (!customSplashScreen).ToString().ToLowerInvariant(),
["customizable_store_path"] = _customizableStorePath.ToString().ToLowerInvariant(),
["estimated_required_space"] = _estimatedRequiredSpace?.ToString(CultureInfo.InvariantCulture) ?? ""
}
}
}
});
};

var stream = new MemoryStream();
using (var writer = new StreamWriter(stream, EncodingUtils.Utf8, bufferSize: 1024, leaveOpen: true))
Expand Down
2 changes: 1 addition & 1 deletion test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pushd $PSScriptRoot
if (Test-path test.exe) {rm test.exe}

# Build bootstrapper
.\0install.ps1 run --batch 0bootstrap-dotnet-$Version.xml https://apps.0install.net/utils/jq.xml test.exe
.\0install.ps1 run --batch 0bootstrap-dotnet-$Version.xml https://apps.0install.net/utils/jq.xml test.exe --config=help_with_testing=true
if (!(Test-path test.exe)) {throw "Failed to generate bootstrapper"}

# Run bootstrapper
Expand Down

0 comments on commit 5f32d82

Please sign in to comment.