2019-12-03 12:13:37 +00:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Linq;
|
2019-12-03 21:56:18 +00:00
|
|
|
|
using System.Threading;
|
2019-12-03 12:13:37 +00:00
|
|
|
|
using System.Windows;
|
2019-11-09 20:40:25 +00:00
|
|
|
|
using Wabbajack.Common;
|
2019-11-09 21:45:10 +00:00
|
|
|
|
using Directory = Alphaleonis.Win32.Filesystem.Directory;
|
|
|
|
|
using File = Alphaleonis.Win32.Filesystem.File;
|
|
|
|
|
using Path = Alphaleonis.Win32.Filesystem.Path;
|
2019-11-09 20:40:25 +00:00
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Lib
|
|
|
|
|
{
|
2019-11-16 13:22:40 +00:00
|
|
|
|
public class VortexInstaller : AInstaller
|
2019-11-09 20:40:25 +00:00
|
|
|
|
{
|
2019-11-09 21:45:10 +00:00
|
|
|
|
public GameMetaData GameInfo { get; internal set; }
|
|
|
|
|
|
2019-12-01 20:22:33 +00:00
|
|
|
|
public override ModManager ModManager => ModManager.Vortex;
|
2019-11-09 21:45:10 +00:00
|
|
|
|
|
2019-12-01 20:22:33 +00:00
|
|
|
|
public VortexInstaller(string archive, ModList modList, string outputFolder, string downloadFolder)
|
|
|
|
|
: base(
|
|
|
|
|
archive: archive,
|
|
|
|
|
modList: modList,
|
|
|
|
|
outputFolder: outputFolder,
|
|
|
|
|
downloadFolder: downloadFolder)
|
|
|
|
|
{
|
|
|
|
|
#if DEBUG
|
2019-11-09 21:45:10 +00:00
|
|
|
|
// TODO: only for testing
|
|
|
|
|
IgnoreMissingFiles = true;
|
2019-12-01 20:22:33 +00:00
|
|
|
|
#endif
|
2019-11-09 21:45:10 +00:00
|
|
|
|
|
|
|
|
|
GameInfo = GameRegistry.Games[ModList.GameType];
|
2019-11-09 20:40:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-03 21:56:18 +00:00
|
|
|
|
protected override bool _Begin(CancellationToken cancel)
|
2019-11-09 21:45:10 +00:00
|
|
|
|
{
|
2019-12-03 21:56:18 +00:00
|
|
|
|
if (cancel.IsCancellationRequested) return false;
|
2019-12-03 12:20:16 +00:00
|
|
|
|
MessageBox.Show(
|
|
|
|
|
"Vortex Support is still experimental and may produce unexpected results. " +
|
|
|
|
|
"If anything fails go to the special vortex support channels on the discord. @erri120#2285 " +
|
|
|
|
|
"for support.", "Warning",
|
|
|
|
|
MessageBoxButton.OK);
|
|
|
|
|
|
2019-12-03 21:56:18 +00:00
|
|
|
|
if (cancel.IsCancellationRequested) return false;
|
2019-11-20 23:39:03 +00:00
|
|
|
|
ConfigureProcessor(10, RecommendQueueSize());
|
2019-11-09 21:45:10 +00:00
|
|
|
|
Directory.CreateDirectory(DownloadFolder);
|
|
|
|
|
|
2019-12-03 21:56:18 +00:00
|
|
|
|
if (cancel.IsCancellationRequested) return false;
|
2019-11-09 21:45:10 +00:00
|
|
|
|
HashArchives();
|
2019-12-03 21:56:18 +00:00
|
|
|
|
|
|
|
|
|
if (cancel.IsCancellationRequested) return false;
|
2019-11-09 21:45:10 +00:00
|
|
|
|
DownloadArchives();
|
2019-12-03 21:56:18 +00:00
|
|
|
|
|
|
|
|
|
if (cancel.IsCancellationRequested) return false;
|
2019-11-09 21:45:10 +00:00
|
|
|
|
HashArchives();
|
|
|
|
|
|
2019-12-03 21:56:18 +00:00
|
|
|
|
if (cancel.IsCancellationRequested) return false;
|
2019-11-09 21:45:10 +00:00
|
|
|
|
var missing = ModList.Archives.Where(a => !HashedArchives.ContainsKey(a.Hash)).ToList();
|
|
|
|
|
if (missing.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (var a in missing)
|
|
|
|
|
Info($"Unable to download {a.Name}");
|
|
|
|
|
if (IgnoreMissingFiles)
|
|
|
|
|
Info("Missing some archives, but continuing anyways at the request of the user");
|
|
|
|
|
else
|
|
|
|
|
Error("Cannot continue, was unable to download one or more archives");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PrimeVFS();
|
|
|
|
|
|
2019-12-03 21:56:18 +00:00
|
|
|
|
if (cancel.IsCancellationRequested) return false;
|
2019-11-09 21:45:10 +00:00
|
|
|
|
BuildFolderStructure();
|
2019-12-03 21:56:18 +00:00
|
|
|
|
|
|
|
|
|
if (cancel.IsCancellationRequested) return false;
|
2019-11-09 21:45:10 +00:00
|
|
|
|
InstallArchives();
|
2019-12-03 21:56:18 +00:00
|
|
|
|
|
|
|
|
|
if (cancel.IsCancellationRequested) return false;
|
2019-11-09 21:45:10 +00:00
|
|
|
|
InstallIncludedFiles();
|
2019-12-03 21:56:18 +00:00
|
|
|
|
|
|
|
|
|
if (cancel.IsCancellationRequested) return false;
|
2019-12-03 12:13:37 +00:00
|
|
|
|
InstallSteamWorkshopItems();
|
2019-11-16 13:22:40 +00:00
|
|
|
|
//InstallIncludedDownloadMetas();
|
2019-11-09 21:45:10 +00:00
|
|
|
|
|
|
|
|
|
Info("Installation complete! You may exit the program.");
|
2019-11-17 23:48:32 +00:00
|
|
|
|
return true;
|
2019-11-09 21:45:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-03 12:13:37 +00:00
|
|
|
|
private void InstallSteamWorkshopItems()
|
|
|
|
|
{
|
|
|
|
|
//var currentLib = "";
|
|
|
|
|
SteamGame currentSteamGame = null;
|
|
|
|
|
SteamHandler.Instance.Games.Where(g => g.Game == GameInfo.Game).Do(s => currentSteamGame = s);
|
|
|
|
|
/*SteamHandler.Instance.InstallFolders.Where(f => f.Contains(currentSteamGame.InstallDir)).Do(s => currentLib = s);
|
|
|
|
|
|
|
|
|
|
var downloadFolder = Path.Combine(currentLib, "workshop", "downloads", currentSteamGame.AppId.ToString());
|
|
|
|
|
var contentFolder = Path.Combine(currentLib, "workshop", "content", currentSteamGame.AppId.ToString());
|
|
|
|
|
*/
|
|
|
|
|
if (!ModList.Directives.Any(s => s is SteamMeta))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var result = MessageBox.Show("The ModList you are installing requires Steam Workshop Items to exist. " +
|
|
|
|
|
"You can check the Workshop Items in the manifest of this ModList. Wabbajack can start Steam for you " +
|
|
|
|
|
"and download the Items automatically. Do you want to proceed with this step?",
|
|
|
|
|
"Warning", MessageBoxButton.YesNo);
|
|
|
|
|
|
|
|
|
|
if (result != MessageBoxResult.Yes)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ModList.Directives.OfType<SteamMeta>()
|
|
|
|
|
.PMap(Queue, item =>
|
|
|
|
|
{
|
|
|
|
|
Status("Extracting Steam meta file to temp folder");
|
|
|
|
|
var path = Path.Combine(DownloadFolder, $"steamWorkshopItem_{item.ItemID}.meta");
|
|
|
|
|
if (!File.Exists(path))
|
|
|
|
|
File.WriteAllBytes(path, LoadBytesFromPath(item.SourceDataID));
|
|
|
|
|
|
|
|
|
|
Status("Downloading Steam Workshop Item through steam cmd");
|
|
|
|
|
|
|
|
|
|
var p = new Process
|
|
|
|
|
{
|
|
|
|
|
StartInfo = new ProcessStartInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = System.IO.Path.Combine(SteamHandler.Instance.SteamPath, "steam.exe"),
|
|
|
|
|
CreateNoWindow = true,
|
|
|
|
|
Arguments = $"console +workshop_download_item {currentSteamGame.AppId} {item.ItemID}"
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
p.Start();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-09 21:45:10 +00:00
|
|
|
|
private void InstallIncludedFiles()
|
|
|
|
|
{
|
|
|
|
|
Info("Writing inline files");
|
|
|
|
|
ModList.Directives.OfType<InlineFile>()
|
2019-11-17 04:16:42 +00:00
|
|
|
|
.PMap(Queue,directive =>
|
2019-11-09 21:45:10 +00:00
|
|
|
|
{
|
2019-12-04 10:42:58 +00:00
|
|
|
|
if (directive.To.EndsWith(".meta"))
|
|
|
|
|
return;
|
|
|
|
|
|
2019-11-09 21:45:10 +00:00
|
|
|
|
Status($"Writing included file {directive.To}");
|
2019-11-16 13:22:40 +00:00
|
|
|
|
var outPath = Path.Combine(OutputFolder, directive.To);
|
2019-11-09 21:45:10 +00:00
|
|
|
|
if(File.Exists(outPath)) File.Delete(outPath);
|
|
|
|
|
File.WriteAllBytes(outPath, LoadBytesFromPath(directive.SourceDataID));
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-11-09 20:40:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|