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

Get correct ApplicationData dir on linux/wine #2298

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Jannify
Copy link
Member

@Jannify Jannify commented Mar 8, 2025

When inside the wine environment Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) points to the very nested virtual wine folder. With this change Nitrox detects the wine environment and returns the dir normally used on linux.

Comment on lines +72 to +83
string applicationData;

/// <summary>
/// Tries to get the launcher path that was previously saved by other Nitrox code.
/// </summary>
public static string LauncherPath
// On linux Environment.SpecialFolder.ApplicationData returns the windows version inside wine, this bypasses that
string homeInWine = Environment.GetEnvironmentVariable("WINEHOMEDIR");
if (homeInWine != null && Directory.Exists(homeInWine[4..])) // WINEHOMEDIR is prefixed with \??\
{
applicationData = Path.Combine(homeInWine[4..], ".config");
}
else
{
applicationData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
}
Copy link
Collaborator

@Measurity Measurity Mar 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add check for IndexOutOfRange errors.

I'm assuming .config folder always exists in winehome:

Suggested change
string applicationData;
/// <summary>
/// Tries to get the launcher path that was previously saved by other Nitrox code.
/// </summary>
public static string LauncherPath
// On linux Environment.SpecialFolder.ApplicationData returns the windows version inside wine, this bypasses that
string homeInWine = Environment.GetEnvironmentVariable("WINEHOMEDIR");
if (homeInWine != null && Directory.Exists(homeInWine[4..])) // WINEHOMEDIR is prefixed with \??\
{
applicationData = Path.Combine(homeInWine[4..], ".config");
}
else
{
applicationData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
}
string applicationData = null;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
// On linux Environment.SpecialFolder.ApplicationData returns the Windows version inside wine, this bypasses that
string homeInWineEnv = Environment.GetEnvironmentVariable("WINEHOMEDIR");
if (homeInWineEnv is { Length: > 4 } && homeInWineEnv[4..] is {} homeInWine) // WINEHOMEDIR is prefixed with \??\
{
if (Directory.Exists(homeInWine))
{
applicationData = Path.Combine(homeInWine, ".config");
}
}
}
if (!Directory.Exists(applicationData))
{
applicationData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
}

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

Successfully merging this pull request may close these issues.

2 participants