feature: add -p:EnablePortable=true option for dotnet publish command to store app data portable (#834)

This commit is contained in:
leo 2024-12-24 09:23:50 +08:00
parent 7028e08390
commit f53b71bfe7
No known key found for this signature in database
3 changed files with 21 additions and 3 deletions

View file

@ -1,5 +1,8 @@
using System;
using System.Collections.Generic;
#if ENABLE_PORTABLE
using System.Diagnostics;
#endif
using System.IO;
using Avalonia;
@ -55,6 +58,16 @@ namespace SourceGit.Native
public static void SetupDataDir()
{
#if ENABLE_PORTABLE
if (OperatingSystem.IsWindows())
{
var execFile = Process.GetCurrentProcess().MainModule!.FileName;
DataDir = Path.Combine(Path.GetDirectoryName(execFile), "data");
if (!Directory.Exists(DataDir))
Directory.CreateDirectory(DataDir);
return;
}
#endif
var osAppDataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
if (string.IsNullOrEmpty(osAppDataDir))
DataDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".sourcegit");

View file

@ -30,6 +30,10 @@
<DefineConstants>$(DefineConstants);DISABLE_UPDATE_DETECTION</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(EnablePortable)' == 'true'">
<DefineConstants>$(DefineConstants);ENABLE_PORTABLE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<AvaloniaResource Include="App.ico" />
<AvaloniaResource Include="Resources/Fonts/*" />