Hot Door CORE 0.8.2
Adobe® Illustrator® Plug-in Library
Loading...
Searching...
No Matches
Typedefs | Functions
hdi::core::files Namespace Reference

Organizes all file-/folder-related functionality into one namespace for convenience. More...

Typedefs

typedef std::vector< std::string > StringVector
 

Functions

bool exists (const std::string &filePath_)
 Checks for the existence of a file or folder.
 
bool onNetwork (const std::string &filePath_)
 Gets whether the given file is stored on a network drive.
 
bool copy (const std::string &filePath_, const std::string &destPath_)
 Copies a source file to a destination path.
 
bool rename (const std::string &filePath_, const std::string &newName_)
 Renames a file.
 
bool move (const std::string &fromFilePath_, const std::string &toFolderPath_)
 Moves a file from one location to another.
 
int64_t getSize (const std::string &filePath_)
 Returns the size of a file in bytes.
 
std::string getTextContents (const std::string &filePath_)
 Gets the contents of a text-based file, assumed to be in UTF-8 encoding.
 
bool setTextContents (const std::string &filePath_, const std::string &contents_)
 Sets the contents of a text-based file in UTF-8 encoding.
 
bool getPermissions (const std::string &filePath_, mode_t &perms__)
 Gets the permission bits of a file or folder.
 
bool makeDirectory (const std::string &path_, const mode_t perms_)
 Cross-platform function to create a directory at a given path with given permissions.
 
bool filesInDirectory (const std::string &path_, StringVector &files__)
 Cross-platform function to retrieve the names of every file in a given directory.
 
bool moveToTrash (const std::string &filePath_)
 Moves a file to the Trash (Mac) or Recycle Bin (Windows)
 
bool ungzip (const std::string &sourcePath_, const std::string &destPath_)
 Un-gzips a source file to a destination path.
 
std::string platformPrefsPath (const std::string &subfolder_, const bool create_=true)
 Gets the prefs/registration/etc. folder path (given a subfolder inside it)
 

Detailed Description

Organizes all file-/folder-related functionality into one namespace for convenience.

Function Documentation

◆ copy()

bool hdi::core::files::copy ( const std::string &  filePath_,
const std::string &  destPath_ 
)

Copies a source file to a destination path.

Author
GW
Date
08/2013
Parameters
filePath_Source file to copy, as UTF-8
destPath_Destination file, as UTF-8, into which the source file will be written
Returns
true for success, false for failure
Note
The copy is performed in a binary fashion, and is safe for both text-based and binary files
The destination file will be overwritten if it already exists

◆ exists()

bool hdi::core::files::exists ( const std::string &  filePath_)

Checks for the existence of a file or folder.

Author
GW
Date
08/2013
Parameters
filePath_Path for the file whose existence is in question, as UTF-8
Returns
true for existent file, false otherwise

◆ filesInDirectory()

bool hdi::core::files::filesInDirectory ( const std::string &  path_,
StringVector &  files__ 
)

Cross-platform function to retrieve the names of every file in a given directory.

Author
GW
Date
11/2013
Parameters
path_Path to directory whose file contents will be read, as UTF-8
files_Return-by-reference for a vector of all file names in the given directory, as UTF-8
Returns
true if the directory exists and its file contents could be read, false otherwise

◆ getPermissions()

bool hdi::core::files::getPermissions ( const std::string &  filePath_,
mode_t &  perms__ 
)

Gets the permission bits of a file or folder.

Author
GW
Date
08/2013
Parameters
filePath_Path for the file whose permissions are in question, as UTF-8
perms__Return-by-reference for bitwise OR of permissions (0 by default)
Returns
true if the permissions could be read, false otherwise
Note
Due to the "unique way" permissions work on Windows, this function will only return the permission bits for the current user (not those of the owning group or everyone else).

◆ getSize()

int64_t hdi::core::files::getSize ( const std::string &  filePath_)

Returns the size of a file in bytes.

Author
GW
Date
08/2013
Parameters
filePath_Path for the file whose size is in question, as UTF-8
Returns
Size of the file in bytes, or -1 for error

◆ getTextContents()

std::string hdi::core::files::getTextContents ( const std::string &  filePath_)

Gets the contents of a text-based file, assumed to be in UTF-8 encoding.

Author
GW
Date
08/2013
Parameters
filePath_Path for the file whose contents are in question, as UTF-8
Returns
String for the contents of the file, in UTF-8 encoding
Warning
This should only be used when you expect the file to be non-binary.

◆ makeDirectory()

bool hdi::core::files::makeDirectory ( const std::string &  path_,
const mode_t  perms_ 
)

Cross-platform function to create a directory at a given path with given permissions.

Author
GW
Date
08/2013
Parameters
path_Location at which the directory will be created, as UTF-8
perms_UNIX-style permissions for the file (e.g. octal 0755 means user rwx, group r-x, others r-x)
Returns
true if the directory is created successfully, false otherwise
Note
This function is safe to call if the directory already exists.
Due to the "unique way" permissions work on Windows, user/group/everyone permission bits will be mapped in the best way possible (typically, the "user" bits apply to the current user, the "group" bits apply to administrators, and the "everyone" bits apply to the local system).

◆ move()

bool hdi::core::files::move ( const std::string &  fromFilePath_,
const std::string &  toFolderPath_ 
)

Moves a file from one location to another.

Author
GW
Date
08/2013
Parameters
fromFilePath_Absolute path to the file that should be moved, as UTF-8
toFolderPath_Absolute path to the destination folder, as UTF-8
Returns
true for success, false for failure
Note
This function cannot be used to rename a file; use rename() instead

◆ moveToTrash()

bool hdi::core::files::moveToTrash ( const std::string &  filePath_)

Moves a file to the Trash (Mac) or Recycle Bin (Windows)

Author
GW
Date
08/2013
Parameters
filePath_Absolute path to the file that should be deleted, as UTF-8
Returns
true for success, false for failure

◆ onNetwork()

bool hdi::core::files::onNetwork ( const std::string &  filePath_)

Gets whether the given file is stored on a network drive.

Author
GW
Date
07/2017
Parameters
filePath_Absolute path to the file in question
Returns
true if the file is on a network drive, false otherwise

◆ platformPrefsPath()

std::string hdi::core::files::platformPrefsPath ( const std::string &  subfolder_,
const bool  create_ = true 
)

Gets the prefs/registration/etc. folder path (given a subfolder inside it)

Author
GW
Date
08/2013
Parameters
subfolder_Your containing prefs subfolder inside the platform prefs path, as UTF-8
create_true to create the folder if it's missing, false to simply return the path
Returns
A string for the path to your prefs/registration/etc. folder, as UTF-8
Note
On OS X: /Library/(user name)/Preferences/<subfolder_>/
On Win XP: \Documents and Settings\(user name)\Local Settings\Application Data<subfolder_>\
On Win Vista, 7, 8: \Users\(user name)\AppData\Local<subfolder_>\

◆ rename()

bool hdi::core::files::rename ( const std::string &  filePath_,
const std::string &  newName_ 
)

Renames a file.

Author
GW
Date
08/2013
Parameters
filePath_Absolute path to the file that should be renamed, as UTF-8
newName_New name for the file, as UTF-8
Returns
true for success, false for failure
Note
This function cannot be used to move a file; use move() instead

◆ setTextContents()

bool hdi::core::files::setTextContents ( const std::string &  filePath_,
const std::string &  contents_ 
)

Sets the contents of a text-based file in UTF-8 encoding.

Author
GW
Date
08/2013
Parameters
filePath_Path for the file whose contents are to be set, as UTF-8
contents_Contents with which to overwrite the file, as UTF-8
Returns
true for success, false for failure
Note
As of now, this function only overwrites the contents of a file and does not allow data appending.
Warning
This should only be used when you expect the file to be non-binary.

◆ ungzip()

bool hdi::core::files::ungzip ( const std::string &  sourcePath_,
const std::string &  destPath_ 
)

Un-gzips a source file to a destination path.

Author
GW
Date
08/2013
Parameters
sourcePath_Absolute path to the file that should be un-gzipped, as UTF-8
destPath_Absolute path to the file that should be created from the gzipped file, as UTF-8
Returns
true if the file was un-gzipped successfully, false otherwise
Note
This function does not understand archive files (e.g. gzipped tar files)