wabbajack/Wabbajack.Lib/VortexInstaller.cs

80 lines
2.5 KiB
C#
Raw Normal View History

2019-11-09 20:40:25 +00:00
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using Wabbajack.Common;
2019-11-09 21:45:10 +00:00
using Wabbajack.Lib.Downloaders;
2019-11-15 13:06:34 +00:00
using Wabbajack.VirtualFileSystem;
2019-11-09 21:45:10 +00:00
using Directory = Alphaleonis.Win32.Filesystem.Directory;
using File = Alphaleonis.Win32.Filesystem.File;
using FileInfo = Alphaleonis.Win32.Filesystem.FileInfo;
using Path = Alphaleonis.Win32.Filesystem.Path;
2019-11-09 20:40:25 +00:00
namespace Wabbajack.Lib
{
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-11-17 04:16:42 +00:00
public WorkQueue Queue { get; }
2019-11-09 20:40:25 +00:00
2019-11-09 21:45:10 +00:00
public bool IgnoreMissingFiles { get; internal set; }
2019-11-09 20:40:25 +00:00
public VortexInstaller(string archive, ModList modList)
{
2019-11-17 04:16:42 +00:00
Queue = new WorkQueue();
ModManager = ModManager.Vortex;
2019-11-09 20:40:25 +00:00
ModListArchive = archive;
ModList = modList;
2019-11-09 21:45:10 +00:00
// TODO: only for testing
IgnoreMissingFiles = true;
GameInfo = GameRegistry.Games[ModList.GameType];
2019-11-09 20:40:25 +00:00
}
public override void Install()
2019-11-09 21:45:10 +00:00
{
Directory.CreateDirectory(DownloadFolder);
HashArchives();
DownloadArchives();
HashArchives();
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();
BuildFolderStructure();
InstallArchives();
InstallIncludedFiles();
//InstallIncludedDownloadMetas();
2019-11-09 21:45:10 +00:00
Info("Installation complete! You may exit the program.");
}
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
{
Status($"Writing included file {directive.To}");
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
}
}