|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <map> |
| 4 | +#include <list> |
| 5 | +#include <string> |
| 6 | +#include <memory> |
| 7 | +#include <cstring> |
| 8 | +#include <unordered_map> |
| 9 | + |
| 10 | +#include "Consts.h" |
| 11 | +#include "WorkingSet.h" |
| 12 | +#include "ClientsToDo.h" |
| 13 | +#include "Filestructures.h" |
| 14 | +#include "lib/hash-library/md5.h" |
| 15 | +#include "lib/hash-library/crc32.h" |
| 16 | + |
| 17 | + |
| 18 | +class Filesystem { |
| 19 | +public: |
| 20 | + static unsigned int filesysze(const std::string FID); |
| 21 | + static void calcSHA256(const std::string FID, char* buffer); |
| 22 | + static void calcCRC32(char* buffer, unsigned int bufferLength, char crc32Bytes[CRC32::HashBytes]); |
| 23 | + static bool exists(std::string path); |
| 24 | +}; |
| 25 | + |
| 26 | +class FilesystemClient:Filesystem { |
| 27 | +private: |
| 28 | + std::unordered_map <std::string, std::shared_ptr<File>> files; |
| 29 | + std::list<std::shared_ptr<Folder>> folders; |
| 30 | + std::string path; |
| 31 | + int genMap(const std::string path, std::unordered_map <std::string, std::shared_ptr<File>> *files, std::list<std::shared_ptr<Folder>> *folders, std::list<std::string> *deleteFile, std::list<std::string> *deleteFolder); |
| 32 | + void compareFiles(const std::string FID, File* f); |
| 33 | + void genCRC32(const std::string FID, File* f); |
| 34 | + void openFilesystem(); |
| 35 | + void closeFilesystem(); |
| 36 | + std::shared_ptr<File> genFileOBJ(const std::string); |
| 37 | +public: |
| 38 | + FilesystemClient(const std::string path); |
| 39 | + void close(); |
| 40 | + int readFilePart(const std::string FID, char* buffer, unsigned int partNr); |
| 41 | + int writeFilePart(const std::string FID, char* buffer, unsigned int partNr, unsigned int length); |
| 42 | + void genFile(const std::string FID, char* hash); |
| 43 | + void genFolder(const std::string path); |
| 44 | + void delFile(const std::string FID); |
| 45 | + void delFolder(const std::string path); |
| 46 | + WorkingSet* getWorkingSet(); |
| 47 | + std::string filesToStirng(); |
| 48 | + std::string folderToString(); |
| 49 | +}; |
| 50 | + |
| 51 | +class FilesystemServer:Filesystem { |
| 52 | +private: |
| 53 | + std::string path = ""; |
| 54 | + std::unordered_map <std::string, bool> folders; |
| 55 | + std::unordered_map <std::string, std::unique_ptr<ServerFile>> files; |
| 56 | + ClientsToDo* clientsToDo; |
| 57 | + bool createPath(); |
| 58 | + void removeFolder(const std::string path); |
| 59 | + void removeFile(const std::string path); |
| 60 | + void openFilesystem(); |
| 61 | + void closeFilesystem(); |
| 62 | + void saveFolders(); |
| 63 | + void saveFiles(); |
| 64 | + void openFiles(); |
| 65 | + void openFolders(); |
| 66 | + void genFile(const std::string FID, char* hash); |
| 67 | + void removeUnknownFiles(); |
| 68 | +public: |
| 69 | + FilesystemServer(const std::string path, ClientsToDo* clientsToDo); |
| 70 | + void close(); |
| 71 | + void genFile(const std::string FID, char* hash, unsigned int clientID); |
| 72 | + void genFolder(const std::string path, unsigned int clientID); |
| 73 | + void delFile(const std::string FID, unsigned int clientID); |
| 74 | + void delFolder(const std::string path, unsigned int clientID); |
| 75 | + unsigned int getLastPart(std::string FID); |
| 76 | + int readFilePart(const std::string FID, char* buffer, unsigned int partNr); |
| 77 | + int writeFilePart(const std::string FID, char* buffer, unsigned int partNr, unsigned int length, unsigned int clientID); |
| 78 | +}; |
0 commit comments