Skip to content

Commit 586510e

Browse files
CopilotJusterZhu
andauthored
Fix Avalonia IDE startup by moving packet workspace off the executable directory (#18)
* Initial plan * fix: use user-writable packet workspace Agent-Logs-Url: https://github.com/GeneralLibrary/GeneralUpdate.Tools/sessions/3713e717-448c-4e9c-b05a-40d972079fc4 Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com> * style: rename packet workspace variable Agent-Logs-Url: https://github.com/GeneralLibrary/GeneralUpdate.Tools/sessions/3713e717-448c-4e9c-b05a-40d972079fc4 Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>
1 parent 8d70e4a commit 586510e

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

src/ViewModels/PacketViewModel.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,8 @@ private async Task<string> CreateConfigInfoFile()
355355
};
356356

357357
var json = JsonConvert.SerializeObject(configInfo, Formatting.Indented);
358-
var configFilePath = Path.Combine(AppContext.BaseDirectory, "update_config.json");
358+
Directory.CreateDirectory(ConfigModel.PatchDirectory);
359+
var configFilePath = Path.Combine(ConfigModel.PatchDirectory, "update_config.json");
359360

360361
await File.WriteAllTextAsync(configFilePath, json, Encoding.UTF8);
361362

@@ -482,22 +483,33 @@ private static string SearchExeFileAndGetDirectory(string rootDirectory, string
482483

483484
private void CreateDirectory()
484485
{
485-
var baseDir = AppContext.BaseDirectory;
486+
var baseDir = GetApplicationDataDirectory();
486487

487-
var packateDir = Path.Combine(baseDir, "packets");
488-
if (!Directory.Exists(packateDir))
488+
var packetDir = Path.Combine(baseDir, "packets");
489+
if (!Directory.Exists(packetDir))
489490
{
490-
Directory.CreateDirectory(packateDir);
491+
Directory.CreateDirectory(packetDir);
491492
}
492493

493-
var patchDir = Path.Combine(packateDir, "patch");
494+
var patchDir = Path.Combine(packetDir, "patch");
494495
if (!Directory.Exists(patchDir))
495496
{
496497
Directory.CreateDirectory(patchDir);
497498
}
498499

499500
ConfigModel.PatchDirectory = patchDir;
500501
}
502+
503+
private static string GetApplicationDataDirectory()
504+
{
505+
var localApplicationData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
506+
if (string.IsNullOrWhiteSpace(localApplicationData))
507+
{
508+
return AppContext.BaseDirectory;
509+
}
510+
511+
return Path.Combine(localApplicationData, "GeneralUpdate.Tool.Avalonia");
512+
}
501513

502514
static void OpenFileDirectoryAndSelectFile(string filePath)
503515
{
@@ -513,4 +525,4 @@ static void OpenFileDirectoryAndSelectFile(string filePath)
513525
UseShellExecute = true
514526
});
515527
}
516-
}
528+
}

0 commit comments

Comments
 (0)