// Copyright (c) 2013, IOnU Security, Inc. // Copyright (c) 2016, Sequence Logic, Inc. All rights reserved. #ifndef FILENAME #define FILENAME #include #include #include #ifdef WIN32 #ifdef SL_CPPCORE_DLLEXPORT #define SL_CPPCORE_EXPORT __declspec(dllexport) #else #define SL_CPPCORE_EXPORT __declspec(dllimport) #endif #else #define SL_CPPCORE_EXPORT #endif namespace sequencelogic { class EyeTime; /** * sequencelogic::File * * A convenience class for working with file attributes. * */ class SL_CPPCORE_EXPORT File { public: static const char DIR_SEP; File() {} File(const File &oldFile) : _mount(oldFile._mount), _path(oldFile._path), _fileName(oldFile._fileName), _ext(oldFile._ext) {} File(const File &parent, const std::string &child); File(const File &parent, const char *pChild); File(const std::string &filename) { setFilename(filename.c_str()); } File(const char *pFilename) { setFilename(pFilename); } ~File() {} File& operator=(const File &oldFile); bool operator==(const File &rhs) const { return (getAbsolutePath() == rhs.getAbsolutePath()); } /** * Split this string into it's various "filename" parts, and set the member * variables accordingly. */ void setFilename(const std::string &filename) { setFilename(filename.c_str()); } void setFilename(const char *pFilename); /** * Does this file exist? */ bool exists() const; /** * Can I read this file? */ bool canRead() const; /** * Can I write this file? */ bool canWrite() const; /** * Is this a file? */ bool isFile() const; /** * Is this a directory? */ bool isDirectory() const; /** * Make all the directories in the path. */ bool mkdirs() const; /** * Delete the file. */ bool deleteFile() const; /** * Get the size of this file... */ unsigned int length() const; /** * When was this file last modified? */ EyeTime lastModified() const; /** * Set a file's last modified time. */ void setLastModified (const EyeTime &lastModified); /** * Get the full path and filename. */ std::string getAbsolutePath() const; /** * Get the name. This is just the filename (no extension), or the last directory name (if there is no filename set). */ std::string getName() const; /** * Get the extension. */ const std::string& getExtension() const { return _ext; } /** * Get the filename. */ const std::string& getFilename() const { return _fileName; } /** * Get the filename with extension. */ const std::string getFilenameWithExt() const { return (_fileName + _ext); } /** * Get the directory... */ std::string getDirectory() const { return (_mount + _path); } /** * Get the parent directory. */ File getParentFile() const; /** * Copy this file to the new filename. */ bool copyFile(const File &destFile) const; /** * If this is a directory, get a list of all the files in the directory. The list does *not* * include the '.' or '..' names. * * @param fileList The list of files in the directory * @return The number of files found */ unsigned int listFiles(std::vector &fileList, const std::string &fileFilter = "") const; /** * Get the absolute filename, in a URI format: * 'file://{absolute path name}' */ std::string toURI() const; #if defined(WIN32) || defined(_WIN32) #pragma warning(push) #pragma warning(disable:4251 4275) // Disable the dumbass XXXX needs to have dll-interface. #endif private: File(const std::string &mount, const std::string &path, const char *pFileName); std::string _mount; // Mount part of filename. Could be a drive letter. std::string _path; // Path of the filename, no mount, no filename. std::string _fileName; // File, without extension std::string _ext; // File extension #if defined(WIN32) || defined(_WIN32) #pragma warning(pop) #endif }; SL_CPPCORE_EXPORT std::ostream& operator<<(std::ostream &out, const File &node); }; #endif