#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; /** * list vector for list command */ std::vector list; 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(); /** * Get vector of all files in current directory. * Ignores directories * * @return vector of all files in the current directory */ std::vector listFiles(); /** * Open list command. Set list vector and claculate chunks * * @return chunks of the resulting list. */ int openList(); int getListSize(); /** * * * @return next chnuk vector */ std::vector getNextChunkFromList(); }; #endif