mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
62 lines
1.8 KiB
C#
62 lines
1.8 KiB
C#
using System.Threading.Tasks;
|
|
using Wabbajack.Common.IO;
|
|
|
|
namespace Wabbajack.Common
|
|
{
|
|
public static class FileCompaction
|
|
{
|
|
private static AbsolutePath _compactExecutable;
|
|
private static bool? _haveCompact = null;
|
|
|
|
private static AbsolutePath? GetCompactPath()
|
|
{
|
|
if (_haveCompact != null && _haveCompact.Value) return _compactExecutable;
|
|
if (_haveCompact != null) return null;
|
|
_compactExecutable = ((AbsolutePath)KnownFolders.SystemX86.Path).Combine("compact.exe");
|
|
|
|
if (!_compactExecutable.Exists) return null;
|
|
|
|
_haveCompact = true;
|
|
return _compactExecutable;
|
|
}
|
|
|
|
public enum Algorithm
|
|
{
|
|
XPRESS4K,
|
|
XPRESS8K,
|
|
XPRESS16K,
|
|
LZX
|
|
}
|
|
|
|
public static async Task<bool> Compact(this AbsolutePath path, Algorithm algorithm)
|
|
{
|
|
if (!path.Exists) return false;
|
|
|
|
|
|
var exe = GetCompactPath();
|
|
if (exe == null) return false;
|
|
|
|
if (path.IsFile)
|
|
{
|
|
var proc = new ProcessHelper
|
|
{
|
|
Path = exe.Value,
|
|
Arguments = new object[] {"/C", "/EXE:" + algorithm, path},
|
|
ThrowOnNonZeroExitCode = false
|
|
};
|
|
return await proc.Start() == 0;
|
|
}
|
|
else
|
|
{
|
|
var proc = new ProcessHelper
|
|
{
|
|
Path = exe.Value,
|
|
Arguments = new object[] {"/C", "/S", "/EXE:" + algorithm, path},
|
|
ThrowOnNonZeroExitCode = false
|
|
};
|
|
return await proc.Start() == 0;
|
|
}
|
|
}
|
|
}
|
|
}
|