misc code formatting improvements in random files in EmuHawk

This commit is contained in:
adelikat 2017-04-17 14:57:01 -05:00
parent 1679c1b565
commit 28da1e215f
11 changed files with 78 additions and 62 deletions

View File

@ -58,7 +58,7 @@
this.OK.TabIndex = 1; this.OK.TabIndex = 1;
this.OK.Text = "&OK"; this.OK.Text = "&OK";
this.OK.UseVisualStyleBackColor = true; this.OK.UseVisualStyleBackColor = true;
this.OK.Click += new System.EventHandler(this.OK_Click); this.OK.Click += new System.EventHandler(this.Ok_Click);
// //
// CommentGrid // CommentGrid
// //

View File

@ -70,7 +70,7 @@ namespace BizHawk.Client.EmuHawk
Close(); Close();
} }
private void OK_Click(object sender, EventArgs e) private void Ok_Click(object sender, EventArgs e)
{ {
Save(); Save();
Close(); Close();
@ -88,24 +88,18 @@ namespace BizHawk.Client.EmuHawk
private void SortColumn(DataGridViewColumn e) private void SortColumn(DataGridViewColumn e)
{ {
ListSortDirection _direction; DataGridViewColumn column = e;
DataGridViewColumn _column = e; if (_lastHeaderClicked != column.Name)
if (_lastHeaderClicked != _column.Name)
{ {
_sortReverse = false; _sortReverse = false;
} }
if (!_sortReverse) var direction = !_sortReverse
{ ? ListSortDirection.Ascending
_direction = ListSortDirection.Ascending; : ListSortDirection.Descending;
}
else
{
_direction = ListSortDirection.Descending;
}
CommentGrid.Sort(_column, _direction); CommentGrid.Sort(column, direction);
_lastHeaderClicked = _column.Name; _lastHeaderClicked = column.Name;
_sortReverse = !_sortReverse; _sortReverse = !_sortReverse;
CommentGrid.Refresh(); CommentGrid.Refresh();
} }

View File

@ -66,7 +66,7 @@
this.OK.TabIndex = 1; this.OK.TabIndex = 1;
this.OK.Text = "&OK"; this.OK.Text = "&OK";
this.OK.UseVisualStyleBackColor = true; this.OK.UseVisualStyleBackColor = true;
this.OK.Click += new System.EventHandler(this.OK_Click); this.OK.Click += new System.EventHandler(this.Ok_Click);
// //
// SubGrid // SubGrid
// //

View File

@ -1,17 +1,16 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.IO;
using System.Windows.Forms; using System.Windows.Forms;
using System.Globalization; using System.Globalization;
using BizHawk.Client.Common; using BizHawk.Client.Common;
using System.IO;
using System.Text;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
public partial class EditSubtitlesForm : Form public partial class EditSubtitlesForm : Form
{ {
public bool ReadOnly; public bool ReadOnly { get; set; }
private IMovie _selectedMovie; private IMovie _selectedMovie;
public EditSubtitlesForm() public EditSubtitlesForm()
@ -23,9 +22,12 @@ namespace BizHawk.Client.EmuHawk
{ {
if (ReadOnly) if (ReadOnly)
{ {
//Set all columns to read only // Set all columns to read only
for (int x = 0; x < SubGrid.Columns.Count; x++) for (int i = 0; i < SubGrid.Columns.Count; i++)
SubGrid.Columns[x].ReadOnly = true; {
SubGrid.Columns[i].ReadOnly = true;
}
Text = "View Subtitles"; Text = "View Subtitles";
} }
@ -49,7 +51,7 @@ namespace BizHawk.Client.EmuHawk
MessageBox.Show(error, caption, MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(error, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
private void OK_Click(object sender, EventArgs e) private void Ok_Click(object sender, EventArgs e)
{ {
if (!ReadOnly) if (!ReadOnly)
{ {
@ -102,7 +104,7 @@ namespace BizHawk.Client.EmuHawk
c = SubGrid.Rows[x].Cells[3]; c = SubGrid.Rows[x].Cells[3];
c.Value = s.Duration; c.Value = s.Duration;
c = SubGrid.Rows[x].Cells[4]; c = SubGrid.Rows[x].Cells[4];
c.Value = String.Format("{0:X8}", s.Color); c.Value = string.Format("{0:X8}", s.Color);
c.Style.BackColor = Color.FromArgb((int)s.Color); c.Style.BackColor = Color.FromArgb((int)s.Color);
c = SubGrid.Rows[x].Cells[5]; c = SubGrid.Rows[x].Cells[5];
c.Value = s.Message; c.Value = s.Message;
@ -111,7 +113,11 @@ namespace BizHawk.Client.EmuHawk
private void ChangeRow(Subtitle s, int index) private void ChangeRow(Subtitle s, int index)
{ {
if (index >= SubGrid.Rows.Count) return; if (index >= SubGrid.Rows.Count)
{
return;
}
var c = SubGrid.Rows[index].Cells[0]; var c = SubGrid.Rows[index].Cells[0];
c.Value = s.Frame; c.Value = s.Frame;
c = SubGrid.Rows[index].Cells[1]; c = SubGrid.Rows[index].Cells[1];
@ -121,7 +127,7 @@ namespace BizHawk.Client.EmuHawk
c = SubGrid.Rows[index].Cells[3]; c = SubGrid.Rows[index].Cells[3];
c.Value = s.Duration; c.Value = s.Duration;
c = SubGrid.Rows[index].Cells[4]; c = SubGrid.Rows[index].Cells[4];
c.Value = String.Format("{0:X8}", s.Color); c.Value = string.Format("{0:X8}", s.Color);
c.Style.BackColor = Color.FromArgb((int)s.Color); c.Style.BackColor = Color.FromArgb((int)s.Color);
c = SubGrid.Rows[index].Cells[5]; c = SubGrid.Rows[index].Cells[5];
c.Value = s.Message; c.Value = s.Message;
@ -134,7 +140,7 @@ namespace BizHawk.Client.EmuHawk
var s = new Subtitle(); var s = new Subtitle();
var c = SubGrid.Rows[index].Cells[0]; var c = SubGrid.Rows[index].Cells[0];
//Empty catch because it should default to subtitle default value // Empty catch because it should default to subtitle default value
try { s.Frame = int.Parse(c.Value.ToString()); } try { s.Frame = int.Parse(c.Value.ToString()); }
catch { } catch { }
c = SubGrid.Rows[index].Cells[1]; c = SubGrid.Rows[index].Cells[1];
@ -159,9 +165,17 @@ namespace BizHawk.Client.EmuHawk
private void SubGrid_MouseDoubleClick(object sender, MouseEventArgs e) private void SubGrid_MouseDoubleClick(object sender, MouseEventArgs e)
{ {
if (ReadOnly) return; if (ReadOnly)
{
return;
}
var c = SubGrid.SelectedRows; var c = SubGrid.SelectedRows;
if (c.Count == 0) return; if (c.Count == 0)
{
return;
}
var s = new SubtitleMaker {Sub = GetRow(c[0].Index)}; var s = new SubtitleMaker {Sub = GetRow(c[0].Index)};
if (s.ShowDialog() == DialogResult.OK) if (s.ShowDialog() == DialogResult.OK)
{ {
@ -172,17 +186,21 @@ namespace BizHawk.Client.EmuHawk
private void Export_Click(object sender, EventArgs e) private void Export_Click(object sender, EventArgs e)
{ {
// Get file to save as // Get file to save as
var form = new SaveFileDialog(); var form = new SaveFileDialog
form.AddExtension = true; {
form.Filter = "SubRip Files (*.srt)|*.srt|All files (*.*)|*.*"; AddExtension = true,
Filter = "SubRip Files (*.srt)|*.srt|All files (*.*)|*.*"
};
var result = form.ShowDialog(); var result = form.ShowDialog();
var fileName = form.FileName; var fileName = form.FileName;
form.Dispose(); form.Dispose();
if (result != System.Windows.Forms.DialogResult.OK) if (result != DialogResult.OK)
{
return; return;
}
// Fetch fps // Fetch fps
var system = _selectedMovie.HeaderEntries[HeaderKeys.PLATFORM]; var system = _selectedMovie.HeaderEntries[HeaderKeys.PLATFORM];
@ -201,8 +219,7 @@ namespace BizHawk.Client.EmuHawk
"Could not determine movie fps, export failed.", "Could not determine movie fps, export failed.",
"Error", "Error",
MessageBoxButtons.OK, MessageBoxButtons.OK,
MessageBoxIcon.Error MessageBoxIcon.Error);
);
return; return;
} }
@ -214,8 +231,7 @@ namespace BizHawk.Client.EmuHawk
// Display success // Display success
MessageBox.Show( MessageBox.Show(
string.Format("Subtitles succesfully exported to {0}.", fileName), string.Format("Subtitles succesfully exported to {0}.", fileName),
"Success" "Success");
);
} }
private void SubGrid_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e) private void SubGrid_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)

View File

@ -1,10 +1,9 @@
using System; using System.Drawing;
using System.Drawing;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
/// <summary> /// <summary>
/// Used for the sorting of the moviedetails in PlayMovie.cs /// Used for the sorting of the movie details in PlayMovie.cs
/// </summary> /// </summary>
public class MovieDetails public class MovieDetails
{ {

View File

@ -87,20 +87,21 @@ namespace BizHawk.Client.EmuHawk
return null; return null;
} }
//System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start();
var movie = PreLoadMovieFile(file, force); var movie = PreLoadMovieFile(file, force);
if (movie == null) if (movie == null)
{ {
return null; return null;
} }
//watch.Stop(); Console.WriteLine("[{0}] {1}",watch.ElapsedMilliseconds,Path.GetFileName(filename));
int? index; int? index;
lock (_movieList) lock (_movieList)
{ {
//need to check IsDuplicateOf within the lock // need to check IsDuplicateOf within the lock
index = IsDuplicateOf(filename); index = IsDuplicateOf(filename);
if (index.HasValue) return index; if (index.HasValue)
{
return index;
}
_movieList.Add(movie); _movieList.Add(movie);
index = _movieList.Count - 1; index = _movieList.Count - 1;
@ -111,7 +112,6 @@ namespace BizHawk.Client.EmuHawk
return index; return index;
} }
} }
private int? IsDuplicateOf(string filename) private int? IsDuplicateOf(string filename)
@ -226,7 +226,6 @@ namespace BizHawk.Client.EmuHawk
} }
HighlightMovie(mostRecent); HighlightMovie(mostRecent);
return;
} }
private void HighlightMovie(int index) private void HighlightMovie(int index)
@ -257,27 +256,33 @@ namespace BizHawk.Client.EmuHawk
{ {
string dp = dpTodo.Dequeue(); string dp = dpTodo.Dequeue();
//enqueue subdirectories if appropriate // enqueue subdirectories if appropriate
if (Global.Config.PlayMovie_IncludeSubdir) if (Global.Config.PlayMovie_IncludeSubdir)
foreach(var subdir in Directory.GetDirectories(dp)) {
foreach (var subdir in Directory.GetDirectories(dp))
{
dpTodo.Enqueue(subdir); dpTodo.Enqueue(subdir);
}
}
//add movies // add movies
fpTodo.AddRange(Directory.GetFiles(dp, "*." + MovieService.DefaultExtension)); fpTodo.AddRange(Directory.GetFiles(dp, "*." + MovieService.DefaultExtension));
fpTodo.AddRange(Directory.GetFiles(dp, "*." + TasMovie.Extension)); fpTodo.AddRange(Directory.GetFiles(dp, "*." + TasMovie.Extension));
} }
//in parallel, scan each movie // in parallel, scan each movie
Parallel.For(0, fpTodo.Count, (i) => Parallel.For(0, fpTodo.Count, i =>
//for(int i=0;i<fpTodo.Count;i++)
{ {
var file = fpTodo[i]; var file = fpTodo[i];
lock(ordinals) ordinals[file] = i; lock (ordinals)
AddMovieToList(file, force: false); {
ordinals[file] = i;
} }
);
//sort by the ordinal key to maintain relatively stable results when rescanning AddMovieToList(file, force: false);
});
// sort by the ordinal key to maintain relatively stable results when rescanning
_movieList.Sort((a, b) => ordinals[a.Filename].CompareTo(ordinals[b.Filename])); _movieList.Sort((a, b) => ordinals[a.Filename].CompareTo(ordinals[b.Filename]));
RefreshMovieList(); RefreshMovieList();

View File

@ -111,6 +111,7 @@ namespace BizHawk.Client.EmuHawk
movieToRecord.TextSavestate = sw.ToString(); movieToRecord.TextSavestate = sw.ToString();
} }
} }
// TODO: do we want to support optionally not saving this? // TODO: do we want to support optionally not saving this?
if (true) if (true)
{ {
@ -169,8 +170,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (movieDirException is IOException || if (movieDirException is IOException ||
movieDirException is UnauthorizedAccessException || movieDirException is UnauthorizedAccessException ||
movieDirException is PathTooLongException movieDirException is PathTooLongException)
)
{ {
//TO DO : Pass error to user? //TO DO : Pass error to user?
} }

View File

@ -59,7 +59,7 @@
this.OK.TabIndex = 0; this.OK.TabIndex = 0;
this.OK.Text = "&Save"; this.OK.Text = "&Save";
this.OK.UseVisualStyleBackColor = true; this.OK.UseVisualStyleBackColor = true;
this.OK.Click += new System.EventHandler(this.OK_Click); this.OK.Click += new System.EventHandler(this.Ok_Click);
// //
// Cancel // Cancel
// //

View File

@ -25,7 +25,7 @@ namespace BizHawk.Client.EmuHawk
Close(); Close();
} }
private void OK_Click(object sender, EventArgs e) private void Ok_Click(object sender, EventArgs e)
{ {
Sub.Frame = (int)FrameNumeric.Value; Sub.Frame = (int)FrameNumeric.Value;
Sub.Message = Message.Text; Sub.Message = Message.Text;

View File

@ -31,6 +31,7 @@ namespace BizHawk.Client.EmuHawk
{ {
return PromptLabel.Text; return PromptLabel.Text;
} }
set set
{ {
PromptLabel.Text = value ?? string.Empty; PromptLabel.Text = value ?? string.Empty;

View File

@ -38,5 +38,6 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SG/@EntryIndexedValue">SG</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SG/@EntryIndexedValue">SG</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SGX/@EntryIndexedValue">SGX</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SGX/@EntryIndexedValue">SGX</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SNES/@EntryIndexedValue">SNES</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SNES/@EntryIndexedValue">SNES</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=TI/@EntryIndexedValue">TI</s:String></wpf:ResourceDictionary> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=TI/@EntryIndexedValue">TI</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=MethodPropertyEvent/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /&gt;</s:String></wpf:ResourceDictionary>