Implemented filesystem handling functions in Common

This commit is contained in:
parax0 2016-05-18 20:59:01 -06:00
parent b362a23e4b
commit 3009f06d11
27 changed files with 445 additions and 279 deletions

View File

@ -1,5 +1,9 @@
# CONFIG += PUBLIC_RELEASE
BUILD_DIR = $$PWD/../build
EXTERNALS_DIR = $$PWD/../externals
PWE_MAIN_INCLUDE = $$PWD
DEFINES += 'APP_NAME=\"\\\"Prime World Editor\\\"\"' \
'APP_VERSION=\"\\\"1.1.0\\\"\"'

View File

@ -6,6 +6,18 @@
#include <cstdlib>
#include <string.h>
/* This header declares a macro, ASSERT(Expression). ASSERT evaluates the input expression and verifies that
* it is true. If the expression is false, an error message will be printed to the log with info on what went
* wrong and (in debug builds) trigger a debug break. Application execution is not aborted, but if an assert
* fails then there is usually a decent chance of the application crashing regardless.
*
* Note that in public release builds, asserts are compiled out entirely, so neither log messages nor debug breaks
* will occur.
*
* There are two other macros defined which can be useful for debugging, but shouldn't be used as permanent error
* checks: BREAK_ONLY_ASSERT, which doesn't write the error to the log, and LOG_ONLY_ASSERT, which doesn't trigger
* a debug break.
*/
#define __FILE_SHORT__ strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__
#if _DEBUG

View File

@ -10,7 +10,7 @@ DEFINES += PWE_COMMON
CONFIG += staticlib
TEMPLATE = lib
DESTDIR = $$PWD/../../build/Common
DESTDIR = $$BUILD_DIR/Common
unix {
target.path = /usr/lib
@ -19,40 +19,43 @@ unix {
CONFIG (debug, debug|release) {
# Debug Config
OBJECTS_DIR = $$PWD/../../build/Common/debug
OBJECTS_DIR = $$BUILD_DIR/Common/debug
TARGET = Commond
# Debug Libs
LIBS += -L$$PWD/../../build/FileIO/ -lFileIOd
LIBS += -L$$BUILD_DIR/FileIO/ -lFileIOd \
-L$$EXTERNALS_DIR/boost_1_56_0/lib32-msvc-12.0 -llibboost_filesystem-vc120-mt-gd-1_56
# Debug Target Dependencies
win32 {
PRE_TARGETDEPS += $$PWD/../../build/FileIO/FileIOd.lib
PRE_TARGETDEPS += $$BUILD_DIR/FileIO/FileIOd.lib
}
}
CONFIG (release, debug|release) {
# Release Config
OBJECTS_DIR = $$PWD/../../build/Common/release
OBJECTS_DIR = $$BUILD_DIR/build/Common/release
TARGET = Common
# Release Libs
LIBS += -L$$PWD/../../build/FileIO/ -lFileIO
LIBS += -L$$BUILD_DIR/FileIO/ -lFileIO \
-L$$EXTERNALS_DIR/boost_1_56_0/lib32-msvc-12.0 -llibboost_filesystem-vc120-mt-1_56
# Release Target Dependencies
win32 {
PRE_TARGETDEPS += $$PWD/../../build/FileIO/FileIO.lib
PRE_TARGETDEPS += $$BUILD_DIR/FileIO/FileIO.lib
}
}
# Debug/Release Libs
LIBS += -L$$PWD/../../externals/lzo-2.08/lib -llzo-2.08 \
-L$$PWD/../../externals/zlib/lib -lzdll
LIBS += -L$$EXTERNALS_DIR/lzo-2.08/lib -llzo-2.08 \
-L$$EXTERNALS_DIR/zlib/lib -lzdll
# Include Paths
INCLUDEPATH += $$PWD/.. \
$$PWD/../../externals/lzo-2.08/include \
$$PWD/../../externals/zlib/include
INCLUDEPATH += $$PWE_MAIN_INCLUDE \
$$EXTERNALS_DIR/boost_1_56_0 \
$$EXTERNALS_DIR/lzo-2.08/include \
$$EXTERNALS_DIR/zlib/include
# Header Files
HEADERS += \
@ -69,7 +72,8 @@ HEADERS += \
TString.h \
types.h \
Log.h \
Assert.h
FileUtil.h \
AssertMacro.h
# Source Files
SOURCES += \
@ -78,4 +82,5 @@ SOURCES += \
CTimer.cpp \
CUniqueID.cpp \
TString.cpp \
Log.cpp
Log.cpp \
FileUtil.cpp

237
src/Common/FileUtil.cpp Normal file
View File

@ -0,0 +1,237 @@
#include "FileUtil.h"
#include "AssertMacro.h"
#include <boost/filesystem.hpp>
#include <boost/system/error_code.hpp>
// These are mostly just wrappers around boost::filesystem functions.
using namespace boost::filesystem;
namespace FileUtil
{
bool Exists(const TWideString &rkFilePath)
{
return exists(*rkFilePath);
}
bool IsRoot(const TWideString& rkPath)
{
// todo: verify that this is actually a good way of checking for root
TWideString AbsPath = MakeAbsolute(rkPath);
TWideStringList Split = AbsPath.Split(L"\\/");
return (Split.size() <= 1);
}
bool IsFile(const TWideString& rkFilePath)
{
return is_regular_file(*rkFilePath);
}
bool IsDirectory(const TWideString& rkDirPath)
{
return is_directory(*rkDirPath);
}
bool CreateDirectory(const TWideString& rkNewDir)
{
return create_directories(*rkNewDir);
}
bool CopyFile(const TWideString& rkOrigPath, const TWideString& rkNewPath)
{
boost::system::error_code Error;
copy(*rkOrigPath, *rkNewPath, Error);
return (Error == boost::system::errc::success);
}
bool CopyDirectory(const TWideString& rkOrigPath, const TWideString& rkNewPath)
{
boost::system::error_code Error;
copy_directory(*rkOrigPath, *rkNewPath, Error);
return (Error == boost::system::errc::success);
}
bool MoveFile(const TWideString& rkOldPath, const TWideString& rkNewPath)
{
if (CopyFile(rkOldPath, rkNewPath))
return DeleteFile(rkOldPath);
else
return false;
}
bool MoveDirectory(const TWideString& rkOldPath, const TWideString& rkNewPath)
{
if (CopyDirectory(rkOldPath, rkNewPath))
return DeleteDirectory(rkOldPath);
else
return false;
}
bool DeleteFile(const TWideString& rkFilePath)
{
if (!IsFile(rkFilePath)) return false;
return remove(*rkFilePath) == 1;
}
bool DeleteDirectory(const TWideString& rkDirPath)
{
if (!IsDirectory(rkDirPath)) return false;
// Sanity check - don't delete root
bool Root = IsRoot(rkDirPath);
if (Root)
{
ASSERT(false);
Log::Error("Attempted to delete root directory!");
return false;
}
boost::system::error_code Error;
remove_all(*rkDirPath, Error);
return (Error == boost::system::errc::success);
}
bool ClearDirectory(const TWideString& rkDirPath)
{
if (!IsDirectory(rkDirPath)) return false;
// Sanity check - don't clear root
bool Root = IsRoot(rkDirPath);
if (Root)
{
ASSERT(false);
Log::Error("Attempted to clear root directory!");
return false;
}
// Delete directory contents
TWideStringList DirContents;
GetDirectoryContents(rkDirPath, DirContents, false);
for (auto It = DirContents.begin(); It != DirContents.end(); It++)
{
bool Success = false;
if (IsFile(*It))
Success = DeleteFile(*It);
else if (IsDirectory(*It))
Success = DeleteDirectory(*It);
if (!Success)
Log::Error("Failed to delete filesystem object: " + TWideString(*It).ToUTF8());
}
return true;
}
int FileSize(const TWideString &rkFilePath)
{
return (int) (Exists(*rkFilePath) ? file_size(*rkFilePath) : -1);
}
TWideString WorkingDirectory()
{
return boost::filesystem::current_path().string();
}
TWideString MakeAbsolute(TWideString Path)
{
if (!boost::filesystem::path(*Path).has_root_name())
Path = WorkingDirectory() + L"\\" + Path;
TWideStringList Components = Path.Split(L"/\\");
TWideStringList::iterator Prev;
for (TWideStringList::iterator Iter = Components.begin(); Iter != Components.end(); Iter++)
{
if (*Iter == L".")
Iter = Components.erase(Iter);
else if (*Iter == L"..")
Iter = std::prev(Components.erase(Prev, std::next(Iter)));
Prev = Iter;
}
TWideString Out;
for (auto it = Components.begin(); it != Components.end(); it++)
Out += *it + L"\\";
return Out;
}
TWideString MakeRelative(const TWideString& rkPath, const TWideString& rkRelativeTo /*= WorkingDirectory()*/)
{
TWideString AbsPath = MakeAbsolute(rkPath);
TWideString AbsRelTo = MakeAbsolute(rkRelativeTo);
TWideStringList PathComponents = AbsPath.Split(L"/\\");
TWideStringList RelToComponents = AbsRelTo.Split(L"/\\");
// Find furthest common parent
TWideStringList::iterator PathIter = PathComponents.begin();
TWideStringList::iterator RelToIter = RelToComponents.begin();
for (; PathIter != PathComponents.end() && RelToIter != RelToComponents.end(); PathIter++, RelToIter++)
{
if (*PathIter != *RelToIter)
break;
}
// If there's no common components, then we can't construct a relative path...
if (PathIter == PathComponents.begin())
return AbsPath;
// Construct output path
TWideString Out;
for (; RelToIter != RelToComponents.end(); RelToIter++)
Out += L"..\\";
for (; PathIter != PathComponents.end(); PathIter++)
Out += *PathIter + L"\\";
return Out;
}
void GetDirectoryContents(TWideString DirPath, TWideStringList& rOut, bool Recursive /*= true*/, bool IncludeFiles /*= true*/, bool IncludeDirs /*= true*/)
{
if (IsDirectory(DirPath))
{
DirPath.Replace(L"/", L"\\");
bool IncludeAll = IncludeFiles && IncludeDirs;
auto AddFileLambda = [IncludeFiles, IncludeDirs, IncludeAll, &rOut](std::wstring Path) -> void {
bool ShouldAddFile = IncludeAll || (IncludeFiles && IsFile(Path)) || (IncludeDirs && IsDirectory(Path));
if (ShouldAddFile)
rOut.push_back(Path);
};
if (Recursive)
{
for (recursive_directory_iterator It(*DirPath); It != recursive_directory_iterator(); ++It)
{
#ifdef _WIN32
AddFileLambda( It->path().native() );
#else
AddFileLambda( TString(It->path().native()).ToUTF16().ToStdString() );
#endif
}
}
else
{
for (directory_iterator It(*DirPath); It != directory_iterator(); ++It)
{
#ifdef _WIN32
AddFileLambda( It->path().native() );
#else
AddFileLambda( TString(It->path().native()).ToUTF16().ToStdString() );
#endif
}
}
}
}
}

31
src/Common/FileUtil.h Normal file
View File

@ -0,0 +1,31 @@
#ifndef FILEUTIL
#define FILEUTIL
#include "Flags.h"
#include "TString.h"
namespace FileUtil
{
bool Exists(const TWideString& rkFilePath);
bool IsRoot(const TWideString& rkPath);
bool IsFile(const TWideString& rkFilePath);
bool IsDirectory(const TWideString& rkDirPath);
bool CreateDirectory(const TWideString& rkNewDir);
bool CopyFile(const TWideString& rkOrigPath, const TWideString& rkNewPath);
bool CopyDirectory(const TWideString& rkOrigPath, const TWideString& rkNewPath);
bool MoveFile(const TWideString& rkOldPath, const TWideString& rkNewPath);
bool MoveDirectory(const TWideString& rkOldPath, const TWideString& rkNewPath);
bool DeleteFile(const TWideString& rkFilePath);
bool DeleteDirectory(const TWideString& rkDirPath);
bool ClearDirectory(const TWideString& rkDirPath);
int FileSize(const TWideString& rkFilePath);
TWideString WorkingDirectory();
TWideString MakeAbsolute(TWideString Path);
TWideString MakeRelative(const TWideString& rkPath, const TWideString& rkRelativeTo = WorkingDirectory());
void GetDirectoryContents(TWideString DirPath, TWideStringList& rOut, bool Recursive = true, bool IncludeFiles = true, bool IncludeDirs = true);
}
#endif // FILEUTIL

View File

@ -1,5 +1,7 @@
#include "TString.h"
#include <FileIO/IOUtil.h>
#include <codecvt>
#include <locale>
// ************ TString ************
TString::TString(const wchar_t* pkText)
@ -19,7 +21,7 @@ TString::TString(const TWideString& rkText)
TWideString TString::ToUTF16() const
{
TWideString out;
TWideString Out;
const char *pkCStr = CString();
while (pkCStr[0])
@ -87,10 +89,10 @@ TWideString TString::ToUTF16() const
// Step 2: Append to output string
if ( ((CodePoint >= 0) && (CodePoint <= 0xD7FF)) ||
((CodePoint >= 0xE000) && (CodePoint <= 0xFFFF)) )
out.Append((wchar_t) (CodePoint & 0xFFFF));
Out.Append((wchar_t) (CodePoint & 0xFFFF));
}
return out;
return Out;
}
// ************ TWideString ************
@ -111,5 +113,6 @@ TWideString::TWideString(const TString& rkText)
TString TWideString::ToUTF8() const
{
return "UTF16 to UTF8 currently unsupported";
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> Convert;
return TString( Convert.to_bytes(ToStdString()) );
}

View File

@ -10,7 +10,7 @@ DEFINES += PWE_CORE
CONFIG += staticlib
TEMPLATE = lib
DESTDIR = $$PWD/../../build/Core
DESTDIR = $$BUILD_DIR/Core
DEFINES += GLEW_STATIC
unix {
@ -20,60 +20,57 @@ unix {
CONFIG (debug, debug|release) {
# Debug Config
OBJECTS_DIR = $$PWD/../../build/Core/debug
OBJECTS_DIR = $$BUILD_DIR/Core/debug
TARGET = Cored
# Debug Libs
LIBS += -L$$PWD/../../build/FileIO/ -lFileIOd \
-L$$PWD/../../build/Common/ -lCommond \
-L$$PWD/../../build/Math/ -lMathd \
-L$$PWD/../../externals/assimp/lib/ -lassimp-vc120-mtd \
-L$$PWD/../../externals/boost_1_56_0/lib32-msvc-12.0 -llibboost_filesystem-vc120-mt-gd-1_56 \
-L$$PWD/../../externals/tinyxml2/lib/ -ltinyxml2d
LIBS += -L$$BUILD_DIR/FileIO/ -lFileIOd \
-L$$BUILD_DIR/Common/ -lCommond \
-L$$BUILD_DIR/Math/ -lMathd \
-L$$EXTERNALS_DIR/assimp/lib/ -lassimp-vc120-mtd \
-L$$EXTERNALS_DIR/tinyxml2/lib/ -ltinyxml2d
# Debug Target Dependencies
win32 {
PRE_TARGETDEPS += $$PWD/../../build/FileIO/FileIOd.lib \
$$PWD/../../build/Common/Commond.lib \
$$PWD/../../build/Math/Mathd.lib
PRE_TARGETDEPS += $$BUILD_DIR/FileIO/FileIOd.lib \
$$BUILD_DIR/Common/Commond.lib \
$$BUILD_DIR/Math/Mathd.lib
}
}
CONFIG (release, debug|release) {
# Release Config
OBJECTS_DIR = $$PWD/../../build/Core/release
OBJECTS_DIR = $$BUILD_DIR/Core/release
TARGET = Core
# Release Libs
LIBS += -L$$PWD/../../build/FileIO/ -lFileIO \
-L$$PWD/../../build/Common/ -lCommon \
-L$$PWD/../../build/Math/ -lMath \
-L$$PWD/../../externals/assimp/lib/ -lassimp-vc120-mt \
-L$$PWD/../../externals/boost_1_56_0/lib32-msvc-12.0 -llibboost_filesystem-vc120-mt-1_56 \
-L$$PWD/../../externals/tinyxml2/lib/ -ltinyxml2
LIBS += -L$$BUILD_DIR/FileIO/ -lFileIO \
-L$$BUILD_DIR/Common/ -lCommon \
-L$$BUILD_DIR/Math/ -lMath \
-L$$EXTERNALS_DIR/assimp/lib/ -lassimp-vc120-mt \
-L$$EXTERNALS_DIR/tinyxml2/lib/ -ltinyxml2
# Release Target Dependencies
win32 {
PRE_TARGETDEPS += $$PWD/../../build/FileIO/FileIO.lib \
$$PWD/../../build/Common/Common.lib \
$$PWD/../../build/Math/Math.lib
PRE_TARGETDEPS += $$BUILD_DIR/FileIO/FileIO.lib \
$$BUILD_DIR/Common/Common.lib \
$$BUILD_DIR/Math/Math.lib
}
}
# Debug/Release Libs
LIBS += -L$$PWD/../../externals/glew-1.9.0/lib/ -lglew32s \
-L$$PWD/../../externals/lzo-2.08/lib -llzo-2.08 \
-L$$PWD/../../externals/zlib/lib -lzdll
LIBS += -L$$EXTERNALS_DIR/glew-1.9.0/lib/ -lglew32s \
-L$$EXTERNALS_DIR/lzo-2.08/lib -llzo-2.08 \
-L$$EXTERNALS_DIR/zlib/lib -lzdll
# Include Paths
INCLUDEPATH += $$PWD/../ \
$$PWD/../../externals/assimp/include \
$$PWD/../../externals/boost_1_56_0 \
$$PWD/../../externals/glew-1.9.0/include \
$$PWD/../../externals/glm/glm \
$$PWD/../../externals/lzo-2.08/include \
$$PWD/../../externals/tinyxml2/include \
$$PWD/../../externals/zlib/include
INCLUDEPATH += $$PWE_MAIN_INCLUDE \
$$EXTERNALS_DIR/assimp/include \
$$EXTERNALS_DIR/glew-1.9.0/include \
$$EXTERNALS_DIR/glm/glm \
$$EXTERNALS_DIR/lzo-2.08/include \
$$EXTERNALS_DIR/tinyxml2/include \
$$EXTERNALS_DIR/zlib/include
# Header Files
HEADERS += \

View File

@ -1,5 +1,5 @@
#include "CShaderGenerator.h"
#include <Common/Assert.h>
#include <Common/AssertMacro.h>
#include <iostream>
#include <fstream>
#include <sstream>

View File

@ -12,15 +12,14 @@
#include "Core/Resource/Factory/CStringLoader.h"
#include "Core/Resource/Factory/CTextureDecoder.h"
#include "Core/Resource/Factory/CWorldLoader.h"
#include <Common/Log.h>
#include <Common/TString.h>
#include <FileIO/FileIO.h>
#include <Common/FileUtil.h>
#include <Common/Log.h>
#include <Common/TString.h>
#include <iostream>
#include <boost/filesystem.hpp>
CResCache::CResCache()
: mpPak(nullptr)
{
}
@ -60,127 +59,33 @@ void CResCache::Clean()
void CResCache::SetFolder(TString Path)
{
Path.EnsureEndsWith("/");
mResSource.Path = Path;
mResSource.Source = SResSource::eFolder;
mResDir = Path;
Log::Write("Set resource folder: " + Path);
}
void CResCache::SetPak(const TString& rkPath)
{
CFileInStream *pPakFile = new CFileInStream(rkPath.ToStdString(), IOUtil::eBigEndian);
if (!pPakFile->IsValid())
{
Log::Error("Couldn't load pak file: " + rkPath);
delete pPakFile;
return;
}
if (mpPak) delete mpPak;
mpPak = new CPakFile(pPakFile);
mResSource.Path = rkPath;
mResSource.Source = SResSource::ePakFile;
Log::Write("Loaded pak file: " + rkPath);
}
void CResCache::SetResSource(SResSource& rResSource)
{
mResSource = rResSource;
}
SResSource CResCache::GetResSource()
{
return mResSource;
}
TString CResCache::GetSourcePath()
{
return mResSource.Path;
return mResDir;
}
CResource* CResCache::GetResource(CUniqueID ResID, CFourCC Type)
{
if (!ResID.IsValid()) return nullptr;
auto got = mResourceCache.find(ResID.ToLongLong());
if (got != mResourceCache.end())
return got->second;
std::vector<u8> *pBuffer = nullptr;
TString Source;
// Load from pak
if (mResSource.Source == SResSource::ePakFile)
{
pBuffer = mpPak->Resource(ResID.ToLongLong(), Type);
Source = ResID.ToString() + "." + Type.ToString();
}
// Load from folder
else
{
Source = mResSource.Path + ResID.ToString() + "." + Type.ToString();
CFileInStream File(Source.ToStdString(), IOUtil::eBigEndian);
if (!File.IsValid())
{
Log::Error("Couldn't open resource: " + ResID.ToString() + "." + Type.ToString());
return nullptr;
}
pBuffer = new std::vector<u8>;
pBuffer->resize(File.Size());
File.ReadBytes(pBuffer->data(), pBuffer->size());
}
if (!pBuffer) return nullptr;
// Load resource
CMemoryInStream Mem(pBuffer->data(), pBuffer->size(), IOUtil::eBigEndian);
Mem.SetSourceString(*Source.GetFileName());
CResource *pRes = nullptr;
bool SupportedFormat = true;
if (Type == "CMDL") pRes = CModelLoader::LoadCMDL(Mem);
else if (Type == "TXTR") pRes = CTextureDecoder::LoadTXTR(Mem);
else if (Type == "ANCS") pRes = CAnimSetLoader::LoadANCS(Mem);
else if (Type == "CHAR") pRes = CAnimSetLoader::LoadCHAR(Mem);
else if (Type == "MREA") pRes = CAreaLoader::LoadMREA(Mem);
else if (Type == "MLVL") pRes = CWorldLoader::LoadMLVL(Mem);
else if (Type == "STRG") pRes = CStringLoader::LoadSTRG(Mem);
else if (Type == "FONT") pRes = CFontLoader::LoadFONT(Mem);
else if (Type == "SCAN") pRes = CScanLoader::LoadSCAN(Mem);
else if (Type == "DCLN") pRes = CCollisionLoader::LoadDCLN(Mem);
else if (Type == "EGMC") pRes = CPoiToWorldLoader::LoadEGMC(Mem);
else if (Type == "CINF") pRes = CSkeletonLoader::LoadCINF(Mem);
else if (Type == "ANIM") pRes = CAnimationLoader::LoadANIM(Mem);
else if (Type == "CSKR") pRes = CSkinLoader::LoadCSKR(Mem);
else SupportedFormat = false;
// Log errors
if (!SupportedFormat)
Log::Write("Unsupported format; unable to load " + Type.ToString() + " " + ResID.ToString());
if (!pRes) pRes = new CResource(); // Default for invalid resource or unsupported format
// Add to cache and cleanup
pRes->mID = ResID;
pRes->mResSource = Source;
mResourceCache[ResID.ToLongLong()] = pRes;
delete pBuffer;
return pRes;
TString Source = mResDir + ResID.ToString() + "." + Type.ToString();
return GetResource(Source);
}
CResource* CResCache::GetResource(const TString& rkResPath)
{
// Since this function takes a string argument it always loads directly from a file - no pak
CUniqueID ResID = rkResPath.Hash64();
// Check if resource already exists
auto Got = mResourceCache.find(ResID.ToLongLong());
if (Got != mResourceCache.end())
return Got->second;
// Open file
CFileInStream File(rkResPath.ToStdString(), IOUtil::eBigEndian);
if (!File.IsValid())
{
@ -188,10 +93,9 @@ CResource* CResCache::GetResource(const TString& rkResPath)
return nullptr;
}
// Save old ResSource to restore later
const SResSource OldSource = mResSource;
mResSource.Source = SResSource::eFolder;
mResSource.Path = rkResPath.GetFileDirectory();
// Save old ResDir to restore later
TString OldResDir = mResDir;
mResDir = rkResPath.GetFileDirectory();
// Load resource
CResource *pRes = nullptr;
@ -220,7 +124,7 @@ CResource* CResCache::GetResource(const TString& rkResPath)
pRes->mID = *rkResPath;
pRes->mResSource = rkResPath;
mResourceCache[ResID.ToLongLong()] = pRes;
mResSource = OldSource;
mResDir = OldResDir;
return pRes;
}
@ -230,30 +134,15 @@ CFourCC CResCache::FindResourceType(CUniqueID ResID, const TStringList& rkPossib
if (rkPossibleTypes.size() == 1)
return CFourCC(rkPossibleTypes.front());
// Determine extension from pak
if (mResSource.Source == SResSource::ePakFile)
{
for (auto it = rkPossibleTypes.begin(); it != rkPossibleTypes.end(); it++)
{
SResInfo ResInfo = mpPak->ResourceInfo(ResID.ToLongLong(), CFourCC(*it));
if (ResInfo.Type != "NULL")
return CFourCC(*it);
}
}
// Determine extension from filesystem - try every extension until we find one that works
else
TString PathBase = mResDir + ResID.ToString() + ".";
for (auto it = rkPossibleTypes.begin(); it != rkPossibleTypes.end(); it++)
{
TString PathBase = mResSource.Path + ResID.ToString() + ".";
TString NewPath = PathBase + *it;
for (auto it = rkPossibleTypes.begin(); it != rkPossibleTypes.end(); it++)
{
TString NewPath = PathBase + *it;
if (boost::filesystem::exists(NewPath.ToStdString()))
return CFourCC(*it);
}
if (FileUtil::Exists(NewPath))
return CFourCC(*it);
}
return "UNKN";

View File

@ -1,34 +1,21 @@
#ifndef CRESCACHE_H
#define CRESCACHE_H
#include "CPakFile.h"
#include "CResource.h"
#include <Common/types.h>
#include <Common/TString.h>
#include <unordered_map>
struct SResSource
{
TString Path;
enum {
eFolder, ePakFile
} Source;
};
class CResCache
{
std::unordered_map<u64, CResource*> mResourceCache;
CPakFile *mpPak;
SResSource mResSource;
TString mResDir;
public:
CResCache();
~CResCache();
void Clean();
void SetFolder(TString Path);
void SetPak(const TString& rkPath);
void SetResSource(SResSource& rResSource);
SResSource GetResSource();
TString GetSourcePath();
CResource* GetResource(CUniqueID ResID, CFourCC Type);
CResource* GetResource(const TString& rkResPath);

View File

@ -5,7 +5,7 @@
#include "CResCache.h"
#include <Common/CUniqueID.h>
#include <Common/CFourCC.h>
#include <boost/filesystem.hpp>
#include <Common/FileUtil.h>
class CResourceInfo
{
@ -20,7 +20,7 @@ public:
CResourceInfo(const TString& rkPath)
: mPath(rkPath), mIsPath(true)
{
mIsValidPath = boost::filesystem::exists(rkPath.ToStdString());
mIsValidPath = FileUtil::Exists(rkPath);
}
CResourceInfo(const CUniqueID& rkID, CFourCC Type)

View File

@ -2,7 +2,7 @@
#include "Core/Render/CBoneTransformData.h"
#include "Core/Render/CDrawUtil.h"
#include "Core/Render/CGraphics.h"
#include <Common/Assert.h>
#include <Common/AssertMacro.h>
#include <Math/MathUtil.h>
// ************ CBone ************

View File

@ -1,7 +1,7 @@
#include "CTemplateWriter.h"
#include "CAreaCooker.h"
#include <Common/FileUtil.h>
#include <boost/filesystem.hpp>
#include <tinyxml2.h>
using namespace tinyxml2;
@ -42,7 +42,7 @@ void CTemplateWriter::SaveAllTemplates()
{
// Create directory
std::list<CMasterTemplate*> MasterList = CMasterTemplate::MasterList();
boost::filesystem::create_directory(smTemplatesDir.ToStdString());
FileUtil::CreateDirectory(smTemplatesDir);
// Resave property list
SavePropertyList();
@ -95,7 +95,7 @@ void CTemplateWriter::SaveGameTemplates(CMasterTemplate *pMaster)
// Create directory
TString OutFile = smTemplatesDir + pMaster->mSourceFile;
TString OutDir = OutFile.GetFileDirectory();
boost::filesystem::create_directory(OutDir.ToStdString());
FileUtil::CreateDirectory(OutDir);
// Resave script templates
for (auto it = pMaster->mTemplates.begin(); it != pMaster->mTemplates.end(); it++)
@ -226,7 +226,7 @@ void CTemplateWriter::SaveScriptTemplate(CScriptTemplate *pTemp)
// Create directory
TString OutFile = smTemplatesDir + pMaster->GetDirectory() + pTemp->mSourceFile;
TString OutDir = OutFile.GetFileDirectory();
boost::filesystem::create_directory(*OutDir);
FileUtil::CreateDirectory(*OutDir);
// Create new document
XMLDocument ScriptXML;
@ -418,7 +418,7 @@ void CTemplateWriter::SaveStructTemplate(CStructTemplate *pTemp)
TString OutFile = smTemplatesDir + pMaster->GetDirectory() + pTemp->mSourceFile;
TString OutDir = OutFile.GetFileDirectory();
TString Name = OutFile.GetFileName(false);
boost::filesystem::create_directory(OutDir.ToStdString());
FileUtil::CreateDirectory(OutDir);
// Create new document and write struct properties to it
XMLDocument StructXML;
@ -442,7 +442,7 @@ void CTemplateWriter::SaveEnumTemplate(CEnumTemplate *pTemp)
TString OutFile = smTemplatesDir + pMaster->GetDirectory() + pTemp->mSourceFile;
TString OutDir = OutFile.GetFileDirectory();
TString Name = OutFile.GetFileName(false);
boost::filesystem::create_directory(*OutDir);
FileUtil::CreateDirectory(OutDir);
// Create new document and write enumerators to it
XMLDocument EnumXML;
@ -465,7 +465,7 @@ void CTemplateWriter::SaveBitfieldTemplate(CBitfieldTemplate *pTemp)
TString OutFile = smTemplatesDir + pMaster->GetDirectory() + pTemp->mSourceFile;
TString OutDir = OutFile.GetFileDirectory();
TString Name = pTemp->mSourceFile.GetFileName(false);
boost::filesystem::create_directory(*OutDir);
FileUtil::CreateDirectory(OutDir);
// Create new document and write enumerators to it
XMLDocument BitfieldXML;

View File

@ -1,5 +1,5 @@
#include "CAnimationLoader.h"
#include <Common/Assert.h>
#include <Common/AssertMacro.h>
#include <Common/Log.h>
#include <Math/MathUtil.h>

View File

@ -1,5 +1,5 @@
#include "CSkeletonLoader.h"
#include <Common/Assert.h>
#include <Common/AssertMacro.h>
#include <Common/Log.h>
#include <vector>

View File

@ -1,5 +1,5 @@
#include "CSkinLoader.h"
#include <Common/Assert.h>
#include <Common/AssertMacro.h>
// ************ STATIC ************
CSkin* CSkinLoader::LoadCSKR(IInputStream& rCSKR)

View File

@ -1,8 +1,8 @@
#include "CTemplateLoader.h"
#include "CAreaLoader.h"
#include "Core/Resource/Script/IPropertyTemplate.h"
#include <Common/FileUtil.h>
#include <Common/Log.h>
#include <boost/filesystem.hpp>
const TString CTemplateLoader::mskTemplatesDir = "../templates/";
const TString CTemplateLoader::mskGameListPath = CTemplateLoader::mskTemplatesDir + "GameList.xml";
@ -533,7 +533,7 @@ CScriptTemplate* CTemplateLoader::LoadScriptTemplate(XMLDocument *pDoc, const TS
else
{
TString Path = "../resources/" + ID;
if (!boost::filesystem::exists(*Path))
if (!FileUtil::Exists(Path))
{
Log::Error(rkTemplateName + ": Invalid file for " + Type + " asset: " + ID);
pAsset = pAsset->NextSiblingElement();

View File

@ -2,7 +2,7 @@
#include "Core/Render/CDrawUtil.h"
#include "Core/Render/CRenderer.h"
#include "Core/OpenGL/GLCommon.h"
#include <Common/Assert.h>
#include <Common/AssertMacro.h>
CModel::CModel()
: CBasicModel()

View File

@ -4,7 +4,7 @@
#include "Core/Render/CDrawUtil.h"
#include "Core/Resource/CGameArea.h"
#include "Core/Resource/CResCache.h"
#include <Common/Assert.h>
#include <Common/AssertMacro.h>
#include <Math/CTransform4f.h>
#include <algorithm>

View File

@ -2,7 +2,7 @@
#include "CScriptNode.h"
#include "Core/Render/CRenderer.h"
#include "Core/Resource/Script/IProperty.h"
#include <Common/Assert.h>
#include <Common/AssertMacro.h>
CScriptAttachNode::CScriptAttachNode(CScene *pScene, const SAttachment& rkAttachment, CScriptNode *pParent)
: CSceneNode(pScene, -1, pParent)

View File

@ -7,7 +7,7 @@
#include "Core/Resource/Script/CMasterTemplate.h"
#include "Core/Resource/Script/CScriptLayer.h"
#include "Core/ScriptExtra/CScriptExtra.h"
#include <Common/Assert.h>
#include <Common/AssertMacro.h>
#include <Math/MathUtil.h>
CScriptNode::CScriptNode(CScene *pScene, u32 NodeID, CSceneNode *pParent, CScriptObject *pInstance)

View File

@ -1,7 +1,7 @@
#include "CDamageableTriggerExtra.h"
#include "Core/Render/CDrawUtil.h"
#include "Core/Render/CRenderer.h"
#include <Common/Assert.h>
#include <Common/AssertMacro.h>
#include <Math/MathUtil.h>
CDamageableTriggerExtra::CDamageableTriggerExtra(CScriptObject *pInstance, CScene *pScene, CScriptNode *pParent)

View File

@ -3,7 +3,7 @@
#include "Core/Scene/CSceneNode.h"
#include "Core/Scene/CScriptNode.h"
#include <Common/Assert.h>
#include <Common/AssertMacro.h>
/* CScriptExtra is a class that allows for additional coded behavior on any given
* script object type. Subclass IScriptExtra, add the new class to CScriptExtra.cpp,

View File

@ -1,7 +1,7 @@
#include "CCharacterEditor.h"
#include "ui_CCharacterEditor.h"
#include "Editor/UICommon.h"
#include <Common/Assert.h>
#include <Common/AssertMacro.h>
#include <Math/MathUtil.h>
#include <QFileDialog>
#include <QMessageBox>

View File

@ -13,7 +13,7 @@ win32: RC_ICONS += icons/AppIcon.ico
TEMPLATE = app
DESTDIR = $$PWD/../../bin
UI_DIR = $$PWD/../../build/Editor
UI_DIR = $$BUILD_DIR/Editor
DEFINES += GLEW_STATIC
!PUBLIC_RELEASE {
@ -22,68 +22,67 @@ DEFINES += GLEW_STATIC
CONFIG(debug, debug|release) {
# Debug Config
OBJECTS_DIR = $$PWD/../../build/Editor/debug
MOC_DIR = $$PWD/../../build/Editor/debug
RCC_DIR = $$PWD/../../build/Editor/debug
OBJECTS_DIR = $$BUILD_DIR/Editor/debug
MOC_DIR = $$BUILD_DIR/Editor/debug
RCC_DIR = $$BUILD_DIR/Editor/debug
TARGET = PrimeWorldEditor-debug
# Debug Libs
LIBS += -L$$PWD/../../build/FileIO/ -lFileIOd \
-L$$PWD/../../build/Common/ -lCommond \
-L$$PWD/../../build/Math/ -lMathd \
-L$$PWD/../../build/Core/ -lCored \
-L$$PWD/../../externals/assimp/lib/ -lassimp-vc120-mtd \
-L$$PWD/../../externals/boost_1_56_0/lib32-msvc-12.0 -llibboost_filesystem-vc120-mt-gd-1_56 \
-L$$PWD/../../externals/tinyxml2/lib/ -ltinyxml2d
LIBS += -L$$BUILD_DIR/FileIO/ -lFileIOd \
-L$$BUILD_DIR/Common/ -lCommond \
-L$$BUILD_DIR/Math/ -lMathd \
-L$$BUILD_DIR/Core/ -lCored \
-L$$EXTERNALS_DIR/assimp/lib/ -lassimp-vc120-mtd \
-L$$EXTERNALS_DIR/boost_1_56_0/lib32-msvc-12.0 -llibboost_filesystem-vc120-mt-gd-1_56 \
-L$$EXTERNALS_DIR/tinyxml2/lib/ -ltinyxml2d
# Debug Target Dependencies
win32 {
PRE_TARGETDEPS += $$PWD/../../build/FileIO/FileIOd.lib \
$$PWD/../../build/Common/Commond.lib \
$$PWD/../../build/Math/Mathd.lib \
$$PWD/../../build/Core/Cored.lib
PRE_TARGETDEPS += $$BUILD_DIR/FileIO/FileIOd.lib \
$$BUILD_DIR/Common/Commond.lib \
$$BUILD_DIR/Math/Mathd.lib \
$$BUILD_DIR/Core/Cored.lib
}
}
CONFIG(release, debug|release) {
# Release Config
OBJECTS_DIR = $$PWD/../../build/Editor/release
MOC_DIR = $$PWD/../../build/Editor/release
RCC_DIR = $$PWD/../../build/Editor/release
OBJECTS_DIR = $$BUILD_DIR/Editor/release
MOC_DIR = $$BUILD_DIR/Editor/release
RCC_DIR = $$BUILD_DIR/Editor/release
TARGET = PrimeWorldEditor
# Release Libs
LIBS += -L$$PWD/../../build/FileIO/ -lFileIO \
-L$$PWD/../../build/Common/ -lCommon \
-L$$PWD/../../build/Math/ -lMath \
-L$$PWD/../../build/Core/ -lCore \
-L$$PWD/../../externals/assimp/lib/ -lassimp-vc120-mt \
-L$$PWD/../../externals/boost_1_56_0/lib32-msvc-12.0 -llibboost_filesystem-vc120-mt-1_56 \
-L$$PWD/../../externals/tinyxml2/lib/ -ltinyxml2
LIBS += -L$$BUILD_DIR/FileIO/ -lFileIO \
-L$$BUILD_DIR/Common/ -lCommon \
-L$$BUILD_DIR/Math/ -lMath \
-L$$BUILD_DIR/Core/ -lCore \
-L$$EXTERNALS_DIR/assimp/lib/ -lassimp-vc120-mt \
-L$$EXTERNALS_DIR/boost_1_56_0/lib32-msvc-12.0 -llibboost_filesystem-vc120-mt-1_56 \
-L$$EXTERNALS_DIR/tinyxml2/lib/ -ltinyxml2
# Release Target Dependencies
win32 {
PRE_TARGETDEPS += $$PWD/../../build/FileIO/FileIO.lib \
$$PWD/../../build/Common/Common.lib \
$$PWD/../../build/Math/Math.lib \
$$PWD/../../build/Core/Core.lib
PRE_TARGETDEPS += $$BUILD_DIR/FileIO/FileIO.lib \
$$BUILD_DIR/Common/Common.lib \
$$BUILD_DIR/Math/Math.lib \
$$BUILD_DIR/Core/Core.lib
}
}
# Debug/Release Libs
LIBS += -L$$PWD/../../externals/glew-1.9.0/lib/ -lglew32s \
-L$$PWD/../../externals/lzo-2.08/lib -llzo-2.08 \
-L$$PWD/../../externals/zlib/lib -lzdll
LIBS += -L$$EXTERNALS_DIR/glew-1.9.0/lib/ -lglew32s \
-L$$EXTERNALS_DIR/lzo-2.08/lib -llzo-2.08 \
-L$$EXTERNALS_DIR/zlib/lib -lzdll
# Include Paths
INCLUDEPATH += $$PWD/../ \
$$PWD/../../externals/assimp/include \
$$PWD/../../externals/boost_1_56_0 \
$$PWD/../../externals/glew-1.9.0/include \
$$PWD/../../externals/glm/glm \
$$PWD/../../externals/lzo-2.08/include \
$$PWD/../../externals/tinyxml2/include \
$$PWD/../../externals/zlib/include
INCLUDEPATH += $$PWE_MAIN_INCLUDE \
$$EXTERNALS_DIR/assimp/include \
$$EXTERNALS_DIR/glew-1.9.0/include \
$$EXTERNALS_DIR/glm/glm \
$$EXTERNALS_DIR/lzo-2.08/include \
$$EXTERNALS_DIR/tinyxml2/include \
$$EXTERNALS_DIR/zlib/include
# Header Files
HEADERS += \
@ -164,7 +163,8 @@ HEADERS += \
CharacterEditor/CCharacterEditorViewport.h \
CGridRenderable.h \
CharacterEditor/CSkeletonHierarchyModel.h \
CLineRenderable.h
CLineRenderable.h \
CGameExporter.h
# Source Files
SOURCES += \
@ -224,7 +224,8 @@ SOURCES += \
CAboutDialog.cpp \
CharacterEditor/CCharacterEditor.cpp \
CharacterEditor/CCharacterEditorViewport.cpp \
CharacterEditor/CSkeletonHierarchyModel.cpp
CharacterEditor/CSkeletonHierarchyModel.cpp \
CGameExporter.cpp
# UI Files
FORMS += \

View File

@ -10,7 +10,7 @@ DEFINES += PWE_FILEIO
CONFIG += staticlib
TEMPLATE = lib
DESTDIR = $$PWD/../../build/FileIO
DESTDIR = $$BUILD_DIR/FileIO
unix {
target.path = /usr/lib
@ -19,13 +19,13 @@ unix {
CONFIG (debug, debug|release) {
# Debug Config
OBJECTS_DIR = $$PWD/../../build/FileIO/debug
OBJECTS_DIR = $$BUILD_DIR/FileIO/debug
TARGET = FileIOd
}
CONFIG (release, debug|release) {
# Release Config
OBJECTS_DIR = $$PWD/../../build/FileIO/release
OBJECTS_DIR = $$BUILD_DIR/FileIO/release
TARGET = FileIO
}

View File

@ -10,7 +10,7 @@ DEFINES += PWE_MATH
CONFIG += staticlib
TEMPLATE = lib
DESTDIR = $$PWD/../../build/Math
DESTDIR = $$BUILD_DIR/Math
unix {
target.path = /usr/lib
@ -19,45 +19,45 @@ unix {
CONFIG (debug, debug|release) {
# Debug Config
OBJECTS_DIR = $$PWD/../../build/Math/debug
OBJECTS_DIR = $$BUILD_DIR/Math/debug
TARGET = Mathd
# Debug Libs
LIBS += -L$$PWD/../../build/FileIO/ -lFileIOd \
-L$$PWD/../../build/Common/ -lCommond
LIBS += -L$$BUILD_DIR/FileIO/ -lFileIOd \
-L$$BUILD_DIR/Common/ -lCommond
# Debug Target Dependencies
win32 {
PRE_TARGETDEPS += $$PWD/../../build/FileIO/FileIOd.lib \
$$PWD/../../build/Common/Commond.lib
PRE_TARGETDEPS += $$BUILD_DIR/FileIO/FileIOd.lib \
$$BUILD_DIR/Common/Commond.lib
}
}
CONFIG (release, debug|release) {
# Release Config
OBJECTS_DIR = $$PWD/../../build/Math/release
OBJECTS_DIR = $$BUILD_DIR/Math/release
TARGET = Math
# Release Libs
LIBS += -L$$PWD/../../build/FileIO/ -lFileIO \
-L$$PWD/../../build/Common/ -lCommon
LIBS += -L$$BUILD_DIR/FileIO/ -lFileIO \
-L$$BUILD_DIR/Common/ -lCommon
# Release Target Dependencies
win32 {
PRE_TARGETDEPS += $$PWD/../../build/FileIO/FileIO.lib \
$$PWD/../../build/Common/Common.lib
PRE_TARGETDEPS += $$BUILD_DIR/FileIO/FileIO.lib \
$$BUILD_DIR/Common/Common.lib
}
}
# Debug/Release Libs
LIBS += -L$$PWD/../../externals/lzo-2.08/lib -llzo-2.08 \
-L$$PWD/../../externals/zlib/lib -lzdll
LIBS += -L$$EXTERNALS_DIR/lzo-2.08/lib -llzo-2.08 \
-L$$EXTERNALS_DIR/zlib/lib -lzdll
# Include Paths
INCLUDEPATH += $$PWD/../ \
$$PWD/../../externals/glm/glm \
$$PWD/../../externals/lzo-2.08/include \
$$PWD/../../externals/zlib/include
INCLUDEPATH += $$PWE_MAIN_INCLUDE \
$$EXTERNALS_DIR/glm/glm \
$$EXTERNALS_DIR/lzo-2.08/include \
$$EXTERNALS_DIR/zlib/include
# Header Files
HEADERS += \