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
22 changes: 14 additions & 8 deletions src/c#/GeneralUpdate.Core/Bootstrap/GeneralUpdateBootstrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,6 @@ private void InitializeFromEnvironment()
var processInfo = new EncryptedFileProcessInfoProvider().Receive();
if (processInfo == null) return;

BlackListManager.Instance.AddBlackFormats(processInfo.BlackFileFormats);
BlackListManager.Instance.AddBlackFiles(processInfo.BlackFiles);
BlackListManager.Instance.AddSkipDirectorys(processInfo.SkipDirectorys);

_configInfo = new GlobalConfigInfo
{
MainAppName = processInfo.AppName,
Expand All @@ -282,8 +278,13 @@ private void InitializeFromEnvironment()
BackupDirectory = processInfo.BackupDirectory,
Scheme = processInfo.Scheme,
Token = processInfo.Token,
DriverDirectory = processInfo.DriverDirectory
DriverDirectory = processInfo.DriverDirectory,
BlackFiles = processInfo.BlackFiles ?? BlackListDefaults.DefaultBlackFiles,
BlackFormats = processInfo.BlackFileFormats ?? BlackListDefaults.DefaultBlackFormats,
SkipDirectorys = processInfo.SkipDirectorys ?? BlackListDefaults.DefaultSkipDirectories
Comment on lines +282 to +284
};

StorageManager.BlackListMatcher = DefaultBlackListMatcher.FromConfigInfo(_configInfo);
}

/// <summary>
Expand Down Expand Up @@ -350,9 +351,14 @@ private async Task LaunchSilentAsync()

private void InitBlackList()
{
BlackListManager.Instance.AddBlackFiles(_configInfo.BlackFiles);
BlackListManager.Instance.AddBlackFormats(_configInfo.BlackFormats);
BlackListManager.Instance.AddSkipDirectorys(_configInfo.SkipDirectorys);
// Build blacklist matcher from GlobalConfigInfo and set on StorageManager.
// The matcher combines user config with system defaults.
var effectiveConfig = new BlackListConfig(
_configInfo.BlackFiles?.Count > 0 ? _configInfo.BlackFiles : BlackListDefaults.DefaultBlackFiles,
_configInfo.BlackFormats?.Count > 0 ? _configInfo.BlackFormats : BlackListDefaults.DefaultBlackFormats,
_configInfo.SkipDirectorys?.Count > 0 ? _configInfo.SkipDirectorys : BlackListDefaults.DefaultSkipDirectories
);
StorageManager.BlackListMatcher = new DefaultBlackListMatcher(effectiveConfig);
}

private async Task CallSmallBowlHomeAsync(string processName)
Expand Down
25 changes: 25 additions & 0 deletions src/c#/GeneralUpdate.Core/FileSystem/BlackListDefaults.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Collections.Generic;

namespace GeneralUpdate.Core.FileSystem;

/// <summary>Built-in default blacklist items — previously hardcoded in BlackListManager.</summary>
public static class BlackListDefaults
{
/// <summary>Default blacklisted files (system DLLs that ship with the runtime).</summary>
public static readonly List<string> DefaultBlackFiles = new()
{
"Microsoft.Bcl.AsyncInterfaces.dll",
"System.Collections.Immutable.dll",
"System.IO.Pipelines.dll",
"System.Text.Encodings.Web.dll",
"System.Text.Json.dll"
};

/// <summary>Default blacklisted file extensions.</summary>
public static readonly List<string> DefaultBlackFormats = new()
{ ".patch", ".pdb", ".rar", ".tar", ".json", Configuration.Format.ZIP };

/// <summary>Default skipped directory prefixes.</summary>
public static readonly List<string> DefaultSkipDirectories = new()
{ "app-", "fail" };
Comment on lines +9 to +24
}
3 changes: 2 additions & 1 deletion src/c#/GeneralUpdate.Core/FileSystem/BlackListManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ public interface IBlackListMatcher
}

/// <summary>
/// Thread-safe blacklist manager. Uses Lazy<T> singleton.
/// Thread-safe blacklist manager. Uses Lazy&lt;T&gt; singleton.
/// Matching is case-insensitive and supports prefix matching for skip directories.
/// </summary>
[Obsolete("Use DefaultBlackListMatcher + StorageManager.BlackListMatcher instead. See #412.")]
public class BlackListManager : IBlackListMatcher
{
private static readonly Lazy<BlackListManager> _lazy = new(() => new BlackListManager());
Expand Down
10 changes: 10 additions & 0 deletions src/c#/GeneralUpdate.Core/FileSystem/DefaultBlackListMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ public class DefaultBlackListMatcher : IBlackListMatcher
public DefaultBlackListMatcher(BlackListConfig config)
=> _config = config ?? throw new ArgumentNullException(nameof(config));

/// <summary>Create a matcher from GlobalConfigInfo blacklist properties.</summary>
public static DefaultBlackListMatcher FromConfigInfo(GlobalConfigInfo config)
{
var cfg = new BlackListConfig(
config.BlackFiles?.Count > 0 ? config.BlackFiles : null,
config.BlackFormats?.Count > 0 ? config.BlackFormats : null,
config.SkipDirectorys?.Count > 0 ? config.SkipDirectorys : null);
Comment on lines +19 to +22
return new DefaultBlackListMatcher(cfg);
}

public bool IsBlacklisted(string relativeFilePath)
{
var fileName = Path.GetFileName(relativeFilePath);
Expand Down
11 changes: 9 additions & 2 deletions src/c#/GeneralUpdate.Core/FileSystem/StorageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
{
private long _fileCount = 0;
public const string DirectoryName = "app-";

/// <summary>Optional blacklist matcher. When set, takes precedence over BlackListManager.</summary>
public static IBlackListMatcher? BlackListMatcher { get; set; }

private ComparisonResult ComparisonResult { get; set; }

Expand Down Expand Up @@ -252,7 +255,7 @@
/// <summary>
/// Recursively read all files in the folder path.
/// </summary>
private IEnumerable<FileNode> ReadFileNode(string path, string rootPath = null)

Check warning on line 258 in src/c#/GeneralUpdate.Core/FileSystem/StorageManager.cs

View workflow job for this annotation

GitHub Actions / build-and-test (windows-latest)

Cannot convert null literal to non-nullable reference type.

Check warning on line 258 in src/c#/GeneralUpdate.Core/FileSystem/StorageManager.cs

View workflow job for this annotation

GitHub Actions / build-and-test (ubuntu-latest)

Cannot convert null literal to non-nullable reference type.
{
var resultFiles = new List<FileNode>();
rootPath ??= path;
Expand All @@ -264,7 +267,9 @@

foreach (var subPath in Directory.EnumerateFiles(path))
{
if (BlackListManager.Instance.IsBlacklisted(subPath)) continue;
#pragma warning disable CS0618 // Obsolete fallback
if ((BlackListMatcher ?? BlackListManager.Instance).IsBlacklisted(subPath)) continue;
#pragma warning restore CS0618

var hashAlgorithm = new Sha256HashAlgorithm();
var hash = hashAlgorithm.ComputeHash(subPath);
Expand All @@ -283,7 +288,9 @@

foreach (var subPath in Directory.EnumerateDirectories(path))
{
if (BlackListManager.Instance.ShouldSkipDirectory(subPath)) continue;
#pragma warning disable CS0618 // Obsolete fallback
if ((BlackListMatcher ?? BlackListManager.Instance).ShouldSkipDirectory(subPath)) continue;
#pragma warning restore CS0618
resultFiles.AddRange(ReadFileNode(subPath, rootPath));
}

Expand Down
19 changes: 11 additions & 8 deletions src/c#/GeneralUpdate.Core/Silent/SilentPollOrchestrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,13 @@ private async Task PrepareUpdateIfNeededAsync(CancellationToken token)
catch (Exception ex) { GeneralTracer.Warn($"Hook OnBeforeUpdateAsync failed: {ex.Message}"); }
}

// Configure for update
BlackListManager.Instance?.AddBlackFiles(_configInfo.BlackFiles);
BlackListManager.Instance?.AddBlackFormats(_configInfo.BlackFormats);
BlackListManager.Instance?.AddSkipDirectorys(_configInfo.SkipDirectorys);
// Configure matcher from config with defaults
var effectiveConfig = new BlackListConfig(
_configInfo.BlackFiles?.Count > 0 ? _configInfo.BlackFiles : BlackListDefaults.DefaultBlackFiles,
_configInfo.BlackFormats?.Count > 0 ? _configInfo.BlackFormats : BlackListDefaults.DefaultBlackFormats,
_configInfo.SkipDirectorys?.Count > 0 ? _configInfo.SkipDirectorys : BlackListDefaults.DefaultSkipDirectories
);
StorageManager.BlackListMatcher = new DefaultBlackListMatcher(effectiveConfig);

_configInfo.LastVersion = latestVersion;
_configInfo.UpdateVersions = new List<VersionInfo>(); // legacy compat
Expand All @@ -160,14 +163,14 @@ private async Task PrepareUpdateIfNeededAsync(CancellationToken token)

// Backup
StorageManager.Backup(_configInfo.InstallPath, _configInfo.BackupDirectory,
BlackListManager.Instance.SkipDirectorys);
_configInfo.SkipDirectorys ?? BlackListDefaults.DefaultSkipDirectories);

Comment on lines 164 to 167
// Build ProcessInfo and store for IPC delivery on process exit
_preparedProcessInfo = ConfigurationMapper.MapToProcessInfo(
_configInfo, new List<VersionInfo>(),
BlackListManager.Instance.BlackFormats.ToList(),
BlackListManager.Instance.BlackFiles.ToList(),
BlackListManager.Instance.SkipDirectorys.ToList());
_configInfo.BlackFormats ?? BlackListDefaults.DefaultBlackFormats,
_configInfo.BlackFiles ?? BlackListDefaults.DefaultBlackFiles,
_configInfo.SkipDirectorys ?? BlackListDefaults.DefaultSkipDirectories);
Comment on lines 169 to +173
_configInfo.ProcessInfo = JsonSerializer.Serialize(_preparedProcessInfo, ProcessInfoJsonContext.Default.ProcessInfo);

// ═══ Reporter: update started ═══
Expand Down
17 changes: 10 additions & 7 deletions src/c#/GeneralUpdate.Core/Strategy/ClientUpdateStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ private async Task ExecuteStandardWorkflowAsync()

var processInfo = ConfigurationMapper.MapToProcessInfo(
_configInfo, downloadVersions,
BlackListManager.Instance.BlackFormats.ToList(),
BlackListManager.Instance.BlackFiles.ToList(),
BlackListManager.Instance.SkipDirectorys.ToList());
_configInfo.BlackFormats ?? BlackListDefaults.DefaultBlackFormats,
_configInfo.BlackFiles ?? BlackListDefaults.DefaultBlackFiles,
_configInfo.SkipDirectorys ?? BlackListDefaults.DefaultSkipDirectories);
Comment on lines 174 to +178

// Keep JSON string for backward compatibility (GlobalConfigInfo.ProcessInfo)
_configInfo.ProcessInfo = JsonSerializer.Serialize(processInfo,
Expand Down Expand Up @@ -243,16 +243,19 @@ private static IStrategy ResolveOsStrategy()

private void InitBlackList()
{
BlackListManager.Instance.AddBlackFiles(_configInfo!.BlackFiles);
BlackListManager.Instance.AddBlackFormats(_configInfo.BlackFormats);
BlackListManager.Instance.AddSkipDirectorys(_configInfo.SkipDirectorys);
var effectiveConfig = new BlackListConfig(
_configInfo!.BlackFiles?.Count > 0 ? _configInfo.BlackFiles : BlackListDefaults.DefaultBlackFiles,
_configInfo.BlackFormats?.Count > 0 ? _configInfo.BlackFormats : BlackListDefaults.DefaultBlackFormats,
_configInfo.SkipDirectorys?.Count > 0 ? _configInfo.SkipDirectorys : BlackListDefaults.DefaultSkipDirectories
);
StorageManager.BlackListMatcher = new DefaultBlackListMatcher(effectiveConfig);
}

private void Backup()
{
GeneralTracer.Info($"ClientUpdateStrategy: backing up {_configInfo!.InstallPath} -> {_configInfo.BackupDirectory}");
StorageManager.Backup(_configInfo.InstallPath, _configInfo.BackupDirectory,
BlackListManager.Instance.SkipDirectorys);
_configInfo.SkipDirectorys ?? BlackListDefaults.DefaultSkipDirectories);
Comment on lines 256 to +258
}

private bool CanSkip(bool isForcibly, UpdateInfoEventArgs updateInfo)
Expand Down
Loading