Skip to content

[C#]: 安装 NeoForge(实例下载流程)失败:DirectoryNotFoundException,临时目录与 versions 路径粘连 #3603

Description

@Rockstar-1998

检查项 / Checklist

  • 我已在 Issues 页面 中搜索,确认了这一 Bug 未被提交过 / I have searched the Issues page and confirmed that this bug has not been reported yet.
  • 我确认只是全部选中而没有仔细确认就直接提交了这个 Issue,并且同意这个 Issue 可以直接被关闭 / I confirm that I checked all boxes without carefully reading them, and agree that this issue may be closed directly.
  • 我确认正在使用当前更新分支的最新版 PCL CE,若不是,此 Issue 可能会被直接关闭(更新方式:启动器 设置-关于-软件更新 检查更新,或在 Releases 页面下载) / I confirm that I am using the latest PCL CE version on the current update channel. If not, this issue may be closed directly. To update, check for updates in Settings → About → Updates, or download the latest version from the Releases page.
  • 我确认会详细描述我所遇到的问题,并附上日志和截图,而不是随便填点东西敷衍了事 / I will describe the problem in detail, attach logs and screenshots, and avoid submitting vague or incomplete information.

描述 / Description

通过「下载 → 新实例」安装 NeoForge 26.2.0.79(MC 26.2)时,在“安装 NeoForge”阶段必然失败,报 DirectoryNotFoundException。

初步分析

McDownloadForgelikeLoader 中存在对 mcFolder 的裸字符串拼接:

var oldList = new DirectoryInfo(mcFolder + "versions/")...
var deltaList = new DirectoryInfo(mcFolder + "versions/").EnumerateDirectories()...
var versionFolder = $@"{mcFolder}versions\{targetVersion}\";

这些代码隐含假设 mcFolder\ 结尾——默认值 ModFolder.mcFolderSelected 满足该条件,因此从实例设置页安装加载器时不会出错。但实例下载流程传入的 mcFolder 是 TaskTemp 下的临时目录(形如 C:\ProgramData\PCL\TaskTemp\725-540111,不带尾部反斜杠),拼接后产生 ...725-540111versions 这个粘连路径,枚举目录时抛出异常。该模式同样存在于 OptiFine 流程的 libraries/versions 路径内插中,疑似同样受影响。

修复建议

在加载器方法入口将外部传入的 mcFolder 规范化为以 \ 结尾(或全部改用 Path.Combine):

mcFolder = mcFolder is null ? ModFolder.mcFolderSelected : EnsureTrailingSlash(mcFolder);

重现步骤 / Steps to Reproduce

1.下载 → 新实例,选择 MC 26.2 + NeoForge 26.2.0.79
2.等待下载进行到「安装 NeoForge」阶段
3.稳定复现,失败后实例残留(
System.Exception: NeoForge 26.2.0.79 下载失败
---> System.Exception: 安装 NeoForge失败
---> System.Exception: 安装新 NeoForge 实例失败
---> System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\ProgramData\PCL\TaskTemp\725-540111versions'.
at System.IO.DirectoryInfo.EnumerateDirectories()
at PCL.ModDownloadLib.<>c__DisplayClass37_0.b__7(LoaderTask`2 task)
...
)

日志与附件 / Logs & Attachments

Launch-2026-9-6-200838537.log

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    ⭕ 等待处理问题或需求已知晓并确认,正在等待后续处理

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions