diff --git a/BTDToolbox/Classes/GeneralMethods.cs b/BTDToolbox/Classes/GeneralMethods.cs index 1491145..d7a14ff 100644 --- a/BTDToolbox/Classes/GeneralMethods.cs +++ b/BTDToolbox/Classes/GeneralMethods.cs @@ -318,6 +318,37 @@ public static void CreateBackup(string game) ConsoleHandler.appendLog("Unable to create backup for " + game + "."); } } + public static void SteamValidateBTD5() + { + Process.Start("steam://validate/306020"); + } + public static void SteamValidateBTDB() + { + Process.Start("steam://validate/444640"); + } + public static void BackupLOC(string game) + { + string backupDir = Environment.CurrentDirectory + "\\Backups"; + string backupLocName = game + "_Original_LOC.xml"; + + if (!Directory.Exists(backupDir)) + { + ConsoleHandler.appendLog("Backup directory does not exist. Creating directory..."); + Directory.CreateDirectory(backupDir); + } + + string gameDir = ""; + if (game == "BTD5") + gameDir = DeserializeConfig().BTD5_Directory; + else + gameDir = DeserializeConfig().BTDB_Directory; + + string steamJetPath = GetJetPath(game); + if (steamJetPath != null) + CopyFile(gameDir + "\\Assets\\Loc\\English.xml", backupDir + "\\" + backupLocName); + else + ConsoleHandler.appendLog("Unable to create backup for " + game + "."); + } public static void RestoreGame_ToBackup(string game) { string gameDir = ""; @@ -516,56 +547,136 @@ public static string OutputJet() } public static void CompileJet(string switchCase) { - if (JsonEditor.jsonError != true) + if (New_JsonEditor.isJsonError != true) { - if (JetProps.get().Count == 1) - { - string dest = ""; - bool isOutputting = false; + string gameDir = ""; + string gameNameTemp = ""; - var zip = new ZipForm(); + if (Serializer.Deserialize_Config().CurrentGame != "" && Serializer.Deserialize_Config() != null) + gameNameTemp = Serializer.Deserialize_Config().CurrentGame; + else if (Main.gameName != "" && Main.gameName != null) + { + gameNameTemp = Main.gameName; + Serializer.SaveConfig(Main.getInstance(), "main", Serializer.Deserialize_Config()); + } + + if(gameNameTemp != "" && gameNameTemp != null) + { + if (Main.gameName == "BTD5") + gameDir = Serializer.Deserialize_Config().BTD5_Directory; + else + gameDir = Serializer.Deserialize_Config().BTDB_Directory; - if (switchCase.Contains("output")) + if (JetProps.get().Count == 1) { - isOutputting = true; - ConsoleHandler.appendLog("Select where you want to export your jet file. Make sure to give it a name.."); - dest = OutputJet(); - zip.destPath = dest; - } - if (switchCase.Contains("launch")) - { - zip.launch = true; - } - if (isOutputting) - { - if (dest != null && dest != "") + string dest = ""; + bool isOutputting = false; + bool abort = false; + + var zip = new ZipForm(); + + if (switchCase.Contains("output")) { - zip.Show(); - zip.Compile(); + isOutputting = true; + string exPath = programData.ExportPath; + if (exPath != "" && exPath != null) + { + DialogResult diag = MessageBox.Show("Do you want export to the same place as last time?", "Export to the same place?", MessageBoxButtons.YesNo); + if (diag == DialogResult.Yes) + dest = exPath; + else + exPath = ""; + } + if (exPath == "" || exPath == null) + { + ConsoleHandler.appendLog("Select where you want to export your jet file. Make sure to give it a name.."); + dest = OutputJet(); + ZipForm.savedExportPath = dest; + Serializer.SaveSmallSettings("export path", Serializer.Deserialize_Config()); + } + zip.destPath = dest; } - else + else if (switchCase.Contains("launch")) { - ConsoleHandler.appendLog("Export cancelled..."); + if (gameDir != null && gameDir != "") + zip.launch = true; + else + { + ConsoleHandler.force_appendNotice("Unable to find your game directory, and therefore, unable to launch. Do you want to try browsing for your game?"); + DialogResult diag = MessageBox.Show("Unable to find your game directory, and therefore, unable to launch. Do you want to try browsing for your game?", "Browse for game?", MessageBoxButtons.YesNoCancel); + if (diag == DialogResult.Yes) + { + browseForExe(gameNameTemp); + } + if (diag == DialogResult.No) + { + DialogResult diag2 = MessageBox.Show("Do you want to just save your jet file instead?", "Save jet instead?", MessageBoxButtons.YesNo); + { + if (diag2 == DialogResult.Yes) + { + isOutputting = true; + string exPath = programData.ExportPath; + if (exPath != "" && exPath != null) + { + DialogResult diagz = MessageBox.Show("Do you want export to the same place as last time?", "Export to the same place?", MessageBoxButtons.YesNo); + if (diagz == DialogResult.Yes) + dest = exPath; + else + exPath = ""; + } + if (exPath == "" || exPath == null) + { + ConsoleHandler.appendLog("Select where you want to export your jet file. Make sure to give it a name.."); + dest = OutputJet(); + ZipForm.savedExportPath = dest; + Serializer.SaveSmallSettings("export path", Serializer.Deserialize_Config()); + } + zip.destPath = dest; + } + } + } + else + abort = true; + } + } + if(!abort) + { + if (isOutputting) + { + if (dest != null && dest != "") + { + zip.Show(); + zip.Compile(); + } + else + { + ConsoleHandler.appendLog("Export cancelled..."); + } + } + else + { + zip.Show(); + zip.Compile(); + } } } else { - zip.Show(); - zip.Compile(); + if (JetProps.get().Count < 1) + { + MessageBox.Show("You have no .jets or projects open, you need one to launch."); + ConsoleHandler.appendLog("You need to open a project to continue..."); + } + else + { + MessageBox.Show("You have multiple .jets or projects open, only one can be launched."); + ConsoleHandler.appendLog("You need to close projects to continue..."); + } } } else { - if (JetProps.get().Count < 1) - { - MessageBox.Show("You have no .jets or projects open, you need one to launch."); - ConsoleHandler.appendLog("You need to open a project to continue..."); - } - else - { - MessageBox.Show("You have multiple .jets or projects open, only one can be launched."); - ConsoleHandler.appendLog("You need to close projects to continue..."); - } + ConsoleHandler.force_appendNotice("There was an issue detecting your current game! Please restart toolbox and try again..."); } } } diff --git a/BTDToolbox/Classes/SerializeOps.cs b/BTDToolbox/Classes/SerializeOps.cs index ec033ec..94330ed 100644 --- a/BTDToolbox/Classes/SerializeOps.cs +++ b/BTDToolbox/Classes/SerializeOps.cs @@ -20,6 +20,10 @@ public static void SaveSmallSettings(string formName, ConfigFile serialize_confi { var cfg = Serializer.Deserialize_Config(); + if (formName == "export path") + { + cfg.ExportPath = ZipForm.savedExportPath; + } if (formName == "updater") { cfg.recentUpdate = UpdateChangelog.recentUpdate; @@ -174,6 +178,8 @@ public static ConfigFile Deserialize_Config() programData.JsonEditor_OpenedTabs = new List(); + programData.ExportPath = ""; + programData.battlesPass = ""; programData.BTD5_Directory = ""; programData.BTDB_Directory = ""; diff --git a/BTDToolbox/Extra Forms/EasyTowerEditor.cs b/BTDToolbox/Extra Forms/EasyTowerEditor.cs index bf35547..eb9eb71 100644 --- a/BTDToolbox/Extra Forms/EasyTowerEditor.cs +++ b/BTDToolbox/Extra Forms/EasyTowerEditor.cs @@ -35,7 +35,7 @@ public partial class EasyTowerEditor : Form string[] loc_upgradeDescs = new string[] { }; string game = Serializer.Deserialize_Config().CurrentGame; - + string gameDir = ""; string[] loc_Text = new string[] { }; string loc_Path = ""; string loc_towerName = ""; @@ -199,7 +199,31 @@ private void PopulateUI() TowerDesc_TextBox.Text = loc_towerDesc; } } - ReadLoc(); + if(game == "BTD5") + { + if(File.Exists(loc_Path)) + ReadLoc(); + else + { + if(Serializer.Deserialize_Config().BTD5_Directory == null || Serializer.Deserialize_Config().BTD5_Directory == "") + { + ConsoleHandler.force_appendNotice("You haven't browsed for your BTD5 Game so you will not be able to edit the tower and upgrade descriptions"); + this.Focus(); + } + else + { + ConsoleHandler.force_appendNotice("Unable to find your LOC file..."); + DialogResult diag = MessageBox.Show("Unable to find BTD5's LOC file. Do you want toolbox to make Steam validate BTD5 so it can reaquire it? If you have any mods applied to btd5 steam, they will be lost. Do you want to continue?", "Continue?", MessageBoxButtons.YesNo); + if (diag == DialogResult.Yes) + GeneralMethods.SteamValidateBTD5(); + else + { + ConsoleHandler.force_appendNotice("Valdation cancelled. You will not be able to mod the tower or upgrade descriptions..."); + this.Focus(); + } + } + } + } if (upgradenames != null) { @@ -397,7 +421,16 @@ private void PopulateUpgrades() RankToUnlockUpgrade_TextBox.Text = upgradeRanks[Upgrades_ListBox.SelectedIndex].ToString(); XpToUnlockUpgrade_TextBox.Text = upgradeXPs[Upgrades_ListBox.SelectedIndex].ToString(); - UpgradeDesc_TextBox.Text = loc_upgradeDescs[Upgrades_ListBox.SelectedIndex].ToString(); + if (game == "BTD5") + { + if (File.Exists(loc_Path)) + UpgradeDesc_TextBox.Text = loc_upgradeDescs[Upgrades_ListBox.SelectedIndex].ToString(); + } + else if (game != "" && game != null) + UpgradeDesc_TextBox.Text = loc_upgradeDescs[Upgrades_ListBox.SelectedIndex].ToString(); + else + ConsoleHandler.force_appendNotice("Something went wrong and your current game was not detected. Please reload BTD Toolbox, otherwise you may encounter errors"); + } } private void ResetUI() @@ -601,7 +634,7 @@ private void SaveLoc() } private void ReadLoc() { - if (Serializer.Deserialize_Config().CurrentGame == "BTD5") + if(File.Exists(loc_Path)) { loc_Text = File.ReadAllLines(loc_Path); string towerName = "LOC_" + TowerType_Label.Text + "_TOWER"; @@ -669,6 +702,10 @@ private void ReadLoc() } } } + else + { + + } } @@ -722,7 +759,8 @@ private void UpgradeName_TextBox_TextChanged(object sender, EventArgs e) private void Save_Button_Click(object sender, EventArgs e) { SaveFile(); - SaveLoc(); + if (File.Exists(loc_Path)) + SaveLoc(); ConsoleHandler.appendLog_CanRepeat("Saved " + AllTowerFiles_ComboBox.SelectedItem.ToString()); } private void UpgradeIcon_TextBox_TextChanged(object sender, EventArgs e) diff --git a/BTDToolbox/Get_BTDB_Password.Designer.cs b/BTDToolbox/Get_BTDB_Password.Designer.cs index c2f6613..9e47e71 100644 --- a/BTDToolbox/Get_BTDB_Password.Designer.cs +++ b/BTDToolbox/Get_BTDB_Password.Designer.cs @@ -34,6 +34,7 @@ private void InitializeComponent() this.Password_TextBox = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.Dont_Ask_Again_Checkbox = new System.Windows.Forms.CheckBox(); + this.UseLastPass_CB = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.SuspendLayout(); // @@ -101,12 +102,26 @@ private void InitializeComponent() this.Dont_Ask_Again_Checkbox.Text = "Don\'t ask me again"; this.Dont_Ask_Again_Checkbox.UseVisualStyleBackColor = true; // + // UseLastPass_CB + // + this.UseLastPass_CB.AutoSize = true; + this.UseLastPass_CB.Font = new System.Drawing.Font("Yu Gothic UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.UseLastPass_CB.ForeColor = System.Drawing.Color.Snow; + this.UseLastPass_CB.Location = new System.Drawing.Point(257, 158); + this.UseLastPass_CB.Name = "UseLastPass_CB"; + this.UseLastPass_CB.Size = new System.Drawing.Size(140, 21); + this.UseLastPass_CB.TabIndex = 15; + this.UseLastPass_CB.Text = "Use last password?"; + this.UseLastPass_CB.UseVisualStyleBackColor = true; + this.UseLastPass_CB.CheckedChanged += new System.EventHandler(this.UseLastPass_CB_CheckedChanged); + // // Get_BTDB_Password // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(50)))), ((int)(((byte)(50)))), ((int)(((byte)(50))))); this.ClientSize = new System.Drawing.Size(409, 191); + this.Controls.Add(this.UseLastPass_CB); this.Controls.Add(this.Dont_Ask_Again_Checkbox); this.Controls.Add(this.label2); this.Controls.Add(this.CreateProject_Button); @@ -133,5 +148,6 @@ private void InitializeComponent() private System.Windows.Forms.TextBox Password_TextBox; private System.Windows.Forms.Label label2; private System.Windows.Forms.CheckBox Dont_Ask_Again_Checkbox; + private System.Windows.Forms.CheckBox UseLastPass_CB; } } \ No newline at end of file diff --git a/BTDToolbox/Get_BTDB_Password.cs b/BTDToolbox/Get_BTDB_Password.cs index 236affb..e71943f 100644 --- a/BTDToolbox/Get_BTDB_Password.cs +++ b/BTDToolbox/Get_BTDB_Password.cs @@ -18,16 +18,21 @@ public partial class Get_BTDB_Password : Form public string destPath { get; set; } public bool isExtracting { get; set; } public bool launch { get; set; } - + string savedPass = Serializer.Deserialize_Config().battlesPass; public Get_BTDB_Password() { InitializeComponent(); this.AcceptButton = CreateProject_Button; + + if (savedPass == "" || savedPass == null) + UseLastPass_CB.Visible = false; + else + UseLastPass_CB.Visible = true; + if (rememberPass == true) Dont_Ask_Again_Checkbox.Checked = true; else Dont_Ask_Again_Checkbox.Checked = false; - } public void GetPass() { @@ -75,5 +80,19 @@ private void CreateProject_Button_Click(object sender, EventArgs e) { GetPass(); } + + private void UseLastPass_CB_CheckedChanged(object sender, EventArgs e) + { + if (UseLastPass_CB.Checked) + { + Password_TextBox.Text = savedPass; + Password_TextBox.ReadOnly = true; + } + else + { + Password_TextBox.Text = ""; + Password_TextBox.ReadOnly = false; + } + } } } diff --git a/BTDToolbox/Main.cs b/BTDToolbox/Main.cs index 180b913..c3dd0b9 100644 --- a/BTDToolbox/Main.cs +++ b/BTDToolbox/Main.cs @@ -17,7 +17,7 @@ namespace BTDToolbox public partial class Main : Form { //Form variables - public static string version = "Alpha 0.1.0"; + public static string version = "Alpha 0.1.1"; public static bool disableUpdates = false; private static Main toolbox; private static UpdateHandler update; @@ -709,12 +709,12 @@ private void Reset_EXE_MouseHover(object sender, EventArgs e) private void ValidateBTD5_Click(object sender, EventArgs e) { - Process.Start("steam://validate/306020"); + GeneralMethods.SteamValidateBTD5(); } private void ValidateBTDB_Click(object sender, EventArgs e) { - Process.Start("steam://validate/444640"); + GeneralMethods.SteamValidateBTDB(); } private void FontForPCToolStripMenuItem_Click(object sender, EventArgs e) diff --git a/BTDToolbox/ThemedForm.cs b/BTDToolbox/ThemedForm.cs index 010fda1..92e4faa 100644 --- a/BTDToolbox/ThemedForm.cs +++ b/BTDToolbox/ThemedForm.cs @@ -59,6 +59,7 @@ public ThemedForm() public void onThemedLoad(object sender, EventArgs e) { titleSeperator.SplitterDistance = 25; + CheckInBounds(); } private void CheckInBounds() { diff --git a/BTDToolbox/ZipForm.cs b/BTDToolbox/ZipForm.cs index e101829..05c1d5f 100644 --- a/BTDToolbox/ZipForm.cs +++ b/BTDToolbox/ZipForm.cs @@ -21,9 +21,11 @@ public partial class ZipForm : Form public int filesTransfered = 0; public static string rememberedPassword = ""; public static string existingJetFile = ""; + public static string savedExportPath = ""; //Config variables ConfigFile programData; + string jetName = ""; public string gameDir; public string gameName; public string steamJetPath; @@ -40,6 +42,7 @@ public partial class ZipForm : Form public string projName { get; set; } public string password { get; set; } public bool launch { get; set; } + public bool isExporting { get; set; } //Threads Thread backgroundThread; @@ -56,7 +59,6 @@ private void StartUp() { programData = DeserializeConfig(); string std = DeserializeConfig().CurrentGame; - string jetName = ""; if (std == "BTDB") { @@ -257,6 +259,7 @@ public void Compile() if (rememberedPassword != null && rememberedPassword != "") { password = rememberedPassword; + Serializer.SaveSmallSettings("battlesPass", programData); } if (password == null || password.Length <= 0) @@ -289,7 +292,19 @@ public void Compile() } private void Compile_OnThread() { - if (gameDir != null && gameDir != "") + bool cont = true; + if(launch) + { + if (gameDir == null || gameDir == "") + { + cont = false; + this.Invoke(new Action(() => this.Close())); + ConsoleHandler.appendLog("There was an issue reading your game directory. Go to the \"Help\" tab at the top, browse for your game again, and then try again..."); + backgroundThread.Abort(); + } + } + + if (cont) { string dir = ""; if (destPath == null || destPath == "") @@ -297,36 +312,48 @@ private void Compile_OnThread() else dir = destPath; - if (DeserializeConfig().LastProject == null) - { - Serializer.SaveConfig(jf, "jet explorer", programData); - } - DirectoryInfo projDir = new DirectoryInfo(DeserializeConfig().LastProject); - if (Directory.Exists(projDir.ToString())) + if (dir != "\\Assets\\" + jetName) { + if (DeserializeConfig().LastProject == null) + Serializer.SaveConfig(jf, "jet explorer", programData); - ConsoleHandler.appendLog("Compiling jet..."); - int numFiles = Directory.GetFiles((projDir.ToString()), "*", SearchOption.AllDirectories).Length; - int numFolders = Directory.GetDirectories(projDir.ToString(), "*", SearchOption.AllDirectories).Count(); - totalFiles = numFiles + numFolders; - filesTransfered = 0; + DirectoryInfo projDir = new DirectoryInfo(DeserializeConfig().LastProject); + if (Directory.Exists(projDir.ToString())) + { + ConsoleHandler.appendLog("Compiling jet..."); + int numFiles = Directory.GetFiles((projDir.ToString()), "*", SearchOption.AllDirectories).Length; + int numFolders = Directory.GetDirectories(projDir.ToString(), "*", SearchOption.AllDirectories).Count(); + totalFiles = numFiles + numFolders; + filesTransfered = 0; - ZipFile toExport = new ZipFile(); + ZipFile toExport = new ZipFile(); + toExport.Password = password; + toExport.AddProgress += ZipCompileProgress; + toExport.AddDirectory(projDir.FullName); + toExport.Encryption = EncryptionAlgorithm.PkzipWeak; + toExport.Name = dir; + toExport.CompressionLevel = CompressionLevel.Level6; + toExport.Save(); + toExport.Dispose(); - toExport.Password = password; - toExport.AddProgress += ZipCompileProgress; - toExport.AddDirectory(projDir.FullName); - toExport.Encryption = EncryptionAlgorithm.PkzipWeak; - toExport.Name = dir; - toExport.CompressionLevel = CompressionLevel.Level6; - toExport.Save(); - toExport.Dispose(); - ConsoleHandler.appendLog("Jet was successfully exported to: " + projDir.FullName); + ConsoleHandler.appendLog("Jet was successfully exported to: " + dir); - if (launch == true) - { - LaunchGame(gameName); + if (launch == true) + LaunchGame(gameName); + try + { + this.Invoke(new Action(() => this.Close())); + } + catch (Exception ex) + { + PrintError(ex.Message); + } + backgroundThread.Abort(); } + } + else + { + ConsoleHandler.appendLog("Something went wrong with the export. The export path might have been invalid, or it might have been cancelled..."); try { this.Invoke(new Action(() => this.Close())); @@ -338,13 +365,6 @@ private void Compile_OnThread() backgroundThread.Abort(); } } - else - { - this.Invoke(new Action(() => this.Close())); - ConsoleHandler.appendLog("There was an issue reading your game directory. Go to the \"Help\" tab at the top, browse for your game again, and then try again..."); - backgroundThread.Abort(); - } - } private void ExtractJet_Window_Load(object sender, EventArgs e) {