From 042c937f751abcfa154aa62326d6ff8e0432abf0 Mon Sep 17 00:00:00 2001 From: FenPhoenix Date: Sun, 14 Apr 2019 00:24:11 -0700 Subject: [PATCH] Import work: -Add autodetect feature for other loaders' .ini files -Fix if one game's ini file failed, the whole operation would abort --- AngelLoader/BusinessLogic.cs | 26 +++--- .../Common/DataClasses/Localization.cs | 1 + AngelLoader/Common/Utility/Methods.cs | 8 +- AngelLoader/English.ini | 1 + AngelLoader/FMBackupAndRestore.cs | 4 +- AngelLoader/FMCache.cs | 2 +- .../ImportFromDarkLoaderForm.Designer.cs | 26 +++++- AngelLoader/Forms/ImportFromDarkLoaderForm.cs | 60 +++++++++++++- .../ImportFromMultipleInisForm.Designer.cs | 80 ++++++++++++++++--- .../Forms/ImportFromMultipleInisForm.cs | 49 ++++++++++++ AngelLoader/Forms/MainForm.cs | 5 +- AngelLoader/Ini/LocalizationIni.cs | 4 + 12 files changed, 227 insertions(+), 39 deletions(-) diff --git a/AngelLoader/BusinessLogic.cs b/AngelLoader/BusinessLogic.cs index 4ed242c34..4d67b06c5 100644 --- a/AngelLoader/BusinessLogic.cs +++ b/AngelLoader/BusinessLogic.cs @@ -793,7 +793,7 @@ void ReportProgress(ProgressReport pr) } else if (GameIsKnownAndSupported(fm)) { - var fmInstalledPath = GetFMInstallsBasePath(fm); + var fmInstalledPath = GetFMInstallsBasePath(fm.Game); if (!fmInstalledPath.IsEmpty()) { fms.Add(Path.Combine(fmInstalledPath, fm.InstalledDir)); @@ -1124,7 +1124,7 @@ internal async Task InstallFM(FanMission fm) return false; } - var instBasePath = GetFMInstallsBasePath(fm); + var instBasePath = GetFMInstallsBasePath(fm.Game); if (!Directory.Exists(instBasePath)) { @@ -1185,7 +1185,7 @@ await Task.Run(() => Log("Couldn't create " + Paths.FMSelInf + " in " + fmInstalledPath, ex); } - var ac = new AudioConverter(fm, GetFMInstallsBasePath(fm)); + var ac = new AudioConverter(fm, GetFMInstallsBasePath(fm.Game)); try { ProgressBox.ShowConvertingFiles(); @@ -1374,7 +1374,7 @@ internal async Task UninstallFM(FanMission fm) try { - var fmInstalledPath = Path.Combine(GetFMInstallsBasePath(fm), fm.InstalledDir); + var fmInstalledPath = Path.Combine(GetFMInstallsBasePath(fm.Game), fm.InstalledDir); var fmDirExists = await Task.Run(() => Directory.Exists(fmInstalledPath)); if (!fmDirExists) @@ -1548,7 +1548,7 @@ internal async Task ConvertOGGsToWAVs(FanMission fm) Debug.Assert(!fm.InstalledDir.IsEmpty(), "fm.InstalledFolderName is null or empty"); - var ac = new AudioConverter(fm, GetFMInstallsBasePath(fm)); + var ac = new AudioConverter(fm, GetFMInstallsBasePath(fm.Game)); try { ProgressBox.ShowConvertingFiles(); @@ -1591,7 +1591,7 @@ internal async Task ConvertWAVsTo16Bit(FanMission fm) Debug.Assert(!fm.InstalledDir.IsEmpty(), "fm.InstalledFolderName is null or empty"); - var ac = new AudioConverter(fm, GetFMInstallsBasePath(fm)); + var ac = new AudioConverter(fm, GetFMInstallsBasePath(fm.Game)); try { ProgressBox.ShowConvertingFiles(); @@ -2066,7 +2066,7 @@ internal bool AddDML(FanMission fm, string sourceDMLPath) return false; } - var installedFMPath = Path.Combine(GetFMInstallsBasePath(fm), fm.InstalledDir); + var installedFMPath = Path.Combine(GetFMInstallsBasePath(fm.Game), fm.InstalledDir); try { var dmlFile = Path.GetFileName(sourceDMLPath); @@ -2091,7 +2091,7 @@ internal bool RemoveDML(FanMission fm, string dmlFile) return false; } - var installedFMPath = Path.Combine(GetFMInstallsBasePath(fm), fm.InstalledDir); + var installedFMPath = Path.Combine(GetFMInstallsBasePath(fm.Game), fm.InstalledDir); try { File.Delete(Path.Combine(installedFMPath, dmlFile)); @@ -2111,7 +2111,7 @@ internal bool RemoveDML(FanMission fm, string dmlFile) { try { - var dmlFiles = Directory.GetFiles(Path.Combine(GetFMInstallsBasePath(fm), fm.InstalledDir), + var dmlFiles = Directory.GetFiles(Path.Combine(GetFMInstallsBasePath(fm.Game), fm.InstalledDir), "*.dml", SearchOption.TopDirectoryOnly); for (int i = 0; i < dmlFiles.Length; i++) { @@ -2129,7 +2129,7 @@ internal bool RemoveDML(FanMission fm, string dmlFile) private static bool FMIsReallyInstalled(FanMission fm) { return fm.Installed && - Directory.Exists(Path.Combine(GetFMInstallsBasePath(fm), fm.InstalledDir)); + Directory.Exists(Path.Combine(GetFMInstallsBasePath(fm.Game), fm.InstalledDir)); } #region Cacheable FM data @@ -2182,7 +2182,7 @@ internal async Task GetCacheableData(FanMission fm) { Debug.Assert(!fm.InstalledDir.IsEmpty(), "fm.InstalledFolderName is null or empty"); - var instBasePath = GetFMInstallsBasePath(fm); + var instBasePath = GetFMInstallsBasePath(fm.Game); if (fm.Installed) { if (instBasePath.IsWhiteSpace()) @@ -2200,7 +2200,7 @@ internal async Task GetCacheableData(FanMission fm) } var readmeOnDisk = FMIsReallyInstalled(fm) - ? Path.Combine(GetFMInstallsBasePath(fm), fm.InstalledDir, fm.SelectedReadme) + ? Path.Combine(GetFMInstallsBasePath(fm.Game), fm.InstalledDir, fm.SelectedReadme) : Path.Combine(Paths.FMsCache, fm.InstalledDir, fm.SelectedReadme); if (fm.SelectedReadme.ExtIsHtml()) return (readmeOnDisk, ReadmeType.HTML); @@ -2377,7 +2377,7 @@ bool ContainsUnsafeOrJunkPhrase(string str) internal void OpenFMFolder(FanMission fm) { - var installsBasePath = GetFMInstallsBasePath(fm); + var installsBasePath = GetFMInstallsBasePath(fm.Game); if (installsBasePath.IsEmpty()) { View.ShowAlert(LText.AlertMessages.Patch_FMFolderNotFound, LText.AlertMessages.Alert); diff --git a/AngelLoader/Common/DataClasses/Localization.cs b/AngelLoader/Common/DataClasses/Localization.cs index 7a998cfe8..9f49cf949 100644 --- a/AngelLoader/Common/DataClasses/Localization.cs +++ b/AngelLoader/Common/DataClasses/Localization.cs @@ -36,6 +36,7 @@ internal static class Global internal static string Remove = "Remove"; internal static string RemoveEllipses = "Remove..."; internal static string Reset = "Reset"; + internal static string Autodetect = "Autodetect"; [FenGenBlankLine] internal static string Unrated = "Unrated"; internal static string None = "None"; diff --git a/AngelLoader/Common/Utility/Methods.cs b/AngelLoader/Common/Utility/Methods.cs index 08f229cfd..d2ad94e12 100644 --- a/AngelLoader/Common/Utility/Methods.cs +++ b/AngelLoader/Common/Utility/Methods.cs @@ -31,12 +31,12 @@ internal static string GetProcessPath(int procId) return ""; } - internal static string GetFMInstallsBasePath(FanMission fm) + internal static string GetFMInstallsBasePath(Game? game) { var thisFMInstallsBasePath = - fm.Game == Game.Thief1 ? Config.T1FMInstallPath : - fm.Game == Game.Thief2 ? Config.T2FMInstallPath : - fm.Game == Game.Thief3 ? Config.T3FMInstallPath : + game == Game.Thief1 ? Config.T1FMInstallPath : + game == Game.Thief2 ? Config.T2FMInstallPath : + game == Game.Thief3 ? Config.T3FMInstallPath : null; return thisFMInstallsBasePath ?? ""; diff --git a/AngelLoader/English.ini b/AngelLoader/English.ini index 0cfba3feb..f87698e25 100644 --- a/AngelLoader/English.ini +++ b/AngelLoader/English.ini @@ -15,6 +15,7 @@ AddEllipses=Add... Remove=Remove RemoveEllipses=Remove... Reset=Reset +Autodetect=Autodetect Unrated=Unrated None=None diff --git a/AngelLoader/FMBackupAndRestore.cs b/AngelLoader/FMBackupAndRestore.cs index fe4a293e1..2061c023f 100644 --- a/AngelLoader/FMBackupAndRestore.cs +++ b/AngelLoader/FMBackupAndRestore.cs @@ -64,7 +64,7 @@ await Task.Run(() => { if (backupSavesAndScreensOnly && fm.InstalledDir.IsEmpty()) return; - var thisFMInstallsBasePath = GetFMInstallsBasePath(fm); + var thisFMInstallsBasePath = GetFMInstallsBasePath(fm.Game); var savesDir = fm.Game == Game.Thief3 ? T3SavesDir : DarkSavesDir; var savesPath = Path.Combine(thisFMInstallsBasePath, fm.InstalledDir, savesDir); // Screenshots directory name is the same for T1/T2/T3 @@ -418,7 +418,7 @@ void AddBakFilesFrom(string path) var excludes = new List(); - var thisFMInstallsBasePath = GetFMInstallsBasePath(fm); + var thisFMInstallsBasePath = GetFMInstallsBasePath(fm.Game); var fmInstalledPath = Path.Combine(thisFMInstallsBasePath, fm.InstalledDir); using (var archive = new ZipArchive(new FileStream(fileToUse.Name, FileMode.Open, FileAccess.Read), diff --git a/AngelLoader/FMCache.cs b/AngelLoader/FMCache.cs index a0bc881bb..4d4870e6e 100644 --- a/AngelLoader/FMCache.cs +++ b/AngelLoader/FMCache.cs @@ -54,7 +54,7 @@ internal static CacheData GetCacheableDataInFMInstalledDir(FanMission fm) var readmes = new List(); - var thisFMInstallsBasePath = GetFMInstallsBasePath(fm); + var thisFMInstallsBasePath = GetFMInstallsBasePath(fm.Game); var path = Path.Combine(thisFMInstallsBasePath, fm.InstalledDir); var files = Directory.GetFiles(path, "*", SearchOption.TopDirectoryOnly).ToList(); diff --git a/AngelLoader/Forms/ImportFromDarkLoaderForm.Designer.cs b/AngelLoader/Forms/ImportFromDarkLoaderForm.Designer.cs index 8e3a6a606..3aa7e1a0b 100644 --- a/AngelLoader/Forms/ImportFromDarkLoaderForm.Designer.cs +++ b/AngelLoader/Forms/ImportFromDarkLoaderForm.Designer.cs @@ -36,6 +36,7 @@ private void InitializeComponent() this.OKButton = new System.Windows.Forms.Button(); this.Cancel_Button = new System.Windows.Forms.Button(); this.OKCancelFlowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel(); + this.AutodetectCheckBox = new System.Windows.Forms.CheckBox(); this.OKCancelFlowLayoutPanel.SuspendLayout(); this.SuspendLayout(); // @@ -44,7 +45,7 @@ private void InitializeComponent() this.ImportFMDataCheckBox.AutoSize = true; this.ImportFMDataCheckBox.Checked = true; this.ImportFMDataCheckBox.CheckState = System.Windows.Forms.CheckState.Checked; - this.ImportFMDataCheckBox.Location = new System.Drawing.Point(16, 56); + this.ImportFMDataCheckBox.Location = new System.Drawing.Point(16, 88); this.ImportFMDataCheckBox.Name = "ImportFMDataCheckBox"; this.ImportFMDataCheckBox.Size = new System.Drawing.Size(97, 17); this.ImportFMDataCheckBox.TabIndex = 3; @@ -56,7 +57,7 @@ private void InitializeComponent() this.ImportSavesCheckBox.AutoSize = true; this.ImportSavesCheckBox.Checked = true; this.ImportSavesCheckBox.CheckState = System.Windows.Forms.CheckState.Checked; - this.ImportSavesCheckBox.Location = new System.Drawing.Point(16, 72); + this.ImportSavesCheckBox.Location = new System.Drawing.Point(16, 104); this.ImportSavesCheckBox.Name = "ImportSavesCheckBox"; this.ImportSavesCheckBox.Size = new System.Drawing.Size(86, 17); this.ImportSavesCheckBox.TabIndex = 4; @@ -74,15 +75,17 @@ private void InitializeComponent() // // DarkLoaderIniTextBox // - this.DarkLoaderIniTextBox.Location = new System.Drawing.Point(16, 32); + this.DarkLoaderIniTextBox.Location = new System.Drawing.Point(16, 64); this.DarkLoaderIniTextBox.Name = "DarkLoaderIniTextBox"; + this.DarkLoaderIniTextBox.ReadOnly = true; this.DarkLoaderIniTextBox.Size = new System.Drawing.Size(440, 20); this.DarkLoaderIniTextBox.TabIndex = 1; // // DarkLoaderIniBrowseButton // this.DarkLoaderIniBrowseButton.AutoSize = true; - this.DarkLoaderIniBrowseButton.Location = new System.Drawing.Point(456, 31); + this.DarkLoaderIniBrowseButton.Enabled = false; + this.DarkLoaderIniBrowseButton.Location = new System.Drawing.Point(456, 63); this.DarkLoaderIniBrowseButton.Name = "DarkLoaderIniBrowseButton"; this.DarkLoaderIniBrowseButton.Padding = new System.Windows.Forms.Padding(6, 0, 6, 0); this.DarkLoaderIniBrowseButton.Size = new System.Drawing.Size(75, 23); @@ -128,6 +131,19 @@ private void InitializeComponent() this.OKCancelFlowLayoutPanel.Size = new System.Drawing.Size(162, 29); this.OKCancelFlowLayoutPanel.TabIndex = 9; // + // AutodetectCheckBox + // + this.AutodetectCheckBox.AutoSize = true; + this.AutodetectCheckBox.Checked = true; + this.AutodetectCheckBox.CheckState = System.Windows.Forms.CheckState.Checked; + this.AutodetectCheckBox.Location = new System.Drawing.Point(16, 40); + this.AutodetectCheckBox.Name = "AutodetectCheckBox"; + this.AutodetectCheckBox.Size = new System.Drawing.Size(78, 17); + this.AutodetectCheckBox.TabIndex = 10; + this.AutodetectCheckBox.Text = "Autodetect"; + this.AutodetectCheckBox.UseVisualStyleBackColor = true; + this.AutodetectCheckBox.CheckedChanged += new System.EventHandler(this.AutodetectCheckBox_CheckedChanged); + // // ImportFromDarkLoaderForm // this.AcceptButton = this.OKButton; @@ -135,6 +151,7 @@ private void InitializeComponent() this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.Cancel_Button; this.ClientSize = new System.Drawing.Size(547, 175); + this.Controls.Add(this.AutodetectCheckBox); this.Controls.Add(this.OKCancelFlowLayoutPanel); this.Controls.Add(this.ImportFMDataCheckBox); this.Controls.Add(this.ImportSavesCheckBox); @@ -167,5 +184,6 @@ private void InitializeComponent() private System.Windows.Forms.Button OKButton; private System.Windows.Forms.Button Cancel_Button; private System.Windows.Forms.FlowLayoutPanel OKCancelFlowLayoutPanel; + private System.Windows.Forms.CheckBox AutodetectCheckBox; } } \ No newline at end of file diff --git a/AngelLoader/Forms/ImportFromDarkLoaderForm.cs b/AngelLoader/Forms/ImportFromDarkLoaderForm.cs index d0fd3bfa1..d98d2bd5d 100644 --- a/AngelLoader/Forms/ImportFromDarkLoaderForm.cs +++ b/AngelLoader/Forms/ImportFromDarkLoaderForm.cs @@ -1,14 +1,17 @@ using System; +using System.Diagnostics; using System.IO; using System.Windows.Forms; using AngelLoader.Common; using AngelLoader.Common.DataClasses; using AngelLoader.Common.Utility; +using static AngelLoader.Common.Logger; namespace AngelLoader.Forms { public partial class ImportFromDarkLoaderForm : Form, ILocalizable { + private const string DarkLoaderIni = "DarkLoader.ini"; internal string DarkLoaderIniFile = ""; internal bool ImportFMData; internal bool ImportSaves; @@ -18,12 +21,14 @@ public partial class ImportFromDarkLoaderForm : Form, ILocalizable private void ImportFromDarkLoaderForm_Load(object sender, EventArgs e) { SetUITextToLocalized(); + AutodetectDarkLoaderIni(); } public void SetUITextToLocalized(bool suspendResume = true) { Text = LText.Importing.ImportFromDarkLoader_TitleText; ChooseDarkLoaderIniLabel.Text = LText.Importing.DarkLoader_ChooseIni; + AutodetectCheckBox.Text = LText.Global.Autodetect; DarkLoaderIniBrowseButton.SetTextAutoSize(DarkLoaderIniTextBox, LText.Global.BrowseEllipses); ImportFMDataCheckBox.Text = LText.Importing.DarkLoader_ImportFMData; ImportSavesCheckBox.Text = LText.Importing.DarkLoader_ImportSaves; @@ -40,7 +45,7 @@ private void ImportFromDarkLoaderForm_FormClosing(object sender, FormClosingEven bool fileNameIsDLIni; try { - fileNameIsDLIni = Path.GetFileName(file).EqualsI("DarkLoader.ini"); + fileNameIsDLIni = Path.GetFileName(file).EqualsI(DarkLoaderIni); } catch (ArgumentException) { @@ -81,6 +86,59 @@ private void DarkLoaderIniBrowseButton_Click(object sender, EventArgs e) } } + private void AutodetectCheckBox_CheckedChanged(object sender, EventArgs e) + { + var s = AutodetectCheckBox; + DarkLoaderIniTextBox.ReadOnly = s.Checked; + DarkLoaderIniBrowseButton.Enabled = !s.Checked; + + if (s.Checked) AutodetectDarkLoaderIni(); + } + + private void AutodetectDarkLoaderIni() + { + // Common locations. Don't go overboard and search the whole filesystem; that would take forever. + var dlLocations = new[] + { + @"DarkLoader", + @"Games\DarkLoader" + }; + + DriveInfo[] drives; + try + { + drives = DriveInfo.GetDrives(); + } + catch (Exception ex) + { + Log("Exception in GetDrives()", ex); + DarkLoaderIniTextBox.Text = ""; + return; + } + + foreach (var drive in drives) + { + if (!drive.IsReady || drive.DriveType != DriveType.Fixed) continue; + + try + { + foreach (var loc in dlLocations) + { + var dlIni = Path.Combine(drive.Name, loc, DarkLoaderIni); + if (File.Exists(dlIni)) + { + DarkLoaderIniTextBox.Text = dlIni; + return; + } + } + } + catch (Exception ex) + { + Log("Exception in DarkLoader multi-drive search", ex); + } + } + } + #region Research notes /* DarkLoader: diff --git a/AngelLoader/Forms/ImportFromMultipleInisForm.Designer.cs b/AngelLoader/Forms/ImportFromMultipleInisForm.Designer.cs index 2aa65a6fa..ca8228ce4 100644 --- a/AngelLoader/Forms/ImportFromMultipleInisForm.Designer.cs +++ b/AngelLoader/Forms/ImportFromMultipleInisForm.Designer.cs @@ -41,6 +41,9 @@ private void InitializeComponent() this.OKButton = new System.Windows.Forms.Button(); this.Cancel_Button = new System.Windows.Forms.Button(); this.OKCancelFlowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel(); + this.Thief1AutodetectCheckBox = new System.Windows.Forms.CheckBox(); + this.Thief2AutodetectCheckBox = new System.Windows.Forms.CheckBox(); + this.Thief3AutodetectCheckBox = new System.Windows.Forms.CheckBox(); this.Thief1GroupBox.SuspendLayout(); this.Thief2GroupBox.SuspendLayout(); this.Thief3GroupBox.SuspendLayout(); @@ -58,11 +61,12 @@ private void InitializeComponent() // // Thief1GroupBox // + this.Thief1GroupBox.Controls.Add(this.Thief1AutodetectCheckBox); this.Thief1GroupBox.Controls.Add(this.Thief1IniBrowseButton); this.Thief1GroupBox.Controls.Add(this.Thief1IniTextBox); this.Thief1GroupBox.Location = new System.Drawing.Point(8, 32); this.Thief1GroupBox.Name = "Thief1GroupBox"; - this.Thief1GroupBox.Size = new System.Drawing.Size(536, 64); + this.Thief1GroupBox.Size = new System.Drawing.Size(536, 80); this.Thief1GroupBox.TabIndex = 2; this.Thief1GroupBox.TabStop = false; this.Thief1GroupBox.Text = "Thief 1"; @@ -70,7 +74,8 @@ private void InitializeComponent() // Thief1IniBrowseButton // this.Thief1IniBrowseButton.AutoSize = true; - this.Thief1IniBrowseButton.Location = new System.Drawing.Point(448, 23); + this.Thief1IniBrowseButton.Enabled = false; + this.Thief1IniBrowseButton.Location = new System.Drawing.Point(448, 47); this.Thief1IniBrowseButton.Name = "Thief1IniBrowseButton"; this.Thief1IniBrowseButton.Padding = new System.Windows.Forms.Padding(6, 0, 6, 0); this.Thief1IniBrowseButton.Size = new System.Drawing.Size(75, 23); @@ -81,18 +86,20 @@ private void InitializeComponent() // // Thief1IniTextBox // - this.Thief1IniTextBox.Location = new System.Drawing.Point(16, 24); + this.Thief1IniTextBox.Location = new System.Drawing.Point(16, 48); this.Thief1IniTextBox.Name = "Thief1IniTextBox"; + this.Thief1IniTextBox.ReadOnly = true; this.Thief1IniTextBox.Size = new System.Drawing.Size(432, 20); this.Thief1IniTextBox.TabIndex = 0; // // Thief2GroupBox // + this.Thief2GroupBox.Controls.Add(this.Thief2AutodetectCheckBox); this.Thief2GroupBox.Controls.Add(this.Thief2IniBrowseButton); this.Thief2GroupBox.Controls.Add(this.Thief2IniTextBox); - this.Thief2GroupBox.Location = new System.Drawing.Point(8, 104); + this.Thief2GroupBox.Location = new System.Drawing.Point(8, 120); this.Thief2GroupBox.Name = "Thief2GroupBox"; - this.Thief2GroupBox.Size = new System.Drawing.Size(536, 72); + this.Thief2GroupBox.Size = new System.Drawing.Size(536, 88); this.Thief2GroupBox.TabIndex = 3; this.Thief2GroupBox.TabStop = false; this.Thief2GroupBox.Text = "Thief 2"; @@ -100,7 +107,8 @@ private void InitializeComponent() // Thief2IniBrowseButton // this.Thief2IniBrowseButton.AutoSize = true; - this.Thief2IniBrowseButton.Location = new System.Drawing.Point(447, 33); + this.Thief2IniBrowseButton.Enabled = false; + this.Thief2IniBrowseButton.Location = new System.Drawing.Point(447, 47); this.Thief2IniBrowseButton.Name = "Thief2IniBrowseButton"; this.Thief2IniBrowseButton.Padding = new System.Windows.Forms.Padding(6, 0, 6, 0); this.Thief2IniBrowseButton.Size = new System.Drawing.Size(75, 23); @@ -111,18 +119,20 @@ private void InitializeComponent() // // Thief2IniTextBox // - this.Thief2IniTextBox.Location = new System.Drawing.Point(15, 34); + this.Thief2IniTextBox.Location = new System.Drawing.Point(15, 48); this.Thief2IniTextBox.Name = "Thief2IniTextBox"; + this.Thief2IniTextBox.ReadOnly = true; this.Thief2IniTextBox.Size = new System.Drawing.Size(432, 20); this.Thief2IniTextBox.TabIndex = 0; // // Thief3GroupBox // + this.Thief3GroupBox.Controls.Add(this.Thief3AutodetectCheckBox); this.Thief3GroupBox.Controls.Add(this.Thief3IniBrowseButton); this.Thief3GroupBox.Controls.Add(this.Thief3IniTextBox); - this.Thief3GroupBox.Location = new System.Drawing.Point(8, 184); + this.Thief3GroupBox.Location = new System.Drawing.Point(8, 216); this.Thief3GroupBox.Name = "Thief3GroupBox"; - this.Thief3GroupBox.Size = new System.Drawing.Size(536, 72); + this.Thief3GroupBox.Size = new System.Drawing.Size(536, 88); this.Thief3GroupBox.TabIndex = 4; this.Thief3GroupBox.TabStop = false; this.Thief3GroupBox.Text = "Thief 3"; @@ -130,7 +140,8 @@ private void InitializeComponent() // Thief3IniBrowseButton // this.Thief3IniBrowseButton.AutoSize = true; - this.Thief3IniBrowseButton.Location = new System.Drawing.Point(447, 33); + this.Thief3IniBrowseButton.Enabled = false; + this.Thief3IniBrowseButton.Location = new System.Drawing.Point(447, 48); this.Thief3IniBrowseButton.Name = "Thief3IniBrowseButton"; this.Thief3IniBrowseButton.Padding = new System.Windows.Forms.Padding(6, 0, 6, 0); this.Thief3IniBrowseButton.Size = new System.Drawing.Size(75, 23); @@ -141,8 +152,9 @@ private void InitializeComponent() // // Thief3IniTextBox // - this.Thief3IniTextBox.Location = new System.Drawing.Point(15, 34); + this.Thief3IniTextBox.Location = new System.Drawing.Point(15, 49); this.Thief3IniTextBox.Name = "Thief3IniTextBox"; + this.Thief3IniTextBox.ReadOnly = true; this.Thief3IniTextBox.Size = new System.Drawing.Size(432, 20); this.Thief3IniTextBox.TabIndex = 0; // @@ -177,18 +189,57 @@ private void InitializeComponent() this.OKCancelFlowLayoutPanel.Controls.Add(this.Cancel_Button); this.OKCancelFlowLayoutPanel.Controls.Add(this.OKButton); this.OKCancelFlowLayoutPanel.FlowDirection = System.Windows.Forms.FlowDirection.RightToLeft; - this.OKCancelFlowLayoutPanel.Location = new System.Drawing.Point(384, 264); + this.OKCancelFlowLayoutPanel.Location = new System.Drawing.Point(384, 312); this.OKCancelFlowLayoutPanel.Name = "OKCancelFlowLayoutPanel"; this.OKCancelFlowLayoutPanel.Size = new System.Drawing.Size(162, 29); this.OKCancelFlowLayoutPanel.TabIndex = 0; // + // Thief1AutodetectCheckBox + // + this.Thief1AutodetectCheckBox.AutoSize = true; + this.Thief1AutodetectCheckBox.Checked = true; + this.Thief1AutodetectCheckBox.CheckState = System.Windows.Forms.CheckState.Checked; + this.Thief1AutodetectCheckBox.Location = new System.Drawing.Point(16, 24); + this.Thief1AutodetectCheckBox.Name = "Thief1AutodetectCheckBox"; + this.Thief1AutodetectCheckBox.Size = new System.Drawing.Size(78, 17); + this.Thief1AutodetectCheckBox.TabIndex = 2; + this.Thief1AutodetectCheckBox.Text = "Autodetect"; + this.Thief1AutodetectCheckBox.UseVisualStyleBackColor = true; + this.Thief1AutodetectCheckBox.CheckedChanged += new System.EventHandler(this.AutodetectCheckBoxes_CheckedChanged); + // + // Thief2AutodetectCheckBox + // + this.Thief2AutodetectCheckBox.AutoSize = true; + this.Thief2AutodetectCheckBox.Checked = true; + this.Thief2AutodetectCheckBox.CheckState = System.Windows.Forms.CheckState.Checked; + this.Thief2AutodetectCheckBox.Location = new System.Drawing.Point(16, 24); + this.Thief2AutodetectCheckBox.Name = "Thief2AutodetectCheckBox"; + this.Thief2AutodetectCheckBox.Size = new System.Drawing.Size(78, 17); + this.Thief2AutodetectCheckBox.TabIndex = 3; + this.Thief2AutodetectCheckBox.Text = "Autodetect"; + this.Thief2AutodetectCheckBox.UseVisualStyleBackColor = true; + this.Thief2AutodetectCheckBox.CheckedChanged += new System.EventHandler(this.AutodetectCheckBoxes_CheckedChanged); + // + // Thief3AutodetectCheckBox + // + this.Thief3AutodetectCheckBox.AutoSize = true; + this.Thief3AutodetectCheckBox.Checked = true; + this.Thief3AutodetectCheckBox.CheckState = System.Windows.Forms.CheckState.Checked; + this.Thief3AutodetectCheckBox.Location = new System.Drawing.Point(16, 24); + this.Thief3AutodetectCheckBox.Name = "Thief3AutodetectCheckBox"; + this.Thief3AutodetectCheckBox.Size = new System.Drawing.Size(78, 17); + this.Thief3AutodetectCheckBox.TabIndex = 4; + this.Thief3AutodetectCheckBox.Text = "Autodetect"; + this.Thief3AutodetectCheckBox.UseVisualStyleBackColor = true; + this.Thief3AutodetectCheckBox.CheckedChanged += new System.EventHandler(this.AutodetectCheckBoxes_CheckedChanged); + // // ImportFromMultipleInisForm // this.AcceptButton = this.OKButton; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.Cancel_Button; - this.ClientSize = new System.Drawing.Size(550, 298); + this.ClientSize = new System.Drawing.Size(550, 346); this.Controls.Add(this.OKCancelFlowLayoutPanel); this.Controls.Add(this.Thief3GroupBox); this.Controls.Add(this.Thief2GroupBox); @@ -231,5 +282,8 @@ private void InitializeComponent() private System.Windows.Forms.Button OKButton; private System.Windows.Forms.Button Cancel_Button; private System.Windows.Forms.FlowLayoutPanel OKCancelFlowLayoutPanel; + private System.Windows.Forms.CheckBox Thief1AutodetectCheckBox; + private System.Windows.Forms.CheckBox Thief2AutodetectCheckBox; + private System.Windows.Forms.CheckBox Thief3AutodetectCheckBox; } } \ No newline at end of file diff --git a/AngelLoader/Forms/ImportFromMultipleInisForm.cs b/AngelLoader/Forms/ImportFromMultipleInisForm.cs index 4e861041e..ca120d25b 100644 --- a/AngelLoader/Forms/ImportFromMultipleInisForm.cs +++ b/AngelLoader/Forms/ImportFromMultipleInisForm.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; +using System.IO; using System.Windows.Forms; using AngelLoader.Common; using AngelLoader.Common.DataClasses; using AngelLoader.Common.Utility; using AngelLoader.Importing; +using static AngelLoader.Common.Utility.Methods; namespace AngelLoader.Forms { @@ -18,6 +20,10 @@ public ImportFromMultipleInisForm(ImportType importType) ImportType = importType; InitializeComponent(); SetUITextToLocalized(); + + AutodetectGameIni(Game.Thief1, Thief1IniTextBox); + AutodetectGameIni(Game.Thief2, Thief2IniTextBox); + AutodetectGameIni(Game.Thief3, Thief3IniTextBox); } public void SetUITextToLocalized(bool suspendResume = true) @@ -33,6 +39,11 @@ public void SetUITextToLocalized(bool suspendResume = true) Thief1GroupBox.Text = LText.Importing.Thief1; Thief2GroupBox.Text = LText.Importing.Thief2; Thief3GroupBox.Text = LText.Importing.Thief3; + + Thief1AutodetectCheckBox.Text = LText.Global.Autodetect; + Thief2AutodetectCheckBox.Text = LText.Global.Autodetect; + Thief3AutodetectCheckBox.Text = LText.Global.Autodetect; + Thief1IniBrowseButton.SetTextAutoSize(Thief1IniTextBox, LText.Global.BrowseEllipses); Thief2IniBrowseButton.SetTextAutoSize(Thief2IniTextBox, LText.Global.BrowseEllipses); Thief3IniBrowseButton.SetTextAutoSize(Thief3IniTextBox, LText.Global.BrowseEllipses); @@ -70,6 +81,44 @@ private void ThiefIniBrowseButtons_Click(object sender, EventArgs e) } } + private void AutodetectCheckBoxes_CheckedChanged(object sender, EventArgs e) + { + var s = (CheckBox)sender; + var textBox = + s == Thief1AutodetectCheckBox ? Thief1IniTextBox : + s == Thief2AutodetectCheckBox ? Thief2IniTextBox : + Thief3IniTextBox; + var button = + s == Thief1AutodetectCheckBox ? Thief1IniBrowseButton : + s == Thief2AutodetectCheckBox ? Thief2IniBrowseButton : + Thief3IniBrowseButton; + var game = + s == Thief1AutodetectCheckBox ? Game.Thief1 : + s == Thief2AutodetectCheckBox ? Game.Thief2 : + Game.Thief3; + + textBox.ReadOnly = s.Checked; + button.Enabled = !s.Checked; + + if (s.Checked) AutodetectGameIni(game, textBox); + } + + private void AutodetectGameIni(Game game, TextBox textBox) + { + var iniFile = ImportType == ImportType.NewDarkLoader ? "NewDarkLoader.ini" : "fmsel.ini"; + + var fmsPath = GetFMInstallsBasePath(game); + if (fmsPath.IsWhiteSpace()) + { + textBox.Text = ""; + } + else + { + var iniFileFull = Path.Combine(fmsPath, iniFile); + textBox.Text = File.Exists(iniFileFull) ? iniFileFull : ""; + } + } + #region NDL Research notes /* NewDarkLoader: diff --git a/AngelLoader/Forms/MainForm.cs b/AngelLoader/Forms/MainForm.cs index 027b2fc27..b191c15bf 100644 --- a/AngelLoader/Forms/MainForm.cs +++ b/AngelLoader/Forms/MainForm.cs @@ -4018,6 +4018,7 @@ private async Task ImportFromNDLOrFMSel(ImportType importType) return; } + int successCount = 0; foreach (var file in iniFiles) { if (file.IsWhiteSpace()) continue; @@ -4025,9 +4026,11 @@ private async Task ImportFromNDLOrFMSel(ImportType importType) bool success = await (importType == ImportType.FMSel ? Model.ImportFromFMSel(file) : Model.ImportFromNDL(file)); - if (!success) return; + if (success) successCount++; } + if (successCount == 0) return; + SortFMTable((Column)FMsDGV.CurrentSortedColumn, FMsDGV.CurrentSortDirection); await SetFilter(forceRefreshReadme: true, forceSuppressSelectionChangedEvent: true); } diff --git a/AngelLoader/Ini/LocalizationIni.cs b/AngelLoader/Ini/LocalizationIni.cs index 09fc11544..b53a64f54 100644 --- a/AngelLoader/Ini/LocalizationIni.cs +++ b/AngelLoader/Ini/LocalizationIni.cs @@ -68,6 +68,10 @@ internal static void ReadLocalizationIni(string file) { LText.Global.Reset = lt.Substring(6); } + else if (lt.StartsWithFast_NoNullChecks("Autodetect=")) + { + LText.Global.Autodetect = lt.Substring(11); + } else if (lt.StartsWithFast_NoNullChecks("Unrated=")) { LText.Global.Unrated = lt.Substring(8);