FileManager.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #ifndef FILEMANAGER_H
  2. #define FILEMANAGER_H
  3. #include <fstream>
  4. #include <vector>
  5. /**
  6. * @class FileManager
  7. *
  8. * Manages file writes for uploads and file reads for downloads
  9. */
  10. class FileManager {
  11. private:
  12. const std::string fileDirectory;
  13. /**
  14. * file stream for get command
  15. */
  16. std::ifstream getFile;
  17. /**
  18. * file stream for put command
  19. */
  20. std::ofstream putFile;
  21. /**
  22. * file name for put command
  23. * (used to delete the file if the upload is canceled)
  24. */
  25. std::string putFileName;
  26. /**
  27. * file name for put command
  28. */
  29. std::string putBaseFileName;
  30. /**
  31. * file name for get command
  32. */
  33. std::string getBaseFileName;
  34. /*
  35. * size of the get file
  36. *
  37. * Used to determine how much to read and encode as base64
  38. */
  39. std::streamoff getFileSize;
  40. public:
  41. enum { max_data_length = 512 };
  42. /**
  43. * Creates the file manager
  44. */
  45. FileManager();
  46. /**
  47. * Destroys the file manager
  48. */
  49. ~FileManager();
  50. /**
  51. * Checks if an upload is running
  52. * @return true - upload running | false - no upload
  53. */
  54. virtual bool isUploading();
  55. /**
  56. * Check if a download is running
  57. * @return true - download running | false - no download
  58. */
  59. virtual bool isDownloading();
  60. /**
  61. * Opens put file if it doesn't exist
  62. * @return true - file is open | false - file is not open
  63. */
  64. virtual bool openPutFile(const std::string &filename);
  65. /**
  66. * Opens get file if it exists and reports the amount of chunks
  67. * @return true - file is open | false - file is not open
  68. */
  69. virtual bool openGetFile(const std::string &filename, int &chunks);
  70. /**
  71. * Closes file
  72. */
  73. void closePutFile();
  74. /**
  75. * Closes file
  76. */
  77. void closeGetFile();
  78. /**
  79. * Closes put file and deletes it
  80. */
  81. virtual void cancelPut();
  82. /**
  83. * Checks if a file name is valid
  84. * @return true - name is valid | false - name is invalid
  85. */
  86. bool checkFilename(const std::string &name);
  87. /**
  88. * Return the name of the download file
  89. * @return name of the download file
  90. */
  91. virtual std::string getGetBaseFileName();
  92. /**
  93. * Return the name of the upload file
  94. * @return name of the upload file
  95. */
  96. virtual std::string getPutBaseFileName();
  97. /**
  98. * Writes data to put file
  99. */
  100. virtual void writePut(const std::vector<char> &data);
  101. /**
  102. * Reads data from get file
  103. */
  104. virtual std::vector<char> readGet();
  105. };
  106. #endif