mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
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:
@@ -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
|
||||
{
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
24
SS14.Shared/Utility/PlatformTools.cs
Normal file
24
SS14.Shared/Utility/PlatformTools.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user