IOUtils Changes

- added new NormalizeFolder method to format the path parameter, so that it is formed correctly.
If the path is a local root path (eg. d:) then it must end with \\.
If the path is not a root path, or is a Unc path, then any ending \\ must be removed.

This fix was due to an issue with the previous code, as it kept appending a \ to the end when the path was a Unc path.
This commit is contained in:
Brett Hewitson 2022-05-09 00:25:27 +10:00
parent 14cff018cd
commit bbaad6099f
9 changed files with 210 additions and 222 deletions

View file

@ -56,38 +56,22 @@ namespace ServerManagerTool
if (!string.IsNullOrWhiteSpace(Config.Default.DataPath))
{
var root = Path.GetPathRoot(Config.Default.DataPath);
if (!root.EndsWith("\\"))
{
Config.Default.DataPath = Config.Default.DataPath.Replace(root, root + "\\");
}
Config.Default.DataPath = IOUtils.NormalizeFolder(Config.Default.DataPath);
}
if (!string.IsNullOrWhiteSpace(Config.Default.ConfigPath))
{
var root = Path.GetPathRoot(Config.Default.ConfigPath);
if (!root.EndsWith("\\"))
{
Config.Default.ConfigPath = Config.Default.ConfigPath.Replace(root, root + "\\");
}
Config.Default.ConfigPath = IOUtils.NormalizeFolder(Config.Default.ConfigPath);
}
if (!string.IsNullOrWhiteSpace(Config.Default.BackupPath))
{
var root = Path.GetPathRoot(Config.Default.BackupPath);
if (!root.EndsWith("\\"))
{
Config.Default.BackupPath = Config.Default.BackupPath.Replace(root, root + "\\");
}
Config.Default.BackupPath = IOUtils.NormalizeFolder(Config.Default.BackupPath);
}
if (!string.IsNullOrWhiteSpace(Config.Default.AutoUpdate_CacheDir))
{
var root = Path.GetPathRoot(Config.Default.AutoUpdate_CacheDir);
if (!root.EndsWith("\\"))
{
Config.Default.AutoUpdate_CacheDir = Config.Default.AutoUpdate_CacheDir.Replace(root, root + "\\");
}
Config.Default.AutoUpdate_CacheDir = IOUtils.NormalizeFolder(Config.Default.AutoUpdate_CacheDir);
}
App.Instance = this;