Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 19, 2026

The GeneralClientBootstrap.SetConfig() and GeneralUpdateBootstrap.SetConfig() methods manually mapped fields from Configinfo to GlobalConfigInfo, and later created ProcessInfo with 19 parameters. Each new field required error-prone updates across three classes and multiple mapping locations in both ClientCore and Core projects.

Changes

Introduced BaseConfigInfo abstract class

  • Consolidates 14 shared fields (AppName, InstallPath, AppSecretKey, BlackFiles, etc.)
  • Eliminates triple-definition of common configuration properties

Introduced ConfigurationMapper utility

  • MapToGlobalConfigInfo() - replaces manual field-by-field assignment in SetConfig()
  • MapToProcessInfo() - replaces 19-parameter constructor call with structured mapping
  • Centralizes all configuration object transformations

Updated inheritance hierarchy

  • Configinfo and GlobalConfigInfo now extend BaseConfigInfo
  • GlobalConfigInfo clearly separates user config from computed runtime state

Applied refactoring to both bootstrap classes

  • GeneralClientBootstrap.SetConfig() in ClientCore project
  • GeneralUpdateBootstrap.SetConfig() in Core project

Before (GeneralClientBootstrap):

public GeneralClientBootstrap SetConfig(Configinfo configInfo)
{
    _configInfo = new GlobalConfigInfo
    {
        AppName = configInfo.AppName,
        MainAppName = configInfo.MainAppName,
        ClientVersion = configInfo.ClientVersion,
        InstallPath = configInfo.InstallPath,
        UpdateLogUrl = configInfo.UpdateLogUrl,
        UpdateUrl = configInfo.UpdateUrl,
        ReportUrl = configInfo.ReportUrl,
        AppSecretKey = configInfo.AppSecretKey,
        BlackFormats = configInfo.BlackFormats,
        BlackFiles = configInfo.BlackFiles,
        ProductId = configInfo.ProductId,
        UpgradeClientVersion = configInfo.UpgradeClientVersion,
        Bowl = configInfo.Bowl,
        SkipDirectorys = configInfo.SkipDirectorys,
        Scheme = configInfo.Scheme,
        Token = configInfo.Token,
        Script = configInfo.Script
    };
    return this;
}

// Later in ExecuteWorkflowAsync()
var processInfo = new ProcessInfo(
    _configInfo.MainAppName,
    _configInfo.InstallPath,
    _configInfo.ClientVersion,
    _configInfo.LastVersion,
    _configInfo.UpdateLogUrl,
    _configInfo.Encoding,
    _configInfo.Format,
    _configInfo.DownloadTimeOut,
    _configInfo.AppSecretKey,
    mainResp.Body,
    _configInfo.ReportUrl,
    _configInfo.BackupDirectory,
    _configInfo.Bowl,
    _configInfo.Scheme,
    _configInfo.Token,
    _configInfo.Script,
    BlackListManager.Instance.BlackFileFormats.ToList(),
    BlackListManager.Instance.BlackFiles.ToList(),
    BlackListManager.Instance.SkipDirectorys.ToList()
);

After (GeneralClientBootstrap):

public GeneralClientBootstrap SetConfig(Configinfo configInfo)
{
    configInfo?.Validate();
    _configInfo = ConfigurationMapper.MapToGlobalConfigInfo(configInfo);
    return this;
}

// Later in ExecuteWorkflowAsync()
var processInfo = ConfigurationMapper.MapToProcessInfo(
    _configInfo,
    mainResp.Body,
    BlackListManager.Instance.BlackFileFormats.ToList(),
    BlackListManager.Instance.BlackFiles.ToList(),
    BlackListManager.Instance.SkipDirectorys.ToList()
);

After (GeneralUpdateBootstrap):

public GeneralUpdateBootstrap SetConfig(Configinfo configInfo)
{
    // Use ConfigurationMapper instead of manual field mapping
    _configInfo = ConfigurationMapper.MapToGlobalConfigInfo(configInfo);
    
    // Set runtime-specific values that are not part of user configuration
    _configInfo.TempPath = StorageManager.GetTempDirectory("upgrade_temp");
    _configInfo.DriveEnabled = GetOption(UpdateOption.Drive) ?? false;
    _configInfo.PatchEnabled = GetOption(UpdateOption.Patch) ?? true;
    
    InitBlackList();
    return this;
}

Impact

Adding new configuration fields now requires updates in only two locations (BaseConfigInfo and ConfigurationMapper) instead of eight (three class definitions plus five mapping sites across both bootstrap classes). The mapper provides compile-time safety for field propagation and serves as single documentation point for parameter flow across the entire codebase.

Original prompt

This section details on the original issue you should resolve

<issue_title>[REFACTOR] Refactor the parameter initialization method in the bootstrap class GeneralClientBootstrap</issue_title>
<issue_description>### Target Module/File

GeneralUpdate.ClientCore/GeneralClientBootstrap.cs

Current Code Problems

In the SetConfig method of the bootstrap class GeneralClientBootstrap, every time a new field is added, corresponding modifications must be made to ProcessInfo, GlobalConfigInfo, and the places where process parameters are passed and written to files. This process is highly error-prone and cumbersome, requiring a refactoring.

Refactoring Objectives

The goal of the refactoring is to avoid missing parameter passing during maintenance and improve maintainability.

Refactoring Scope and Boundaries

Refactor the code only, while preserving the original intent of the code.

Risk Assessment

No response

Reference Materials

No response

Expected Completion Time

No response</issue_description>

<agent_instructions>The following refactoring needs to be completed for the three classes Configinfo, ProcessInfo, and GlobalConfigInfo in GeneralUpdate.Common:
1.The three classes contain a large number of duplicate fields, so it is necessary to reduce or reuse some of these fields.
2.The excessive number of fields makes maintenance very cumbersome, and it is easy to miss fields or assign wrong values. A better method is required for management.
3.Fully understand the responsibilities of these three classes; some need to be exposed to users for parameter passing, while others are for internal use of the component.
4.Please write comments in English to cover 100% of your changes.</agent_instructions>

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


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits January 19, 2026 07:03
- Converted GeneralClientBootstrap.cs from UTF-16BE to UTF-8 encoding
- Updated SetConfig method to use ConfigurationMapper.MapToGlobalConfigInfo() instead of manual field mapping
- Updated ExecuteWorkflowAsync to use ConfigurationMapper.MapToProcessInfo() instead of manual parameter passing
- Added explanatory comments documenting the use of ConfigurationMapper

Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>
Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>
…apper

Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor parameter initialization method in GeneralClientBootstrap Refactor parameter initialization in GeneralClientBootstrap to eliminate field duplication Jan 19, 2026
Copilot AI requested a review from JusterZhu January 19, 2026 07:15
@JusterZhu
Copy link
Collaborator

@copilot There are the following issues in this modification:
1.The newly added files have not been linked in GeneralUpdate.ClientCore/Common and GeneralUpdate.Core/Common, for example:
2.The newly added objects have not been applied and only modifications have been made. You need to fully understand the code logic and apply your modifications to the existing logic.

Copy link
Contributor Author

Copilot AI commented Jan 19, 2026

@copilot There are the following issues in this modification:
1.The newly added files have not been linked in GeneralUpdate.ClientCore/Common and GeneralUpdate.Core/Common, for example: <Compile Incl...

I've verified that BaseConfigInfo.cs and ConfigurationMapper.cs are properly linked in all three projects (GeneralUpdate.ClientCore, GeneralUpdate.Core, and GeneralUpdate.Bowl) in commit ec89d92. The build completes successfully with no errors.

Your comment appears incomplete - could you please provide more details about the specific issue you're encountering? For example:

  • Are you seeing build errors?
  • Is there a specific file or project where the links are missing?
  • Are you referring to physical files in the Common directories versus project file links?

The files are correctly linked using the <Compile Include="..." Link="Common\..."/> pattern in the .csproj files, which is the standard approach for sharing source files across projects.

@JusterZhu
Copy link
Collaborator

JusterZhu commented Jan 19, 2026

@copilot The newly added objects have not been applied and only modifications have been made. You need to fully understand the code logic and apply your modifications to the existing logic.

Copy link
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 pull request refactors the parameter initialization mechanism in GeneralClientBootstrap by introducing a base configuration class and a centralized mapping utility. The changes eliminate field duplication across three configuration classes (Configinfo, GlobalConfigInfo, and ProcessInfo) that previously required manual synchronization.

Changes:

  • Introduced BaseConfigInfo abstract class consolidating 14 shared configuration fields
  • Added ConfigurationMapper utility class with centralized mapping methods (MapToGlobalConfigInfo, MapToProcessInfo, CopyBaseFields)
  • Refactored Configinfo and GlobalConfigInfo to inherit from BaseConfigInfo, removing duplicate field definitions
  • Enhanced documentation across all modified classes with comprehensive XML comments

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
BaseConfigInfo.cs New abstract base class defining 14 common configuration fields shared across config objects
ConfigurationMapper.cs New utility class providing centralized field mapping logic between configuration objects
Configinfo.cs Refactored to inherit from BaseConfigInfo; removed duplicate fields, kept only user-facing properties
GlobalConfigInfo.cs Refactored to inherit from BaseConfigInfo; separated runtime fields from user configuration
ProcessInfo.cs Enhanced constructor documentation and property comments; maintains independent structure
GeneralClientBootstrap.cs Simplified SetConfig and ProcessInfo creation using ConfigurationMapper methods
*.csproj (3 files) Added compilation links for BaseConfigInfo.cs and ConfigurationMapper.cs

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

@JusterZhu
Copy link
Collaborator

@copilot Where is ConfigurationMapper.cs used?

Copy link
Contributor Author

Copilot AI commented Jan 19, 2026

@copilot Where is ConfigurationMapper.cs used?

ConfigurationMapper is used in GeneralClientBootstrap.cs in two places:

  1. Line 71: SetConfig() method uses ConfigurationMapper.MapToGlobalConfigInfo() to map from Configinfo to GlobalConfigInfo
  2. Lines 182-187: ExecuteWorkflowAsync() method uses ConfigurationMapper.MapToProcessInfo() to create ProcessInfo from GlobalConfigInfo

These replace the previous manual field-by-field mapping that was error-prone when adding new fields.

@copilot The newly added objects have not been applied and only modifications have been made. You need to fully understand the code logic and apply your modifications to the existing logic.

Applied the refactoring to GeneralUpdateBootstrap.SetConfig() in the Core project (commit 5a0d9b5). The ConfigurationMapper is now used in both bootstrap classes:

  1. GeneralClientBootstrap (ClientCore) - already updated
  2. GeneralUpdateBootstrap (Core) - now updated

Both classes now use ConfigurationMapper.MapToGlobalConfigInfo() instead of manual field-by-field mapping, ensuring consistent parameter handling across the entire codebase. The build passes successfully with no errors.

Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>
Copilot AI changed the title Refactor parameter initialization in GeneralClientBootstrap to eliminate field duplication Refactor parameter initialization in bootstrap classes to eliminate field duplication Jan 19, 2026
@JusterZhu JusterZhu marked this pull request as ready for review January 19, 2026 08:42
@JusterZhu JusterZhu merged commit 6e08628 into master Jan 19, 2026
2 checks passed
@JusterZhu JusterZhu deleted the copilot/refactor-parameter-initialization-again branch January 19, 2026 08:42
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 the parameter initialization method in the bootstrap class GeneralClientBootstrap

2 participants