Skip to content

Commit

Permalink
Remove checking for Localization, Data and Tables folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Antstar609 committed Aug 25, 2024
1 parent 703fb22 commit a79a8c5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 67 deletions.
49 changes: 6 additions & 43 deletions MakeModFolder/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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;
}

Expand Down Expand Up @@ -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();
}
Expand Down
14 changes: 7 additions & 7 deletions MakeModFolder/ModManifestWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace MakeModFolder;

public class ModManifestWriter(MainWindow _MainWindow)
public class ModManifestWriter(MainWindow _mainWindow)
{
public void WriteModManifest()
{
Expand All @@ -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
Expand Down
36 changes: 19 additions & 17 deletions MakeModFolder/UserData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>
{
{ "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<Dictionary<string, string>>(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"];
}
}

0 comments on commit a79a8c5

Please sign in to comment.