mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Merge pull request #1223 from wabbajack-tools/add-tesru-back-in
Add tesru back in
This commit is contained in:
@ -34,7 +34,8 @@ namespace Wabbajack.CLI
|
|||||||
typeof(ExportServerGameFiles),
|
typeof(ExportServerGameFiles),
|
||||||
typeof(HashGamefiles),
|
typeof(HashGamefiles),
|
||||||
typeof(Backup),
|
typeof(Backup),
|
||||||
typeof(Restore)
|
typeof(Restore),
|
||||||
|
typeof(PurgeArchive)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
65
Wabbajack.CLI/Verbs/PurgeArchive.cs
Normal file
65
Wabbajack.CLI/Verbs/PurgeArchive.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -95,7 +95,7 @@ namespace Wabbajack.Common
|
|||||||
public ValueTask<FileStream> OpenWrite()
|
public ValueTask<FileStream> OpenWrite()
|
||||||
{
|
{
|
||||||
var path = _path;
|
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)
|
public async Task WriteAllTextAsync(string text)
|
||||||
|
@ -69,6 +69,16 @@ namespace Wabbajack.Lib.Downloaders
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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/"))
|
if (!url.PathAndQuery.StartsWith("/files/file/"))
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(url.Query)) return null;
|
if (string.IsNullOrWhiteSpace(url.Query)) return null;
|
||||||
@ -76,6 +86,7 @@ namespace Wabbajack.Lib.Downloaders
|
|||||||
absolute = false;
|
absolute = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var id = HttpUtility.ParseQueryString(url.Query)["r"];
|
var id = HttpUtility.ParseQueryString(url.Query)["r"];
|
||||||
var file = absolute
|
var file = absolute
|
||||||
? url.AbsolutePath.Split('/').Last(s => s != "")
|
? url.AbsolutePath.Split('/').Last(s => s != "")
|
||||||
|
@ -407,13 +407,12 @@ namespace Wabbajack.Test
|
|||||||
Assert.Equal("Cheese for Everyone!", await filename.Path.ReadAllTextAsync());
|
Assert.Equal("Cheese for Everyone!", await filename.Path.ReadAllTextAsync());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Site is down
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task TESAllDownloader()
|
public async Task TESAllDownloader()
|
||||||
{
|
{
|
||||||
await DownloadDispatcher.GetInstance<TESAllDownloader>().Prepare();
|
await DownloadDispatcher.GetInstance<TESAllDownloader>().Prepare();
|
||||||
const string ini = "[General]\n" +
|
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());
|
var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());
|
||||||
|
|
||||||
@ -431,7 +430,6 @@ namespace Wabbajack.Test
|
|||||||
|
|
||||||
Assert.Equal("Cheese for Everyone!", await filename.Path.ReadAllTextAsync());
|
Assert.Equal("Cheese for Everyone!", await filename.Path.ReadAllTextAsync());
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/* WAITING FOR APPROVAL BY MODERATOR
|
/* WAITING FOR APPROVAL BY MODERATOR
|
||||||
[Fact]
|
[Fact]
|
||||||
|
Reference in New Issue
Block a user