diff --git a/CnCTDRAMapEditor/App.config b/CnCTDRAMapEditor/App.config index 3d96fb1..1d630ac 100644 --- a/CnCTDRAMapEditor/App.config +++ b/CnCTDRAMapEditor/App.config @@ -26,6 +26,9 @@ True + + + diff --git a/CnCTDRAMapEditor/CnCTDRAMapEditor.csproj b/CnCTDRAMapEditor/CnCTDRAMapEditor.csproj index fc9ee59..0dc33b7 100644 --- a/CnCTDRAMapEditor/CnCTDRAMapEditor.csproj +++ b/CnCTDRAMapEditor/CnCTDRAMapEditor.csproj @@ -177,6 +177,12 @@ + + Form + + + GameInstallationPathForm.cs + @@ -469,6 +475,9 @@ TeamTypesDialog.cs + + GameInstallationPathForm.cs + MainForm.cs diff --git a/CnCTDRAMapEditor/GameInstallationPathForm.Designer.cs b/CnCTDRAMapEditor/GameInstallationPathForm.Designer.cs new file mode 100644 index 0000000..5fb8cd2 --- /dev/null +++ b/CnCTDRAMapEditor/GameInstallationPathForm.Designer.cs @@ -0,0 +1,113 @@ +namespace MobiusEditor +{ + partial class GameInstallationPathForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.btnBrowse = new System.Windows.Forms.Button(); + this.btnContinue = new System.Windows.Forms.Button(); + this.btnQuit = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(13, 13); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(300, 13); + this.label1.TabIndex = 0; + this.label1.Text = "Please enter your C&&C Remastered Collection installation path:"; + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(12, 39); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(301, 20); + this.textBox1.TabIndex = 1; + // + // btnBrowse + // + this.btnBrowse.Location = new System.Drawing.Point(319, 37); + this.btnBrowse.Name = "btnBrowse"; + this.btnBrowse.Size = new System.Drawing.Size(84, 23); + this.btnBrowse.TabIndex = 2; + this.btnBrowse.Text = "Browse"; + this.btnBrowse.UseVisualStyleBackColor = true; + this.btnBrowse.Click += new System.EventHandler(this.btnBrowse_Click); + // + // btnContinue + // + this.btnContinue.Location = new System.Drawing.Point(319, 97); + this.btnContinue.Name = "btnContinue"; + this.btnContinue.Size = new System.Drawing.Size(84, 23); + this.btnContinue.TabIndex = 3; + this.btnContinue.Text = "OK"; + this.btnContinue.UseVisualStyleBackColor = true; + this.btnContinue.Click += new System.EventHandler(this.btnContinue_Click); + // + // btnQuit + // + this.btnQuit.Location = new System.Drawing.Point(229, 97); + this.btnQuit.Name = "btnQuit"; + this.btnQuit.Size = new System.Drawing.Size(84, 23); + this.btnQuit.TabIndex = 4; + this.btnQuit.Text = "Quit Editor"; + this.btnQuit.UseVisualStyleBackColor = true; + this.btnQuit.Click += new System.EventHandler(this.btnQuit_Click); + // + // GameInstallationPathForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(419, 132); + this.ControlBox = false; + this.Controls.Add(this.btnQuit); + this.Controls.Add(this.btnContinue); + this.Controls.Add(this.btnBrowse); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.label1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "GameInstallationPathForm"; + this.Text = "Select game installation path"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.Button btnBrowse; + private System.Windows.Forms.Button btnContinue; + private System.Windows.Forms.Button btnQuit; + } +} \ No newline at end of file diff --git a/CnCTDRAMapEditor/GameInstallationPathForm.cs b/CnCTDRAMapEditor/GameInstallationPathForm.cs new file mode 100644 index 0000000..2b73ae3 --- /dev/null +++ b/CnCTDRAMapEditor/GameInstallationPathForm.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace MobiusEditor +{ + public partial class GameInstallationPathForm : Form + { + private OpenFileDialog fileDialog; + public string SelectedPath => textBox1.Text; + + public GameInstallationPathForm() + { + InitializeComponent(); + fileDialog = new OpenFileDialog(); + fileDialog.Filter = "C&C Remastered Executable (ClientG.exe)|ClientG.exe"; + fileDialog.Title = "Select C&C Remastered Executable (ClientG.exe)"; + fileDialog.CheckPathExists = true; + fileDialog.InitialDirectory = Environment.CurrentDirectory; + + textBox1.Text = Environment.CurrentDirectory; + } + + private void btnBrowse_Click(object sender, EventArgs e) + { + if (fileDialog.ShowDialog() == DialogResult.OK) + { + textBox1.Text = fileDialog.FileName; + } + } + + private void btnContinue_Click(object sender, EventArgs e) + { + if (!File.Exists(Path.Combine(Path.GetDirectoryName(textBox1.Text), "DATA", "CONFIG.MEG"))) + { + MessageBox.Show("Required data is missing, please enter the valid " + + "installation path for the C&C Remastered Collection. The " + + "installation directory is where the main executables of the " + + "collection (ClientG.exe and ClientLauncherG.exe) reside.", "Invalid directory"); + return; + } + + DialogResult = DialogResult.OK; + Close(); + } + + private void btnQuit_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.No; + Close(); + } + } +} diff --git a/CnCTDRAMapEditor/GameInstallationPathForm.resx b/CnCTDRAMapEditor/GameInstallationPathForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/CnCTDRAMapEditor/GameInstallationPathForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ No newline at end of file diff --git a/CnCTDRAMapEditor/Program.cs b/CnCTDRAMapEditor/Program.cs index 8cce048..aae2666 100644 --- a/CnCTDRAMapEditor/Program.cs +++ b/CnCTDRAMapEditor/Program.cs @@ -36,6 +36,36 @@ namespace MobiusEditor Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US"); } + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + + // Do a test for CONFIG.MEG + if (!FileTest()) + { + // If it does not exist, then try to use the directory from settings + bool validSavedDirectory = false; + if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.GameDirectoryPath) && + Directory.Exists(Properties.Settings.Default.GameDirectoryPath)) + { + Environment.CurrentDirectory = Properties.Settings.Default.GameDirectoryPath; + if (FileTest()) + { + validSavedDirectory = true; + } + } + + // If the directory in settings is wrong too, then we need to ask the user for the installation dir + if (!validSavedDirectory) + { + var gameInstallationPathForm = new GameInstallationPathForm(); + if (gameInstallationPathForm.ShowDialog() == DialogResult.No) + return; + Environment.CurrentDirectory = Path.GetDirectoryName(gameInstallationPathForm.SelectedPath); + Properties.Settings.Default.GameDirectoryPath = Environment.CurrentDirectory; + Properties.Settings.Default.Save(); + } + } + // Initialize megafiles var runPath = Environment.CurrentDirectory; Globals.TheMegafileManager = new MegafileManager(runPath); @@ -80,9 +110,6 @@ namespace MobiusEditor } } - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - if (Properties.Settings.Default.ShowInviteWarning) { var inviteMessageBox = new InviteMessageBox(); @@ -101,5 +128,10 @@ namespace MobiusEditor Globals.TheMegafileManager.Dispose(); } + + static bool FileTest() + { + return File.Exists(Path.Combine(Environment.CurrentDirectory, "DATA", "CONFIG.MEG")); + } } } diff --git a/CnCTDRAMapEditor/Properties/Resources.Designer.cs b/CnCTDRAMapEditor/Properties/Resources.Designer.cs index 37050ac..32dfbef 100644 --- a/CnCTDRAMapEditor/Properties/Resources.Designer.cs +++ b/CnCTDRAMapEditor/Properties/Resources.Designer.cs @@ -1,18 +1,4 @@ -// -// Copyright 2020 Electronic Arts Inc. -// -// The Command & Conquer Map Editor and corresponding source code is free -// software: you can redistribute it and/or modify it under the terms of -// the GNU General Public License as published by the Free Software Foundation, -// either version 3 of the License, or (at your option) any later version. - -// The Command & Conquer Map Editor and corresponding source code is distributed -// in the hope that it will be useful, but with permitted additional restrictions -// under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT -// distributed with this program. You should have received a copy of the -// GNU General Public License along with permitted additional restrictions -// with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by a tool. // Runtime Version:4.0.30319.42000 diff --git a/CnCTDRAMapEditor/Properties/Settings.Designer.cs b/CnCTDRAMapEditor/Properties/Settings.Designer.cs index 82df2e0..4bbaaff 100644 --- a/CnCTDRAMapEditor/Properties/Settings.Designer.cs +++ b/CnCTDRAMapEditor/Properties/Settings.Designer.cs @@ -1,18 +1,4 @@ -// -// Copyright 2020 Electronic Arts Inc. -// -// The Command & Conquer Map Editor and corresponding source code is free -// software: you can redistribute it and/or modify it under the terms of -// the GNU General Public License as published by the Free Software Foundation, -// either version 3 of the License, or (at your option) any later version. - -// The Command & Conquer Map Editor and corresponding source code is distributed -// in the hope that it will be useful, but with permitted additional restrictions -// under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT -// distributed with this program. You should have received a copy of the -// GNU General Public License along with permitted additional restrictions -// with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by a tool. // Runtime Version:4.0.30319.42000 @@ -69,5 +55,17 @@ namespace MobiusEditor.Properties { this["ShowInviteWarning"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string GameDirectoryPath { + get { + return ((string)(this["GameDirectoryPath"])); + } + set { + this["GameDirectoryPath"] = value; + } + } } } diff --git a/CnCTDRAMapEditor/Properties/Settings.settings b/CnCTDRAMapEditor/Properties/Settings.settings index ebd61e1..9b66e8a 100644 --- a/CnCTDRAMapEditor/Properties/Settings.settings +++ b/CnCTDRAMapEditor/Properties/Settings.settings @@ -11,5 +11,8 @@ True + + + \ No newline at end of file