Improve OS Paths
This commit is contained in:
parent
0e66c1421c
commit
687fbdbde6
@ -9,32 +9,71 @@ namespace TrueCraft.Core
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var xdg_config_home = Environment.GetEnvironmentVariable("XDG_CONFIG_HOME");
|
string os;
|
||||||
string config = null;
|
// FIXME: SDL_GetPlatform() is nicer! -flibit
|
||||||
if (xdg_config_home != null)
|
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
|
||||||
{
|
{
|
||||||
config = Path.Combine(xdg_config_home, "truecraft");
|
os = "Windows";
|
||||||
if (Directory.Exists(config))
|
|
||||||
return config;
|
|
||||||
}
|
}
|
||||||
var appdata = Path.Combine(
|
else
|
||||||
|
{
|
||||||
|
if (Environment.CurrentDirectory.StartsWith("/Users/"))
|
||||||
|
{
|
||||||
|
os = "Mac OS X";
|
||||||
|
}
|
||||||
|
else // FIXME: Assumption! -flibit
|
||||||
|
{
|
||||||
|
os = "Linux";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
string result;
|
||||||
|
if (os.Equals("Windows"))
|
||||||
|
{
|
||||||
|
result = Path.Combine(
|
||||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||||
"truecraft");
|
"truecraft"
|
||||||
if (Directory.Exists(appdata))
|
);
|
||||||
return appdata;
|
|
||||||
var userprofile = Path.Combine(
|
|
||||||
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
|
|
||||||
".truecraft");
|
|
||||||
if (Directory.Exists(userprofile))
|
|
||||||
return userprofile;
|
|
||||||
// At this point, there's no existing data to choose from, so use the best option
|
|
||||||
if (config != null)
|
|
||||||
{
|
|
||||||
Directory.CreateDirectory(config);
|
|
||||||
return config;
|
|
||||||
}
|
}
|
||||||
Directory.CreateDirectory(appdata);
|
else if (os.Equals("Mac OS X"))
|
||||||
return appdata;
|
{
|
||||||
|
result = Environment.GetEnvironmentVariable("HOME");
|
||||||
|
if (String.IsNullOrEmpty(result))
|
||||||
|
{
|
||||||
|
result = "./"; // Oh well.
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result += "/Library/Application Support/truecraft";
|
||||||
|
}
|
||||||
|
result = Path.Combine(result, "truecraft");
|
||||||
|
}
|
||||||
|
else if (os.Equals("Linux"))
|
||||||
|
{
|
||||||
|
// Assuming a non-OSX Unix platform will follow the XDG. Which it should.
|
||||||
|
result = Environment.GetEnvironmentVariable("XDG_CONFIG_HOME");
|
||||||
|
if (String.IsNullOrEmpty(result))
|
||||||
|
{
|
||||||
|
result = Environment.GetEnvironmentVariable("HOME");
|
||||||
|
if (String.IsNullOrEmpty(result))
|
||||||
|
{
|
||||||
|
result = "./"; // Oh well.
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result += "/.config/";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result = Path.Combine(result, "truecraft");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new NotSupportedException("Unhandled SDL2 platform!");
|
||||||
|
}
|
||||||
|
if (!Directory.Exists(result))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user