update shit

This commit is contained in:
yyc12345 2023-02-10 16:17:17 +08:00
parent 6bda076a1d
commit 6cb47a68c8
8 changed files with 343 additions and 8 deletions

View File

@ -100,7 +100,7 @@
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>LIBCMO_EXPORTING;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>LIBCMO_EXPORTING;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(BOOST_MMAP_INCLUDE_PATH);$(ZLIB_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(BOOST_INCLUDE_PATH);$(ZLIB_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard> <LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile> </ClCompile>
<Link> <Link>
@ -118,7 +118,7 @@
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>LIBCMO_EXPORTING;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>LIBCMO_EXPORTING;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(BOOST_MMAP_INCLUDE_PATH);$(ZLIB_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(BOOST_INCLUDE_PATH);$(ZLIB_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard> <LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile> </ClCompile>
<Link> <Link>
@ -136,7 +136,7 @@
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>LIBCMO_EXPORTING;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>LIBCMO_EXPORTING;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(BOOST_MMAP_INCLUDE_PATH);$(ZLIB_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(BOOST_INCLUDE_PATH);$(ZLIB_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard> <LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile> </ClCompile>
<Link> <Link>
@ -154,7 +154,7 @@
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>LIBCMO_EXPORTING;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>LIBCMO_EXPORTING;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(BOOST_MMAP_INCLUDE_PATH);$(ZLIB_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(BOOST_INCLUDE_PATH);$(ZLIB_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard> <LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile> </ClCompile>
<Link> <Link>
@ -168,9 +168,11 @@
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="VTReader.cpp" /> <ClCompile Include="VTReader.cpp" />
<ClCompile Include="VTStruct.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="VTConstants.hpp" /> <ClInclude Include="VTConstants.hpp" />
<ClInclude Include="VTEncoding.hpp" />
<ClInclude Include="VTReader.hpp" /> <ClInclude Include="VTReader.hpp" />
<ClInclude Include="VTStruct.hpp" /> <ClInclude Include="VTStruct.hpp" />
<ClInclude Include="VTUtils.hpp" /> <ClInclude Include="VTUtils.hpp" />

View File

@ -18,6 +18,9 @@
<ClCompile Include="VTReader.cpp"> <ClCompile Include="VTReader.cpp">
<Filter>Sources</Filter> <Filter>Sources</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="VTStruct.cpp">
<Filter>Sources</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="VTReader.hpp"> <ClInclude Include="VTReader.hpp">
@ -32,5 +35,8 @@
<ClInclude Include="VTUtils.hpp"> <ClInclude Include="VTUtils.hpp">
<Filter>Headers</Filter> <Filter>Headers</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="VTEncoding.hpp">
<Filter>Headers</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -4,6 +4,8 @@
#include <cstdint> #include <cstdint>
#include <cstdarg> #include <cstdarg>
#include <type_traits> #include <type_traits>
#include <string>
#include <vector>
namespace LibCmo { namespace LibCmo {
@ -25,6 +27,16 @@ namespace LibCmo {
} }
using CK_ID = uint32_t; using CK_ID = uint32_t;
using CKDWORD = uint32_t;
using CKBOOL = int32_t;
using XString = std::string;
using XBitArray = std::vector<bool>;
template<typename T>
using XArray = std::vector<T>;
using XIntArray = std::vector<int32_t>;
template<typename T>
using XClassArray = std::vector<T*>;
enum class CK_CLASSID : uint32_t { enum class CK_CLASSID : uint32_t {
CKCID_OBJECT = 1, CKCID_OBJECT = 1,

118
LibCmo/VTEncoding.hpp Normal file
View File

@ -0,0 +1,118 @@
#pragma once
#include <string>
#if defined(_WIN32)
#define LIBCMO_OS_WIN32
#endif
#if defined(LIBCMO_OS_WIN32)
#include <Windows.h>
#else
#include <iconv.h>
#endif
namespace LibCmo {
namespace Encoding {
#pragma region assist functions
#if defined(LIBCMO_OS_WIN32)
#define LIBCMO_STR_EQUAL(a, b) strcmp(reinterpret_cast<const char*>(a), reinterpret_cast<const char*>(b)) == 0
bool GetWindowsCodePage(const char* u8_encoding_spec, UINT* result) {
if (LIBCMO_STR_EQUAL(u8_encoding_spec, u8"CP_ACP")) *result = CP_ACP;
else if (LIBCMO_STR_EQUAL(u8_encoding_spec, u8"CP_MACCP")) *result = CP_MACCP;
else if (LIBCMO_STR_EQUAL(u8_encoding_spec, u8"CP_OEMCP")) *result = CP_OEMCP;
else if (LIBCMO_STR_EQUAL(u8_encoding_spec, u8"CP_THREAD_ACPP")) *result = CP_THREAD_ACP;
else if (LIBCMO_STR_EQUAL(u8_encoding_spec, u8"CP_UTF8")) *result = CP_UTF8;
else {
char* pend = nullptr;
errno = 0;
uint64_t v = std::strtoull(u8_encoding_spec, &pend, 10);
if (pend == u8_encoding_spec || errno == ERANGE) return false;
*result = static_cast<UINT>(v);
}
return true;
}
#undef LIBCMO_STR_EQUAL
bool WcharToChar(const wchar_t* src, std::string& dest, UINT codepage) {
int count, write_result;
//converter to CHAR
count = WideCharToMultiByte(CP_UTF8, 0, src, -1, NULL, 0, NULL, NULL);
if (count <= 0) return false;
dest.resize(count);
write_result = WideCharToMultiByte(CP_UTF8, 0, src, -1, dest.data(), count, NULL, NULL);
if (write_result <= 0) return false;
return true;
}
bool WcharToChar(std::wstring& src, std::string& dest, UINT codepage) {
return WcharToChar(src.c_str(), dest, codepage);
}
bool CharToWchar(const char* src, std::wstring& dest, UINT codepage) {
int wcount, write_result;
// convert to WCHAR
wcount = MultiByteToWideChar(codepage, 0, src, -1, NULL, 0);
if (wcount <= 0) return false;
dest.resize(wcount);
write_result = MultiByteToWideChar(CP_UTF8, 0, src, -1, dest.data(), wcount);
if (write_result <= 0) return false;
return true;
}
bool CharToWchar(std::string& src, std::wstring& dest, UINT codepage) {
return CharToWchar(src.c_str(), dest, codepage);
}
#else
//todo: linux implementation
#endif
#pragma endregion
#pragma region core functions
#if defined(LIBCMO_OS_WIN32)
void GetUtf8VirtoolsName(std::string& native_name, std::string& u8_name, const char* u8_encoding_spec) {
// switch encoding spec
UINT codepage = CP_ACP;
if (!GetWindowsCodePage(u8_encoding_spec, &codepage)) {
u8_name = native_name.c_str();
return;
}
// do convert
std::wstring intermediary;
if (!CharToWchar(native_name, intermediary, codepage)) {
u8_name = native_name.c_str();
return;
}
if (!WcharToChar(intermediary, u8_name, CP_UTF8)) {
u8_name = native_name.c_str();
return;
}
return;
}
#else
//todo: linux implementation
#error NO IMPLEMENTATION FOR LINUX ENCODING!
#endif
#pragma endregion
}
}

56
LibCmo/VTStruct.cpp Normal file
View File

@ -0,0 +1,56 @@
#include "VTStruct.hpp"
namespace LibCmo {
VxMemoryMappedFile::VxMemoryMappedFile(const char* u8_filepath) :
m_szFilePath(),
m_hFile(nullptr), m_hFileMapping(nullptr),
m_bIsValid(false) {
// save file path and set region option
boost::interprocess::map_options_t region_option;
#if defined(LIBCMO_OS_WIN32)
Encoding::CharToWchar(u8_filepath, this->m_szFilePath, CP_UTF8);
region_option = FILE_MAP_READ;
#else
this->m_szFilePath = u8_filepath;
region_option = boost::interprocess::default_map_options;
#endif
// open file
this->m_hFile = new boost::interprocess::file_mapping(
this->m_szFilePath.c_str(), boost::interprocess::read_only
);
// open region
this->m_hFileMapping = new boost::interprocess::mapped_region(
this->m_hFile, boost::interprocess::read_only,
0, 0, nullptr,
region_option
);
// set valid
this->m_bIsValid = true;
}
VxMemoryMappedFile::~VxMemoryMappedFile(void) {
this->m_bIsValid = false;
delete this->m_hFileMapping;
boost::interprocess::file_mapping::remove(this->m_szFilePath.c_str());
delete this->m_hFile;
}
void* VxMemoryMappedFile::GetBase(void) { return this->m_hFileMapping->get_address(); }
size_t VxMemoryMappedFile::GetFileSize(void) { return this->m_hFileMapping->get_size(); }
bool VxMemoryMappedFile::IsValid(void) { return this->m_bIsValid; }
CKFile::CKFile() {
}
CKFile::~CKFile() {
}
}

View File

@ -1 +1,142 @@
#pragma once #pragma once
#include "VTConstants.hpp"
#include "VTEncoding.hpp"
#include <vector>
// only expose boost in libcom self. do not let it be seen by any program using libcmo.
#if defined(LIBCMO_EXPORTING)
#include <boost/interprocess/file_mapping.hpp>
#include <boost/interprocess/mapped_region.hpp>
#endif
namespace LibCmo {
struct CKGUID {
union {
struct {
CKDWORD d1, d2;
};
CKDWORD d[2];
};
CKGUID(CKDWORD gd1 = 0, CKDWORD gd2 = 0) { d[0] = gd1; d[1] = gd2; }
};
// define some mapped file to make boost is invisible for
// any program using this library
#if defined(LIBCMO_EXPORTING)
using P_FILE_MAPPING = boost::interprocess::file_mapping*;
using P_MAPPED_REGION = boost::interprocess::mapped_region*;
#else
using P_FILE_MAPPING = void*;
using P_MAPPED_REGION = void*;
#endif
class VxMemoryMappedFile {
public:
VxMemoryMappedFile(const char* u8_filepath);
~VxMemoryMappedFile(void);
void* GetBase(void);
size_t GetFileSize(void);
bool IsValid(void);
private:
#if defined(LIBCMO_OS_WIN32)
std::wstring m_szFilePath;
#else
std::string m_szFilePath;
#endif
P_FILE_MAPPING m_hFile;
P_MAPPED_REGION m_hFileMapping;
bool m_bIsValid;
};
class CKBufferParser {
private:
char* m_ReaderBegin;
size_t m_ReaderPos;
bool m_NeedManualFree;
size_t m_ReaderSize;
public:
CKBufferParser(void* ptr, size_t rsize, bool need_manual_free) :
m_ReaderBegin(static_cast<char*>(ptr)),
m_ReaderPos(0u), m_ReaderSize(rsize),
m_NeedManualFree(need_manual_free) {
;
}
~CKBufferParser() {
if (this->m_NeedManualFree) free(this->m_ReaderBegin);
}
inline void* GetPtr(void) { return (this->m_ReaderBegin + m_ReaderPos); }
inline size_t GetSize(void) { return this->m_ReaderSize; }
inline void MoveCursor(size_t off) { this->m_ReaderPos += off; }
inline void SetCursor(size_t off) { this->m_ReaderPos = off; }
};
struct CKFileInfo {
CKDWORD ProductVersion; // Virtools Version (Dev/Creation). (CK_VIRTOOLS_VERSION)
CKDWORD ProductBuild; // Virtools Build Number.
CK_FILE_WRITEMODE FileWriteMode; // Options used to save this file. (CK_FILE_WRITEMODE)
CKDWORD FileVersion; // Version of file format when file was saved.
CKDWORD CKVersion; // Version of CK when file was saved.
CKDWORD FileSize; // Size of file in bytes.
CKDWORD ObjectCount; // Number of objects stored in the file.
CKDWORD ManagerCount; // Number of managers which saved data in the file.
CKDWORD MaxIDSaved; // Maximum Object identifier saved
CKDWORD Crc; // Crc of data
CKDWORD Hdr1PackSize; // Reserved
CKDWORD Hdr1UnPackSize; // Reserved
CKDWORD DataPackSize; // Reserved
CKDWORD DataUnPackSize; // Reserved
};
struct CKFileObject {
CK_ID Object;
CK_ID CreatedObject;
CK_CLASSID ObjectCid;
void* ObjPtr;
std::string Name;
void* Data;
CKDWORD PostPackSize;
CKDWORD PrePackSize;
CK_FO_OPTIONS Options;
CKDWORD FileIndex;
CK_FILE_WRITEMODE SaveFlags;
};
struct CKFilePluginDependencies {
CKDWORD m_PluginCategory;
XArray<CKGUID> m_Guids;
XBitArray ValidGuids;
};
class CKFile {
public:
CKFile();
~CKFile();
int32_t m_SaveIDMax;
XArray<CKFileObject> m_FileObject;
//XArray<CKFileManagerData> m_ManagersData;
XClassArray<CKFilePluginDependencies> m_PluginDep;
//XClassArray<XIntArray> m_IndexByClassId;
//XClassArray<XString> m_IncludedFiles;
CKFileInfo m_FileInfo;
CK_LOAD_FLAGS m_Flags;
std::string m_FileName;
CKBufferParser* m_Parser;
VxMemoryMappedFile* m_MappedFile;
bool m_ReadFileDataDone;
};
}

View File

@ -2,7 +2,7 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" /> <ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros"> <PropertyGroup Label="UserMacros">
<BOOST_MMAP_INCLUDE_PATH>D:\CppLib\interprocess-boost-1.81.0\include</BOOST_MMAP_INCLUDE_PATH> <BOOST_INCLUDE_PATH>D:\CppLib\boost_1_81_0</BOOST_INCLUDE_PATH>
<SQLITE_HEADER_PATH>D:\CppLib\SQLite\sqlite-amalgamation-3400100</SQLITE_HEADER_PATH> <SQLITE_HEADER_PATH>D:\CppLib\SQLite\sqlite-amalgamation-3400100</SQLITE_HEADER_PATH>
<SQLITE_WIN32_LIB_PATH>D:\CppLib\SQLite\sqlite-dll-win32-x86-3400100</SQLITE_WIN32_LIB_PATH> <SQLITE_WIN32_LIB_PATH>D:\CppLib\SQLite\sqlite-dll-win32-x86-3400100</SQLITE_WIN32_LIB_PATH>
@ -13,8 +13,8 @@
<PropertyGroup /> <PropertyGroup />
<ItemDefinitionGroup /> <ItemDefinitionGroup />
<ItemGroup> <ItemGroup>
<BuildMacro Include="BOOST_MMAP_INCLUDE_PATH"> <BuildMacro Include="BOOST_INCLUDE_PATH">
<Value>$(BOOST_MMAP_INCLUDE_PATH)</Value> <Value>$(BOOST_INCLUDE_PATH)</Value>
</BuildMacro> </BuildMacro>
<BuildMacro Include="SQLITE_HEADER_PATH"> <BuildMacro Include="SQLITE_HEADER_PATH">