Merge pull request #1517 from TASVideos/interp_emucommon

Use string interpolation in BizHawk.Emulation.Common and BizHawk.Emulation.DiscSystem
This commit is contained in:
adelikat 2019-03-27 19:24:41 -05:00 committed by GitHub
commit f4340943c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 56 additions and 57 deletions

View File

@ -36,7 +36,7 @@ namespace BizHawk.Emulation.Common
DB.TryGetValue(hashNotype, out cgi); DB.TryGetValue(hashNotype, out cgi);
if (cgi == null) if (cgi == null)
{ {
Console.WriteLine("DB: hash " + hash + " not in game database."); Console.WriteLine($"DB: hash {hash} not in game database.");
return null; return null;
} }
@ -187,7 +187,7 @@ namespace BizHawk.Emulation.Common
} }
catch catch
{ {
Console.WriteLine("Error parsing database entry: " + line); Console.WriteLine($"Error parsing database entry: {line}");
} }
} }
} }

View File

@ -28,7 +28,7 @@ namespace BizHawk.Emulation.Common
} }
public NoAvailableCoreException(string message) public NoAvailableCoreException(string message)
: base ("System is currently NOT emulated: " + message) : base ($"System is currently NOT emulated: {message}")
{ {
} }

View File

@ -21,7 +21,7 @@ namespace BizHawk.Emulation.DiscSystem
handle = mednadisc_LoadCD(pathToDisc); handle = mednadisc_LoadCD(pathToDisc);
if (handle == IntPtr.Zero) if (handle == IntPtr.Zero)
throw new InvalidOperationException("Failed to load MednaDisc: " + pathToDisc); throw new InvalidOperationException($"Failed to load MednaDisc: {pathToDisc}");
//read the mednafen toc //read the mednafen toc
TOCTracks = new MednadiscTOCTrack[101]; TOCTracks = new MednadiscTOCTrack[101];

View File

@ -466,7 +466,7 @@ namespace BizHawk.Emulation.DiscSystem
public bool GetISO9660(byte[] buffer) public bool GetISO9660(byte[] buffer)
{ {
//zero 24-jun-2013 - validate ISO9660 //zero 24-jun-2013 - validate ISO9660
// "CD001" + 0x01 // "CD001\x01"
if (buffer[1] == 'C' && buffer[2] == 'D' && buffer[3] == '0' && buffer[4] == '0' && buffer[5] == '1' && buffer[6] == 0x01) if (buffer[1] == 'C' && buffer[2] == 'D' && buffer[3] == '0' && buffer[4] == '0' && buffer[5] == '1' && buffer[6] == 0x01)
{ {
ISOFile.Format = ISOFile.ISOFormat.ISO9660; ISOFile.Format = ISOFile.ISOFormat.ISO9660;

View File

@ -19,7 +19,7 @@ namespace BizHawk.Emulation.DiscSystem
private static string[] Escape(IEnumerable<string> args) private static string[] Escape(IEnumerable<string> args)
{ {
return args.Select(s => s.Contains(" ") ? string.Format("\"{0}\"", s) : s).ToArray(); return args.Select(s => s.Contains(" ") ? $"\"{s}\"" : s).ToArray();
} }
//note: accepts . or : in the stream stream/substream separator in the stream ID format, since that changed at some point in FFMPEG history //note: accepts . or : in the stream stream/substream separator in the stream ID format, since that changed at some point in FFMPEG history
@ -92,10 +92,10 @@ namespace BizHawk.Emulation.DiscSystem
{ {
var runResults = Run("-i", path, "-xerror", "-f", "wav", "-ar", "44100", "-ac", "2", "-acodec", "pcm_s16le", "-y", tempfile); var runResults = Run("-i", path, "-xerror", "-f", "wav", "-ar", "44100", "-ac", "2", "-acodec", "pcm_s16le", "-y", tempfile);
if(runResults.ExitCode != 0) if(runResults.ExitCode != 0)
throw new InvalidOperationException("Failure running ffmpeg for audio decode. here was its output:\r\n" + runResults.Text); throw new InvalidOperationException($"Failure running ffmpeg for audio decode. here was its output:\r\n{runResults.Text}");
byte[] ret = File.ReadAllBytes(tempfile); byte[] ret = File.ReadAllBytes(tempfile);
if (ret.Length == 0) if (ret.Length == 0)
throw new InvalidOperationException("Failure running ffmpeg for audio decode. here was its output:\r\n" + runResults.Text); throw new InvalidOperationException($"Failure running ffmpeg for audio decode. here was its output:\r\n{runResults.Text}");
return ret; return ret;
} }
finally finally
@ -163,7 +163,7 @@ namespace BizHawk.Emulation.DiscSystem
string path = FindAudio(audioPath); string path = FindAudio(audioPath);
if (path == null) if (path == null)
{ {
throw new AudioDecoder_Exception("Could not find source audio for: " + Path.GetFileName(audioPath)); throw new AudioDecoder_Exception($"Could not find source audio for: {Path.GetFileName(audioPath)}");
} }
return new FFMpeg().DecodeAudio(path); return new FFMpeg().DecodeAudio(path);
} }

View File

@ -11,11 +11,11 @@ namespace BizHawk.Emulation.DiscSystem
public class DiscReferenceException : Exception public class DiscReferenceException : Exception
{ {
public DiscReferenceException(string fname, Exception inner) public DiscReferenceException(string fname, Exception inner)
: base(string.Format("A disc attempted to reference a file which could not be accessed or loaded: {0}", fname), inner) : base($"A disc attempted to reference a file which could not be accessed or loaded: {fname}", inner)
{ {
} }
public DiscReferenceException(string fname, string extrainfo) public DiscReferenceException(string fname, string extrainfo)
: base(string.Format("A disc attempted to reference a file which could not be accessed or loaded:\n\n{0}\n\n{1}", fname, extrainfo)) : base($"A disc attempted to reference a file which could not be accessed or loaded:\n\n{fname}\n\n{extrainfo}")
{ {
} }
} }

View File

@ -42,7 +42,7 @@ namespace BizHawk.Emulation.DiscSystem
private static string ReadTag(BinaryReader br) private static string ReadTag(BinaryReader br)
{ {
return "" + br.ReadChar() + br.ReadChar() + br.ReadChar() + br.ReadChar(); return $"{br.ReadChar()}{br.ReadChar()}{br.ReadChar()}{br.ReadChar()}";
} }
protected static void WriteTag(BinaryWriter bw, string tag) protected static void WriteTag(BinaryWriter bw, string tag)

View File

@ -171,7 +171,7 @@ namespace BizHawk.Emulation.DiscSystem
{ {
int ret; int ret;
if(!TryGetValue(key, out ret)) if(!TryGetValue(key, out ret))
throw new CCDParseException("Malformed or unexpected CCD format: missing required [Entry] key: " + key); throw new CCDParseException($"Malformed or unexpected CCD format: missing required [Entry] key: {key}");
return ret; return ret;
} }
} }

View File

@ -28,7 +28,7 @@ namespace BizHawk.Emulation.DiscSystem.CUE
public override string ToString() public override string ToString()
{ {
return string.Format("I#{0:D2} {1}", Number, FileMSF); return $"I#{Number:D2} {FileMSF}";
} }
} }
@ -72,7 +72,7 @@ namespace BizHawk.Emulation.DiscSystem.CUE
public CompiledCueFileType Type; public CompiledCueFileType Type;
public override string ToString() public override string ToString()
{ {
return string.Format("{0}: {1}", Type, Path.GetFileName(FullPath)); return $"{Type}: {Path.GetFileName(FullPath)}";
} }
} }
@ -109,11 +109,11 @@ namespace BizHawk.Emulation.DiscSystem.CUE
{ {
var idx = Indexes.Find((i) => i.Number == 1); var idx = Indexes.Find((i) => i.Number == 1);
if (idx == null) if (idx == null)
return string.Format("T#{0:D2} NO INDEX 1", Number); return $"T#{Number:D2} NO INDEX 1";
else else
{ {
var indexlist = string.Join("|", Indexes); var indexlist = string.Join("|", Indexes);
return string.Format("T#{0:D2} {1}:{2} ({3})", Number, BlobIndex, idx.FileMSF, indexlist); return $"T#{Number:D2} {BlobIndex}:{idx.FileMSF} ({indexlist})";
} }
} }
} }
@ -223,7 +223,7 @@ namespace BizHawk.Emulation.DiscSystem.CUE
string choice = null; string choice = null;
if (options.Count == 0) if (options.Count == 0)
{ {
Error(string.Format("Couldn't resolve referenced cue file: {0} ; you can commonly repair the cue file yourself, or a file might be missing", f.Path)); Error($"Couldn't resolve referenced cue file: {f.Path} ; you can commonly repair the cue file yourself, or a file might be missing");
//add a null entry to keep the count from being wrong later (quiets a warning) //add a null entry to keep the count from being wrong later (quiets a warning)
OUT_CompiledCueFiles.Add(null); OUT_CompiledCueFiles.Add(null);
return; return;
@ -232,7 +232,7 @@ namespace BizHawk.Emulation.DiscSystem.CUE
{ {
choice = options[0]; choice = options[0];
if (options.Count > 1) if (options.Count > 1)
Warn("Multiple options resolving referenced cue file; choosing: " + Path.GetFileName(choice)); Warn($"Multiple options resolving referenced cue file; choosing: {Path.GetFileName(choice)}");
} }
var cfi = new CompiledCueFile(); var cfi = new CompiledCueFile();
@ -275,7 +275,7 @@ namespace BizHawk.Emulation.DiscSystem.CUE
cfi.Type = CompiledCueFileType.ECM; cfi.Type = CompiledCueFileType.ECM;
if (!Disc.Blob_ECM.IsECM(choice)) if (!Disc.Blob_ECM.IsECM(choice))
{ {
Error("an ECM file was specified or detected, but it isn't a valid ECM file: " + Path.GetFileName(choice)); Error($"an ECM file was specified or detected, but it isn't a valid ECM file: {Path.GetFileName(choice)}");
cfi.Type = CompiledCueFileType.Unknown; cfi.Type = CompiledCueFileType.Unknown;
} }
} }

View File

@ -12,20 +12,20 @@ namespace BizHawk.Emulation.DiscSystem.CUE
public static class Command public static class Command
{ {
//TODO - record line number origin of command? Kind of nice but inessential //TODO - record line number origin of command? Kind of nice but inessential
public class CATALOG { public string Value; public override string ToString() { return string.Format("CATALOG: {0}", Value); } } public class CATALOG { public string Value; public override string ToString() { return $"CATALOG: {Value}"; } }
public class CDTEXTFILE { public string Path; public override string ToString() { return string.Format("CDTEXTFILE: {0}", Path); } } public class CDTEXTFILE { public string Path; public override string ToString() { return $"CDTEXTFILE: {Path}"; } }
public class FILE { public string Path; public CueFileType Type; public override string ToString() { return string.Format("FILE ({0}): {1}", Type, Path); } } public class FILE { public string Path; public CueFileType Type; public override string ToString() { return $"FILE ({Type}): {Path}"; } }
public class FLAGS { public CueTrackFlags Flags; public override string ToString() { return string.Format("FLAGS {0}", Flags); } } public class FLAGS { public CueTrackFlags Flags; public override string ToString() { return $"FLAGS {Flags}"; } }
public class INDEX { public int Number; public Timestamp Timestamp; public override string ToString() { return string.Format("INDEX {0,2} {1}", Number, Timestamp); } } public class INDEX { public int Number; public Timestamp Timestamp; public override string ToString() { return $"INDEX {Number,2} {Timestamp}"; } }
public class ISRC { public string Value; public override string ToString() { return string.Format("ISRC: {0}", Value); } } public class ISRC { public string Value; public override string ToString() { return $"ISRC: {Value}"; } }
public class PERFORMER { public string Value; public override string ToString() { return string.Format("PERFORMER: {0}", Value); } } public class PERFORMER { public string Value; public override string ToString() { return $"PERFORMER: {Value}"; } }
public class POSTGAP { public Timestamp Length; public override string ToString() { return string.Format("POSTGAP: {0}", Length); } } public class POSTGAP { public Timestamp Length; public override string ToString() { return $"POSTGAP: {Length}"; } }
public class PREGAP { public Timestamp Length; public override string ToString() { return string.Format("PREGAP: {0}", Length); } } public class PREGAP { public Timestamp Length; public override string ToString() { return $"PREGAP: {Length}"; } }
public class REM { public string Value; public override string ToString() { return string.Format("REM: {0}", Value); } } public class REM { public string Value; public override string ToString() { return $"REM: {Value}"; } }
public class COMMENT { public string Value; public override string ToString() { return string.Format("COMMENT: {0}", Value); } } public class COMMENT { public string Value; public override string ToString() { return $"COMMENT: {Value}"; } }
public class SONGWRITER { public string Value; public override string ToString() { return string.Format("SONGWRITER: {0}", Value); } } public class SONGWRITER { public string Value; public override string ToString() { return $"SONGWRITER: {Value}"; } }
public class TITLE { public string Value; public override string ToString() { return string.Format("TITLE: {0}", Value); } } public class TITLE { public string Value; public override string ToString() { return $"TITLE: {Value}"; } }
public class TRACK { public int Number; public CueTrackType Type; public override string ToString() { return string.Format("TRACK {0,2} ({1})", Number, Type); } } public class TRACK { public int Number; public CueTrackType Type; public override string ToString() { return $"TRACK {Number,2} ({Type})"; } }
} }

View File

@ -306,7 +306,7 @@ namespace BizHawk.Emulation.DiscSystem.CUE
default: default:
case CueTrackType.Mode2_2336: case CueTrackType.Mode2_2336:
throw new InvalidOperationException("Not supported: " + cct.TrackType); throw new InvalidOperationException($"Not supported: {cct.TrackType}");
} }
ss.Blob = curr_blobInfo.Blob; ss.Blob = curr_blobInfo.Blob;

View File

@ -170,7 +170,7 @@ namespace BizHawk.Emulation.DiscSystem.CUE
else switch (key) else switch (key)
{ {
default: default:
job.Warn("Unknown command: " + key); job.Warn($"Unknown command: {key}");
break; break;
case "CATALOG": case "CATALOG":
@ -204,7 +204,7 @@ namespace BizHawk.Emulation.DiscSystem.CUE
switch (strType) switch (strType)
{ {
default: default:
job.Error("Unknown FILE type: " + strType); job.Error($"Unknown FILE type: {strType}");
ft = CueFileType.Unspecified; ft = CueFileType.Unspecified;
break; break;
case "BINARY": ft = CueFileType.BINARY; break; case "BINARY": ft = CueFileType.BINARY; break;
@ -229,7 +229,7 @@ namespace BizHawk.Emulation.DiscSystem.CUE
{ {
case "DATA": case "DATA":
default: default:
job.Warn("Unknown FLAG: " + flag); job.Warn($"Unknown FLAG: {flag}");
break; break;
case "DCP": cmd.Flags |= CueTrackFlags.DCP; break; case "DCP": cmd.Flags |= CueTrackFlags.DCP; break;
case "4CH": cmd.Flags |= CueTrackFlags._4CH; break; case "4CH": cmd.Flags |= CueTrackFlags._4CH; break;
@ -253,7 +253,7 @@ namespace BizHawk.Emulation.DiscSystem.CUE
int indexnum; int indexnum;
if (!int.TryParse(strindexnum, out indexnum) || indexnum < 0 || indexnum > 99) if (!int.TryParse(strindexnum, out indexnum) || indexnum < 0 || indexnum > 99)
{ {
job.Error("Invalid INDEX number: " + strindexnum); job.Error($"Invalid INDEX number: {strindexnum}");
break; break;
} }
string str_timestamp = clp.ReadToken(); string str_timestamp = clp.ReadToken();
@ -267,7 +267,7 @@ namespace BizHawk.Emulation.DiscSystem.CUE
if (!ts.Valid) if (!ts.Valid)
{ {
if (IN_Strict) if (IN_Strict)
job.Error("Invalid INDEX timestamp: " + str_timestamp); job.Error($"Invalid INDEX timestamp: {str_timestamp}");
break; break;
} }
OUT_CueFile.Commands.Add(new CUE_File.Command.INDEX() { Number = indexnum, Timestamp = ts }); OUT_CueFile.Commands.Add(new CUE_File.Command.INDEX() { Number = indexnum, Timestamp = ts });
@ -283,7 +283,7 @@ namespace BizHawk.Emulation.DiscSystem.CUE
{ {
var isrc = clp.ReadToken(); var isrc = clp.ReadToken();
if (isrc.Length != 12) if (isrc.Length != 12)
job.Warn("Invalid ISRC code ignored: " + isrc); job.Warn($"Invalid ISRC code ignored: {isrc}");
else else
{ {
OUT_CueFile.Commands.Add(OUT_CueFile.GlobalDiscInfo.ISRC = new CUE_File.Command.ISRC() { Value = isrc }); OUT_CueFile.Commands.Add(OUT_CueFile.GlobalDiscInfo.ISRC = new CUE_File.Command.ISRC() { Value = isrc });
@ -301,7 +301,7 @@ namespace BizHawk.Emulation.DiscSystem.CUE
var str_msf = clp.ReadToken(); var str_msf = clp.ReadToken();
var msf = new Timestamp(str_msf); var msf = new Timestamp(str_msf);
if (!msf.Valid) if (!msf.Valid)
job.Error("Ignoring {0} with invalid length MSF: " + str_msf, key); job.Error($"Ignoring {{0}} with invalid length MSF: {str_msf}", key);
else else
{ {
if (key == "POSTGAP") if (key == "POSTGAP")
@ -335,7 +335,7 @@ namespace BizHawk.Emulation.DiscSystem.CUE
int tracknum; int tracknum;
if (!int.TryParse(str_tracknum, out tracknum) || tracknum < 1 || tracknum > 99) if (!int.TryParse(str_tracknum, out tracknum) || tracknum < 1 || tracknum > 99)
{ {
job.Error("Invalid TRACK number: " + str_tracknum); job.Error($"Invalid TRACK number: {str_tracknum}");
break; break;
} }
@ -346,7 +346,7 @@ namespace BizHawk.Emulation.DiscSystem.CUE
switch (str_trackType.ToUpperInvariant()) switch (str_trackType.ToUpperInvariant())
{ {
default: default:
job.Error("Unknown TRACK type: " + str_trackType); job.Error($"Unknown TRACK type: {str_trackType}");
tt = CueTrackType.Unknown; tt = CueTrackType.Unknown;
break; break;
case "AUDIO": tt = CueTrackType.Audio; break; case "AUDIO": tt = CueTrackType.Audio; break;
@ -372,7 +372,7 @@ namespace BizHawk.Emulation.DiscSystem.CUE
//add a comment //add a comment
OUT_CueFile.Commands.Add(new CUE_File.Command.COMMENT() { Value = remainder }); OUT_CueFile.Commands.Add(new CUE_File.Command.COMMENT() { Value = remainder });
} }
else job.Warn("Unknown text at end of line after processing command: " + key); else job.Warn($"Unknown text at end of line after processing command: {key}");
} }
} //end cue parsing loop } //end cue parsing loop

View File

@ -127,7 +127,7 @@ namespace BizHawk.Emulation.DiscSystem.CUE
case CueTrackType.Mode2_2336: case CueTrackType.Mode2_2336:
default: default:
throw new InvalidOperationException("Not supported: " + TrackType); throw new InvalidOperationException($"Not supported: {TrackType}");
} }
//audio has no sector header but the others do //audio has no sector header but the others do

View File

@ -314,7 +314,7 @@ namespace BizHawk.Emulation.DiscSystem
if (aFile.Header.Version[0] > 1) if (aFile.Header.Version[0] > 1)
{ {
throw new MDSParseException("MDS Parse Error: Only MDS version 1.x is supported!\nDetected version: " + aFile.Header.Version[0] + "." + aFile.Header.Version[1]); throw new MDSParseException($"MDS Parse Error: Only MDS version 1.x is supported!\nDetected version: {aFile.Header.Version[0]}.{aFile.Header.Version[1]}");
} }
// parse sessions // parse sessions
@ -477,11 +477,11 @@ namespace BizHawk.Emulation.DiscSystem
if (f.FilenameOffset == 0 || if (f.FilenameOffset == 0 ||
string.Compare(fileName, "*.mdf", StringComparison.InvariantCultureIgnoreCase) == 0) string.Compare(fileName, "*.mdf", StringComparison.InvariantCultureIgnoreCase) == 0)
{ {
fileName = dir + @"\" + Path.GetFileNameWithoutExtension(aFile.MDSPath) + ".mdf"; fileName = $@"{dir}\{Path.GetFileNameWithoutExtension(aFile.MDSPath)}.mdf";
} }
else else
{ {
fileName = dir + @"\" + fileName; fileName = $@"{dir}\{fileName}";
} }
track.ImageFileNamePaths.Add(fileName); track.ImageFileNamePaths.Add(fileName);
@ -621,7 +621,7 @@ namespace BizHawk.Emulation.DiscSystem
foreach (var file in track.ImageFileNamePaths.Distinct()) foreach (var file in track.ImageFileNamePaths.Distinct())
{ {
if (!File.Exists(file)) if (!File.Exists(file))
throw new MDSParseException("Malformed MDS format: nonexistent image file: " + file); throw new MDSParseException($"Malformed MDS format: nonexistent image file: {file}");
IBlob mdfBlob = null; IBlob mdfBlob = null;
long mdfLen = -1; long mdfLen = -1;
@ -848,7 +848,7 @@ namespace BizHawk.Emulation.DiscSystem
//userSector = 2048; //userSector = 2048;
break; break;
//throw new Exception("Not supported: Sector Size " + track.SectorSize); //throw new Exception($"Not supported: Sector Size {track.SectorSize}");
} }
// configure blob // configure blob

View File

@ -116,11 +116,10 @@ namespace BizHawk.Emulation.DiscSystem
{ {
//make a fake cue file to represent this iso file and rerun it as a cue //make a fake cue file to represent this iso file and rerun it as a cue
string filebase = Path.GetFileName(infile); string filebase = Path.GetFileName(infile);
cue_content = string.Format(@" cue_content = $@"
FILE ""{0}"" BINARY FILE ""{filebase}"" BINARY
TRACK 01 MODE1/2048 TRACK 01 MODE1/2048
INDEX 01 00:00:00", INDEX 01 00:00:00";
filebase);
infile = Path.ChangeExtension(infile, ".cue"); infile = Path.ChangeExtension(infile, ".cue");
goto RERUN; goto RERUN;
} }

View File

@ -138,7 +138,7 @@ namespace BizHawk.Emulation.DiscSystem
get get
{ {
if (!Valid) return "--:--:--"; if (!Valid) return "--:--:--";
return string.Format("{0}{1:D2}:{2:D2}:{3:D2}", Negative ? '-' : '+', MIN, SEC, FRAC); return $"{(Negative ? '-' : '+')}{MIN:D2}:{SEC:D2}:{FRAC:D2}";
} }
} }