From 4e9b6be8e5aa3c3c2b48e109460f8c790345f377 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 1 Jul 2017 19:43:51 -0700 Subject: [PATCH] Convert console output to debug output output messages are now no longer in release builds, as they are only visible when debugging in an IDE. --- PKHeX.Core/Legality/Analysis.cs | 3 +- PKHeX.Core/PKM/PK2.cs | 3 +- PKHeX.Core/PKM/PKMConverter.cs | 3 +- PKHeX.Core/PersonalInfo/PersonalTable.cs | 5 +-- PKHeX.Core/Saves/SAV5.cs | 7 ++-- PKHeX.Core/Saves/SAV6.cs | 5 +-- PKHeX.Core/Saves/SAV7.cs | 5 +-- PKHeX.Core/Saves/SaveFile.cs | 3 +- PKHeX.Core/Util/DataUtil.cs | 3 +- .../Controls/SAV Editor/SlotChangeManager.cs | 33 ++++++++----------- PKHeX.WinForms/MainWindow/Main.cs | 6 ++-- .../Subforms/PKM Editors/BatchEditor.cs | 9 ++--- PKHeX.WinForms/Subforms/SAV_Database.cs | 2 +- PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs | 2 +- .../Subforms/Save Editors/SAV_EventFlags.cs | 5 +-- PKHeX.WinForms/Util/FontUtil.cs | 3 +- PKHeX.WinForms/Util/NetUtil.cs | 5 +-- PKHeX.WinForms/Util/SAVUtil.cs | 3 +- 18 files changed, 57 insertions(+), 48 deletions(-) diff --git a/PKHeX.Core/Legality/Analysis.cs b/PKHeX.Core/Legality/Analysis.cs index 299fbca6d..8c3fa6033 100644 --- a/PKHeX.Core/Legality/Analysis.cs +++ b/PKHeX.Core/Legality/Analysis.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Reflection; using static PKHeX.Core.LegalityCheckStrings; @@ -91,7 +92,7 @@ public LegalityAnalysis(PKM pk) } catch (Exception e) { - Console.WriteLine(e.Message); + Debug.WriteLine(e.Message); Valid = false; AddLine(Severity.Invalid, V190, CheckIdentifier.Misc); pkm = pk; diff --git a/PKHeX.Core/PKM/PK2.cs b/PKHeX.Core/PKM/PK2.cs index 5626b375b..190a56ab7 100644 --- a/PKHeX.Core/PKM/PK2.cs +++ b/PKHeX.Core/PKM/PK2.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Linq; namespace PKHeX.Core @@ -266,7 +267,7 @@ public override int Gender case 191: return IV_ATK >= 12 ? 0 : 1; } - Console.WriteLine("Unknown Gender value: " + gv); + Debug.WriteLine("Unknown Gender value: " + gv); return 0; } set { } diff --git a/PKHeX.Core/PKM/PKMConverter.cs b/PKHeX.Core/PKM/PKMConverter.cs index 87cbb9fe9..4d0c79318 100644 --- a/PKHeX.Core/PKM/PKMConverter.cs +++ b/PKHeX.Core/PKM/PKMConverter.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Linq; using System.Reflection; @@ -197,7 +198,7 @@ public static PKM ConvertToType(PKM pk, Type PKMType, out string comment) Type fromType = pk.GetType(); int fromFormat = int.Parse(fromType.Name.Last().ToString()); int toFormat = int.Parse(PKMType.Name.Last().ToString()); - Console.WriteLine($"Trying to convert {fromType.Name} to {PKMType.Name}."); + Debug.WriteLine($"Trying to convert {fromType.Name} to {PKMType.Name}."); PKM pkm = null; diff --git a/PKHeX.Core/PersonalInfo/PersonalTable.cs b/PKHeX.Core/PersonalInfo/PersonalTable.cs index f16f1b76d..f5ce5edf8 100644 --- a/PKHeX.Core/PersonalInfo/PersonalTable.cs +++ b/PKHeX.Core/PersonalInfo/PersonalTable.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Linq; namespace PKHeX.Core @@ -119,13 +120,13 @@ private PersonalTable(byte[] data, GameVersion format) public int[] GetAbilities(int species, int forme) { if (species >= Table.Length) - { species = 0; Console.WriteLine("Requested out of bounds SpeciesID"); } + { species = 0; Debug.WriteLine("Requested out of bounds SpeciesID"); } return this[GetFormeIndex(species, forme)].Abilities; } public int GetFormeIndex(int species, int forme) { if (species >= Table.Length) - { species = 0; Console.WriteLine("Requested out of bounds SpeciesID"); } + { species = 0; Debug.WriteLine("Requested out of bounds SpeciesID"); } return this[species].FormeIndex(species, forme); } public PersonalInfo GetFormeEntry(int species, int forme) diff --git a/PKHeX.Core/Saves/SAV5.cs b/PKHeX.Core/Saves/SAV5.cs index a248e258f..069241146 100644 --- a/PKHeX.Core/Saves/SAV5.cs +++ b/PKHeX.Core/Saves/SAV5.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Linq; using System.Text; @@ -290,7 +291,7 @@ protected override void SetChecksums() // Check for invalid block lengths if (Blocks.Length < 3) // arbitrary... { - Console.WriteLine("Not enough blocks ({0}), aborting SetChecksums", Blocks.Length); + Debug.WriteLine("Not enough blocks ({0}), aborting SetChecksums", Blocks.Length); return; } // Apply checksums @@ -309,7 +310,7 @@ public override bool ChecksumsValid // Check for invalid block lengths if (Blocks.Length < 3) // arbitrary... { - Console.WriteLine("Not enough blocks ({0}), aborting SetChecksums", Blocks.Length); + Debug.WriteLine("Not enough blocks ({0}), aborting SetChecksums", Blocks.Length); return false; } @@ -332,7 +333,7 @@ public override string ChecksumInfo // Check for invalid block lengths if (Blocks.Length < 3) // arbitrary... { - Console.WriteLine("Not enough blocks ({0}), aborting SetChecksums", Blocks.Length); + Debug.WriteLine("Not enough blocks ({0}), aborting SetChecksums", Blocks.Length); return "Not a valid save to check."; } string r = ""; diff --git a/PKHeX.Core/Saves/SAV6.cs b/PKHeX.Core/Saves/SAV6.cs index adf4b0d5a..6788091ef 100644 --- a/PKHeX.Core/Saves/SAV6.cs +++ b/PKHeX.Core/Saves/SAV6.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Linq; using System.Text; @@ -92,14 +93,14 @@ protected override void SetChecksums() // Check for invalid block lengths if (Blocks.Length < 3) // arbitrary... { - Console.WriteLine("Not enough blocks ({0}), aborting SetChecksums", Blocks.Length); + Debug.WriteLine("Not enough blocks ({0}), aborting SetChecksums", Blocks.Length); return; } // Apply checksums for (int i = 0; i < Blocks.Length; i++) { if (Blocks[i].Length + Blocks[i].Offset > Data.Length) - { Console.WriteLine("Block {0} has invalid offset/length value.", i); return; } + { Debug.WriteLine("Block {0} has invalid offset/length value.", i); return; } byte[] array = new byte[Blocks[i].Length]; Array.Copy(Data, Blocks[i].Offset, array, 0, array.Length); BitConverter.GetBytes(SaveUtil.CRC16_CCITT(array)).CopyTo(Data, BlockInfoOffset + 6 + i * 8); diff --git a/PKHeX.Core/Saves/SAV7.cs b/PKHeX.Core/Saves/SAV7.cs index b36543c4e..43144fba8 100644 --- a/PKHeX.Core/Saves/SAV7.cs +++ b/PKHeX.Core/Saves/SAV7.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Linq; using System.Text; @@ -130,14 +131,14 @@ protected override void SetChecksums() // Check for invalid block lengths if (Blocks.Length < 3) // arbitrary... { - Console.WriteLine("Not enough blocks ({0}), aborting SetChecksums", Blocks.Length); + Debug.WriteLine("Not enough blocks ({0}), aborting SetChecksums", Blocks.Length); return; } // Apply checksums for (int i = 0; i < Blocks.Length; i++) { if (Blocks[i].Length + Blocks[i].Offset > Data.Length) - { Console.WriteLine("Block {0} has invalid offset/length value.", i); return; } + { Debug.WriteLine("Block {0} has invalid offset/length value.", i); return; } byte[] array = new byte[Blocks[i].Length]; Array.Copy(Data, Blocks[i].Offset, array, 0, array.Length); BitConverter.GetBytes(SaveUtil.CRC16_7(array, Blocks[i].ID)).CopyTo(Data, BlockInfoOffset + 6 + i * 8); diff --git a/PKHeX.Core/Saves/SaveFile.cs b/PKHeX.Core/Saves/SaveFile.cs index cd4622710..fb7fc358b 100644 --- a/PKHeX.Core/Saves/SaveFile.cs +++ b/PKHeX.Core/Saves/SaveFile.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Linq; namespace PKHeX.Core @@ -193,7 +194,7 @@ public PKM[] PartyData if (value.Any(pk => PKMType != pk.GetType())) throw new ArgumentException($"Not {PKMType} array."); if (value[0].Species == 0) - Console.WriteLine($"Empty first slot, received {value.Length}."); + Debug.WriteLine($"Empty first slot, received {value.Length}."); PKM[] newParty = value.Where(pk => pk.Species != 0).ToArray(); diff --git a/PKHeX.Core/Util/DataUtil.cs b/PKHeX.Core/Util/DataUtil.cs index 7fe1d7c23..21f543b5a 100644 --- a/PKHeX.Core/Util/DataUtil.cs +++ b/PKHeX.Core/Util/DataUtil.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Reflection; @@ -199,7 +200,7 @@ private static void SetLocalization(Type t, IEnumerable lines) } catch { - Console.WriteLine($"Property not present: {prop} || Value written: {value}"); + Debug.WriteLine($"Property not present: {prop} || Value written: {value}"); } } } diff --git a/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs b/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs index 3cc681f75..9d00a75b9 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; @@ -120,23 +121,17 @@ public void HandleMovePKM(PictureBox pb, int slot, int box, bool encrypt) // Browser apps need time to load data since the file isn't moved to a location on the user's local storage. // Tested 10ms -> too quick, 100ms was fine. 500ms should be safe? - if (!external) - { - if (File.Exists(newfile) && DragInfo.CurrentPath == null) - File.Delete(newfile); - } - else - { - new Task(() => - { - Thread.Sleep(500); - if (File.Exists(newfile) && DragInfo.CurrentPath == null) - File.Delete(newfile); - }).Start(); - } + int delay = external ? 500 : 0; + DeleteAsync(newfile, delay); if (DragInfo.Source.IsParty || DragInfo.Destination.IsParty) SE.SetParty(); } + private async void DeleteAsync(string path, int delay) + { + await Task.Delay(delay); + if (File.Exists(path) && DragInfo.CurrentPath == null) + File.Delete(path); + } private string CreateDragDropPKM(PictureBox pb, int box, bool encrypt, out bool external) { byte[] dragdata = SAV.DecryptPKM(DragInfo.Source.OriginalData); @@ -245,7 +240,7 @@ private bool TryLoadFiles(string[] files, DragEventArgs e, bool noEgg) if (pk == null) { WinFormsUtil.Error(c); - Console.WriteLine(c); + Debug.WriteLine(c); return false; } @@ -258,14 +253,14 @@ private bool TryLoadFiles(string[] files, DragEventArgs e, bool noEgg) string concat = string.Join(Environment.NewLine, errata); if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, concat, "Continue?")) { - Console.WriteLine(c); - Console.WriteLine(concat); + Debug.WriteLine(c); + Debug.WriteLine(concat); return false; } } SetPKM(pk, false, Resources.slotSet); - Console.WriteLine(c); + Debug.WriteLine(c); return true; } private bool TrySetPKMDestination(object sender, DragEventArgs e, bool overwrite, bool clone, bool noEgg) @@ -355,7 +350,7 @@ public void SetPKM(PKM pk, SlotChange slot, bool src, Image img) { if (boxview.CurrentBox == slot.Box) { - Console.WriteLine($"Setting to {boxview.Parent.Name}'s [{boxview.CurrentBox+1:d2}]|{boxview.CurrentBoxName} at Slot {slot.Slot+1}."); + Debug.WriteLine($"Setting to {boxview.Parent.Name}'s [{boxview.CurrentBox+1:d2}]|{boxview.CurrentBoxName} at Slot {slot.Slot+1}."); SetSlotSprite(slot, pk, boxview); } } diff --git a/PKHeX.WinForms/MainWindow/Main.cs b/PKHeX.WinForms/MainWindow/Main.cs index d90a4fb1e..7d3d29fc9 100644 --- a/PKHeX.WinForms/MainWindow/Main.cs +++ b/PKHeX.WinForms/MainWindow/Main.cs @@ -595,7 +595,7 @@ private bool TryLoadPKM(byte[] input, string path, string ext, SaveFile SAV) } PKME_Tabs.PopulateFields(pk); - Console.WriteLine(c); + Debug.WriteLine(c); return true; } private bool TryLoadPCBoxBin(byte[] input) @@ -619,7 +619,7 @@ private bool TryLoadBattleVideo(byte[] input) BattleVideo b = BattleVideo.GetVariantBattleVideo(input); bool result = C_SAV.OpenBattleVideo(b, out string c); WinFormsUtil.Alert(c); - Console.WriteLine(c); + Debug.WriteLine(c); return result; } private bool TryLoadMysteryGift(byte[] input, string path, string ext) @@ -643,7 +643,7 @@ private bool TryLoadMysteryGift(byte[] input, string path, string ext) } PKME_Tabs.PopulateFields(pk); - Console.WriteLine(c); + Debug.WriteLine(c); return true; } diff --git a/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs b/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs index 2ea0c8be6..962d8a6a8 100644 --- a/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs +++ b/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Diagnostics; using System.Drawing; using System.Globalization; using System.IO; @@ -279,7 +280,7 @@ private bool ProcessPKM(PKM pkm, IEnumerable Filters, IEnumer if (!pkm.Valid || pkm.Locked) { len++; - Console.WriteLine("Skipped a pkm due to disallowed input: " + (pkm.Locked ? "Locked." : "Not Valid.")); + Debug.WriteLine("Skipped a pkm due to disallowed input: " + (pkm.Locked ? "Locked." : "Not Valid.")); return false; } @@ -348,7 +349,7 @@ public void SetRandRange(string pv) if (Min == Max) { PropertyValue = Min.ToString(); - Console.WriteLine(PropertyName + " randomization range Min/Max same?"); + Debug.WriteLine(PropertyName + " randomization range Min/Max same?"); } else Random = true; @@ -439,7 +440,7 @@ private static ModifyResult TryModifyPKM(PKM PKM, IEnumerable if (IsPKMFiltered(pkm, cmd, info, out result)) return result; // why it was filtered out } - catch { Console.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}."); } + catch { Debug.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}."); } } foreach (var cmd in Instructions) @@ -448,7 +449,7 @@ private static ModifyResult TryModifyPKM(PKM PKM, IEnumerable { result = SetPKMProperty(PKM, info, cmd); } - catch { Console.WriteLine($"Unable to set {cmd.PropertyName} to {cmd.PropertyValue}."); } + catch { Debug.WriteLine($"Unable to set {cmd.PropertyName} to {cmd.PropertyValue}."); } } return result; } diff --git a/PKHeX.WinForms/Subforms/SAV_Database.cs b/PKHeX.WinForms/Subforms/SAV_Database.cs index 06983883a..3dde6e7e2 100644 --- a/PKHeX.WinForms/Subforms/SAV_Database.cs +++ b/PKHeX.WinForms/Subforms/SAV_Database.cs @@ -546,7 +546,7 @@ private IEnumerable SearchDatabase() if (!pkm.GetType().HasPropertyAll(cmd.PropertyName)) return false; try { if (ReflectUtil.IsValueEqual(pkm, cmd.PropertyName, cmd.PropertyValue) == cmd.Evaluator) continue; } - catch { Console.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}."); } + catch { Debug.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}."); } return false; } return true; diff --git a/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs b/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs index 15cb67425..955c3f4aa 100644 --- a/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs +++ b/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs @@ -291,7 +291,7 @@ private void B_Search_Click(object sender, EventArgs e) if (!gift.GetType().HasPropertyAll(cmd.PropertyName)) return false; try { if (ReflectUtil.IsValueEqual(gift, cmd.PropertyName, cmd.PropertyValue) == cmd.Evaluator) continue; } - catch { Console.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}."); } + catch { Debug.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}."); } return false; } return true; diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_EventFlags.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_EventFlags.cs index 9ed6c26c8..4625405e0 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_EventFlags.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_EventFlags.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; @@ -418,7 +419,7 @@ private void DiffSaves() catch (Exception e) { WinFormsUtil.Error("An unexpected error has occurred.", e); - Console.Write(e); + Debug.WriteLine(e); } TB_IsSet.Text = tbIsSet; TB_UnSet.Text = tbUnSet; @@ -438,7 +439,7 @@ private void DiffSaves() catch (Exception e) { WinFormsUtil.Error("An unexpected error has occurred.", e); - Console.Write(e); + Debug.WriteLine(e); } if (string.IsNullOrEmpty(r)) diff --git a/PKHeX.WinForms/Util/FontUtil.cs b/PKHeX.WinForms/Util/FontUtil.cs index 15c789fb5..9d1db6fda 100644 --- a/PKHeX.WinForms/Util/FontUtil.cs +++ b/PKHeX.WinForms/Util/FontUtil.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Drawing; using System.Drawing.Text; using System.Runtime.InteropServices; @@ -46,7 +47,7 @@ private static void SetPKXFont() #endif } - catch (Exception ex) { Console.WriteLine("Unable to add ingame font: " + ex.Message); } + catch (Exception ex) { Debug.WriteLine("Unable to add ingame font: " + ex.Message); } } } } diff --git a/PKHeX.WinForms/Util/NetUtil.cs b/PKHeX.WinForms/Util/NetUtil.cs index ada30599b..b71bdf498 100644 --- a/PKHeX.WinForms/Util/NetUtil.cs +++ b/PKHeX.WinForms/Util/NetUtil.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Drawing; using System.IO; using System.Net; @@ -18,7 +19,7 @@ public static string GetStringFromURL(string webURL) } catch (Exception e) { - Console.WriteLine(e.Message); + Debug.WriteLine(e.Message); return null; } } @@ -33,7 +34,7 @@ public static Image GetImageFromURL(string webURL) } catch (Exception e) { - Console.WriteLine(e.Message); + Debug.WriteLine(e.Message); return null; } } diff --git a/PKHeX.WinForms/Util/SAVUtil.cs b/PKHeX.WinForms/Util/SAVUtil.cs index 843af71fd..88cded897 100644 --- a/PKHeX.WinForms/Util/SAVUtil.cs +++ b/PKHeX.WinForms/Util/SAVUtil.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using PKHeX.Core; @@ -115,7 +116,7 @@ public static bool LoadBoxes(this SaveFile SAV, string path, out string result, PKM pk = PKMConverter.ConvertToType(temp, SAV.PKMType, out string c); if (pk == null) - { Console.WriteLine(c); continue; } + { Debug.WriteLine(c); continue; } if (SAV.IsPKMCompatible(pk).Length > 0) continue;