From a79a8c52b3341b7f8a99735843af3d95c5366ef6 Mon Sep 17 00:00:00 2001 From: Antstar609 Date: Sun, 25 Aug 2024 19:26:44 +0200 Subject: [PATCH] Remove checking for Localization, Data and Tables folder --- MakeModFolder/MainWindow.xaml.cs | 49 ++++-------------------------- MakeModFolder/ModManifestWriter.cs | 14 ++++----- MakeModFolder/UserData.cs | 36 +++++++++++----------- 3 files changed, 32 insertions(+), 67 deletions(-) diff --git a/MakeModFolder/MainWindow.xaml.cs b/MakeModFolder/MainWindow.xaml.cs index b57fd44..7309b8f 100644 --- a/MakeModFolder/MainWindow.xaml.cs +++ b/MakeModFolder/MainWindow.xaml.cs @@ -39,7 +39,7 @@ private void MakeModFolder() { string ModPath = GamePath.Text + "\\Mods\\" + ModName.Text; - CreateModFolder(ModPath); + Directory.CreateDirectory(ModPath); CopyModdingEula(ModPath); if (!ZipDirectories(ModPath)) return; @@ -51,13 +51,6 @@ private void MakeModFolder() Application.Current.Shutdown(); } - private void CreateModFolder(string _ModPath) - { - Directory.CreateDirectory(_ModPath); - Directory.CreateDirectory(_ModPath + "\\Data"); - Directory.CreateDirectory(_ModPath + "\\Localization"); - } - private void CopyModdingEula(string _ModPath) { string ExePath = System.Reflection.Assembly.GetExecutingAssembly().Location; @@ -81,10 +74,11 @@ private bool ZipDirectories(string _ModPath) bool IsLocalizationZipped = false; bool IsTablesZipped = false; - foreach (var DirectoryName in Directories) + foreach (string DirectoryName in Directories) { if (DirectoryName.Contains("Data") && !IsDataZipped) { + Directory.CreateDirectory(_ModPath + "\\Data"); string DataDataPak = _ModPath + "\\Data\\Data.pak"; ZipFile.CreateFromDirectory(DirectoryName, DataDataPak, CompressionLevel.Optimal, false); IsDataZipped = true; @@ -99,15 +93,10 @@ private bool ZipDirectories(string _ModPath) if (DirectoryName.Contains("Localization") && !IsLocalizationZipped) { + Directory.CreateDirectory(_ModPath + "\\Localization"); string[] LocalizationDirectories = Directory.GetDirectories(DirectoryName); - if (LocalizationDirectories.Length == 0) - { - CustomMessageBox.Display("The localization folder is empty", IsSilent); - return false; - } - - foreach (var LocalizationDirectory in LocalizationDirectories) + foreach (string LocalizationDirectory in LocalizationDirectories) { string LocalizationPath = _ModPath + "\\Localization\\" + Path.GetFileName(LocalizationDirectory) + "_xml.pak"; ZipFile.CreateFromDirectory(LocalizationDirectory, LocalizationPath, CompressionLevel.Optimal, false); @@ -120,32 +109,6 @@ private bool ZipDirectories(string _ModPath) break; } - // Handle missing directories - - string ErrorMessage = ""; - - if (!IsDataZipped) - { - ErrorMessage += "The data folder is missing.\n"; - } - - if (!IsTablesZipped) - { - ErrorMessage += "The tables folder is missing.\n"; - } - - if (!IsLocalizationZipped) - { - ErrorMessage += "The localization folder is missing.\n"; - } - - if (!string.IsNullOrEmpty(ErrorMessage)) - { - CustomMessageBox.Display(ErrorMessage.TrimEnd('\n'), IsSilent); - Directory.Delete(_ModPath, true); - return false; - } - return true; } @@ -216,9 +179,9 @@ public void Run_Button_Click(object _Sender, RoutedEventArgs _Event) } else { - // All fields are not filled if (IsSilent) { + // All fields are not filled Console.WriteLine("Please ensure all fields are filled in the application before using silent mode"); Application.Current.Shutdown(); } diff --git a/MakeModFolder/ModManifestWriter.cs b/MakeModFolder/ModManifestWriter.cs index 6869113..44ffaa4 100644 --- a/MakeModFolder/ModManifestWriter.cs +++ b/MakeModFolder/ModManifestWriter.cs @@ -3,7 +3,7 @@ namespace MakeModFolder; -public class ModManifestWriter(MainWindow _MainWindow) +public class ModManifestWriter(MainWindow _mainWindow) { public void WriteModManifest() { @@ -14,31 +14,31 @@ public void WriteModManifest() NewLineOnAttributes = true }; - using var Writer = XmlWriter.Create(_MainWindow.GamePath.Text + "\\Mods\\" + _MainWindow.ModName.Text + "\\mod.manifest", Settings); + using var Writer = XmlWriter.Create(_mainWindow.GamePath.Text + "\\Mods\\" + _mainWindow.ModName.Text + "\\mod.manifest", Settings); Writer.WriteStartDocument(); Writer.WriteStartElement("kcd_mod"); // kcd_mod Writer.WriteStartElement("info"); // info Writer.WriteStartElement("name"); // name - Writer.WriteValue(_MainWindow.ModName.Text); + Writer.WriteValue(_mainWindow.ModName.Text); Writer.WriteEndElement(); // /name Writer.WriteStartElement("modid"); // modid - Writer.WriteValue(_MainWindow.ModName.Text.Replace(" ", "").ToLower()); + Writer.WriteValue(_mainWindow.ModName.Text.Replace(" ", "").ToLower()); Writer.WriteEndElement(); // /modid Writer.WriteStartElement("description"); // description Writer.WriteValue("A mod for Kingdom Come: Deliverance"); Writer.WriteEndElement(); // /description Writer.WriteStartElement("author"); // author - Writer.WriteValue(_MainWindow.Author.Text); + Writer.WriteValue(_mainWindow.Author.Text); Writer.WriteEndElement(); // /author Writer.WriteStartElement("version"); // version - Writer.WriteValue(_MainWindow.ModVersion.Text); + Writer.WriteValue(_mainWindow.ModVersion.Text); Writer.WriteEndElement(); // /version Writer.WriteStartElement("created_on"); // created_on Writer.WriteValue(DateTime.Now.ToString("dd.MM.yyyy")); Writer.WriteEndElement(); // /created_on Writer.WriteStartElement("modifies_level"); // modifies_level - Writer.WriteValue(_MainWindow.IsMapModified.IsChecked.ToString()?.ToLower()); + Writer.WriteValue(_mainWindow.IsMapModified.IsChecked.ToString()?.ToLower()); Writer.WriteEndElement(); // /modifies_level Writer.WriteEndElement(); // /info Writer.WriteEndElement(); // /kcd_mod diff --git a/MakeModFolder/UserData.cs b/MakeModFolder/UserData.cs index dfcb249..cc0a67c 100644 --- a/MakeModFolder/UserData.cs +++ b/MakeModFolder/UserData.cs @@ -4,38 +4,40 @@ namespace MakeModFolder; -public class UserData(MainWindow _MainWindow) +public class UserData(MainWindow _mainWindow) { + private readonly JsonSerializerOptions m_options = new() { WriteIndented = true }; + public void SetUserData() { var Data = new Dictionary { - { "ModName", _MainWindow.ModName.Text }, - { "GamePath", _MainWindow.GamePath.Text }, - { "RepoPath", _MainWindow.RepoPath.Text }, - { "ModVersion", _MainWindow.ModVersion.Text }, - { "IsMapModified", _MainWindow.IsMapModified.IsChecked.ToString() }, - { "Author", _MainWindow.Author.Text } + { "ModName", _mainWindow.ModName.Text }, + { "GamePath", _mainWindow.GamePath.Text }, + { "RepoPath", _mainWindow.RepoPath.Text }, + { "ModVersion", _mainWindow.ModVersion.Text }, + { "IsMapModified", _mainWindow.IsMapModified.IsChecked.ToString() }, + { "Author", _mainWindow.Author.Text } }; - string Json = JsonSerializer.Serialize(Data, new JsonSerializerOptions { WriteIndented = true }); - File.WriteAllText(_MainWindow.JsonPath, Json); + string Json = JsonSerializer.Serialize(Data, m_options); + File.WriteAllText(_mainWindow.JsonPath, Json); } public void GetUserData() { - if (!File.Exists(_MainWindow.JsonPath)) return; + if (!File.Exists(_mainWindow.JsonPath)) return; - string Json = File.ReadAllText(_MainWindow.JsonPath); + string Json = File.ReadAllText(_mainWindow.JsonPath); var Data = JsonSerializer.Deserialize>(Json); if (Data == null) return; - _MainWindow.ModName.Text = Data["ModName"]; - _MainWindow.GamePath.Text = Data["GamePath"]; - _MainWindow.RepoPath.Text = Data["RepoPath"]; - _MainWindow.ModVersion.Text = Data["ModVersion"]; - _MainWindow.IsMapModified.IsChecked = bool.Parse(Data["IsMapModified"]); - _MainWindow.Author.Text = Data["Author"]; + _mainWindow.ModName.Text = Data["ModName"]; + _mainWindow.GamePath.Text = Data["GamePath"]; + _mainWindow.RepoPath.Text = Data["RepoPath"]; + _mainWindow.ModVersion.Text = Data["ModVersion"]; + _mainWindow.IsMapModified.IsChecked = bool.Parse(Data["IsMapModified"]); + _mainWindow.Author.Text = Data["Author"]; } } \ No newline at end of file