SOM_Scope void  SOMLINK ODLinkSpecInitLinkSpec(ODLinkSpec *somSelf, Environment *ev,
                ODPart* part,
                ODByteArray* partData)
{
    ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
    ODLinkSpecMethodDebug("ODLinkSpec","InitLinkSpec");

        SOM_CATCH return;

        /* Moved from somInit. SOM itself sets fields to zero
        _fProcessLaunchDate = 0;
        */
        _fProcessID.lowLongOfPSN = kNoProcess;
        _fProcessID.highLongOfPSN = 0;

        somSelf->InitBaseLinkSpec(ev, part, partData);

        if ( part )
        {
                ProcessSerialNumber psn;
                ProcessInfoRec myProcessInfo;

                psn.lowLongOfPSN = kCurrentProcess;
                psn.highLongOfPSN = 0;
                myProcessInfo.processAppSpec = NULL;
                myProcessInfo.processName = NULL;
                myProcessInfo.processInfoLength = sizeof(myProcessInfo);

                OSErr error = GetProcessInformation(&psn, &myProcessInfo);
                ASSERT((error == 0), kODErrAssertionFailed);

                _fProcessID = myProcessInfo.processNumber;
                _fProcessLaunchDate = myProcessInfo.processLaunchDate;
        }
}
SOM_Scope ODBoolean  SOMLINK ODLinkSpecFromThisDraft(ODLinkSpec *somSelf, Environment *ev)
{
    ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
    ODLinkSpecMethodDebug("ODLinkSpec","FromThisDraft");

        #ifdef _PLATFORM_MACINTOSH_
        SOM_CATCH return kODFalse;

        ProcessSerialNumber myPSN;
        ProcessInfoRec myProcessInfo;
        Boolean isSamePSN;

        myPSN.lowLongOfPSN = kCurrentProcess;
        myPSN.highLongOfPSN = 0;
        myProcessInfo.processAppSpec = NULL;
        myProcessInfo.processName = NULL;
        myProcessInfo.processInfoLength = sizeof(myProcessInfo);
        THROW_IF_ERROR(GetProcessInformation(&myPSN, &myProcessInfo));
        THROW_IF_ERROR(SameProcess(&_fProcessID, &myProcessInfo.processNumber, &isSamePSN));

        return (isSamePSN && (myProcessInfo.processLaunchDate == _fProcessLaunchDate));
        #else
        return(kODFalse);
        #endif
}
// ---------------------------------------------------------------------------
OSErr FindProcess (OSType typeToFind, OSType creatorToFind, ProcessSerialNumberPtr processSN)
{
    ProcessInfoRec tempInfo;
    FSSpec procSpec;
    Str31 processName;
    OSErr myErr = noErr;
    /* null out the PSN so we're starting at the beginning of the list */
    processSN->lowLongOfPSN = kNoProcess;
    processSN->highLongOfPSN = kNoProcess;
    /* initialize the process information record */
    tempInfo.processInfoLength = sizeof(ProcessInfoRec);
    tempInfo.processName = processName;
    tempInfo.processAppSpec = &procSpec;
    /* loop through all the processes until we */
    /* 1) find the process we want */
    /* 2) error out because of some reason (usually, no more processes) */
    do {
        myErr = GetNextProcess(processSN);
        if (myErr == noErr)
            GetProcessInformation(processSN, &tempInfo);
    }
            while ((tempInfo.processSignature != creatorToFind || tempInfo.processType != typeToFind) &&
                   myErr == noErr);
    return(myErr);
}
 string& Configuration::GetExecutablePath() {
     string& path = new string("");
     ProcessSerialNumber PSN;
     ProcessInfoRec pinfo;
     FSSpec pspec;
     FSRef fsr;
     OSStatus err;
     // set up process serial number.
     PSN.highLongOfPSN = 0;
     PSN.lowLongOfPSN = kCurrentProcess;
     // set up info block.
     pinfo.processInfoLength = sizeof(pinfo);
     pinfo.processName = NULL;
     pinfo.processAppSpec = &pspec;
     // grab the vrefnum and directory.
     err = GetProcessInformation(&PSN, &pinfo);
     if (! err ) {
         char c_path[2048];
         FSSpec fss2;
         int tocopy;
         err = FSMakeFSSpec(pspec.vRefNum, pspec.parID, 0, &fss2);
         if ( ! err ) {
             err = FSpMakeFSRef(&fss2, &fsr);
             if ( ! err ) {
                 char c_path[2049];
                 err = (OSErr)FSRefMakePath(&fsr, (UInt8*)c_path, 2048);
                 if (! err ) {
                     path += c_path;
                 }
             }
         }
     }
     return path;
 }
Exemple #5
0
/******************************************************************************
	Returns the name of the process specified by ProcessSerialNumberPtr.
	
	The string pointed to by pProcessName will be untouched if the process
	can't be found. 

	pPSN			input:	The process whose name you want (nil for current).
	pProcessName	input:	Pointer to a Str31 for the process name.
					output:	The process name.
	
	RESULT CODES
	____________
	noErr			   0	No error
	paramErr		 �	Process serial number is invalid
	____________
*/
pascal	OSStatus	MoreProcGetProcessName(
								const ProcessSerialNumberPtr pPSN,
								StringPtr pProcessName)
{
	OSStatus		anErr = noErr;	
	ProcessInfoRec	infoRec;
	ProcessSerialNumber localPSN;

	MoreAssertQ(pProcessName != nil);
		
	infoRec.processInfoLength = sizeof(ProcessInfoRec);
	infoRec.processName = pProcessName;
#ifndef __LP64__
	infoRec.processAppSpec = nil;
#endif
	
	if ( pPSN == nil ) {
		localPSN.highLongOfPSN = 0;
		localPSN.lowLongOfPSN  = kCurrentProcess;
	} else {
		localPSN = *pPSN;
	}
	
	anErr = GetProcessInformation(&localPSN, &infoRec);
	
	return anErr;
}//end MoreProcGetProcessName
Exemple #6
0
// Set s_bSkipExitConfirmation to true if cancelled because of logging out or shutting down
OSErr QuitAppleEventHandler( const AppleEvent *appleEvt, AppleEvent* reply, UInt32 refcon ) {
        DescType            senderType;
        Size                actualSize;
        ProcessSerialNumber SenderPSN;
        ProcessInfoRec      pInfo;
        FSSpec              fileSpec;
        OSStatus            anErr;

        // Refuse to quit if a modal dialog is open.  
        // Unfortunately, I know of no way to disable the Quit item in our Dock menu
        if (wxGetApp().IsModalDialogDisplayed()) {
            SysBeep(4);
            return userCanceledErr;
        }
                
        anErr = AEGetAttributePtr(appleEvt, keyAddressAttr, typeProcessSerialNumber,
                                    &senderType, &SenderPSN, sizeof(SenderPSN), &actualSize);

        if (anErr == noErr) {
            pInfo.processInfoLength = sizeof( ProcessInfoRec );
            pInfo.processName = NULL;
            pInfo.processAppSpec = &fileSpec;

            anErr = GetProcessInformation(&SenderPSN, &pInfo);

            // Consider a Quit command from our Dock menu as coming from this application
            if ( (pInfo.processSignature != 'dock') && (pInfo.processSignature != 'BNC!') ) {
                s_bSkipExitConfirmation = true; // Not from our app, our dock icon or our taskbar icon
                wxGetApp().ExitMainLoop();  // Prevents wxMac from issuing events to closed frames
            }
        }
    
    return wxGetApp().MacHandleAEQuit((AppleEvent*)appleEvt, reply);
}
static OSStatus FindSystemEvents(ProcessSerialNumber *psnPtr)
	// Finds the "System Events" process or, if it's not 
	// running, launches it.
{
	OSStatus		err;
	Boolean			found = false;
	ProcessInfoRec	info;
	
	assert(psnPtr != NULL);

	psnPtr->lowLongOfPSN	= kNoProcess;
	psnPtr->highLongOfPSN	= kNoProcess;

	do {
		err = GetNextProcess(psnPtr);
		if (err == noErr) {	
			memset(&info, 0, sizeof(info));
			err = GetProcessInformation(psnPtr, &info);
		}
		if (err == noErr) {
			found = (info.processSignature == kSystemEventsCreator);
		}
	} while ( (err == noErr) && ! found );

	if (err == procNotFound) {
		err = LaunchSystemEvents(psnPtr);
	}
	return err;
}
Exemple #8
0
static pascal OSErr CoercePSNToType (DescType typecode, Ptr dataptr, Size datasize, DescType totype, long refcon, AEDesc *result) {
	
	#pragma unused (typecode, datasize, totype, refcon)
	
	ProcessInfoRec info;
	OSErr ec;
	
	info.processInfoLength = (long) sizeof (info);
	
	info.processName = nil;
	
	info.processAppSpec = nil;
	
	//Code check by Timothy Paustian Tuesday, April 25, 2000 10:22:33 PM
	//somewhat of a dangerous call, This routine assumed the dataptr coming in
	//is a ProcessSerialNumber, only accesses the signature so OK.
	ec = GetProcessInformation ((ProcessSerialNumber *) dataptr, &info);
	
	if (ec != noErr)
		return (ec);
		
	(*result).descriptorType = typeType;
	
	#if TARGET_API_MAC_CARBON == 1 /*PBS 03/14/02: AE OS X fix.*/
	
		return (putdescdatapointer (result, typeType, &info.processSignature, 4));
	
	#else
	
		return (PtrToHand (&info.processSignature, &(*result).dataHandle, 4));
	
	#endif
	} /*CoercePSNToType*/
Exemple #9
0
OSErr
FindProcessBySignature(
					   OSType				type,
					   OSType				creator,
					   ProcessSerialNumber	*psn )
{
    ProcessSerialNumber tempPSN = { 0, kNoProcess };
    ProcessInfoRec procInfo = {0};
    OSErr err = noErr;
    
    procInfo.processInfoLength = sizeof( ProcessInfoRec );
    procInfo.processName = nil;
    //procInfo.processAppSpec = nil;
    
    while( !err ) {
        err = GetNextProcess( &tempPSN );
        if( !err )
            err = GetProcessInformation( &tempPSN, &procInfo );
        if( !err
		   && procInfo.processType == type
		   && procInfo.processSignature == creator ) {
            *psn = tempPSN;
            return noErr;
        }
    }
    
    return err;
}
Exemple #10
0
/******************************************************************************
	Returns information about the process specified by ProcessSerialNumberPtr.
	
	pProcessType and pCreator will be untouched if the process
	can't be found. 

	pPSN				input:	The process whose info you want (nil for current).
	pProcessType		output:	The process's type.
	pCreator			output:	The process's signature.
	
	RESULT CODES
	____________
	noErr			   0	No error
	paramErr		 �	Process serial number is invalid
	____________
*/
pascal	OSStatus	MoreProcGetProcessTypeSignature(
						const ProcessSerialNumberPtr pPSN,
						OSType *pProcessType,
						OSType *pCreator)
{
	OSStatus			anErr = noErr;	
	ProcessInfoRec		infoRec;
	ProcessSerialNumber localPSN;
	
	infoRec.processInfoLength = sizeof(ProcessInfoRec);
	infoRec.processName = nil;
#ifndef __LP64__
	infoRec.processAppSpec = nil;
#endif

	if ( pPSN == nil ) {
		localPSN.highLongOfPSN = 0;
		localPSN.lowLongOfPSN  = kCurrentProcess;
	} else {
		localPSN = *pPSN;
	}
	
	anErr = GetProcessInformation(&localPSN, &infoRec);
	if (noErr == anErr)
	{
		*pProcessType = infoRec.processType;
		*pCreator = infoRec.processSignature;
	}
	
	return anErr;
}//end MoreProcGetProcessTypeSignature
Exemple #11
0
static Boolean appRunning (OSType appid) {
	
	/*
	return true if the server application is running. 
	*/
	
	ProcessInfoRec info;
	ProcessSerialNumber psn;
	Str255 bsname;
	FSSpec fss;
	
	info.processInfoLength = sizeof (info);
	
	info.processName = bsname; /*place to store process name*/
	
	info.processAppSpec = &fss; /*place to store process filespec*/
	
	psn.highLongOfPSN = kNoProcess;
	
	psn.lowLongOfPSN = kNoProcess;
	
	while (GetNextProcess (&psn) == noErr) {
		
	 	info.processInfoLength = sizeof (ProcessInfoRec);
	 	
		if (GetProcessInformation (&psn, &info) != noErr)
			continue; /*keep going -- ignore error*/
		
		if (info.processSignature == appid)
			return (true);
		} /*while*/
	
	return (false); /*loop completed, no server*/
	} /*appRunning*/
SOM_Scope void  SOMLINK ODLinkSpecGetOriginatingProcessID(ODLinkSpec *somSelf, Environment *ev,
                ProcessSerialNumber *psn)
{
    ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
    ODLinkSpecMethodDebug("ODLinkSpec","GetProcessLaunchDate");

        #ifdef _PLATFORM_OS2_
        _interrupt( 3 );
        #else
        ProcessInfoRec info;

        info.processAppSpec = NULL;
        info.processName = NULL;
        info.processInfoLength = sizeof(info);

        if ( (GetProcessInformation(&_fProcessID, &info) == noErr) &&
                        (info.processLaunchDate == _fProcessLaunchDate) )
        {
                *psn = _fProcessID;
        }
        else
        {
                psn->lowLongOfPSN = kNoProcess;
                psn->highLongOfPSN = 0;
                ODSetSOMException(ev, kODErrCannotGetExternalLink);
        }
        #endif
}
Exemple #13
0
/******************************************************************************
	Returns the Process Information for the process specified by pPSN.
	
	pPSN				input:	The process's Serial Number
	pPIR				output:	The process's Information.
	
	RESULT CODES
	____________
	noErr			   0	No error
	paramErr		 �	Process serial number is invalid (or pPSN or pPIR is nil)
	____________
*/
pascal OSStatus MoreProcGetProcessInformation(const ProcessSerialNumber *pPSN,ProcessInfoRec *pPIR)
{
	if (!MoreAssert (pPIR))
		return paramErr;

	pPIR->processInfoLength	= sizeof (*pPIR);
	pPIR->processName		= nil;
#ifndef __LP64__
	pPIR->processAppSpec	= nil;
#endif

	if (pPSN)
		return GetProcessInformation (pPSN,pPIR);
	else
	{
		ProcessSerialNumber psn = { kNoProcess,kCurrentProcess };
		return GetProcessInformation (&psn,pPIR);
	}
}
Exemple #14
0
void SetUpQD(void)
{
    ProcessSerialNumber PSN;
    FSSpec              myFSSpec;
    Str63               name;
    ProcessInfoRec      infoRec;
    OSErr               result = noErr;
    CFragConnectionID   connID;
    Str255              errName;

    // Memorize the plugin¹s resource file refnum for later use.
    gResFile = CurResFile();

#if !TARGET_API_MAC_CARBON
    // Ask the system if CFM is available.
    long response;
    OSErr err = Gestalt(gestaltCFMAttr, &response);
    Boolean hasCFM = BitTst(&response, 31-gestaltCFMPresent);

    if (hasCFM) {
        // GetProcessInformation takes a process serial number and
        // will give us back the name and FSSpec of the application.
        // See the Process Manager in IM.
        infoRec.processInfoLength = sizeof(ProcessInfoRec);
        infoRec.processName = name;
        infoRec.processAppSpec = &myFSSpec;

        PSN.highLongOfPSN = 0;
        PSN.lowLongOfPSN = kCurrentProcess;

        result = GetProcessInformation(&PSN, &infoRec);
    } else {
        // If no CFM installed, assume it must be a 68K app.
        result = -1;
    }

    if (result == noErr) {
        // Now that we know the app name and FSSpec, we can call
        // GetDiskFragmentto get a connID to use in a subsequent call
        // to FindSymbol (it will also return the address of ³main² in
        // app, which we ignore). If GetDiskFragment returns an
        // error, we assume the app must be 68K.
        Ptr mainAddr;
        result =  GetDiskFragment(infoRec.processAppSpec, 0L, 0L,
                                  infoRec.processName, kReferenceCFrag,
                                  &connID, (Ptr*)&mainAddr, errName);
    }

    if (result == noErr) {
        // The app is a PPC code fragment, so call FindSymbol
        // to get the exported ³qd² symbol so we can access its
        // QuickDraw globals.
        CFragSymbolClass symClass;
        result = FindSymbol(connID, "\pqd", (Ptr*)&gQDPtr, &symClass);
    } else {
Exemple #15
0
WB_INLINE
OSStatus _WBProcessGetInformation(ProcessSerialNumber *psn, ProcessInfoRec *info) {
  info->processInfoLength = (UInt32)sizeof(*info);
  info->processName = NULL;
#if defined(__LP64__) && __LP64__
  info->processAppRef = NULL;
#else
  info->processAppSpec = NULL;
#endif
  return GetProcessInformation(psn, info);
}
Exemple #16
0
internal void
CarbonApplicationLaunched(ProcessSerialNumber PSN)
{
    Str255 ProcessName = {};
    ProcessInfoRec ProcessInfo = {};
    ProcessInfo.processInfoLength = sizeof(ProcessInfoRec);
    ProcessInfo.processName = ProcessName;

    /* NOTE(koekeishiya): Deprecated, consider switching to
     * CFDictionaryRef ProcessInformationCopyDictionary(const ProcessSerialNumber *PSN, UInt32 infoToReturn) */
    GetProcessInformation(&PSN, &ProcessInfo);

    char ProcessNameCString[256] = {0};
    if(ProcessInfo.processName)
        CopyPascalStringToC(ProcessInfo.processName, ProcessNameCString);
    std::string Name = ProcessNameCString;

    /* NOTE(koekeishiya): Check if we should care about this process. */
    if((!IsProcessWhitelisted(Name)) &&
       ((ProcessInfo.processMode & modeOnlyBackground) != 0))
        return;

    pid_t PID = 0;
    GetProcessPID(&PSN, &PID);

    /*
    printf("Carbon: Application launched %s\n", Name.c_str());
    printf("%d: modeReserved\n", ProcessInfo.processMode & modeReserved);
    printf("%d: modeControlPanel\n", ProcessInfo.processMode & modeControlPanel);
    printf("%d: modeLaunchDontSwitch\n", ProcessInfo.processMode & modeLaunchDontSwitch);
    printf("%d: modeDeskAccessory\n", ProcessInfo.processMode & modeDeskAccessory);
    printf("%d: modeMultiLaunch\n", ProcessInfo.processMode & modeMultiLaunch);
    printf("%d: modeNeedSuspendResume\n", ProcessInfo.processMode & modeNeedSuspendResume);
    printf("%d: modeCanBackground\n", ProcessInfo.processMode & modeCanBackground);
    printf("%d: modeDoesActivateOnFGSwitch\n", ProcessInfo.processMode & modeDoesActivateOnFGSwitch);
    printf("%d: modeOnlyBackground\n", ProcessInfo.processMode & modeOnlyBackground);
    printf("%d: modeGetFrontClicks\n", ProcessInfo.processMode & modeGetFrontClicks);
    printf("%d: modeGetAppDiedMsg\n", ProcessInfo.processMode & modeGetAppDiedMsg);
    printf("%d: mode32BitCompatible\n", ProcessInfo.processMode & mode32BitCompatible);
    printf("%d: modeHighLevelEventAware\n", ProcessInfo.processMode & modeHighLevelEventAware);
    printf("%d: modeLocalAndRemoteHLEvents\n", ProcessInfo.processMode & modeLocalAndRemoteHLEvents);
    printf("%d: modeStationeryAware\n", ProcessInfo.processMode & modeStationeryAware);
    printf("%d: modeUseTextEditServices\n", ProcessInfo.processMode & modeUseTextEditServices);
    printf("%d: modeDisplayManagerAware\n", ProcessInfo.processMode & modeDisplayManagerAware);
    */

    (*Applications)[PID] = AXLibConstructApplication(PID, Name);
    ax_application *Application = &(*Applications)[PID];

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(),
    ^{
        if(AXLibInitializeApplication(Application->PID))
            AXLibInitializedApplication(Application);
    });
Exemple #17
0
void	AppPath(string& outString)
{
	ProcessSerialNumber	psn = { 0, kCurrentProcess };
	ProcessInfoRec info = { 0 };
	FSSpec	spec;
	Str255	name;
	info.processInfoLength = sizeof(info);
	info.processAppSpec = &spec;
	info.processName = name;
	GetProcessInformation(&psn, &info);
	FSSpec_2_String(spec, outString);
}
Exemple #18
0
int __PHYSFS_platformInit(void)
{
    OSErr err;
    ProcessSerialNumber psn;
    BAIL_IF_MACRO(oserr(GetCurrentProcess(&psn)) != noErr, NULL, 0);
    memset(&procInfo, '\0', sizeof (ProcessInfoRec));
    memset(&procfsspec, '\0', sizeof (FSSpec));
    procInfo.processInfoLength = sizeof (ProcessInfoRec);
    procInfo.processAppSpec = &procfsspec;
    err = GetProcessInformation(&psn, &procInfo);
    BAIL_IF_MACRO(oserr(err) != noErr, NULL, 0);
    return(1);  /* we're golden. */
} /* __PHYSFS_platformInit */
//
// Taken from http://wxwidgets.org/docs/technote/install.htm
//
wxString PlatformCompatibility::GetExecutablePath()
{
    static bool found = false;
    static wxString path;

    if (found)
        return path;
    else
    {
#ifdef __WXMSW__

        wxChar buf[512];
        *buf = '\0';
        GetModuleFileName(NULL, buf, 511);
        path = buf;

#elif defined(__WXMAC__)

        ProcessInfoRec processinfo;
        ProcessSerialNumber procno ;
        FSSpec fsSpec;

        procno.highLongOfPSN = 0 ;
        procno.lowLongOfPSN = kCurrentProcess ;
        processinfo.processInfoLength = sizeof(ProcessInfoRec);
        processinfo.processName = NULL;
        processinfo.processAppSpec = &fsSpec;

        GetProcessInformation( &procno , &processinfo ) ;
        path = wxMacFSSpec2MacFilename(&fsSpec);
#else
        wxString argv0 = wxGetApp().argv[0];

        if (wxIsAbsolutePath(argv0))
            path = argv0;
        else
        {
            wxPathList pathlist;
            pathlist.AddEnvList(wxT("PATH"));
            path = pathlist.FindAbsoluteValidPath(argv0);
        }

        wxFileName filename(path);
        filename.Normalize();
        path = filename.GetFullPath();
#endif
        found = true;
        return path;
    }
}
Exemple #20
0
static void noise_get_processes(void (*func) (void *, int))
{
    ProcessSerialNumber psn = {0, kNoProcess};
    ProcessInfoRec info;

    for (;;) {
        GetNextProcess(&psn);
        if (psn.highLongOfPSN == 0 && psn.lowLongOfPSN == kNoProcess) return;
        info.processInfoLength = sizeof(info);
        info.processName = NULL;
        info.processAppSpec = NULL;
        GetProcessInformation(&psn, &info);
        func(&info, sizeof(info));
    }
}
Exemple #21
0
bool __GetExeCRC(DWORD & r_dwProcCRC, DWORD & r_dwFileCRC)
{
	std::string exeFileName;
	LPCVOID c_pvBaseAddress;

	GetExcutedFileName(exeFileName);

	if (GetProcessInformation(exeFileName, &c_pvBaseAddress))
		r_dwProcCRC = GetProcessMemoryCRC(c_pvBaseAddress);
	else
		r_dwProcCRC = 0;

	r_dwFileCRC = GetFileCRC32(exeFileName.c_str());
	return true;
}
COSXScreenSaver::COSXScreenSaver(void* eventTarget) :
	m_eventTarget(eventTarget),
	m_enabled(true)
{
	m_autoReleasePool       = screenSaverUtilCreatePool();
	m_screenSaverController = screenSaverUtilCreateController();

	// install launch/termination event handlers
	EventTypeSpec launchEventTypes[2];
	launchEventTypes[0].eventClass = kEventClassApplication;
	launchEventTypes[0].eventKind  = kEventAppLaunched;
	launchEventTypes[1].eventClass = kEventClassApplication;
	launchEventTypes[1].eventKind  = kEventAppTerminated;
	
	EventHandlerUPP launchTerminationEventHandler =
		NewEventHandlerUPP(launchTerminationCallback);
	InstallApplicationEventHandler(launchTerminationEventHandler, 2,
								launchEventTypes, this,
								&m_launchTerminationEventHandlerRef);
	DisposeEventHandlerUPP(launchTerminationEventHandler);
	
	m_screenSaverPSN.highLongOfPSN = 0;
	m_screenSaverPSN.lowLongOfPSN  = 0;

	// test if screensaver is running and find process number
	if (isActive()) {
		ProcessInfoRec	procInfo;
		Str31			procName;	// pascal string. first byte holds length.
		memset(&procInfo, 0, sizeof(procInfo));
		procInfo.processName       = procName;
		procInfo.processInfoLength = sizeof(ProcessInfoRec);

		ProcessSerialNumber	psn;
		OSErr err = GetNextProcess(&psn);
		while (err == 0) {
			memset(procName, 0, sizeof(procName));
			err = GetProcessInformation(&psn, &procInfo);
			if (err != 0) {
				break;
			}
			if (strcmp("ScreenSaverEngine", (const char*)&procName[1]) == 0) {
				m_screenSaverPSN = psn;
				break;
			}
			err = GetNextProcess(&psn);
		}
	}
}
Exemple #23
0
static void getappspec (FSSpec *fs) {
	
	ProcessSerialNumber psn;
	ProcessInfoRec info;
	Str255 s;
	
	GetCurrentProcess (&psn);
	
	info.processInfoLength = (long) sizeof (info);
	
	info.processName = s; /*place to store process name*/
	
	info.processAppSpec = fs; /*place to store process filespec*/
	
	GetProcessInformation (&psn, &info);
	} /*getappspec*/
Exemple #24
0
extern OSErr get_my_fsspec(
  FSSpec *spec)
{
  ProcessSerialNumber psn;
  ProcessInfoRec pir;

  psn.highLongOfPSN=0;
  psn.lowLongOfPSN=kCurrentProcess;
  pir.processInfoLength=sizeof pir;
  pir.processName=NULL;
  pir.processAppSpec=spec;
#if defined(APPLICATION_IS_BUNDLED)
  OSStatus err = GetProcessInformation(&psn,&pir);
  if(err == noErr) {
    // Back up out of our bundle
    err = FSMakeFSSpec(spec->vRefNum, spec->parID, "\p:::", spec);
  }
Exemple #25
0
// TODO: implement this using real CoreFoundation API instead of Carbon API
wxString wxStandardPathsCF::GetExecutablePath() const
{
#ifdef __WXMAC__
    ProcessInfoRec processinfo;
    ProcessSerialNumber procno ;
    FSSpec fsSpec;

    procno.highLongOfPSN = 0 ;
    procno.lowLongOfPSN = kCurrentProcess ;
    processinfo.processInfoLength = sizeof(ProcessInfoRec);
    processinfo.processName = NULL;
    processinfo.processAppSpec = &fsSpec;

    GetProcessInformation( &procno , &processinfo ) ;
    return wxMacFSSpec2MacFilename(&fsSpec);
#else
    return wxStandardPathsBase::GetExecutablePath();
#endif
}
OSType HelperMacX::getProcessSignature(pid_t pid){
	OSErr err;
	ProcessSerialNumber processSerialNumber;
	ProcessInfoRec processInfoRec;
	processInfoRec.processInfoLength = sizeof(processInfoRec);
	processInfoRec.processAppSpec = NULL;
	processInfoRec.processName = NULL;
	err = GetProcessForPID(pid, &processSerialNumber);
	if (noErr != err) {
		qWarning("HelperMacX::getProcessSignature: GetProcessForPID error for pid %d: %d", pid, err);
		return 0;
	}
	err = GetProcessInformation(&processSerialNumber, &processInfoRec);
	if (noErr != err) {
		qWarning("HelperMacX::getProcessSignature: GetProcessInformation error for pid %d: %d\n", pid, err);
		return 0;
	}
	return processInfoRec.processSignature;
}
int
IsSkypeRunning(void)
{
	OSStatus status = noErr;
	ProcessSerialNumber psn = {kNoProcess, kNoProcess};
	unsigned int procNameLength = 32;
	unsigned char procName[procNameLength];
	unsigned int i = 0;
	ProcessInfoRec info;
	info.processInfoLength = sizeof(ProcessInfoRec);
	info.processName = procName;
#if __LP64__
	info.processAppRef = NULL;
#else
	info.processAppSpec = NULL;
#endif
	pid_t pid = 0;
	
	while(status == noErr)
	{
		for(i = 0; i < procNameLength; i++)
			procName[i] = '\0';
		
		status = GetNextProcess(&psn);
		if (status == noErr)
		{
			if (GetProcessInformation(&psn, &info) == noErr)
			{
				//for some reason first character is poisioned
				if (g_str_equal((char *)&procName[1], "Skype"))
				{
					if (GetProcessPID(&psn, &pid) == noErr)
					{
						return (int)pid;
					}
				}
			}
		}
	}
	return 0;
}
 OSStatus GetApplicationDirectory(short *vRefNum, long *dirID) {
     ProcessSerialNumber PSN;
     ProcessInfoRec pinfo;
     FSSpec pspec;
     OSStatus err;
         /* valid parameters */
     if (vRefNum == NULL || dirID == NULL) return paramErr;
         /* set up process serial number */
     PSN.highLongOfPSN = 0;
     PSN.lowLongOfPSN = kCurrentProcess;
         /* set up info block */
     pinfo.processInfoLength = sizeof(pinfo);
     pinfo.processName = NULL;
     pinfo.processAppSpec = &pspec;
         /* grab the vrefnum and directory */
     err = GetProcessInformation(&PSN, &pinfo);
     if (err == noErr) {
         *vRefNum = pspec.vRefNum;
         *dirID = pspec.parID;
     }
     return err;
 }
Exemple #29
0
/* デバッグファイルを作成し、開く */
void CreateDebugFile(void)
{
	OSErr	err;
	FSSpec	spec;
	ProcessSerialNumber	psn;
	ProcessInfoRec		processInfo;
	
	/* アプリケーションの位置を記録 */
	err=GetCurrentProcess(&psn);
	processInfo.processInfoLength=sizeof(ProcessInfoRec);
	processInfo.processName=nil;
	processInfo.processAppSpec=&spec;
	err=GetProcessInformation(&psn,&processInfo);
	
	if (err!=noErr) return;
	
	PStrCpy(kDebugFileName,spec.name);
	
	#ifdef BACKUP_LOG
	{
		/* バックアップする */
		FSSpec	bSpec=spec;
		PStrCpy(kBDebugFileName,bSpec.name);
		
		err=FSpCreate(&bSpec,kDebugFileCreator,kDebugFileType,smSystemScript);
		
		err=FSpExchangeFiles(&spec,&bSpec);
	}
	#endif
	
	/* まず消す */
	err=FSpDelete(&spec);
	
	err=FSpCreate(&spec,kDebugFileCreator,kDebugFileType,smSystemScript);
	if (err!=noErr) return;
	
	err=FSpOpenDF(&spec,fsWrPerm,&debugFileRefNum);
	if (err!=noErr) return;
}
Exemple #30
0
OSStatus GetApplicationDirectory(FSSpec *workingDirectory) {
        ProcessSerialNumber PSN;
        ProcessInfoRec pinfo;
        OSErr	err;
        
                  /* set up process serial number */
        PSN.highLongOfPSN = 0;
        PSN.lowLongOfPSN = kCurrentProcess;
            /* set up info block */
        pinfo.processInfoLength = sizeof(pinfo);
        pinfo.processName = 0;
        pinfo.processAppSpec = workingDirectory;
        err = GetProcessInformation(&PSN, &pinfo);
        if (err == noErr && isSystem9_0_or_better()) {
#if TARGET_API_MAC_CARBON && !defined(__MWERKS__)
			FSMakeFSSpecCompat(workingDirectory->vRefNum, workingDirectory->parID,"\p:::",workingDirectory);
#else
			FSSpec	checkDirectory;
            FSMakeFSSpecCompat(workingDirectory->vRefNum, workingDirectory->parID,"\p:",&checkDirectory);
            if (strncmp((const char *)checkDirectory.name,(const char *) "\pMacOSClassic",13) == 0)
				FSMakeFSSpecCompat(workingDirectory->vRefNum, workingDirectory->parID,"\p:::",workingDirectory);
#endif
        }