Skip to content

Commit f53b71b

Browse files
committed
feature: add -p:EnablePortable=true option for dotnet publish command to store app data portable (#834)
1 parent 7028e08 commit f53b71b

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ This software creates a folder `$"{System.Environment.SpecialFolder.ApplicationD
6464
| macOS | `${HOME}/Library/Application Support/SourceGit` |
6565

6666
> [!TIP]
67-
> You can open the app data dir from the main menu.
67+
> You can open this data storage directory from the main menu.
6868
6969
For **Windows** users:
7070

@@ -80,7 +80,8 @@ For **Windows** users:
8080
scoop bucket add extras
8181
scoop install sourcegit
8282
```
83-
* Portable versions can be found in [Releases](https://github.com/sourcegit-scm/sourcegit/releases/latest)
83+
* Pre-built binaries can be found in [Releases](https://github.com/sourcegit-scm/sourcegit/releases/latest)
84+
* You can run `dotnet publish -c Release -r win-x64 -p:EnablePortable=true -o $YOUR_PUBLISH_DIR .\src\SourceGit.csproj` to build a portable version.
8485

8586
For **macOS** users:
8687

@@ -159,7 +160,7 @@ This app supports open repository in external tools listed in the table below.
159160

160161
> [!NOTE]
161162
> This app will try to find those tools based on some pre-defined or expected locations automatically. If you are using one portable version of these tools, it will not be detected by this app.
162-
> To solve this problem you can add a file named `external_editors.json` in app data dir and provide the path directly. For example:
163+
> To solve this problem you can add a file named `external_editors.json` in app data storage directory and provide the path directly. For example:
163164
```json
164165
{
165166
"tools": {

src/Native/OS.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using System;
22
using System.Collections.Generic;
3+
#if ENABLE_PORTABLE
4+
using System.Diagnostics;
5+
#endif
36
using System.IO;
47

58
using Avalonia;
@@ -55,6 +58,16 @@ public static void SetupApp(AppBuilder builder)
5558

5659
public static void SetupDataDir()
5760
{
61+
#if ENABLE_PORTABLE
62+
if (OperatingSystem.IsWindows())
63+
{
64+
var execFile = Process.GetCurrentProcess().MainModule!.FileName;
65+
DataDir = Path.Combine(Path.GetDirectoryName(execFile), "data");
66+
if (!Directory.Exists(DataDir))
67+
Directory.CreateDirectory(DataDir);
68+
return;
69+
}
70+
#endif
5871
var osAppDataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
5972
if (string.IsNullOrEmpty(osAppDataDir))
6073
DataDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".sourcegit");

src/SourceGit.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
<DefineConstants>$(DefineConstants);DISABLE_UPDATE_DETECTION</DefineConstants>
3131
</PropertyGroup>
3232

33+
<PropertyGroup Condition="'$(EnablePortable)' == 'true'">
34+
<DefineConstants>$(DefineConstants);ENABLE_PORTABLE</DefineConstants>
35+
</PropertyGroup>
36+
3337
<ItemGroup>
3438
<AvaloniaResource Include="App.ico" />
3539
<AvaloniaResource Include="Resources/Fonts/*" />

0 commit comments

Comments
 (0)