@@ -55,13 +55,22 @@ const std::string PROJECT_SOURCE_URL = "https://github.com/PokemonAutomation/Ard
5555
5656namespace {
5757
58+ QString get_application_base_dir_path (){
59+ QString application_dir_path = qApp->applicationDirPath ();
60+ if (application_dir_path.endsWith (" .app/Contents/MacOS" )){
61+ // a macOS bundle. Change working directory to the folder that hosts the .app folder.
62+ QString app_bundle_path = application_dir_path.chopped (15 );
63+ QString base_folder_path = QFileInfo (app_bundle_path).dir ().absolutePath ();
64+ return base_folder_path;
65+ }
66+ return application_dir_path;
67+ }
5868std::string get_resource_path (){
5969 // Find the resource directory.
60- QString path = QCoreApplication::applicationDirPath ();
70+ QString path = get_application_base_dir_path ();
6171 for (size_t c = 0 ; c < 5 ; c++){
6272 QString try_path = path + " /Resources/" ;
6373 QFile file (try_path);
64- // cout << path.toUtf8().data() << endl;
6574 if (file.exists ()){
6675 return try_path.toStdString ();
6776 }
@@ -70,12 +79,11 @@ std::string get_resource_path(){
7079 return (QCoreApplication::applicationDirPath () + " /../Resources/" ).toStdString ();
7180}
7281std::string get_training_path (){
73- // Find the resource directory.
74- QString path = QCoreApplication::applicationDirPath ();
82+ // Find the training data directory.
83+ QString path = get_application_base_dir_path ();
7584 for (size_t c = 0 ; c < 5 ; c++){
7685 QString try_path = path + " /TrainingData/" ;
7786 QFile file (try_path);
78- // cout << path.toUtf8().data() << endl;
7987 if (file.exists ()){
8088 return try_path.toStdString ();
8189 }
@@ -85,15 +93,13 @@ std::string get_training_path(){
8593}
8694
8795std::string get_runtime_base_path (){
88- QString application_dir_path = qApp->applicationDirPath ();
89- if (application_dir_path.endsWith (" .app/Contents/MacOS" )){
90- // a macOS bundle. Change working directory to the folder that hosts the .app folder.
91- QString app_bundle_path = application_dir_path.chopped (15 );
92- QString base_folder_path = QFileInfo (app_bundle_path).dir ().absolutePath ();
93- return base_folder_path.toStdString () + " /" ;
96+ if (QSysInfo::productType () == " macos" || QSysInfo::productType () == " osx" ){
97+ QString application_dir_path = get_application_base_dir_path ();
98+ return application_dir_path.toStdString () + " /" ;
9499 }
95100 return " ./" ;
96101}
102+
97103const std::string& RUNTIME_BASE_PATH (){
98104 static std::string path = get_runtime_base_path ();
99105 return path;
0 commit comments