diff options
author | Andrew Belt <andrewpbelt@gmail.com> | 2024-03-25 18:57:30 -0400 |
---|---|---|
committer | Andrew Belt <andrewpbelt@gmail.com> | 2024-03-25 18:57:30 -0400 |
commit | ba84d1446716dd7732f122da9160270e08929aa5 (patch) | |
tree | c33289995b54cd7b77649edf17f0b3279b0f4169 | |
parent | b04beb96809bd7979d3bb1a08c7627cd52d074b9 (diff) |
If log file cannot be written, show error dialog and exit. On Mac, explain how to enable Document Folder permission and open System Settings before exit.
-rw-r--r-- | adapters/standalone.cpp | 12 | ||||
-rw-r--r-- | include/logger.hpp | 3 | ||||
-rw-r--r-- | src/logger.cpp | 12 |
3 files changed, 19 insertions, 8 deletions
diff --git a/adapters/standalone.cpp b/adapters/standalone.cpp index 6542cd85..3dcbff86 100644 --- a/adapters/standalone.cpp +++ b/adapters/standalone.cpp @@ -134,7 +134,17 @@ int main(int argc, char* argv[]) { if (!settings::devMode) { logger::logPath = asset::user("log.txt"); } - logger::init(); + if (!logger::init()) { + std::string msg = "Cannot access Rack's user folder " + asset::userDir; +#if defined ARCH_MAC + // The user likely clicked "Don't Allow" on the Documents Folder permissions dialog, so tell them how to allow it. + msg += "\n\nMake sure Rack has permission by opening Apple's System Settings and enabling Privacy & Security > Files and Folders > " + APP_NAME + " " + APP_VERSION_MAJOR + " " + APP_EDITION_NAME + " > Documents Folder."; + // Launch Apple's Privacy & Security settings + std::system("open x-apple.systempreferences:com.apple.preference.security"); +#endif + osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, msg.c_str()); + exit(1); + } random::init(); // Test code diff --git a/include/logger.hpp b/include/logger.hpp index d47725fc..89910f3c 100644 --- a/include/logger.hpp +++ b/include/logger.hpp @@ -31,7 +31,8 @@ enum Level { FATAL_LEVEL }; -PRIVATE void init(); +/** Returns whether logger was successfully initialized. */ +PRIVATE bool init(); PRIVATE void destroy(); /** Do not use this function directly. Use the macros above. Thread-safe, meaning messages cannot overlap each other in the log. diff --git a/src/logger.cpp b/src/logger.cpp index 542af66f..12b2261a 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -46,8 +46,10 @@ static bool isTruncated() { } -void init() { - assert(!outputFile); +bool init() { + if (outputFile) + return true; + std::lock_guard<std::mutex> lock(mutex); truncated = false; @@ -61,13 +63,11 @@ void init() { outputFile = std::fopen(logPath.c_str(), "w"); if (!outputFile) { std::fprintf(stderr, "Could not open log at %s\n", logPath.c_str()); + return false; } } - // Redirect stdout and stderr to the file - // Actually, disable this because we don't want to steal stdout/stderr from the DAW in Rack for DAWs. - // dup2(fileno(outputFile), fileno(stdout)); - // dup2(fileno(outputFile), fileno(stderr)); + return true; } void destroy() { |