Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] Is there any plan following GetFolderPath changes in .NET 8? #522

Open
anatawa12 opened this issue Aug 27, 2024 · 7 comments
Open
Labels

Comments

@anatawa12
Copy link
Contributor

In current VPM CLI and vpm-resplver, it looks System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) is used for base path of settings.json and other VCC and VPM related files.

However, .NET 6 is being dead and .NET 8 is here, and I think VPM CLI will need to move to .NET 8 soon.
However, in .NET 8, System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) will return other directory on macOS.
This will cause compatibility problem in my tool and future VPM so I opened this issue.

As a command-line tools, it's common to use $XDG_DATA_HOME or $HOME/.local/share on macOS and Unity mono still returns them for Environment.GetFolderPath, and, I think it's better to use $XDG_DATA_HOME on macOS.

For more information about breaking changes in .NET 8, please refer https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/8.0/getfolderpath-unix and dotnet/runtime#68610

@orels1
Copy link
Contributor

orels1 commented Aug 27, 2024

Thank you for flagging that. I added this to our notes on the .NET 8 upgrade.
We will most likely maintain the current $HOME/.local/share behavior.

I will keep this thread updated with details as I have them

@orels1
Copy link
Contributor

orels1 commented Sep 19, 2024

Confirming that the plan is to maintain $HOME/.local/share on macOS

@orels1
Copy link
Contributor

orels1 commented Sep 24, 2024

VCC and VCC CLI are moving to .NET 6 with VCC 2.4.0 (next major release) which will maintain the existing path.

@orels1 orels1 added vpm-cli Issues related to the CLI Available in future release and removed Tracked This issue is tracked by the VRChat team labels Sep 24, 2024
@orels1
Copy link
Contributor

orels1 commented Oct 11, 2024

The CLI pre-release using .NET 8 and pathing fix is available now

https://www.nuget.org/packages/VRChat.VPM.CLI#versions-body-tab

dotnet tool install -g VRChat.VPM.CLI --version 0.1.28-beta.1

If everything goes well - this should go live in the near future

@anatawa12
Copy link
Contributor Author

It looks vpm cli 0.1.28-beta.1 is using './$HOME/.local/share/VRChatCreatorCompanion/settings.json' relative to working directory of vpm cli instead of .local/share/VRChatCreatorCompanion/settings.json relative to user home directory, which is stored in HOME environment variable.

In general, *nix platform can use any character in file system entry name, so when you request OS to access directory named $HOME, OS simply checks file system entry named $HOME in the current working directory.
Expanding environment variable (or others) is our responsibility and we have to expand environment variable.

Also I found that VPM Cli is using $HOME/.local/share directory, but we should try XDG_DATA_HOME before trying XDG_DATA_HOME.
Here's example code to get correct VRChatCreatorCompanion for *nix platform including macOS and linux.
(This code is my own code and putting here with CC0 license)

#nullable enable
using System;
using System.IO;
using System.Runtime.InteropServices;

string GetVCCDirectory()
{
    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
    {
        // For windows platform, we use the %LOCALAPPDATA%\VRChatCreatorCompanion directory
        return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "VRChatCreatorCompanion");
    }
    else
    {
        // For *nix platform, we use the $XDG_DATA_HOME/VRChatCreatorCompanion directory
        var xdgDataHome = Environment.GetEnvironmentVariable("XDG_DATA_HOME");

        if (string.IsNullOrEmpty(xdgDataHome))
        {
            // if XDG_DATA_HOME is not set, we use the default value
            // Default value of XDG_DATA_HOME is $HOME/.local/share
            // We should use default value even if XDG_DATA_HOME is defined with empty value.
            // Please read https://specifications.freedesktop.org/basedir-spec/latest/#variables
            // for more information.

            var home = Environment.GetEnvironmentVariable("HOME");
            if (string.IsNullOrEmpty(home)) throw new InvalidOperationException("HOME is not set");
            xdgDataHome = Path.Combine(home, ".local", "share");
        }

        return Path.Combine(xdgDataHome, "VRChatCreatorCompanion");
    }
}

@orels1
Copy link
Contributor

orels1 commented Oct 12, 2024

This should be fixed in the 0.1.28-beta.2
Tested on macOS

@anatawa12
Copy link
Contributor Author

it looks working well in 0.1.28-beta.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants