1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-22 01:34:21 +00:00

Added code to make the mac detect its executable file, removing the need for the juce_setCurrentExecutable function, and removed this function from the codebase.

This commit is contained in:
jules 2009-07-16 15:41:42 +00:00
parent 5df4ac7dec
commit 6fe090f2cb
10 changed files with 1696 additions and 1789 deletions

View file

@ -70,10 +70,6 @@ BEGIN_JUCE_NAMESPACE
#include "../../macosx/platform_specific_code/juce_posix_SharedCode.h"
//==============================================================================
static File executableFile;
//==============================================================================
void juce_getFileTimes (const String& fileName,
int64& modificationTime,
@ -262,21 +258,7 @@ const File File::getSpecialLocation (const SpecialLocationType type)
case currentExecutableFile:
case currentApplicationFile:
if (! executableFile.exists())
{
Dl_info executableInfo;
dladdr ((const void*) juce_getFileTimes, &executableInfo);
if (executableInfo.dli_fname != 0)
executableFile = File (String (executableInfo.dli_fname));
}
// if this fails, it's probably because juce_setCurrentExecutableFileName()
// was never called to set the filename - this should be done by the juce
// main() function, so maybe you've hacked it to use your own custom main()?
jassert (executableFile.exists());
return executableFile;
return juce_getExecutableFile();
default:
jassertfalse // unknown type?
@ -286,11 +268,6 @@ const File File::getSpecialLocation (const SpecialLocationType type)
return File::nonexistent;
}
//==============================================================================
void juce_setCurrentExecutableFileName (const String& filename) throw()
{
executableFile = File::getCurrentWorkingDirectory().getChildFile (filename);
}
//==============================================================================
const File File::getCurrentWorkingDirectory() throw()

View file

@ -39,8 +39,6 @@
*/
//==============================================================================
static File executableFile;
const unsigned int macTimeToUnixTimeDiff = 0x7c25be90;
static uint64 utcDateTimeToUnixTime (const UTCDateTime& d) throw()
@ -281,22 +279,23 @@ const File File::getSpecialLocation (const SpecialLocationType type)
case tempDirectory:
{
File tmp (T("~/Library/Caches/") + executableFile.getFileNameWithoutExtension());
File tmp (T("~/Library/Caches/") + juce_getExecutableFile().getFileNameWithoutExtension());
tmp.createDirectory();
return tmp.getFullPathName();
}
case currentExecutableFile:
return executableFile;
return juce_getExecutableFile();
case currentApplicationFile:
{
const File parent (executableFile.getParentDirectory());
const File exe (juce_getExecutableFile());
const File parent (exe.getParentDirectory());
return parent.getFullPathName().endsWithIgnoreCase (T("Contents/MacOS"))
? parent.getParentDirectory().getParentDirectory()
: executableFile;
: exe;
}
default:
@ -310,22 +309,6 @@ const File File::getSpecialLocation (const SpecialLocationType type)
return File::nonexistent;
}
void juce_setCurrentExecutableFileName (const String& filename) throw()
{
executableFile = File::getCurrentWorkingDirectory()
.getChildFile (PlatformUtilities::convertToPrecomposedUnicode (filename));
}
void juce_setCurrentExecutableFileNameFromBundleId (const String& bundleId) throw()
{
const ScopedAutoReleasePool pool;
NSBundle* b = [NSBundle bundleWithIdentifier: juceStringToNS (bundleId)];
if (b != nil)
executableFile = nsStringToJuce ([b executablePath]);
}
//==============================================================================
const File File::getCurrentWorkingDirectory() throw()
{

View file

@ -64,6 +64,7 @@
#include <sys/mount.h>
#include <fnmatch.h>
#include <utime.h>
#include <dlfcn.h>
#if MACOS_10_4_OR_EARLIER
#include <GLUT/glut.h>

View file

@ -320,6 +320,13 @@ void juce_fileFlush (void* handle) throw()
fsync ((int) (pointer_sized_int) handle);
}
const File juce_getExecutableFile()
{
Dl_info exeInfo;
dladdr ((const void*) juce_getExecutableFile, &exeInfo);
return File (exeInfo.dli_fname);
}
//==============================================================================
// if this file doesn't exist, find a parent of it that does..
static bool doStatFS (const File* file, struct statfs& result) throw()

View file

@ -512,12 +512,6 @@ const File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType typ
return juce_getSpecialFolderPath (csidlType);
}
void juce_setCurrentExecutableFileName (const String&) throw()
{
// n/a on windows
}
//==============================================================================
const File File::getCurrentWorkingDirectory() throw()
{

View file

@ -60,10 +60,6 @@ static VoidArray activePlugins;
static const short channelConfigs[][2] = { JucePlugin_PreferredChannelConfigurations };
static const int numChannelConfigs = numElementsInArray (channelConfigs);
BEGIN_JUCE_NAMESPACE
extern void juce_setCurrentExecutableFileNameFromBundleId (const String& bundleId) throw();
END_JUCE_NAMESPACE
#if JucePlugin_IsSynth
#define JuceAUBaseClass MusicDeviceBase
#else
@ -119,10 +115,6 @@ public:
#endif
initialiseJuce_GUI();
#ifdef JucePlugin_CFBundleIdentifier
juce_setCurrentExecutableFileNameFromBundleId (JucePlugin_CFBundleIdentifier);
#endif
}
juceFilter = createPluginFilter();

View file

@ -1,127 +1,119 @@
/*
==============================================================================
This file is part of the JUCE library - "Jules' Utility Class Extensions"
Copyright 2004-7 by Raw Material Software ltd.
------------------------------------------------------------------------------
JUCE can be redistributed and/or modified under the terms of the
GNU General Public License, as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.
JUCE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with JUCE; if not, visit www.gnu.org/licenses or write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
------------------------------------------------------------------------------
If you'd like to release a closed-source product which uses JUCE, commercial
licenses are also available: visit www.rawmaterialsoftware.com/juce for
more information.
==============================================================================
*/
// If you get an error here, you might need to make sure that
// your build config files don't specify "C++" as one of the
// flags in OTHER_CFLAGS, because that stops the compiler building
// obj-c files correctly.
@class dummyclassname;
// Horrible carbon-based fix for a cocoa bug, where an NSWindow that wraps a carbon
// window fails to keep its position updated when the user drags the window around..
#define WINDOWPOSITON_BODGE 1
#if WINDOWPOSITON_BODGE
#include <Carbon/Carbon.h>
#endif
#include <Cocoa/Cocoa.h>
#include "../juce_PluginHeaders.h"
#if JucePlugin_Build_RTAS
BEGIN_JUCE_NAMESPACE
extern void juce_setCurrentExecutableFileNameFromBundleId (const String& bundleId) throw();
END_JUCE_NAMESPACE
//==============================================================================
void initialiseMacRTAS()
{
NSApplicationLoad();
#if defined (JucePlugin_CFBundleIdentifier)
juce_setCurrentExecutableFileNameFromBundleId (JucePlugin_CFBundleIdentifier);
#endif
}
void* attachSubWindow (void* hostWindowRef, Component* comp)
{
const ScopedAutoReleasePool pool;
NSWindow* hostWindow = [[NSWindow alloc] initWithWindowRef: hostWindowRef];
[hostWindow retain];
[hostWindow setCanHide: YES];
[hostWindow setReleasedWhenClosed: YES];
NSView* content = [hostWindow contentView];
NSRect f = [content frame];
f.size.width = comp->getWidth();
f.size.height = comp->getHeight();
[content setFrame: f];
#if WINDOWPOSITON_BODGE
{
Rect winBounds;
GetWindowBounds ((WindowRef) hostWindowRef, kWindowContentRgn, &winBounds);
NSRect w = [hostWindow frame];
w.origin.x = winBounds.left;
w.origin.y = [[NSScreen mainScreen] frame].size.height - winBounds.bottom;
[hostWindow setFrame: w display: NO animate: NO];
}
#endif
NSPoint windowPos = [hostWindow convertBaseToScreen: f.origin];
windowPos.y = [[NSScreen mainScreen] frame].size.height - (windowPos.y + f.size.height);
comp->setTopLeftPosition ((int) windowPos.x, (int) windowPos.y);
#if ! JucePlugin_EditorRequiresKeyboardFocus
comp->addToDesktop (ComponentPeer::windowIsTemporary | ComponentPeer::windowIgnoresKeyPresses);
#else
comp->addToDesktop (ComponentPeer::windowIsTemporary);
#endif
comp->setVisible (true);
NSView* pluginView = (NSView*) comp->getWindowHandle();
NSWindow* pluginWindow = [pluginView window];
[hostWindow addChildWindow: pluginWindow
ordered: NSWindowAbove];
[hostWindow orderFront: nil];
[pluginWindow orderFront: nil];
return hostWindow;
}
void removeSubWindow (void* nsWindow, Component* comp)
{
const ScopedAutoReleasePool pool;
NSView* pluginView = (NSView*) comp->getWindowHandle();
NSWindow* hostWindow = (NSWindow*) nsWindow;
NSWindow* pluginWindow = [pluginView window];
[hostWindow removeChildWindow: pluginWindow];
comp->removeFromDesktop();
[hostWindow release];
}
#endif
/*
==============================================================================
This file is part of the JUCE library - "Jules' Utility Class Extensions"
Copyright 2004-7 by Raw Material Software ltd.
------------------------------------------------------------------------------
JUCE can be redistributed and/or modified under the terms of the
GNU General Public License, as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.
JUCE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with JUCE; if not, visit www.gnu.org/licenses or write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
------------------------------------------------------------------------------
If you'd like to release a closed-source product which uses JUCE, commercial
licenses are also available: visit www.rawmaterialsoftware.com/juce for
more information.
==============================================================================
*/
// If you get an error here, you might need to make sure that
// your build config files don't specify "C++" as one of the
// flags in OTHER_CFLAGS, because that stops the compiler building
// obj-c files correctly.
@class dummyclassname;
// Horrible carbon-based fix for a cocoa bug, where an NSWindow that wraps a carbon
// window fails to keep its position updated when the user drags the window around..
#define WINDOWPOSITON_BODGE 1
#if WINDOWPOSITON_BODGE
#include <Carbon/Carbon.h>
#endif
#include <Cocoa/Cocoa.h>
#include "../juce_PluginHeaders.h"
#if JucePlugin_Build_RTAS
//==============================================================================
void initialiseMacRTAS()
{
NSApplicationLoad();
}
void* attachSubWindow (void* hostWindowRef, Component* comp)
{
const ScopedAutoReleasePool pool;
NSWindow* hostWindow = [[NSWindow alloc] initWithWindowRef: hostWindowRef];
[hostWindow retain];
[hostWindow setCanHide: YES];
[hostWindow setReleasedWhenClosed: YES];
NSView* content = [hostWindow contentView];
NSRect f = [content frame];
f.size.width = comp->getWidth();
f.size.height = comp->getHeight();
[content setFrame: f];
#if WINDOWPOSITON_BODGE
{
Rect winBounds;
GetWindowBounds ((WindowRef) hostWindowRef, kWindowContentRgn, &winBounds);
NSRect w = [hostWindow frame];
w.origin.x = winBounds.left;
w.origin.y = [[NSScreen mainScreen] frame].size.height - winBounds.bottom;
[hostWindow setFrame: w display: NO animate: NO];
}
#endif
NSPoint windowPos = [hostWindow convertBaseToScreen: f.origin];
windowPos.y = [[NSScreen mainScreen] frame].size.height - (windowPos.y + f.size.height);
comp->setTopLeftPosition ((int) windowPos.x, (int) windowPos.y);
#if ! JucePlugin_EditorRequiresKeyboardFocus
comp->addToDesktop (ComponentPeer::windowIsTemporary | ComponentPeer::windowIgnoresKeyPresses);
#else
comp->addToDesktop (ComponentPeer::windowIsTemporary);
#endif
comp->setVisible (true);
NSView* pluginView = (NSView*) comp->getWindowHandle();
NSWindow* pluginWindow = [pluginView window];
[hostWindow addChildWindow: pluginWindow
ordered: NSWindowAbove];
[hostWindow orderFront: nil];
[pluginWindow orderFront: nil];
return hostWindow;
}
void removeSubWindow (void* nsWindow, Component* comp)
{
const ScopedAutoReleasePool pool;
NSView* pluginView = (NSView*) comp->getWindowHandle();
NSWindow* hostWindow = (NSWindow*) nsWindow;
NSWindow* pluginWindow = [pluginView window];
[hostWindow removeChildWindow: pluginWindow];
comp->removeFromDesktop();
[hostWindow release];
}
#endif

File diff suppressed because it is too large Load diff

View file

@ -679,6 +679,7 @@ public:
#include <sys/mount.h>
#include <fnmatch.h>
#include <utime.h>
#include <dlfcn.h>
#if MACOS_10_4_OR_EARLIER
#include <GLUT/glut.h>
@ -16037,7 +16038,6 @@ END_JUCE_NAMESPACE
BEGIN_JUCE_NAMESPACE
void juce_setCurrentExecutableFileName (const String& filename) throw();
void juce_setCurrentThreadName (const String& name) throw();
static JUCEApplication* appInstance = 0;
@ -16257,8 +16257,6 @@ int JUCEApplication::main (int argc, char* argv[],
const ScopedAutoReleasePool pool;
#endif
juce_setCurrentExecutableFileName (String::fromUTF8 ((const uint8*) argv[0]));
String cmd;
for (int i = 1; i < argc; ++i)
cmd << String::fromUTF8 ((const uint8*) argv[i]) << T(' ');
@ -242340,11 +242338,6 @@ const File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType typ
return juce_getSpecialFolderPath (csidlType);
}
void juce_setCurrentExecutableFileName (const String&) throw()
{
// n/a on windows
}
const File File::getCurrentWorkingDirectory() throw()
{
WCHAR dest [MAX_PATH_CHARS];
@ -257098,6 +257091,13 @@ void juce_fileFlush (void* handle) throw()
fsync ((int) (pointer_sized_int) handle);
}
const File juce_getExecutableFile()
{
Dl_info exeInfo;
dladdr ((const void*) juce_getExecutableFile, &exeInfo);
return File (exeInfo.dli_fname);
}
// if this file doesn't exist, find a parent of it that does..
static bool doStatFS (const File* file, struct statfs& result) throw()
{
@ -257282,8 +257282,6 @@ void InterProcessLock::exit() throw()
}
/********* End of inlined file: juce_posix_SharedCode.h *********/
static File executableFile;
void juce_getFileTimes (const String& fileName,
int64& modificationTime,
int64& accessTime,
@ -257469,21 +257467,7 @@ const File File::getSpecialLocation (const SpecialLocationType type)
case currentExecutableFile:
case currentApplicationFile:
if (! executableFile.exists())
{
Dl_info executableInfo;
dladdr ((const void*) juce_getFileTimes, &executableInfo);
if (executableInfo.dli_fname != 0)
executableFile = File (String (executableInfo.dli_fname));
}
// if this fails, it's probably because juce_setCurrentExecutableFileName()
// was never called to set the filename - this should be done by the juce
// main() function, so maybe you've hacked it to use your own custom main()?
jassert (executableFile.exists());
return executableFile;
return juce_getExecutableFile();
default:
jassertfalse // unknown type?
@ -257493,11 +257477,6 @@ const File File::getSpecialLocation (const SpecialLocationType type)
return File::nonexistent;
}
void juce_setCurrentExecutableFileName (const String& filename) throw()
{
executableFile = File::getCurrentWorkingDirectory().getChildFile (filename);
}
const File File::getCurrentWorkingDirectory() throw()
{
char buf [2048];
@ -267222,6 +267201,13 @@ void juce_fileFlush (void* handle) throw()
fsync ((int) (pointer_sized_int) handle);
}
const File juce_getExecutableFile()
{
Dl_info exeInfo;
dladdr ((const void*) juce_getExecutableFile, &exeInfo);
return File (exeInfo.dli_fname);
}
// if this file doesn't exist, find a parent of it that does..
static bool doStatFS (const File* file, struct statfs& result) throw()
{
@ -267416,8 +267402,6 @@ void InterProcessLock::exit() throw()
live in juce_posix_SharedCode.h!
*/
static File executableFile;
const unsigned int macTimeToUnixTimeDiff = 0x7c25be90;
static uint64 utcDateTimeToUnixTime (const UTCDateTime& d) throw()
@ -267656,22 +267640,23 @@ const File File::getSpecialLocation (const SpecialLocationType type)
case tempDirectory:
{
File tmp (T("~/Library/Caches/") + executableFile.getFileNameWithoutExtension());
File tmp (T("~/Library/Caches/") + juce_getExecutableFile().getFileNameWithoutExtension());
tmp.createDirectory();
return tmp.getFullPathName();
}
case currentExecutableFile:
return executableFile;
return juce_getExecutableFile();
case currentApplicationFile:
{
const File parent (executableFile.getParentDirectory());
const File exe (juce_getExecutableFile());
const File parent (exe.getParentDirectory());
return parent.getFullPathName().endsWithIgnoreCase (T("Contents/MacOS"))
? parent.getParentDirectory().getParentDirectory()
: executableFile;
: exe;
}
default:
@ -267685,22 +267670,6 @@ const File File::getSpecialLocation (const SpecialLocationType type)
return File::nonexistent;
}
void juce_setCurrentExecutableFileName (const String& filename) throw()
{
executableFile = File::getCurrentWorkingDirectory()
.getChildFile (PlatformUtilities::convertToPrecomposedUnicode (filename));
}
void juce_setCurrentExecutableFileNameFromBundleId (const String& bundleId) throw()
{
const ScopedAutoReleasePool pool;
NSBundle* b = [NSBundle bundleWithIdentifier: juceStringToNS (bundleId)];
if (b != nil)
executableFile = nsStringToJuce ([b executablePath]);
}
const File File::getCurrentWorkingDirectory() throw()
{
char buf [2048];

View file

@ -53,7 +53,6 @@ BEGIN_JUCE_NAMESPACE
#include "../../juce_core/threads/juce_InterProcessLock.h"
#include "../../juce_core/misc/juce_PlatformUtilities.h"
void juce_setCurrentExecutableFileName (const String& filename) throw();
void juce_setCurrentThreadName (const String& name) throw();
static JUCEApplication* appInstance = 0;
@ -279,8 +278,6 @@ int JUCEApplication::main (int argc, char* argv[],
const ScopedAutoReleasePool pool;
#endif
juce_setCurrentExecutableFileName (String::fromUTF8 ((const uint8*) argv[0]));
String cmd;
for (int i = 1; i < argc; ++i)
cmd << String::fromUTF8 ((const uint8*) argv[i]) << T(' ');