Replace concatenation and StringBuilder with string.Concat/string.Join

This commit is contained in:
YoshiRulz 2019-03-28 00:40:18 +10:00
parent 56c33ac99b
commit f256c164d1
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
30 changed files with 142 additions and 503 deletions

View File

@ -23,10 +23,8 @@ namespace BizHawk.Client.Common
public override string ToString()
{
var sb = new StringBuilder();
Sort();
ForEach(subtitle => sb.AppendLine(subtitle.ToString()));
return sb.ToString();
return string.Join("\n", this) + "\n";
}
public bool AddFromString(string subtitleStr)
@ -37,13 +35,6 @@ namespace BizHawk.Client.Common
{
var subparts = subtitleStr.Split(' ');
// Unfortunately I made the file format space delminated so this hack is necessary to get the message
var message = "";
for (var i = 6; i < subparts.Length; i++)
{
message += subparts[i] + ' ';
}
Add(new Subtitle
{
Frame = int.Parse(subparts[1]),
@ -51,7 +42,7 @@ namespace BizHawk.Client.Common
Y = int.Parse(subparts[3]),
Duration = int.Parse(subparts[4]),
Color = uint.Parse(subparts[5], NumberStyles.HexNumber),
Message = message.Trim()
Message = string.Join(" ", subparts.Skip(6)) // Unfortunately this is necessary to get the value of Message because the format is space-delimited
});
return true;
@ -76,8 +67,6 @@ namespace BizHawk.Client.Common
public string ToSubRip(double fps)
{
int index = 1;
var sb = new StringBuilder();
List<Subtitle> subs = new List<Subtitle>();
foreach (var subtitle in this)
{
@ -117,12 +106,8 @@ namespace BizHawk.Client.Common
subs = subs.OrderBy(s => s.Frame).ThenByDescending(s => s.Y).ToList();
}
foreach (var subtitle in subs)
{
sb.Append(subtitle.ToSubRip(index++, fps, AddColorTag));
}
return sb.ToString();
var index = 1;
return string.Concat(subs.Select(subtitle => subtitle.ToSubRip(index++, fps, AddColorTag)));
}
}
}

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BizHawk.Client.Common
@ -25,20 +26,6 @@ namespace BizHawk.Client.Common
}
}
public override string ToString()
{
var sb = new StringBuilder();
foreach (var kvp in this)
{
sb
.Append(kvp.Key)
.Append(' ')
.Append(kvp.Value)
.AppendLine();
}
return sb.ToString();
}
public override string ToString() => string.Concat(this.Select((k, v) => $"{k} {v}\n"));
}
}

View File

@ -46,21 +46,10 @@ namespace BizHawk.Client.Common
public string GenerateLogKey()
{
var sb = new StringBuilder();
sb.Append("LogKey:");
foreach (var group in _source.Definition.ControlsOrdered.Where(c => c.Any()))
{
sb.Append("#");
foreach (var button in group)
{
sb
.Append(button)
.Append('|');
}
}
return sb.ToString();
var s = string.Join("#", _source.Definition.ControlsOrdered
.Select(group => string.Concat(group.Select(button => $"{button}|")))
.Where(groupStr => !string.IsNullOrEmpty(groupStr)));
return $"LogKey:{(s.Length > 0 ? $"#{s}" : string.Empty)}";
}
public Dictionary<string, string> Map()
@ -86,64 +75,25 @@ namespace BizHawk.Client.Common
private string CreateLogEntry(bool createEmpty = false, bool forInputDisplay = false)
{
var sb = new StringBuilder();
if (!forInputDisplay)
{
sb.Append('|');
}
foreach (var group in _source.Definition.ControlsOrdered)
{
if (group.Any())
{
foreach (var button in group)
var list = _source.Definition.ControlsOrdered.Select(group => string.Concat(group.Select(
button => {
if (_source.Definition.FloatControls.Contains(button))
{
if (_source.Definition.FloatControls.Contains(button))
{
int val;
int i = _source.Definition.FloatControls.IndexOf(button);
int mid = (int)_source.Definition.FloatRanges[i].Mid;
if (createEmpty)
{
val = mid;
}
else
{
val = (int)_source.GetFloat(button);
}
if (forInputDisplay && val == mid)
{
sb.Append(" ");
}
else
{
sb.Append(val.ToString().PadLeft(5, ' ')).Append(',');
}
}
else if (_source.Definition.BoolButtons.Contains(button))
{
if (createEmpty)
{
sb.Append('.');
}
else
{
sb.Append(_source.IsPressed(button) ? _mnemonics[button] : forInputDisplay ? ' ' : '.');
}
}
var mid = (int)_source.Definition.FloatRanges[_source.Definition.FloatControls.IndexOf(button)].Mid;
var val = createEmpty ? mid : (int)_source.GetFloat(button);
return forInputDisplay && val == mid ? " " : $"{val,5},";
}
if (!forInputDisplay)
{
sb.Append('|');
}
}
}
return sb.ToString();
else if (_source.Definition.BoolButtons.Contains(button))
return (createEmpty
? '.'
: _source.IsPressed(button)
? _mnemonics[button]
: forInputDisplay
? ' '
: '.').ToString();
else return string.Empty;
})));
return forInputDisplay ? string.Concat(list) : $"|{string.Join("|", list)}|";
}
}
}

View File

@ -274,17 +274,7 @@ namespace BizHawk.Client.Common
}
}
protected string CommentsString()
{
var sb = new StringBuilder();
foreach (var comment in Comments)
{
sb.AppendLine(comment);
}
return sb.ToString();
}
protected string CommentsString() => string.Join("\n", Comments) + "\n";
public string TextSavestate { get; set; }
public byte[] BinarySavestate { get; set; }

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BizHawk.Client.Common
@ -151,24 +152,9 @@ namespace BizHawk.Client.Common
base.Clear();
}
public override string ToString()
{
var sb = new StringBuilder();
foreach (var kvp in this)
{
sb
.Append(kvp.Key)
.Append(' ')
.Append(kvp.Value)
.AppendLine();
}
sb.Append(Subtitles);
Comments.ForEach(comment => sb.AppendLine(comment));
return sb.ToString();
}
public override string ToString() => string.Concat(this.Select((k, v) => $"{k} {v}\n"))
+ Subtitles
+ string.Join("\n", Comments) + "\n";
public bool ParseLineFromFile(string line)
{

View File

@ -1,4 +1,5 @@
using System.Text;
using System.Linq;
using System.Text;
using BizHawk.Emulation.Common;
@ -345,45 +346,21 @@ namespace BizHawk.Client.Common
return input.ToString();
}
private string GetDualGameBoyControllerAsMnemonic()
{
// |.|........|.|........|
var input = new StringBuilder();
/// <remarks>|.|........|.|........|</remarks>
private string GetDualGameBoyControllerAsMnemonic() => string.Concat(BkmMnemonicConstants.DgbMnemonic.Select(t =>
t.Item1 == null // true if separator
? t.Item2
: IsBasePressed(t.Item1)
? t.Item2
: '.'));
foreach (var t in BkmMnemonicConstants.DgbMnemonic)
{
if (t.Item1 != null)
{
input.Append(IsBasePressed(t.Item1) ? t.Item2 : '.');
}
else
{
input.Append(t.Item2); // Separator
}
}
return input.ToString();
}
private string GetWonderSwanControllerAsMnemonic()
{
// |....|....|...|
var input = new StringBuilder();
foreach (var t in BkmMnemonicConstants.WsMnemonic)
{
if (t.Item1 != null)
{
input.Append(IsBasePressed(t.Item1) ? t.Item2 : '.');
}
else
{
input.Append(t.Item2); // Separator
}
}
return input.ToString();
}
/// <remarks>|....|....|...|</remarks>
private string GetWonderSwanControllerAsMnemonic() => string.Concat(BkmMnemonicConstants.WsMnemonic.Select(t =>
t.Item1 == null // true if separator
? t.Item2
: IsBasePressed(t.Item1)
? t.Item2
: '.'));
private string GetA78ControllersAsMnemonic()
{

View File

@ -56,7 +56,7 @@ namespace BizHawk.Client.Common
if (VerificationLog.Count > 0)
{
bs.PutLump(BinaryStateLump.VerificationLog, tw => tw.WriteLine(InputLogToString(VerificationLog)));
bs.PutLump(BinaryStateLump.VerificationLog, tw => tw.WriteLine(string.Join("\n", VerificationLog) + "\n")); // double newline present with StringBuilder
}
if (Branches.Count > 0)
@ -276,16 +276,5 @@ namespace BizHawk.Client.Common
Markers.Clear();
ChangeLog.ClearLog();
}
private static string InputLogToString(IStringLog log)
{
var sb = new StringBuilder();
foreach (var record in log)
{
sb.AppendLine(record);
}
return sb.ToString();
}
}
}

View File

@ -99,16 +99,7 @@ namespace BizHawk.Client.Common
CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}
public override string ToString()
{
var sb = new StringBuilder();
foreach (var marker in this)
{
sb.AppendLine(marker.ToString());
}
return sb.ToString();
}
public override string ToString() => string.Join("\n", this) + "\n";
// the inherited one
public new void Add(TasMovieMarker item)

View File

@ -370,38 +370,23 @@ namespace BizHawk.Client.Common
file.Directory.Create();
}
using (var sw = new StreamWriter(path))
{
var sb = new StringBuilder();
foreach (var cheat in _cheatList)
{
if (cheat.IsSeparator)
{
sb.AppendLine("----");
}
else
{
// Set to hex for saving
cheat.SetType(DisplayType.Hex);
sb
.Append(cheat.AddressStr).Append('\t')
.Append(cheat.ValueStr).Append('\t')
.Append(cheat.Compare?.ToString() ?? "N").Append('\t')
.Append(cheat.Domain != null ? cheat.Domain.Name : "").Append('\t')
.Append(cheat.Enabled ? '1' : '0').Append('\t')
.Append(cheat.Name).Append('\t')
.Append(cheat.SizeAsChar).Append('\t')
.Append(cheat.TypeAsChar).Append('\t')
.Append((cheat.BigEndian ?? false) ? '1' : '0').Append('\t')
.Append(cheat.ComparisonType).Append('\t')
.AppendLine();
}
}
sw.WriteLine(sb.ToString());
}
using (var sw = new StreamWriter(path)) sw.WriteLine(
string.Join("\n", _cheatList.Select(cheat => {
if (cheat.IsSeparator) return "----";
cheat.SetType(DisplayType.Hex); // ignore chosen format for saving
return string.Join("\t",
cheat.AddressStr,
cheat.ValueStr,
cheat.Compare?.ToString() ?? "N",
cheat.Domain != null ? cheat.Domain.Name : "",
cheat.Enabled ? '1' : '0',
cheat.Name,
cheat.SizeAsChar,
cheat.TypeAsChar,
cheat.BigEndian ?? false ? '1' : '0',
cheat.ComparisonType);
}))
+ "\n"); // double newline present with StringBuilder
_currentFileName = path;
Global.Config.RecentCheats.Add(_currentFileName);

View File

@ -457,18 +457,7 @@ namespace BizHawk.Client.Common
}
using (var sw = new StreamWriter(CurrentFileName))
{
var sb = new StringBuilder();
sb.Append("SystemID ").AppendLine(_systemid);
foreach (var watch in _watchList)
{
sb.AppendLine(watch.ToString());
}
sw.WriteLine(sb.ToString());
}
sw.WriteLine($"SystemID {_systemid}\n{string.Join("\n", _watchList)}\n"); // double newline present with StringBuilder
Changes = false;
return true;
}

View File

@ -74,17 +74,8 @@ namespace BizHawk.Client.DBMan
/// <param name="e"></param>
private void buttonRemove_Click(object sender, EventArgs e)
{
List<string> files = new List<string>();
foreach (var s in listBoxFiles.SelectedItems)
{
files.Add(s.ToString());
}
if (files.Count > 0)
{
foreach (var s in files)
listBoxFiles.Items.Remove(s);
}
foreach (var s in listBoxFiles.SelectedItems.Cast<object>().Select(o => o.ToString()))
listBoxFiles.Items.Remove(s);
}
/// <summary>

View File

@ -317,13 +317,9 @@ namespace BizHawk.Client.DBMan
if (rom.VersionTags != null)
{
var versions = rom.VersionTags.Split(';');
foreach (var version in versions)
{
if (version.Trim().Length == 0)
continue;
romName += " (" + version + ")";
}
romName += string.Concat(rom.VersionTags.Split(';')
.Where(version => !string.IsNullOrWhiteSpace(version))
.Select(version => $" ({version.Trim()})"));
}
tw.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}", rom.MD5, romCode, romName, rom.System, rom.Game.Tags, rom.CombinedMetaData, rom.Region);

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.DiscSystem;
@ -213,14 +214,7 @@ namespace BizHawk.Client.DBMan
}
}
static string BytesToHexString(byte[] bytes)
{
var sb = new StringBuilder();
foreach (var b in bytes)
sb.AppendFormat("{0:X2}", b);
return sb.ToString();
}
static string BytesToHexString(byte[] bytes) => string.Concat(bytes.Select(b => $"{b:X2}"));
static byte[] MaybeStripHeader512(byte[] fileBytes)
{

View File

@ -236,39 +236,11 @@ namespace BizHawk.Client.EmuHawk.WinFormExtensions
/// <summary>
/// Dumps the contents of the ListView into a tab separated list of lines
/// </summary>
public static string CopyItemsAsText(this ListView listViewControl)
{
var indexes = listViewControl.SelectedIndices;
if (indexes.Count <= 0)
{
return "";
}
var sb = new StringBuilder();
// walk over each selected item and subitem within it to generate a string from it
foreach (int index in indexes)
{
foreach (ListViewItem.ListViewSubItem item in listViewControl.Items[index].SubItems)
{
if (!String.IsNullOrWhiteSpace(item.Text))
{
sb.Append(item.Text).Append('\t');
}
}
// remove the last tab
sb.Remove(sb.Length - 1, 1);
sb.Append("\r\n");
}
// remove last newline
sb.Length -= 2;
return sb.ToString();
}
public static string CopyItemsAsText(this ListView listViewControl) =>
string.Join("\r\n", listViewControl.SelectedIndices.Cast<int>()
.Select(index => string.Join("\t", listViewControl.Items[index].SubItems.Cast<ListViewItem.ListViewSubItem>()
.Select(subItem => subItem.Text)
.Where(subItemText => !string.IsNullOrWhiteSpace(subItemText)))));
public static void SetSortIcon(this ListView listViewControl, int columnIndex, SortOrder order)
{

View File

@ -113,20 +113,14 @@ namespace BizHawk.Client.EmuHawk
private void buttonCopy_Click(object sender, EventArgs e)
{
var sb = new StringBuilder();
foreach (var line in virtualListView1.SelectedIndices.Cast<int>().SelectAsIndexOf(Lines))
sb.AppendLine(line);
if (sb.Length > 0)
Clipboard.SetText(sb.ToString(), TextDataFormat.Text);
var s = string.Join("\n", virtualListView1.SelectedIndices.Cast<int>().SelectAsIndexOf(Lines));
if (s.Length > 0) Clipboard.SetText($"{s}\n", TextDataFormat.Text);
}
private void buttonCopyAll_Click(object sender, EventArgs e)
{
var sb = new StringBuilder();
foreach (var s in Lines)
sb.AppendLine(s);
if (sb.Length > 0)
Clipboard.SetText(sb.ToString(), TextDataFormat.Text);
var s = string.Join("\n", Lines);
if (s.Length > 0) Clipboard.SetText($"{s}\n", TextDataFormat.Text);
}
private void virtualListView1_KeyDown(object sender, KeyEventArgs e)

View File

@ -40,13 +40,7 @@ namespace BizHawk.Client.EmuHawk
if (_syncSettings.InitialWRamStatePattern != null && _syncSettings.InitialWRamStatePattern.Count > 0)
{
var sb = new StringBuilder();
foreach (var b in _syncSettings.InitialWRamStatePattern)
{
sb.Append(b.ToHexString(2));
}
RamPatternOverrideBox.Text = sb.ToString();
RamPatternOverrideBox.Text = string.Concat(_syncSettings.InitialWRamStatePattern.Select(b => b.ToHexString(2)));
}
}

View File

@ -316,21 +316,14 @@ namespace BizHawk.Client.EmuHawk
{
if (e.Control && e.KeyCode == Keys.C)
{
var indexes = MovieView.SelectedIndices;
if (indexes.Count > 0)
{
var copyStr = new StringBuilder();
foreach (var movie in indexes.Cast<int>().SelectAsIndexOf(_movieList))
{
copyStr
.Append(movie.Filename).Append('\t')
.Append(movie.SystemID).Append('\t')
.Append(movie.GameName).Append('\t')
.Append(PlatformFrameRates.MovieTime(movie).ToString(@"hh\:mm\:ss\.fff"))
.AppendLine();
}
Clipboard.SetDataObject(copyStr.ToString());
}
var s = string.Join("\n", MovieView.SelectedIndices.Cast<int>()
.SelectAsIndexOf(_movieList)
.Select(movie => string.Join("\t",
movie.Filename,
movie.SystemID,
movie.GameName,
PlatformFrameRates.MovieTime(movie).ToString(@"hh\:mm\:ss\.fff"))));
if (s.Length > 0) Clipboard.SetDataObject($"{s}\n");
}
}

View File

@ -1012,13 +1012,7 @@ namespace BizHawk.Client.EmuHawk
BestTieBreak1Box.Text = _bestBotAttempt.TieBreak1.ToString();
BestTieBreak2Box.Text = _bestBotAttempt.TieBreak2.ToString();
BestTieBreak3Box.Text = _bestBotAttempt.TieBreak3.ToString();
var sb = new StringBuilder();
foreach (var logEntry in _bestBotAttempt.Log)
{
sb.AppendLine(logEntry);
}
BestAttemptLogLabel.Text = sb.ToString();
BestAttemptLogLabel.Text = string.Join("\n", _bestBotAttempt.Log) + "\n";
PlayBestButton.Enabled = true;
}
else

View File

@ -196,25 +196,10 @@ namespace BizHawk.Client.EmuHawk
private void CopySelectedDisassembler()
{
var indices = DisassemblerView.SelectedIndices;
if (indices.Count > 0)
{
var blob = new StringBuilder();
foreach (var disasmOp in indices.Cast<int>().SelectAsIndexOf(_disassemblyLines))
{
if (blob.Length != 0)
{
blob.AppendLine();
}
blob.Append(string.Format("{0:X" + _pcRegisterSize + "}", disasmOp.Address))
.Append(" ")
.Append(disasmOp.Mnemonic);
}
Clipboard.SetDataObject(blob.ToString());
}
var s = string.Join("\n", DisassemblerView.SelectedIndices.Cast<int>()
.SelectAsIndexOf(_disassemblyLines)
.Select(d => $"{string.Format($"{{0:X{_pcRegisterSize}}}", d.Address)} {d.Mnemonic}"));
if (s.Length > 0) Clipboard.SetDataObject(s);
}
private void OnPauseChanged(object sender, MainForm.PauseChangedEventArgs e)

View File

@ -1,5 +1,6 @@
using System;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
@ -55,15 +56,7 @@ namespace BizHawk.Client.EmuHawk
return FindBox.Text;
}
var bytes = GlobalWin.Tools.HexEditor.ConvertTextToBytes(FindBox.Text);
var bytestring = new StringBuilder();
foreach (var b in bytes)
{
bytestring.Append($"{b:X2}");
}
return bytestring.ToString();
return string.Concat(GlobalWin.Tools.HexEditor.ConvertTextToBytes(FindBox.Text).Select(b => $"{b:X2}"));
}
private void Find_Prev_Click(object sender, EventArgs e)

View File

@ -6,6 +6,7 @@ using BizHawk.Client.Common;
using System.Text;
using System.Collections.Generic;
using System.Net.Http;
using System.Reflection;
using System.Windows.Forms;
@ -28,18 +29,10 @@ namespace BizHawk.Client.EmuHawk
public override string Name => "comm";
//TO DO: not fully working yet!
//TODO: not fully working yet!
[LuaMethod("getluafunctionslist", "returns a list of implemented functions")]
public static string GetLuaFunctionsList()
{
var list = new StringBuilder();
foreach (var function in typeof(CommunicationLuaLibrary).GetMethods())
{
list.AppendLine(function.ToString());
}
return list.ToString();
}
public static string GetLuaFunctionsList() =>
string.Join("\n", (IEnumerable<MethodInfo>) typeof(CommunicationLuaLibrary).GetMethods()) + "\n";
[LuaMethod("socketServerScreenShot", "sends a screenshot to the Socket server")]
public string SocketServerScreenShot()

View File

@ -30,16 +30,8 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodExample("local stconget = console.getluafunctionslist( );")]
[LuaMethod("getluafunctionslist", "returns a list of implemented functions")]
public static string GetLuaFunctionsList()
{
var list = new StringBuilder();
foreach (var function in GlobalWin.Tools.LuaConsole.LuaImp.Docs)
{
list.AppendLine(function.Name);
}
return list.ToString();
}
public static string GetLuaFunctionsList() =>
string.Join("\n", GlobalWin.Tools.LuaConsole.LuaImp.Docs.Select(function => function.Name)) + "\n";
[LuaMethodExample("console.log( \"New log.\" );")]
[LuaMethod("log", "Outputs the given object to the output box on the Lua Console dialog. Note: Can accept a LuaTable")]

View File

@ -155,26 +155,13 @@ namespace BizHawk.Client.EmuHawk
private void FunctionView_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.C && e.Control && !e.Alt && !e.Shift) // Copy
if (e.KeyCode == Keys.C && e.Control && !e.Alt && !e.Shift // Copy
&& FunctionView.SelectedIndices.Count > 0)
{
var indexes = FunctionView.SelectedIndices;
//TODO - duplicated code with FunctionView_Copy
//also -- this list is more compact (the examples would fill space)
//it isn't clear whether we should copy the examples here. So maybe this should stay distinct (and more compact?)
if (indexes.Count > 0)
{
var sb = new StringBuilder();
foreach (var libraryFunction in indexes.Cast<int>().SelectAsIndexOf(GlobalWin.Tools.LuaConsole.LuaImp.Docs))
{
sb.Append(libraryFunction.Library).Append('.').Append(libraryFunction.Name).Append("()\n");
}
if (sb.Length > 0)
Clipboard.SetDataObject(sb.ToString());
}
var s = string.Concat(FunctionView.SelectedIndices.Cast<int>()
.SelectAsIndexOf(GlobalWin.Tools.LuaConsole.LuaImp.Docs)
.Select(lf => $"{lf.Library}.{lf.Name}()\n"));
if (s.Length > 0) Clipboard.SetDataObject(s);
}
}

View File

@ -328,18 +328,11 @@ namespace BizHawk.Client.EmuHawk
private void CopyMenuItem_Click(object sender, EventArgs e)
{
var indices = TraceView.SelectedIndices;
if (indices.Count > 0)
if (TraceView.SelectedIndices.Count > 0)
{
var blob = new StringBuilder();
foreach (var traceInfo in indices.Cast<int>().SelectAsIndexOf(_instructions))
{
blob.Append(string.Format("{0} {1}\n",
traceInfo.Disassembly,
traceInfo.RegisterInfo));
}
Clipboard.SetDataObject(blob.ToString());
Clipboard.SetDataObject(string.Concat(TraceView.SelectedIndices.Cast<int>()
.SelectAsIndexOf(_instructions)
.Select(instr => $"{instr.Disassembly} {instr.RegisterInfo}\n")));
}
}

View File

@ -1519,19 +1519,8 @@ namespace BizHawk.Client.EmuHawk
private void CopyWatchesToClipBoard()
{
if (SelectedItems.Any())
{
var sb = new StringBuilder();
foreach (var watch in SelectedItems)
{
sb.AppendLine(watch.ToString());
}
if (sb.Length > 0)
{
Clipboard.SetDataObject(sb.ToString());
}
}
var s = string.Join("\n", SelectedItems);
if (s.Length > 0) Clipboard.SetDataObject($"{s}\n");
}
#endregion

View File

@ -347,19 +347,8 @@ namespace BizHawk.Client.EmuHawk
private void CopyWatchesToClipBoard()
{
if (SelectedItems.Any())
{
var sb = new StringBuilder();
foreach (var watch in SelectedItems)
{
sb.AppendLine(watch.ToString());
}
if (sb.Length > 0)
{
Clipboard.SetDataObject(sb.ToString());
}
}
var s = string.Join("\n", SelectedItems);
if (s.Length > 0) Clipboard.SetDataObject($"{s}\n");
}
private void PasteWatchesToClipBoard()

View File

@ -310,21 +310,14 @@ namespace BizHawk.Client.MultiHawk
{
if (e.Control && e.KeyCode == Keys.C)
{
var indexes = MovieView.SelectedIndices;
if (indexes.Count > 0)
{
var copyStr = new StringBuilder();
foreach (var movie in indexes.Cast<int>().SelectAsIndexOf(_movieList))
{
copyStr
.Append(movie.Filename).Append('\t')
.Append(movie.SystemID).Append('\t')
.Append(movie.GameName).Append('\t')
.Append(PlatformFrameRates.MovieTime(movie).ToString(@"hh\:mm\:ss\.fff"))
.AppendLine();
}
Clipboard.SetDataObject(copyStr.ToString());
}
var s = string.Join("\n", MovieView.SelectedIndices.Cast<int>()
.SelectAsIndexOf(_movieList)
.Select(movie => string.Join("\t",
movie.Filename,
movie.SystemID,
movie.GameName,
PlatformFrameRates.MovieTime(movie).ToString(@"hh\:mm\:ss\.fff"))));
if (s.Length > 0) Clipboard.SetDataObject($"{s}\n");
}
}

View File

@ -1,6 +1,7 @@
using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
@ -172,16 +173,7 @@ namespace BizHawk.Common.BufferExtensions
/// <summary>
/// Converts bytes to an uppercase string of hex numbers in upper case without any spacing or anything
/// </summary>
public static string BytesToHexString(this byte[] bytes)
{
var sb = new StringBuilder();
foreach (var b in bytes)
{
sb.AppendFormat("{0:X2}", b);
}
return sb.ToString();
}
public static string BytesToHexString(this byte[] bytes) => string.Concat(bytes.Select(b => $"{b:X2}"));
public static bool FindBytes(this byte[] array, byte[] pattern)
{

View File

@ -1,6 +1,7 @@
using BizHawk.Emulation.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BizHawk.Common.NumberExtensions;
@ -31,33 +32,19 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
Disassembly = string.Format("{0:X6}: {1}", pc, disasm).PadRight(50)
};
var sb = new StringBuilder();
foreach (var r in regs)
{
if (r.Key.StartsWith("M68K")) // drop Z80 regs until it has its own debugger/tracer
{
if (r.Key != "M68K SP" && r.Key != "M68K ISP" && // copies of a7
r.Key != "M68K PC" && // already present in every line start
r.Key != "M68K IR") // copy of last opcode, already shown in raw bytes
{
sb.Append(
string.Format("{0}:{1} ",
r.Key.Replace("M68K", "").Trim(),
r.Value.Value.ToHexString(r.Value.BitSize / 4)));
}
}
}
var regStr = string.Concat(regs.Where(r => r.Key.StartsWith("M68K") // drop Z80 regs until it has its own debugger/tracer
&& r.Key != "M68K SP" && r.Key != "M68K ISP" // copies of a7
&& r.Key != "M68K PC" // already present in every line start
&& r.Key != "M68K IR") // copy of last opcode, already shown in raw bytes
.Select(r => $"{r.Key.Replace("M68K", "").Trim()}:{r.Value.Value.ToHexString(r.Value.BitSize / 4)} "));
var sr = regs["M68K SR"].Value;
sb.Append(
string.Format("{0}{1}{2}{3}{4}",
traceInfo.RegisterInfo = regStr + string.Concat(
(sr & 16) > 0 ? "X" : "x",
(sr & 8) > 0 ? "N" : "n",
(sr & 4) > 0 ? "Z" : "z",
(sr & 2) > 0 ? "V" : "v",
(sr & 1) > 0 ? "C" : "c"));
traceInfo.RegisterInfo = sb.ToString().Trim();
(sr & 1) > 0 ? "C" : "c");
Put(traceInfo);
}

View File

@ -18,22 +18,11 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
public void ShockTraceCallback(IntPtr opaque, uint PC, uint inst, string dis)
{
var regs = GetCpuFlagsAndRegisters();
StringBuilder sb = new StringBuilder();
foreach (var r in regs)
{
if (r.Key != "pc")
sb.Append(
string.Format("{0}:{1} ",
r.Key,
r.Value.Value.ToHexString(r.Value.BitSize / 4)));
}
Tracer.Put(new TraceInfo
{
Disassembly = string.Format("{0:X8}: {1:X8} {2}", PC, inst, dis.PadRight(30)),
RegisterInfo = sb.ToString().Trim()
Disassembly = $"{PC:X8}: {inst:X8} {dis.PadRight(30)}",
RegisterInfo = string.Join(" ", GetCpuFlagsAndRegisters().Where(r => r.Key != "pc")
.Select(r => $"{r.Key}:{r.Value.Value.ToHexString(r.Value.BitSize / 4)}"))
});
}