| @@ -129,7 +129,8 @@ File File::getLinkedTarget() const | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| const char* juce_Argv0 = nullptr; // referenced from juce_Application.cpp | |||||
| extern const char** juce_argv; // declared in juce_Application.cpp | |||||
| extern int juce_argc; | |||||
| File File::getSpecialLocation (const SpecialLocationType type) | File File::getSpecialLocation (const SpecialLocationType type) | ||||
| { | { | ||||
| @@ -180,8 +181,8 @@ File File::getSpecialLocation (const SpecialLocationType type) | |||||
| } | } | ||||
| case invokedExecutableFile: | case invokedExecutableFile: | ||||
| if (juce_Argv0 != nullptr) | |||||
| return File (CharPointer_UTF8 (juce_Argv0)); | |||||
| if (juce_argv != nullptr && juce_argc > 0) | |||||
| return File (CharPointer_UTF8 (juce_argv[0])); | |||||
| // deliberate fall-through... | // deliberate fall-through... | ||||
| case currentExecutableFile: | case currentExecutableFile: | ||||
| @@ -163,7 +163,8 @@ bool File::isHidden() const | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| const char* juce_Argv0 = nullptr; // referenced from juce_Application.cpp | |||||
| extern const char** juce_argv; // declared in juce_Application.cpp | |||||
| extern int juce_argc; | |||||
| File File::getSpecialLocation (const SpecialLocationType type) | File File::getSpecialLocation (const SpecialLocationType type) | ||||
| { | { | ||||
| @@ -204,8 +205,8 @@ File File::getSpecialLocation (const SpecialLocationType type) | |||||
| case globalApplicationsDirectory: resultPath = "/Applications"; break; | case globalApplicationsDirectory: resultPath = "/Applications"; break; | ||||
| case invokedExecutableFile: | case invokedExecutableFile: | ||||
| if (juce_Argv0 != 0) | |||||
| return File (CharPointer_UTF8 (juce_Argv0)); | |||||
| if (juce_argv != nullptr && juce_argc > 0) | |||||
| return File (CharPointer_UTF8 (juce_argv[0])); | |||||
| // deliberate fall-through... | // deliberate fall-through... | ||||
| case currentExecutableFile: | case currentExecutableFile: | ||||
| @@ -282,13 +282,6 @@ bool JUCE_CALLTYPE Process::isRunningUnderDebugger() | |||||
| return juce_isRunningUnderDebugger(); | return juce_isRunningUnderDebugger(); | ||||
| } | } | ||||
| String JUCE_CALLTYPE Process::getCurrentCommandLineParams() | |||||
| { | |||||
| return CharacterFunctions::findEndOfToken (CharPointer_UTF16 (GetCommandLineW()), | |||||
| CharPointer_UTF16 (L" "), | |||||
| CharPointer_UTF16 (L"\"")).findEndOfWhitespace(); | |||||
| } | |||||
| static void* currentModuleHandle = nullptr; | static void* currentModuleHandle = nullptr; | ||||
| void* Process::getCurrentModuleInstanceHandle() noexcept | void* Process::getCurrentModuleInstanceHandle() noexcept | ||||
| @@ -128,11 +128,6 @@ public: | |||||
| @see getCurrentModuleInstanceHandle() | @see getCurrentModuleInstanceHandle() | ||||
| */ | */ | ||||
| static void JUCE_CALLTYPE setCurrentModuleInstanceHandle (void* newHandle) noexcept; | static void JUCE_CALLTYPE setCurrentModuleInstanceHandle (void* newHandle) noexcept; | ||||
| /** WINDOWS ONLY - Gets the command-line params as a string. | |||||
| This is needed to avoid unicode problems with the argc type params. | |||||
| */ | |||||
| static String JUCE_CALLTYPE getCurrentCommandLineParams(); | |||||
| #endif | #endif | ||||
| private: | private: | ||||
| @@ -85,8 +85,10 @@ public: | |||||
| If during the initialise() method, the application decides not to start-up | If during the initialise() method, the application decides not to start-up | ||||
| after all, it can just call the quit() method and the event loop won't be run. | after all, it can just call the quit() method and the event loop won't be run. | ||||
| @param commandLineParameters the line passed in does not include the | |||||
| name of the executable, just the parameter list. | |||||
| @param commandLineParameters the line passed in does not include the name of | |||||
| the executable, just the parameter list. To get the | |||||
| parameters as an array, you can call | |||||
| JUCEApplication::getCommandLineParameters() | |||||
| @see shutdown, quit | @see shutdown, quit | ||||
| */ | */ | ||||
| virtual void initialise (const String& commandLineParameters) = 0; | virtual void initialise (const String& commandLineParameters) = 0; | ||||
| @@ -136,10 +136,8 @@ bool JUCEApplication::perform (const InvocationInfo& info) | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| bool JUCEApplication::initialiseApp (const String& commandLine) | |||||
| bool JUCEApplication::initialiseApp() | |||||
| { | { | ||||
| commandLineParameters = commandLine.trim(); | |||||
| #if ! (JUCE_IOS || JUCE_ANDROID) | #if ! (JUCE_IOS || JUCE_ANDROID) | ||||
| jassert (appLock == nullptr); // initialiseApp must only be called once! | jassert (appLock == nullptr); // initialiseApp must only be called once! | ||||
| @@ -150,7 +148,7 @@ bool JUCEApplication::initialiseApp (const String& commandLine) | |||||
| if (! appLock->enter(0)) | if (! appLock->enter(0)) | ||||
| { | { | ||||
| appLock = nullptr; | appLock = nullptr; | ||||
| MessageManager::broadcastMessage (getApplicationName() + "/" + commandLineParameters); | |||||
| MessageManager::broadcastMessage (getApplicationName() + "/" + getCommandLineParameters()); | |||||
| DBG ("Another instance is running - quitting..."); | DBG ("Another instance is running - quitting..."); | ||||
| return false; | return false; | ||||
| @@ -159,7 +157,7 @@ bool JUCEApplication::initialiseApp (const String& commandLine) | |||||
| #endif | #endif | ||||
| // let the app do its setting-up.. | // let the app do its setting-up.. | ||||
| initialise (commandLineParameters); | |||||
| initialise (getCommandLineParameters()); | |||||
| #if JUCE_MAC | #if JUCE_MAC | ||||
| juce_initialiseMacMainMenu(); // needs to be called after the app object has created, to get its name | juce_initialiseMacMainMenu(); // needs to be called after the app object has created, to get its name | ||||
| @@ -190,73 +188,85 @@ int JUCEApplication::shutdownApp() | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| #if ! JUCE_ANDROID | |||||
| int JUCEApplication::main (const String& commandLine) | |||||
| #if JUCE_ANDROID | |||||
| StringArray JUCEApplication::getCommandLineParameterArray() { return StringArray(); } | |||||
| String JUCEApplication::getCommandLineParameters() { return String::empty; } | |||||
| #else | |||||
| int JUCEApplication::main() | |||||
| { | { | ||||
| ScopedJuceInitialiser_GUI libraryInitialiser; | ScopedJuceInitialiser_GUI libraryInitialiser; | ||||
| jassert (createInstance != nullptr); | jassert (createInstance != nullptr); | ||||
| int returnCode = 0; | |||||
| { | |||||
| const ScopedPointer<JUCEApplication> app (dynamic_cast <JUCEApplication*> (createInstance())); | |||||
| jassert (app != nullptr); | |||||
| const ScopedPointer<JUCEApplication> app (dynamic_cast <JUCEApplication*> (createInstance())); | |||||
| jassert (app != nullptr); | |||||
| if (! app->initialiseApp (commandLine)) | |||||
| return 0; | |||||
| if (! app->initialiseApp()) | |||||
| return 0; | |||||
| JUCE_TRY | |||||
| { | |||||
| // loop until a quit message is received.. | |||||
| MessageManager::getInstance()->runDispatchLoop(); | |||||
| } | |||||
| JUCE_CATCH_EXCEPTION | |||||
| returnCode = app->shutdownApp(); | |||||
| JUCE_TRY | |||||
| { | |||||
| // loop until a quit message is received.. | |||||
| MessageManager::getInstance()->runDispatchLoop(); | |||||
| } | } | ||||
| JUCE_CATCH_EXCEPTION | |||||
| return returnCode; | |||||
| return app->shutdownApp(); | |||||
| } | } | ||||
| #if ! JUCE_WINDOWS | |||||
| #if JUCE_IOS | #if JUCE_IOS | ||||
| extern int juce_iOSMain (int argc, const char* argv[]); | extern int juce_iOSMain (int argc, const char* argv[]); | ||||
| #endif | #endif | ||||
| #if ! JUCE_WINDOWS | |||||
| extern const char* juce_Argv0; | |||||
| #endif | |||||
| #if JUCE_MAC | #if JUCE_MAC | ||||
| extern void initialiseNSApplication(); | extern void initialiseNSApplication(); | ||||
| #endif | #endif | ||||
| const char* const* juce_argv = nullptr; | |||||
| int juce_argc = 0; | |||||
| StringArray JUCEApplication::getCommandLineParameterArray() | |||||
| { | |||||
| return StringArray (juce_argv + 1, juce_argc - 1); | |||||
| } | |||||
| String JUCEApplication::getCommandLineParameters() | |||||
| { | |||||
| String argString; | |||||
| for (int i = 1; i < juce_argc; ++i) | |||||
| { | |||||
| String arg (juce_argv[i]); | |||||
| if (arg.containsChar (' ') && ! arg.isQuotedString()) | |||||
| arg = arg.quoted ('"'); | |||||
| argString << arg << ' '; | |||||
| } | |||||
| return argString.trim(); | |||||
| } | |||||
| int JUCEApplication::main (int argc, const char* argv[]) | int JUCEApplication::main (int argc, const char* argv[]) | ||||
| { | { | ||||
| JUCE_AUTORELEASEPOOL | JUCE_AUTORELEASEPOOL | ||||
| juce_argc = argc; | |||||
| juce_argv = argv; | |||||
| #if JUCE_MAC | #if JUCE_MAC | ||||
| initialiseNSApplication(); | initialiseNSApplication(); | ||||
| #endif | #endif | ||||
| #if ! JUCE_WINDOWS | |||||
| jassert (createInstance != nullptr); | |||||
| juce_Argv0 = argv[0]; | |||||
| #endif | |||||
| #if JUCE_IOS | #if JUCE_IOS | ||||
| return juce_iOSMain (argc, argv); | return juce_iOSMain (argc, argv); | ||||
| #else | #else | ||||
| String cmd; | |||||
| for (int i = 1; i < argc; ++i) | |||||
| { | |||||
| String arg (argv[i]); | |||||
| if (arg.containsChar (' ') && ! arg.isQuotedString()) | |||||
| arg = arg.quoted ('"'); | |||||
| cmd << arg << ' '; | |||||
| } | |||||
| return JUCEApplication::main (cmd); | |||||
| return JUCEApplication::main(); | |||||
| #endif | #endif | ||||
| } | } | ||||
| #endif | #endif | ||||
| #endif | |||||
| @@ -204,8 +204,15 @@ public: | |||||
| */ | */ | ||||
| int getApplicationReturnValue() const noexcept { return appReturnValue; } | int getApplicationReturnValue() const noexcept { return appReturnValue; } | ||||
| /** Returns the application's command line parameters. */ | |||||
| const String& getCommandLineParameters() const noexcept { return commandLineParameters; } | |||||
| /** Returns the application's command line parameters as a set of strings. | |||||
| @see getCommandLineParameters | |||||
| */ | |||||
| static StringArray JUCE_CALLTYPE getCommandLineParameterArray(); | |||||
| /** Returns the application's command line parameters as a single string. | |||||
| @see getCommandLineParameterArray | |||||
| */ | |||||
| static String JUCE_CALLTYPE getCommandLineParameters(); | |||||
| /** Returns true if this executable is running as an app (as opposed to being a plugin | /** Returns true if this executable is running as an app (as opposed to being a plugin | ||||
| or other kind of shared library. */ | or other kind of shared library. */ | ||||
| @@ -224,16 +231,15 @@ public: | |||||
| //============================================================================== | //============================================================================== | ||||
| #ifndef DOXYGEN | #ifndef DOXYGEN | ||||
| // The following methods are internal calls - not for public use. | // The following methods are internal calls - not for public use. | ||||
| static int main (const String& commandLine); | |||||
| static int main(); | |||||
| static int main (int argc, const char* argv[]); | static int main (int argc, const char* argv[]); | ||||
| static void sendUnhandledException (const std::exception*, const char* sourceFile, int lineNumber); | static void sendUnhandledException (const std::exception*, const char* sourceFile, int lineNumber); | ||||
| bool initialiseApp (const String& commandLine); | |||||
| bool initialiseApp(); | |||||
| int shutdownApp(); | int shutdownApp(); | ||||
| #endif | #endif | ||||
| private: | private: | ||||
| //============================================================================== | //============================================================================== | ||||
| String commandLineParameters; | |||||
| ScopedPointer<InterProcessLock> appLock; | ScopedPointer<InterProcessLock> appLock; | ||||
| ScopedPointer<ActionListener> broadcastCallback; | ScopedPointer<ActionListener> broadcastCallback; | ||||
| int appReturnValue; | int appReturnValue; | ||||
| @@ -89,8 +89,16 @@ public: | |||||
| #define START_JUCE_APPLICATION(AppClass) \ | #define START_JUCE_APPLICATION(AppClass) \ | ||||
| juce::JUCEApplication* juce_CreateApplication() { return new AppClass(); } | juce::JUCEApplication* juce_CreateApplication() { return new AppClass(); } | ||||
| #elif defined (JUCE_GCC) || defined (__MWERKS__) | |||||
| #elif JUCE_WINDOWS | |||||
| #define START_JUCE_APPLICATION(AppClass) \ | |||||
| static juce::JUCEApplicationBase* juce_CreateApplication() { return new AppClass(); } \ | |||||
| int __stdcall WinMain (void*, void*, const char*, int) \ | |||||
| { \ | |||||
| juce::JUCEApplication::createInstance = &juce_CreateApplication; \ | |||||
| return juce::JUCEApplication::main(); \ | |||||
| } | |||||
| #else | |||||
| #define START_JUCE_APPLICATION(AppClass) \ | #define START_JUCE_APPLICATION(AppClass) \ | ||||
| static juce::JUCEApplicationBase* juce_CreateApplication() { return new AppClass(); } \ | static juce::JUCEApplicationBase* juce_CreateApplication() { return new AppClass(); } \ | ||||
| int main (int argc, char* argv[]) \ | int main (int argc, char* argv[]) \ | ||||
| @@ -99,36 +107,6 @@ public: | |||||
| return juce::JUCEApplication::main (argc, (const char**) argv); \ | return juce::JUCEApplication::main (argc, (const char**) argv); \ | ||||
| } | } | ||||
| #elif JUCE_WINDOWS | |||||
| #ifdef _CONSOLE | |||||
| #define START_JUCE_APPLICATION(AppClass) \ | |||||
| static juce::JUCEApplicationBase* juce_CreateApplication() { return new AppClass(); } \ | |||||
| int main (int, char* argv[]) \ | |||||
| { \ | |||||
| juce::JUCEApplication::createInstance = &juce_CreateApplication; \ | |||||
| return juce::JUCEApplication::main (juce::Process::getCurrentCommandLineParams()); \ | |||||
| } | |||||
| #elif ! defined (_AFXDLL) | |||||
| #ifdef _WINDOWS_ | |||||
| #define START_JUCE_APPLICATION(AppClass) \ | |||||
| static juce::JUCEApplicationBase* juce_CreateApplication() { return new AppClass(); } \ | |||||
| int WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int) \ | |||||
| { \ | |||||
| juce::JUCEApplication::createInstance = &juce_CreateApplication; \ | |||||
| return juce::JUCEApplication::main (juce::Process::getCurrentCommandLineParams()); \ | |||||
| } | |||||
| #else | |||||
| #define START_JUCE_APPLICATION(AppClass) \ | |||||
| static juce::JUCEApplicationBase* juce_CreateApplication() { return new AppClass(); } \ | |||||
| int __stdcall WinMain (void*, void*, const char*, int) \ | |||||
| { \ | |||||
| juce::JUCEApplication::createInstance = &juce_CreateApplication; \ | |||||
| return juce::JUCEApplication::main (juce::Process::getCurrentCommandLineParams()); \ | |||||
| } | |||||
| #endif | |||||
| #endif | |||||
| #endif | #endif | ||||
| @@ -43,7 +43,7 @@ JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, launchApp, void, (JNIEnv* en | |||||
| initialiseJuce_GUI(); | initialiseJuce_GUI(); | ||||
| JUCEApplication* app = dynamic_cast <JUCEApplication*> (JUCEApplicationBase::createInstance()); | JUCEApplication* app = dynamic_cast <JUCEApplication*> (JUCEApplicationBase::createInstance()); | ||||
| if (! app->initialiseApp (String::empty)) | |||||
| if (! app->initialiseApp()) | |||||
| exit (0); | exit (0); | ||||
| jassert (MessageManager::getInstance()->isThisTheMessageThread()); | jassert (MessageManager::getInstance()->isThisTheMessageThread()); | ||||
| @@ -41,7 +41,7 @@ | |||||
| initialiseJuce_GUI(); | initialiseJuce_GUI(); | ||||
| JUCEApplication* app = dynamic_cast <JUCEApplication*> (JUCEApplicationBase::createInstance()); | JUCEApplication* app = dynamic_cast <JUCEApplication*> (JUCEApplicationBase::createInstance()); | ||||
| if (! app->initialiseApp (String::empty)) | |||||
| if (! app->initialiseApp()) | |||||
| exit (0); | exit (0); | ||||
| } | } | ||||
| @@ -3059,6 +3059,30 @@ String SystemClipboard::getTextFromClipboard() | |||||
| return result; | return result; | ||||
| } | } | ||||
| //============================================================================== | |||||
| String JUCE_CALLTYPE JUCEApplication::getCommandLineParameters() | |||||
| { | |||||
| return CharacterFunctions::findEndOfToken (CharPointer_UTF16 (GetCommandLineW()), | |||||
| CharPointer_UTF16 (L" "), | |||||
| CharPointer_UTF16 (L"\"")).findEndOfWhitespace(); | |||||
| } | |||||
| StringArray JUCE_CALLTYPE JUCEApplication::getCommandLineParameterArray() | |||||
| { | |||||
| StringArray s; | |||||
| int argc = 0; | |||||
| LPWSTR* const argv = CommandLineToArgvW (GetCommandLineW(), &argc); | |||||
| if (argv != nullptr) | |||||
| { | |||||
| s = StringArray (argv + 1, argc - 1); | |||||
| LocalFree (argv); | |||||
| } | |||||
| return s; | |||||
| } | |||||
| //============================================================================== | //============================================================================== | ||||
| void Desktop::setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool /*allowMenusAndBars*/) | void Desktop::setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool /*allowMenusAndBars*/) | ||||
| { | { | ||||