Skip to content

Commit

Permalink
fix(vpkpp): modify language bindings to add new method and fix method…
Browse files Browse the repository at this point in the history
… names
  • Loading branch information
craftablescience committed Jul 18, 2024
1 parent 729d2be commit 280df48
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 31 deletions.
12 changes: 7 additions & 5 deletions lang/c/include/vpkppc/PackFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@ SOURCEPP_API bool vpkpp_has_entry_checksums(vpkpp_pack_file_handle_t handle);
// REQUIRES MANUAL FREE: sourcepp_string_array_free
SOURCEPP_API sourcepp_string_array_t vpkpp_verify_entry_checksums(vpkpp_pack_file_handle_t handle);

SOURCEPP_API bool vpkpp_has_file_checksum(vpkpp_pack_file_handle_t handle);
SOURCEPP_API bool vpkpp_has_pack_file_checksum(vpkpp_pack_file_handle_t handle);

SOURCEPP_API bool vpkpp_verify_file_checksum(vpkpp_pack_file_handle_t handle);
SOURCEPP_API bool vpkpp_verify_pack_file_checksum(vpkpp_pack_file_handle_t handle);

SOURCEPP_API bool vpkpp_has_file_signature(vpkpp_pack_file_handle_t handle);
SOURCEPP_API bool vpkpp_has_pack_file_signature(vpkpp_pack_file_handle_t handle);

SOURCEPP_API bool vpkpp_verify_file_signature(vpkpp_pack_file_handle_t handle);
SOURCEPP_API bool vpkpp_verify_pack_file_signature(vpkpp_pack_file_handle_t handle);

SOURCEPP_API bool vpkpp_is_case_sensitive(vpkpp_pack_file_handle_t handle);

SOURCEPP_API bool vpkpp_has_entry(vpkpp_pack_file_handle_t handle, const char* filename, bool includeUnbaked);

// REQUIRES MANUAL FREE: vpkpp_entry_free
SOURCEPP_API vpkpp_entry_handle_t vpkpp_find_entry(vpkpp_pack_file_handle_t handle, const char* filename, bool includeUnbaked);

Expand All @@ -64,7 +66,7 @@ SOURCEPP_API bool vpkpp_bake(vpkpp_pack_file_handle_t handle, const char* output

SOURCEPP_API bool vpkpp_extract_entry(vpkpp_pack_file_handle_t handle, vpkpp_entry_handle_t entry, const char* filePath);

SOURCEPP_API bool vpkpp_extract_dir(vpkpp_pack_file_handle_t handle, const char* dir, const char* outputDir);
SOURCEPP_API bool vpkpp_extract_directory(vpkpp_pack_file_handle_t handle, const char* dir, const char* outputDir);

SOURCEPP_API bool vpkpp_extract_all(vpkpp_pack_file_handle_t handle, const char* outputDir, bool createUnderPackFileDir);

Expand Down
27 changes: 17 additions & 10 deletions lang/c/src/vpkppc/PackFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,28 @@ SOURCEPP_API sourcepp_string_array_t vpkpp_verify_entry_checksums(vpkpp_pack_fil
return Convert::toStringArray(Convert::packFile(handle)->verifyEntryChecksums());
}

SOURCEPP_API bool vpkpp_has_file_checksum(vpkpp_pack_file_handle_t handle) {
SOURCEPP_API bool vpkpp_has_pack_file_checksum(vpkpp_pack_file_handle_t handle) {
SOURCEPP_EARLY_RETURN_VAL(handle, false);

return Convert::packFile(handle)->hasFileChecksum();
return Convert::packFile(handle)->hasPackFileChecksum();
}

SOURCEPP_API bool vpkpp_verify_file_checksum(vpkpp_pack_file_handle_t handle) {
SOURCEPP_API bool vpkpp_verify_pack_file_checksum(vpkpp_pack_file_handle_t handle) {
SOURCEPP_EARLY_RETURN_VAL(handle, false);

return Convert::packFile(handle)->verifyFileChecksum();
return Convert::packFile(handle)->verifyPackFileChecksum();
}

SOURCEPP_API bool vpkpp_has_file_signature(vpkpp_pack_file_handle_t handle) {
SOURCEPP_API bool vpkpp_has_pack_file_signature(vpkpp_pack_file_handle_t handle) {
SOURCEPP_EARLY_RETURN_VAL(handle, false);

return Convert::packFile(handle)->hasFileSignature();
return Convert::packFile(handle)->hasPackFileSignature();
}

SOURCEPP_API bool vpkpp_verify_file_signature(vpkpp_pack_file_handle_t handle) {
SOURCEPP_API bool vpkpp_verify_pack_file_signature(vpkpp_pack_file_handle_t handle) {
SOURCEPP_EARLY_RETURN_VAL(handle, false);

return Convert::packFile(handle)->verifyFileSignature();
return Convert::packFile(handle)->verifyPackFileSignature();
}

SOURCEPP_API bool vpkpp_is_case_sensitive(vpkpp_pack_file_handle_t handle) {
Expand All @@ -85,6 +85,13 @@ SOURCEPP_API bool vpkpp_is_case_sensitive(vpkpp_pack_file_handle_t handle) {
return Convert::packFile(handle)->isCaseSensitive();
}

SOURCEPP_API bool vpkpp_has_entry(vpkpp_pack_file_handle_t handle, const char* filename, bool includeUnbaked) {
SOURCEPP_EARLY_RETURN_VAL(handle, false);
SOURCEPP_EARLY_RETURN_VAL(filename, false);

return Convert::packFile(handle)->hasEntry(filename, includeUnbaked);
}

SOURCEPP_API vpkpp_entry_handle_t vpkpp_find_entry(vpkpp_pack_file_handle_t handle, const char* filename, bool includeUnbaked) {
SOURCEPP_EARLY_RETURN_VAL(handle, nullptr);
SOURCEPP_EARLY_RETURN_VAL(filename, nullptr);
Expand Down Expand Up @@ -159,12 +166,12 @@ SOURCEPP_API bool vpkpp_extract_entry(vpkpp_pack_file_handle_t handle, vpkpp_ent
return Convert::packFile(handle)->extractEntry(*Convert::entry(entry), filePath);
}

SOURCEPP_API bool vpkpp_extract_dir(vpkpp_pack_file_handle_t handle, const char* dir, const char* outputDir) {
SOURCEPP_API bool vpkpp_extract_directory(vpkpp_pack_file_handle_t handle, const char* dir, const char* outputDir) {
SOURCEPP_EARLY_RETURN_VAL(handle, false);
SOURCEPP_EARLY_RETURN_VAL(dir, false);
SOURCEPP_EARLY_RETURN_VAL(outputDir, false);

return Convert::packFile(handle)->extractDir(dir, outputDir);
return Convert::packFile(handle)->extractDirectory(dir, outputDir);
}

SOURCEPP_API bool vpkpp_extract_all(vpkpp_pack_file_handle_t handle, const char* outputDir, bool createUnderPackFileDir) {
Expand Down
41 changes: 26 additions & 15 deletions lang/csharp/src/vpkpp/PackFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,23 @@ internal static unsafe partial class Extern
public static extern StringArray vpkpp_verify_entry_checksums(void* handle);

[DllImport("vpkppc")]
public static extern byte vpkpp_has_file_checksum(void* handle);
public static extern byte vpkpp_has_pack_file_checksum(void* handle);

[DllImport("vpkppc")]
public static extern byte vpkpp_verify_file_checksum(void* handle);
public static extern byte vpkpp_verify_pack_file_checksum(void* handle);

[DllImport("vpkppc")]
public static extern byte vpkpp_has_file_signature(void* handle);
public static extern byte vpkpp_has_pack_file_signature(void* handle);

[DllImport("vpkppc")]
public static extern byte vpkpp_verify_file_signature(void* handle);
public static extern byte vpkpp_verify_pack_file_signature(void* handle);

[DllImport("vpkppc")]
public static extern byte vpkpp_is_case_sensitive(void* handle);

[DllImport("vpkppc")]
public static extern byte vpkpp_has_entry(void* handle, [MarshalAs(UnmanagedType.LPStr)] string filename, byte includeUnbaked);

[DllImport("vpkppc")]
public static extern void* vpkpp_find_entry(void* handle, [MarshalAs(UnmanagedType.LPStr)] string filename, byte includeUnbaked);

Expand Down Expand Up @@ -68,7 +71,7 @@ internal static unsafe partial class Extern
public static extern byte vpkpp_extract_entry(void* handle, void* entry, [MarshalAs(UnmanagedType.LPStr)] string filePath);

[DllImport("vpkppc")]
public static extern byte vpkpp_extract_dir(void* handle, [MarshalAs(UnmanagedType.LPStr)] string dir, [MarshalAs(UnmanagedType.LPStr)] string outputDir);
public static extern byte vpkpp_extract_directory(void* handle, [MarshalAs(UnmanagedType.LPStr)] string dir, [MarshalAs(UnmanagedType.LPStr)] string outputDir);

[DllImport("vpkppc")]
public static extern byte vpkpp_extract_all(void* handle, [MarshalAs(UnmanagedType.LPStr)] string outputDir, byte createUnderPackFileDir);
Expand Down Expand Up @@ -184,35 +187,43 @@ public IEnumerable<string> VerifyEntryChecksums()
}
}

public bool HasFileChecksum()
public bool HasPackFileChecksum()
{
unsafe
{
return Convert.ToBoolean(Extern.vpkpp_has_pack_file_checksum(Handle));
}
}

public bool VerifyPackFileChecksum()
{
unsafe
{
return Convert.ToBoolean(Extern.vpkpp_has_file_checksum(Handle));
return Convert.ToBoolean(Extern.vpkpp_verify_pack_file_checksum(Handle));
}
}

public bool VerifyFileChecksum()
public bool HasPackFileSignature()
{
unsafe
{
return Convert.ToBoolean(Extern.vpkpp_verify_file_checksum(Handle));
return Convert.ToBoolean(Extern.vpkpp_has_pack_file_signature(Handle));
}
}

public bool HasFileSignature()
public bool VerifyPackFileSignature()
{
unsafe
{
return Convert.ToBoolean(Extern.vpkpp_has_file_signature(Handle));
return Convert.ToBoolean(Extern.vpkpp_verify_pack_file_signature(Handle));
}
}

public bool VerifyFileSignature()
public bool HasEntry(string filename, bool includeUnbaked = true)
{
unsafe
{
return Convert.ToBoolean(Extern.vpkpp_verify_file_signature(Handle));
return Convert.ToBoolean(Extern.vpkpp_has_entry(Handle, filename, Convert.ToByte(includeUnbaked)));
}
}

Expand Down Expand Up @@ -298,11 +309,11 @@ public bool ExtractEntry(Entry entry, string filePath)
}
}

public bool ExtractDir(string dir, string outputDir)
public bool ExtractDirectory(string dir, string outputDir)
{
unsafe
{
return Convert.ToBoolean(Extern.vpkpp_extract_dir(Handle, dir, outputDir));
return Convert.ToBoolean(Extern.vpkpp_extract_directory(Handle, dir, outputDir));
}
}

Expand Down
2 changes: 1 addition & 1 deletion lang/csharp/test/vpkpp.test/PackFileTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void VerifyChecksums()
var vpk = PackFile.Open(BasePortalPath + "portal_pak_dir.vpk");
Assert.IsNotNull(vpk);
Assert.AreEqual(vpk.VerifyEntryChecksums().Count(), 0);
Assert.IsTrue(vpk.VerifyFileChecksum());
Assert.IsTrue(vpk.VerifyPackFileChecksum());
}

[TestMethod]
Expand Down

0 comments on commit 280df48

Please sign in to comment.