feat(resource): 支持从其他实例导入资源包与光影包 [GPT-5.6] - #3536
Conversation
审阅者指南为从其他实例导入资源包和光影包的功能添加了 UI 和逻辑,包括实例选择、安全的文件枚举/复制(带覆盖确认提示),以及新的导入流程所需的本地化文案。 从其他实例导入资源/光影包的时序图sequenceDiagram
actor User
participant PageInstanceCompResource
participant ModInstanceList
participant Directory
participant ModMain
participant ModBase
participant HintService
User->>PageInstanceCompResource: BtnManageImport_Click
PageInstanceCompResource->>PageInstanceCompResource: resolve folderName (resourcepacks/shaderpacks)
PageInstanceCompResource->>ModInstanceList: mcInstanceList
ModInstanceList-->>PageInstanceCompResource: candidate instances
loop each instance
PageInstanceCompResource->>Directory: _GetImportEntries(instance, sourceFolder)
Directory-->>PageInstanceCompResource: entries[]
end
PageInstanceCompResource->>PageInstanceCompResource: filter empty / same target
alt no available source
PageInstanceCompResource->>HintService: Hint(Instance.Resource.Import.NoAvailableInstance)
PageInstanceCompResource-->>User: return
else sources available
PageInstanceCompResource->>ModMain: MyMsgBoxSelect(selection)
ModMain-->>PageInstanceCompResource: selectedIndex
alt user cancelled
PageInstanceCompResource-->>User: return
else instance selected
PageInstanceCompResource->>PageInstanceCompResource: _ImportEntries(entries, targetFolder)
loop each sourceEntry
PageInstanceCompResource->>Directory: File/Directory.Exists(targetEntry)
Directory-->>PageInstanceCompResource: exists?
alt target exists
PageInstanceCompResource->>ModMain: MyMsgBox(OverwriteConfirm)
ModMain-->>PageInstanceCompResource: result
alt user confirms overwrite
PageInstanceCompResource->>PageInstanceCompResource: _DeleteImportTarget(targetEntry)
else cancel this entry
PageInstanceCompResource-->>PageInstanceCompResource: continue
end
end
alt source is file
PageInstanceCompResource->>ModBase: CopyFile(sourceEntry, targetEntry)
else source is directory
PageInstanceCompResource->>PageInstanceCompResource: _CopyImportDirectory(sourceEntry, targetEntry)
end
end
alt importedCount > 0
PageInstanceCompResource->>HintService: Hint(Import.Success, HintType.Success)
PageInstanceCompResource->>PageInstanceCompResource: ReloadCompFileList(true)
end
end
end
Note over PageInstanceCompResource,ModBase: Exceptions are logged via ModBase.Log in _GetImportEntries/_ImportEntries
文件级更改
提示与命令与 Sourcery 交互
自定义你的体验打开你的 控制面板 可以:
获取帮助Original review guide in EnglishReviewer's GuideAdds UI and logic to import resource packs and shader packs from other instances, including instance selection, safe file enumeration/copying with overwrite prompts, and localization strings for the new import flow. Sequence diagram for importing resource/shader packs from another instancesequenceDiagram
actor User
participant PageInstanceCompResource
participant ModInstanceList
participant Directory
participant ModMain
participant ModBase
participant HintService
User->>PageInstanceCompResource: BtnManageImport_Click
PageInstanceCompResource->>PageInstanceCompResource: resolve folderName (resourcepacks/shaderpacks)
PageInstanceCompResource->>ModInstanceList: mcInstanceList
ModInstanceList-->>PageInstanceCompResource: candidate instances
loop each instance
PageInstanceCompResource->>Directory: _GetImportEntries(instance, sourceFolder)
Directory-->>PageInstanceCompResource: entries[]
end
PageInstanceCompResource->>PageInstanceCompResource: filter empty / same target
alt no available source
PageInstanceCompResource->>HintService: Hint(Instance.Resource.Import.NoAvailableInstance)
PageInstanceCompResource-->>User: return
else sources available
PageInstanceCompResource->>ModMain: MyMsgBoxSelect(selection)
ModMain-->>PageInstanceCompResource: selectedIndex
alt user cancelled
PageInstanceCompResource-->>User: return
else instance selected
PageInstanceCompResource->>PageInstanceCompResource: _ImportEntries(entries, targetFolder)
loop each sourceEntry
PageInstanceCompResource->>Directory: File/Directory.Exists(targetEntry)
Directory-->>PageInstanceCompResource: exists?
alt target exists
PageInstanceCompResource->>ModMain: MyMsgBox(OverwriteConfirm)
ModMain-->>PageInstanceCompResource: result
alt user confirms overwrite
PageInstanceCompResource->>PageInstanceCompResource: _DeleteImportTarget(targetEntry)
else cancel this entry
PageInstanceCompResource-->>PageInstanceCompResource: continue
end
end
alt source is file
PageInstanceCompResource->>ModBase: CopyFile(sourceEntry, targetEntry)
else source is directory
PageInstanceCompResource->>PageInstanceCompResource: _CopyImportDirectory(sourceEntry, targetEntry)
end
end
alt importedCount > 0
PageInstanceCompResource->>HintService: Hint(Import.Success, HintType.Success)
PageInstanceCompResource->>PageInstanceCompResource: ReloadCompFileList(true)
end
end
end
Note over PageInstanceCompResource,ModBase: Exceptions are logged via ModBase.Log in _GetImportEntries/_ImportEntries
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - 我在这里给出了一些整体层面的反馈:
- 导入操作(扫描实例并复制可能很大的资源/着色器目录)目前在 UI 线程上同步执行;建议把耗时较长的工作移动到后台任务中(例如使用 Task.Run,通过 dispatcher 更新 UI),以避免在执行大型导入时界面卡死。
- 在
_ImportEntries中,只要一次文件/文件夹复制抛出异常,就会中止整个导入循环;如果合适,建议在循环内部按条目处理失败情况(记录日志并继续),这样单个有问题的条目就不会阻止其他资源被导入。
给 AI Agent 的提示
请根据这次代码评审中的评论进行修改:
## 总体评论
- 导入操作(扫描实例并复制可能很大的资源/着色器目录)目前在 UI 线程上同步执行;建议把耗时较长的工作移动到后台任务中(例如使用 Task.Run,通过 dispatcher 更新 UI),以避免在执行大型导入时界面卡死。
- 在 `_ImportEntries` 中,只要一次文件/文件夹复制抛出异常,就会中止整个导入循环;如果合适,建议在循环内部按条目处理失败情况(记录日志并继续),这样单个有问题的条目就不会阻止其他资源被导入。帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据反馈改进后续的评审。
Original comment in English
Hey - I've left some high level feedback:
- The import operation (scanning instances and copying potentially large resource/shader directories) runs synchronously on the UI thread; consider moving the heavy work into a background task (e.g., Task.Run with UI updates via dispatcher) to avoid freezing the interface during large imports.
- In
_ImportEntries, a single exception during one file/folder copy aborts the entire import loop; if appropriate, consider handling per-entry failures inside the loop (logging and continuing) so that one problematic item does not prevent other resources from being imported.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The import operation (scanning instances and copying potentially large resource/shader directories) runs synchronously on the UI thread; consider moving the heavy work into a background task (e.g., Task.Run with UI updates via dispatcher) to avoid freezing the interface during large imports.
- In `_ImportEntries`, a single exception during one file/folder copy aborts the entire import loop; if appropriate, consider handling per-entry failures inside the loop (logging and continuing) so that one problematic item does not prevent other resources from being imported.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0db2ec4028
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| }; | ||
| if (folderName is null) return; | ||
|
|
||
| var targetFolder = Path.GetFullPath(Path.Combine(PageInstanceLeft.McInstance.PathIndie, folderName)); |
There was a problem hiding this comment.
Use the LabyMod-aware component directory for imports
When either the current or source instance is a LabyMod instance, LoaderRun manages resources under the instance's LabyMod-specific labymod-neo/fabric/<VanillaName> prefix, while this code always targets PathIndie/<folderName> and line 1053 searches sources there as well. As a result, a target import can report success but remain absent after the refresh, and LabyMod sources containing resources in the managed directory are not offered; derive both paths using the same LabyMod-aware component-path logic as the page loader.
Useful? React with 👍 / 👎.
修改内容
验证情况
dotnet build "Plain Craft Launcher 2/Plain Craft Launcher 2.csproj" -c Debug -p:Platform=x64 --no-restore:通过,0 个错误git diff --check dev...feat/import-from-other-instance:通过AI 使用
Summary by Sourcery
为资源包和光影包管理增加跨实例导入能力。
New Features:
Enhancements:
Original summary in English
Summary by Sourcery
为资源包和光影包管理增加跨实例导入能力。
New Features:
Enhancements: