Skip to content

Conversation

Copy link

Copilot AI commented Jan 12, 2026

LinuxStrategy and WindowsStrategy contained significant code duplication including identical helper methods and nearly identical main execution logic.

Changes

AbstractStrategy (base class)

  • Added CheckPath method previously duplicated in both derived classes

LinuxStrategy

  • Changed Execute() wrapper to direct ExecuteAsync() implementation to match WindowsStrategy and actual call sites in GeneralUpdateBootstrap
  • Removed duplicate CheckPath method
  • Fixed error messages incorrectly referencing "WindowsStrategy" class name

WindowsStrategy

  • Removed duplicate CheckPath method
  • Corrected error message to reference ExecuteAsync instead of Execute

Before/After

// Before: Duplicated in both classes
private string CheckPath(string path, string name)
{
    if (string.IsNullOrWhiteSpace(path) || string.IsNullOrWhiteSpace(name)) return string.Empty;
    var tempPath = Path.Combine(path, name);
    return File.Exists(tempPath) ? tempPath : string.Empty;
}

// After: Once in AbstractStrategy
protected static string CheckPath(string path, string name)
{
    if (string.IsNullOrWhiteSpace(path) || string.IsNullOrWhiteSpace(name)) return string.Empty;
    var tempPath = Path.Combine(path, name);
    return File.Exists(tempPath) ? tempPath : string.Empty;
}
// Before: LinuxStrategy wrapping async in Task.Run
public override void Execute()
{
    Task.Run(async () => { /* async logic */ });
}

// After: Direct async implementation matching WindowsStrategy
public override async Task ExecuteAsync()
{
    /* async logic */
}

Platform-specific behavior (Linux script execution, Windows Bowl app launching) remains unchanged.

Note: ExecuteAsync methods remain identical in both classes. Further extraction would require relocating pipeline/event dependencies to Common assembly.

Original prompt

This section details on the original issue you should resolve

<issue_title>[REFACTOR] Refactor Strategy</issue_title>
<issue_description>### Target Module/File

GeneralUpdate.Core/Strategys/LinuxStrategy.cs and WindowsStrategy.cs

Current Code Problems

In GeneralUpdate.Core, LinuxStrategy and WindowsStrategy share a lot of similar code.

Refactoring Objectives

It is necessary to optimize the duplicate code without changing the original functionality.

Refactoring Scope and Boundaries

Only refactor in the GeneralUpdate.Core.

Risk Assessment

No response

Reference Materials

No response

Expected Completion Time

No response</issue_description>

<agent_instructions>Perform code refactoring in accordance with the content specified in the issue.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor Linux and Windows strategy to optimize duplicate code Refactor LinuxStrategy and WindowsStrategy to eliminate duplicate code Jan 12, 2026
Copilot AI requested a review from JusterZhu January 12, 2026 04:19
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.

[REFACTOR] Refactor Strategy

2 participants