Skip to content

refactor: 替换 + 为 Path.Combine#2818

Open
LuLu-ling wants to merge 2 commits into
devfrom
refactor/Path.Combine
Open

refactor: 替换 + 为 Path.Combine#2818
LuLu-ling wants to merge 2 commits into
devfrom
refactor/Path.Combine

Conversation

@LuLu-ling
Copy link
Copy Markdown
Member

@LuLu-ling LuLu-ling commented May 11, 2026

Partly Generated with Deepseek-v4-pro

Summary by Sourcery

在 Minecraft 的下载、实例、整合包、崩溃处理和启动等模块中重构文件系统路径处理,将手动字符串拼接统一改为使用 Path.Combine 和相关辅助方法。

增强点:

  • 在下载、启动、实例管理、整合包安装、崩溃报告以及组件/资源管理代码中,统一使用 Path.Combine 和相关工具来构建文件和目录路径。
  • 提高针对 Minecraft 文件夹、库、资源(assets)、natives、临时/缓存目录和配置文件等路径处理的健壮性和可读性。
  • 在采用新的路径构建方式的同时,移除或调整部分冗余的 using 和字面量。
Original summary in English

Summary by Sourcery

Refactor filesystem path handling across Minecraft download, instance, modpack, crash, and launch modules to use Path.Combine and related helpers instead of manual string concatenation.

Enhancements:

  • Standardize construction of file and directory paths using Path.Combine and related utilities throughout download, launch, instance management, modpack installation, crash reporting, and component/resource management code.
  • Improve robustness and readability of path handling for Minecraft folders, libraries, assets, natives, temp/cache directories, and configuration files.
  • Remove or adjust a few redundant usings and literals while aligning code with the new path-building approach.

@pcl-ce-automation pcl-ce-automation Bot added 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查 size: XL PR 大小评估:超大型 labels May 11, 2026
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 11, 2026

审阅者指南

在整个启动器中重构路径处理逻辑,用 Path.Combine 及相关辅助方法替换手动字符串拼接,从而提升跨平台正确性和可读性,并移除冗余的 using,顺带做了一些小的清理优化。

文件级变更

变更 详情 文件
使用 Path.Combine 替代字符串拼接来处理 Minecraft 版本、实例和库路径。
  • 使用 Path.Combine(ModMinecraft.McFolderSelected, "versions", id/instanceName) 来构建版本文件夹,而不是依赖硬编码的 \versions\ 字符串。
  • 将所有 JSON/JAR 的存在性检查、读写和删除操作统一改为通过 Path.Combine(versionFolder, fileName) 实现。
  • 调整继承、资源索引、natives 以及启动器配置文件路径,使其通过 Path.Combine 计算以保持一致性。
Plain Craft Launcher 2/Pages/PageDownload/ModDownloadLib.cs
Plain Craft Launcher 2/Modules/Minecraft/ModMinecraft.cs
Plain Craft Launcher 2/Modules/Minecraft/ModDownload.cs
使用 Path.Combine 规范化临时文件、缓存和 appdata 相关的文件/文件夹路径。
  • Path.Combine 变体替换诸如 PathTemp + "Cache"+ 文件名这类临时/缓存/下载文件路径拼接方式。
  • 更新崩溃报告的临时/报告文件夹以及导出文件路径,使其使用 Path.Combine
  • UpdateManager、Java 包装器/authlib/mesa-loader 等路径改为通过 Path.Combine 指定文件位置。
Plain Craft Launcher 2/Modules/Minecraft/ModCrash.cs
Plain Craft Launcher 2/Modules/Updates/UpdateManager.cs
Plain Craft Launcher 2/Modules/Minecraft/ModLaunch.cs
Plain Craft Launcher 2/Modules/Base/ModBase.cs
Plain Craft Launcher 2/Application.xaml.cs
Plain Craft Launcher 2/Pages/PageInstance/PageInstanceExport.xaml.cs
将整合包、组件、存档和 LabyMod 相关资源路径重构为基于 Path.Combine 的构建方式。
  • 在复制/解压 CurseForge/Modrinth/HMCL/MCBBS/MMC 等整合包的 override 目录和 logo 时使用 Path.Combine
  • 在组件管理页面中,使用 Path.Combine 构建组件目录(mods、datapacks、labymod-neo 路径)。
  • 将与存档相关的 datapack/icon 路径更新为 Path.Combine,用于加载/更新/打开操作。
Plain Craft Launcher 2/Modules/Minecraft/ModModpack.cs
Plain Craft Launcher 2/Modules/Minecraft/ModLocalComp.cs
Plain Craft Launcher 2/Pages/PageInstance/PageInstanceCompResource.xaml.cs
Plain Craft Launcher 2/Pages/PageInstance/PageInstanceSaves/PageInstanceSavesDatapack.xaml.cs
Plain Craft Launcher 2/Pages/PageInstance/PageInstanceSaves.xaml.cs
将启动器文件夹发现、实例管理和选择界面统一为基于 Path.Combine 的路径方案。
  • 在扫描潜在 Minecraft 目录时,通过 Path.Combine 检测 .minecraftversions 文件夹。
  • 更新实例重命名/删除流程、缓存失效(PCL.ini/options.txt)以及 PCL 元数据清理,使其依赖于由 Path.Combine 构造的路径。
  • 在服务器列表 servers.dat 的 NBT 访问以及启动页面的自动整合包检测中使用 Path.Combine
Plain Craft Launcher 2/Modules/Minecraft/ModMinecraft.cs
Plain Craft Launcher 2/Pages/PageSelectLeft.xaml.cs
Plain Craft Launcher 2/Pages/PageSelectRight.xaml.cs
Plain Craft Launcher 2/Pages/PageInstance/PageInstanceOverall.xaml.cs
Plain Craft Launcher 2/Pages/PageInstance/PageInstanceServer.xaml.cs
Plain Craft Launcher 2/Pages/PageLaunch/PageLaunchLeft.xaml.cs
与本次重构相关的小型清理和引入调整。
  • PageInstanceInstall.xaml.cs 中移除未使用的 Microsoft.VisualBasic using
  • 在使用 Path.Combine 的文件中补充缺失的 System.IO using
  • 调整部分与 PCL 文件夹初始化和忽略标记相关的字符串字面量,使其与 Path.Combine 的使用保持一致。
Plain Craft Launcher 2/Pages/PageInstance/PageInstanceInstall.xaml.cs
Plain Craft Launcher 2/Pages/PageSelectRight.xaml.cs
Plain Craft Launcher 2/Application.xaml.cs
Plain Craft Launcher 2/Pages/PageDownload/Comp/PageDownloadCompDetail.xaml.cs
Plain Craft Launcher 2/FormMain.xaml.cs

提示与命令

与 Sourcery 交互

  • 触发一次新的审阅: 在 pull request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 从审阅评论生成 GitHub issue: 在某条审阅评论下回复,请求 Sourcery 从该评论创建一个 issue。你也可以在审阅评论下回复 @sourcery-ai issue 来从该评论创建 issue。
  • 生成 pull request 标题: 在 pull request 标题的任意位置输入 @sourcery-ai,即可随时生成标题。你也可以在 pull request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 pull request 摘要: 在 pull request 正文任意位置写入 @sourcery-ai summary,即可在指定位置生成 PR 摘要。你也可以在 pull request 中评论 @sourcery-ai summary 来在任意时间(重新)生成摘要。
  • 生成审阅者指南: 在 pull request 中评论 @sourcery-ai guide,即可在任意时间(重新)生成审阅者指南。
  • 解决所有 Sourcery 评论: 在 pull request 中评论 @sourcery-ai resolve,即可一次性标记所有 Sourcery 评论为已解决。如果你已经处理完所有评论且不想再看到它们,这会非常有用。
  • 撤销所有 Sourcery 审阅: 在 pull request 中评论 @sourcery-ai dismiss,即可撤销所有现有的 Sourcery 审阅。若你希望从头开始一次新的审阅,这尤其有用——记得随后再评论 @sourcery-ai review 来触发新的审阅!

自定义你的体验

访问你的 控制面板 以:

  • 启用或禁用诸如 Sourcery 自动生成的 pull request 摘要、审阅者指南等审阅功能。
  • 更改审阅语言。
  • 添加、移除或编辑自定义审阅说明。
  • 调整其他审阅相关设置。

获取帮助

Original review guide in English

Reviewer's Guide

Refactors path handling across the launcher to replace manual string concatenation with Path.Combine and related helpers, improving cross-platform correctness and readability, and removes a redundant using plus a few minor cleanups.

File-Level Changes

Change Details Files
Use Path.Combine instead of string concatenation for Minecraft version, instance, and library paths.
  • Build version folders with Path.Combine(ModMinecraft.McFolderSelected, "versions", id/instanceName) instead of hard-coded \versions\ strings.
  • Update all JSON/JAR existence checks, reads, writes, and deletes to use Path.Combine(versionFolder, fileName).
  • Adjust inheritance, assets index, natives and launcher profile paths to be computed via Path.Combine for consistency.
Plain Craft Launcher 2/Pages/PageDownload/ModDownloadLib.cs
Plain Craft Launcher 2/Modules/Minecraft/ModMinecraft.cs
Plain Craft Launcher 2/Modules/Minecraft/ModDownload.cs
Normalize temporary, cache, and appdata file/folder paths using Path.Combine.
  • Replace temp/cache/download file paths like PathTemp + "Cache" or + filenames with Path.Combine variants.
  • Update crash report temp/report folders and exported files to use Path.Combine.
  • Change UpdateManager, Java wrapper/authlib/mesa-loader paths to use Path.Combine for file locations.
Plain Craft Launcher 2/Modules/Minecraft/ModCrash.cs
Plain Craft Launcher 2/Modules/Updates/UpdateManager.cs
Plain Craft Launcher 2/Modules/Minecraft/ModLaunch.cs
Plain Craft Launcher 2/Modules/Base/ModBase.cs
Plain Craft Launcher 2/Application.xaml.cs
Plain Craft Launcher 2/Pages/PageInstance/PageInstanceExport.xaml.cs
Refactor modpack, component, saves, and LabyMod-related resource paths to Path.Combine-based construction.
  • Use Path.Combine when copying/extracting modpack override directories and logos for CurseForge/Modrinth/HMCL/MCBBS/MMC packs.
  • Build component directories (mods, datapacks, labymod-neo paths) with Path.Combine in component management pages.
  • Update save-related datapack/icon paths to Path.Combine for load/update/open operations.
Plain Craft Launcher 2/Modules/Minecraft/ModModpack.cs
Plain Craft Launcher 2/Modules/Minecraft/ModLocalComp.cs
Plain Craft Launcher 2/Pages/PageInstance/PageInstanceCompResource.xaml.cs
Plain Craft Launcher 2/Pages/PageInstance/PageInstanceSaves/PageInstanceSavesDatapack.xaml.cs
Plain Craft Launcher 2/Pages/PageInstance/PageInstanceSaves.xaml.cs
Align launcher folder discovery, instance management, and selection UI with Path.Combine-based paths.
  • Use Path.Combine for detecting .minecraft and versions folders when scanning possible Minecraft directories.
  • Update instance rename/delete flows, cache invalidation (PCL.ini/options.txt), and PCL metadata cleanup to rely on Path.Combine paths.
  • Use Path.Combine for servers.dat NBT access and auto modpack detection in the launch page.
Plain Craft Launcher 2/Modules/Minecraft/ModMinecraft.cs
Plain Craft Launcher 2/Pages/PageSelectLeft.xaml.cs
Plain Craft Launcher 2/Pages/PageSelectRight.xaml.cs
Plain Craft Launcher 2/Pages/PageInstance/PageInstanceOverall.xaml.cs
Plain Craft Launcher 2/Pages/PageInstance/PageInstanceServer.xaml.cs
Plain Craft Launcher 2/Pages/PageLaunch/PageLaunchLeft.xaml.cs
Minor cleanups and imports associated with the refactor.
  • Remove an unused Microsoft.VisualBasic using from PageInstanceInstall.xaml.cs.
  • Add missing System.IO using where Path.Combine is now used.
  • Adjust a few string literals for PCL folder initialization and ignore markers to be consistent with Path.Combine usage.
Plain Craft Launcher 2/Pages/PageInstance/PageInstanceInstall.xaml.cs
Plain Craft Launcher 2/Pages/PageSelectRight.xaml.cs
Plain Craft Launcher 2/Application.xaml.cs
Plain Craft Launcher 2/Pages/PageDownload/Comp/PageDownloadCompDetail.xaml.cs
Plain Craft Launcher 2/FormMain.xaml.cs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - 我在这里给出了一些整体性的反馈:

  • 有很多类似 Path.Combine(... ) + @"\" 的写法;由于 Path.Combine 本身就会处理路径分隔符,建议在返回目录路径时不要再手动追加 "\",这样可以减少冗余,并让代码在不同平台上更加健壮。
  • 在好几处你传入的路径片段本身就包含路径分隔符(例如 Path.Combine(ModBase.ExePath, @"PCL\Pictures\"));更安全、更清晰的做法是只传入干净的片段名称(例如 "PCL", "Pictures"),这样所有分隔符都可以交由 Path.Combine` 统一处理。
给 AI 代理的提示
Please address the comments from this code review:

## Overall Comments
- There are many patterns like `Path.Combine(... ) + @"\"`; since `Path.Combine` already handles separators, consider returning directory paths without manually appending `"\"` to reduce redundancy and make the code more robust across platforms.
- In several places you pass segments that already include path separators (e.g. `Path.Combine(ModBase.ExePath, @"PCL\Pictures\")`); it would be safer and clearer to pass only clean segment names (e.g. `"PCL"`, "Pictures") so `Path.Combine` can handle all separators consistently.

Sourcery 对开源项目免费——如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English

Hey - I've left some high level feedback:

  • There are many patterns like Path.Combine(... ) + @"\"; since Path.Combine already handles separators, consider returning directory paths without manually appending "\" to reduce redundancy and make the code more robust across platforms.
  • In several places you pass segments that already include path separators (e.g. Path.Combine(ModBase.ExePath, @"PCL\Pictures\")); it would be safer and clearer to pass only clean segment names (e.g. "PCL", "Pictures") so Path.Combine can handle all separators consistently.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- There are many patterns like `Path.Combine(... ) + @"\"`; since `Path.Combine` already handles separators, consider returning directory paths without manually appending `"\"` to reduce redundancy and make the code more robust across platforms.
- In several places you pass segments that already include path separators (e.g. `Path.Combine(ModBase.ExePath, @"PCL\Pictures\")`); it would be safer and clearer to pass only clean segment names (e.g. `"PCL"`, "Pictures") so `Path.Combine` can handle all separators consistently.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@LuLu-ling LuLu-ling requested a review from a team May 11, 2026 14:12
Chiloven945
Chiloven945 previously approved these changes May 11, 2026
Copy link
Copy Markdown
Member

@whitecat346 whitecat346 left a comment

Choose a reason for hiding this comment

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

as what ai has said.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: XL PR 大小评估:超大型 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants