#ifndef FILEMANAGER_H #define FILEMANAGER_H #include #include /** * @class FileManager * * Manages file writes for uploads and file reads for downloads */ class FileManager { private: const std::string fileDirectory; /** * file stream for get command */ std::ifstream getFile; /** * file stream for put command */ std::ofstream putFile; /** * file name for put command * (used to delete the file if the upload is canceled) */ std::string putFileName; /** * file name for put command */ std::string putBaseFileName; /** * file name for get command */ std::string getBaseFileName; /* * size of the get file * * Used to determine how much to read and encode as base64 */ std::streamoff getFileSize; public: enum { max_data_length = 512 }; /** * Creates the file manager */ FileManager(); /** * Destroys the file manager */ ~FileManager(); /** * Checks if an upload is running * @return true - upload running | false - no upload */ virtual bool isUploading(); /** * Check if a download is running * @return true - download running | false - no download */ virtual bool isDownloading(); /** * Opens put file if it doesn't exist * @return true - file is open | false - file is not open */ virtual bool openPutFile(const std::string &filename); /** * Opens get file if it exists and reports the amount of chunks * @return true - file is open | false - file is not open */ virtual bool openGetFile(const std::string &filename, int &chunks); /** * Closes file */ void closePutFile(); /** * Closes file */ void closeGetFile(); /** * Closes put file and deletes it */ virtual void cancelPut(); /** * Checks if a file name is valid * @return true - name is valid | false - name is invalid */ bool checkFilename(const std::string &name); /** * Return the name of the download file * @return name of the download file */ virtual std::string getGetBaseFileName(); /** * Return the name of the upload file * @return name of the upload file */ virtual std::string getPutBaseFileName(); /** * Writes data to put file */ virtual void writePut(const std::vector &data); /** * Reads data from get file */ virtual std::vector readGet(); }; #endif