feat: 增强便携版支持与配置管理
- 更新 .gitignore 文件,添加便携版分发目录和 Fody 生成的配置文件。 - 修改 README.md,详细说明便携版的构建与分发流程,强调单文件分发的优势。 - 在 Config.cs 中实现便携配置管理,优先使用 exe 同目录的 config.json,提升用户体验。 - 更新 ExcelService.cs,优化默认模板的导出逻辑,支持现场替换模板文件。 - 在 MainForm.cs 中加载应用图标,提升界面一致性。 - 调整 Program.cs,确保在单文件分发时正确加载 native DLL。
This commit is contained in:
@@ -44,11 +44,39 @@ namespace TfsExcelImporter
|
||||
// 父 Product Backlog Item:所有 Task 默认挂接的 PBI Id(如 219975);Excel 每行 PBI Id 列可覆盖
|
||||
public string ParentPbiId { get; set; } = "";
|
||||
|
||||
private static string ConfigPath
|
||||
// 便携优先:配置写在 exe 同目录(拷走 exe 即可带走配置);
|
||||
// exe 目录只读(如放在 Program Files)时回退到 %AppData%\TfsExcelImporter。
|
||||
private static string PortableConfigPath
|
||||
{
|
||||
get { return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.json"); }
|
||||
}
|
||||
|
||||
private static string RoamingConfigPath
|
||||
{
|
||||
get
|
||||
{
|
||||
return Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||
"TfsExcelImporter", "config.json");
|
||||
}
|
||||
}
|
||||
|
||||
private static string ConfigPath
|
||||
{
|
||||
get
|
||||
{
|
||||
if (File.Exists(PortableConfigPath)) return PortableConfigPath;
|
||||
if (File.Exists(RoamingConfigPath)) return RoamingConfigPath;
|
||||
return PortableConfigPath;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>当前实际使用的配置文件路径(界面提示用)。</summary>
|
||||
public static string ConfigLocation
|
||||
{
|
||||
get { return ConfigPath; }
|
||||
}
|
||||
|
||||
public static AppConfig Load()
|
||||
{
|
||||
try
|
||||
@@ -68,14 +96,28 @@ namespace TfsExcelImporter
|
||||
|
||||
public void Save()
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||
try
|
||||
{
|
||||
File.WriteAllText(ConfigPath, JsonConvert.SerializeObject(this, Formatting.Indented));
|
||||
File.WriteAllText(ConfigPath, json);
|
||||
return;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("写入 config.json 失败: " + ex.Message);
|
||||
}
|
||||
|
||||
// exe 目录不可写(只读介质 / Program Files)时落到用户配置目录
|
||||
try
|
||||
{
|
||||
var fallback = RoamingConfigPath;
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(fallback));
|
||||
File.WriteAllText(fallback, json);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("写入用户配置目录失败: " + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user