-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathGlobals.cpp
More file actions
264 lines (219 loc) · 8.21 KB
/
Globals.cpp
File metadata and controls
264 lines (219 loc) · 8.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/* Globals
*
* From: https://github.com/PokemonAutomation/
*
*/
#include <QCoreApplication>
#include <QStandardPaths>
#include <QFile>
#include <QFileInfo>
#include <QDir>
#include "Globals.h"
namespace PokemonAutomation{
//
// ATTENTION!!!
//
// If you are building from source, do not change any of these version numbers
// or tags. When filing reports or asking for support, we (the developers) need
// to know exactly what you are running. Changing these values can lead to
// misleading version information.
//
#ifndef PA_IS_BETA
#define PA_IS_BETA true
#endif
#ifndef PA_VERSION_MAJOR
#define PA_VERSION_MAJOR 0
#endif
#ifndef PA_VERSION_MINOR
#define PA_VERSION_MINOR 63
#endif
#ifndef PA_VERSION_PATCH
#define PA_VERSION_PATCH 1
#endif
const bool IS_BETA_VERSION = PA_IS_BETA;
const int PROGRAM_VERSION_MAJOR = PA_VERSION_MAJOR;
const int PROGRAM_VERSION_MINOR = PA_VERSION_MINOR;
const int PROGRAM_VERSION_PATCH = PA_VERSION_PATCH;
const std::string PROGRAM_VERSION_BASE =
"v" + std::to_string(PROGRAM_VERSION_MAJOR) +
"." + std::to_string(PROGRAM_VERSION_MINOR) +
"." + std::to_string(PROGRAM_VERSION_PATCH);
#ifdef PA_OFFICIAL
const std::string PROGRAM_VERSION = IS_BETA_VERSION
? PROGRAM_VERSION_BASE + "-beta"
: PROGRAM_VERSION_BASE;
#else
const std::string PROGRAM_VERSION = PROGRAM_VERSION_BASE + "-user";
#endif
const std::string PROGRAM_NAME = "Pok\u00e9mon Automation";
const std::string ONLINE_DOC_URL_BASE = "https://pokemonautomation.github.io/";
const std::string PROJECT_SOURCE_URL = "https://github.com/PokemonAutomation/Arduino-Source/";
const std::string RESOURCES_URL_BASE = "https://github.com/PokemonAutomation/Packages/";
// This the URL that we display. We don't actually use this for linking.
const std::string GITHUB_LINK_TEXT = "pokemonautomation.github.io";
// This is the URL that we actually link to.
const std::string GITHUB_LINK_URL = "https://pokemonautomation.github.io";
// URL to display. (the vanity link)
// We don't actually use this URL for linking since the vanity link will go
// away if we lose too many nitro boosts.
const std::string DISCORD_LINK_TEXT = "discord.gg/PokemonAutomation";
// URL to use inside the program.
const std::string DISCORD_LINK_URL_PROGRAM = "https://discord.gg/BSjDp27";
// URL to use in the Discord notifications/embeds.
const std::string DISCORD_LINK_URL_EMBED = "https://discord.gg/xMJcveK";
// URL to use in the DiscordSocialSDK integration.
const std::string DISCORD_LINK_URL_SDK = "https://discord.gg/gn9YEyjjAV";
#if 0
#elif __INTEL_LLVM_COMPILER
const std::string COMPILER_VERSION = "ICX " + std::to_string(__VERSION__);
#elif __INTEL_COMPILER
const std::string COMPILER_VERSION = "ICC " + std::to_string(__INTEL_COMPILER) + "." + std::to_string(__INTEL_COMPILER_UPDATE);
#elif _MSC_VER
const std::string COMPILER_VERSION = "MSVC " + std::to_string(_MSC_FULL_VER);
#elif __clang__
const std::string COMPILER_VERSION = "Clang " + std::string(__clang_version__);
#elif __GNUC__
const std::string COMPILER_VERSION = "GCC " + std::to_string(__GNUC__) + "." + std::to_string(__GNUC_MINOR__);
#else
const std::string COMPILER_VERSION = "Unknown Compiler";
#endif
const size_t LOG_HISTORY_LINES = 10000;
namespace{
QString get_application_base_dir_path(){
QString application_dir_path = qApp->applicationDirPath();
if (application_dir_path.endsWith(".app/Contents/MacOS")){
// a macOS bundle. Change working directory to the folder that hosts the .app folder.
QString app_bundle_path = application_dir_path.chopped(15);
QString base_folder_path = QFileInfo(app_bundle_path).dir().absolutePath();
return base_folder_path;
}
return application_dir_path;
}
std::string get_resource_path(){
// Find the resource directory.
QString path = get_application_base_dir_path();
for (size_t c = 0; c < 5; c++){
QString try_path = path + "/Resources/";
QFile file(try_path);
if (file.exists()){
return try_path.toStdString();
}
path += "/..";
}
return (QCoreApplication::applicationDirPath() + "/../Resources/").toStdString();
}
std::string get_training_path(){
// Find the training data directory.
QString path = get_application_base_dir_path();
for (size_t c = 0; c < 5; c++){
QString try_path = path + "/TrainingData/";
QFile file(try_path);
if (file.exists()){
return try_path.toStdString();
}
path += "/..";
}
return (QCoreApplication::applicationDirPath() + "/../TrainingData/").toStdString();
}
std::string get_runtime_base_path(){
// On MacOS, find the writable application support directory
if (QSysInfo::productType() == "macos" || QSysInfo::productType() == "osx"){
// QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) returns
// "/Users/$USERNAME/Library/Application Support", the parent folder
// to hold application-specific persistent data.
// QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) returns
// "/Users/$USERNAME/Library/Application Support/SerialPrograms",
// the folder where we store persistent data.
QString appSupportPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
QDir dir(appSupportPath);
if (!dir.exists()){
dir.mkpath(".");
}
return appSupportPath.toStdString() + "/";
}
return "./";
}
std::string get_setting_path(){
return RUNTIME_BASE_PATH() + "UserSettings/";
}
std::string get_screenshot_path(){
return RUNTIME_BASE_PATH() + "Screenshots/";
}
std::string get_debug_path(){
return RUNTIME_BASE_PATH() + "DebugDumps/";
}
std::string get_error_path(){
return RUNTIME_BASE_PATH() + "ErrorDumps/";
}
std::string get_user_file_path(){
return RUNTIME_BASE_PATH();
}
} // anonymous namespace
const std::string& RUNTIME_BASE_PATH(){
static std::string path = get_runtime_base_path();
return path;
}
const std::string& SETTINGS_PATH(){
static std::string path = get_setting_path();
return path;
}
const std::string& PROGRAM_SETTING_JSON_PATH(){
static std::string path = SETTINGS_PATH() + QCoreApplication::applicationName().toStdString() + "-Settings.json";
return path;
}
const std::string& SCREENSHOTS_PATH(){
static std::string path = get_screenshot_path();
return path;
}
const std::string& DEBUG_PATH(){
static std::string path = get_debug_path();
return path;
}
const std::string& ERROR_PATH(){
static std::string path = get_error_path();
return path;
}
const std::string& USER_FILE_PATH(){
static std::string path = get_user_file_path();
return path;
}
const std::string& RESOURCE_PATH(){
static std::string path = get_resource_path();
return path;
}
const std::string& DOWNLOADED_RESOURCE_PATH(){
static std::string path = RUNTIME_BASE_PATH() + "DownloadedResources/";
return path;
}
const std::string& TRAINING_PATH(){
static std::string path = get_training_path();
return path;
}
const std::string& ML_ANNOTATION_PATH(){
static const std::string path = RUNTIME_BASE_PATH() + "DataAnnotation/";
return path;
}
const std::string& ML_MODEL_CACHE_PATH(){
static const std::string path = RUNTIME_BASE_PATH() + "ModelCache/";
return path;
}
#if 0
// Program executable path information
namespace {
std::string g_program_absolute_path;
std::string g_program_filename;
std::string g_program_basename;
}
void set_program_path(const char* argv0){
if (argv0 != nullptr){
std::filesystem::path program_path(argv0);
g_program_absolute_path = std::filesystem::absolute(program_path).string();
g_program_filename = program_path.filename().string();
g_program_basename = program_path.stem().string();
}
}
const std::string& PROGRAM_ABSOLUTE_PATH(){ return g_program_absolute_path }
const std::string& PROGRAM_FILENAME(){ return g_program_filename; }
const std::string& PROGRAM_BASENAME(){ return g_program_basename; }
#endif
}