Merge pull request #1223 from wabbajack-tools/add-tesru-back-in

Add tesru back in
This commit is contained in:
Timothy Baldridge 2020-12-15 21:23:40 -07:00 committed by GitHub
commit b2a49fd944
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 80 additions and 5 deletions

View File

@ -34,7 +34,8 @@ namespace Wabbajack.CLI
typeof(ExportServerGameFiles),
typeof(HashGamefiles),
typeof(Backup),
typeof(Restore)
typeof(Restore),
typeof(PurgeArchive)
};
}
}

View File

@ -0,0 +1,65 @@
using System.IO.Compression;
using System.Linq;
using System.Threading.Tasks;
using CommandLine;
using Wabbajack.Common;
using Wabbajack.Lib;
namespace Wabbajack.CLI.Verbs
{
[Verb("purge-archive", HelpText = "Purges an archive and all directives from a .wabbajack file")]
public class PurgeArchive : AVerb
{
[Option('i', "input", Required = true, HelpText = "Input .wabbajack file")]
public string Input { get; set; } = "";
private AbsolutePath _Input => (AbsolutePath)Input;
[Option('o', "output", Required = true, HelpText = "Output .wabbajack file")]
public string Output { get; set; } = "";
private AbsolutePath _Output => (AbsolutePath)Output;
[Option('h', "hash", Required = true, HelpText = "Hash to purge")]
public string ArchiveHash { get; set; } = "";
private Hash _Hash => Hash.Interpret(ArchiveHash);
protected override async Task<ExitCode> Run()
{
Utils.Log("Copying .wabbajack file");
await _Input.CopyToAsync(_Output);
Utils.Log("Loading modlist");
await using var fs = await _Output.OpenWrite();
using var ar = new ZipArchive(fs, ZipArchiveMode.Update);
ModList modlist;
await using (var entry = ar.Entries.First(e => e.Name == "modlist").Open())
{
modlist = entry.FromJson<ModList>();
}
Utils.Log("Purging archives");
modlist.Archives = modlist.Archives.Where(a => a.Hash != _Hash).ToList();
modlist.Directives = modlist.Directives.Select(d =>
{
if (d is FromArchive a)
{
if (a.ArchiveHashPath.BaseHash == _Hash) return (false, d);
}
return (true, d);
}).Where(d => d.Item1)
.Select(d => d.d)
.ToList();
Utils.Log("Writing modlist");
await using (var entry = ar.Entries.First(e => e.Name == "modlist").Open())
{
entry.SetLength(0);
entry.Position = 0;
modlist.ToJson(entry);
}
return ExitCode.Ok;
}
}
}

View File

@ -95,7 +95,7 @@ namespace Wabbajack.Common
public ValueTask<FileStream> OpenWrite()
{
var path = _path;
return CircuitBreaker.WithAutoRetryAsync<FileStream, IOException>(async () => File.OpenWrite(path));
return CircuitBreaker.WithAutoRetryAsync<FileStream, IOException>(async () => File.Open(path, FileMode.OpenOrCreate, FileAccess.ReadWrite));
}
public async Task WriteAllTextAsync(string text)

View File

@ -68,6 +68,16 @@ namespace Wabbajack.Lib.Downloaders
IsAttachment = true
};
}
if (url.PathAndQuery.StartsWith("/files/download/") && long.TryParse(url.PathAndQuery.Split("/").Last(), out var fileId))
{
return new TState
{
FullURL = url.ToString(),
IsAttachment = true
};
}
if (!url.PathAndQuery.StartsWith("/files/file/"))
{
@ -76,6 +86,7 @@ namespace Wabbajack.Lib.Downloaders
absolute = false;
}
var id = HttpUtility.ParseQueryString(url.Query)["r"];
var file = absolute
? url.AbsolutePath.Split('/').Last(s => s != "")

View File

@ -407,13 +407,12 @@ namespace Wabbajack.Test
Assert.Equal("Cheese for Everyone!", await filename.Path.ReadAllTextAsync());
}
/* Site is down
[Fact]
public async Task TESAllDownloader()
{
await DownloadDispatcher.GetInstance<TESAllDownloader>().Prepare();
const string ini = "[General]\n" +
"directURL=https://tesall.ru/files/getdownload/594545-wabbajack-test-file/";
"directURL=https://tesall.ru/files/download/594545";
var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());
@ -431,7 +430,6 @@ namespace Wabbajack.Test
Assert.Equal("Cheese for Everyone!", await filename.Path.ReadAllTextAsync());
}
*/
/* WAITING FOR APPROVAL BY MODERATOR
[Fact]