mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2026-05-14 23:04:52 +08:00
PR #221 changes
This commit is contained in:
@@ -1436,21 +1436,50 @@ namespace CodeWalker.GameFiles
|
||||
}
|
||||
|
||||
|
||||
public long GetDefragmentedFileSize()
|
||||
public long GetDefragmentedFileSize(bool recursive = true)
|
||||
{
|
||||
//this represents the size the file would be when fully defragmented.
|
||||
uint blockcount = GetHeaderBlockCount();
|
||||
|
||||
foreach (var entry in AllEntries)
|
||||
if (!recursive)
|
||||
{
|
||||
var fentry = entry as RpfFileEntry;
|
||||
if (fentry != null)
|
||||
{
|
||||
blockcount += GetBlockCount(fentry.GetFileSize());
|
||||
}
|
||||
}
|
||||
uint blockcount = GetHeaderBlockCount();
|
||||
|
||||
return (long)blockcount * 512;
|
||||
|
||||
foreach (var entry in AllEntries)
|
||||
{
|
||||
var fentry = entry as RpfFileEntry;
|
||||
if (fentry != null)
|
||||
{
|
||||
blockcount += GetBlockCount(fentry.GetFileSize());
|
||||
}
|
||||
}
|
||||
|
||||
return (long)blockcount * 512;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint blockcount = GetHeaderBlockCount();
|
||||
long childRpfsSize = 0;
|
||||
|
||||
foreach (var entry in AllEntries)
|
||||
{
|
||||
var fentry = entry as RpfFileEntry;
|
||||
if (fentry != null)
|
||||
{
|
||||
var childRpf = this.FindChildArchive(fentry);
|
||||
if (childRpf == null)
|
||||
{
|
||||
blockcount += GetBlockCount(fentry.GetFileSize());
|
||||
}
|
||||
else
|
||||
{
|
||||
childRpfsSize += childRpf.GetDefragmentedFileSize(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (long)blockcount * 512 + childRpfsSize;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1914,10 +1943,25 @@ namespace CodeWalker.GameFiles
|
||||
}
|
||||
|
||||
|
||||
public static void Defragment(RpfFile file, Action<string, float> progress = null)
|
||||
public static void Defragment(RpfFile file, Action<string, float> progress = null, bool recursive = true)
|
||||
{
|
||||
if (file?.AllEntries == null) return;
|
||||
|
||||
if (recursive)
|
||||
{
|
||||
foreach (var entry in file?.AllEntries)
|
||||
{
|
||||
if (entry is RpfFileEntry)
|
||||
{
|
||||
var childRpf = file.FindChildArchive(entry as RpfFileEntry);
|
||||
if (childRpf != null)
|
||||
{
|
||||
Defragment(childRpf, null, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string fpath = file.GetPhysicalFilePath();
|
||||
using (var fstream = File.Open(fpath, FileMode.Open, FileAccess.ReadWrite))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user