2017-10-02 21:06:50 +00:00
|
|
|
#include "Launcher.h"
|
|
|
|
#include <boost/filesystem/fstream.hpp>
|
|
|
|
#include <iostream>
|
2017-10-08 20:23:08 +00:00
|
|
|
#include <sstream>
|
2017-10-02 21:06:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace fs = boost::filesystem;
|
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
Launcher::Launcher(boost::program_options::variables_map &options)
|
|
|
|
: options(options)
|
|
|
|
{
|
2019-08-18 11:21:00 +00:00
|
|
|
string fn = options["application"].as<std::string>();
|
|
|
|
|
|
|
|
if(fn == "-")
|
|
|
|
{
|
|
|
|
std::stringstream tmp;
|
|
|
|
tmp << std::cin.rdbuf();
|
|
|
|
if(!app.read(tmp, ResourceFile::Format::macbin))
|
|
|
|
throw std::runtime_error("Could not load application from stdin.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-25 15:48:02 +00:00
|
|
|
if(!app.read(fn))
|
2019-08-18 11:21:00 +00:00
|
|
|
throw std::runtime_error("Could not load application file.");
|
|
|
|
}
|
|
|
|
|
|
|
|
tempDir = fs::absolute(fs::unique_path());
|
|
|
|
fs::create_directories(tempDir);
|
|
|
|
|
|
|
|
appPath = tempDir / "Application";
|
|
|
|
outPath = tempDir / "out";
|
|
|
|
|
|
|
|
fs::ofstream out(outPath);
|
2017-10-02 21:06:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Launcher::Launcher(boost::program_options::variables_map &options, ResourceFile::Format f)
|
|
|
|
: Launcher(options)
|
|
|
|
{
|
2019-08-25 15:48:02 +00:00
|
|
|
app.write(appPath.string(), f);
|
2017-10-02 21:06:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Launcher::DumpOutput()
|
|
|
|
{
|
2019-08-18 11:21:00 +00:00
|
|
|
fs::ifstream in(outPath);
|
|
|
|
std::cout << in.rdbuf();
|
2017-10-02 21:06:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Launcher::~Launcher()
|
|
|
|
{
|
2019-08-18 11:21:00 +00:00
|
|
|
fs::remove_all(tempDir);
|
2017-10-02 21:06:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|