Refactor path sanitization

ZIPfiles use windows paths, sanitize the pathnames as they come out.
Move the code into SS14.Shared.PlatformTools, and add that to the
prebuild.xml
This commit is contained in:
Harik
2015-03-25 07:37:17 -04:00
parent c1528e5c97
commit 4034347138
4 changed files with 29 additions and 12 deletions

View File

@@ -22,18 +22,8 @@ namespace SS14.Client.Services.Configuration
configReader.Close();
Configuration = config;
// sanitize the pathname in config.xml for the current OS
// N.B.: You cannot use Path.DirectorySeparatorChar and
// Path.AltDirectorySeparatorChar here, because on some platforms
// they are the same. Mono/linux has both as '/', for example.
// Hardcode the only platforms we care about.
// FIXME: Move this into SS14.Shared.PlatformIndependant or similar.
config.ResourcePack=SS14.Shared.Utility.PlatformTools.SanePath(config.ResourcePack);
var separators = new char [] { '/', '\\' };
string newpath = "";
foreach (string tmp in config.ResourcePack.Split(separators))
newpath = Path.Combine (newpath, tmp);
config.ResourcePack = newpath;
}
else
{

View File

@@ -401,7 +401,9 @@ namespace SS14.Client.Services.Resources
string[] splitLine = line.Split(',');
string[] fullPath = Regex.Split(splitLine[0], "\t");
string originalName = Path.GetFileNameWithoutExtension(fullPath[0]).ToLowerInvariant();
string PlatformPathname = SS14.Shared.Utility.PlatformTools.SanePath(fullPath[0]);
string originalName = Path.GetFileNameWithoutExtension(PlatformPathname).ToLowerInvariant();
//The name of the original picture without extension, before it became part of the atlas.
//This will be the name we can find this under in our Resource lists.

View File

@@ -0,0 +1,24 @@
using System;
using System.IO;
namespace SS14.Shared.Utility
{
public class PlatformTools
{
public static string SanePath(String pathname)
{
// sanitize the pathname in config.xml for the current OS
// N.B.: You cannot use Path.DirectorySeparatorChar and
// Path.AltDirectorySeparatorChar here, because on some platforms
// they are the same. Mono/linux has both as '/', for example.
// Hardcode the only platforms we care about.
var separators = new char [] { '/', '\\' };
string newpath = "";
foreach (string tmp in pathname.Split(separators))
newpath = Path.Combine (newpath, tmp);
return newpath;
}
}
}

View File

@@ -98,6 +98,7 @@
<File buildAction="Compile">Utility/CommandParsing.cs</File>
<File buildAction="Compile">Utility/NetParamsPacker.cs</File>
<File buildAction="Compile">Utility/PlatformDetector.cs</File>
<File buildAction="Compile">Utility/PlatformTools.cs</File>
<File buildAction="Compile">Utility/RandomString.cs</File>
<File buildAction="Compile">Utility/Range.cs</File>
<File buildAction="Compile">Utility/unZipString.cs</File>