Ask the user for their game installation path on startup if config files are not found from the main dir, save given path and use it later

This commit is contained in:
Rampastring 2020-09-12 01:36:38 +03:00
parent 6497f95c04
commit e6575eee3a
9 changed files with 357 additions and 33 deletions

View File

@ -26,6 +26,9 @@
<setting name="ShowInviteWarning" serializeAs="String">
<value>True</value>
</setting>
<setting name="GameDirectoryPath" serializeAs="String">
<value />
</setting>
</MobiusEditor.Properties.Settings>
</userSettings>
<runtime>

View File

@ -177,6 +177,12 @@
</Compile>
<Compile Include="Event\RenderEventArgs.cs" />
<Compile Include="Event\UndoRedoEventArgs.cs" />
<Compile Include="GameInstallationPathForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="GameInstallationPathForm.Designer.cs">
<DependentUpon>GameInstallationPathForm.cs</DependentUpon>
</Compile>
<Compile Include="Globals.cs" />
<Compile Include="Interface\IBrowsableType.cs" />
<Compile Include="Interface\ICellOccupier.cs" />
@ -469,6 +475,9 @@
<EmbeddedResource Include="Dialogs\TeamTypesDialog.resx">
<DependentUpon>TeamTypesDialog.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="GameInstallationPathForm.resx">
<DependentUpon>GameInstallationPathForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>

View File

@ -0,0 +1,113 @@
namespace MobiusEditor
{
partial class GameInstallationPathForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View File

@ -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();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -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"));
}
}
}

View File

@ -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
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000

View File

@ -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
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// <auto-generated>
// 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;
}
}
}
}

View File

@ -11,5 +11,8 @@
<Setting Name="ShowInviteWarning" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="GameDirectoryPath" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>