Retro68/LaunchAPPL/Server/AppLauncher.cc

112 lines
3.1 KiB
C++
Raw Normal View History

2019-01-23 18:41:12 +00:00
/*
Copyright 2019 Wolfgang Thaller.
This file is part of Retro68.
Retro68 is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Retro68 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 Retro68. If not, see <http://www.gnu.org/licenses/>.
*/
#include "AppLauncher.h"
#include <Processes.h>
#include <TextUtils.h>
#include <string.h>
class AppLauncher7 : public AppLauncher
{
ProcessSerialNumber psn;
public:
virtual bool Launch(ConstStr255Param name)
{
LaunchParamBlockRec lpb;
memset(&lpb, 0, sizeof(lpb));
FSSpec spec;
FSMakeFSSpec(0,0,name,&spec);
lpb.launchBlockID = extendedBlock;
lpb.launchEPBLength = extendedBlockLen;
lpb.launchFileFlags = 0;
lpb.launchControlFlags = launchContinue;
lpb.launchAppSpec = &spec;
OSErr err = LaunchApplication(&lpb);
psn = lpb.launchProcessSN;
return err >= 0;
}
virtual bool IsRunning(ConstStr255Param name)
{
ProcessInfoRec info;
memset(&info, 0, sizeof(info));
info.processInfoLength = sizeof(info);
OSErr err = GetProcessInformation(&psn,&info);
return err == noErr;
}
};
class AppLauncher6 : public AppLauncher
{
public:
virtual bool Launch(ConstStr255Param name)
{
LaunchParamBlockRec lpb;
memset(&lpb, 0, sizeof(lpb));
lpb.reserved1 = (unsigned long) name;
lpb.reserved2 = 0;
lpb.launchBlockID = extendedBlock;
lpb.launchEPBLength = 6;
lpb.launchFileFlags = 0;
lpb.launchControlFlags = 0xC000;
OSErr err = LaunchApplication(&lpb);
return err >= 0;
}
virtual bool IsRunning(ConstStr255Param name)
{
2018-04-29 14:39:12 +00:00
// Iterate through open files to find if the application is still open
uint8_t *fcbs = *(uint8_t**)0x34E; // FCBSPtr;
uint16_t bufSize = * (uint16_t*) fcbs;
uint8_t *end = fcbs + bufSize;
for(uint8_t *fcb = fcbs + 2; fcb < end; fcb += 94)
{
if(*(uint32_t*) fcb == 0)
continue;
if(*(OSType*) (fcb + 0x32) != 'APPL')
continue;
2018-04-29 14:39:12 +00:00
if(EqualString(fcb + 0x3E, name, true, true))
return true;
}
return false;
}
};
std::unique_ptr<AppLauncher> CreateAppLauncher()
{
#if TARGET_API_MAC_CARBON || TARGET_RT_MAC_CFM
return std::make_unique<AppLauncher7>();
#else
SysEnvRec environ;
SysEnvirons(curSysEnvVers, &environ);
if(environ.systemVersion >= 0x0700)
return std::make_unique<AppLauncher7>();
else
return std::make_unique<AppLauncher6>();
#endif
}