diff --git a/BizHawk.MultiClient/Config.cs b/BizHawk.MultiClient/Config.cs index 8e5d91a697..ecf294625e 100644 --- a/BizHawk.MultiClient/Config.cs +++ b/BizHawk.MultiClient/Config.cs @@ -48,6 +48,7 @@ // RamSearch Settings public bool AutoLoadRamSearch = false; + public RecentFiles RecentSearches = new RecentFiles(8); public int RamSearchWndx = -1; //Negative numbers will be ignored even with save window position set public int RamSearchWndy = -1; public int RamSearchWidth = -1; //Negative numbers will be ignored diff --git a/BizHawk.MultiClient/tools/RamSearch.Designer.cs b/BizHawk.MultiClient/tools/RamSearch.Designer.cs index 1d1016ef36..b92aafb2c4 100644 --- a/BizHawk.MultiClient/tools/RamSearch.Designer.cs +++ b/BizHawk.MultiClient/tools/RamSearch.Designer.cs @@ -48,11 +48,16 @@ this.newSearchToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.saveAsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.saveAsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.appendFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.recentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.noneToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); + this.clearToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.autoLoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.hackyAutoLoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.restoreOriginalWindowSizeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.saveWindowPositionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripContainer1 = new System.Windows.Forms.ToolStripContainer(); @@ -260,8 +265,10 @@ this.newSearchToolStripMenuItem, this.toolStripSeparator1, this.openToolStripMenuItem, - this.saveAsToolStripMenuItem, this.saveToolStripMenuItem, + this.saveAsToolStripMenuItem, + this.appendFileToolStripMenuItem, + this.recentToolStripMenuItem, this.exitToolStripMenuItem}); this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; this.fileToolStripMenuItem.Size = new System.Drawing.Size(35, 20); @@ -287,6 +294,13 @@ this.openToolStripMenuItem.Text = "&Open..."; this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click); // + // saveToolStripMenuItem + // + this.saveToolStripMenuItem.Name = "saveToolStripMenuItem"; + this.saveToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S))); + this.saveToolStripMenuItem.Size = new System.Drawing.Size(204, 22); + this.saveToolStripMenuItem.Text = "&Save"; + // // saveAsToolStripMenuItem // this.saveAsToolStripMenuItem.Name = "saveAsToolStripMenuItem"; @@ -296,38 +310,65 @@ this.saveAsToolStripMenuItem.Text = "Save As..."; this.saveAsToolStripMenuItem.Click += new System.EventHandler(this.saveAsToolStripMenuItem_Click); // - // saveToolStripMenuItem + // appendFileToolStripMenuItem // - this.saveToolStripMenuItem.Name = "saveToolStripMenuItem"; - this.saveToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S))); - this.saveToolStripMenuItem.Size = new System.Drawing.Size(204, 22); - this.saveToolStripMenuItem.Text = "Save"; + this.appendFileToolStripMenuItem.Name = "appendFileToolStripMenuItem"; + this.appendFileToolStripMenuItem.Size = new System.Drawing.Size(204, 22); + this.appendFileToolStripMenuItem.Text = "&Append File..."; + this.appendFileToolStripMenuItem.Click += new System.EventHandler(this.appendFileToolStripMenuItem_Click); + // + // recentToolStripMenuItem + // + this.recentToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.noneToolStripMenuItem, + this.toolStripSeparator2, + this.clearToolStripMenuItem, + this.autoLoadToolStripMenuItem}); + this.recentToolStripMenuItem.Name = "recentToolStripMenuItem"; + this.recentToolStripMenuItem.Size = new System.Drawing.Size(204, 22); + this.recentToolStripMenuItem.Text = "Recent"; + this.recentToolStripMenuItem.DropDownOpened += new System.EventHandler(this.recentToolStripMenuItem_DropDownOpened); + // + // noneToolStripMenuItem + // + this.noneToolStripMenuItem.Name = "noneToolStripMenuItem"; + this.noneToolStripMenuItem.Size = new System.Drawing.Size(135, 22); + this.noneToolStripMenuItem.Text = "None"; + // + // toolStripSeparator2 + // + this.toolStripSeparator2.Name = "toolStripSeparator2"; + this.toolStripSeparator2.Size = new System.Drawing.Size(132, 6); + // + // clearToolStripMenuItem + // + this.clearToolStripMenuItem.Name = "clearToolStripMenuItem"; + this.clearToolStripMenuItem.Size = new System.Drawing.Size(135, 22); + this.clearToolStripMenuItem.Text = "Clear"; + // + // autoLoadToolStripMenuItem + // + this.autoLoadToolStripMenuItem.Name = "autoLoadToolStripMenuItem"; + this.autoLoadToolStripMenuItem.Size = new System.Drawing.Size(135, 22); + this.autoLoadToolStripMenuItem.Text = "Auto-Load"; // // exitToolStripMenuItem // this.exitToolStripMenuItem.Name = "exitToolStripMenuItem"; this.exitToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.F4))); this.exitToolStripMenuItem.Size = new System.Drawing.Size(204, 22); - this.exitToolStripMenuItem.Text = "E&xit"; + this.exitToolStripMenuItem.Text = "&Close"; this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); // // optionsToolStripMenuItem // this.optionsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.hackyAutoLoadToolStripMenuItem, this.restoreOriginalWindowSizeToolStripMenuItem, this.saveWindowPositionToolStripMenuItem}); this.optionsToolStripMenuItem.Name = "optionsToolStripMenuItem"; this.optionsToolStripMenuItem.Size = new System.Drawing.Size(56, 20); this.optionsToolStripMenuItem.Text = "&Options"; // - // hackyAutoLoadToolStripMenuItem - // - this.hackyAutoLoadToolStripMenuItem.Name = "hackyAutoLoadToolStripMenuItem"; - this.hackyAutoLoadToolStripMenuItem.Size = new System.Drawing.Size(190, 22); - this.hackyAutoLoadToolStripMenuItem.Text = "HackyAutoLoad"; - this.hackyAutoLoadToolStripMenuItem.Click += new System.EventHandler(this.hackyAutoLoadToolStripMenuItem_Click_1); - // // restoreOriginalWindowSizeToolStripMenuItem // this.restoreOriginalWindowSizeToolStripMenuItem.Name = "restoreOriginalWindowSizeToolStripMenuItem"; @@ -865,12 +906,17 @@ private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem newSearchToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem optionsToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem hackyAutoLoadToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem restoreOriginalWindowSizeToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem saveWindowPositionToolStripMenuItem; private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; private System.Windows.Forms.Label MemDomainLabel; private System.Windows.Forms.Label OutputLabel; private System.Windows.Forms.Label label1; + private System.Windows.Forms.ToolStripMenuItem recentToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem noneToolStripMenuItem; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator2; + private System.Windows.Forms.ToolStripMenuItem clearToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem autoLoadToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem appendFileToolStripMenuItem; } } \ No newline at end of file diff --git a/BizHawk.MultiClient/tools/RamSearch.cs b/BizHawk.MultiClient/tools/RamSearch.cs index 9ee75b9c2c..13846f879c 100644 --- a/BizHawk.MultiClient/tools/RamSearch.cs +++ b/BizHawk.MultiClient/tools/RamSearch.cs @@ -20,7 +20,7 @@ namespace BizHawk.MultiClient //Window position gets saved but doesn't load properly //Add to Ram watch fails to open ram watch if it has neve been opened //Implement DWORD start new search & updateValues - //Impelment File handling + //Doesnt' release handle after saving file, Ram Watch too? //Implement Preview search //Implement Check Misaligned (does 2 & 4 byte on each possible address instead of every other (or every 4) //Implement definitions of Previous value @@ -37,6 +37,8 @@ namespace BizHawk.MultiClient //Reset window position item int defaultWidth; //For saving the default size of the dialog, so the user can restore if desired int defaultHeight; + string currentSearchFile = ""; + bool changes = false; public RamSearch() { @@ -123,12 +125,17 @@ namespace BizHawk.MultiClient private void OpenSearchFile() { - - } - - private void SaveAs() - { - + var file = GetFileFromUser(); + if (file != null) + { + bool r = true; + if (changes) r = AskSave(); + if (r) + { + LoadSearchFile(file.FullName, false); + DisplaySearchList(); + } + } } private void openToolStripMenuItem_Click(object sender, EventArgs e) @@ -914,20 +921,6 @@ namespace BizHawk.MultiClient DisplaySearchList(); } - private void hackyAutoLoadToolStripMenuItem_Click_1(object sender, EventArgs e) - { - if (Global.Config.AutoLoadRamSearch == true) - { - Global.Config.AutoLoadRamSearch = false; - hackyAutoLoadToolStripMenuItem.Checked = false; - } - else - { - Global.Config.AutoLoadRamSearch = true; - hackyAutoLoadToolStripMenuItem.Checked = true; - } - } - private void SearchListView_MouseDoubleClick(object sender, MouseEventArgs e) { ListView.SelectedIndexCollection indexes = SearchListView.SelectedIndices; @@ -1025,5 +1018,260 @@ namespace BizHawk.MultiClient t.Show("Must be a valid unsigned decimal value", DifferentByBox, 5000); } } + + private bool SaveSearchFile(string path) + { + var file = new FileInfo(path); + + using (StreamWriter sw = new StreamWriter(path)) + { + string str = ""; + + for (int x = 0; x < searchList.Count; x++) + { + str += string.Format("{0:X4}", searchList[x].address) + "\t"; + str += searchList[x].GetTypeByChar().ToString() + "\t"; + str += searchList[x].GetSignedByChar().ToString() + "\t"; + + if (searchList[x].bigendian == true) + str += "1\t"; + else + str += "0\t"; + + str += searchList[x].notes + "\n"; + } + + sw.WriteLine(str); + } + changes = false; + return true; + } + + private FileInfo GetSaveFileFromUser() + { + var sfd = new SaveFileDialog(); + sfd.InitialDirectory = Global.Config.LastRomPath; + sfd.Filter = "Watch Files (*.wch)|*.wch|All Files|*.*"; + sfd.RestoreDirectory = true; + Global.Sound.StopSound(); + var result = sfd.ShowDialog(); + Global.Sound.StartSound(); + if (result != DialogResult.OK) + return null; + var file = new FileInfo(sfd.FileName); + Global.Config.LastRomPath = file.DirectoryName; + return file; + } + + public void SaveAs() + { + var file = GetSaveFileFromUser(); + if (file != null) + { + SaveSearchFile(file.FullName); + currentSearchFile = file.FullName; + } + OutputLabel.Text = Path.GetFileName(currentSearchFile) + " saved."; + } + + public bool AskSave() + { + if (changes) + { + DialogResult result = MessageBox.Show("Save Changes?", "Ram Watch", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3); + + if (result == DialogResult.Yes) + { + //TOOD: Do quicksave if filename, else save as + if (string.Compare(currentSearchFile, "") == 0) + { + SaveAs(); + } + else + SaveSearchFile(currentSearchFile); + return true; + } + else if (result == DialogResult.No) + return true; + else if (result == DialogResult.Cancel) + return false; + } + return true; + } + + + private void LoadSearchFromRecent(string file) + { + bool z = true; + if (changes) z = AskSave(); + + if (z) + { + bool r = LoadSearchFile(file, false); + if (!r) + { + DialogResult result = MessageBox.Show("Could not open " + file + "\nRemove from list?", "File not found", MessageBoxButtons.YesNo, MessageBoxIcon.Error); + if (result == DialogResult.Yes) + Global.Config.RecentSearches.Remove(file); + } + DisplaySearchList(); + changes = false; + } + } + + public int HowMany(string str, char c) + { + int count = 0; + for (int x = 0; x < str.Length; x++) + { + if (str[x] == c) + count++; + } + return count; + } + + bool LoadSearchFile(string path, bool append) + { + int y, z; + var file = new FileInfo(path); + if (file.Exists == false) return false; + + using (StreamReader sr = file.OpenText()) + { + if (!append) + currentSearchFile = path; + + int count = 0; + string s = ""; + string temp = ""; + + if (append == false) + searchList.Clear(); //Wipe existing list and read from file + + while ((s = sr.ReadLine()) != null) + { + //parse each line and add to watchList + + //.wch files from other emulators start with a number representing the number of watch, that line can be discarded here + //Any properly formatted line couldn't possibly be this short anyway, this also takes care of any garbage lines that might be in a file + if (s.Length < 5) continue; + + z = HowMany(s, '\t'); + if (z == 5) + { + //If 5, then this is a .wch file format made from another emulator, the first column (watch position) is not needed here + y = s.IndexOf('\t') + 1; + s = s.Substring(y, s.Length - y); //5 digit value representing the watch position number + } + else if (z != 4) + continue; //If not 4, something is wrong with this line, ignore it + count++; + Watch w = new Watch(); + + temp = s.Substring(0, s.IndexOf('\t')); + w.address = int.Parse(temp, NumberStyles.HexNumber); + + y = s.IndexOf('\t') + 1; + s = s.Substring(y, s.Length - y); //Type + w.SetTypeByChar(s[0]); + + y = s.IndexOf('\t') + 1; + s = s.Substring(y, s.Length - y); //Signed + w.SetSignedByChar(s[0]); + + y = s.IndexOf('\t') + 1; + s = s.Substring(y, s.Length - y); //Endian + y = Int16.Parse(s[0].ToString()); + if (y == 0) + w.bigendian = false; + else + w.bigendian = true; + + //w.notes = s.Substring(2, s.Length - 2); //User notes + + searchList.Add(w); + } + + Global.Config.RecentSearches.Add(file.FullName); + changes = false; + OutputLabel.Text = Path.GetFileName(file.FullName); + //Update the number of watches + SetTotal(); + } + + return true; + } + + private void recentToolStripMenuItem_DropDownOpened(object sender, EventArgs e) + { + //Clear out recent Roms list + //repopulate it with an up to date list + recentToolStripMenuItem.DropDownItems.Clear(); + + if (Global.Config.RecentSearches.IsEmpty()) + { + recentToolStripMenuItem.DropDownItems.Add("None"); + } + else + { + for (int x = 0; x < Global.Config.RecentSearches.Length(); x++) + { + string path = Global.Config.RecentSearches.GetRecentFileByPosition(x); + var item = new ToolStripMenuItem(); + item.Text = path; + item.Click += (o, ev) => LoadSearchFromRecent(path); + recentToolStripMenuItem.DropDownItems.Add(item); + } + } + + recentToolStripMenuItem.DropDownItems.Add("-"); + + var clearitem = new ToolStripMenuItem(); + clearitem.Text = "&Clear"; + clearitem.Click += (o, ev) => Global.Config.RecentSearches.Clear(); + recentToolStripMenuItem.DropDownItems.Add(clearitem); + + var auto = new ToolStripMenuItem(); + auto.Text = "&Auto-Load"; + auto.Click += (o, ev) => UpdateAutoLoadRamSearch(); + if (Global.Config.AutoLoadRamSearch == true) + auto.Checked = true; + else + auto.Checked = false; + recentToolStripMenuItem.DropDownItems.Add(auto); + } + + private void UpdateAutoLoadRamSearch() + { + autoLoadToolStripMenuItem.Checked = Global.Config.AutoLoadRamSearch ^= true; + } + + private void appendFileToolStripMenuItem_Click(object sender, EventArgs e) + { + var file = GetFileFromUser(); + if (file != null) + LoadSearchFile(file.FullName, true); + DisplaySearchList(); + changes = true; + } + + private FileInfo GetFileFromUser() + { + var ofd = new OpenFileDialog(); + ofd.InitialDirectory = Global.Config.LastRomPath; + ofd.Filter = "Watch Files (*.wch)|*.wch|All Files|*.*"; + ofd.RestoreDirectory = true; + + Global.Sound.StopSound(); + var result = ofd.ShowDialog(); + Global.Sound.StartSound(); + if (result != DialogResult.OK) + return null; + var file = new FileInfo(ofd.FileName); + Global.Config.LastRomPath = file.DirectoryName; + return file; + } } + + } diff --git a/BizHawk.MultiClient/tools/RamWatch.Designer.cs b/BizHawk.MultiClient/tools/RamWatch.Designer.cs index 37d5f1b258..de1ca90f4b 100644 --- a/BizHawk.MultiClient/tools/RamWatch.Designer.cs +++ b/BizHawk.MultiClient/tools/RamWatch.Designer.cs @@ -56,7 +56,7 @@ this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator(); this.moveUpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.moveDownToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.WatchListView = new VirtualListView(); + this.WatchListView = new BizHawk.VirtualListView(); this.Address = new System.Windows.Forms.ColumnHeader(); this.Value = new System.Windows.Forms.ColumnHeader(); this.Notes = new System.Windows.Forms.ColumnHeader(); @@ -174,24 +174,24 @@ // noneToolStripMenuItem // this.noneToolStripMenuItem.Name = "noneToolStripMenuItem"; - this.noneToolStripMenuItem.Size = new System.Drawing.Size(135, 22); + this.noneToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.noneToolStripMenuItem.Text = "None"; // // toolStripSeparator4 // this.toolStripSeparator4.Name = "toolStripSeparator4"; - this.toolStripSeparator4.Size = new System.Drawing.Size(132, 6); + this.toolStripSeparator4.Size = new System.Drawing.Size(149, 6); // // clearToolStripMenuItem // this.clearToolStripMenuItem.Name = "clearToolStripMenuItem"; - this.clearToolStripMenuItem.Size = new System.Drawing.Size(135, 22); + this.clearToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.clearToolStripMenuItem.Text = "Clear"; // // autoLoadToolStripMenuItem // this.autoLoadToolStripMenuItem.Name = "autoLoadToolStripMenuItem"; - this.autoLoadToolStripMenuItem.Size = new System.Drawing.Size(135, 22); + this.autoLoadToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.autoLoadToolStripMenuItem.Text = "Auto-Load"; // // toolStripSeparator1 @@ -318,16 +318,17 @@ this.WatchListView.ContextMenuStrip = this.contextMenuStrip1; this.WatchListView.FullRowSelect = true; this.WatchListView.GridLines = true; + this.WatchListView.ItemCount = 0; this.WatchListView.LabelEdit = true; this.WatchListView.Location = new System.Drawing.Point(25, 76); this.WatchListView.Name = "WatchListView"; + this.WatchListView.selectedItem = -1; this.WatchListView.Size = new System.Drawing.Size(314, 327); this.WatchListView.TabIndex = 1; this.WatchListView.UseCompatibleStateImageBehavior = false; this.WatchListView.View = System.Windows.Forms.View.Details; this.WatchListView.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.WatchListView_MouseDoubleClick); this.WatchListView.AfterLabelEdit += new System.Windows.Forms.LabelEditEventHandler(this.WatchListView_AfterLabelEdit); - this.WatchListView.SelectedIndexChanged += new System.EventHandler(this.WatchListView_SelectedIndexChanged); // // Address // diff --git a/BizHawk.MultiClient/tools/RamWatch.cs b/BizHawk.MultiClient/tools/RamWatch.cs index 4700367516..05b8c9a2c7 100644 --- a/BizHawk.MultiClient/tools/RamWatch.cs +++ b/BizHawk.MultiClient/tools/RamWatch.cs @@ -464,7 +464,6 @@ namespace BizHawk.MultiClient private void OpenWatchFile() { - var file = GetFileFromUser(); if (file != null) { @@ -600,16 +599,7 @@ namespace BizHawk.MultiClient private void UpdateAutoLoadRamWatch() { - if (Global.Config.AutoLoadRamWatch == true) - { - Global.Config.AutoLoadRamWatch = false; - autoLoadToolStripMenuItem.Checked = false; - } - else - { - Global.Config.AutoLoadRamWatch = true; - autoLoadToolStripMenuItem.Checked = true; - } + autoLoadToolStripMenuItem.Checked = Global.Config.AutoLoadRamWatch ^= true; } private void recentToolStripMenuItem_DropDownOpened(object sender, EventArgs e) { @@ -637,7 +627,7 @@ namespace BizHawk.MultiClient var clearitem = new ToolStripMenuItem(); clearitem.Text = "&Clear"; - clearitem.Click += (o, ev) => Global.Config.RecentRoms.Clear(); + clearitem.Click += (o, ev) => Global.Config.RecentWatches.Clear(); recentToolStripMenuItem.DropDownItems.Add(clearitem); var auto = new ToolStripMenuItem(); @@ -887,10 +877,5 @@ namespace BizHawk.MultiClient { e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.Copy : DragDropEffects.None;string[] filePaths = (string[]) e.Data.GetData(DataFormats.FileDrop); } - - private void WatchListView_SelectedIndexChanged(object sender, EventArgs e) - { - - } } }