FileManager.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. * list vector for list command
  36. */
  37. std::vector<std::string> list;
  38. public:
  39. enum { max_data_length = 512 };
  40. /**
  41. * Creates the file manager
  42. */
  43. FileManager();
  44. /**
  45. * Destroys the file manager
  46. */
  47. ~FileManager();
  48. /**
  49. * Checks if an upload is running
  50. * @return true - upload running | false - no upload
  51. */
  52. virtual bool isUploading();
  53. /**
  54. * Check if a download is running
  55. * @return true - download running | false - no download
  56. */
  57. virtual bool isDownloading();
  58. /**
  59. * Opens put file if it doesn't exist
  60. * @return true - file is open | false - file is not open
  61. */
  62. virtual bool openPutFile(const std::string &filename);
  63. /**
  64. * Opens get file if it exists and reports the amount of chunks
  65. * @return true - file is open | false - file is not open
  66. */
  67. virtual bool openGetFile(const std::string &filename, int &chunks);
  68. /**
  69. * Closes file
  70. */
  71. void closePutFile();
  72. /**
  73. * Closes file
  74. */
  75. void closeGetFile();
  76. /**
  77. * Closes put file and deletes it
  78. */
  79. virtual void cancelPut();
  80. /**
  81. * Checks if a file name is valid
  82. * @return true - name is valid | false - name is invalid
  83. */
  84. bool checkFilename(const std::string &name);
  85. /**
  86. * Return the name of the download file
  87. * @return name of the download file
  88. */
  89. virtual std::string getGetBaseFileName();
  90. /**
  91. * Return the name of the upload file
  92. * @return name of the upload file
  93. */
  94. virtual std::string getPutBaseFileName();
  95. /**
  96. * Writes data to put file
  97. */
  98. virtual void writePut(const std::vector<char> &data);
  99. /**
  100. * Reads data from get file
  101. */
  102. virtual std::vector<char> readGet();
  103. /**
  104. * Get vector of all files in current directory.
  105. * Ignores directories
  106. *
  107. * @return vector of all files in the current directory
  108. */
  109. std::vector<std::string> listFiles();
  110. /**
  111. * Open list command. Set list vector and claculate chunks
  112. *
  113. * @return chunks of the resulting list.
  114. */
  115. int openList();
  116. int getListSize();
  117. /**
  118. *
  119. *
  120. * @return next chnuk vector
  121. */
  122. std::vector<std::string> getNextChunkFromList();
  123. };
  124. #endif