diff --git a/IconResource/icon.icns b/IconResource/icon.icns new file mode 100644 index 0000000000..9483d6da0f Binary files /dev/null and b/IconResource/icon.icns differ diff --git a/SerialPrograms/CMakeLists.txt b/SerialPrograms/CMakeLists.txt index 9d9a4daaaf..101a0874e7 100644 --- a/SerialPrograms/CMakeLists.txt +++ b/SerialPrograms/CMakeLists.txt @@ -2034,7 +2034,7 @@ source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}../../ FILES ${MAIN_SOURCES}) if (APPLE) # TODO: set up the correct application icon - # set(SerialPrograms_ICON ${CMAKE_CURRENT_SOURCE_DIR}/../Resources/icon.icns) + set(SerialPrograms_ICON ${CMAKE_CURRENT_SOURCE_DIR}/../IconResource/icon.icns) # set_source_files_properties(SerialPrograms_ICON PROPERTIES MACOSX_PACKAGE_LOCATION "Resources") # Links on how to create a MacOS app bundle with cmake @@ -2047,9 +2047,10 @@ if (APPLE) MACOSX_BUNDLE_BUNDLE_NAME SerialPrograms MACOSX_BUNDLE_BUNDLE_VERSION "0.1" MACOSX_BUNDLE_SHORT_VERSION_STRING "0.1" - # MACOSX_BUNDLE_ICON_FILE icon + MACOSX_BUNDLE_ICON_FILE "icon.icns" # MacOSXBundleInfo.plist.in is modified from https://github.com/Kitware/CMake/blob/master/Modules/MacOSXBundleInfo.plist.in MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/cmake/MacOSXBundleInfo.plist.in + RESOURCE ${SerialPrograms_ICON} ) else() # WIN and Linux: add_executable(SerialPrograms WIN32 ${MAIN_SOURCES}) diff --git a/SerialPrograms/Source/CommonFramework/Globals.cpp b/SerialPrograms/Source/CommonFramework/Globals.cpp index 4486da86a2..0ca795e431 100644 --- a/SerialPrograms/Source/CommonFramework/Globals.cpp +++ b/SerialPrograms/Source/CommonFramework/Globals.cpp @@ -55,13 +55,22 @@ const std::string PROJECT_SOURCE_URL = "https://github.com/PokemonAutomation/Ard 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 = QCoreApplication::applicationDirPath(); + QString path = get_application_base_dir_path(); for (size_t c = 0; c < 5; c++){ QString try_path = path + "/Resources/"; QFile file(try_path); -// cout << path.toUtf8().data() << endl; if (file.exists()){ return try_path.toStdString(); } @@ -70,12 +79,11 @@ std::string get_resource_path(){ return (QCoreApplication::applicationDirPath() + "/../Resources/").toStdString(); } std::string get_training_path(){ - // Find the resource directory. - QString path = QCoreApplication::applicationDirPath(); + // 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); -// cout << path.toUtf8().data() << endl; if (file.exists()){ return try_path.toStdString(); } @@ -85,15 +93,13 @@ std::string get_training_path(){ } std::string get_runtime_base_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.toStdString() + "/"; + if (QSysInfo::productType() == "macos" || QSysInfo::productType() == "osx"){ + QString application_dir_path = get_application_base_dir_path(); + return application_dir_path.toStdString() + "/"; } return "./"; } + const std::string& RUNTIME_BASE_PATH(){ static std::string path = get_runtime_base_path(); return path; diff --git a/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.cpp b/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.cpp index c5a0df9e82..200952a97b 100644 --- a/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.cpp +++ b/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "CommonFramework/Windows/DpiScaler.h" #include "CommonFramework/Windows/WindowTracker.h" #include "FileWindowLogger.h" @@ -19,7 +20,7 @@ namespace PokemonAutomation{ Logger& global_logger_raw(){ - static FileWindowLogger logger((QCoreApplication::applicationName() + ".log").toStdString()); + static FileWindowLogger logger(USER_FILE_PATH() + (QCoreApplication::applicationName() + ".log").toStdString()); return logger; }