Skip to content

Fix Avalonia IDE startup by moving packet workspace off the executable directory#18

Merged
JusterZhu merged 3 commits into
mainfrom
copilot/fix-debugging-errors-avalonia
May 20, 2026
Merged

Fix Avalonia IDE startup by moving packet workspace off the executable directory#18
JusterZhu merged 3 commits into
mainfrom
copilot/fix-debugging-errors-avalonia

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 20, 2026

Debugging GeneralUpdate.Tool.Avalonia from the IDE could leave the process running without showing the window, while the packaged executable only started reliably with administrator privileges. The shared failure mode was runtime writes targeting the app’s install/output directory.

  • Move runtime workspace to a user-writable location

    • PacketViewModel now creates its default packets/patch workspace under LocalApplicationData/GeneralUpdate.Tool.Avalonia instead of AppContext.BaseDirectory.
    • This removes the startup-time dependency on write access to the executable folder.
  • Write generated config into the patch output

    • update_config.json is now created in ConfigModel.PatchDirectory, matching the existing method contract and keeping generated artifacts with the packet output.
    • The patch directory is created before writing to avoid implicit dependence on the app base path.
  • Scope

    • The change is limited to packet-generation path selection and config-file output behavior.
    • No changes were made to packaging logic, UI structure, or unrelated warnings.
private static string GetApplicationDataDirectory()
{
    var localApplicationData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
    if (string.IsNullOrWhiteSpace(localApplicationData))
    {
        return AppContext.BaseDirectory;
    }

    return Path.Combine(localApplicationData, "GeneralUpdate.Tool.Avalonia");
}

// ...

Directory.CreateDirectory(ConfigModel.PatchDirectory);
var configFilePath = Path.Combine(ConfigModel.PatchDirectory, "update_config.json");

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • av-build-tel-api-v1.avaloniaui.net
    • Triggering command: /usr/share/dotnet/dotnet dotnet exec --runtimeconfig /home/REDACTED/.nuget/packages/avalonia.buildservices/0.0.29/tools/netstandard2.0/runtimeconfig.json /home/REDACTED/.nuget/packages/avalonia.buildservices/0.0.29/tools/netstandard2.0/Avalonia.BuildServices.Collector.dll (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI and others added 2 commits May 20, 2026 07:31
@JusterZhu
Copy link
Copy Markdown
Collaborator

@copilot 异常原因是什么?

Copilot AI changed the title [WIP] Fix debugging errors in GeneralUpdate.Tool.Avalonia project Fix Avalonia IDE startup by moving packet workspace off the executable directory May 20, 2026
Copilot AI requested a review from JusterZhu May 20, 2026 07:37
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 20, 2026

@copilot 异常原因是什么?

根因是启动阶段就发生了对可执行目录的写操作。PacketView 加载后会走 LoadedCommand -> ResetAction -> CreateDirectory(),原来这里默认在 AppContext.BaseDirectory 下创建 packets/patch,后续还会把 update_config.json 写到同一目录。IDE 调试目录或安装目录如果是受保护位置(例如 Program Files),普通权限下很容易触发 UnauthorizedAccessException / 权限相关 Win32 异常,结果就是进程起来了,但窗口初始化没有正常完成。现在已在 b0fa3fd 中改为写到 LocalApplicationData,避免依赖管理员权限。

@JusterZhu
Copy link
Copy Markdown
Collaborator

@copilot 异常原因是什么?

根因是启动阶段就发生了对可执行目录的写操作。PacketView 加载后会走 LoadedCommand -> ResetAction -> CreateDirectory(),原来这里默认在 AppContext.BaseDirectory 下创建 packets/patch,后续还会把 update_config.json 写到同一目录。IDE 调试目录或安装目录如果是受保护位置(例如 Program Files),普通权限下很容易触发 UnauthorizedAccessException / 权限相关 Win32 异常,结果就是进程起来了,但窗口初始化没有正常完成。现在已在 b0fa3fd 中改为写到 LocalApplicationData,避免依赖管理员权限。

现在可以正常运行了吗

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 20, 2026

@copilot 异常原因是什么?

根因是启动阶段就发生了对可执行目录的写操作。PacketView 加载后会走 LoadedCommand -> ResetAction -> CreateDirectory()�...

从当前验证看,这个问题已经修掉了:我刚重新执行了 dotnet build src/GeneralUpdate.Tool.Avalonia.sln,构建通过;这个分支最近一次已完成的 Actions 运行也成功。当前沙箱里没法直接做 Windows 图形界面启动实测,但按现在的代码路径,启动时已经不再往可执行目录写 packets/patchupdate_config.json,所以 IDE 调试和安装版都不应再因为这个权限异常卡住。

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • av-build-tel-api-v1.avaloniaui.net
    • Triggering command: /usr/share/dotnet/dotnet dotnet exec --runtimeconfig /home/REDACTED/.nuget/packages/avalonia.buildservices/0.0.29/tools/netstandard2.0/runtimeconfig.json /home/REDACTED/.nuget/packages/avalonia.buildservices/0.0.29/tools/netstandard2.0/Avalonia.BuildServices.Collector.dll (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@JusterZhu JusterZhu marked this pull request as ready for review May 20, 2026 08:10
Copilot AI review requested due to automatic review settings May 20, 2026 08:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses Avalonia startup/debug reliability issues caused by runtime writes targeting the executable/output directory by moving the default packet workspace to a user-writable location and adjusting where update_config.json is generated.

Changes:

  • Default packet workspace moved from AppContext.BaseDirectory to %LocalAppData%/GeneralUpdate.Tool.Avalonia (with packets/patch beneath it).
  • update_config.json is now written into ConfigModel.PatchDirectory and the directory is created before writing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 357 to 361
var json = JsonConvert.SerializeObject(configInfo, Formatting.Indented);
var configFilePath = Path.Combine(AppContext.BaseDirectory, "update_config.json");
Directory.CreateDirectory(ConfigModel.PatchDirectory);
var configFilePath = Path.Combine(ConfigModel.PatchDirectory, "update_config.json");

await File.WriteAllTextAsync(configFilePath, json, Encoding.UTF8);
Comment on lines +505 to +511
var localApplicationData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
if (string.IsNullOrWhiteSpace(localApplicationData))
{
return AppContext.BaseDirectory;
}

return Path.Combine(localApplicationData, "GeneralUpdate.Tool.Avalonia");
@JusterZhu JusterZhu merged commit 586510e into main May 20, 2026
3 checks passed
@JusterZhu JusterZhu deleted the copilot/fix-debugging-errors-avalonia branch May 20, 2026 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GeneralUpdate.Tool.Avalonia project has debugging errors in IDE.

3 participants