Harmonic Flow Framework (libhffwk)
Cross platform C++ 2D Game Engine Framework
Public Types | Public Member Functions | List of all members
HFCore::FileDirUtils Class Referenceabstract

Interface useful for generic directory and file operations. More...

#include <FileDirUtils.h>

Public Types

enum  FilterType {
  FTYPE_ALL = 0x00000000, IMGTYPE_ALL = 0x00000001, IMGTYPE_JPEG = 0x00000002, IMGTYPE_PNG = 0x00000040,
  IMGTYPE_BMP = 0x00000080, IMGTYPE_TGA = 0x00000100, SNDTYPE_ALL = 0x00010000, SNDTYPE_OGG = 0x00020000,
  SNDTYPE_WAV = 0x00040000
}
 Enum holding file filter types. More...
 

Public Member Functions

 FileDirUtils ()
 Constructor.
 
virtual ~FileDirUtils ()
 Destructor.
 
virtual int8_hfmakeFilePath (int8_hf *fileName)
 Builds full file path to file on platforms where relative paths doesn't work such as iOS and Mac. More...
 
virtual std::wstring getAppDataFolder ()=0
 Get the default application data folder. More...
 
virtual std::wstring getUserMusicFolder ()=0
 Get the default music folder. More...
 
virtual std::wstring getUserPicturesFolder ()=0
 Get the default pictures folder. More...
 
virtual void createDirectory (const std::wstring sDirectoryPath)=0
 Create directory. More...
 
virtual void removeDirectory (const std::wstring sDirectoryPath)=0
 Remove directory. More...
 
virtual bool copyFile (const std::wstring sFromFileFullPath, const std::wstring sToFileFullPath)=0
 Copy file. More...
 
virtual void removeFile (const std::wstring sFilePath)=0
 Remove file. More...
 
virtual void splitDirFileExt (const std::wstring &path, std::wstring *dir, std::wstring *name, std::wstring *ext)
 Splits full file path into: directory, file name and file extension. More...
 
virtual void splitDirFileExt (const std::string &path, std::string *dir, std::string *name, std::string *ext)
 Splits full file path into: directory, file name and file extension. More...
 
virtual std::wstring getFileExt (std::wstring sFileName)=0
 Get the file extension for given sFileName (example: "ogg"). More...
 
virtual std::string getFileExt (std::string sFileName)=0
 Get the file extension for given sFileName (example: "ogg"). More...
 
virtual bool isDirectory (const std::wstring item)=0
 Determines whether item is a directory. More...
 
virtual bool isFile (const std::wstring item)=0
 Determines whether item is a file. More...
 
virtual std::wstring getDefaultDrivePath ()=0
 Get default drive path (example "C:/" on Windows, "/home/username/" on Linux etc). More...
 
virtual std::wstring extractDriveFromPath (std::wstring sDirectoryPath)=0
 Extract drive from path (Windows only). More...
 
virtual std::wstring extractPreviousDirectoryPath (std::wstring sCurrentDirectoryPath)=0
 Extract previous directory path. More...
 
virtual void getAllSystemDrives (StringUtil::WStringVector &vDrivesOnly, StringUtil::WStringVector &vDrivesAndInfo)=0
 Get all sytem drives (Windows only). More...
 
virtual void getAllDirectories (const std::wstring sFromCurrentDirectoryPath, StringUtil::WStringVector &vOutputDirs, StringUtil::WStringVector &vOutputDirsFP, const std::wstring sFilter=L"*")=0
 Get all directories for a given path. More...
 
virtual void getAllFilesInDirectory (const std::wstring sFromCurrentDirectoryPath, FilterType filterType, StringUtil::WStringVector &vOutputFilesInDir, StringUtil::WStringVector &vOutputFilesInDirFP)=0
 Get all files for a given path. More...
 
virtual void getAllDirectoriesAndFiles (const std::wstring sFromCurrentDirectoryPath, FilterType filterType, StringUtil::WStringVector &vOutDirsAndFiles, StringUtil::WStringVector &vOutDirsAndFilesFP)=0
 Get all directories and files for a given path. More...
 
virtual std::wstring getFilterStr (FilterType filterType)=0
 Get filter wstring for given FileDirUtils::FilterType enum. More...
 

Detailed Description

Interface useful for generic directory and file operations.

Example code:

// Good example of makeFilePath usage:
int8_hf path[] = "data/resources.xml";
const int8_hf *fullFilePath = path;
if (HFCORE_ENV->getPakDataFileName().length() == 0)
fullFilePath = HFCORE_FDU->makeFilePath(path);
bool result = HFCORE_RESMGR->parseResourceFile(fullFilePath);
if (!result)
{
envEngineLog("Unable to parse [%s]\r\n", fullFilePath);
}
// Get file extension (returns "xml"):
std::string fileExt = HFCORE_FDU->getFileExt(fullFilePath);
// etc ..

Definition at line 57 of file FileDirUtils.h.

Member Enumeration Documentation

◆ FilterType

Enum holding file filter types.

Enumerator
FTYPE_ALL 

All supported formats.

IMGTYPE_ALL 

Image format: All supported.

IMGTYPE_JPEG 

Image format: JPEG.

IMGTYPE_PNG 

Image format: PNG.

IMGTYPE_BMP 

Image format: BMP.

IMGTYPE_TGA 

Image format: TGA.

SNDTYPE_ALL 

Sound / SoundPlayer format: All supported.

SNDTYPE_OGG 

Sound / SoundPlayer format: OGG Vorbis.

SNDTYPE_WAV 

Sound / SoundPlayer format: WAV.

Definition at line 63 of file FileDirUtils.h.

Member Function Documentation

◆ copyFile()

virtual bool HFCore::FileDirUtils::copyFile ( const std::wstring  sFromFileFullPath,
const std::wstring  sToFileFullPath 
)
pure virtual

Copy file.

Parameters
sFromFileFullPathPath to copy file from.
sToFileFullPathPath to copy file to.
Returns

◆ createDirectory()

virtual void HFCore::FileDirUtils::createDirectory ( const std::wstring  sDirectoryPath)
pure virtual

Create directory.

Parameters
sDirectoryPathDirectory to create.

◆ extractDriveFromPath()

std::wstring FileDirUtils::extractDriveFromPath ( std::wstring  sDirectoryPath)
pure virtual

Extract drive from path (Windows only).

Parameters
sDirectoryPathPath.
Returns
Drive for path such as "C:/".
Note
Only useful on Windows.

Definition at line 202 of file FileDirUtils.cpp.

◆ extractPreviousDirectoryPath()

std::wstring FileDirUtils::extractPreviousDirectoryPath ( std::wstring  sCurrentDirectoryPath)
pure virtual

Extract previous directory path.

Example: "/home/user/test/" will return "home/user/").

Parameters
sCurrentDirectoryPathPath.
Returns
Previous directory path.

Definition at line 219 of file FileDirUtils.cpp.

◆ getAllDirectories()

virtual void HFCore::FileDirUtils::getAllDirectories ( const std::wstring  sFromCurrentDirectoryPath,
StringUtil::WStringVector vOutputDirs,
StringUtil::WStringVector vOutputDirsFP,
const std::wstring  sFilter = L"*" 
)
pure virtual

Get all directories for a given path.

Parameters
sFromCurrentDirectoryPathPath to get all directories for.
[out]vOutputDirsVector containing directory names only.
[out]vOutputDirsFPVector containing full directory paths.
sFilterFilter to use, defaults to all.

◆ getAllDirectoriesAndFiles()

virtual void HFCore::FileDirUtils::getAllDirectoriesAndFiles ( const std::wstring  sFromCurrentDirectoryPath,
FilterType  filterType,
StringUtil::WStringVector vOutDirsAndFiles,
StringUtil::WStringVector vOutDirsAndFilesFP 
)
pure virtual

Get all directories and files for a given path.

Parameters
sFromCurrentDirectoryPathPath to get all directories and files for.
filterTypeFileDirUtils::FilterType to use as filter.
[out]vOutDirsAndFilesVector containing directory names and file names only.
[out]vOutDirsAndFilesFPVector containing full directory and file paths.

◆ getAllFilesInDirectory()

virtual void HFCore::FileDirUtils::getAllFilesInDirectory ( const std::wstring  sFromCurrentDirectoryPath,
FilterType  filterType,
StringUtil::WStringVector vOutputFilesInDir,
StringUtil::WStringVector vOutputFilesInDirFP 
)
pure virtual

Get all files for a given path.

Parameters
sFromCurrentDirectoryPathPath to get all directories for.
filterTypeFileDirUtils::FilterType to use as filter.
[out]vOutputFilesInDirVector containing file names only.
[out]vOutputFilesInDirFPVector containing full file paths.

◆ getAllSystemDrives()

virtual void HFCore::FileDirUtils::getAllSystemDrives ( StringUtil::WStringVector vDrivesOnly,
StringUtil::WStringVector vDrivesAndInfo 
)
pure virtual

Get all sytem drives (Windows only).

Parameters
[out]vDrivesOnlyVector containing drive name only (example: "C:/").
[out]vDrivesAndInfoVector containing drive name, volume name and some extra info (example: "(C:) Windows 10 - Local Drive").
Note
Only useful on Windows.

◆ getAppDataFolder()

virtual std::wstring HFCore::FileDirUtils::getAppDataFolder ( )
pure virtual

Get the default application data folder.

Application data folder is where engine log files and Preferences are stored for example.

It is recommended to store all your game save data and similar in this folder.

Returns
Default application data folder.

◆ getDefaultDrivePath()

virtual std::wstring HFCore::FileDirUtils::getDefaultDrivePath ( )
pure virtual

Get default drive path (example "C:/" on Windows, "/home/username/" on Linux etc).

Returns
Default drive path for current platform.

◆ getFileExt() [1/2]

std::wstring FileDirUtils::getFileExt ( std::wstring  sFileName)
pure virtual

Get the file extension for given sFileName (example: "ogg").

Parameters
sFileNamePath to file.
Returns
File extension (example: "ogg").

Definition at line 149 of file FileDirUtils.cpp.

◆ getFileExt() [2/2]

std::string FileDirUtils::getFileExt ( std::string  sFileName)
pure virtual

Get the file extension for given sFileName (example: "ogg").

Parameters
sFileNamePath to file.
Returns
File extension (example: "ogg").

Definition at line 163 of file FileDirUtils.cpp.

◆ getFilterStr()

std::wstring FileDirUtils::getFilterStr ( FilterType  filterType)
pure virtual

Get filter wstring for given FileDirUtils::FilterType enum.

Parameters
filterTypeFileDirUtils::FilterType enum to convert to wstring.
Returns
Filter wstring for fiven FileDirUtils::FilterType.

Definition at line 244 of file FileDirUtils.cpp.

◆ getUserMusicFolder()

virtual std::wstring HFCore::FileDirUtils::getUserMusicFolder ( )
pure virtual

Get the default music folder.

Returns
Default music folder.

◆ getUserPicturesFolder()

virtual std::wstring HFCore::FileDirUtils::getUserPicturesFolder ( )
pure virtual

Get the default pictures folder.

Returns
Default pictures folder.

◆ isDirectory()

bool FileDirUtils::isDirectory ( const std::wstring  item)
pure virtual

Determines whether item is a directory.

Parameters
itemPath.
Returns
true if item is a directory, else false.

Definition at line 177 of file FileDirUtils.cpp.

◆ isFile()

bool FileDirUtils::isFile ( const std::wstring  item)
pure virtual

Determines whether item is a file.

Parameters
itemPath.
Returns
true if item is a file, else false.

Definition at line 190 of file FileDirUtils.cpp.

◆ makeFilePath()

virtual int8_hf* HFCore::FileDirUtils::makeFilePath ( int8_hf fileName)
inlinevirtual

Builds full file path to file on platforms where relative paths doesn't work such as iOS and Mac.

It is the recommended way to keep file fetching working fine on all platforms.

Parameters
fileNamePath to file.
Returns
Full path to file.

Definition at line 100 of file FileDirUtils.h.

◆ removeDirectory()

virtual void HFCore::FileDirUtils::removeDirectory ( const std::wstring  sDirectoryPath)
pure virtual

Remove directory.

Parameters
sDirectoryPathDirectory to remove.

◆ removeFile()

virtual void HFCore::FileDirUtils::removeFile ( const std::wstring  sFilePath)
pure virtual

Remove file.

Parameters
sFilePathPath to file to remove.

◆ splitDirFileExt() [1/2]

void FileDirUtils::splitDirFileExt ( const std::wstring &  path,
std::wstring *  dir,
std::wstring *  name,
std::wstring *  ext 
)
virtual

Splits full file path into: directory, file name and file extension.

Parameters
pathFull file path.
[out]dirDirectory name if not NULL.
[out]nameFile name if not NULL.
[out]extFile extension (example: png) if not NULL.

Definition at line 35 of file FileDirUtils.cpp.

◆ splitDirFileExt() [2/2]

void FileDirUtils::splitDirFileExt ( const std::string &  path,
std::string *  dir,
std::string *  name,
std::string *  ext 
)
virtual

Splits full file path into: directory, file name and file extension.

Parameters
pathFull file path.
[out]dirDirectory name if not NULL.
[out]nameFile name if not NULL.
[out]extFile extension (example: png) if not NULL.

Definition at line 92 of file FileDirUtils.cpp.


The documentation for this class was generated from the following files: