From 1b0e85d1870827d068301ec7a4fd0bf69b94e23d Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Fri, 13 Nov 2009 15:56:29 +0000 Subject: [PATCH] Added a File::invokedExecutableFile key that can be used to find the name of the file or link that launched the exe --- src/application/juce_Application.cpp | 8 ++++++++ src/io/files/juce_File.h | 10 ++++++++++ src/native/linux/juce_linux_Files.cpp | 7 +++++++ src/native/mac/juce_mac_Files.mm | 7 +++++++ src/native/windows/juce_win32_Files.cpp | 1 + 5 files changed, 33 insertions(+) diff --git a/src/application/juce_Application.cpp b/src/application/juce_Application.cpp index b22a0b6af2..2d8ff9ba71 100644 --- a/src/application/juce_Application.cpp +++ b/src/application/juce_Application.cpp @@ -273,9 +273,17 @@ int JUCEApplication::shutdownAppAndClearUp() extern int juce_IPhoneMain (int argc, char* argv[], JUCEApplication* app); #endif +#if ! JUCE_WINDOWS +extern const char* juce_Argv0; +#endif + int JUCEApplication::main (int argc, char* argv[], JUCEApplication* const newApp) { +#if ! JUCE_WINDOWS + juce_Argv0 = argv[0]; +#endif + #if JUCE_IPHONE const ScopedAutoReleasePool pool; return juce_IPhoneMain (argc, argv, newApp); diff --git a/src/io/files/juce_File.h b/src/io/files/juce_File.h index 64c9bdb4f7..745475b619 100644 --- a/src/io/files/juce_File.h +++ b/src/io/files/juce_File.h @@ -779,6 +779,9 @@ public: On the mac this will return the unix binary, not the package folder - see currentApplicationFile for that. + + See also invokedExecutableFile, which is similar, but if the exe was launched from a + file link, invokedExecutableFile will return the name of the link. */ currentExecutableFile, @@ -792,6 +795,13 @@ public: */ currentApplicationFile, + /** Returns the file that was invoked to launch this executable. + This may differ from currentExecutableFile if the app was started from e.g. a link - this + will return the name of the link that was used, whereas currentExecutableFile will return + the actual location of the target executable. + */ + invokedExecutableFile, + /** The directory in which applications normally get installed. So on windows, this would be something like "c:\program files", on the diff --git a/src/native/linux/juce_linux_Files.cpp b/src/native/linux/juce_linux_Files.cpp index c7a4613888..d48fe4c39e 100644 --- a/src/native/linux/juce_linux_Files.cpp +++ b/src/native/linux/juce_linux_Files.cpp @@ -171,6 +171,8 @@ bool File::isHidden() const throw() } //============================================================================== +const char* juce_Argv0 = 0; // referenced from juce_Application.cpp + const File File::getSpecialLocation (const SpecialLocationType type) { switch (type) @@ -219,6 +221,11 @@ const File File::getSpecialLocation (const SpecialLocationType type) return tmp; } + case invokedExecutableFile: + if (juce_Argv0 != 0) + return File (String::fromUTF8 ((const uint8*) juce_Argv0)); + // deliberate fall-through... + case currentExecutableFile: case currentApplicationFile: return juce_getExecutableFile(); diff --git a/src/native/mac/juce_mac_Files.mm b/src/native/mac/juce_mac_Files.mm index b81c0f3f4a..f0d2094cd2 100644 --- a/src/native/mac/juce_mac_Files.mm +++ b/src/native/mac/juce_mac_Files.mm @@ -182,6 +182,8 @@ bool File::isHidden() const throw() } //============================================================================== +const char* juce_Argv0 = 0; // referenced from juce_Application.cpp + const File File::getSpecialLocation (const SpecialLocationType type) { const ScopedAutoReleasePool pool; @@ -230,6 +232,11 @@ const File File::getSpecialLocation (const SpecialLocationType type) return tmp.getFullPathName(); } + case invokedExecutableFile: + if (juce_Argv0 != 0) + return File (String::fromUTF8 ((const uint8*) juce_Argv0)); + // deliberate fall-through... + case currentExecutableFile: return juce_getExecutableFile(); diff --git a/src/native/windows/juce_win32_Files.cpp b/src/native/windows/juce_win32_Files.cpp index ce99091fea..1f927c8c05 100644 --- a/src/native/windows/juce_win32_Files.cpp +++ b/src/native/windows/juce_win32_Files.cpp @@ -489,6 +489,7 @@ const File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType typ return File (String (dest)); } + case invokedExecutableFile: case currentExecutableFile: case currentApplicationFile: {