mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-27 23:01:55 +00:00
Import code from previous AssetBuilder version
This commit is contained in:
179
src/Utils/Utils.vcxproj
Normal file
179
src/Utils/Utils.vcxproj
Normal file
@ -0,0 +1,179 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Utils\ClassUtils.h" />
|
||||
<ClInclude Include="Utils\FileAPI.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Utils\FileAPI.cpp" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{757FB12A-B410-4B76-B525-2D11A14DAD9D}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>Utils</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<OutDir>$(SolutionDir)lib\$(Configuration)_$(Platform)\</OutDir>
|
||||
<IntDir>$(SolutionDir)obj\$(ProjectName)\$(Configuration)_$(Platform)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<OutDir>$(SolutionDir)lib\$(Configuration)_$(Platform)\</OutDir>
|
||||
<IntDir>$(SolutionDir)obj\$(ProjectName)\$(Configuration)_$(Platform)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<OutDir>$(SolutionDir)lib\$(Configuration)_$(Platform)\</OutDir>
|
||||
<IntDir>$(SolutionDir)obj\$(ProjectName)\$(Configuration)_$(Platform)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<OutDir>$(SolutionDir)lib\$(Configuration)_$(Platform)\</OutDir>
|
||||
<IntDir>$(SolutionDir)obj\$(ProjectName)\$(Configuration)_$(Platform)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<TreatSpecificWarningsAsErrors>4715;%(TreatSpecificWarningsAsErrors)</TreatSpecificWarningsAsErrors>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
<Lib>
|
||||
<AdditionalOptions>/ignore:4221</AdditionalOptions>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<TreatSpecificWarningsAsErrors>4715;%(TreatSpecificWarningsAsErrors)</TreatSpecificWarningsAsErrors>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
<Lib>
|
||||
<AdditionalOptions>/ignore:4221</AdditionalOptions>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<TreatSpecificWarningsAsErrors>4715;%(TreatSpecificWarningsAsErrors)</TreatSpecificWarningsAsErrors>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
<Lib>
|
||||
<AdditionalOptions>/ignore:4221</AdditionalOptions>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<TreatSpecificWarningsAsErrors>4715;%(TreatSpecificWarningsAsErrors)</TreatSpecificWarningsAsErrors>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
<Lib>
|
||||
<AdditionalOptions>/ignore:4221</AdditionalOptions>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
3
src/Utils/Utils/ClassUtils.h
Normal file
3
src/Utils/Utils/ClassUtils.h
Normal file
@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#define STR(x) #x
|
145
src/Utils/Utils/FileAPI.cpp
Normal file
145
src/Utils/Utils/FileAPI.cpp
Normal file
@ -0,0 +1,145 @@
|
||||
#include "FileAPI.h"
|
||||
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
|
||||
bool FileAPI::FileExists(const std::string& fileName)
|
||||
{
|
||||
struct stat st{};
|
||||
|
||||
return stat(fileName.c_str(), &st) >= 0 && !(st.st_mode & S_IFDIR);
|
||||
}
|
||||
|
||||
uint64_t FileAPI::FileSize(const std::string& fileName)
|
||||
{
|
||||
struct stat st{};
|
||||
|
||||
if (stat(fileName.c_str(), &st) >= 0 && !(st.st_mode & S_IFDIR))
|
||||
{
|
||||
return st.st_size;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool FileAPI::DirectoryExists(const std::string& directoryName)
|
||||
{
|
||||
struct stat st{};
|
||||
|
||||
return stat(directoryName.c_str(), &st) >= 0 && st.st_mode & S_IFDIR;
|
||||
}
|
||||
|
||||
FileAPI::File FileAPI::Open(const std::string& filename, const Mode mode)
|
||||
{
|
||||
const char* modeStr;
|
||||
switch(mode)
|
||||
{
|
||||
default:
|
||||
case MODE_READ:
|
||||
modeStr = "rb";
|
||||
break;
|
||||
|
||||
case MODE_WRITE:
|
||||
modeStr = "wb";
|
||||
break;
|
||||
}
|
||||
|
||||
FILE* handle;
|
||||
if (fopen_s(&handle, filename.c_str(), modeStr) != 0)
|
||||
{
|
||||
return File(nullptr);
|
||||
}
|
||||
|
||||
return File(handle);
|
||||
}
|
||||
|
||||
FileAPI::File::File()
|
||||
{
|
||||
this->m_handle = nullptr;
|
||||
}
|
||||
|
||||
FileAPI::File::File(void* handle)
|
||||
{
|
||||
this->m_handle = handle;
|
||||
}
|
||||
|
||||
FileAPI::File::File(File&& f) noexcept
|
||||
{
|
||||
m_handle = f.m_handle;
|
||||
f.m_handle = nullptr;
|
||||
}
|
||||
|
||||
FileAPI::File::~File()
|
||||
{
|
||||
this->Close();
|
||||
}
|
||||
|
||||
FileAPI::File& FileAPI::File::operator=(File&& f) noexcept
|
||||
{
|
||||
m_handle = f.m_handle;
|
||||
f.m_handle = nullptr;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool FileAPI::File::IsOpen() const
|
||||
{
|
||||
return this->m_handle != nullptr;
|
||||
}
|
||||
|
||||
size_t FileAPI::File::Read(void* buffer, const size_t elementSize, const size_t elementCount) const
|
||||
{
|
||||
if (!this->IsOpen())
|
||||
return 0;
|
||||
|
||||
return fread(buffer, elementSize, elementCount, static_cast<FILE*>(m_handle));
|
||||
}
|
||||
|
||||
size_t FileAPI::File::Write(void* data, const size_t elementSize, const size_t elementCount) const
|
||||
{
|
||||
if (!this->IsOpen())
|
||||
return 0;
|
||||
|
||||
return fwrite(data, elementSize, elementCount, static_cast<FILE*>(m_handle));
|
||||
}
|
||||
|
||||
void FileAPI::File::Skip(const size_t amount) const
|
||||
{
|
||||
if(!this->IsOpen())
|
||||
return;
|
||||
|
||||
fseek(static_cast<FILE*>(m_handle), amount, SEEK_CUR);
|
||||
}
|
||||
|
||||
size_t FileAPI::File::Printf(char* fmt, ...) const
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
if (!this->IsOpen())
|
||||
return 0;
|
||||
|
||||
va_start(ap, fmt);
|
||||
const int result = fprintf(static_cast<FILE*>(m_handle), fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int64_t FileAPI::File::Pos() const
|
||||
{
|
||||
return _ftelli64(static_cast<FILE*>(m_handle));
|
||||
}
|
||||
|
||||
void FileAPI::File::Goto(const int64_t pos) const
|
||||
{
|
||||
_fseeki64(static_cast<FILE*>(m_handle), pos, SEEK_SET);
|
||||
}
|
||||
|
||||
void FileAPI::File::Close()
|
||||
{
|
||||
if (this->m_handle != nullptr)
|
||||
{
|
||||
fclose(static_cast<FILE*>(m_handle));
|
||||
this->m_handle = nullptr;
|
||||
}
|
||||
}
|
43
src/Utils/Utils/FileAPI.h
Normal file
43
src/Utils/Utils/FileAPI.h
Normal file
@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
class FileAPI
|
||||
{
|
||||
public:
|
||||
enum Mode
|
||||
{
|
||||
MODE_READ = 0,
|
||||
MODE_WRITE = 1
|
||||
};
|
||||
|
||||
class File
|
||||
{
|
||||
void* m_handle;
|
||||
|
||||
public:
|
||||
File();
|
||||
explicit File(void* handle);
|
||||
File(File&) = delete;
|
||||
File(File&& f) noexcept;
|
||||
~File();
|
||||
|
||||
File& operator=(File&) = delete;
|
||||
File& operator=(File&& f) noexcept;
|
||||
|
||||
bool IsOpen() const;
|
||||
size_t Read(void* buffer, size_t elementSize, size_t elementCount) const;
|
||||
size_t Write(void* data, size_t elementSize, size_t elementCount) const;
|
||||
void Skip(size_t amount) const;
|
||||
size_t Printf(char* fmt, ...) const;
|
||||
int64_t Pos() const;
|
||||
void Goto(int64_t pos) const;
|
||||
void Close();
|
||||
};
|
||||
|
||||
static bool FileExists(const std::string& fileName);
|
||||
static uint64_t FileSize(const std::string& fileName);
|
||||
static bool DirectoryExists(const std::string& directoryName);
|
||||
static File Open(const std::string& filename, Mode mode);
|
||||
};
|
Reference in New Issue
Block a user