Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 3 additions & 39 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,7 @@ static async Task<int> MainAsync(string[] args)
Console.WriteLine(" --dialog-title Custom title for progress dialog");
Console.WriteLine(" --dialog-message Custom message for progress dialog");
Console.WriteLine(" --pipe <name> Named pipe for GUI output streaming");
Console.WriteLine(" --save-settings Save GUI settings to registry");
Console.WriteLine(" --save-settings-file <path> Save settings from JSON file to registry");
Console.WriteLine(" --save-settings Save settings to HKLM machine settings (administrator)");
Console.WriteLine(" --help Show this help message");
Console.WriteLine(" --version, -V Show version information");
Console.WriteLine(" --status Show current installation status");
Expand Down Expand Up @@ -624,12 +623,6 @@ static async Task<int> MainAsync(string[] args)
case "--save-settings":
return SaveSettingsFromArgs(args);

case "--save-settings-file":
if (i + 1 < args.Length)
return SaveSettingsFromFile(args[++i]);
Console.WriteLine("ERROR: --save-settings-file requires a file path");
return ExitFailure;

case "--headers":
// The GUI passes the authorization header this way. Consume the
// value - leaving it in place made the header string itself get
Expand Down Expand Up @@ -748,36 +741,7 @@ static async Task<int> MainAsync(string[] args)
}

/// <summary>
/// Saves settings from a JSON file. Called by the GUI app via elevated process.
/// </summary>
private static int SaveSettingsFromFile(string filePath)
{
try
{
var json = File.ReadAllText(filePath);
var config = System.Text.Json.JsonSerializer.Deserialize<BootstrapMateConfig>(json);
if (config is null)
{
Logger.Error("Failed to deserialize settings file.");
return 1;
}
ConfigManager.SaveUserSettings(config);
Logger.Info("Settings saved from file successfully.");
return 0;
}
catch (Exception ex)
{
Logger.Error($"Failed to save settings from file: {ex.Message}");
return 1;
}
finally
{
try { File.Delete(filePath); } catch { }
}
}

/// <summary>
/// Saves settings from CLI args to user registry. Called by the GUI app via elevated process.
/// Saves settings from CLI args to the HKLM machine settings key (requires administrator).
/// Expected format: --save-settings --url X --dialog-title Y ...
/// </summary>
private static int SaveSettingsFromArgs(string[] args)
Expand Down Expand Up @@ -818,7 +782,7 @@ private static int SaveSettingsFromArgs(string[] args)

try
{
ConfigManager.SaveUserSettings(config);
ConfigManager.SaveMachineSettings(config);
Logger.Info("Settings saved to registry successfully.");
return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Before building, set up your environment variables:

When a run completes, BootstrapMate can POST a vendor-neutral JSON run summary to an optional endpoint, turning "did this PC provision cleanly?" into a fleet-dashboard query. The payload is plain JSON and not tied to any specific backend — any service accepting a JSON POST (a custom collector, ReportMate, MunkiReport, etc.) can consume it. Both the Windows and macOS clients emit the same schema.

Configure via Intune CSP / Group Policy (the bundled ADMX), the machine/user registry, or both keys below:
Configure via Intune CSP / Group Policy (the bundled ADMX), the machine registry (`HKLM\SOFTWARE\BootstrapMate\Settings`), or both keys below:

| Key | Type | Effect |
|---|---|---|
Expand All @@ -50,7 +50,7 @@ The POST is best-effort: it is bounded by a short timeout and never fails the ru

Before any MSI or EXE installer is executed elevated, BootstrapMate verifies its Authenticode signature with `WinVerifyTrust`. A successful download only proves where the bytes came from — not who produced them. The signature gate ensures an installer carries a signature that chains to a trusted root (and, when configured, matches an expected publisher) before it runs as an elevated process.

Behaviour is controlled via Intune CSP / Group Policy (the bundled ADMX), the machine/user registry, or per-item manifest fields.
Behaviour is controlled via Intune CSP / Group Policy (the bundled ADMX), the machine registry, or per-item manifest fields.

Policy / registry keys (`HKLM\SOFTWARE\Policies\BootstrapMate` for policy; `HKLM\SOFTWARE\BootstrapMate\Settings` for machine settings):

Expand Down Expand Up @@ -743,7 +743,7 @@ Options:
--dialog-title <text> Custom progress dialog title
--dialog-message <text> Custom progress dialog message
--pipe <name> Named pipe for GUI output streaming
--save-settings Save GUI settings to the registry
--save-settings Save settings to the HKLM machine settings key (administrator)
--status Show current installation status
--clear-status Clear all installation status data
--clear-cache Clear caches, including failed installation files
Expand Down
7 changes: 5 additions & 2 deletions src/BootstrapMate.App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ public MainWindow()
// Apply Mica backdrop for modern Windows 11 look
SystemBackdrop = new MicaBackdrop();

// Select the first tab on launch
NavView.SelectedItem = NavView.MenuItems[0];
// Open on Prefs when asked to (the elevated relaunch from Unlock passes --prefs);
// Prefs is also the first tab, so this is the default either way.
NavView.SelectedItem = BootstrapMate.Core.PrefsElevation.OpensOnPrefs(Environment.GetCommandLineArgs().Skip(1))
? NavView.MenuItems.OfType<NavigationViewItem>().First(i => (string?)i.Tag == "prefs")
: NavView.MenuItems[0];
}

private void NavView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
Expand Down
82 changes: 79 additions & 3 deletions src/BootstrapMate.App/ViewModels/PrefsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ namespace BootstrapMate.App.ViewModels;

/// <summary>
/// ViewModel for the Prefs tab. Mirrors macOS SettingsViewModel.
/// Loads from ConfigManager, saves non-managed settings to the user registry (HKCU), shows management lock state.
/// Loads from ConfigManager and shows management lock state. Settings live in HKLM, so the tab is
/// read-only unless this process is elevated; Unlock relaunches the app elevated on this tab.
/// When elevated, non-managed settings auto-save to HKLM through ConfigManager.SaveMachineSettings.
/// </summary>
public partial class PrefsViewModel : ObservableObject
{
Expand Down Expand Up @@ -89,6 +91,67 @@ public double NetworkTimeoutValue

// ── Policy Lock Properties (for x:Bind) ─────────────────────

// ── Elevation State ─────────────────────────────────────────

/// <summary>True when this process can write HKLM (elevated administrator token).</summary>
public bool IsElevated { get; } = PrefsElevation.IsProcessElevated();

public bool IsReadOnly => !IsElevated;

[ObservableProperty] private string _unlockError = "";

public bool HasUnlockError => !string.IsNullOrEmpty(UnlockError);

partial void OnUnlockErrorChanged(string value) => OnPropertyChanged(nameof(HasUnlockError));

/// <summary>
/// Relaunches this app elevated through UAC, opening on the Prefs tab. Returns true when the
/// elevated instance started, so the caller can close this one. A cancelled UAC prompt
/// returns false quietly and leaves the tab read-only.
/// </summary>
public bool TryRelaunchElevated()
{
UnlockError = "";
try
{
var exe = Environment.ProcessPath;
if (string.IsNullOrEmpty(exe))
{
UnlockError = "Could not find the app's own executable to relaunch.";
return false;
}

using var process = System.Diagnostics.Process.Start(PrefsElevation.BuildElevatedRelaunch(exe));
return process is not null;
}
catch (Exception ex) when (PrefsElevation.IsElevationCancelled(ex))
{
return false;
}
catch (Exception ex)
{
UnlockError = $"Could not relaunch as administrator: {ex.Message}";
return false;
}
}

// ── Editability (elevated and not managed by policy) ────────

private bool CanEdit(string key) => PrefsElevation.CanEdit(IsElevated, _managedKeys.Contains(key));

public bool CanEditManifestUrl => CanEdit("ManifestUrl");
public bool CanEditAuthHeader => CanEdit("AuthorizationHeader");
public bool CanEditSilentMode => CanEdit("SilentMode");
public bool CanEditVerboseMode => CanEdit("VerboseMode");
public bool CanEditDryRun => CanEdit("DryRun");
public bool CanEditEnableDialog => CanEdit("EnableDialog");
public bool CanEditDialogTitle => CanEdit("DialogTitle");
public bool CanEditDialogMessage => CanEdit("DialogMessage");
public bool CanEditDialogIcon => CanEdit("DialogIcon");
public bool CanEditBlurScreen => CanEdit("BlurScreen");
public bool CanEditCustomInstallPath => CanEdit("CustomInstallPath");
public bool CanEditNetworkTimeout => CanEdit("NetworkTimeout");

public bool IsManifestUrlLocked => _managedKeys.Contains("ManifestUrl");
public bool IsAuthHeaderLocked => _managedKeys.Contains("AuthorizationHeader");
public bool IsSilentModeLocked => _managedKeys.Contains("SilentMode");
Expand Down Expand Up @@ -164,20 +227,22 @@ public void Load()
nameof(AuthPlaceholderText), nameof(NetworkTimeoutValue), nameof(VersionDisplay),
nameof(IsManifestPreviewLoading), nameof(ManifestPreviewContent), nameof(ManifestPreviewError),
nameof(HasManifestPreviewContent), nameof(HasManifestPreviewError),
nameof(UnlockError), nameof(HasUnlockError),
"", // string.Empty from Load's bulk notify
];

protected override void OnPropertyChanged(System.ComponentModel.PropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);

if (_isLoading || _nonSettingProperties.Contains(e.PropertyName ?? ""))
// Not elevated: HKLM is not writable and the tab is read-only, so never save.
if (_isLoading || !IsElevated || _nonSettingProperties.Contains(e.PropertyName ?? ""))
return;

_autoSaveTimer?.Dispose();
_autoSaveTimer = new System.Threading.Timer(_ =>
{
try { ConfigManager.SaveUserSettings(BuildConfig()); } catch { }
try { ConfigManager.SaveMachineSettings(BuildConfig(), PageKeys); } catch { }
}, null, 500, System.Threading.Timeout.Infinite);
}

Expand Down Expand Up @@ -223,6 +288,17 @@ public List<string> BuildRunArguments()

// ── Private ──────────────────────────────────────────────────

/// <summary>
/// The machine settings this tab edits. Saving writes only these, so values the tab does not
/// show (reporting, signature checks, baseline interval) keep whatever HKLM already holds.
/// </summary>
private static readonly string[] PageKeys =
[
"ManifestUrl", "AuthorizationHeader", "SilentMode", "VerboseMode", "DryRun",
"EnableDialog", "NoDialog", "DialogTitle", "DialogMessage", "DialogIcon", "BlurScreen",
"CustomInstallPath", "NetworkTimeout",
];

private BootstrapMateConfig BuildConfig() => new()
{
ManifestUrl = ManifestUrl,
Expand Down
Loading
Loading