-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vpkpp: add support for 007 format (closes #45)
- Loading branch information
1 parent
0f60123
commit 32c9f8d
Showing
11 changed files
with
324 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#pragma once | ||
|
||
#include <array> | ||
|
||
#include "../PackFile.h" | ||
|
||
namespace vpkpp { | ||
|
||
constexpr std::string_view OO7_EXTENSION = ".007"; | ||
|
||
class OO7 : public PackFileReadOnly { | ||
public: | ||
/// Open a 007 file | ||
[[nodiscard]] static std::unique_ptr<PackFile> open(const std::string& path, const EntryCallback& callback = nullptr); | ||
|
||
static constexpr inline std::string_view GUID = "7E4766FD0F7340069AA923C9D3DAB37B"; | ||
|
||
[[nodiscard]] constexpr std::string_view getGUID() const override { | ||
return OO7::GUID; | ||
} | ||
|
||
[[nodiscard]] bool hasPackFileChecksum() const override; | ||
|
||
[[nodiscard]] bool verifyPackFileChecksum() const override; | ||
|
||
[[nodiscard]] constexpr bool isCaseSensitive() const override { | ||
return true; | ||
} | ||
|
||
[[nodiscard]] std::optional<std::vector<std::byte>> readEntry(const std::string& path_) const override; | ||
|
||
[[nodiscard]] Attribute getSupportedEntryAttributes() const override; | ||
|
||
[[nodiscard]] explicit operator std::string() const override; | ||
|
||
protected: | ||
using PackFileReadOnly::PackFileReadOnly; | ||
|
||
uint32_t majorVersion{}; | ||
uint32_t minorVersion{}; | ||
bool hasChecksum = false; | ||
std::array<std::byte, 16> checksum{}; | ||
|
||
private: | ||
VPKPP_REGISTER_PACKFILE_OPEN(OO7_EXTENSION, &OO7::open); | ||
}; | ||
|
||
} // namespace vpkpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
|
||
#include "../PackFile.h" | ||
|
||
// REQUIRES MANUAL FREE: vpkpp_close | ||
SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_007_open(const char* path, vpkpp_entry_callback_t callback); | ||
|
||
// REQUIRES MANUAL FREE: sourcepp_string_free | ||
SOURCEPP_API sourcepp_string_t vpkpp_007_guid(vpkpp_pack_file_handle_t handle); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <vpkppc/format/OO7.h> | ||
|
||
#include <vpkpp/format/OO7.h> | ||
|
||
#include <sourceppc/Convert.hpp> | ||
#include <sourceppc/Helpers.h> | ||
|
||
using namespace vpkpp; | ||
|
||
SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_007_open(const char* path, vpkpp_entry_callback_t callback) { | ||
SOURCEPP_EARLY_RETURN_VAL(path, nullptr); | ||
|
||
auto packFile = OO7::open(path, callback ? [callback](const std::string& path, const Entry& entry) { | ||
callback(path.c_str(), const_cast<Entry*>(&entry)); | ||
} : static_cast<PackFile::EntryCallback>(nullptr)); | ||
if (!packFile) { | ||
return nullptr; | ||
} | ||
return packFile.release(); | ||
} | ||
|
||
// REQUIRES MANUAL FREE: sourcepp_string_free | ||
SOURCEPP_API sourcepp_string_t vpkpp_007_guid(vpkpp_pack_file_handle_t handle) { | ||
SOURCEPP_EARLY_RETURN_VAL(handle, SOURCEPP_STRING_INVALID); | ||
|
||
return Convert::toString(OO7::GUID); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace vpkpp.Format | ||
{ | ||
using EntryCallback = Action<string, Entry>; | ||
|
||
internal static unsafe partial class Extern | ||
{ | ||
internal static unsafe partial class OO7 | ||
{ | ||
[LibraryImport("vpkppc", EntryPoint = "vpkpp_007_open")] | ||
public static partial void* Open([MarshalAs(UnmanagedType.LPStr)] string path, IntPtr callback); | ||
|
||
[LibraryImport("vpkppc", EntryPoint = "vpkpp_007_guid")] | ||
public static partial sourcepp.String GUID(); | ||
} | ||
} | ||
|
||
public class OO7 : PackFile | ||
{ | ||
private protected unsafe OO7(void* handle) : base(handle) {} | ||
|
||
public new static OO7? Open(string path) | ||
{ | ||
unsafe | ||
{ | ||
var handle = Extern.OO7.Open(path, 0); | ||
return handle == null ? null : new OO7(handle); | ||
} | ||
} | ||
|
||
public new static OO7? Open(string path, EntryCallback callback) | ||
{ | ||
unsafe | ||
{ | ||
EntryCallbackNative callbackNative = (path, entry) => | ||
{ | ||
callback(path, new Entry(entry, true)); | ||
}; | ||
var handle = Extern.OO7.Open(path, Marshal.GetFunctionPointerForDelegate(callbackNative)); | ||
return handle == null ? null : new OO7(handle); | ||
} | ||
} | ||
|
||
public static string GUID | ||
{ | ||
get | ||
{ | ||
unsafe | ||
{ | ||
var str = Extern.OO7.GUID(); | ||
return sourcepp.StringUtils.ConvertToStringAndDelete(ref str); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.