Only 69 errors left, Nice!

This commit is contained in:
Timothy Baldridge 2020-03-25 16:49:32 -06:00
parent defbc15593
commit 5bc361663f
6 changed files with 67 additions and 58 deletions

View File

@ -232,7 +232,7 @@ namespace Wabbajack.Lib
{
foreach (var a in missing.Where(a => a.State.GetType() == typeof(ManualDownloader.State)))
{
var outputPath = Path.Combine(DownloadFolder, a.Name);
var outputPath = DownloadFolder.Combine(a.Name);
await a.State.Download(a, outputPath);
}
}
@ -241,18 +241,17 @@ namespace Wabbajack.Lib
.PMap(Queue, async archive =>
{
Info($"Downloading {archive.Name}");
var outputPath = Path.Combine(DownloadFolder, archive.Name);
var outputPath = DownloadFolder.Combine(archive.Name);
if (download)
{
if (outputPath.FileExists())
if (outputPath.Exists)
{
var orig_name = Path.GetFileNameWithoutExtension(archive.Name);
var origName = Path.GetFileNameWithoutExtension(archive.Name);
var ext = Path.GetExtension(archive.Name);
var unique_key = archive.State.PrimaryKeyString.StringSha256Hex();
outputPath = Path.Combine(DownloadFolder, orig_name + "_" + unique_key + "_" + ext);
if (outputPath.FileExists())
File.Delete(outputPath);
var uniqueKey = archive.State.PrimaryKeyString.StringSha256Hex();
outputPath = DownloadFolder.Combine(origName + "_" + uniqueKey + "_" + ext);
outputPath.Delete();
}
}
@ -260,13 +259,13 @@ namespace Wabbajack.Lib
});
}
public async Task<bool> DownloadArchive(Archive archive, bool download, string destination = null)
public async Task<bool> DownloadArchive(Archive archive, bool download, AbsolutePath? destination = null)
{
try
{
if (destination == null)
destination = Path.Combine(DownloadFolder, archive.Name);
await DownloadDispatcher.DownloadWithPossibleUpgrade(archive, destination);
destination = DownloadFolder.Combine(archive.Name);
await DownloadDispatcher.DownloadWithPossibleUpgrade(archive, destination.Value);
}
catch (Exception ex)
{
@ -280,11 +279,11 @@ namespace Wabbajack.Lib
public async Task HashArchives()
{
var hashResults = await Directory.EnumerateFiles(DownloadFolder)
.Where(e => !e.EndsWith(Consts.HashFileExtension))
.PMap(Queue, e => (e.FileHashCached(), e));
var hashResults = await DownloadFolder.EnumerateFiles()
.Where(e => e.Extension != Consts.HashFileExtension)
.PMap(Queue, async e => (await e.FileHashCachedAsync(), e));
HashedArchives = hashResults
.OrderByDescending(e => File.GetLastWriteTime(e.Item2))
.OrderByDescending(e => e.Item2.LastModified)
.GroupBy(e => e.Item1)
.Select(e => e.First())
.ToDictionary(e => e.Item1, e => e.Item2);

View File

@ -45,7 +45,7 @@ namespace Wabbajack.Lib.CompilationSteps
else
{
var bsa_path = _bsa.FullPath.Paths.Last().RelativeTo(((MO2Compiler)_compiler).MO2Folder);
mod_ini = ((MO2Compiler)_compiler).ModMetas.FirstOrDefault(f => ((string)bsa_path).StartsWith(f.Key)).Value;
mod_ini = ((MO2Compiler)_compiler).ModMetas.FirstOrDefault(f => ((string)bsa_path).StartsWith((string)f.Key)).Value;
}
var installationFile = mod_ini?.General?.installationFile;

View File

@ -31,7 +31,7 @@ namespace Wabbajack.Lib
public AbsolutePath MO2Folder;
public string MO2Profile { get; }
public Dictionary<string, dynamic> ModMetas { get; set; }
public Dictionary<RelativePath, dynamic> ModMetas { get; set; }
public override ModManager ModManager => ModManager.MO2;
@ -103,19 +103,19 @@ namespace Wabbajack.Lib
if (cancel.IsCancellationRequested) return false;
await VFS.IntegrateFromFile(VFSCacheName);
var roots = new List<string>()
var roots = new List<AbsolutePath>()
{
MO2Folder, GamePath, MO2DownloadsFolder
};
// TODO: make this generic so we can add more paths
var lootPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
var lootPath = (AbsolutePath)Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"LOOT");
IEnumerable<RawSourceFile> lootFiles = new List<RawSourceFile>();
if (Directory.Exists(lootPath))
if (lootPath.Exists)
{
roots.Add(lootPath);
roots.Add((AbsolutePath)lootPath);
}
UpdateTracker.NextStep("Indexing folders");
@ -123,7 +123,7 @@ namespace Wabbajack.Lib
await VFS.AddRoots(roots);
await VFS.WriteToFile(VFSCacheName);
if (Directory.Exists(lootPath))
if (lootPath.Exists)
{
var lootGameDirs = new []
{
@ -150,9 +150,7 @@ namespace Wabbajack.Lib
if (cancel.IsCancellationRequested) return false;
UpdateTracker.NextStep("Cleaning output folder");
if (Directory.Exists(ModListOutputFolder))
Utils.DeleteDirectory(ModListOutputFolder);
ModListOutputFolder.DeleteDirectory();
if (cancel.IsCancellationRequested) return false;
UpdateTracker.NextStep("Inferring metas for game file downloads");
@ -168,29 +166,28 @@ namespace Wabbajack.Lib
UpdateTracker.NextStep("Pre-validating Archives");
IndexedArchives = Directory.EnumerateFiles(MO2DownloadsFolder)
.Where(f => File.Exists(f + Consts.MetaFileExtension))
.Select(f => new IndexedArchive
IndexedArchives = (await MO2DownloadsFolder.EnumerateFiles()
.Where(f => f.WithExtension(Consts.MetaFileExtension).Exists)
.PMap(Queue, async f => new IndexedArchive
{
File = VFS.Index.ByRootPath[f],
Name = Path.GetFileName(f),
IniData = (f + Consts.MetaFileExtension).LoadIniFile(),
Meta = File.ReadAllText(f + Consts.MetaFileExtension)
})
.ToList();
Name = (string)f.FileName,
IniData = f.WithExtension(Consts.MetaFileExtension).LoadIniFile(),
Meta = await f.WithExtension(Consts.MetaFileExtension).ReadAllTextAsync()
})).ToList();
await CleanInvalidArchives();
UpdateTracker.NextStep("Finding Install Files");
Directory.CreateDirectory(ModListOutputFolder);
ModListOutputFolder.CreateDirectory();
var mo2Files = Directory.EnumerateFiles(MO2Folder, "*", SearchOption.AllDirectories)
.Where(p => p.FileExists())
var mo2Files = MO2Folder.EnumerateFiles()
.Where(p => p.IsFile)
.Select(p =>
{
if (!VFS.Index.ByFullPath.ContainsKey(p))
if (!VFS.Index.ByRootPath.ContainsKey(p))
Utils.Log($"WELL THERE'S YOUR PROBLEM: {p} {VFS.Index.ByRootPath.Count}");
return new RawSourceFile(VFS.Index.ByRootPath[p], p.RelativeTo(MO2Folder));
@ -198,13 +195,13 @@ namespace Wabbajack.Lib
// If Game Folder Files exists, ignore the game folder
IEnumerable<RawSourceFile> gameFiles;
if (!Directory.Exists(Path.Combine(MO2Folder, Consts.GameFolderFilesDir)))
if (!MO2Folder.Combine(Consts.GameFolderFilesDir).Exists)
{
gameFiles = Directory.EnumerateFiles(GamePath, "*", SearchOption.AllDirectories)
.Where(p => p.FileExists())
.Where(p => Path.GetExtension(p) != Consts.HashFileExtension)
gameFiles = GamePath.EnumerateFiles()
.Where(p => p.IsFile)
.Where(p => p.Extension!= Consts.HashFileExtension)
.Select(p => new RawSourceFile(VFS.Index.ByRootPath[p],
Path.Combine(Consts.GameFolderFilesDir, p.RelativeTo(GamePath))));
Consts.GameFolderFilesDir.Combine(p.RelativeTo(GamePath))));
}
else
{
@ -212,12 +209,12 @@ namespace Wabbajack.Lib
}
ModMetas = Directory.EnumerateDirectories(Path.Combine(MO2Folder, Consts.MO2ModFolderName))
ModMetas = MO2Folder.Combine(Consts.MO2ModFolderName).EnumerateFiles()
.Keep(f =>
{
var path = Path.Combine(f, "meta.ini");
return File.Exists(path) ? (f, path.LoadIniFile()) : default;
}).ToDictionary(f => f.f.RelativeTo(MO2Folder) + "\\", v => v.Item2);
var path = f.Combine("meta.ini");
return path.Exists ? (f, path.LoadIniFile()) : default;
}).ToDictionary(f => f.f.RelativeTo(MO2Folder), v => v.Item2);
IndexedFiles = IndexedArchives.SelectMany(f => f.File.ThisAndAllChildren)
.OrderBy(f => f.NestingFactor)

View File

@ -329,13 +329,13 @@ namespace Wabbajack.Lib
private void SetScreenSizeInPrefs()
{
var config = new IniParserConfiguration {AllowDuplicateKeys = true, AllowDuplicateSections = true};
foreach (var file in Directory.EnumerateFiles(Path.Combine(OutputFolder, "profiles"), "*refs.ini",
DirectoryEnumerationOptions.Recursive))
foreach (var file in OutputFolder.Combine("profiles").EnumerateFiles()
.Where(f => ((string)f.FileName).EndsWith("*refs.ini")))
{
try
{
var parser = new FileIniDataParser(new IniDataParser(config));
var data = parser.ReadFile(file);
var data = parser.ReadFile((string)file);
bool modified = false;
if (data.Sections["Display"] != null)
{
@ -361,7 +361,7 @@ namespace Wabbajack.Lib
}
if (modified)
parser.WriteFile(file, data);
parser.WriteFile((string)file, data);
}
catch (Exception ex)
{

View File

@ -101,7 +101,7 @@ namespace Wabbajack.Lib
if (cancel.IsCancellationRequested) return false;
await VFS.IntegrateFromFile(VFSCacheName);
var roots = new List<string> {StagingFolder, GamePath, DownloadsFolder};
var roots = new List<AbsolutePath> {StagingFolder, GamePath, DownloadsFolder};
AddExternalFolder(ref roots);
if (cancel.IsCancellationRequested) return false;
@ -111,12 +111,11 @@ namespace Wabbajack.Lib
if (cancel.IsCancellationRequested) return false;
UpdateTracker.NextStep("Cleaning output folder");
if (Directory.Exists(ModListOutputFolder))
Utils.DeleteDirectory(ModListOutputFolder);
Directory.CreateDirectory(ModListOutputFolder);
ModListOutputFolder.DeleteDirectory();
ModListOutputFolder.CreateDirectory();
UpdateTracker.NextStep("Finding Install Files");
/* TODO
var vortexStagingFiles = Directory.EnumerateFiles(StagingFolder, "*", SearchOption.AllDirectories)
.Where(p => p.FileExists() && p != StagingMarkerName && !p.Contains(Consts.ManualGameFilesDir))
.Select(p => new RawSourceFile(VFS.Index.ByRootPath[p], p.RelativeTo(StagingFolder)));
@ -254,6 +253,7 @@ namespace Wabbajack.Lib
ResetMembers();
UpdateTracker.NextStep("Done Building ModList");
*/
return true;
}
@ -268,19 +268,20 @@ namespace Wabbajack.Lib
SelectedArchives = null;
}
private void AddExternalFolder(ref List<string> roots)
private void AddExternalFolder(ref List<AbsolutePath> roots)
{
var currentGame = Game.MetaData();
if (currentGame.AdditionalFolders == null || currentGame.AdditionalFolders.Count == 0) return;
foreach (var path in currentGame.AdditionalFolders.Select(f => f.Replace("%documents%", KnownFolders.Documents.Path)))
{
if (!Directory.Exists(path)) return;
roots.Add(path);
roots.Add((AbsolutePath)path);
}
}
private void ParseDeploymentFile()
{
/* TODO
Info("Searching for vortex.deployment.json...");
var deploymentFile = "";
@ -319,10 +320,12 @@ namespace Wabbajack.Lib
Utils.Log($"Adding archive {archive} to ActiveArchives");
ActiveArchives.Add(archive);
});
*/
}
private async Task CreateMetaFiles()
{
/*
Utils.Log("Getting Nexus API key, please click authorize if a browser window appears");
var nexusClient = await NexusApiClient.Get();
@ -424,10 +427,12 @@ namespace Wabbajack.Lib
Utils.Error(e, $"Exception while writing to disk at {filePath}");
}
});
*/
}
public override IEnumerable<ICompilationStep> GetStack()
{
/*
var s = Consts.TestMode ? DownloadsFolder : VortexFolder;
var userConfig = Path.Combine(s, "compilation_stack.yml");
if (File.Exists(userConfig))
@ -440,6 +445,8 @@ namespace Wabbajack.Lib
Serialization.Serialize(compilationSteps));
return compilationSteps;
*/
return null;
}
public override IEnumerable<ICompilationStep> MakeStack()
@ -459,8 +466,10 @@ namespace Wabbajack.Lib
Game == Game.DarkestDungeon ? new IncludeRegex(this, "project\\.xml$") : null,
/*
new IgnoreStartsWith(this, StagingFolder),
new IgnoreEndsWith(this, StagingFolder),
*/
new IgnoreGameFiles(this),
@ -488,10 +497,14 @@ namespace Wabbajack.Lib
public static string RetrieveStagingLocation(Game game, string vortexFolderPath = null)
{
/*
vortexFolderPath = vortexFolderPath ?? TypicalVortexFolder();
var gameName = game.MetaData().NexusName;
return Path.Combine(vortexFolderPath, gameName, Consts.MO2ModFolderName);
*/
return null;
}
public static IErrorResponse IsValidBaseDownloadsFolder(string path)
{

View File

@ -108,7 +108,7 @@ namespace Wabbajack.Lib
};
}).ToList();
var src_data = result.Sources.Select(f => File.ReadAllBytes(Path.Combine(_mo2Compiler.MO2Folder, f.RelativePath)))
var src_data = result.Sources.Select(f => _mo2Compiler.MO2Folder.Combine(f.RelativePath).ReadAllBytes())
.ConcatArrays();
var dst_data = File.ReadAllBytes(source.AbsolutePath);