Skip to content

Commit

Permalink
refactor: rewrite the portable mode (#851)
Browse files Browse the repository at this point in the history
  • Loading branch information
love-linger committed Dec 30, 2024
1 parent 093176d commit 0408a32
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ This software creates a folder `$"{System.Environment.SpecialFolder.ApplicationD
| macOS | `${HOME}/Library/Application Support/SourceGit` |

> [!TIP]
> You can open this data storage directory from the main menu.
> * You can open this data storage directory from the main menu `Open Data Storage Directory`.
> * You can create a `data` folder next to the `SourceGit` executable to force this app stores data (user settings, downloaded avatars and crash logs) into it (Portable-Mode). Only works on Windows.
For **Windows** users:

Expand All @@ -81,7 +82,6 @@ For **Windows** users:
scoop install sourcegit
```
* Pre-built binaries can be found in [Releases](https://github.com/sourcegit-scm/sourcegit/releases/latest)
* 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.

For **macOS** users:

Expand Down
15 changes: 7 additions & 8 deletions src/Native/OS.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
#if ENABLE_PORTABLE
using System.Diagnostics;
#endif
using System.IO;

using Avalonia;
Expand Down Expand Up @@ -58,16 +56,17 @@ public static void SetupApp(AppBuilder builder)

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;
var portableDir = Path.Combine(Path.GetDirectoryName(execFile), "data");
if (Directory.Exists(portableDir))
{
DataDir = portableDir;
return;
}
}
#endif

var osAppDataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
if (string.IsNullOrEmpty(osAppDataDir))
DataDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".sourcegit");
Expand Down
4 changes: 0 additions & 4 deletions src/SourceGit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
<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/*" />
Expand Down

0 comments on commit 0408a32

Please sign in to comment.