From e49616b567c57309aa78cb3cf2fa00379c94150d Mon Sep 17 00:00:00 2001 From: Emilian Roman Date: Wed, 21 Nov 2018 10:37:47 +0800 Subject: [PATCH] Use resource files for file name & message strings --- AmaiSosu/AmaiSosu.csproj | 18 +++ AmaiSosu/Main.cs | 28 ++--- AmaiSosu/Resources/FileNames.Designer.cs | 117 +++++++++++++++++++ AmaiSosu/Resources/FileNames.resx | 138 +++++++++++++++++++++++ AmaiSosu/Resources/Messages.Designer.cs | 90 +++++++++++++++ AmaiSosu/Resources/Messages.resx | 129 +++++++++++++++++++++ 6 files changed, 506 insertions(+), 14 deletions(-) create mode 100644 AmaiSosu/Resources/FileNames.Designer.cs create mode 100644 AmaiSosu/Resources/FileNames.resx create mode 100644 AmaiSosu/Resources/Messages.Designer.cs create mode 100644 AmaiSosu/Resources/Messages.resx diff --git a/AmaiSosu/AmaiSosu.csproj b/AmaiSosu/AmaiSosu.csproj index 68b2ef3..acab53b 100644 --- a/AmaiSosu/AmaiSosu.csproj +++ b/AmaiSosu/AmaiSosu.csproj @@ -62,6 +62,16 @@ + + True + True + FileNames.resx + + + True + True + Messages.resx + @@ -101,6 +111,14 @@ + + ResXFileCodeGenerator + FileNames.Designer.cs + + + ResXFileCodeGenerator + Messages.Designer.cs + Always diff --git a/AmaiSosu/Main.cs b/AmaiSosu/Main.cs index a4f84f9..98a7cad 100644 --- a/AmaiSosu/Main.cs +++ b/AmaiSosu/Main.cs @@ -5,10 +5,11 @@ using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; -using System.Windows; using AmaiSosu.IO; using AmaiSosu.Properties; using Atarashii.API; +using static AmaiSosu.Resources.FileNames; +using static AmaiSosu.Resources.Messages; namespace AmaiSosu { @@ -25,7 +26,7 @@ public sealed class Main : INotifyPropertyChanged /// /// Current state of the OpenSauce installation. /// - private string _installState = "Click Browse and select the HCE installation path."; + private string _installState = BrowseHce; /// /// Installation path. @@ -41,9 +42,11 @@ public string Version get { using (var stream = Assembly.GetExecutingAssembly() - .GetManifestResourceStream("AmaiSosu.Resources.Version.txt")) + .GetManifestResourceStream(AmaiSosuVersion)) using (var reader = new StreamReader(stream ?? throw new FileNotFoundException())) + { return reader.ReadToEnd().Trim(); + } } } @@ -104,7 +107,7 @@ public void Initialise() } catch (Exception) { - InstallText = "Click Browse and select the HCE installation path."; + InstallText = BrowseHce; } } @@ -115,13 +118,13 @@ public void Install() { try { - var backupDir = System.IO.Path.Combine(_path, "AmaiSosu.Backup." + Guid.NewGuid()); + var backupDir = System.IO.Path.Combine(_path, AmaiSosuBackup + '.' + Guid.NewGuid()); CommitBackups(backupDir); OpenSauce.Install(Path); FinishInstall(backupDir); - InstallText = "Installation has been successful!"; + InstallText = InstallSuccess; } catch (Exception e) { @@ -159,14 +162,11 @@ private void FinishInstall(string backupDir) // restore backed up HCE shaders MoveFactory.Get(MoveFactory.Type.RestoreHceShaders, _path, backupDir).Commit(); - // move the OpenSauce IDE data - const string dirName = "OpenSauceIDE"; - var source = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), - "Kornner Studios", "OpenSauce", dirName); + OpenSauceDeveloper, OpenSauceDirectory, OpenSauceIDE); - var target = System.IO.Path.Combine(Path, dirName); + var target = System.IO.Path.Combine(Path, OpenSauceIDE); Copy.All(new DirectoryInfo(source), new DirectoryInfo(target)); Directory.Delete(source, true); @@ -180,10 +180,10 @@ private void FinishInstall(string backupDir) /// private void OnPathChanged() { - CanInstall = Directory.Exists(Path) && File.Exists(System.IO.Path.Combine(Path, "haloce.exe")); + CanInstall = Directory.Exists(Path) && File.Exists(System.IO.Path.Combine(Path, HceExecutable)); InstallText = CanInstall - ? "Ready to install OpenSauce to the HCE folder!" - : "Click Browse and select the HCE installation path."; + ? InstallReady + : BrowseHce; } [NotifyPropertyChangedInvocator] diff --git a/AmaiSosu/Resources/FileNames.Designer.cs b/AmaiSosu/Resources/FileNames.Designer.cs new file mode 100644 index 0000000..ccf8bb1 --- /dev/null +++ b/AmaiSosu/Resources/FileNames.Designer.cs @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace AmaiSosu.Resources { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class FileNames { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal FileNames() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AmaiSosu.Resources.FileNames", typeof(FileNames).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to AmaiSosu.Backup. + /// + internal static string AmaiSosuBackup { + get { + return ResourceManager.GetString("AmaiSosuBackup", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to AmaiSosu.Resources.Version.txt. + /// + internal static string AmaiSosuVersion { + get { + return ResourceManager.GetString("AmaiSosuVersion", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to haloce.exe. + /// + internal static string HceExecutable { + get { + return ResourceManager.GetString("HceExecutable", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Kornner Studios. + /// + internal static string OpenSauceDeveloper { + get { + return ResourceManager.GetString("OpenSauceDeveloper", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to OpenSauce. + /// + internal static string OpenSauceDirectory { + get { + return ResourceManager.GetString("OpenSauceDirectory", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to OpenSauceIDE. + /// + internal static string OpenSauceIDE { + get { + return ResourceManager.GetString("OpenSauceIDE", resourceCulture); + } + } + } +} diff --git a/AmaiSosu/Resources/FileNames.resx b/AmaiSosu/Resources/FileNames.resx new file mode 100644 index 0000000..4b15398 --- /dev/null +++ b/AmaiSosu/Resources/FileNames.resx @@ -0,0 +1,138 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + AmaiSosu.Backup + + + AmaiSosu.Resources.Version.txt + + + haloce.exe + + + Kornner Studios + + + OpenSauce + + + OpenSauceIDE + + \ No newline at end of file diff --git a/AmaiSosu/Resources/Messages.Designer.cs b/AmaiSosu/Resources/Messages.Designer.cs new file mode 100644 index 0000000..a372070 --- /dev/null +++ b/AmaiSosu/Resources/Messages.Designer.cs @@ -0,0 +1,90 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace AmaiSosu.Resources { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Messages { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Messages() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AmaiSosu.Resources.Messages", typeof(Messages).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Click Browse and select the HCE installation path.. + /// + internal static string BrowseHce { + get { + return ResourceManager.GetString("BrowseHce", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Ready to install OpenSauce to the HCE folder!. + /// + internal static string InstallReady { + get { + return ResourceManager.GetString("InstallReady", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Installation has been successful!. + /// + internal static string InstallSuccess { + get { + return ResourceManager.GetString("InstallSuccess", resourceCulture); + } + } + } +} diff --git a/AmaiSosu/Resources/Messages.resx b/AmaiSosu/Resources/Messages.resx new file mode 100644 index 0000000..e551ab8 --- /dev/null +++ b/AmaiSosu/Resources/Messages.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Click Browse and select the HCE installation path. + + + Ready to install OpenSauce to the HCE folder! + + + Installation has been successful! + + \ No newline at end of file