2020-01-26 04:50:17 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Alphaleonis.Win32.Filesystem;
|
|
|
|
|
using Wabbajack.BuildServer.Model.Models;
|
|
|
|
|
using Wabbajack.BuildServer.Models.JobQueue;
|
|
|
|
|
using Wabbajack.Common;
|
|
|
|
|
using Wabbajack.VirtualFileSystem;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.BuildServer.Models.Jobs
|
|
|
|
|
{
|
|
|
|
|
public class ReindexArchives : AJobPayload
|
|
|
|
|
{
|
|
|
|
|
public override string Description => "Reindex all files in the mod archive folder";
|
|
|
|
|
public override async Task<JobResult> Execute(DBContext db, SqlService sql, AppSettings settings)
|
|
|
|
|
{
|
|
|
|
|
using (var queue = new WorkQueue())
|
|
|
|
|
{
|
2020-03-28 20:42:45 +00:00
|
|
|
|
var files = settings.ArchiveDir.EnumerateFiles()
|
|
|
|
|
.Where(f => f.Extension != Consts.HashFileExtension)
|
2020-02-04 04:58:32 +00:00
|
|
|
|
.ToList();
|
|
|
|
|
var total_count = files.Count;
|
2020-01-26 04:50:17 +00:00
|
|
|
|
int completed = 0;
|
|
|
|
|
|
|
|
|
|
|
2020-02-04 04:58:32 +00:00
|
|
|
|
await files.PMap(queue, async file =>
|
2020-01-26 04:50:17 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Interlocked.Increment(ref completed);
|
|
|
|
|
|
2020-02-04 04:58:32 +00:00
|
|
|
|
if (await sql.HaveIndexdFile(await file.FileHashCachedAsync()))
|
2020-01-26 04:50:17 +00:00
|
|
|
|
{
|
2020-03-28 20:42:45 +00:00
|
|
|
|
Utils.Log($"({completed}/{total_count}) Skipping {file.FileName}, it's already indexed");
|
2020-01-26 04:50:17 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var sub_folder = Guid.NewGuid().ToString();
|
2020-03-28 20:42:45 +00:00
|
|
|
|
var folder = settings.DownloadDir.Combine(sub_folder);
|
2020-01-26 04:50:17 +00:00
|
|
|
|
|
|
|
|
|
Utils.Log($"({completed}/{total_count}) Copying {file}");
|
2020-03-28 20:42:45 +00:00
|
|
|
|
folder.CreateDirectory();
|
2020-01-26 04:50:17 +00:00
|
|
|
|
|
|
|
|
|
Utils.Log($"({completed}/{total_count}) Copying {file}");
|
2020-03-28 20:42:45 +00:00
|
|
|
|
file.CopyTo(folder.Combine(file.FileName));
|
2020-01-26 04:50:17 +00:00
|
|
|
|
|
|
|
|
|
Utils.Log($"({completed}/{total_count}) Analyzing {file}");
|
|
|
|
|
var vfs = new Context(queue, true);
|
|
|
|
|
await vfs.AddRoot(folder);
|
|
|
|
|
|
|
|
|
|
var root = vfs.Index.ByRootPath.First().Value;
|
|
|
|
|
|
|
|
|
|
Utils.Log($"({completed}/{total_count}) Ingesting {root.ThisAndAllChildren.Count()} files");
|
|
|
|
|
|
|
|
|
|
await sql.MergeVirtualFile(root);
|
|
|
|
|
Utils.Log($"({completed}/{total_count}) Cleaning up {file}");
|
2020-03-28 20:42:45 +00:00
|
|
|
|
await Utils.DeleteDirectory(folder);
|
2020-01-26 04:50:17 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Utils.Log(ex.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return JobResult.Success();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|