Skip to content

refactor: remove dead code and fix bugs in GeneralUpdate.Core#405

Merged
JusterZhu merged 5 commits into
masterfrom
fix/code-cleanup-dead-code-and-bugs
May 25, 2026
Merged

refactor: remove dead code and fix bugs in GeneralUpdate.Core#405
JusterZhu merged 5 commits into
masterfrom
fix/code-cleanup-dead-code-and-bugs

Conversation

@JusterZhu
Copy link
Copy Markdown
Collaborator

Closes #404

Summary

Systematic code review and cleanup — 22 files changed, +106/-292 lines. Build: 0 errors, 0 warnings.

Bug Fixes (7)

  • WindowsStrategy/MacStrategy Execute() missing or broken overrides
  • DownloadProgressReporter all-completed event now fires once after all downloads (was per-asset)
  • StorageManager GetAllfiles returns empty list instead of null (prevents NRE)
  • FileNode GetHashCode fixed to respect Equals contract
  • ObjectTranslator safe pattern-match cast (was unsafe)
  • Fixed typo IsComplated -> IsCompleted

Dead Code Removed (9)

  • FileTreeCore duplicate types, IEventManager interface
  • Unused fields: _diffMode, _script, _compressionStrategy, _hooks/_reporter
  • Empty InfixOrder methods, duplicate DriverDirectory property, dead private ctor

Deduplication (3)

  • Extracted StreamDownloadAsync() shared download loop
  • Added Hooks/Reporter properties to AbstractStrategy base class
  • Wired _customSkipOption into bootstrap execution flow

JusterZhu added 3 commits May 25, 2026 15:21
…ethods

- Remove #define AOT constant and SignalR Compile Remove entries from csproj
- Remove Condition on SignalR.Client PackageReference for AOT builds
- Remove #if !AOT blocks in GeneralUpdateBootstrap.cs (HubDownloadSource + LaunchSilentAsync)
- Delete deprecated abstract/override methods (ExecuteStrategy, ExecuteStrategyAsync, StrategyFactory)

Closes #402
- Add PacketDTO to HttpParameterJsonContext for source-generated AOT deserialization
- Replace reflection-based Deserialize<PacketDTO> with source-gen version in HubDownloadSource
- Remove try/catch in UpgradeHubService.StartAsync so hub connection failures propagate
- Fix WindowsStrategy/MacStrategy Execute() missing or broken overrides
- Fix DownloadProgressReporter all-completed event firing prematurely
- Fix StorageManager GetAllfiles null return causing NRE
- Fix FileNode GetHashCode violating Equals contract
- Fix ObjectTranslator unsafe cast, IsComplated typo
- Delete unused FileTreeCore duplicate types, IEventManager interface
- Remove dead fields: _diffMode, _script, _compressionStrategy, _hooks/_reporter
- Remove empty InfixOrder methods, duplicate DriverDirectory, dead ctor
- Extract shared StreamDownloadAsync to eliminate download loop duplication
- Wire _customSkipOption into bootstrap execution flow
- Clean stale XML doc params

Closes #404
Copilot AI review requested due to automatic review settings May 25, 2026 08:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR performs a cleanup/refactor of GeneralUpdate.Core by removing unused/dead code, deduplicating download logic, and addressing several correctness issues in strategies, download progress/events, hashing, and configuration.

Changes:

  • Fixed strategy execution paths (Windows/macOS) and hardened a few runtime behaviors (e.g., StorageManager.GetAllfiles, safer ObjectTranslator cast).
  • Refactored multi-download completion signaling so the “all completed” event is dispatched once after orchestration completes, and deduplicated stream download loops.
  • Removed dead/duplicate code and unused members across configuration, filesystem, events, and bootstrap layers.

Reviewed changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/c#/GeneralUpdate.Core/Strategy/WindowsStrategy.cs Adds missing Execute() override to run the async pipeline synchronously.
src/c#/GeneralUpdate.Core/Strategy/MacStrategy.cs Simplifies Execute() to delegate to ExecuteAsync().
src/c#/GeneralUpdate.Core/Strategy/ClientUpdateStrategy.cs Removes unused diff-mode field.
src/c#/GeneralUpdate.Core/Strategy/AbstractStrategy.cs Introduces optional Hooks/Reporter fields for strategy subclasses.
src/c#/GeneralUpdate.Core/Silent/SilentPollOrchestrator.cs Removes now-unused hooks/reporter injection API.
src/c#/GeneralUpdate.Core/Network/VersionService.cs Removes unused private constructor.
src/c#/GeneralUpdate.Core/JsonContext/HttpParameterJsonContext.cs Extends source-gen JSON context to include PacketDTO types.
src/c#/GeneralUpdate.Core/Hubs/UpgradeHubService.cs Simplifies StartAsync() logging/flow (exception now propagates).
src/c#/GeneralUpdate.Core/GeneralUpdate.Core.csproj Adjusts package/compile conditions (removes AOT-specific exclusions).
src/c#/GeneralUpdate.Core/FileSystem/StorageManager.cs Returns empty list instead of null from GetAllfiles() on exception.
src/c#/GeneralUpdate.Core/FileSystem/FileTreeCore/FileTreeEnumerator.cs Removes duplicate/unused file tree enumerator and related types.
src/c#/GeneralUpdate.Core/FileSystem/FileTree.cs Removes unused traversal method.
src/c#/GeneralUpdate.Core/FileSystem/FileNode.cs Updates GetHashCode() implementation to align with equality intent.
src/c#/GeneralUpdate.Core/Event/IEventManager.cs Removes unused event manager interface.
src/c#/GeneralUpdate.Core/Download/Sources/HubDownloadSource.cs Switches to source-generated JSON deserialization for packets.
src/c#/GeneralUpdate.Core/Download/Progress/DownloadProgressReporter.cs Removes per-asset “all completed” behavior and adds a static dispatcher.
src/c#/GeneralUpdate.Core/Download/Orchestrators/DefaultDownloadOrchestrator.cs Dispatches “all completed” once after WhenAll() completes.
src/c#/GeneralUpdate.Core/Download/MultiEventArgs/MutiDownloadCompletedEventArgs.cs Renames completion flag parameter/property (but currently inconsistent).
src/c#/GeneralUpdate.Core/Download/Executors/OssDownloadExecutor.cs Uses shared stream download loop helper.
src/c#/GeneralUpdate.Core/Download/Executors/HttpDownloadExecutor.cs Extracts shared StreamDownloadAsync() loop.
src/c#/GeneralUpdate.Core/Configuration/ProcessInfo.cs Removes stale XML doc parameter reference.
src/c#/GeneralUpdate.Core/Configuration/ObjectTranslator.cs Makes packet hash extraction safe via pattern matching.
src/c#/GeneralUpdate.Core/Configuration/GlobalConfigInfo.cs Removes redundant/hiding DriverDirectory property.
src/c#/GeneralUpdate.Core/Configuration/ConfiginfoBuilder.cs Removes unused script field and builder method.
src/c#/GeneralUpdate.Core/Configuration/AbstractBootstrap.cs Removes protected abstract members from base class API.
src/c#/GeneralUpdate.Core/Compress/CompressProvider.cs Removes static strategy field; uses local strategy instance.
src/c#/GeneralUpdate.Core/Bootstrap/GeneralUpdateBootstrap.cs Wires custom skip option into execution; removes AOT preprocessor guards and dead overrides.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 48 to 54
public static void DispatchAllCompleted(bool success, List<(object, string)> details)
{
EventManager.Instance.Dispatch(null!,
new MultiAllDownloadCompletedEventArgs(success, details ?? new List<(object, string)>()));
}

/// <summary>
sw.Stop();

// Dispatch all-completed event ONCE after all assets finish
var details = results.Select(r => ((object)r.Url, r.Success ? "success" : r.ErrorMessage ?? "failed")).ToList();
}

public override int GetHashCode() => base.GetHashCode();
public override int GetHashCode() => (Name?.GetHashCode() ?? 0) ^ (Hash?.GetHashCode() ?? 0);
public object Version { get; private set; } = version;

public bool IsComplated { get; private set; } = isComplated;
public bool isCompleted { get; private set; } = isCompleted;
Comment on lines 26 to 30
}

public abstract Task<TBootstrap> LaunchAsync();
protected abstract void ExecuteStrategy();
protected abstract Task ExecuteStrategyAsync();
protected abstract TBootstrap StrategyFactory();

public TBootstrap Option<T>(UpdateOption<T> option, T value)
JusterZhu added 2 commits May 25, 2026 17:05
Previously hooks and reporter were injected into SilentPollOrchestrator
but never actually used. This commit completes the integration:

- Hooks.OnBeforeUpdateAsync() called before download (allows cancellation)
- Hooks.OnDownloadCompletedAsync() called after successful download
- Hooks.OnAfterUpdateAsync() called after pipeline completes
- Hooks.OnUpdateErrorAsync() called on download or pipeline failures
- Reporter reports: UpdateStarted, DownloadCompleted, UpdateApplied, UpdateFailed
- Hooks & reporter calls are wrapped in try/catch so they never break the flow

Closes #404
- Fix MutiDownloadCompletedEventArgs.IsCompleted PascalCase (was isCompleted)
- Fix EventListenerTests to use IsCompleted instead of IsComplated
- Fix DispatchAllCompleted to accept sender param (was passing null)
- Fix DefaultDownloadOrchestrator to filter only failed results for FailedVersions
- Fix FileNode.GetHashCode to use OrdinalIgnoreCase (match Equals contract)
@JusterZhu JusterZhu merged commit 98df906 into master May 25, 2026
3 checks passed
@JusterZhu JusterZhu deleted the fix/code-cleanup-dead-code-and-bugs branch May 25, 2026 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code cleanup: remove dead code and fix bugs in GeneralUpdate.Core

2 participants