diff --git a/Forms/mainFrm.cs b/Forms/mainFrm.cs index 14d6f36..3e805ce 100644 --- a/Forms/mainFrm.cs +++ b/Forms/mainFrm.cs @@ -37,7 +37,7 @@ private void StartPatching(execID ID) OpenFileDialog ofd = Helpers.CreateOFDialog(); if (ofd.ShowDialog() == DialogResult.OK && File.Exists(ofd.FileName)) { - if (Helpers.CreateBackup(ofd.FileName) == false) + if (Backup.Instance.CreateBackup(ofd.FileName) == false) { MessageBox.Show(Resources.ErrorBackup, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); return; diff --git a/Forms/mainPatcher.cs b/Forms/mainPatcher.cs index 484067d..a4aae39 100644 --- a/Forms/mainPatcher.cs +++ b/Forms/mainPatcher.cs @@ -159,32 +159,26 @@ private void cbHighTextures_CheckedChanged(object sender, EventArgs e) private void btnPatch_Click(object sender, EventArgs e) { SelectPatchVersion(GlobalID, ref GlobalStream); - DialogResult = DialogResult.OK; // Patching successfull - + DialogResult = DialogResult.OK; // Patching successful Close(); Dispose(); } private void btnAbort_Click(object sender, EventArgs e) { DialogResult = DialogResult.Abort; // Abort - Close(); Dispose(); } private void btnBackup_Click(object sender, EventArgs e) { - string Path = GlobalStream.Name; - GlobalStream.Close(); - GlobalStream.Dispose(); - - bool Result = Helpers.RestoreBackup(Path); + bool Result = Backup.Instance.RestoreBackup(ref GlobalStream); if (Result == false) { DialogResult = DialogResult.Cancel; // Backup failed } else { - DialogResult = DialogResult.Retry; // Backup successfull + DialogResult = DialogResult.Retry; // Backup successful } Close(); diff --git a/Helpers/Backup.cs b/Helpers/Backup.cs new file mode 100644 index 0000000..3f2522c --- /dev/null +++ b/Helpers/Backup.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Windows.Forms; +using static S6Patcher.Helpers; + +namespace S6Patcher +{ + public sealed class Backup + { + private static readonly Backup _instance = new Backup(); + private Backup() {} + public static Backup Instance + { + get + { + return _instance; + } + } + public bool CreateBackup(string Filepath) + { + string FileName = Path.GetFileNameWithoutExtension(Filepath); + string DirectoryPath = Path.GetDirectoryName(Filepath); + string FinalPath = Path.Combine(DirectoryPath, FileName + "_BACKUP.exe"); + + if (File.Exists(FinalPath) == false) + { + try + { + File.Copy(Filepath, FinalPath, false); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + return false; + } + } + return true; + } + public void RemoveUserScriptFiles() + { + string[] ScriptFiles = { "UserScriptLocal.lua", "EMXBinData.s6patcher" }; + List Directories = GetUserScriptDirectories(); + foreach (string Element in Directories) + { + string ScriptPath = Path.Combine(Element, "Script"); + if (!Directory.Exists(ScriptPath)) + { + continue; + } + foreach (string Entry in ScriptFiles) + { + try + { + File.Delete(Path.Combine(ScriptPath, Entry)); + } + catch (Exception) // Errors here do not matter + { + continue; + } + } + } + } + public bool RestoreBackup(ref FileStream Stream) + { + RemoveUserScriptFiles(); // Delete Userscript from Folders + + string FilePath = Stream.Name; + string FileName = Path.GetFileNameWithoutExtension(FilePath); + string DirectoryPath = Path.GetDirectoryName(FilePath); + string FinalPath = Path.Combine(DirectoryPath, FileName + "_BACKUP.exe"); + + if (File.Exists(FinalPath) == false) + { + return false; + } + + Stream.Close(); + Stream.Dispose(); + + try + { + File.Replace(FinalPath, FilePath, null); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + return false; + } + + return true; + } + } +} diff --git a/Helpers/Helpers.cs b/Helpers/Helpers.cs index 8bc5bf7..5a01f92 100644 --- a/Helpers/Helpers.cs +++ b/Helpers/Helpers.cs @@ -61,26 +61,6 @@ public static OpenFileDialog CreateOFDialog() return ofd; } - public static bool CreateBackup(string Filepath) - { - string FileName = Path.GetFileNameWithoutExtension(Filepath); - string DirectoryPath = Path.GetDirectoryName(Filepath); - string FinalPath = Path.Combine(DirectoryPath, FileName + "_BACKUP.exe"); - - if (File.Exists(FinalPath) == false) - { - try - { - File.Copy(Filepath, FinalPath, false); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return false; - } - } - return true; - } public static bool CheckExecVersion(ref FileStream Reader, execID Identifier, Int64 Offset = 0x0) { string ExpectedVersion = "1, 71, 4289, 0"; @@ -144,56 +124,5 @@ public static List GetUserScriptDirectories() return Directories; } - public static void RemoveUserScriptFiles() - { - string[] ScriptFiles = {"UserScriptLocal.lua", "EMXBinData.s6patcher"}; - List Directories = GetUserScriptDirectories(); - - string ScriptPath = String.Empty; - foreach (string Element in Directories) - { - ScriptPath = Path.Combine(Element, "Script"); - if (!Directory.Exists(ScriptPath)) - { - continue; - } - try - { - foreach (string Entry in ScriptFiles) - { - File.Delete(Path.Combine(ScriptPath, Entry)); - } - } - catch (Exception) // Errors here do not matter - { - continue; - } - } - } - public static bool RestoreBackup(string filePath) - { - RemoveUserScriptFiles(); // Delete Userscript from Folders - - string FileName = Path.GetFileNameWithoutExtension(filePath); - string DirectoryPath = Path.GetDirectoryName(filePath); - string FinalPath = Path.Combine(DirectoryPath, FileName + "_BACKUP.exe"); - - if (File.Exists(FinalPath) == false) - { - return false; - } - - try - { - File.Replace(FinalPath, filePath, null); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return false; - } - - return true; - } } -} +} \ No newline at end of file diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index 860be1b..e515b22 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -156,8 +156,8 @@ internal static string btnPatchHE_GermanText { ///- Can set the maximum zoom level in the game. ///- Can activate the Development-Mode permanently without Registry-Key. ///- Can set the Large Address Aware Flag for more usable memory. - ///- Can fix Bugs in Script&Code (e.g. "Meldungsstau", "Entertainercrash"). - ///-> Original versions from Steam will need to be extracted with the tool "Steamless" first!. + ///- Can fix Bugs in Script&Code (e.g. "Meldungsstau", "Entertainercrash", "2K & 4K - Resolution"). + ///-> Original releases from Steam will need to be extracted with the tool "Steamless" first!. /// internal static string btnPatchOV_EnglishText { get { @@ -171,8 +171,8 @@ internal static string btnPatchOV_EnglishText { ///- Kann den maximalen Zoomlevel setzen. ///- Kann das Large Address Aware Flag setzen, um mehr adressierbaren Speicher zu haben. ///- Kann den Development-Mode ohne Registry-Key dauerhaft aktivieren. - ///- Kann Script&Code-Bugs fixen (z.B. "Meldungsstau", "Entertainercrash"). - ///-> Originalversionen von Steam müssen zuerst mit dem Tool "Steamless" entpackt werden!. + ///- Kann Script&Code-Bugs fixen (z.B. "Meldungsstau", "Entertainercrash", "2K & 4K - Auflösung"). + ///-> Originalversionen von Steam müssen zuerst mit dem Tool "Steam [rest of string was truncated]";. /// internal static string btnPatchOV_GermanText { get { diff --git a/Properties/Resources.resx b/Properties/Resources.resx index 7185d35..f671c07 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -151,8 +151,8 @@ Process was aborted ... - Can set the maximum zoom level in the game. - Can activate the Development-Mode permanently without Registry-Key. - Can set the Large Address Aware Flag for more usable memory. -- Can fix Bugs in Script&Code (e.g. "Meldungsstau", "Entertainercrash"). --> Original versions from Steam will need to be extracted with the tool "Steamless" first! +- Can fix Bugs in Script&Code (e.g. "Meldungsstau", "Entertainercrash", "2K & 4K - Resolution"). +-> Original releases from Steam will need to be extracted with the tool "Steamless" first! - Kann den Textur-Slider im Menü reaktivieren, um hohe Texturen auswählen zu können. @@ -160,7 +160,7 @@ Process was aborted ... - Kann den maximalen Zoomlevel setzen. - Kann das Large Address Aware Flag setzen, um mehr adressierbaren Speicher zu haben. - Kann den Development-Mode ohne Registry-Key dauerhaft aktivieren. -- Kann Script&Code-Bugs fixen (z.B. "Meldungsstau", "Entertainercrash"). +- Kann Script&Code-Bugs fixen (z.B. "Meldungsstau", "Entertainercrash", "2K & 4K - Auflösung"). -> Originalversionen von Steam müssen zuerst mit dem Tool "Steamless" entpackt werden! @@ -172,7 +172,7 @@ Process was aborted ... - Activates the Development-Mode without Registry-Key. - Enables walls and wall gates from all climate zones in all climate zones. - Can place, select and move all entity types (Careful, some may crash). -- Can apply all texture types from all climate zones (and some hidden too). +- Can apply all texture types from all climate zones (and some hidden ones too). - Can open map files that have been protected with the "S6Tools". - Can set the Large Address Aware Flag for more usable memory. diff --git a/Resources/UserScriptLocal.lua b/Resources/UserScriptLocal.lua index e8c309b..cb79200 100644 --- a/Resources/UserScriptLocal.lua +++ b/Resources/UserScriptLocal.lua @@ -62,6 +62,10 @@ end S6Patcher.GlobalScriptOverridden = false; S6Patcher.DefaultKnightNames = {"U_KnightSaraya", "U_KnightTrading", "U_KnightHealing", "U_KnightChivalry", "U_KnightWisdom", "U_KnightPlunder", "U_KnightSong"}; S6Patcher.OverrideGlobalScript = function() + if S6Patcher.SelectedKnight == nil then + return; + end + local Knight = Entities[S6Patcher.DefaultKnightNames[S6Patcher.SelectedKnight]]; Framework.SetOnGameStartLuaCommand(""); -- free memory diff --git a/S6Patcher.csproj b/S6Patcher.csproj index 01585bd..0f8b5a7 100644 --- a/S6Patcher.csproj +++ b/S6Patcher.csproj @@ -74,6 +74,7 @@ mainFrm.cs +