Use built-in path delim...

This commit is contained in:
Matt Nadareski
2016-04-12 16:33:15 -07:00
parent 25469e0068
commit 1e685ad948
2 changed files with 14 additions and 30 deletions

View File

@@ -22,7 +22,6 @@ namespace SabreTools
private static string _tempDir; private static string _tempDir;
// Extraction and listing related variables // Extraction and listing related variables
private static char _delim;
private static string _baseExtract; private static string _baseExtract;
private static ProcessStartInfo _psi; private static ProcessStartInfo _psi;
private static List<RomData> _roms; private static List<RomData> _roms;
@@ -65,7 +64,7 @@ namespace SabreTools
case "-?": case "-?":
case "--help": case "--help":
Help(); Help();
// Build.Help(); //Build.Help();
return; return;
case "-m": case "-m":
case "--noMD5": case "--noMD5":
@@ -120,27 +119,18 @@ namespace SabreTools
if (inputs.Count == 0) if (inputs.Count == 0)
{ {
Help(); Help();
// Build.Help(); //Build.Help();
return; return;
} }
// Determine the deliminator that is to be used
if (Environment.CurrentDirectory.Contains("\\"))
{
_delim = '\\';
}
else
{
_delim = '/';
}
// Set 7za required variables // Set 7za required variables
_isMono = (Type.GetType("Mono.Runtime") != null); _isMono = (Type.GetType("Mono.Runtime") != null);
_7zPath = Environment.CurrentDirectory + _delim + "7z" + (Environment.Is64BitOperatingSystem && !_isMono ? _delim + "x64" : "") + _delim; _7zPath = Environment.CurrentDirectory + Path.DirectorySeparatorChar + "7z" + (Environment.Is64BitOperatingSystem && !_isMono ? Path.DirectorySeparatorChar + "x64" : "") + Path.DirectorySeparatorChar;
_psi = new ProcessStartInfo _psi = new ProcessStartInfo
{ {
Arguments = "", Arguments = "",
FileName = (_isMono ? "mono" : _7zPath + "7za.exe"), FileName = (_isMono ? "mono" : _7zPath + "7za.exe"),
//FileName = (Build.MonoEnvironment ? "mono" : SevenZipPath + "7za.exe"),
RedirectStandardError = true, RedirectStandardError = true,
RedirectStandardOutput = true, RedirectStandardOutput = true,
UseShellExecute = false, UseShellExecute = false,
@@ -153,9 +143,10 @@ namespace SabreTools
foreach (string path in inputs) foreach (string path in inputs)
{ {
// Set local paths and vars // Set local paths and vars
_tempDir = Environment.CurrentDirectory + _delim + "temp" + DateTime.Now.ToString("yyyyMMddHHmmss") + _delim; _tempDir = Environment.CurrentDirectory + Path.DirectorySeparatorChar + "temp" + DateTime.Now.ToString("yyyyMMddHHmmss") + Path.DirectorySeparatorChar;
_basePath = (args.Length == 0 ? Environment.CurrentDirectory + _delim : (File.Exists(path) ? path : path + _delim)); _basePath = (File.Exists(path) ? path : path + Path.DirectorySeparatorChar);
_baseExtract = (_isMono ? _7zPath + "7za.exe " : "") + "x -o\"" + _tempDir + "\""; _baseExtract = (_isMono ? _7zPath + "7za.exe " : "") + "x -o\"" + _tempDir + "\"";
//_baseExtract = (Build.MonoEnvironment ? SevenZipPath + "7za.exe " : "") + "x -o\"" + _tempDir + "\"";
// This is where the main loop would go // This is where the main loop would go
if (File.Exists(_basePath)) if (File.Exists(_basePath))
@@ -191,9 +182,9 @@ namespace SabreTools
// the possibiliites for different ways to generate a DAT from multiple things // the possibiliites for different ways to generate a DAT from multiple things
// Double check to see what it needs to be named // Double check to see what it needs to be named
string[] splitPath = _basePath.Split(_delim); string[] splitPath = _basePath.Split(Path.DirectorySeparatorChar);
_name = (_name == "" ? (inputs.Count > 1 ? Environment.CurrentDirectory.Split(_delim).Last() : _name = (_name == "" ? (inputs.Count > 1 ? Environment.CurrentDirectory.Split(Path.DirectorySeparatorChar).Last() :
(_basePath.EndsWith(_delim.ToString()) ? splitPath[splitPath.Length - 2] : splitPath.Last())) : _name); (_basePath.EndsWith(Path.DirectorySeparatorChar.ToString()) ? splitPath[splitPath.Length - 2] : splitPath.Last())) : _name);
_desc = (_desc == "" ? _name + " (" + _date + ")" : _desc); _desc = (_desc == "" ? _name + " (" + _date + ")" : _desc);
// Now write it all out as a DAT // Now write it all out as a DAT
@@ -409,7 +400,7 @@ Options:
} }
} }
string actualroot = (item == _basePath ? "Default" : Path.GetDirectoryName(item.Remove(0, _basePath.Length)).Split(_delim)[0]); string actualroot = (item == _basePath ? "Default" : Path.GetDirectoryName(item.Remove(0, _basePath.Length)).Split(Path.DirectorySeparatorChar)[0]);
actualroot = (actualroot == "" ? "Default" : actualroot); actualroot = (actualroot == "" ? "Default" : actualroot);
string actualitem = (item == _basePath ? item : item.Remove(0, _basePath.Length).Remove(0, (actualroot != "Default" ? actualroot.Length + 1 : 0))); string actualitem = (item == _basePath ? item : item.Remove(0, _basePath.Length).Remove(0, (actualroot != "Default" ? actualroot.Length + 1 : 0)));

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Reflection; using System.Reflection;
namespace SabreTools.Helper namespace SabreTools.Helper
@@ -19,15 +20,7 @@ namespace SabreTools.Helper
/// </summary> /// </summary>
public static bool MonoEnvironment public static bool MonoEnvironment
{ {
get { return (Type.GetType("Mono.Runtime") != null); } get { return (Type.GetType("Mono.Runtime") != null); }
}
/// <summary>
/// The path delimiter for the current environment
/// </summary>
public static char PathDelim
{
get { return (Environment.CurrentDirectory.Contains("\\") ? '\\' : '/'); }
} }
/// <summary> /// <summary>
@@ -37,7 +30,7 @@ namespace SabreTools.Helper
{ {
get get
{ {
return Environment.CurrentDirectory + PathDelim + (!MonoEnvironment && Environment.Is64BitOperatingSystem ? "x64" : "x86") + PathDelim; return Environment.CurrentDirectory + Path.DirectorySeparatorChar + (!MonoEnvironment && Environment.Is64BitOperatingSystem ? "x64" : "x86") + Path.DirectorySeparatorChar;
} }
} }