Skip to content

Commit

Permalink
add 自动下载字典
Browse files Browse the repository at this point in the history
fix 一堆BUG
  • Loading branch information
dawn-lc committed Oct 2, 2022
1 parent 654beb8 commit ab9c4cf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
47 changes: 30 additions & 17 deletions ArchivePasswordTestTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace ArchivePasswordTestTool
public class Program
{
public static readonly string AppName = "ArchivePasswordTestTool";
public static readonly int[] Version = new int[] { 1, 5, 2 };
public static readonly int[] Version = new int[] { 1, 5, 3 };
public static readonly string VersionType = "Release";
public static readonly string AppHomePage = "https://www.bilibili.com/read/cv6101558";
public static readonly string Developer = "dawn-lc";
Expand Down Expand Up @@ -109,11 +109,9 @@ private static async Task Initialization(StatusContext ctx)
}
Warn($"{item.Name} 运行库缺少或损坏! ");
item.Exists = false;
config.CheckUpgrade = new();
}
if (!File.Exists("PasswordDictionary.txt"))
{
File.WriteAllText("PasswordDictionary.txt", "");
}
File.WriteAllText($"config.json", JsonSerializer.Serialize(config));
}
static async Task Main(string[] args)
{
Expand All @@ -133,11 +131,14 @@ await AnsiConsole.Progress().AutoClear(true).HideCompleted(true).StartAsync(asyn
{
foreach (var item in config.Libs.Where(i => !i.Exists))
{
HTTP.DownloadAsync(await HTTP.GetAsync(new Uri(item.DownloadUrl), new Dictionary<string, IEnumerable<string>>() { ["user-agent"] = new List<string>() { AppName + " " + string.Join(".", Version) } }), $"lib/{item.Name}", ctx.AddTask($"下载 {item.Name}"), item.Name);
await HTTP.DownloadAsync(await HTTP.GetAsync(new Uri(item.DownloadUrl), new Dictionary<string, IEnumerable<string>>() { ["user-agent"] = new List<string>() { AppName + " " + string.Join(".", Version) } }), $"lib/{item.Name}", ctx.AddTask($"下载 {item.Name}"), item.Name);
}
if (!File.Exists("PasswordDictionary.txt"))
{
await HTTP.DownloadAsync(await HTTP.GetAsync(new Uri("https://raw.githubusercontent.com/baidusama/EroPassword/main/PasswordDictionary.txt"), new Dictionary<string, IEnumerable<string>>() { ["user-agent"] = new List<string>() { AppName + " " + string.Join(".", Version) } }), "PasswordDictionary.txt", ctx.AddTask($"下载 PasswordDictionary.txt"), "PasswordDictionary.txt");
}
});
Log("下载完成,请重启软件以完成更新。");
await Task.Delay(5000);
AnsiConsole.Confirm("下载完成,请重启软件以完成更新。", true);
Environment.Exit(0);
}
AnsiConsole.Clear();
Expand Down Expand Up @@ -174,20 +175,32 @@ await AnsiConsole.Progress().AutoClear(true).HideCompleted(true).StartAsync(asyn
}
}

SevenZipBase.SetLibraryPath("lib/7z.dll");
string? EncryptArchivePassword = null;
await AnsiConsole.Status().StartAsync("测试密码中...", async ctx => {
Parallel.ForEach(File.ReadAllLines(config.Dictionary), new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount - 1 }, (i, loopState) =>
string[] Dictionary = File.ReadAllLines(config.Dictionary);

AnsiConsole.WriteLine($"字典内包含: {Dictionary.Length} 条密码。");
SevenZipBase.SetLibraryPath("lib/7z.dll");
await AnsiConsole.Progress().AutoClear(true).HideCompleted(true).StartAsync(async ctx =>
{
var Test = ctx.AddTask($"测试进度");
Parallel.ForEach(Dictionary, new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount - 1 }, (i, loopState) =>
{
using var temp = new SevenZipExtractor(ArchiveFile, i);
if (temp.Check())
try
{
using var temp = new SevenZipExtractor(ArchiveFile, i);
Test.Increment((double)1 / Dictionary.Length * 100);
if (temp.Check())
{
EncryptArchivePassword = i;
loopState.Break();
}
}
catch (Exception)
{
EncryptArchivePassword = i;
loopState.Break();
}
});
ctx.Status("测试结束。");
await Task.Delay(500);
Test.Increment(100);
Test.StopTask();
});
AnsiConsole.WriteLine(EncryptArchivePassword != null ? $"已找到解压密码: {EncryptArchivePassword}" : "没有找到正确的解压密码!");
if (AnsiConsole.Confirm("是否保存测试结果?", true))
Expand Down
2 changes: 1 addition & 1 deletion ArchivePasswordTestTool/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public static async Task<HttpResponseMessage> PutAsync(Uri url, HttpContent cont
{
return await Constructor(head, timeout).PutAsync(url, content);
}
public static async void DownloadAsync(HttpResponseMessage response, string path, ProgressTask task, string? name)
public static async Task DownloadAsync(HttpResponseMessage response, string path, ProgressTask task, string? name)
{
if (File.Exists(path))
{
Expand Down

0 comments on commit ab9c4cf

Please sign in to comment.