Files
Shigure/App/Program.cs
liantian-cn 4179af4f4d feat: 模块目录迁移至我的文档目录
模块存储位置从 {UserProfile}/.config/{AppName}/module 迁移至
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)/{AppName}/module
(Windows 下跟随用户已知文件夹重定向,本机为 E:\Documents\Shigure\module)。

- ModuleStore.ResolveModuleDirectory() 返回表达式改为 MyDocuments 版本,三个无参调用点自动跟随
- Program.cs 迁移提示文案「用户配置目录」改为「我的文档目录」,检测逻辑不变(仅检测 exe 旁 module/)
- 7 个文档同步更新(README/CLAUDE/打包说明/Obsidian 00/01/10/11),路径统一写 {MyDocuments}/Shigure/module
- 旧目录(含 .config 版本)不自动迁移、不删除,由提示引导手动移动
2026-08-15 13:09:52 +08:00

71 lines
2.6 KiB
C#

namespace Shigure;
internal static class Program
{
[STAThread]
private static void Main(string[] args)
{
if (!OperatingSystem.IsWindows())
{
MessageBox.Show(
"Shigure 需要在 Windows 上运行。",
"Shigure",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
return;
}
ApplicationConfiguration.Initialize();
var options = AppOptions.FromArgs(args);
var baseDirectory = AppPaths.BaseDirectory;
var moduleStore = new ModuleStore(ModuleStore.ResolveModuleDirectory());
ShowModuleMigrationHint(baseDirectory, moduleStore);
var triggerKeyState = new WindowsTriggerKeyState();
var processLocator = new WowProcessLocator(baseDirectory);
var runtimeFactory = new ShigureRuntimeFactory(baseDirectory, moduleStore, triggerKeyState, processLocator);
var runtimeSession = new RuntimeSessionCoordinator(runtimeFactory);
Application.Run(new MainForm(
options,
baseDirectory,
moduleStore,
triggerKeyState,
processLocator,
runtimeSession));
}
// 模块目录迁移提示:旧目录(baseDirectory/module)存在且有内容、且新目录(我的文档目录)尚无模块文件时,
// 弹一次纯文案提示,引导用户手动移动模块;条件不满足或检测异常时静默,不影响启动。
private static void ShowModuleMigrationHint(string baseDirectory, ModuleStore moduleStore)
{
try
{
var oldDirectory = Path.Combine(baseDirectory, "module");
if (!Directory.Exists(oldDirectory)
|| !Directory.EnumerateFileSystemEntries(oldDirectory).Any())
{
return;
}
// 新目录以是否存在模块文件(.json)判空,避免保存崩溃残留的 .tmp 原子写文件阻断提示。
if (Directory.EnumerateFiles(moduleStore.ModuleDirectory, "*.json", SearchOption.AllDirectories).Any())
{
return;
}
MessageBox.Show(
$"模块目录已迁移到我的文档目录。\n\n" +
$"新的模块目录:\n{moduleStore.ModuleDirectory}\n\n" +
$"请将旧目录 {oldDirectory} 中的模块文件手动移动到新目录。",
"Shigure",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
catch
{
// 检测或提示异常时静默跳过,避免影响启动。
}
}
}