Skip to content

Commit

Permalink
Add support for deleted files in PAKs
Browse files Browse the repository at this point in the history
  • Loading branch information
Norbyte committed Jul 22, 2021
1 parent 2cbce96 commit ed3576b
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
4 changes: 2 additions & 2 deletions ConverterApp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.15.8.0")]
[assembly: AssemblyFileVersion("1.15.8.0")]
[assembly: AssemblyVersion("1.15.9.0")]
[assembly: AssemblyFileVersion("1.15.9.0")]
2 changes: 1 addition & 1 deletion Divine/CLI/CommandLinePackageProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private static void ExtractSingleFile(string packagePath, string destinationPath
{
Package package = reader.Read();
// Try to match by full path
AbstractFileInfo file = package.Files.Find(fileInfo => string.Compare(fileInfo.Name, packagedPath, StringComparison.OrdinalIgnoreCase) == 0);
AbstractFileInfo file = package.Files.Find(fileInfo => string.Compare(fileInfo.Name, packagedPath, StringComparison.OrdinalIgnoreCase) == 0 && !fileInfo.IsDeletion());
if (file == null)
{
// Try to match by filename only
Expand Down
2 changes: 1 addition & 1 deletion LSLib/LS/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static class Common

public const int MinorVersion = 15;

public const int PatchVersion = 8;
public const int PatchVersion = 9;

/// <summary>
/// Returns the version number of the LSLib library
Expand Down
2 changes: 2 additions & 0 deletions LSLib/LS/Mods/ModResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ private void AddLevelObjectsToMod(string modName, string path, AbstractFileInfo

private void DiscoverPackagedFile(AbstractFileInfo file)
{
if (file.IsDeletion()) return;

if (file.Name.EndsWith("meta.lsx", StringComparison.Ordinal))
{
var match = metaRe.Match(file.Name);
Expand Down
23 changes: 23 additions & 0 deletions LSLib/LS/PackageCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public abstract class AbstractFileInfo
public abstract UInt32 CRC();
public abstract Stream MakeStream();
public abstract void ReleaseStream();
public abstract bool IsDeletion();
}


Expand Down Expand Up @@ -238,6 +239,11 @@ public void Dispose()

public override Stream MakeStream()
{
if (IsDeletion())
{
throw new InvalidOperationException("Cannot open file stream for a deleted file");
}

if (_uncompressedStream != null)
{
return _uncompressedStream;
Expand Down Expand Up @@ -447,6 +453,11 @@ internal FileEntry15 MakeEntryV15()

return entry;
}

public override bool IsDeletion()
{
return OffsetInFile == 0xdeadbeefdeadbeef;
}
}

public class FilesystemFileInfo : AbstractFileInfo, IDisposable
Expand Down Expand Up @@ -488,6 +499,11 @@ public static FilesystemFileInfo CreateFromEntry(string filesystemPath, string n
info.CachedSize = fsInfo.Length;
return info;
}

public override bool IsDeletion()
{
return false;
}
}

public class StreamFileInfo : AbstractFileInfo
Expand All @@ -513,6 +529,11 @@ public static StreamFileInfo CreateFromStream(Stream stream, string name)
};
return info;
}

public override bool IsDeletion()
{
return false;
}
}

public class Package
Expand Down Expand Up @@ -583,6 +604,8 @@ public void UncompressPackage(Package package, string outputPath, Func<AbstractF
ProgressUpdate(file.Name, currentSize, totalSize, file);
currentSize += (long)file.Size();

if (file.IsDeletion()) continue;

string outPath = outputPath + file.Name;

FileManager.TryToCreateDirectory(outPath);
Expand Down
4 changes: 2 additions & 2 deletions LSLib/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.15.8.0")]
[assembly: AssemblyFileVersion("1.15.8.0")]
[assembly: AssemblyVersion("1.15.9.0")]
[assembly: AssemblyFileVersion("1.15.9.0")]

0 comments on commit ed3576b

Please sign in to comment.