LaunchAPPLServer: remote upgrade capability

This commit is contained in:
Wolfgang Thaller 2018-05-05 23:45:59 +02:00
parent 569ef3d65e
commit f1fd304af4
4 changed files with 25 additions and 5 deletions

View File

@ -128,6 +128,7 @@ int main(int argc, char *argv[])
desc.add_options() desc.add_options()
("timeout,t", po::value<int>(),"abort after timeout") ("timeout,t", po::value<int>(),"abort after timeout")
("upgrade-server", "upgrade the server application")
; ;
po::options_description hidden, alldesc; po::options_description hidden, alldesc;
hidden.add_options() hidden.add_options()

View File

@ -36,6 +36,7 @@ class SerialLauncher : public Launcher
SerialStream stream; SerialStream stream;
ReliableStream rStream; ReliableStream rStream;
std::vector<char> outputBytes; std::vector<char> outputBytes;
bool upgradeMode = false;
public: public:
SerialLauncher(po::variables_map& options); SerialLauncher(po::variables_map& options);
virtual ~SerialLauncher(); virtual ~SerialLauncher();
@ -131,6 +132,8 @@ void SerialStream::wait()
SerialLauncher::SerialLauncher(po::variables_map &options) SerialLauncher::SerialLauncher(po::variables_map &options)
: Launcher(options), stream(options), rStream(&stream) : Launcher(options), stream(options), rStream(&stream)
{ {
if(options.count("upgrade-server"))
upgradeMode = true;
} }
SerialLauncher::~SerialLauncher() SerialLauncher::~SerialLauncher()
@ -174,7 +177,7 @@ bool SerialLauncher::Go(int timeout)
std::cerr << "Connected." << std::endl; std::cerr << "Connected." << std::endl;
{ {
RemoteCommand cmd = RemoteCommand::launchApp; RemoteCommand cmd = upgradeMode ? RemoteCommand::upgradeLauncher : RemoteCommand::launchApp;
write(&cmd, 1); write(&cmd, 1);
write(std::string(app.type).data(), 4); write(std::string(app.type).data(), 4);
@ -199,13 +202,12 @@ bool SerialLauncher::Go(int timeout)
std::cerr << "Running Appliation..." << std::endl; std::cerr << "Running Appliation..." << std::endl;
read(&tmp, 4); read(&tmp, 4);
uint32_t result = ntohl(tmp); uint32_t result = ntohl(tmp);
std::cerr << "Finished." << std::endl; std::cerr << "Finished (result = " << result << ")." << std::endl;
if(result == 0) if(result == 0)
{ {
read(&tmp, 4); read(&tmp, 4);
uint32_t size = ntohl(tmp); uint32_t size = ntohl(tmp);
outputBytes.resize(size); outputBytes.resize(size);
if(size > 0) if(size > 0)
read(outputBytes.data(), size); read(outputBytes.data(), size);

View File

@ -4,5 +4,6 @@
enum class RemoteCommand : uint8_t enum class RemoteCommand : uint8_t
{ {
launchApp = 1 launchApp = 1,
upgradeLauncher = 2
}; };

View File

@ -27,6 +27,7 @@
#include <Dialogs.h> #include <Dialogs.h>
#include <Devices.h> #include <Devices.h>
#include <Traps.h> #include <Traps.h>
#include <LowMem.h>
#include "MacSerialStream.h" #include "MacSerialStream.h"
#include "AppLauncher.h" #include "AppLauncher.h"
@ -290,7 +291,7 @@ public:
if(n < 1) if(n < 1)
return 0; return 0;
command = (RemoteCommand)p[0]; command = (RemoteCommand)p[0];
if(command == RemoteCommand::launchApp) if(command == RemoteCommand::launchApp || command == RemoteCommand::upgradeLauncher)
state = State::header; state = State::header;
return 1; return 1;
} }
@ -538,6 +539,21 @@ int main()
gSerialStream->close(); gSerialStream->close();
gPrefs.inSubLaunch = true; gPrefs.inSubLaunch = true;
WritePrefs(); WritePrefs();
if(server.command == RemoteCommand::upgradeLauncher)
{
FSDelete("\pLaunchAPPLServer.old", 0);
Rename(LMGetCurApName(), 0, "\pLaunchAPPLServer.old");
Rename("\pRetro68App", 0, LMGetCurApName());
LaunchParamBlockRec lpb;
memset(&lpb, 0, sizeof(lpb));
lpb.reserved1 = (unsigned long) LMGetCurApName();
lpb.reserved2 = 0;
OSErr err = LaunchApplication(&lpb);
ExitToShell();
}
bool launched = appLauncher->Launch("\pRetro68App"); bool launched = appLauncher->Launch("\pRetro68App");
gPrefs.inSubLaunch = false; gPrefs.inSubLaunch = false;
WritePrefs(); WritePrefs();