mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
bunch of fixes to file extraction
This commit is contained in:
parent
5ddbd832f6
commit
b72a64ff8b
@ -7,8 +7,11 @@ using System.Collections.Immutable;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Security.AccessControl;
|
||||
using Alphaleonis.Win32.Filesystem;
|
||||
using Wabbajack.Common;
|
||||
using Directory = Alphaleonis.Win32.Filesystem.Directory;
|
||||
using DirectoryInfo = Alphaleonis.Win32.Filesystem.DirectoryInfo;
|
||||
using File = Alphaleonis.Win32.Filesystem.File;
|
||||
using FileInfo = Alphaleonis.Win32.Filesystem.FileInfo;
|
||||
using Path = Alphaleonis.Win32.Filesystem.Path;
|
||||
@ -32,33 +35,49 @@ namespace VFS
|
||||
VFS = new VirtualFileSystem();
|
||||
RootFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||
_stagedRoot = Path.Combine(RootFolder, "vfs_staged_files");
|
||||
Utils.OnQueue(() =>
|
||||
{
|
||||
if (Directory.Exists(_stagedRoot))
|
||||
DeleteDirectory(_stagedRoot);
|
||||
});
|
||||
|
||||
Directory.CreateDirectory(_stagedRoot);
|
||||
}
|
||||
|
||||
private static void DeleteDirectory(string path)
|
||||
{
|
||||
foreach (var file in Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories))
|
||||
Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories)
|
||||
.DoProgress("Cleaning VFS Files", file =>
|
||||
{
|
||||
File.SetAttributes(file, FileAttributes.Normal);
|
||||
try
|
||||
{
|
||||
var fi = new FileInfo(file);
|
||||
fi.Attributes &= ~FileAttributes.ReadOnly;
|
||||
File.Delete(file);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utils.Log(ex.ToString());
|
||||
}
|
||||
}
|
||||
try {
|
||||
});
|
||||
|
||||
Directory.EnumerateDirectories(path, DirectoryEnumerationOptions.Recursive)
|
||||
.DoProgress("Cleaning VFS Folders", folder =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists(folder))
|
||||
return;
|
||||
var di = new DirectoryInfo(folder);
|
||||
di.Attributes &= ~FileAttributes.ReadOnly;
|
||||
Directory.Delete(path, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utils.Log(ex.ToString());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -365,7 +384,7 @@ namespace VFS
|
||||
{
|
||||
var tmp_path = Path.Combine(_stagedRoot, Guid.NewGuid().ToString());
|
||||
FileExtractor.ExtractAll(group.Key.StagedPath, tmp_path);
|
||||
|
||||
Paths.Add(tmp_path);
|
||||
foreach (var file in group)
|
||||
file._stagedPath = Path.Combine(tmp_path, file.Paths[group.Key.Paths.Length]);
|
||||
|
||||
|
@ -83,7 +83,7 @@ namespace Wabbajack.Common
|
||||
var info = new ProcessStartInfo
|
||||
{
|
||||
FileName = "7z.exe",
|
||||
Arguments = $"x -o\"{dest}\" \"{source}\"",
|
||||
Arguments = $"x -bsp1 -y -o\"{dest}\" \"{source}\"",
|
||||
RedirectStandardError = true,
|
||||
RedirectStandardInput = true,
|
||||
RedirectStandardOutput = true,
|
||||
@ -104,6 +104,28 @@ namespace Wabbajack.Common
|
||||
}
|
||||
catch (Exception) { }
|
||||
|
||||
var name = Path.GetFileName(source);
|
||||
try
|
||||
{
|
||||
while (!p.HasExited)
|
||||
{
|
||||
var line = p.StandardOutput.ReadLine();
|
||||
if (line == null)
|
||||
break;
|
||||
int percent = 0;
|
||||
if (line.Length > 4 && line[3] == '%')
|
||||
{
|
||||
Int32.TryParse(line.Substring(0, 3), out percent);
|
||||
Utils.Status($"Extracting {name} - {line.Trim()}", percent);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
p.WaitForExit();
|
||||
if (p.ExitCode != 0)
|
||||
{
|
||||
@ -113,7 +135,6 @@ namespace Wabbajack.Common
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the given extension type can be extracted
|
||||
/// </summary>
|
||||
|
@ -7,11 +7,15 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Configuration;
|
||||
using System.Net.Http;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using File = Alphaleonis.Win32.Filesystem.File;
|
||||
using FileInfo = Alphaleonis.Win32.Filesystem.FileInfo;
|
||||
using Path = Alphaleonis.Win32.Filesystem.Path;
|
||||
|
||||
namespace Wabbajack.Common
|
||||
{
|
||||
@ -301,6 +305,21 @@ namespace Wabbajack.Common
|
||||
return;
|
||||
}
|
||||
|
||||
public static void DoProgress<T>(this IEnumerable<T> coll, String msg, Action<T> f)
|
||||
{
|
||||
var lst = coll.ToList();
|
||||
lst.DoIndexed((idx, i) =>
|
||||
{
|
||||
Status(msg, idx * 100 / lst.Count);
|
||||
f(i);
|
||||
});
|
||||
}
|
||||
|
||||
public static void OnQueue(Action f)
|
||||
{
|
||||
new List<bool>().Do(_ => f());
|
||||
}
|
||||
|
||||
public static HttpResponseMessage GetSync(this HttpClient client, string url)
|
||||
{
|
||||
var result = client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead);
|
||||
|
@ -10,7 +10,7 @@ namespace Wabbajack.Common
|
||||
{
|
||||
public class WorkQueue
|
||||
{
|
||||
internal static BlockingCollection<Action> Queue = new BlockingCollection<Action>();
|
||||
internal static BlockingCollection<Action> Queue = new BlockingCollection<Action>(new ConcurrentStack<Action>());
|
||||
|
||||
[ThreadStatic]
|
||||
private static int CpuId;
|
||||
|
Loading…
Reference in New Issue
Block a user