mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-05-31 10:36:30 +03:00
Added System::DirectoryPack.
--HG-- branch : dev-2.1
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include <eepp/system/pack.hpp>
|
||||
#include <eepp/system/pak.hpp>
|
||||
#include <eepp/system/zip.hpp>
|
||||
#include <eepp/system/directorypack.hpp>
|
||||
#include <eepp/system/rc4.hpp>
|
||||
#include <eepp/system/objectloader.hpp>
|
||||
#include <eepp/system/resourceloader.hpp>
|
||||
|
||||
76
include/eepp/system/directorypack.hpp
Normal file
76
include/eepp/system/directorypack.hpp
Normal file
@@ -0,0 +1,76 @@
|
||||
#ifndef EE_SYSTEM_DIRECTORYPACK_HPP
|
||||
#define EE_SYSTEM_DIRECTORYPACK_HPP
|
||||
|
||||
#include <eepp/system/pack.hpp>
|
||||
|
||||
namespace EE { namespace System {
|
||||
|
||||
/** @brief A local file system directory. */
|
||||
class EE_API DirectoryPack : public Pack {
|
||||
public:
|
||||
DirectoryPack();
|
||||
|
||||
~DirectoryPack();
|
||||
|
||||
/** Creates a new pack file */
|
||||
bool create( const std::string& path );
|
||||
|
||||
/** Open a pack file */
|
||||
bool open( const std::string& path );
|
||||
|
||||
/** Close the pack file */
|
||||
bool close();
|
||||
|
||||
/** Add a file to the pack file
|
||||
* @param path Path to the file in the disk
|
||||
* @param inpack Path that will have the file inside the pak
|
||||
* @return True if success
|
||||
*/
|
||||
bool addFile( const std::string& path, const std::string& inpack );
|
||||
|
||||
/** Add a new file from memory */
|
||||
bool addFile( const Uint8 * data, const Uint32& dataSize, const std::string& inpack );
|
||||
|
||||
/** Add a new file from memory */
|
||||
bool addFile( std::vector<Uint8>& data, const std::string& inpack );
|
||||
|
||||
/** Add a map of files to the pack file ( myMap[ myFilepath ] = myInPackFilepath ) */
|
||||
bool addFiles( std::map<std::string, std::string> paths );
|
||||
|
||||
/** Erase a file from the pack file.*/
|
||||
bool eraseFile( const std::string& path );
|
||||
|
||||
/** Erase all passed files from the pack file. */
|
||||
bool eraseFiles( const std::vector<std::string>& paths );
|
||||
|
||||
/** Extract a file from the pack file */
|
||||
bool extractFile( const std::string& path , const std::string& dest );
|
||||
|
||||
/** Extract a file to memory from the pack file */
|
||||
bool extractFileToMemory( const std::string& path, std::vector<Uint8>& data );
|
||||
|
||||
/** Extract a file to memory from the pakFile */
|
||||
bool extractFileToMemory( const std::string& path, SafeDataPointer& data );
|
||||
|
||||
/** Check if a file exists in the pack file and return the number of the file, otherwise return -1. */
|
||||
Int32 exists( const std::string& path );
|
||||
|
||||
/** Check the integrity of the pack file. \n If return 0 integrity OK. -1 wrong indentifier. -2 wrong header. */
|
||||
Int8 checkPack();
|
||||
|
||||
/** @return a vector with all the files inside the pack file */
|
||||
std::vector<std::string> getFileList();
|
||||
|
||||
/** @return The file path of the opened package */
|
||||
std::string getPackPath();
|
||||
|
||||
IOStream * getFileStream( const std::string& path );
|
||||
protected:
|
||||
std::string mPath;
|
||||
|
||||
void getDirectoryFiles(std::vector<std::string> & files, std::string directory);
|
||||
};
|
||||
|
||||
}}
|
||||
#endif
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
../../include/eepp/math/interpolation1d.hpp
|
||||
../../include/eepp/math/interpolation2d.hpp
|
||||
../../include/eepp/system/color.hpp
|
||||
../../include/eepp/system/directorypack.hpp
|
||||
../../include/eepp/system/iostreampak.hpp
|
||||
../../include/eepp/system/iostreamzip.hpp
|
||||
../../include/eepp/system/translator.hpp
|
||||
@@ -83,6 +84,7 @@
|
||||
../../src/eepp/math/interpolation1d.cpp
|
||||
../../src/eepp/math/interpolation2d.cpp
|
||||
../../src/eepp/system/color.cpp
|
||||
../../src/eepp/system/directorypack.cpp
|
||||
../../src/eepp/system/iostreampak.cpp
|
||||
../../src/eepp/system/iostreamzip.cpp
|
||||
../../src/eepp/system/translator.cpp
|
||||
|
||||
134
src/eepp/system/directorypack.cpp
Normal file
134
src/eepp/system/directorypack.cpp
Normal file
@@ -0,0 +1,134 @@
|
||||
#include <eepp/system/directorypack.hpp>
|
||||
#include <eepp/system/filesystem.hpp>
|
||||
#include <eepp/system/iostreamfile.hpp>
|
||||
|
||||
namespace EE { namespace System {
|
||||
|
||||
DirectoryPack::DirectoryPack() {}
|
||||
|
||||
DirectoryPack::~DirectoryPack() {}
|
||||
|
||||
bool DirectoryPack::create( const std::string& path ) {
|
||||
if ( !FileSystem::isDirectory( path ) ) {
|
||||
FileSystem::makeDir( path );
|
||||
}
|
||||
|
||||
return open( path );
|
||||
}
|
||||
|
||||
bool DirectoryPack::open( const std::string& path ) {
|
||||
if ( FileSystem::isDirectory( path ) ) {
|
||||
mPath = path;
|
||||
|
||||
#if EE_PLATFORM == EE_PLATFORM_WIN
|
||||
if ( mPath.find_first_of( '\\' ) != std::string::npos ) {
|
||||
String::replaceAll( mPath, "\\", "/" );
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( mPath.size() && mPath[ path.size() - 1 ] != '/' )
|
||||
mPath += "/";
|
||||
|
||||
mIsOpen = true;
|
||||
|
||||
onPackOpened();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DirectoryPack::close() {
|
||||
mPath = "";
|
||||
onPackClosed();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DirectoryPack::addFile( const std::string& path, const std::string& inpack ) {
|
||||
return FileSystem::fileCopy( path, mPath + inpack );
|
||||
}
|
||||
|
||||
bool DirectoryPack::addFile( const Uint8 * data, const Uint32 & dataSize, const std::string& inpack ) {
|
||||
return FileSystem::fileWrite( mPath + inpack, data, dataSize );
|
||||
}
|
||||
|
||||
bool DirectoryPack::addFile( std::vector<Uint8>& data, const std::string& inpack ) {
|
||||
return FileSystem::fileWrite( mPath + inpack, data );
|
||||
}
|
||||
|
||||
bool DirectoryPack::addFiles( std::map<std::string, std::string> paths ) {
|
||||
for( std::map<std::string, std::string>::iterator itr = paths.begin(); itr != paths.end(); itr++)
|
||||
if ( !addFile( itr->first, itr->second ) )
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DirectoryPack::eraseFile( const std::string& path ) {
|
||||
return FileSystem::fileRemove( mPath + path );
|
||||
}
|
||||
|
||||
bool DirectoryPack::eraseFiles( const std::vector<std::string>& paths ) {
|
||||
for ( auto it = paths.begin(); it != paths.end(); ++it ) {
|
||||
if ( !eraseFile( mPath + (*it) ) )
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DirectoryPack::extractFile( const std::string& path, const std::string& dest) {
|
||||
return FileSystem::fileCopy( mPath + path, dest );
|
||||
}
|
||||
|
||||
bool DirectoryPack::extractFileToMemory( const std::string& path, std::vector<Uint8>& data ) {
|
||||
return FileSystem::fileGet( mPath + path, data );
|
||||
}
|
||||
|
||||
bool DirectoryPack::extractFileToMemory( const std::string& path, SafeDataPointer& data ) {
|
||||
return FileSystem::fileGet( mPath + path, data );
|
||||
}
|
||||
|
||||
Int32 DirectoryPack::exists( const std::string& path ) {
|
||||
return FileSystem::fileExists( mPath + path ) ? 0 : -1;
|
||||
}
|
||||
|
||||
Int8 DirectoryPack::checkPack() {
|
||||
return mPath.empty() ? -1 : 1;
|
||||
}
|
||||
|
||||
void DirectoryPack::getDirectoryFiles( std::vector<std::string>& files, std::string directory ) {
|
||||
std::vector<std::string> pathFiles = FileSystem::filesGetInPath( directory );
|
||||
std::string path( directory );
|
||||
|
||||
if ( String::startsWith( path, mPath ) && mPath.length() <= path.size() ) {
|
||||
path = path.substr( mPath.length() );
|
||||
}
|
||||
|
||||
for ( auto it = pathFiles.begin(); it != pathFiles.end(); ++it ) {
|
||||
if ( FileSystem::isDirectory( directory + (*it) ) ) {
|
||||
getDirectoryFiles( files, directory + (*it) + "/" );
|
||||
} else {
|
||||
files.push_back( path + (*it) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> DirectoryPack::getFileList() {
|
||||
std::vector<std::string> files;
|
||||
|
||||
if ( !mPath.empty() ) {
|
||||
getDirectoryFiles( files, mPath );
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
std::string DirectoryPack::getPackPath() {
|
||||
return mPath;
|
||||
}
|
||||
|
||||
IOStream * DirectoryPack::getFileStream( const std::string & path ) {
|
||||
return eeNew( IOStreamFile, ( path ) );
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -45,7 +45,7 @@ IniFile::IniFile( Pack * Pack, std::string iniPackPath, const bool& shouldReadFi
|
||||
}
|
||||
|
||||
bool IniFile::loadFromPack( Pack * Pack, std::string iniPackPath ) {
|
||||
if ( NULL != Pack && Pack->isOpen() && Pack->exists( iniPackPath ) ) {
|
||||
if ( NULL != Pack && Pack->isOpen() && -1 != Pack->exists( iniPackPath ) ) {
|
||||
SafeDataPointer PData;
|
||||
|
||||
Pack->extractFileToMemory( iniPackPath, PData );
|
||||
|
||||
Reference in New Issue
Block a user