On Mac I'm getting a bad data storage path only if my game is downloaded from the internet

Hi this is a weird one. The strategy I’ve used for storing save data works in all situations except in the one case where you try to play the game after downloading it from the internet on Mac.

In troubleshooting this I’ve made a simple MonoGame app that just saves/loads a .txt file.

Exporting from Windows for Mac, it works just fine if I transfer the application via a USB stick. We can see the path it’s saving to is relevant to the location of the application on my USB stick called “Ferry”

However if I download this very same application via the internet, it does not work. You can see in the image that the Data Path is not relevant to the .app file. No matter where I put it, it’s this weird private path that I can’t write files to.

I’ve been troubleshooting this quite a bit, and I’m happy I at least know this much. But I have no idea how to properly work around this.

Below is my basic strategy for saving and loading data. Perhaps this is just an issue of using a different strategy that works on all platforms? I’ve tried a few different things, but none of them seem to work.

public static class Storage
{
    // For testing I'm just trying to save and load a number, 
    // normally this would be JSON or something.
    public static SaveData int = 1;
     
    // Get BasePath based on Platform
    public static string BasePath()
    {
        string root = AppDomain.CurrentDomain.BaseDirectory;
        string result = "";

        if (MyGame.Platform == PlatformType.Windows)
        {
            result = $"{root}Content";
        }
        else if (MyGame.Platform == PlatformType.Linux)
        {
            result = $"{root}Content";
        }
        else if (MyGame.Platform == PlatformType.Mac)
        {
            result = $"{root}../Resources/Content";
        }
        else
        {
            result = "";
        }

        return result.Replace("\\", "/");
    }

    public static void Save()
    {
        MyGame.Log("Saving");

        if (!Directory.Exists($"{BasePath()}/Storage"))
        {
            Directory.CreateDirectory($"{BasePath()}/Storage");
        }
        string path = $"{$"{BasePath()}/Storage"}/savedata.txt";
        File.WriteAllText(path, SaveData.ToString());
    }

    public static void Load()
    {
        MyGame.Log("Loading");

        string path = $"{BasePath()}/Storage/savedata.txt";
        if (File.Exists(path))
        {
            string data = File.ReadAllText(path);

            if (!String.IsNullOrWhiteSpace(data))
            {
                SaveData = Int32.Parse(data);
            }
        }
    }
}

Thanks!

Okay I seem to have found a fix. If I change the path to use the Application Support folder instead it will work always on Mac, as far as I know.

        else if (MyGame.Platform == PlatformType.Mac)
        {
            result = $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/Library/Application Support/SimpleMonoGameTest";
        }

Still pretty weird it would only not work if downloaded from the internet lol.