fix various poorly constructed auxfile paths and paths with invalid characters

This commit is contained in:
zeromus 2011-06-07 21:10:30 +00:00
parent 232d8c91f6
commit 9ea6a0b7a8
5 changed files with 50 additions and 32 deletions

View File

@ -4,7 +4,11 @@ using System.IO;
namespace BizHawk namespace BizHawk
{ {
public sealed class Game : IGame /// <summary>
/// THIS CLASS IS NOT USED RIGHT NOW.
/// I dont think it is architecturally going to last.
/// </summary>
public sealed class Game //: IGame
{ {
public byte[] RomData; public byte[] RomData;
private string name; private string name;

View File

@ -6,8 +6,10 @@ namespace BizHawk
{ {
/// <summary> /// <summary>
/// Loader for .SMD Genesis ROM format (Super Magic Drive) /// Loader for .SMD Genesis ROM format (Super Magic Drive)
/// THIS CLASS IS NOT USED RIGHT NOW
/// I dont think it is architecturally going to last.
/// </summary> /// </summary>
public sealed class SmdGame : IGame public sealed class SmdGame //: IGame
{ {
public byte[] RomData; public byte[] RomData;
private string name; private string name;

View File

@ -7,6 +7,11 @@ namespace BizHawk
byte[] GetRomData(); byte[] GetRomData();
byte[] GetFileData(); byte[] GetFileData();
IList<string> GetOptions(); IList<string> GetOptions();
//only use this for cosmetic purposes
string Name { get; } string Name { get; }
//use this for path-building purposes
string FilesystemSafeName { get; }
} }
} }

View File

@ -12,6 +12,7 @@ namespace BizHawk.MultiClient
public string System; public string System;
private string name; private string name;
private string filesystemSafeName;
private List<string> options; private List<string> options;
private const int BankSize = 4096; private const int BankSize = 4096;
@ -42,6 +43,11 @@ namespace BizHawk.MultiClient
options = new List<string>(info.GetOptions()); options = new List<string>(info.GetOptions());
CheckForPatchOptions(); CheckForPatchOptions();
//build a safe filesystem name for use in auxilary files (savestates, saveram, etc)
filesystemSafeName = file.CanonicalName.Replace("|", "+");
filesystemSafeName = Path.Combine(Path.GetDirectoryName(filesystemSafeName), Path.GetFileNameWithoutExtension(filesystemSafeName));
if (patch != null) if (patch != null)
{ {
using (var patchFile = new HawkFile(patch)) using (var patchFile = new HawkFile(patch))
@ -104,6 +110,7 @@ namespace BizHawk.MultiClient
public byte[] GetFileData() { return FileData; } public byte[] GetFileData() { return FileData; }
public IList<string> GetOptions() { return options; } public IList<string> GetOptions() { return options; }
public string Name { get { return name; } set { name = value; } } public string Name { get { return name; } set { name = value; } }
public string FilesystemSafeName { get { return filesystemSafeName; } }
public string SaveRamPath public string SaveRamPath
{ {
@ -111,15 +118,15 @@ namespace BizHawk.MultiClient
{ {
switch (System) switch (System)
{ {
case "SMS": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathSMSSaveRAM, "SMS"), Name + ".SaveRAM"); case "SMS": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathSMSSaveRAM, "SMS"), filesystemSafeName + ".SaveRAM");
case "GG": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathGGSaveRAM, "GG"), Name + ".SaveRAM"); case "GG": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathGGSaveRAM, "GG"), filesystemSafeName + ".SaveRAM");
case "SG": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathSGSaveRAM, "SG"), Name + ".SaveRAM"); case "SG": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathSGSaveRAM, "SG"), filesystemSafeName + ".SaveRAM");
case "SGX": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathPCESaveRAM, "PCE"), Name + ".SaveRAM"); case "SGX": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathPCESaveRAM, "PCE"), filesystemSafeName + ".SaveRAM");
case "PCE": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathPCESaveRAM, "PCE"), Name + ".SaveRAM"); case "PCE": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathPCESaveRAM, "PCE"), filesystemSafeName + ".SaveRAM");
case "GB": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathGBSaveRAM, "GB"), Name + ".SaveRAM"); case "GB": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathGBSaveRAM, "GB"), filesystemSafeName + ".SaveRAM");
case "GEN": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathGenesisSaveRAM, "GEN"), Name + ".SaveRAM"); case "GEN": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathGenesisSaveRAM, "GEN"), filesystemSafeName + ".SaveRAM");
case "NES": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathNESSaveRAM, "NES"), Name + ".SaveRAM"); case "NES": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathNESSaveRAM, "NES"), filesystemSafeName + ".SaveRAM");
case "TI83": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathTI83SaveRAM, "TI83"), Name + ".SaveRAM"); case "TI83": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathTI83SaveRAM, "TI83"), filesystemSafeName + ".SaveRAM");
default: return ""; default: return "";
} }
} }
@ -130,19 +137,19 @@ namespace BizHawk.MultiClient
get get
{ {
string Bind = ""; string Bind = "";
if (Global.Config.BindSavestatesToMovies && Global.MainForm.UserMovie.GetMovieMode() != MOVIEMODE.FINISHED) //TODO: what about movie finished? if (Global.Config.BindSavestatesToMovies && Global.MainForm.UserMovie.GetMovieMode() != MOVIEMODE.FINISHED && Global.MainForm.UserMovie.GetMovieMode() != MOVIEMODE.INACTIVE) //TODO: what about movie finished?
Bind += " - " + Path.GetFileNameWithoutExtension(Global.MainForm.UserMovie.GetFilePath()); Bind += " - " + Path.GetFileNameWithoutExtension(Global.MainForm.UserMovie.GetFilePath());
switch (System) switch (System)
{ {
case "SMS": return PathManager.MakeAbsolutePath(Global.Config.PathSMSSavestates, "SMS") + "/" + Name + Bind; case "SMS": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathSMSSavestates, "SMS") ,filesystemSafeName + Bind);
case "GG": return PathManager.MakeAbsolutePath(Global.Config.PathGGSavestates, "GG") + "/" + Name + Bind; case "GG": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathGGSavestates, "GG") ,filesystemSafeName + Bind);
case "SG": return PathManager.MakeAbsolutePath(Global.Config.PathSGSavestates, "SG") + "/" + Name + Bind; case "SG": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathSGSavestates, "SG") ,filesystemSafeName + Bind);
case "PCE": return PathManager.MakeAbsolutePath(Global.Config.PathPCESavestates, "PCE") + "/" + Name + Bind; case "PCE": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathPCESavestates, "PCE") ,filesystemSafeName + Bind);
case "SGX": return PathManager.MakeAbsolutePath(Global.Config.PathPCESavestates, "PCE") + "/" + Name + Bind; case "SGX": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathPCESavestates, "PCE") ,filesystemSafeName + Bind);
case "GB": return PathManager.MakeAbsolutePath(Global.Config.PathGBSavestates, "GB") + "/" + Name + Bind; case "GB": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathGBSavestates, "GB") ,filesystemSafeName + Bind);
case "GEN": return PathManager.MakeAbsolutePath(Global.Config.PathGenesisSavestates, "GEN") + "/" + Name + Bind; case "GEN": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathGenesisSavestates, "GEN") ,filesystemSafeName + Bind);
case "NES": return PathManager.MakeAbsolutePath(Global.Config.PathNESSavestates, "NES") + "/" + Name + Bind; case "NES": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathNESSavestates, "NES") ,filesystemSafeName + Bind);
case "TI83": return PathManager.MakeAbsolutePath(Global.Config.PathTI83Savestates, "TI83") + "/" + Name + Bind; case "TI83": return Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathTI83Savestates, "TI83"), filesystemSafeName + Bind);
default: return ""; default: return "";
} }
@ -156,15 +163,15 @@ namespace BizHawk.MultiClient
{ {
switch (System) switch (System)
{ {
case "SMS": return "SMS/Movie/" + Name; case "SMS": return "SMS/Movie/" + filesystemSafeName;
case "GG": return "Game Gear/Movie/" + Name; case "GG": return "Game Gear/Movie/" + filesystemSafeName;
case "SG": return "SG-1000/Movie/" + Name; case "SG": return "SG-1000/Movie/" + filesystemSafeName;
case "PCE": return "TurboGrafx/Movie/" + Name; case "PCE": return "TurboGrafx/Movie/" + filesystemSafeName;
case "SGX": return "TurboGrafx/Movie/" + Name; case "SGX": return "TurboGrafx/Movie/" + filesystemSafeName;
case "GB": return "Gameboy/Movie/" + Name; case "GB": return "Gameboy/Movie/" + filesystemSafeName;
case "GEN": return "Genesis/Movie/" + Name; case "GEN": return "Genesis/Movie/" + filesystemSafeName;
case "NES": return "NES/Movie/" + Name; case "NES": return "NES/Movie/" + filesystemSafeName;
case "TI83": return "TI83/Movie/" + Name; case "TI83": return "TI83/Movie/" + filesystemSafeName;
default: return ""; default: return "";
} }
} }

View File

@ -58,7 +58,7 @@ namespace BizHawk.MultiClient
private string MakeDefaultFilename() private string MakeDefaultFilename()
{ {
return GetCheatsPath() + "\\" + Global.Game.Name + ".cht"; return Path.Combine(GetCheatsPath(), Global.Game.FilesystemSafeName + ".cht");
} }
private void ClearFields() private void ClearFields()