diff --git a/NHSE.Core/Save/Meta/EncryptedFilePair.cs b/NHSE.Core/Save/Meta/EncryptedFilePair.cs index 5f074ca..fb8077a 100644 --- a/NHSE.Core/Save/Meta/EncryptedFilePair.cs +++ b/NHSE.Core/Save/Meta/EncryptedFilePair.cs @@ -77,19 +77,7 @@ public IEnumerable InvalidHashes() } } - public string GetString(int offset, int maxLength) - { - var str = Encoding.Unicode.GetString(Data, offset, maxLength * 2); - return StringUtil.TrimFromZero(str); - } - - public static byte[] GetBytes(string value, int maxLength) - { - if (value.Length > maxLength) - value = value.Substring(0, maxLength); - else if (value.Length < maxLength) - value = value.PadRight(maxLength, '\0'); - return Encoding.Unicode.GetBytes(value); - } + public string GetString(int offset, int maxLength) => StringUtil.GetString(Data, offset, maxLength); + public static byte[] GetBytes(string value, int maxLength) => StringUtil.GetBytes(value, maxLength); } } \ No newline at end of file diff --git a/NHSE.Core/Util/StringUtil.cs b/NHSE.Core/Util/StringUtil.cs index dc2173f..37f12a0 100644 --- a/NHSE.Core/Util/StringUtil.cs +++ b/NHSE.Core/Util/StringUtil.cs @@ -1,4 +1,6 @@ -using System.Runtime.CompilerServices; +using System.IO; +using System.Runtime.CompilerServices; +using System.Text; namespace NHSE.Core { @@ -20,5 +22,25 @@ private static string TrimFromFirst(string input, char c) int index = input.IndexOf(c); return index < 0 ? input : input.Substring(0, index); } + + public static string GetString(byte[] data, int offset, int maxLength) + { + var str = Encoding.Unicode.GetString(data, offset, maxLength * 2); + return TrimFromZero(str); + } + + public static byte[] GetBytes(string value, int maxLength) + { + if (value.Length > maxLength) + value = value.Substring(0, maxLength); + else if (value.Length < maxLength) + value = value.PadRight(maxLength, '\0'); + return Encoding.Unicode.GetBytes(value); + } + + public static string CleanFileName(string fileName) + { + return string.Concat(fileName.Split(Path.GetInvalidFileNameChars())); + } } } \ No newline at end of file diff --git a/NHSE.WinForms/Main.cs b/NHSE.WinForms/Main.cs index d8d7a0f..0f92a8e 100644 --- a/NHSE.WinForms/Main.cs +++ b/NHSE.WinForms/Main.cs @@ -63,21 +63,30 @@ private void Menu_Open(object sender, EventArgs e) private static void Open(string path) { + #if !DEBUG try + #endif { - var file = new HorizonSave(path); - Open(file); - - var settings = Settings.Default; - settings.LastFilePath = path; - settings.Save(); + OpenSaveFile(path); } + #if !DEBUG #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) #pragma warning restore CA1031 // Do not catch general exception types { WinFormsUtil.Error(ex.Message); } + #endif + } + + private static void OpenSaveFile(string path) + { + var file = new HorizonSave(path); + Open(file); + + var settings = Settings.Default; + settings.LastFilePath = path; + settings.Save(); } } }