From 741a4a9b83cf0c1790dd4dfda002b327a83c6f2c Mon Sep 17 00:00:00 2001 From: adelikat Date: Thu, 3 Oct 2013 15:27:51 +0000 Subject: [PATCH] New Cheat List - some small progress --- BizHawk.MultiClient/tools/Cheats/CheatList.cs | 62 ++++++++++++++++++- .../tools/Cheats/NewCheatForm.Designer.cs | 27 ++++---- .../tools/Cheats/NewCheatForm.cs | 29 ++++++++- .../tools/Cheats/NewCheatForm.resx | 2 +- 4 files changed, 103 insertions(+), 17 deletions(-) diff --git a/BizHawk.MultiClient/tools/Cheats/CheatList.cs b/BizHawk.MultiClient/tools/Cheats/CheatList.cs index 85cdd4fd17..3077320b5a 100644 --- a/BizHawk.MultiClient/tools/Cheats/CheatList.cs +++ b/BizHawk.MultiClient/tools/Cheats/CheatList.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.IO; +using System.Windows.Forms; namespace BizHawk.MultiClient { @@ -112,7 +114,7 @@ namespace BizHawk.MultiClient } else { - switch(domain.Endian) + switch (domain.Endian) { default: case Endian.Unknown: @@ -144,6 +146,38 @@ namespace BizHawk.MultiClient public bool Load(string path, bool append) { + var file = new FileInfo(path); + if (file.Exists == false) + { + return false; + } + + if (!append) + { + _currentFileName = path; + } + + using (StreamReader sr = file.OpenText()) + { + if (!append) + { + Clear(); + } + + string s; + while ((s = sr.ReadLine()) != null) + { + try + { + + } + catch + { + continue; + } + } + } + throw new NotImplementedException(); } @@ -165,5 +199,31 @@ namespace BizHawk.MultiClient } #endregion + + #region File Handling + + public static FileInfo GetFileFromUser(string currentFile) + { + var ofd = new OpenFileDialog(); + if (!String.IsNullOrWhiteSpace(currentFile)) + { + ofd.FileName = Path.GetFileNameWithoutExtension(currentFile); + } + ofd.InitialDirectory = PathManager.MakeAbsolutePath( + Global.Config.PathEntries[Global.Emulator.SystemId, "Cheats"].Path, + Global.Emulator.SystemId); + ofd.Filter = "Cheat Files (*.cht)|*.cht|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); + return file; + } + + #endregion } } diff --git a/BizHawk.MultiClient/tools/Cheats/NewCheatForm.Designer.cs b/BizHawk.MultiClient/tools/Cheats/NewCheatForm.Designer.cs index 3159e8e9d7..c67f443053 100644 --- a/BizHawk.MultiClient/tools/Cheats/NewCheatForm.Designer.cs +++ b/BizHawk.MultiClient/tools/Cheats/NewCheatForm.Designer.cs @@ -72,7 +72,7 @@ this.ColumnsSubMenu = new System.Windows.Forms.ToolStripMenuItem(); this.toolStrip1 = new ToolStripEx(); this.newToolStripButton = new System.Windows.Forms.ToolStripButton(); - this.openToolStripButton = new System.Windows.Forms.ToolStripButton(); + this.OpenToolBarItem = new System.Windows.Forms.ToolStripButton(); this.saveToolStripButton = new System.Windows.Forms.ToolStripButton(); this.toolStripSeparator = new System.Windows.Forms.ToolStripSeparator(); this.cutToolStripButton = new System.Windows.Forms.ToolStripButton(); @@ -186,12 +186,12 @@ // // OpenMenuItem // - this.OpenMenuItem.Enabled = false; this.OpenMenuItem.Image = global::BizHawk.MultiClient.Properties.Resources.OpenFile; this.OpenMenuItem.Name = "OpenMenuItem"; this.OpenMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O))); this.OpenMenuItem.Size = new System.Drawing.Size(195, 22); this.OpenMenuItem.Text = "&Open..."; + this.OpenMenuItem.Click += new System.EventHandler(this.OpenMenuItem_Click); // // SaveMenuItem // @@ -213,7 +213,6 @@ // // AppendMenuItem // - this.AppendMenuItem.Enabled = false; this.AppendMenuItem.Name = "AppendMenuItem"; this.AppendMenuItem.Size = new System.Drawing.Size(195, 22); this.AppendMenuItem.Text = "Append File"; @@ -231,7 +230,7 @@ // toolStripSeparator4 // this.toolStripSeparator4.Name = "toolStripSeparator4"; - this.toolStripSeparator4.Size = new System.Drawing.Size(149, 6); + this.toolStripSeparator4.Size = new System.Drawing.Size(57, 6); // // toolStripSeparator1 // @@ -439,7 +438,7 @@ this.toolStrip1.ClickThrough = true; this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.newToolStripButton, - this.openToolStripButton, + this.OpenToolBarItem, this.saveToolStripButton, this.toolStripSeparator, this.cutToolStripButton, @@ -465,15 +464,15 @@ this.newToolStripButton.Size = new System.Drawing.Size(23, 22); this.newToolStripButton.Text = "&New"; // - // openToolStripButton + // OpenToolBarItem // - this.openToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; - this.openToolStripButton.Enabled = false; - this.openToolStripButton.Image = ((System.Drawing.Image)(resources.GetObject("openToolStripButton.Image"))); - this.openToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta; - this.openToolStripButton.Name = "openToolStripButton"; - this.openToolStripButton.Size = new System.Drawing.Size(23, 22); - this.openToolStripButton.Text = "&Open"; + this.OpenToolBarItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.OpenToolBarItem.Image = ((System.Drawing.Image)(resources.GetObject("OpenToolBarItem.Image"))); + this.OpenToolBarItem.ImageTransparentColor = System.Drawing.Color.Magenta; + this.OpenToolBarItem.Name = "OpenToolBarItem"; + this.OpenToolBarItem.Size = new System.Drawing.Size(23, 22); + this.OpenToolBarItem.Text = "&Open"; + this.OpenToolBarItem.Click += new System.EventHandler(this.OpenMenuItem_Click); // // saveToolStripButton // @@ -643,7 +642,7 @@ private System.Windows.Forms.ToolStripMenuItem RestoreWindowSizeMenuItem; private ToolStripEx toolStrip1; private System.Windows.Forms.ToolStripButton newToolStripButton; - private System.Windows.Forms.ToolStripButton openToolStripButton; + private System.Windows.Forms.ToolStripButton OpenToolBarItem; private System.Windows.Forms.ToolStripButton saveToolStripButton; private System.Windows.Forms.ToolStripSeparator toolStripSeparator; private System.Windows.Forms.ToolStripButton cutToolStripButton; diff --git a/BizHawk.MultiClient/tools/Cheats/NewCheatForm.cs b/BizHawk.MultiClient/tools/Cheats/NewCheatForm.cs index 2780bc7855..86f2546ad3 100644 --- a/BizHawk.MultiClient/tools/Cheats/NewCheatForm.cs +++ b/BizHawk.MultiClient/tools/Cheats/NewCheatForm.cs @@ -13,6 +13,8 @@ namespace BizHawk.MultiClient { public partial class NewCheatForm : Form { + private NewCheatList Cheats = new NewCheatList(); + public NewCheatForm() { InitializeComponent(); @@ -79,9 +81,28 @@ namespace BizHawk.MultiClient return true; } + private void LoadFile(FileInfo file, bool append) + { + if (file != null) + { + bool result = true; + if (Cheats.Changes) + { + result = AskSave(); + } + + if (result) + { + Cheats.Load(file.FullName, append); + UpdateListView(); + Global.Config.RecentCheats.Add(Cheats.CurrentFileName); + } + } + } + private void NewCheatForm_Load(object sender, EventArgs e) { - + } #region Events @@ -99,6 +120,12 @@ namespace BizHawk.MultiClient RecentSubMenu.DropDownItems.AddRange(Global.Config.RecentCheats.GenerateRecentMenu(LoadFileFromRecent)); } + private void OpenMenuItem_Click(object sender, EventArgs e) + { + bool append = sender == AppendMenuItem; + LoadFile(NewCheatList.GetFileFromUser(Cheats.CurrentFileName), append); + } + private void ExitMenuItem_Click(object sender, EventArgs e) { Close(); diff --git a/BizHawk.MultiClient/tools/Cheats/NewCheatForm.resx b/BizHawk.MultiClient/tools/Cheats/NewCheatForm.resx index d9ad53d612..6cc3b67bf5 100644 --- a/BizHawk.MultiClient/tools/Cheats/NewCheatForm.resx +++ b/BizHawk.MultiClient/tools/Cheats/NewCheatForm.resx @@ -135,7 +135,7 @@ 2Mz2wxeg6/UAAAAASUVORK5CYII= - + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAJHSURBVDhPxZBdSNNhFMb/F110ZZEVhVBgeeHNICiiuggp