Skip to content
Open
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
34 changes: 31 additions & 3 deletions src/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public async Task PrintDiffAsync(Configuration config)
_logger.LogError("\n[-] Items to Remove:");
foreach (var item in itemsToRemove)
{
_logger.LogError($" - {item}");
_logger.LogError($" - {FormatFriendlyName(item)}");
}
}

Expand All @@ -349,7 +349,7 @@ public async Task PrintDiffAsync(Configuration config)
_logger.LogSuccess("\n[+] Items to Add:");
foreach (var item in itemsToAdd)
{
_logger.LogSuccess($" + {item}");
_logger.LogSuccess($" + {FormatFriendlyName(item)}");
}
}

Expand All @@ -358,11 +358,39 @@ public async Task PrintDiffAsync(Configuration config)
_logger.LogInfo("\n[=] Unchanged Items:");
foreach (var item in unchangedItems)
{
_logger.LogInfo($" = {item}");
_logger.LogInfo($" = {FormatFriendlyName(item)}");
}
}
}

private string FormatFriendlyName(string item)
{
if (item.StartsWith("reg:"))
{
var parts = item.Substring(4).Split('|', 2);
if (parts.Length == 2)
{
string path = parts[0];
string name = parts[1];
string? settingKey = _systemSettings.GetFriendlyName(path, name);
if (settingKey != null)
{
return $"System Setting: {settingKey}";
}
return $"Registry Tweak: {path} -> {name}";
}
}
else
{
var parts = item.Split(':', 2);
if (parts.Length == 2)
{
return $"App ({parts[0]}): {parts[1]}";
}
}
return item;
}

private async Task<HashSet<string>> BuildStateFromConfig(Configuration config)
{
var state = new HashSet<string>();
Expand Down
1 change: 1 addition & 0 deletions src/Interfaces/ISystemSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public interface ISystemSettingsService
Task<IEnumerable<RegistryTweak>> GetTweaksAsync(Dictionary<string, object> settings);
Task ApplyNonRegistrySettingsAsync(Dictionary<string, object> settings, bool dryRun);
Task<Dictionary<string, object>> GetCapturedSettingsAsync();
string? GetFriendlyName(string registryPath, string registryName);
}
}
9 changes: 9 additions & 0 deletions src/Services/System/SystemSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ public async Task<Dictionary<string, object>> GetCapturedSettingsAsync()
});
}

public string? GetFriendlyName(string registryPath, string registryName)
{
var match = _catalog.FirstOrDefault(d =>
d.RegistryPath.Equals(registryPath, StringComparison.OrdinalIgnoreCase) &&
d.RegistryName.Equals(registryName, StringComparison.OrdinalIgnoreCase));

return match?.SettingKey;
}

public Task ApplyNonRegistrySettingsAsync(Dictionary<string, object> settings, bool dryRun)
{
if (settings == null) return Task.CompletedTask;
Expand Down
6 changes: 3 additions & 3 deletions tests/WinHome.Tests/EngineTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ public async Task PrintDiffAsync_ShouldPrintCorrectDiff()

// Assert
mockLogger.Verify(l => l.LogError(It.Is<string>(s => s.Contains("Items to Remove"))), Times.Once);
mockLogger.Verify(l => l.LogError(It.Is<string>(s => s.Contains("winget:OldApp"))), Times.Once);
mockLogger.Verify(l => l.LogError(It.Is<string>(s => s.Contains("App (winget): OldApp"))), Times.Once);
mockLogger.Verify(l => l.LogSuccess(It.Is<string>(s => s.Contains("Items to Add"))), Times.Once);
mockLogger.Verify(l => l.LogSuccess(It.Is<string>(s => s.Contains("winget:NewApp"))), Times.Once);
mockLogger.Verify(l => l.LogSuccess(It.Is<string>(s => s.Contains("App (winget): NewApp"))), Times.Once);
mockLogger.Verify(l => l.LogInfo(It.Is<string>(s => s.Contains("Unchanged Items"))), Times.Once);
mockLogger.Verify(l => l.LogInfo(It.Is<string>(s => s.Contains("winget:UnchangedApp"))), Times.Once);
mockLogger.Verify(l => l.LogInfo(It.Is<string>(s => s.Contains("App (winget): UnchangedApp"))), Times.Once);
}
}
}
Loading