Skip to content

Commit

Permalink
Import work:
Browse files Browse the repository at this point in the history
-Add autodetect feature for other loaders' .ini files
-Fix if one game's ini file failed, the whole operation would abort
  • Loading branch information
FenPhoenix committed Apr 14, 2019
1 parent c251358 commit 042c937
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 39 deletions.
26 changes: 13 additions & 13 deletions AngelLoader/BusinessLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -1124,7 +1124,7 @@ internal async Task<bool> InstallFM(FanMission fm)
return false;
}

var instBasePath = GetFMInstallsBasePath(fm);
var instBasePath = GetFMInstallsBasePath(fm.Game);

if (!Directory.Exists(instBasePath))
{
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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));
Expand All @@ -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++)
{
Expand All @@ -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
Expand Down Expand Up @@ -2182,7 +2182,7 @@ internal async Task<CacheData> 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())
Expand All @@ -2200,7 +2200,7 @@ internal async Task<CacheData> 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);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions AngelLoader/Common/DataClasses/Localization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
8 changes: 4 additions & 4 deletions AngelLoader/Common/Utility/Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? "";
Expand Down
1 change: 1 addition & 0 deletions AngelLoader/English.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ AddEllipses=Add...
Remove=Remove
RemoveEllipses=Remove...
Reset=Reset
Autodetect=Autodetect

Unrated=Unrated
None=None
Expand Down
4 changes: 2 additions & 2 deletions AngelLoader/FMBackupAndRestore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -418,7 +418,7 @@ void AddBakFilesFrom(string path)

var excludes = new List<string>();

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),
Expand Down
2 changes: 1 addition & 1 deletion AngelLoader/FMCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ internal static CacheData GetCacheableDataInFMInstalledDir(FanMission fm)

var readmes = new List<string>();

var thisFMInstallsBasePath = GetFMInstallsBasePath(fm);
var thisFMInstallsBasePath = GetFMInstallsBasePath(fm.Game);

var path = Path.Combine(thisFMInstallsBasePath, fm.InstalledDir);
var files = Directory.GetFiles(path, "*", SearchOption.TopDirectoryOnly).ToList();
Expand Down
26 changes: 22 additions & 4 deletions AngelLoader/Forms/ImportFromDarkLoaderForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 59 additions & 1 deletion AngelLoader/Forms/ImportFromDarkLoaderForm.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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)
{
Expand Down Expand Up @@ -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:
Expand Down
Loading

0 comments on commit 042c937

Please sign in to comment.