Skip to content

Commit 70a98b8

Browse files
committed
Fix: Shrinker.Avalonia - Use proper platform path for loading/saving app settings.
1 parent c9171b7 commit 70a98b8

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

ShaderShrinker/Shrinker.Avalonia/UserSettings.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.IO;
33
using System.Reflection;
4+
using System.Runtime.InteropServices;
45
using Newtonsoft.Json;
56
using Shrinker.Parser;
67
// ReSharper disable UnusedMember.Global
@@ -32,8 +33,7 @@ private UserSettings()
3233
companyName = RemoveInvalidChars(companyName);
3334
productName = RemoveInvalidChars(productName);
3435

35-
var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
36-
var appDirectory = Path.Combine(appData, companyName, productName);
36+
var appDirectory = Path.Combine(GetAppDataPath(), companyName, productName);
3737
Directory.CreateDirectory(appDirectory);
3838
m_filePath = Path.Combine(appDirectory, "settings.json");
3939

@@ -48,6 +48,27 @@ private string RemoveInvalidChars(string s)
4848
return s;
4949
}
5050

51+
private static string GetAppDataPath()
52+
{
53+
var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
54+
55+
if (string.IsNullOrEmpty(appDataPath))
56+
{
57+
var homePath = Environment.GetEnvironmentVariable("HOME");
58+
if (string.IsNullOrEmpty(homePath))
59+
{
60+
// Fallback to using ~ if HOME environment variable is not set
61+
homePath = "~";
62+
}
63+
64+
appDataPath = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? Path.Combine(homePath, "Library", "Preferences") : homePath;
65+
}
66+
67+
Directory.CreateDirectory(appDataPath);
68+
69+
return appDataPath;
70+
}
71+
5172
public void Dispose() =>
5273
File.WriteAllText(m_filePath, JsonConvert.SerializeObject(this, Formatting.Indented));
5374
}

ShaderShrinker/Shrinker.Avalonia/packageMe.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
# Define variables
44
APP_NAME="GLSL Shader Shrinker"
55
APP_VERSION="2.0.0"
6+
APP_VERSION_SHORT="2.0"
67
EXECUTABLE_NAME="Shrinker.Avalonia"
78
BUNDLE_NAME="GLSLShaderShrinker.app"
89
IDENTIFIER="com.deanedis.glslshadershrinker"
910

1011
# Step 1: Publish the application
1112
rm -rf bin/Release/net7.0/osx-arm64/publish/
12-
dotnet publish -c Release -r osx-arm64 --self-contained -p:PublishSingleFile=true
13+
dotnet publish -c Release -r osx-arm64 --self-contained true -property:Configuration=Release -p:UseAppHost=true
1314

1415
# Step 2: Create the app bundle structure
1516
mkdir -p "$BUNDLE_NAME/Contents/MacOS"
@@ -38,7 +39,7 @@ cat > "$BUNDLE_NAME/Contents/Info.plist" << EOF
3839
<key>CFBundleVersion</key>
3940
<string>$APP_VERSION</string>
4041
<key>CFBundleShortVersionString</key>
41-
<string>$APP_VERSION</string>
42+
<string>$APP_VERSION_SHORT</string>
4243
<key>LSMinimumSystemVersion</key>
4344
<string>10.12</string>
4445
<key>CFBundleSignature</key>
@@ -52,4 +53,3 @@ EOF
5253
cp Assets/Icon.icns "$BUNDLE_NAME/Contents/Resources/Icon.icns"
5354

5455
echo "App bundle $BUNDLE_NAME created."
55-

0 commit comments

Comments
 (0)