├── icon.png
├── citraholdminibanner.png
├── banner.qrc
├── utils.h
├── about.cpp
├── about.h
├── README.md
├── main.cpp
├── .gitignore
├── gameidmanager.h
├── citraholdUI.pro
├── mainwindow.h
├── utils.cpp
├── CitraholdServer.h
├── ConfigManager.h
├── about.ui
├── gameidmanager.ui
├── CitraholdServer.cpp
├── mainwindow.ui
├── gameidmanager.cpp
├── ConfigManager.cpp
├── mainwindow.cpp
└── LICENSE
/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/regimensocial/citraholdUI/HEAD/icon.png
--------------------------------------------------------------------------------
/citraholdminibanner.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/regimensocial/citraholdUI/HEAD/citraholdminibanner.png
--------------------------------------------------------------------------------
/banner.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | citraholdminibanner.png
4 | icon.png
5 |
6 |
7 |
--------------------------------------------------------------------------------
/utils.h:
--------------------------------------------------------------------------------
1 | #ifndef UTILS_H
2 | #define UTILS_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | // Function prototypes
11 | std::filesystem::path getSaveDirectory();
12 | std::filesystem::path getLikelyCitraDirectory();
13 |
14 | #endif // UTILS_H
--------------------------------------------------------------------------------
/about.cpp:
--------------------------------------------------------------------------------
1 | #include "about.h"
2 | #include "ui_about.h"
3 |
4 | About::About(QWidget *parent) :
5 | QDialog(parent),
6 | ui(new Ui::About)
7 | {
8 | ui->setupUi(this);
9 | ui->versionLabel->setText("This is Citrahold PC v" + QCoreApplication::applicationVersion());
10 | }
11 |
12 | About::~About()
13 | {
14 | delete ui;
15 | }
16 |
--------------------------------------------------------------------------------
/about.h:
--------------------------------------------------------------------------------
1 | #ifndef ABOUT_H
2 | #define ABOUT_H
3 |
4 | #include
5 |
6 | namespace Ui {
7 | class About;
8 | }
9 |
10 | class About : public QDialog
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | explicit About(QWidget *parent = nullptr);
16 | ~About();
17 |
18 | private:
19 | Ui::About *ui;
20 | };
21 |
22 | #endif // ABOUT_H
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Citrahold PC (citraholdUI)
2 |
3 | **[Download here](https://github.com/regimensocial/citraholdUI/releases/latest)**
4 |
5 | **Please go [here](https://github.com/regimensocial/Citrahold-3DS) for more info.**
6 |
7 | This is Citrahold PC, for Windows, macOS, and Linux(~)
8 |
9 | Citrahold is a 3DS Homebrew App, a piece of software, and a web service which allows you to easily sync your saves between 3DSes and Emulators.
10 |
11 | **Big changes are coming to Citrahold PC...**
12 |
--------------------------------------------------------------------------------
/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include
3 |
4 | #ifndef APP_VERSION
5 | #define APP_VERSION 0
6 | #endif
7 |
8 | int main(int argc, char *argv[])
9 | {
10 | QApplication a(argc, argv);
11 |
12 | QString VERSION = APP_VERSION;
13 | QCoreApplication::setApplicationVersion(VERSION);
14 |
15 | qDebug() << APP_VERSION;
16 | qDebug() << "Application Version:" << QCoreApplication::applicationVersion();
17 |
18 | a.setWindowIcon(QIcon(":/banner/icon.png"));
19 | MainWindow w;
20 | w.setWindowTitle("Citrahold PC v" + QCoreApplication::applicationVersion());
21 |
22 | w.show();
23 |
24 | return a.exec();
25 | }
26 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # This file is used to ignore files which are generated
2 | # ----------------------------------------------------------------------------
3 |
4 | *~
5 | *.autosave
6 | *.a
7 | *.core
8 | *.moc
9 | *.o
10 | *.obj
11 | *.orig
12 | *.rej
13 | *.so
14 | *.so.*
15 | *_pch.h.cpp
16 | *_resource.rc
17 | *.qm
18 | .#*
19 | *.*#
20 | core
21 | !core/
22 | tags
23 | .DS_Store
24 | .directory
25 | *.debug
26 | Makefile*
27 | *.prl
28 | *.app
29 | moc_*.cpp
30 | ui_*.h
31 | qrc_*.cpp
32 | Thumbs.db
33 | *.res
34 | *.rc
35 | /.qmake.cache
36 | /.qmake.stash
37 |
38 | # qtcreator generated files
39 | *.pro.user*
40 | CMakeLists.txt.user*
41 |
42 | # xemacs temporary files
43 | *.flc
44 |
45 | # Vim temporary files
46 | .*.swp
47 |
48 | # Visual Studio generated files
49 | *.ib_pdb_index
50 | *.idb
51 | *.ilk
52 | *.pdb
53 | *.sln
54 | *.suo
55 | *.vcproj
56 | *vcproj.*.*.user
57 | *.ncb
58 | *.sdf
59 | *.opensdf
60 | *.vcxproj
61 | *vcxproj.*
62 |
63 | # MinGW generated files
64 | *.Debug
65 | *.Release
66 |
67 | # Python byte code
68 | *.pyc
69 |
70 | # Binaries
71 | # --------
72 | *.dll
73 | *.exe
74 |
75 | .vscode/
--------------------------------------------------------------------------------
/gameidmanager.h:
--------------------------------------------------------------------------------
1 | #ifndef GAMEIDMANAGER_H
2 | #define GAMEIDMANAGER_H
3 |
4 | #include
5 | #include "ConfigManager.h"
6 | #include "CitraholdServer.h"
7 |
8 | namespace Ui {
9 | class GameIDManager;
10 | }
11 |
12 | class GameIDManager : public QDialog
13 | {
14 | Q_OBJECT
15 |
16 | public:
17 | explicit GameIDManager(QWidget *parent = nullptr, ConfigManager *configManager = nullptr);
18 | ~GameIDManager();
19 |
20 | ConfigManager *configManager;
21 | void setUploadType(UploadType uploadType, bool ignoreOther = false);
22 | void setGameID(QString gameID);
23 |
24 | private:
25 | Ui::GameIDManager *ui;
26 | UploadType uploadType;
27 | bool validGameID(QString gameID);
28 |
29 | private slots:
30 | void resetDirectory(bool doubleCheck = false);
31 | void handleSaveExtdataRadios();
32 | void handleDirectoryButton(bool openSelection = true, bool existing = false);
33 | void addGameIDToFile(bool existing = false);
34 | void switchBetweenNewAndExisting();
35 | void retrieveGameIDList();
36 | void handleExistingGameIDSelection();
37 | void handleChangeToNew();
38 | void handleChangeToExisting();
39 | void handleDeleteExistingGameID();
40 |
41 | };
42 |
43 | #endif // GAMEIDMANAGER_H
44 |
--------------------------------------------------------------------------------
/citraholdUI.pro:
--------------------------------------------------------------------------------
1 | QT += core gui network widgets
2 |
3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
4 |
5 | CONFIG += c++17
6 |
7 | # You can make your code fail to compile if it uses deprecated APIs.
8 | # In order to do so, uncomment the following line.
9 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
10 |
11 | SOURCES += \
12 | CitraholdServer.cpp \
13 | about.cpp \
14 | gameidmanager.cpp \
15 | main.cpp \
16 | mainwindow.cpp \
17 | ConfigManager.cpp
18 |
19 | HEADERS += \
20 | CitraholdServer.h \
21 | about.h \
22 | gameidmanager.h \
23 | mainwindow.h \
24 | ConfigManager.h
25 |
26 | FORMS += \
27 | about.ui \
28 | gameidmanager.ui \
29 | mainwindow.ui
30 |
31 | # Default rules for deployment.
32 | qnx: target.path = /tmp/$${TARGET}/bin
33 | else: unix:!android: target.path = /opt/$${TARGET}/bin
34 | !isEmpty(target.path): INSTALLS += target
35 |
36 | DISTFILES += \
37 | banner.png \
38 | icon.png
39 |
40 | RESOURCES += \
41 | banner.qrc
42 |
43 | TARGET = Citrahold
44 | TEMPLATE = app
45 |
46 | VERSION = 1.1.0
47 |
48 | DEFINES += APP_VERSION=\\\"$$VERSION\\\"
49 |
50 | # Select ARM build in Creator!!
51 | QMAKE_APPLE_DEVICE_ARCHS += \
52 | x86_64 \
53 | arm64
54 |
--------------------------------------------------------------------------------
/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 | #include "ConfigManager.h"
6 | #include
7 | #include "CitraholdServer.h"
8 | #include "gameidmanager.h"
9 | #include "about.h"
10 |
11 | QT_BEGIN_NAMESPACE
12 | namespace Ui { class MainWindow; }
13 | QT_END_NAMESPACE
14 |
15 | class MainWindow : public QMainWindow
16 | {
17 | Q_OBJECT
18 |
19 |
20 | public:
21 | MainWindow(QWidget *parent = nullptr);
22 | ~MainWindow();
23 |
24 | void setUploadType(UploadType uploadType, bool ignoreOther = false);
25 | void retrieveGameIDList(QString gameID = "");
26 |
27 | private slots:
28 | void handleVerifyButtonClicked();
29 | void manageTokenTextEdit();
30 |
31 | void handleUploadButton();
32 | void handleServerFetch();
33 | void handleDownloadButton();
34 | void handleClearOldSavesButton();
35 | void handleToggleModeButton();
36 | void openConfigFolder();
37 | void openAboutWindow();
38 | void changeLastUploadText();
39 | void changeLastDownloadText();
40 | void changeLastServerUploadText(bool upload);
41 |
42 |
43 | private:
44 | Ui::MainWindow *ui;
45 | ConfigManager *configManager;
46 | CitraholdServer *citraholdServer;
47 | GameIDManager *gameIDManager;
48 | About *aboutWindow;
49 |
50 | void handleSuccessfulLogin();
51 | void openGameIDSelector();
52 | void handleSaveExtdataRadios();
53 | void handleDownloadGameIDMissing();
54 | void showErrorBox(QString error = "");
55 | void showSuccessBox(QString text);
56 |
57 | UploadType savesOrExtdata();
58 |
59 | };
60 | #endif // MAINWINDOW_H
61 |
--------------------------------------------------------------------------------
/utils.cpp:
--------------------------------------------------------------------------------
1 | #include "utils.h"
2 |
3 | std::string directory;
4 |
5 | std::filesystem::path getSaveDirectory()
6 | {
7 |
8 | std::filesystem::path saveDirectory;
9 | #ifdef _WIN32
10 | // Windows
11 | saveDirectory = std::getenv("APPDATA");
12 | saveDirectory /= "Citrahold";
13 | #else
14 | // offensively assuming all other platforms are Linux or macOS
15 | saveDirectory = std::getenv("HOME");
16 | saveDirectory /= ".config";
17 | saveDirectory /= "Citrahold";
18 | #endif
19 | if (!std::filesystem::exists(saveDirectory))
20 | {
21 | std::filesystem::create_directories(saveDirectory);
22 | }
23 |
24 | return saveDirectory;
25 | }
26 |
27 | std::filesystem::path getLikelyCitraDirectory()
28 | {
29 | // so on MacOS
30 | // ~/Library/Application Support/Citra/
31 |
32 | // on Linux
33 | // ~/.local/share/citra-emu/
34 |
35 | // and on Windows
36 | // AppData/Roaming/Citra/
37 |
38 | std::filesystem::path citraDirectory;
39 | #ifdef _WIN32
40 | // Windows
41 | citraDirectory = std::getenv("APPDATA");
42 | citraDirectory /= "Citra";
43 | #elif __APPLE__
44 | // macos
45 | citraDirectory = std::getenv("HOME");
46 | citraDirectory /= "Library";
47 | citraDirectory /= "Application Support";
48 | citraDirectory /= "Citra";
49 | #else
50 | // offensively assuming all other platforms are Linux
51 | citraDirectory = std::getenv("HOME");
52 | citraDirectory /= ".local";
53 | citraDirectory /= "share";
54 | citraDirectory /= "citra-emu";
55 |
56 | #endif
57 | if (!std::filesystem::exists(citraDirectory))
58 | {
59 | return "";
60 | }
61 |
62 | return citraDirectory;
63 | }
--------------------------------------------------------------------------------
/CitraholdServer.h:
--------------------------------------------------------------------------------
1 | #ifndef CITRAHOLDSERVER_H
2 | #define CITRAHOLDSERVER_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 |
15 | using responsePair = std::pair;
16 |
17 | enum UploadType
18 | {
19 | SAVES,
20 | EXTDATA
21 | };
22 |
23 | class CitraholdServer {
24 | public:
25 | CitraholdServer(QString serverAddress, QString token);
26 |
27 | QString getTokenFromShorthandToken(QString shorthandToken);
28 |
29 | QString verifyTokenToSetUserID(QString fullToken);
30 |
31 | QJsonArray getGameIDsFromServer(UploadType type);
32 | void updateServerGameIDVariables();
33 |
34 | QVector serverGameIDSaves;
35 | QVector serverGameIDExtdata;
36 |
37 | QDateTime getLastUploadTime(UploadType type, QString gameID);
38 |
39 | bool checkServerIsOnline();
40 |
41 | QVector getSoftwareVersions();
42 |
43 | int upload(UploadType type, QString filePath, QString base64Data);
44 | int uploadMultiple(UploadType type, QJsonArray files);
45 | int download(UploadType type, QString gameID, std::filesystem::path gamePath);
46 | int downloadMultiple(UploadType type, QString gameID, std::filesystem::path gamePath);
47 |
48 | private:
49 | QString serverAddress;
50 | QString token;
51 | QNetworkAccessManager *networkManager;
52 |
53 | void setTokenFromString(QString token);
54 | responsePair sendRequest(QString address, QJsonObject* dataToSend = nullptr, QString* downloadPath = nullptr); //
55 |
56 | };
57 |
58 | #endif // CITRAHOLDSERVER_H
59 |
--------------------------------------------------------------------------------
/ConfigManager.h:
--------------------------------------------------------------------------------
1 | #ifndef CONFIGMANAGER_H
2 | #define CONFIGMANAGER_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include "CitraholdServer.h"
12 | #include
13 |
14 | class ConfigManager
15 | {
16 | public:
17 | ConfigManager();
18 |
19 | std::filesystem::path getSaveDirectory() const;
20 | std::filesystem::path getLikelyCitraDirectory(UploadType type = UploadType::SAVES);
21 | std::filesystem::path getOldSaveDirectory(UploadType type = UploadType::SAVES) const;
22 |
23 | void updateConfigFile(QJsonDocument newConfig);
24 | void setToken(QString token);
25 |
26 | QJsonDocument getGameIDFile(UploadType type);
27 | void updateGameIDFile(UploadType type, QJsonDocument newFile);
28 |
29 | void updateConfigProperty(QString property, QJsonValue value);
30 | QString getConfigProperty(QString property);
31 |
32 | void addEntryToGameIDFile(UploadType type, QString gameID, QString gameName);
33 | void removeEntryFromGameIDFile(UploadType type, QString gameID);
34 |
35 | QJsonDocument getConfig();
36 | QString getToken();
37 |
38 | std::filesystem::path getGamePathFromGameID(UploadType type, QString gameID);
39 | QDateTime getLastUploadTime(UploadType type, QString gameID);
40 | void setLastUploadTime(UploadType type, QString gameID, QDateTime time);
41 |
42 | QDateTime getLastDownloadTime(UploadType type, QString gameID);
43 | void setLastDownloadTime(UploadType type, QString gameID, QDateTime time);
44 |
45 | bool copyDirectory(const std::filesystem::path &source, const std::filesystem::path &destination);
46 |
47 | QString userID;
48 |
49 | bool loggedIn();
50 |
51 | private:
52 | std::filesystem::path saveDirectory;
53 | std::filesystem::path citraDirectory;
54 | QJsonDocument config;
55 |
56 | void initialise();
57 | };
58 |
59 | #endif // CONFIGMANAGER_H
60 |
--------------------------------------------------------------------------------
/about.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | About
4 |
5 |
6 |
7 | 0
8 | 0
9 | 400
10 | 523
11 |
12 |
13 |
14 | About Citrahold
15 |
16 |
17 |
18 | true
19 |
20 |
21 |
22 | 50
23 | 0
24 | 301
25 | 200
26 |
27 |
28 |
29 |
30 |
31 |
32 | :/banner/citraholdminibanner.png
33 |
34 |
35 |
36 |
37 |
38 | 50
39 | 190
40 | 301
41 | 51
42 |
43 |
44 |
45 | <html><head/><body><p><a href="https://www.citrahold.com/"><span style=" text-decoration: underline; color:#007af4;">Citrahold</span></a> is a collection of tools to allow you to sync saves between a PC emulator, and a real 3DS.</p></body></html>
46 |
47 |
48 | Qt::RichText
49 |
50 |
51 | true
52 |
53 |
54 | true
55 |
56 |
57 |
58 |
59 |
60 | 50
61 | 260
62 | 301
63 | 21
64 |
65 |
66 |
67 | This is Citrahold PC.
68 |
69 |
70 | true
71 |
72 |
73 |
74 |
75 |
76 | 50
77 | 300
78 | 301
79 | 41
80 |
81 |
82 |
83 | <html><head/><body><p>All of Citrahold is available as open source software on GitHub. <a href="https://github.com/regimensocial/citraholdUI/"><span style=" text-decoration: underline; color:#007af4;">Citrahold PC's repository.</span></a></p></body></html>
84 |
85 |
86 | Qt::RichText
87 |
88 |
89 | true
90 |
91 |
92 | true
93 |
94 |
95 |
96 |
97 |
98 | 50
99 | 360
100 | 301
101 | 41
102 |
103 |
104 |
105 | Citrahold's original author is Jamie Adams (regimensocial)
106 |
107 |
108 | true
109 |
110 |
111 |
112 |
113 |
114 | 50
115 | 420
116 | 301
117 | 61
118 |
119 |
120 |
121 | 3DS is a trademark of Nintendo. Citrahold is not affiliated with Nintendo in any way, nor are we affiliated with Citra. This is simply a complementary tool.
122 |
123 |
124 | true
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
--------------------------------------------------------------------------------
/gameidmanager.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | GameIDManager
4 |
5 |
6 |
7 | 0
8 | 0
9 | 370
10 | 420
11 |
12 |
13 |
14 | Game IDs
15 |
16 |
17 |
18 |
19 | 10
20 | 100
21 | 351
22 | 311
23 |
24 |
25 |
26 | 0
27 |
28 |
29 |
30 |
31 |
32 | 20
33 | 55
34 | 311
35 | 91
36 |
37 |
38 |
39 |
40 |
41 |
42 | 20
43 | 210
44 | 311
45 | 31
46 |
47 |
48 |
49 |
50 |
51 |
52 | QPlainTextEdit::NoWrap
53 |
54 |
55 |
56 |
57 |
58 | 20
59 | 190
60 | 161
61 | 16
62 |
63 |
64 |
65 | Enter an ID for this game
66 |
67 |
68 |
69 |
70 |
71 | 20
72 | 20
73 | 311
74 | 32
75 |
76 |
77 |
78 | Select Directory
79 |
80 |
81 |
82 |
83 |
84 | 20
85 | 245
86 | 311
87 | 32
88 |
89 |
90 |
91 | Add New Game ID
92 |
93 |
94 |
95 |
96 |
97 | 240
98 | 150
99 | 91
100 | 32
101 |
102 |
103 |
104 | Reset
105 |
106 |
107 |
108 |
109 |
110 | 20
111 | 0
112 | 131
113 | 16
114 |
115 |
116 |
117 | Game Save Directory
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 | 20
126 | 20
127 | 311
128 | 32
129 |
130 |
131 |
132 |
133 |
134 |
135 | 20
136 | 0
137 | 191
138 | 16
139 |
140 |
141 |
142 | Select existing Game ID
143 |
144 |
145 |
146 |
147 |
148 | 20
149 | 90
150 | 311
151 | 91
152 |
153 |
154 |
155 |
156 |
157 |
158 | 20
159 | 210
160 | 311
161 | 31
162 |
163 |
164 |
165 |
166 |
167 |
168 | QPlainTextEdit::NoWrap
169 |
170 |
171 |
172 |
173 |
174 | 20
175 | 190
176 | 161
177 | 16
178 |
179 |
180 |
181 | Game ID
182 |
183 |
184 |
185 |
186 |
187 | 240
188 | 58
189 | 91
190 | 31
191 |
192 |
193 |
194 | Select New
195 |
196 |
197 |
198 |
199 |
200 | 20
201 | 245
202 | 311
203 | 32
204 |
205 |
206 |
207 | Update Changes
208 |
209 |
210 |
211 |
212 |
213 | 180
214 | 278
215 | 151
216 | 31
217 |
218 |
219 |
220 | Delete From Device
221 |
222 |
223 |
224 |
225 |
226 | 20
227 | 66
228 | 101
229 | 16
230 |
231 |
232 |
233 | Game Directory
234 |
235 |
236 |
237 |
238 |
239 | 140
240 | 58
241 | 101
242 | 31
243 |
244 |
245 |
246 | Open Current
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 | 30
255 | 50
256 | 221
257 | 32
258 |
259 |
260 |
261 | Switch to existing Game IDs
262 |
263 |
264 |
265 |
266 |
267 | 30
268 | 30
269 | 251
270 | 16
271 |
272 |
273 |
274 | You are adding a new gameID
275 |
276 |
277 |
278 |
279 |
280 | 270
281 | 50
282 | 71
283 | 20
284 |
285 |
286 |
287 | extdata
288 |
289 |
290 |
291 |
292 |
293 | 270
294 | 30
295 | 61
296 | 20
297 |
298 |
299 |
300 | saves
301 |
302 |
303 |
304 |
305 |
306 |
307 |
--------------------------------------------------------------------------------
/CitraholdServer.cpp:
--------------------------------------------------------------------------------
1 | #include "CitraholdServer.h"
2 | #include "QtCore/qjsonarray.h"
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 |
15 | #include
16 | #include
17 |
18 | CitraholdServer::CitraholdServer(QString serverAddress, QString token)
19 | {
20 | this->serverAddress = serverAddress;
21 | this->token = token;
22 | this->networkManager = new QNetworkAccessManager();
23 | }
24 |
25 | void CitraholdServer::setTokenFromString(QString token)
26 | {
27 |
28 | this->token = token;
29 | }
30 |
31 | QVector CitraholdServer::getSoftwareVersions()
32 | {
33 | QVector versions;
34 |
35 | responsePair response = sendRequest(this->serverAddress + "/softwareVersion");
36 |
37 | if (response.first == 200)
38 | {
39 | QJsonArray versionsArray = response.second["pc"].toArray();
40 |
41 | for (int i = 0; i < versionsArray.size(); ++i)
42 | {
43 | versions.append(versionsArray.at(i).toString());
44 | }
45 | }
46 |
47 | return versions;
48 | }
49 |
50 | responsePair CitraholdServer::sendRequest(QString address, QJsonObject *dataToSend, QString *downloadPath)
51 | {
52 | QEventLoop eventLoop;
53 |
54 | QObject::connect(networkManager, SIGNAL(finished(QNetworkReply *)), &eventLoop, SLOT(quit()));
55 |
56 | QNetworkRequest req(address);
57 |
58 | req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
59 |
60 | QJsonObject jsonObject = QJsonObject();
61 | if (dataToSend != nullptr)
62 | {
63 | jsonObject = *dataToSend;
64 | }
65 |
66 | QByteArray jsonData = QJsonDocument(jsonObject).toJson();
67 |
68 | QNetworkReply *reply = this->networkManager->post(req, jsonData);
69 |
70 | eventLoop.exec();
71 |
72 | int httpStatusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
73 |
74 | if (reply->error() == QNetworkReply::NoError)
75 | {
76 |
77 | QVariant contentType = reply->header(QNetworkRequest::ContentTypeHeader);
78 |
79 | if (contentType.toString().startsWith("application/json"))
80 | {
81 |
82 | QJsonDocument response = QJsonDocument::fromJson(reply->readAll());
83 | delete reply;
84 | return std::make_pair(httpStatusCode, response);
85 | }
86 | else if (downloadPath != nullptr)
87 | {
88 | QFile file(*downloadPath);
89 |
90 | if (file.open(QIODevice::WriteOnly))
91 | {
92 | file.write(reply->readAll());
93 | file.close();
94 | qDebug() << "Downloaded to" << *downloadPath;
95 | }
96 | else
97 | {
98 | qDebug() << "Failed to open file for writing.";
99 | }
100 |
101 | delete reply;
102 | return std::make_pair(httpStatusCode, QJsonDocument());
103 | }
104 | }
105 | else // actual error
106 | {
107 |
108 | QJsonDocument response = QJsonDocument::fromJson(reply->readAll());
109 | delete reply;
110 | return std::make_pair(httpStatusCode, response);
111 | }
112 |
113 | delete reply;
114 | return std::make_pair(0, QJsonDocument());
115 | }
116 |
117 | QString CitraholdServer::getTokenFromShorthandToken(QString shorthandToken)
118 | {
119 | QJsonObject data;
120 |
121 | data["shorthandToken"] = shorthandToken;
122 |
123 | // this will return a full token
124 | responsePair response = sendRequest(this->serverAddress + "/getToken", &data);
125 | if (response.first == 200)
126 | {
127 |
128 | this->token = response.second["token"].toString();
129 | return response.second["token"].toString();
130 | }
131 | else
132 | {
133 | // we didn't get a token
134 | // TODO: handle this????
135 | return "invalid";
136 | }
137 | }
138 |
139 | QString CitraholdServer::verifyTokenToSetUserID(QString fullToken)
140 | {
141 | QJsonObject data;
142 |
143 | data["token"] = fullToken;
144 |
145 | responsePair response = sendRequest(this->serverAddress + "/getUserID", &data);
146 | if (response.first == 200)
147 | {
148 | this->token = fullToken;
149 | return response.second["userID"].toString();
150 | }
151 | else
152 | {
153 | // we didn't get a token
154 | // TODO: handle this
155 | return "invalid";
156 | }
157 | }
158 |
159 | bool CitraholdServer::checkServerIsOnline()
160 | {
161 | responsePair response = sendRequest(this->serverAddress + "/areyouawake");
162 | return response.first == 200;
163 | }
164 |
165 | int CitraholdServer::upload(UploadType type, QString filePath, QString base64Data)
166 | {
167 |
168 | QJsonObject data;
169 |
170 | data["token"] = this->token;
171 | data["filename"] = filePath;
172 | data["data"] = base64Data;
173 |
174 | // this will return a full token
175 | responsePair response = sendRequest(this->serverAddress + (type == UploadType::SAVES ? "/uploadSaves" : "/uploadExtdata"), &data);
176 |
177 | qDebug() << "uploadResponse " << response.first;
178 |
179 | return response.first;
180 | }
181 |
182 | int CitraholdServer::uploadMultiple(UploadType type, QJsonArray files)
183 | {
184 |
185 | QJsonObject data;
186 |
187 | data["token"] = this->token;
188 | data["multi"] = files;
189 |
190 | // this will return a full token
191 | qDebug() << "uploading multiple files";
192 | responsePair response = sendRequest(this->serverAddress + (type == UploadType::SAVES ? "/uploadMultiSaves" : "/uploadMultiExtdata"), &data);
193 |
194 | qDebug() << "uploadResponse " << response.first;
195 |
196 | return response.first;
197 | }
198 |
199 | QJsonArray CitraholdServer::getGameIDsFromServer(UploadType type)
200 | {
201 |
202 | QJsonObject data;
203 |
204 | data["token"] = this->token;
205 | responsePair response = sendRequest(this->serverAddress + (type == UploadType::SAVES ? "/getSaves" : "/getExtdata"), &data);
206 |
207 | if (response.first == 200)
208 | {
209 | return response.second["games"].toArray();
210 | }
211 | else
212 | {
213 | return {};
214 | }
215 | }
216 |
217 | int CitraholdServer::download(UploadType type, QString gameID, std::filesystem::path gamePath)
218 | {
219 | QJsonObject data;
220 |
221 | data["token"] = this->token;
222 | data["game"] = gameID;
223 |
224 | responsePair response = sendRequest(this->serverAddress + (type == UploadType::SAVES ? "/downloadSaves" : "/downloadExtdata"), &data);
225 |
226 | if (response.first == 200)
227 | {
228 | QJsonArray files = response.second["files"].toArray();
229 |
230 | bool successfulSoFar = true;
231 |
232 | for (int i = 0; i < files.size(); ++i)
233 | {
234 |
235 | if (successfulSoFar)
236 | {
237 | data["file"] = files.at(i).toString();
238 |
239 | std::filesystem::path value = files.at(i).toString().toStdString();
240 |
241 | QString downloadPath = QString::fromStdString((gamePath / value).string());
242 |
243 | if (downloadPath.contains("citraholdDirectoryDummy"))
244 | {
245 | if (!std::filesystem::exists(downloadPath.toStdString()) || !std::filesystem::is_directory(downloadPath.toStdString()))
246 | {
247 | std::filesystem::path dir = downloadPath.toStdString();
248 |
249 | if (std::filesystem::create_directories(dir.parent_path()))
250 | {
251 | qDebug() << "Directory created successfully.";
252 | }
253 | }
254 | }
255 | else
256 | {
257 | responsePair downloadResponse = sendRequest(this->serverAddress + (type == UploadType::SAVES ? "/downloadSaves" : "/downloadExtdata"), &data, &downloadPath);
258 |
259 | // qDebug() << "downloadResponse " << downloadResponse.first;
260 | successfulSoFar = (downloadResponse.first == 200);
261 |
262 | // qDebug() << "downloadPath " << downloadPath;
263 | if (successfulSoFar && (downloadPath.contains("citraholdDirectoryDummy")))
264 | {
265 | // QFile::remove(downloadPath);
266 | qDebug() << "Dummy file removed";
267 | }
268 | }
269 | }
270 | }
271 |
272 | return successfulSoFar;
273 | }
274 | return 0;
275 | }
276 |
277 | int CitraholdServer::downloadMultiple(UploadType type, QString gameID, std::filesystem::path gamePath)
278 | {
279 |
280 | QJsonObject data;
281 |
282 | data["token"] = this->token;
283 | data["game"] = gameID;
284 |
285 | responsePair response = sendRequest(this->serverAddress + (type == UploadType::EXTDATA ? "/downloadMultiExtdata" : "/downloadMultiSaves"), &data);
286 |
287 | qDebug() << response.first;
288 | if (response.first == 200)
289 | {
290 | bool successfulSoFar = true;
291 |
292 | QJsonDocument responseJSON = (response.second);
293 | QJsonArray files = responseJSON["files"].toArray();
294 | int numberOfItems = files.size();
295 | int itemNumber = 0;
296 |
297 | qDebug() << "Retrieved " << numberOfItems << " files\n";
298 |
299 | for (const QJsonValueRef &element : files)
300 | {
301 | if (!successfulSoFar)
302 | {
303 | return false;
304 | }
305 |
306 | itemNumber++;
307 |
308 | std::string filename = element[0].toString().toStdString();
309 | QString base64Data = element[1].toString();
310 |
311 | std::filesystem::path downloadPath = (gamePath / filename).string();
312 |
313 | QByteArray base64DataDecoded = QByteArray::fromBase64(base64Data.toUtf8());
314 |
315 | // write the file
316 | std::filesystem::path parentPath = downloadPath.parent_path();
317 |
318 | if (!std::filesystem::exists(parentPath))
319 | {
320 | std::filesystem::create_directories(parentPath);
321 | }
322 |
323 | if (filename.find("citraholdDirectoryDummy") == std::string::npos)
324 | {
325 |
326 | QFile file(downloadPath);
327 |
328 | if (file.open(QIODevice::WriteOnly))
329 | {
330 | file.write(base64DataDecoded);
331 |
332 | file.close();
333 | }
334 | else
335 | {
336 | qDebug() << "Error opening the file for writing.";
337 | }
338 | }
339 | else
340 | {
341 | qDebug() << "[" << itemNumber << "/" << numberOfItems << "] "
342 | << "Ignoring dummy file " << filename << "\n";
343 | }
344 | }
345 |
346 | return response.first;
347 | }
348 | return false;
349 | }
350 |
351 | void CitraholdServer::updateServerGameIDVariables()
352 | {
353 |
354 | QVector *serverGameID;
355 | UploadType type;
356 |
357 | for (int i = 0; i <= 1; ++i)
358 | {
359 | if (i == 0)
360 | {
361 | serverGameID = &serverGameIDSaves;
362 | type = UploadType::SAVES;
363 | }
364 | else
365 | {
366 | serverGameID = &serverGameIDExtdata;
367 | type = UploadType::EXTDATA;
368 | }
369 | serverGameID->clear();
370 | QJsonArray gameIDs = CitraholdServer::getGameIDsFromServer(type);
371 | for (int i = 0; i < gameIDs.size(); ++i)
372 | {
373 | QJsonValue gameValue = gameIDs.at(i);
374 | if (gameValue.isString())
375 | {
376 | serverGameID->append(gameValue.toString());
377 | }
378 | }
379 | }
380 | }
381 |
382 | QDateTime CitraholdServer::getLastUploadTime(UploadType type, QString gameID)
383 | {
384 | QJsonObject data;
385 |
386 | data["token"] = this->token;
387 | data["game"] = gameID;
388 |
389 | responsePair response = sendRequest(this->serverAddress + (type == UploadType::SAVES ? "/getSavesLastUpdated" : "/getExtdataLastUpdated"), &data);
390 |
391 | if (response.first == 200)
392 | {
393 | return QDateTime::fromString(response.second["lastModified"].toString(), Qt::ISODate);
394 | }
395 | else
396 | {
397 | return QDateTime();
398 | }
399 | }
--------------------------------------------------------------------------------
/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 361
10 | 431
11 |
12 |
13 |
14 |
15 | .AppleSystemUIFont
16 |
17 |
18 |
19 | Citrahold PC
20 |
21 |
22 |
23 | 512
24 | 512
25 |
26 |
27 |
28 |
29 |
30 |
31 | -10
32 | 120
33 | 371
34 | 271
35 |
36 |
37 |
38 | 2
39 |
40 |
41 |
42 |
43 |
44 | 40
45 | 70
46 | 171
47 | 16
48 |
49 |
50 |
51 | Enter your token
52 |
53 |
54 |
55 |
56 |
57 | 40
58 | 180
59 | 401
60 | 16
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 | 40
71 | 140
72 | 301
73 | 41
74 |
75 |
76 |
77 | Verify
78 |
79 |
80 |
81 |
82 |
83 | 40
84 | 100
85 | 301
86 | 31
87 |
88 |
89 |
90 | Enter your shorthand token
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 | 40
99 | 130
100 | 301
101 | 101
102 |
103 |
104 |
105 | Upload Save
106 |
107 |
108 |
109 |
110 |
111 | 40
112 | 10
113 | 131
114 | 16
115 |
116 |
117 |
118 | Upload a save below.
119 |
120 |
121 |
122 |
123 |
124 | 40
125 | 50
126 | 311
127 | 16
128 |
129 |
130 |
131 |
132 | .AppleSystemUIFont
133 | false
134 | false
135 | false
136 | false
137 | false
138 |
139 |
140 |
141 | Game ID
142 |
143 |
144 |
145 |
146 |
147 | 40
148 | 70
149 | 301
150 | 32
151 |
152 |
153 | -
154 |
155 | test option 1
156 |
157 |
158 |
159 |
160 |
161 |
162 | 10
163 | 230
164 | 361
165 | 21
166 |
167 |
168 |
169 |
170 | .AppleSystemUIFont
171 | 11
172 | false
173 |
174 |
175 |
176 |
177 |
178 |
179 | Qt::AlignCenter
180 |
181 |
182 |
183 |
184 |
185 | 50
186 | 100
187 | 281
188 | 16
189 |
190 |
191 |
192 |
193 | .AppleSystemUIFont
194 | 11
195 |
196 |
197 |
198 | Last uploaded to server
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 | 40
207 | 180
208 | 301
209 | 71
210 |
211 |
212 |
213 | Download Save
214 |
215 |
216 |
217 |
218 |
219 | 40
220 | 30
221 | 301
222 | 51
223 |
224 |
225 |
226 | Fetch Saves
227 |
228 |
229 |
230 |
231 |
232 | 40
233 | 100
234 | 301
235 | 16
236 |
237 |
238 |
239 |
240 | .AppleSystemUIFont
241 | false
242 | false
243 | false
244 | false
245 | false
246 |
247 |
248 |
249 | Game ID
250 |
251 |
252 |
253 |
254 |
255 | 40
256 | 120
257 | 301
258 | 32
259 |
260 |
261 |
262 |
263 |
264 |
265 | 140
266 | 80
267 | 201
268 | 31
269 |
270 |
271 |
272 | Clear old saves on this system
273 |
274 |
275 |
276 |
277 |
278 | 40
279 | 10
280 | 161
281 | 16
282 |
283 |
284 |
285 | Download a save below.
286 |
287 |
288 |
289 |
290 |
291 | 10
292 | 250
293 | 361
294 | 21
295 |
296 |
297 |
298 |
299 | .AppleSystemUIFont
300 | 11
301 | false
302 |
303 |
304 |
305 |
306 |
307 |
308 | Qt::AlignCenter
309 |
310 |
311 |
312 |
313 |
314 | 50
315 | 150
316 | 281
317 | 16
318 |
319 |
320 |
321 |
322 | .AppleSystemUIFont
323 | 11
324 |
325 |
326 |
327 | Last uploaded to server
328 |
329 |
330 |
331 |
332 |
333 |
334 | true
335 |
336 |
337 |
338 | 20
339 | 20
340 | 311
341 | 91
342 |
343 |
344 |
345 |
346 |
347 | 10
348 | 50
349 | 61
350 | 20
351 |
352 |
353 |
354 | saves
355 |
356 |
357 |
358 |
359 |
360 | 80
361 | 50
362 | 71
363 | 20
364 |
365 |
366 |
367 | extdata
368 |
369 |
370 |
371 |
372 |
373 | 170
374 | 40
375 | 141
376 | 51
377 |
378 |
379 |
380 | Switch to Download
381 |
382 |
383 |
384 |
385 |
386 | 10
387 | 0
388 | 301
389 | 41
390 |
391 |
392 |
393 |
394 | .AppleSystemUIFont
395 | 12
396 | false
397 |
398 |
399 |
400 | Game ID Menu
401 |
402 |
403 |
404 |
405 |
406 | true
407 |
408 |
409 |
410 | 30
411 | -1000
412 | 341
413 | 200
414 |
415 |
416 |
417 |
418 |
419 |
420 | :/banner/citraholdminibanner.png
421 |
422 |
423 |
424 |
442 |
443 |
444 |
445 | Information
446 |
447 |
448 |
449 |
450 | Open Config Folder
451 |
452 |
453 |
454 |
455 |
456 |
457 |
458 |
459 |
--------------------------------------------------------------------------------
/gameidmanager.cpp:
--------------------------------------------------------------------------------
1 | #include "gameidmanager.h"
2 | #include "ui_gameidmanager.h"
3 | #include "ConfigManager.h"
4 | #include "CitraholdServer.h"
5 | #include "mainwindow.h"
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | GameIDManager::GameIDManager(QWidget *parent, ConfigManager *configManager) : QDialog(parent), ui(new Ui::GameIDManager)
14 | {
15 | ui->setupUi(this);
16 |
17 | this->configManager = configManager;
18 |
19 | connect(ui->resetDirectoryButton, &QPushButton::clicked, this, &GameIDManager::resetDirectory);
20 | connect(ui->extdataRadio, &QRadioButton::clicked, this, &GameIDManager::handleSaveExtdataRadios);
21 | connect(ui->saveRadio, &QRadioButton::clicked, this, &GameIDManager::handleSaveExtdataRadios);
22 | connect(ui->selectDirectoryButton, &QPushButton::clicked, this, [&]
23 | { handleDirectoryButton(true); });
24 | connect(ui->directoryText, &QPlainTextEdit::textChanged, this, [&]
25 | { handleDirectoryButton(false); });
26 | connect(ui->gameIDText, &QPlainTextEdit::textChanged, this, &GameIDManager::handleChangeToNew);
27 | connect(ui->addGameIDButton, &QPushButton::clicked, this, &GameIDManager::addGameIDToFile);
28 | connect(ui->switchModeButton, &QPushButton::clicked, this, &GameIDManager::switchBetweenNewAndExisting);
29 | connect(ui->existingDirectoryText, &QPlainTextEdit::textChanged, this, &GameIDManager::handleChangeToExisting);
30 | connect(ui->existingGameIDText, &QPlainTextEdit::textChanged, this, &GameIDManager::handleChangeToExisting);
31 | connect(ui->gameIDComboBox, &QComboBox::currentTextChanged, this, &GameIDManager::handleExistingGameIDSelection);
32 | connect(ui->updateGameIDButton, &QPushButton::clicked, this, [&]
33 | { addGameIDToFile(true); });
34 | connect(ui->existingDirectoryButton, &QPushButton::clicked, this, [&]
35 | { handleDirectoryButton(true, true); });
36 | connect(ui->deleteGameIDButton, &QPushButton::clicked, this, &GameIDManager::handleDeleteExistingGameID);
37 | connect(ui->openDirectoryButton, &QPushButton::clicked, this, [&]
38 | { QDesktopServices::openUrl(QUrl::fromLocalFile(ui->existingDirectoryText->toPlainText())); });
39 |
40 | resetDirectory();
41 | ui->addGameIDButton->setDisabled(true);
42 | ui->stackedWidget->setCurrentIndex(0);
43 |
44 | this->setHidden(true);
45 | }
46 |
47 | GameIDManager::~GameIDManager()
48 | {
49 | delete ui;
50 | }
51 |
52 | bool GameIDManager::validGameID(QString gameID)
53 | {
54 | QRegularExpression regex("^[a-zA-Z0-9_]+$");
55 | return (gameID.length() <= 32 && (regex.match(gameID)).hasMatch());
56 | }
57 |
58 | void GameIDManager::resetDirectory(bool doubleCheck)
59 | {
60 |
61 | if (!doubleCheck || (doubleCheck && ((ui->directoryText->toPlainText().isEmpty() || ui->directoryText->toPlainText() == QString::fromStdString(this->configManager->getLikelyCitraDirectory(UploadType::SAVES).u8string()) || ui->directoryText->toPlainText() == QString::fromStdString(this->configManager->getLikelyCitraDirectory(UploadType::EXTDATA).u8string())))))
62 | {
63 | ui->directoryText->setPlainText(QString::fromStdString(this->configManager->getLikelyCitraDirectory(uploadType).u8string()));
64 | }
65 | }
66 |
67 | void GameIDManager::setGameID(QString gameID)
68 | {
69 | ui->gameIDText->setPlainText(gameID);
70 | if (ui->stackedWidget->currentIndex() == 1)
71 | {
72 | switchBetweenNewAndExisting();
73 | }
74 | }
75 |
76 | void GameIDManager::setUploadType(UploadType uploadType, bool ignoreOther)
77 | {
78 | qDebug() << "Setting upload type to " << uploadType;
79 | this->uploadType = uploadType;
80 | if (uploadType == UploadType::SAVES)
81 | {
82 | ui->saveRadio->setChecked(true);
83 | ui->extdataRadio->setChecked(false);
84 | }
85 | else if (uploadType == UploadType::EXTDATA)
86 | {
87 | ui->saveRadio->setChecked(false);
88 | ui->extdataRadio->setChecked(true);
89 | }
90 |
91 | if (ui->stackedWidget->currentIndex() == 1)
92 | {
93 | retrieveGameIDList();
94 | }
95 |
96 | if (!ignoreOther)
97 | {
98 | ((MainWindow *)parentWidget())->setUploadType(uploadType);
99 | }
100 | resetDirectory(true);
101 | }
102 |
103 | void GameIDManager::handleSaveExtdataRadios()
104 | {
105 | if (
106 | !this->isHidden() && ((
107 | !ui->directoryText->toPlainText().isEmpty() &&
108 | ui->directoryText->toPlainText() != QString::fromStdString(this->configManager->getLikelyCitraDirectory(UploadType::SAVES).u8string()) &&
109 | ui->directoryText->toPlainText() != QString::fromStdString(this->configManager->getLikelyCitraDirectory(UploadType::EXTDATA).u8string())) &&
110 | ui->directoryText->toPlainText().contains("extdata") && uploadType == UploadType::EXTDATA))
111 | {
112 | QMessageBox::StandardButton reply;
113 | reply = QMessageBox::question(this, "Extdata Detected", "This might be extdata. Would you like to switch to extdata mode?", QMessageBox::Yes | QMessageBox::No);
114 | if (reply == QMessageBox::Yes)
115 | {
116 | setUploadType(UploadType::EXTDATA);
117 | }
118 | }
119 |
120 | if (ui->saveRadio->isChecked())
121 | {
122 | setUploadType(UploadType::SAVES);
123 | }
124 | else if (ui->extdataRadio->isChecked())
125 | {
126 | setUploadType(UploadType::EXTDATA);
127 | }
128 | }
129 |
130 | void GameIDManager::handleDirectoryButton(bool openSelection, bool existing)
131 | {
132 |
133 | QString directory = existing ? ui->existingDirectoryText->toPlainText() : ui->directoryText->toPlainText();
134 |
135 | if (openSelection)
136 | {
137 | qDebug() << "Opening directory selection";
138 | directory = QFileDialog::getExistingDirectory(this, tr("Open Directory"), directory);
139 | }
140 |
141 | if (directory != "")
142 | {
143 | // check if directory string contains "extdata"
144 |
145 | if (!this->isHidden() && !existing && directory.contains("extdata") && uploadType != UploadType::EXTDATA)
146 | {
147 | QMessageBox::StandardButton reply;
148 | reply = QMessageBox::question(this, "Extdata Detected", "This might be extdata. Would you like to switch to extdata mode?", QMessageBox::Yes | QMessageBox::No);
149 | if (reply == QMessageBox::Yes)
150 | {
151 | setUploadType(UploadType::EXTDATA);
152 | }
153 | }
154 |
155 | (existing) ? handleChangeToExisting() : handleChangeToNew();
156 |
157 | if (openSelection)
158 | {
159 | if (existing)
160 | {
161 | (ui->existingDirectoryText)->setPlainText(directory);
162 | }
163 | else
164 | {
165 | (ui->directoryText)->setPlainText(directory);
166 | }
167 | }
168 | }
169 | }
170 |
171 | void GameIDManager::handleChangeToNew()
172 | {
173 | bool validDirectory = (ui->directoryText->toPlainText().trimmed() != "" &&
174 | std::filesystem::exists(ui->directoryText->toPlainText().toStdString()) &&
175 | ui->directoryText->toPlainText().trimmed().toStdString() != this->configManager->getLikelyCitraDirectory(uploadType).u8string());
176 |
177 | if (
178 | ui->gameIDText->toPlainText().trimmed() != "" &&
179 | validDirectory && validGameID(ui->gameIDText->toPlainText().trimmed()))
180 | {
181 | ui->addGameIDButton->setDisabled(false);
182 | }
183 | else
184 | {
185 | ui->addGameIDButton->setDisabled(true);
186 | }
187 | }
188 |
189 | void GameIDManager::addGameIDToFile(bool existing)
190 | {
191 | QString gameID;
192 | QString directory;
193 |
194 | if (!existing)
195 | {
196 | gameID = ui->gameIDText->toPlainText();
197 | directory = ui->directoryText->toPlainText();
198 | }
199 | else
200 | {
201 | gameID = ui->existingGameIDText->toPlainText();
202 | directory = ui->existingDirectoryText->toPlainText();
203 | }
204 |
205 | if (!std::filesystem::exists(directory.toStdString()))
206 | {
207 | QMessageBox::critical(this, "Error", "Directory does not exist.");
208 | }
209 |
210 | if (!existing)
211 | {
212 | if (configManager->getGamePathFromGameID(uploadType, gameID) != "")
213 | {
214 | QMessageBox::StandardButton reply;
215 | reply = QMessageBox::question(this, "Duplicate Game ID", "You're trying to add a Game ID which already exists. Do you want to overwrite it?", QMessageBox::Yes | QMessageBox::No);
216 | if (reply == QMessageBox::Yes)
217 | {
218 | configManager->removeEntryFromGameIDFile(uploadType, gameID);
219 | }
220 | else
221 | {
222 | return;
223 | }
224 | }
225 | }
226 | else
227 | {
228 | configManager->removeEntryFromGameIDFile(uploadType, gameID);
229 | configManager->removeEntryFromGameIDFile(uploadType, ui->gameIDComboBox->currentText());
230 | }
231 |
232 | this->configManager->addEntryToGameIDFile(uploadType, gameID, directory);
233 |
234 | QString message = gameID + " successfully " + (existing ? "updated in " : "added to ") + (uploadType == UploadType::SAVES ? "saves" : "extdata") + ".";
235 | QMessageBox::information(this, "Success", message);
236 |
237 | QMessageBox::StandardButton reply = QMessageBox::question(this, "Close Game ID Menu", "Should Game ID Menu be closed now?", QMessageBox::Yes | QMessageBox::No);
238 | if (reply == QMessageBox::Yes)
239 | {
240 | this->close();
241 | }
242 |
243 | ui->gameIDText->setPlainText("");
244 | resetDirectory(false);
245 |
246 | retrieveGameIDList();
247 | ((MainWindow *)parentWidget())->retrieveGameIDList(gameID);
248 |
249 | if (existing)
250 | {
251 | ui->gameIDComboBox->setCurrentText(gameID);
252 | }
253 | }
254 |
255 | void GameIDManager::switchBetweenNewAndExisting()
256 | {
257 | ui->stackedWidget->setCurrentIndex(ui->stackedWidget->currentIndex() == 0 ? 1 : 0);
258 | if (ui->stackedWidget->currentIndex() == 0)
259 | {
260 | ui->activityLabel->setText("You are adding a new game ID");
261 | ui->switchModeButton->setText("Switch to existing Game IDs");
262 | }
263 | else
264 | {
265 | ui->activityLabel->setText("You are looking at existing game IDs");
266 | ui->switchModeButton->setText("Switch to adding a new Game ID");
267 | retrieveGameIDList();
268 | }
269 | }
270 |
271 | void GameIDManager::retrieveGameIDList()
272 | {
273 | QJsonDocument gameIDFile = configManager->getGameIDFile(uploadType);
274 |
275 | QJsonArray gameIDArray = gameIDFile["gameID"].toArray();
276 |
277 | QString previousGameID = ui->gameIDComboBox->currentText();
278 |
279 | ui->gameIDComboBox->clear();
280 |
281 | for (int i = 0; i < gameIDArray.size(); ++i)
282 | {
283 | QJsonArray gameIDEntry = gameIDArray[i].toArray();
284 | ui->gameIDComboBox->addItem(gameIDEntry[0].toString());
285 | }
286 |
287 | if ((previousGameID != "") && (ui->gameIDComboBox->findText(previousGameID) != -1))
288 | {
289 | ui->gameIDComboBox->setCurrentText(previousGameID);
290 | }
291 |
292 | ui->deleteGameIDButton->setDisabled(ui->gameIDComboBox->count() == 0);
293 | ui->existingDirectoryButton->setDisabled(ui->gameIDComboBox->count() == 0);
294 | ui->existingDirectoryText->setDisabled(ui->gameIDComboBox->count() == 0);
295 | ui->existingGameIDText->setDisabled(ui->gameIDComboBox->count() == 0);
296 | ui->openDirectoryButton->setDisabled(ui->gameIDComboBox->count() == 0);
297 |
298 | handleExistingGameIDSelection();
299 | }
300 |
301 | void GameIDManager::handleExistingGameIDSelection()
302 | {
303 | QString gameID = ui->gameIDComboBox->currentText();
304 | std::filesystem::path directory = configManager->getGamePathFromGameID(uploadType, gameID);
305 |
306 | ui->existingGameIDText->setPlainText(gameID);
307 | ui->existingDirectoryText->setPlainText(directory.string().c_str());
308 | ui->updateGameIDButton->setDisabled(true);
309 | }
310 |
311 | void GameIDManager::handleChangeToExisting()
312 | {
313 | bool validDirectory = (ui->existingDirectoryText->toPlainText().trimmed() != "" &&
314 | ui->existingDirectoryText->toPlainText() != ui->directoryText->toPlainText() &&
315 | std::filesystem::exists(ui->existingDirectoryText->toPlainText().toStdString()));
316 |
317 | ui->openDirectoryButton->setDisabled(!validDirectory);
318 |
319 | if (
320 | (
321 | ui->existingGameIDText->toPlainText().trimmed() != "" &&
322 | ui->existingGameIDText->toPlainText() != ui->gameIDComboBox->currentText()) ||
323 | ((std::filesystem::exists(ui->existingDirectoryText->toPlainText().toStdString()))
324 | && validGameID(ui->existingGameIDText->toPlainText().trimmed()))
325 | )
326 | {
327 | ui->updateGameIDButton->setDisabled(false);
328 | }
329 | else
330 | {
331 | ui->updateGameIDButton->setDisabled(true);
332 | }
333 | }
334 |
335 | void GameIDManager::handleDeleteExistingGameID()
336 | {
337 | QString gameID = ui->gameIDComboBox->currentText();
338 | QMessageBox::StandardButton reply;
339 | reply = QMessageBox::question(this, "Delete Game ID", "Are you sure you want to delete " + gameID + " from " + (uploadType == UploadType::EXTDATA ? "extdata?" : "saves?"), QMessageBox::Yes | QMessageBox::No);
340 | if (reply == QMessageBox::Yes)
341 | {
342 | configManager->removeEntryFromGameIDFile(uploadType, gameID);
343 | retrieveGameIDList();
344 | }
345 | }
346 |
--------------------------------------------------------------------------------
/ConfigManager.cpp:
--------------------------------------------------------------------------------
1 | #include "ConfigManager.h"
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include "CitraholdServer.h"
7 |
8 | ConfigManager::ConfigManager()
9 | {
10 | // Constructor: Initialise the directory paths based on the platform
11 | initialise();
12 | }
13 |
14 | std::filesystem::path ConfigManager::getSaveDirectory() const
15 | {
16 | return saveDirectory;
17 | }
18 |
19 | std::filesystem::path ConfigManager::getLikelyCitraDirectory(UploadType type)
20 | {
21 | std::filesystem::path directory = citraDirectory;
22 |
23 | if (type == UploadType::SAVES)
24 | {
25 |
26 | directory /= "title";
27 | }
28 | else
29 | {
30 | directory /= "extdata";
31 | }
32 |
33 | return directory;
34 | }
35 |
36 | void ConfigManager::setToken(QString token)
37 | {
38 | QJsonDocument config = getConfig();
39 |
40 | QJsonObject configObject = config.object();
41 |
42 | configObject["token"] = token;
43 |
44 | config = QJsonDocument(configObject);
45 |
46 | updateConfigFile(config);
47 | }
48 |
49 | QJsonDocument ConfigManager::getConfig()
50 | {
51 |
52 | std::filesystem::path filePath = saveDirectory / "config.json";
53 |
54 | std::fstream file(filePath, std::ios::in | std::ios::out);
55 | if (!file)
56 | {
57 | file.open(filePath, std::ios::out);
58 |
59 | QJsonObject json;
60 | json["serverAddress"] = "https://api.citrahold.com";
61 | json["token"] = "invalid";
62 | json["_note"] = "keep your token private!";
63 | json["defaultCitraDirectory"] = QString(citraDirectory.string().c_str());
64 | json["lastUploadedGameID"] = "";
65 | json["lastDownloadedGameID"] = "";
66 | json["lastType"] = "SAVES";
67 | json["lastMode"] = "UPLOAD";
68 |
69 | QJsonDocument jsonDoc(json);
70 | QString jsonString = jsonDoc.toJson();
71 |
72 | file << jsonString.toStdString();
73 | file.close();
74 |
75 | return jsonDoc;
76 | }
77 | else
78 | {
79 | file.seekp(0);
80 | std::string fileContents((std::istreambuf_iterator(file)), std::istreambuf_iterator());
81 | file.close();
82 | return QJsonDocument::fromJson(fileContents.c_str());
83 | }
84 | }
85 |
86 | QDateTime ConfigManager::getLastDownloadTime(UploadType type, QString gameID) {
87 | QJsonObject gameIDFileAsObject = getGameIDFile(type).object();
88 |
89 | QJsonArray gameIDArray = gameIDFileAsObject["gameID"].toArray();
90 |
91 | for (int i = 0; i < gameIDArray.size(); ++i)
92 | {
93 | QJsonValue value = gameIDArray.at(i);
94 | if (gameID == value[0].toString())
95 | {
96 | return QDateTime::fromString(value[3].toString(), Qt::ISODate);
97 | }
98 | }
99 |
100 | return QDateTime::fromString("1970-01-01T00:00:00", Qt::ISODate);
101 | }
102 |
103 | void ConfigManager::setLastDownloadTime(UploadType type, QString gameID, QDateTime time) {
104 | QJsonDocument gameIDFile = getGameIDFile(type);
105 |
106 | QJsonArray gameIDArray = gameIDFile["gameID"].toArray();
107 |
108 | for (int i = 0; i < gameIDArray.size(); ++i)
109 | {
110 | QJsonValue value = gameIDArray.at(i);
111 | if (gameID == value[0].toString())
112 | {
113 | QJsonArray newEntry;
114 | newEntry.append(value[0].toString());
115 | newEntry.append(value[1].toString());
116 | newEntry.append(value[2].toString());
117 | newEntry.append(time.toString(Qt::ISODate));
118 |
119 | gameIDArray.replace(i, newEntry);
120 | break;
121 | }
122 | }
123 |
124 | QJsonObject gameIDFileAsObject = gameIDFile.object();
125 | gameIDFileAsObject["gameID"] = gameIDArray;
126 | gameIDFile = QJsonDocument(gameIDFileAsObject);
127 | updateGameIDFile(type, gameIDFile);
128 | }
129 |
130 | QJsonDocument ConfigManager::getGameIDFile(UploadType type)
131 | {
132 |
133 | std::filesystem::path filePath = saveDirectory / (type == UploadType::SAVES ? "gameIDSaves.json" : "gameIDExtdata.json");
134 |
135 | std::fstream file(filePath, std::ios::in | std::ios::out);
136 | if (!file)
137 | {
138 | file.open(filePath, std::ios::out);
139 |
140 | QJsonObject json;
141 | json["gameID"] = QJsonArray();
142 | QJsonDocument jsonDoc(json);
143 | QString jsonString = jsonDoc.toJson();
144 |
145 | file << jsonString.toStdString();
146 | file.close();
147 |
148 | return jsonDoc;
149 | }
150 | else
151 | {
152 | file.seekp(0);
153 | std::string fileContents((std::istreambuf_iterator(file)), std::istreambuf_iterator());
154 | file.close();
155 |
156 | QJsonDocument fileAsObject = QJsonDocument::fromJson(fileContents.c_str());
157 | return fileAsObject;
158 | }
159 | }
160 |
161 | void ConfigManager::updateGameIDFile(UploadType type, QJsonDocument newFile)
162 | {
163 |
164 | std::filesystem::path filePath = saveDirectory / (type == UploadType::SAVES ? "gameIDSaves.json" : "gameIDExtdata.json");
165 |
166 | std::ofstream file(filePath);
167 |
168 | if (file.is_open())
169 | {
170 |
171 | QString jsonString = newFile.toJson();
172 | file << jsonString.toStdString();
173 | file.close();
174 | }
175 | else
176 | {
177 | qDebug() << "Failed to open the file for writing.";
178 | }
179 | }
180 |
181 | void ConfigManager::updateConfigProperty(QString property, QJsonValue value)
182 | {
183 | QJsonDocument config = getConfig();
184 |
185 | QJsonObject configObject = config.object();
186 |
187 | configObject[property] = value;
188 |
189 | config = QJsonDocument(configObject);
190 |
191 | updateConfigFile(config);
192 | }
193 |
194 | QString ConfigManager::getConfigProperty(QString property)
195 | {
196 | QJsonDocument config = getConfig();
197 |
198 | QJsonObject configObject = config.object();
199 |
200 | return configObject[property].toString();
201 | }
202 |
203 | void ConfigManager::addEntryToGameIDFile(UploadType type, QString gameID, QString gameName)
204 | {
205 |
206 | QJsonDocument gameIDFile = getGameIDFile(type);
207 |
208 | QJsonArray gameIDArray = gameIDFile["gameID"].toArray();
209 |
210 | qDebug() << gameID;
211 | if (getGamePathFromGameID(type, gameID.trimmed()) != "")
212 | {
213 | qDebug() << "Game ID already exists!";
214 | return;
215 | }
216 |
217 | QJsonArray newEntry;
218 | newEntry.append(gameID.trimmed());
219 | newEntry.append(gameName.trimmed());
220 |
221 | gameIDArray.append(newEntry);
222 |
223 | QJsonObject gameIDFileAsObject = gameIDFile.object();
224 | gameIDFileAsObject["gameID"] = gameIDArray;
225 | gameIDFile = QJsonDocument(gameIDFileAsObject);
226 | updateGameIDFile(type, gameIDFile);
227 |
228 |
229 | }
230 |
231 | void ConfigManager::updateConfigFile(QJsonDocument newConfig)
232 | {
233 | std::filesystem::path filePath = saveDirectory / "config.json";
234 |
235 | std::ofstream file(filePath);
236 |
237 | if (file.is_open())
238 | {
239 |
240 | QString jsonString = newConfig.toJson();
241 | file << jsonString.toStdString();
242 | file.close();
243 | }
244 | else
245 | {
246 | qDebug() << "Failed to open the file for writing.";
247 | }
248 | }
249 |
250 | void ConfigManager::initialise()
251 | {
252 | // Initialise the directory paths based on the platform
253 | #ifdef _WIN32
254 | // Windows
255 | saveDirectory = std::getenv("APPDATA");
256 | saveDirectory /= "Citrahold";
257 |
258 | citraDirectory = std::getenv("APPDATA");
259 | citraDirectory /= "Citra";
260 |
261 | #elif __APPLE__
262 | // macOS
263 | saveDirectory = std::getenv("HOME");
264 | saveDirectory /= ".config";
265 | saveDirectory /= "Citrahold";
266 |
267 | citraDirectory = std::getenv("HOME");
268 | citraDirectory /= "Library";
269 | citraDirectory /= "Application Support";
270 | citraDirectory /= "Citra";
271 |
272 | #else
273 | // Assume all other platforms are Linux
274 | saveDirectory = std::getenv("HOME");
275 | saveDirectory /= ".config";
276 | saveDirectory /= "Citrahold";
277 |
278 | citraDirectory = std::getenv("HOME");
279 | citraDirectory /= ".local";
280 | citraDirectory /= "share";
281 | citraDirectory /= "citra-emu";
282 |
283 | #endif
284 |
285 | citraDirectory /= "sdmc";
286 | citraDirectory /= "Nintendo 3DS";
287 | citraDirectory /= "00000000000000000000000000000000";
288 | citraDirectory /= "00000000000000000000000000000000";
289 |
290 | if (!std::filesystem::exists(saveDirectory))
291 | {
292 | std::filesystem::create_directories(saveDirectory);
293 | }
294 |
295 | if (!std::filesystem::exists(saveDirectory / "oldSaves"))
296 | {
297 | std::filesystem::create_directories(saveDirectory / "oldSaves");
298 | }
299 |
300 | if (!std::filesystem::exists(saveDirectory / "oldExtdata"))
301 | {
302 | std::filesystem::create_directories(saveDirectory / "oldExtdata");
303 | }
304 |
305 | if (!std::filesystem::exists(citraDirectory))
306 | {
307 | citraDirectory = ""; // Return an empty path if the Citra directory doesn't exist
308 | }
309 |
310 | QJsonDocument config = getConfig();
311 | if (getConfigProperty("defaultCitraDirectory").toStdString() != citraDirectory)
312 | {
313 | citraDirectory = std::filesystem::path(getConfigProperty("defaultCitraDirectory").toStdString());
314 | }
315 |
316 | getGameIDFile(UploadType::EXTDATA);
317 | getGameIDFile(UploadType::SAVES);
318 | }
319 |
320 | std::filesystem::path ConfigManager::getGamePathFromGameID(UploadType type, QString gameID)
321 | {
322 |
323 | QJsonObject gameIDFileAsObject = getGameIDFile(type).object();
324 |
325 | QJsonArray gameIDArray = gameIDFileAsObject["gameID"].toArray();
326 |
327 | for (int i = 0; i < gameIDArray.size(); ++i)
328 | {
329 | QJsonValue value = gameIDArray.at(i);
330 | if (gameID == value[0].toString())
331 | {
332 | return std::filesystem::path(value[1].toString().toStdString());
333 | }
334 | }
335 |
336 | return "";
337 | }
338 |
339 | QDateTime ConfigManager::getLastUploadTime(UploadType type, QString gameID) {
340 | QJsonObject gameIDFileAsObject = getGameIDFile(type).object();
341 |
342 | QJsonArray gameIDArray = gameIDFileAsObject["gameID"].toArray();
343 |
344 | for (int i = 0; i < gameIDArray.size(); ++i)
345 | {
346 | QJsonValue value = gameIDArray.at(i);
347 | if (gameID == value[0].toString())
348 | {
349 | return QDateTime::fromString(value[2].toString(), Qt::ISODate);
350 | }
351 | }
352 |
353 | return QDateTime::fromString("1970-01-01T00:00:00", Qt::ISODate);
354 | }
355 |
356 | void ConfigManager::setLastUploadTime(UploadType type, QString gameID, QDateTime time) {
357 | QJsonDocument gameIDFile = getGameIDFile(type);
358 |
359 | QJsonArray gameIDArray = gameIDFile["gameID"].toArray();
360 |
361 | for (int i = 0; i < gameIDArray.size(); ++i)
362 | {
363 | QJsonValue value = gameIDArray.at(i);
364 | if (gameID == value[0].toString())
365 | {
366 | QJsonArray newEntry;
367 | newEntry.append(value[0].toString());
368 | newEntry.append(value[1].toString());
369 | newEntry.append(time.toString(Qt::ISODate));
370 | newEntry.append(value[3].toString());
371 |
372 | gameIDArray.replace(i, newEntry);
373 | break;
374 | }
375 | }
376 |
377 | QJsonObject gameIDFileAsObject = gameIDFile.object();
378 | gameIDFileAsObject["gameID"] = gameIDArray;
379 | gameIDFile = QJsonDocument(gameIDFileAsObject);
380 | updateGameIDFile(type, gameIDFile);
381 | }
382 |
383 | QString ConfigManager::getToken()
384 | {
385 | return getConfig()["token"].toString();
386 | }
387 |
388 | bool ConfigManager::loggedIn()
389 | {
390 | return userID != "invalid";
391 | }
392 |
393 | bool ConfigManager::copyDirectory(const std::filesystem::path &source, const std::filesystem::path &destination)
394 | {
395 | try
396 | {
397 | if (!std::filesystem::exists(source) || !std::filesystem::is_directory(source))
398 | {
399 | qDebug() << "Source directory doesn't exist or is not a directory.";
400 | return false;
401 | }
402 |
403 | if (!std::filesystem::exists(destination))
404 | {
405 | if (!std::filesystem::create_directories(destination))
406 | {
407 | qDebug() << "Failed to create the destination directory.";
408 | return false;
409 | }
410 | }
411 |
412 | for (const auto &entry : std::filesystem::directory_iterator(source))
413 | {
414 | const std::filesystem::path entryPath = entry.path();
415 | const std::filesystem::path destinationPath = destination / entryPath.filename();
416 |
417 | if (std::filesystem::is_directory(entryPath))
418 | {
419 | if (!copyDirectory(entryPath, destinationPath))
420 | {
421 | return false;
422 | }
423 | }
424 | else if (std::filesystem::is_regular_file(entryPath))
425 | {
426 | std::filesystem::copy_file(entryPath, destinationPath, std::filesystem::copy_options::overwrite_existing);
427 | }
428 | }
429 | }
430 | catch (const std::exception &e)
431 | {
432 | std::cerr << "An error occurred: " << e.what() << std::endl;
433 | return false;
434 | }
435 |
436 | return true;
437 | }
438 |
439 | std::filesystem::path ConfigManager::getOldSaveDirectory(UploadType type) const
440 | {
441 | return saveDirectory / ((type == UploadType::SAVES) ? "oldSaves" : "oldExtdata");
442 | }
443 |
444 | void ConfigManager::removeEntryFromGameIDFile(UploadType type, QString gameID) {
445 | QJsonDocument gameIDFile = getGameIDFile(type);
446 |
447 | QJsonArray gameIDArray = gameIDFile["gameID"].toArray();
448 |
449 | for (int i = 0; i < gameIDArray.size(); ++i)
450 | {
451 | QJsonValue value = gameIDArray.at(i);
452 | if (gameID == value[0].toString())
453 | {
454 | gameIDArray.removeAt(i);
455 | break;
456 | }
457 | }
458 |
459 | QJsonObject gameIDFileAsObject = gameIDFile.object();
460 | gameIDFileAsObject["gameID"] = gameIDArray;
461 | gameIDFile = QJsonDocument(gameIDFileAsObject);
462 | updateGameIDFile(type, gameIDFile);
463 | }
--------------------------------------------------------------------------------
/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | #include "gameidmanager.h"
29 | #include "about.h"
30 |
31 | MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
32 | {
33 | configManager = new ConfigManager();
34 |
35 | citraholdServer = new CitraholdServer(
36 | configManager->getConfigProperty("serverAddress"),
37 | configManager->getConfigProperty("token"));
38 |
39 | ui->setupUi(this);
40 |
41 | gameIDManager = new GameIDManager(this, configManager);
42 | aboutWindow = new About(this);
43 |
44 | ui->statusbar->showMessage("Not logged in.");
45 |
46 | ui->selectionBox->hide();
47 |
48 | configManager = new ConfigManager();
49 |
50 | connect(
51 | ui->verifyButton, &QPushButton::clicked,
52 | this, &MainWindow::handleVerifyButtonClicked);
53 |
54 | connect(
55 | ui->tokenText, &QPlainTextEdit::textChanged,
56 | this, &MainWindow::manageTokenTextEdit);
57 |
58 | connect(ui->uploadButton, &QPushButton::clicked, this, &MainWindow::handleUploadButton);
59 |
60 | connect(ui->selectPreviousGameIDsButton, &QPushButton::clicked, this, &MainWindow::openGameIDSelector);
61 |
62 | connect(ui->extdataRadio, &QRadioButton::clicked, this, &MainWindow::handleSaveExtdataRadios);
63 | connect(ui->saveRadio, &QRadioButton::clicked, this, &MainWindow::handleSaveExtdataRadios);
64 | connect(ui->fetchButton, &QPushButton::clicked, this, &MainWindow::handleServerFetch);
65 |
66 | connect(ui->downloadButton, &QPushButton::clicked, this, &MainWindow::handleDownloadButton);
67 |
68 | connect(ui->clearOldSavesButton, &QPushButton::clicked, this, &MainWindow::handleClearOldSavesButton);
69 |
70 | connect(ui->switchModeButton, &QPushButton::clicked, this, &MainWindow::handleToggleModeButton);
71 |
72 | connect(ui->aboutCitraholdOption, &QAction::triggered, this, &MainWindow::openAboutWindow);
73 | connect(ui->openConfigFolderOption, &QAction::triggered, this, &MainWindow::openConfigFolder);
74 | connect(ui->aboutCitraholdOption, &QAction::triggered, this, &MainWindow::openAboutWindow);
75 |
76 | connect(ui->uploadGameIDComboBox, &QComboBox::currentTextChanged, this, [&]
77 | { MainWindow::changeLastUploadText ();
78 | MainWindow::changeLastServerUploadText(true); });
79 |
80 | connect(ui->downloadGameIDComboBox, &QComboBox::currentTextChanged, this, [&]
81 | {
82 | MainWindow::changeLastDownloadText();
83 | MainWindow::changeLastServerUploadText(false); });
84 |
85 | QString userID = citraholdServer->verifyTokenToSetUserID(configManager->getToken());
86 | configManager->userID = userID;
87 |
88 | if (configManager->loggedIn())
89 | {
90 |
91 | handleSuccessfulLogin();
92 | }
93 | else
94 | {
95 | ui->stackedWidget->setCurrentWidget(ui->loginWidget);
96 | ui->selectionBox->hide();
97 | ui->citraholdLogo->show();
98 | // this is just because it's hidden in the designer
99 | ui->citraholdLogo->move(ui->citraholdLogo->x(), 30);
100 | }
101 |
102 | if (!citraholdServer->checkServerIsOnline())
103 | {
104 | showErrorBox("The server is inaccessible at this time. Please try again later.");
105 | }
106 | else
107 | {
108 | QStringList versions = citraholdServer->getSoftwareVersions();
109 |
110 | if (!versions.contains("v" + QCoreApplication::applicationVersion()) && (configManager->getConfigProperty("ignoreVersion") != versions[0]))
111 | {
112 | QMessageBox msgBox;
113 | QString message = "There is a new version of Citrahold PC available (" + versions[0] + "). Would you like to download it?";
114 | msgBox.setText(tr(message.toStdString().c_str()));
115 | QAbstractButton *pButtonYes = msgBox.addButton(tr("Yes"), QMessageBox::YesRole);
116 | msgBox.addButton(tr("Not now"), QMessageBox::NoRole);
117 | QAbstractButton *pButtonIgnore = msgBox.addButton(tr("Don't remind me"), QMessageBox::NoRole);
118 |
119 | msgBox.exec();
120 |
121 | if (msgBox.clickedButton() == pButtonYes)
122 | {
123 | QDesktopServices::openUrl(QUrl("https://github.com/regimensocial/citraholdUI/releases/latest"));
124 | }
125 | else if (msgBox.clickedButton() == pButtonIgnore)
126 | {
127 | configManager->updateConfigProperty("ignoreVersion", versions[0]);
128 | }
129 | }
130 | }
131 |
132 | #ifdef _WIN32
133 | // Windows only
134 |
135 | QFont font;
136 | font.setPointSize(8);
137 |
138 | ui->downloadLastUploadedLabel->setFont(font);
139 | ui->uploadLastUploadedLabel->setFont(font);
140 | ui->lastDeviceUploadLabel->setFont(font);
141 | ui->lastDeviceDownloadLabel->setFont(font);
142 | #endif
143 |
144 | retrieveGameIDList();
145 | }
146 |
147 | MainWindow::~MainWindow()
148 | {
149 | delete ui;
150 | }
151 |
152 | void MainWindow::changeLastUploadText()
153 | {
154 | QDateTime lastUploadTime = configManager->getLastUploadTime(MainWindow::savesOrExtdata(), ui->uploadGameIDComboBox->currentText());
155 |
156 | if (lastUploadTime.toString("yyyy") == "1970" || lastUploadTime.toString("yyyy") == "")
157 | {
158 | ui->lastDeviceUploadLabel->setText("");
159 | }
160 | else
161 | {
162 | ui->lastDeviceUploadLabel->setText("Last upload on this device: " + lastUploadTime.toString("dd/MM/yyyy hh:mm:ss"));
163 | ui->lastDeviceUploadLabel->setToolTip("day/month/year hour:minute:second");
164 | }
165 | }
166 |
167 | void MainWindow::changeLastDownloadText()
168 | {
169 | QDateTime lastDownloadTime = configManager->getLastDownloadTime(MainWindow::savesOrExtdata(), ui->downloadGameIDComboBox->currentText());
170 |
171 | if (lastDownloadTime.toString("yyyy") == "1970" || lastDownloadTime.toString("yyyy") == "")
172 | {
173 | ui->lastDeviceDownloadLabel->setText("");
174 | }
175 | else
176 | {
177 | ui->lastDeviceDownloadLabel->setText("Last download on this device: " + lastDownloadTime.toString("dd/MM/yyyy hh:mm:ss"));
178 | ui->lastDeviceDownloadLabel->setToolTip("day/month/year hour:minute:second");
179 | }
180 | }
181 |
182 | void MainWindow::openGameIDSelector()
183 | {
184 | gameIDManager->setModal(true);
185 | gameIDManager->setHidden(false);
186 | gameIDManager->exec();
187 | }
188 |
189 | void MainWindow::setUploadType(UploadType uploadType, bool ignoreOther)
190 | {
191 | if (uploadType == UploadType::SAVES)
192 | {
193 | ui->saveRadio->setChecked(true);
194 | ui->extdataRadio->setChecked(false);
195 | }
196 | else if (uploadType == UploadType::EXTDATA)
197 | {
198 | ui->saveRadio->setChecked(false);
199 | ui->extdataRadio->setChecked(true);
200 | }
201 |
202 | retrieveGameIDList();
203 |
204 | if (!ignoreOther)
205 | {
206 | gameIDManager->setUploadType(uploadType, true);
207 | }
208 | }
209 |
210 | void MainWindow::handleToggleModeButton()
211 | {
212 | if (ui->stackedWidget->currentIndex() == 1)
213 | {
214 | ui->stackedWidget->setCurrentWidget(ui->downloadWidget);
215 | ui->switchModeButton->setText("Switch to Upload");
216 | }
217 | else
218 | {
219 | ui->stackedWidget->setCurrentWidget(ui->uploadWidget);
220 | ui->switchModeButton->setText("Switch to Download");
221 | }
222 | }
223 |
224 | void MainWindow::manageTokenTextEdit()
225 | {
226 | if (ui->tokenText->toPlainText().length() > 36)
227 | {
228 | ui->tokenText->setPlainText(ui->tokenText->toPlainText().left(36));
229 | }
230 | }
231 |
232 | void MainWindow::handleVerifyButtonClicked()
233 | {
234 | QJsonObject data;
235 |
236 | ui->tokenText->setPlainText(ui->tokenText->toPlainText().trimmed());
237 |
238 | if (ui->tokenText->toPlainText().length() <= 6)
239 | { // Handle a shorthand token
240 |
241 | QString fullToken = citraholdServer->getTokenFromShorthandToken(ui->tokenText->toPlainText());
242 | if (fullToken != "invalid")
243 | {
244 |
245 | ui->statusbar->showMessage("Logged in.");
246 | QString userID = citraholdServer->verifyTokenToSetUserID(fullToken);
247 | if (userID != "invalid")
248 | {
249 | configManager->userID = userID;
250 | configManager->setToken(fullToken);
251 | ui->tokenText->setPlainText("");
252 | ui->tokenOutput->setText("Successfully authenticated.");
253 | handleSuccessfulLogin();
254 | }
255 | else
256 | {
257 | if (citraholdServer->checkServerIsOnline())
258 | {
259 | ui->tokenOutput->setText("You have the wrong credentials.");
260 | }
261 | else
262 | {
263 | ui->tokenOutput->setText("The server is inaccessible.");
264 | }
265 | }
266 | }
267 | else
268 | {
269 | if (citraholdServer->checkServerIsOnline())
270 | {
271 | ui->tokenOutput->setText("You have the wrong credentials.");
272 | }
273 | else
274 | {
275 | ui->tokenOutput->setText("The server is inaccessible.");
276 | }
277 | }
278 | }
279 | else // full token
280 | {
281 | QString fullToken = ui->tokenText->toPlainText();
282 | QString userID = citraholdServer->verifyTokenToSetUserID(fullToken);
283 | if (userID != "invalid")
284 | {
285 |
286 | configManager->setToken(fullToken);
287 | configManager->userID = userID;
288 |
289 | ui->tokenText->setPlainText("");
290 |
291 | ui->tokenOutput->setText("Successfully authenticated.");
292 |
293 | handleSuccessfulLogin();
294 | }
295 | else
296 | {
297 | if (citraholdServer->checkServerIsOnline())
298 | {
299 | ui->tokenOutput->setText("You have the wrong credentials.");
300 | }
301 | else
302 | {
303 | ui->tokenOutput->setText("The server is inaccessible.");
304 | }
305 | }
306 | }
307 | }
308 |
309 | void MainWindow::handleSuccessfulLogin()
310 | {
311 | ui->stackedWidget->setCurrentWidget(ui->uploadWidget);
312 | ui->selectionBox->show();
313 | ui->citraholdLogo->hide();
314 | ui->statusbar->showMessage("Logged in.");
315 | handleServerFetch();
316 |
317 | QJsonObject config = configManager->getConfig().object();
318 |
319 | if (configManager->getConfigProperty("lastMode") == "DOWNLOAD")
320 | {
321 | handleToggleModeButton();
322 | }
323 |
324 | if (configManager->getConfigProperty("lastType") == "SAVES")
325 | {
326 | setUploadType(UploadType::SAVES);
327 | }
328 | else
329 | {
330 |
331 | setUploadType(UploadType::EXTDATA);
332 | }
333 |
334 | if ((configManager->getConfigProperty("lastDownloadedGameID") != "") && (ui->downloadGameIDComboBox->findText(configManager->getConfigProperty("lastDownloadedGameID")) != -1))
335 | {
336 | ui->downloadGameIDComboBox->setCurrentText(configManager->getConfigProperty("lastDownloadedGameID"));
337 | }
338 |
339 | if ((configManager->getConfigProperty("lastUploadedGameID") != "") && (ui->uploadGameIDComboBox->findText(configManager->getConfigProperty("lastUploadedGameID")) != -1))
340 | {
341 | ui->uploadGameIDComboBox->setCurrentText(configManager->getConfigProperty("lastUploadedGameID"));
342 | }
343 | }
344 |
345 | void MainWindow::showErrorBox(QString error)
346 | {
347 | QMessageBox errorMessage;
348 | errorMessage.setIcon(QMessageBox::Critical);
349 | errorMessage.setWindowTitle("Error");
350 | errorMessage.setText("An error has occurred.\n");
351 | if (error != "")
352 | {
353 | errorMessage.setText(errorMessage.text() + "\n" + error);
354 | }
355 |
356 | errorMessage.setStandardButtons(QMessageBox::Ok);
357 |
358 | // Show the error message dialog
359 | errorMessage.exec();
360 | }
361 |
362 | void MainWindow::showSuccessBox(QString text)
363 | {
364 | QMessageBox errorMessage;
365 | errorMessage.setWindowTitle("Success");
366 | errorMessage.setText(text);
367 | errorMessage.setStandardButtons(QMessageBox::Ok);
368 |
369 | // Show the error message dialog
370 | errorMessage.exec();
371 | }
372 |
373 | UploadType MainWindow::savesOrExtdata()
374 | {
375 | return (ui->extdataRadio->isChecked() ? UploadType::EXTDATA : UploadType::SAVES);
376 | }
377 |
378 | void MainWindow::retrieveGameIDList(QString gameID)
379 | {
380 | QJsonDocument gameIDFile = configManager->getGameIDFile(savesOrExtdata());
381 |
382 | QJsonArray gameIDArray = gameIDFile["gameID"].toArray();
383 |
384 | QString previousGameID = ui->uploadGameIDComboBox->currentText();
385 |
386 | ui->uploadGameIDComboBox->clear();
387 |
388 | for (int i = 0; i < gameIDArray.size(); ++i)
389 | {
390 | QJsonArray gameIDEntry = gameIDArray[i].toArray();
391 | ui->uploadGameIDComboBox->addItem(gameIDEntry[0].toString());
392 | }
393 |
394 | if (gameID != "")
395 | {
396 | previousGameID = gameID;
397 | }
398 |
399 | if ((previousGameID != "") && (ui->uploadGameIDComboBox->findText(previousGameID) != -1))
400 | {
401 | ui->uploadGameIDComboBox->setCurrentText(previousGameID);
402 | }
403 |
404 | ui->uploadButton->setEnabled(ui->uploadGameIDComboBox->count() > 0);
405 | }
406 |
407 | void MainWindow::handleUploadButton()
408 | {
409 |
410 | ui->uploadButton->setEnabled(false);
411 | QString gameID = ui->uploadGameIDComboBox->currentText();
412 | QString directory = configManager->getGamePathFromGameID(MainWindow::savesOrExtdata(), gameID).string().c_str();
413 |
414 | if (gameID.trimmed() == "")
415 | {
416 | showErrorBox("Invalid game ID");
417 | ui->uploadButton->setEnabled(true);
418 | return;
419 | }
420 |
421 | QDateTime lastUploadTime = configManager->getLastUploadTime(MainWindow::savesOrExtdata(), gameID);
422 | QDateTime lastDownloadTime = configManager->getLastDownloadTime(MainWindow::savesOrExtdata(), gameID);
423 | QDateTime lastServerUploadTime = citraholdServer->getLastUploadTime(MainWindow::savesOrExtdata(), gameID);
424 |
425 | if (
426 | (lastUploadTime.toString("yyyy") != "1970" && lastUploadTime.toString("yyyy") != "") &&
427 | (lastServerUploadTime.toString("yyyy") != "1970" && lastServerUploadTime.toString("yyyy") != "") &&
428 | (lastDownloadTime.toString("yyyy") != "1970" && lastDownloadTime.toString("yyyy") != ""))
429 | {
430 | if (lastServerUploadTime > lastDownloadTime)
431 | {
432 | QMessageBox msgBox;
433 | QString message = "You have uploaded to the server on a different device, but not downloaded it here.\nIt will overwrite whatever is on the server.\nAre you sure you want to upload?";
434 | msgBox.setText(tr(message.toStdString().c_str()));
435 | QAbstractButton *pButtonYes = msgBox.addButton(tr("Yes"), QMessageBox::YesRole);
436 | msgBox.addButton(tr("No"), QMessageBox::NoRole);
437 |
438 | msgBox.exec();
439 |
440 | if (msgBox.clickedButton() != pButtonYes)
441 | {
442 | ui->uploadButton->setEnabled(true);
443 | return;
444 | }
445 | }
446 | }
447 |
448 | QQueue directoriesToVisit;
449 | directoriesToVisit.enqueue(directory);
450 |
451 | QQueue allFilesFull;
452 | QQueue allFilesRelative;
453 |
454 | while (!directoriesToVisit.isEmpty())
455 | {
456 | QDir currentDir = directoriesToVisit.dequeue();
457 |
458 | QStringList entryList = currentDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
459 |
460 | for (const QString &entry : entryList)
461 | {
462 | const QString fullPath = currentDir.filePath(entry);
463 | if (QFileInfo(fullPath).isDir())
464 | {
465 | directoriesToVisit.enqueue(QDir(fullPath));
466 |
467 | QString relativePath = QDir(directory).relativeFilePath(fullPath) + "/" + "citraholdDirectoryDummy";
468 | allFilesRelative.enqueue(relativePath);
469 | }
470 | else
471 | {
472 | allFilesFull.enqueue(fullPath);
473 |
474 | QString relativePath = QDir(directory).relativeFilePath(fullPath);
475 | allFilesRelative.enqueue(relativePath);
476 | }
477 | }
478 | }
479 |
480 | QJsonArray allFilesArray;
481 |
482 | int fileSizes = 0;
483 |
484 | for (const QDir &filePath : allFilesFull)
485 | {
486 | QFile file(filePath.path());
487 |
488 | if (file.open(QIODevice::ReadOnly))
489 | {
490 | QByteArray fileData = file.readAll();
491 |
492 | fileSizes += fileData.size();
493 |
494 | file.close();
495 |
496 | // 128 MB limit, but this might be different on the server
497 | // TODO: make this configurable??????
498 | if (fileSizes > 128000000)
499 | {
500 | showErrorBox("Your save data is too large to upload.");
501 | ui->uploadButton->setEnabled(true);
502 | return;
503 | }
504 |
505 | QString base64Data = QString(fileData.toBase64());
506 |
507 | QJsonArray fileEntry;
508 | fileEntry.append(gameID + "/" + allFilesRelative.first().path());
509 | fileEntry.append(base64Data);
510 |
511 | allFilesArray.append(fileEntry);
512 | }
513 | else
514 | {
515 | qDebug() << "Failed to open file.";
516 |
517 | ui->uploadButton->setEnabled(true);
518 | }
519 |
520 | allFilesRelative.removeFirst();
521 | }
522 |
523 | qDebug() << "Total file size: " << fileSizes;
524 | int responseCode = citraholdServer->uploadMultiple(MainWindow::savesOrExtdata(), allFilesArray);
525 | qDebug() << "Response code: " << responseCode;
526 |
527 | if (responseCode == 201)
528 | {
529 | MainWindow::showSuccessBox("Upload successful!");
530 |
531 | configManager->updateConfigProperty("lastType", (savesOrExtdata() == UploadType::SAVES ? "SAVES" : "EXTDATA"));
532 | configManager->updateConfigProperty("lastUploadedGameID", ui->uploadGameIDComboBox->currentText());
533 | configManager->updateConfigProperty("lastMode", "UPLOAD");
534 |
535 | QDateTime currentDateTime = citraholdServer->getLastUploadTime(MainWindow::savesOrExtdata(), ui->uploadGameIDComboBox->currentText());
536 | configManager->setLastUploadTime(MainWindow::savesOrExtdata(), ui->uploadGameIDComboBox->currentText(), currentDateTime);
537 | configManager->setLastDownloadTime(MainWindow::savesOrExtdata(), ui->uploadGameIDComboBox->currentText(), currentDateTime.addSecs(1));
538 | changeLastUploadText();
539 |
540 | handleServerFetch();
541 | }
542 | else
543 | {
544 | showErrorBox("Something went wrong during upload, HTTP " + QString::number(responseCode));
545 | }
546 |
547 | ui->uploadButton->setEnabled(true);
548 | }
549 |
550 | void MainWindow::handleServerFetch()
551 | {
552 | QString previousGameID = ui->downloadGameIDComboBox->currentText();
553 |
554 | ui->downloadGameIDComboBox->clear();
555 | citraholdServer->updateServerGameIDVariables();
556 |
557 | QVector *serverGameIDs = (MainWindow::savesOrExtdata() == UploadType::SAVES) ? &citraholdServer->serverGameIDSaves : &citraholdServer->serverGameIDExtdata;
558 |
559 | ui->downloadButton->setEnabled((serverGameIDs->size() > 0));
560 |
561 | for (const QString &key : *serverGameIDs)
562 | {
563 | ui->downloadGameIDComboBox->addItem(key);
564 | }
565 |
566 | if (ui->downloadGameIDComboBox->findText(previousGameID) != -1)
567 | {
568 | ui->downloadGameIDComboBox->setCurrentText(previousGameID);
569 | }
570 |
571 | changeLastServerUploadText(true);
572 |
573 | if (ui->uploadGameIDComboBox->currentText() == ui->downloadGameIDComboBox->currentText())
574 | {
575 | changeLastServerUploadText(false);
576 | }
577 | }
578 |
579 | void MainWindow::handleDownloadGameIDMissing()
580 | {
581 | showErrorBox("You need to add " + ui->downloadGameIDComboBox->currentText().trimmed() + " to your gameID list.");
582 | gameIDManager->setGameID(ui->downloadGameIDComboBox->currentText());
583 | openGameIDSelector();
584 | }
585 |
586 | void MainWindow::handleDownloadButton()
587 | {
588 |
589 | ui->downloadButton->setEnabled(false);
590 | QJsonArray gameIDsOnFile = configManager->getGameIDFile(MainWindow::savesOrExtdata())["gameID"].toArray();
591 |
592 | if (gameIDsOnFile.size() == 0)
593 | {
594 | handleDownloadGameIDMissing();
595 | ui->downloadButton->setEnabled(true);
596 | return;
597 | }
598 |
599 | bool gameIDpresent = false;
600 |
601 | for (int i = 0; i < gameIDsOnFile.size(); ++i)
602 | {
603 | QJsonValue value = gameIDsOnFile.at(i);
604 | if (ui->downloadGameIDComboBox->currentText() == value[0].toString())
605 | {
606 | gameIDpresent = true;
607 | }
608 | }
609 |
610 | if (!gameIDpresent)
611 | {
612 | handleDownloadGameIDMissing();
613 | ui->downloadButton->setEnabled(true);
614 | return;
615 | }
616 | else
617 | {
618 |
619 | QDateTime lastUploadTime = configManager->getLastUploadTime(MainWindow::savesOrExtdata(), ui->downloadGameIDComboBox->currentText());
620 | QDateTime lastDownloadTime = configManager->getLastDownloadTime(MainWindow::savesOrExtdata(), ui->downloadGameIDComboBox->currentText());
621 | QDateTime lastServerUploadTime = citraholdServer->getLastUploadTime(MainWindow::savesOrExtdata(), ui->downloadGameIDComboBox->currentText());
622 |
623 | if (
624 | (lastUploadTime.toString("yyyy") != "1970" && lastUploadTime.toString("yyyy") != "") &&
625 | (lastServerUploadTime.toString("yyyy") != "1970" && lastServerUploadTime.toString("yyyy") != "") &&
626 | (lastDownloadTime.toString("yyyy") != "1970" && lastDownloadTime.toString("yyyy") != ""))
627 | {
628 | if (lastDownloadTime > lastServerUploadTime)
629 | {
630 | QMessageBox msgBox;
631 | QString message = "You've already downloaded this save.\nAre you sure you want to download it again? It will overwrite any changes you've made.";
632 | msgBox.setText(tr(message.toStdString().c_str()));
633 | QAbstractButton *pButtonYes = msgBox.addButton(tr("Yes"), QMessageBox::YesRole);
634 | msgBox.addButton(tr("No"), QMessageBox::NoRole);
635 |
636 | msgBox.exec();
637 |
638 | if (msgBox.clickedButton() != pButtonYes)
639 | {
640 | ui->downloadButton->setEnabled(true);
641 | return;
642 | }
643 | }
644 | }
645 |
646 | QDateTime currentDateTime = QDateTime::currentDateTime();
647 | QString formattedDateTime = currentDateTime.toString("yyyyMMdd-hhmmss");
648 |
649 | configManager->copyDirectory(
650 | configManager->getGamePathFromGameID(MainWindow::savesOrExtdata(), ui->downloadGameIDComboBox->currentText()),
651 | (configManager->getOldSaveDirectory(MainWindow::savesOrExtdata()) / std::filesystem::path((ui->downloadGameIDComboBox->currentText() + "-" + formattedDateTime).toStdString())));
652 |
653 | std::filesystem::remove_all(configManager->getGamePathFromGameID(MainWindow::savesOrExtdata(), ui->downloadGameIDComboBox->currentText()));
654 | if (!std::filesystem::exists(configManager->getGamePathFromGameID(MainWindow::savesOrExtdata(), ui->downloadGameIDComboBox->currentText())))
655 | {
656 | std::filesystem::create_directories(configManager->getGamePathFromGameID(MainWindow::savesOrExtdata(), ui->downloadGameIDComboBox->currentText()));
657 | }
658 |
659 | int downloadResponse = citraholdServer->downloadMultiple(
660 | MainWindow::savesOrExtdata(),
661 | ui->downloadGameIDComboBox->currentText(),
662 | configManager->getGamePathFromGameID(MainWindow::savesOrExtdata(), ui->downloadGameIDComboBox->currentText()));
663 |
664 | if (downloadResponse)
665 | {
666 | showSuccessBox("Download successful!");
667 |
668 | configManager->updateConfigProperty("lastType", (savesOrExtdata() == UploadType::SAVES ? "SAVES" : "EXTDATA"));
669 | configManager->updateConfigProperty("lastDownloadedGameID", ui->downloadGameIDComboBox->currentText());
670 | configManager->updateConfigProperty("lastMode", "DOWNLOAD");
671 | configManager->setLastDownloadTime(MainWindow::savesOrExtdata(), ui->downloadGameIDComboBox->currentText(), QDateTime::currentDateTime());
672 | changeLastServerUploadText(false);
673 |
674 | if (ui->uploadGameIDComboBox->currentText() == ui->downloadGameIDComboBox->currentText())
675 | {
676 | changeLastServerUploadText(true);
677 | }
678 |
679 | changeLastDownloadText();
680 | }
681 | else
682 | {
683 | showErrorBox("Something went wrong with the download... ");
684 |
685 | std::filesystem::remove_all(configManager->getGamePathFromGameID(MainWindow::savesOrExtdata(), ui->downloadGameIDComboBox->currentText()));
686 | configManager->copyDirectory(
687 | (configManager->getOldSaveDirectory(MainWindow::savesOrExtdata()) / std::filesystem::path((ui->downloadGameIDComboBox->currentText() + "-" + formattedDateTime).toStdString())),
688 | configManager->getGamePathFromGameID(MainWindow::savesOrExtdata(), ui->downloadGameIDComboBox->currentText()));
689 | }
690 |
691 | ui->downloadButton->setEnabled(true);
692 | return;
693 | }
694 | }
695 |
696 | void MainWindow::handleSaveExtdataRadios()
697 | {
698 | setUploadType(savesOrExtdata());
699 |
700 | if (ui->stackedWidget->currentIndex() == 2)
701 | {
702 | handleServerFetch();
703 | }
704 | }
705 |
706 | void MainWindow::handleClearOldSavesButton()
707 | {
708 | std::filesystem::remove_all(configManager->getOldSaveDirectory(MainWindow::savesOrExtdata()));
709 | }
710 |
711 | void MainWindow::openAboutWindow()
712 | {
713 | aboutWindow->exec();
714 | }
715 |
716 | void MainWindow::openConfigFolder()
717 | {
718 | QDesktopServices::openUrl(QUrl::fromLocalFile(configManager->getSaveDirectory().string().c_str()));
719 | }
720 |
721 | void MainWindow::changeLastServerUploadText(bool upload)
722 | {
723 |
724 | QComboBox *comboBox = upload ? ui->uploadGameIDComboBox : ui->downloadGameIDComboBox;
725 | QLabel *label = upload ? ui->uploadLastUploadedLabel : ui->downloadLastUploadedLabel;
726 |
727 | QString gameID = comboBox->currentText();
728 |
729 | if (gameID == "")
730 | {
731 | return;
732 | }
733 |
734 | QDateTime lastUploadTime = citraholdServer->getLastUploadTime(MainWindow::savesOrExtdata(), gameID);
735 |
736 | if (lastUploadTime.toString("yyyy") == "1970" || lastUploadTime.toString("yyyy") == "")
737 | {
738 | label->setText("");
739 | }
740 | else
741 | {
742 | label->setText("Last upload on server: " + lastUploadTime.toString("dd/MM/yyyy hh:mm:ss"));
743 | label->setToolTip("day/month/year hour:minute:second");
744 | }
745 | }
746 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------