1 #pragma once 2 3 #include "util.h" 4 #include "highscores.h" 5 #include "save_file_info.h" 6 #include "saved_game_info.h" 7 8 class ProgressMeter; 9 10 class FileSharing { 11 public: 12 FileSharing(const string& uploadUrl, Options&, long long installId); 13 14 optional<string> uploadSite(const FilePath& path, ProgressMeter&); 15 struct SiteInfo { 16 SavedGameInfo gameInfo; 17 SaveFileInfo fileInfo; 18 int totalGames; 19 int wonGames; 20 int version; 21 }; 22 optional<vector<SiteInfo>> listSites(); 23 optional<string> download(const string& filename, const DirectoryPath& dir, ProgressMeter&); 24 25 typedef map<string, string> GameEvent; 26 bool uploadGameEvent(const GameEvent&, bool requireGameEventsPermission = true); 27 void uploadHighscores(const FilePath&); 28 29 struct BoardMessage { 30 string text; 31 string author; 32 }; 33 optional<vector<BoardMessage>> getBoardMessages(int boardId); 34 bool uploadBoardMessage(const string& gameId, int hash, const string& author, const string& text); 35 36 string downloadHighscores(int version); 37 38 void cancel(); 39 bool consumeCancelled(); 40 ~FileSharing(); 41 42 private: 43 string uploadUrl; 44 Options& options; 45 SyncQueue<function<void()>> uploadQueue; 46 AsyncLoop uploadLoop; 47 void uploadingLoop(); 48 void uploadGameEventImpl(const GameEvent&, int tries); 49 optional<string> downloadContent(const string& url); 50 long long installId; 51 atomic<bool> wasCancelled; 52 }; 53 54