X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7db33dd7ad69260bf3ee0a36278285448442daa5..0bbe61b8c18a1795189f0cf73cc61c14a0fb846d:/src/mac/corefoundation/utilsexc_base.cpp?ds=sidebyside diff --git a/src/mac/corefoundation/utilsexc_base.cpp b/src/mac/corefoundation/utilsexc_base.cpp index db2c9f38a4..41172aed2d 100644 --- a/src/mac/corefoundation/utilsexc_base.cpp +++ b/src/mac/corefoundation/utilsexc_base.cpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // Name: mac/corefoundation/utilsexc_base.cpp -// Purpose: wxMacExecute +// Purpose: wxMacLaunch // Author: Ryan Norton // Modified by: // Created: 2005-06-21 @@ -28,6 +28,7 @@ #include "wx/log.h" #include "wx/intl.h" #include "wx/utils.h" + #include "wx/wxcrt.h" #endif // WX_PRECOMP // Mac Includes @@ -39,11 +40,7 @@ #include "wx/mac/corefoundation/cfstring.h" // Default path style -#ifdef __WXMAC_OSX__ #define kDefaultPathStyle kCFURLPOSIXPathStyle -#else -#define kDefaultPathStyle kCFURLHFSPathStyle -#endif //=========================================================================== // IMPLEMENTATION @@ -51,25 +48,19 @@ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // -// wxMacExecute +// wxMacLaunch // // argv is the command line split up, with the application path first -// flags are the flags from wxExecute +// flags are the flags from wxExecute // process is the process passed from wxExecute for pipe streams etc. // returns -1 on error for wxEXEC_SYNC and 0 on error for wxEXEC_ASYNC //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -long wxMacExecute(wxChar **argv, - int flags, - wxProcess *process) +bool wxMacLaunch(char **argv) { - // Semi-macros used for return value of wxMacExecute - const long errorCode = ((flags & wxEXEC_SYNC) ? -1 : 0); - const long successCode = ((flags & wxEXEC_SYNC) ? 0 : -1); // fake PID - // Obtains the number of arguments for determining the size of // the CFArray used to hold them CFIndex cfiCount = 0; - for(wxChar** argvcopy = argv; *argvcopy != NULL ; ++argvcopy) + for(char** argvcopy = argv; *argvcopy != NULL ; ++argvcopy) { ++cfiCount; } @@ -78,28 +69,27 @@ long wxMacExecute(wxChar **argv, // to launch if(cfiCount == 0) { - wxLogDebug(wxT("wxMacExecute No file to launch!")); - return errorCode ; + wxLogDebug(wxT("wxMacLaunch No file to launch!")); + return false ; } - + // Path to bundle wxString path = *argv++; // Create a CFURL for the application path // Created this way because we are opening a bundle which is a directory - CFURLRef cfurlApp = + CFURLRef cfurlApp = CFURLCreateWithFileSystemPath( kCFAllocatorDefault, - wxMacCFStringHolder(path, - wxLocale::GetSystemEncoding()), - kDefaultPathStyle, + wxCFStringRef(path), + kDefaultPathStyle, true); //false == not a directory // Check for error from the CFURL if(!cfurlApp) { - wxLogDebug(wxT("wxMacExecute Can't open path: %s"), path.c_str()); - return errorCode ; + wxLogDebug(wxT("wxMacLaunch Can't open path: %s"), path.c_str()); + return false ; } // Create a CFBundle from the CFURL created earlier @@ -110,58 +100,57 @@ long wxMacExecute(wxChar **argv, // at all (maybe a simple directory etc.) if(!cfbApp) { - wxLogDebug(wxT("wxMacExecute Bad bundle: %s"), path.c_str()); + wxLogDebug(wxT("wxMacLaunch Bad bundle: %s"), path.c_str()); CFRelease(cfurlApp); - return errorCode ; + return false ; } - + // Get the bundle type and make sure its an 'APPL' bundle // Otherwise we're dealing with something else here... UInt32 dwBundleType, dwBundleCreator; CFBundleGetPackageInfo(cfbApp, &dwBundleType, &dwBundleCreator); if(dwBundleType != 'APPL') { - wxLogDebug(wxT("wxMacExecute Not an APPL bundle: %s"), path.c_str()); + wxLogDebug(wxT("wxMacLaunch Not an APPL bundle: %s"), path.c_str()); CFRelease(cfbApp); CFRelease(cfurlApp); - return errorCode ; + return false ; } - + // Create a CFArray for dealing with the command line // arguments to the bundle - CFMutableArrayRef cfaFiles = CFArrayCreateMutable(kCFAllocatorDefault, + CFMutableArrayRef cfaFiles = CFArrayCreateMutable(kCFAllocatorDefault, cfiCount-1, &kCFTypeArrayCallBacks); if(!cfaFiles) //This should never happen { - wxLogDebug(wxT("wxMacExecute Could not create CFMutableArray")); + wxLogDebug(wxT("wxMacLaunch Could not create CFMutableArray")); CFRelease(cfbApp); CFRelease(cfurlApp); - return errorCode ; + return false ; } - + // Loop through command line arguments to the bundle, // turn them into CFURLs and then put them in cfaFiles // For use to launch services call for( ; *argv != NULL ; ++argv) { - // Check for '<' as this will ring true for + // Check for '<' as this will ring true for // CFURLCreateWithString but is generally not considered // typical on mac but is usually passed here from wxExecute if (wxStrcmp(*argv, wxT("<")) == 0) continue; - - - CFURLRef cfurlCurrentFile; // CFURL to hold file path - wxFileName argfn(*argv); // Filename for path - + + + CFURLRef cfurlCurrentFile; // CFURL to hold file path + wxFileName argfn(*argv); // Filename for path + if(argfn.DirExists()) { // First, try creating as a directory cfurlCurrentFile = CFURLCreateWithFileSystemPath( kCFAllocatorDefault, - wxMacCFStringHolder(*argv, - wxLocale::GetSystemEncoding()), - kDefaultPathStyle, + wxCFStringRef(*argv), + kDefaultPathStyle, true); //true == directory } else if(argfn.FileExists()) @@ -170,27 +159,26 @@ long wxMacExecute(wxChar **argv, // as a regular file cfurlCurrentFile = CFURLCreateWithFileSystemPath( kCFAllocatorDefault, - wxMacCFStringHolder(*argv, - wxLocale::GetSystemEncoding()), - kDefaultPathStyle, + wxCFStringRef(*argv), + kDefaultPathStyle, false); //false == regular file - } + } else { // Argument did not refer to // an entry in the local filesystem, // so try creating it through CFURLCreateWithString cfurlCurrentFile = CFURLCreateWithString( - kCFAllocatorDefault, - wxMacCFStringHolder(*argv, wxLocale::GetSystemEncoding()), - NULL); + kCFAllocatorDefault, + wxCFStringRef(*argv), + NULL); } - + // Continue in the loop if the CFURL could not be created if(!cfurlCurrentFile) { wxLogDebug( - wxT("wxMacExecute Could not create CFURL for argument:%s"), + wxT("wxMacLaunch Could not create CFURL for argument:%s"), *argv); continue; } @@ -203,7 +191,7 @@ long wxMacExecute(wxChar **argv, ); CFRelease(cfurlCurrentFile); // array has retained it } - + // Create a LSLaunchURLSpec for use with LSOpenFromURLSpec // Note that there are several flag options (launchFlags) such // as kLSLaunchDontSwitch etc. and maybe we could be more @@ -211,10 +199,10 @@ long wxMacExecute(wxChar **argv, LSLaunchURLSpec launchspec; launchspec.appURL = cfurlApp; launchspec.itemURLs = cfaFiles; - launchspec.passThruParams = NULL; //AEDesc* - launchspec.launchFlags = kLSLaunchDefaults; + launchspec.passThruParams = NULL; //AEDesc* + launchspec.launchFlags = kLSLaunchDefaults; launchspec.asyncRefCon = NULL; - + // Finally, call LSOpenFromURL spec with our arguments // 2nd parameter is a pointer to a CFURL that gets // the actual path launched by the function @@ -224,16 +212,16 @@ long wxMacExecute(wxChar **argv, CFRelease(cfbApp); CFRelease(cfurlApp); CFRelease(cfaFiles); - + // Check for error from LSOpenFromURLSpec if(status != noErr) { - wxLogDebug(wxT("wxMacExecute LSOpenFromURLSpec Error: %d"), + wxLogDebug(wxT("wxMacLaunch LSOpenFromURLSpec Error: %d"), (int)status); - return errorCode ; + return false ; } - + // No error from LSOpenFromURLSpec, so app was launched - return successCode; + return true ; }