diff --git a/BizHawk.MultiClient/RamWatch.cs b/BizHawk.MultiClient/RamWatch.cs index 9422e0abac..e635a8af52 100644 --- a/BizHawk.MultiClient/RamWatch.cs +++ b/BizHawk.MultiClient/RamWatch.cs @@ -55,6 +55,35 @@ namespace BizHawk.MultiClient watchList.Clear(); DisplayWatchList(); } + + private bool SaveWatchFile(string path) + { + var file = new FileInfo(path); + //if (file.Exists == true) //TODO: prompt to overwrite + + using (StreamWriter sw = new StreamWriter(path)) + { + string str = ""; + + for (int x = 0; x < watchList.Count; x++) + { + str += watchList[x].address.ToString() + "\t"; //TODO: Make hex + str += watchList[x].GetTypeByChar().ToString() + "\t"; + str += watchList[x].GetSignedByChar().ToString() + "\t"; + + if (watchList[x].bigendian == true) + str += "1\t"; + else + str += "0\t"; + + str += watchList[x].notes + "\n"; + } + + sw.WriteLine(str); + } + + return true; + } bool LoadWatchFile(string path, bool append) { @@ -188,9 +217,28 @@ namespace BizHawk.MultiClient } + 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; + } + private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) { - + var file = GetSaveFileFromUser(); + if (file != null) + SaveWatchFile(file.FullName); + //TODO: inform the user (with using an annoying message box) } private void appendFileToolStripMenuItem_Click(object sender, EventArgs e) diff --git a/BizHawk.MultiClient/Watch.cs b/BizHawk.MultiClient/Watch.cs index 1d861a6253..4d254e6602 100644 --- a/BizHawk.MultiClient/Watch.cs +++ b/BizHawk.MultiClient/Watch.cs @@ -53,6 +53,21 @@ namespace BizHawk.MultiClient } } + public char GetTypeByChar() + { + switch (type) + { + case atype.BYTE: + return 'b'; + case atype.WORD: + return 'w'; + case atype.DWORD: + return 'd'; + default: + return 'b'; //Just in case + } + } + public bool SetSignedByChar(char c) //s = signed, u = unsigned, h = hex { switch (c) @@ -70,5 +85,20 @@ namespace BizHawk.MultiClient return false; } } + + public char GetSignedByChar() + { + switch (signed) + { + case asigned.SIGNED: + return 's'; + case asigned.UNSIGNED: + return 'u'; + case asigned.HEX: + return 'h'; + default: + return 's'; //Just in case + } + } } }