123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- #ifndef FILEMANAGER_H
- #define FILEMANAGER_H
- #include <fstream>
- #include <vector>
- /**
- * @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<char> &data);
- /**
- * Reads data from get file
- */
- virtual std::vector<char> readGet();
- };
- #endif
|