Closed InkyQuill closed 6 years ago
It will take me 24h to upload the fix,
for the time being add event handler before calling Load to BeforeSave
and BeforeLoad
which passes ref string destinition
which is the path that is used for saving.
e.g.
private static Settings Settings { get; } = JsonSettings.Load<Settings>("memory.jsn", ConfigSettings);
private static void ConfigSettings(Settings settings) {
settings.BeforeLoad += (ref string destinition) => destinition = destinition.Replace('\\', '/');
settings.BeforeSave += (ref string destinition) => destinition = destinition.Replace('\\', '/');
}
Let me know if it worked, I haven't tested the library under Linux or OSX so feel free to flood me with issues and keep me posted ! Thanks !
Well, I just forked your version and rewrote the function like this:
path = path
.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
if (forEquality) {
#if CROSSPLATFORM
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
path = path.Replace('/', '\\');
path = path.ToUpperInvariant();
}
#else
path = path.ToUpperInvariant();
#endif
}
if (path.Contains("\\") || path.Contains("/"))
if (Uri.IsWellFormedUriString(path, UriKind.RelativeOrAbsolute))
try {
path = Path.GetFullPath(new Uri(path).LocalPath);
} catch { }
#if CROSSPLATFORM
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
//is root, fix.
if ((path.Length == 2) && (path[1] == ':') && char.IsLetter(path[0]))
path = path + "\\";
}
#endif
return path;
}
Everything else works like it should as it is not platform-specific.
I've modified your version a little and uploaded it to nuget as version 1.0.6. Thanks for helping 👍
As it replaces all
/
to\
, path becomes wrong on linux: