91 lines
2.9 KiB
C++
91 lines
2.9 KiB
C++
#include "editor/SpineEditorLocator.hpp"
|
|
#include "editor/SpineProbe.hpp"
|
|
#include "platform/ProcessRunner.hpp"
|
|
#include "scan/SpineDataVersionDetector.hpp"
|
|
|
|
#include <chrono>
|
|
#include <filesystem>
|
|
#include <iostream>
|
|
#include <string>
|
|
|
|
namespace {
|
|
|
|
void printProbe(const dts::EditorProbeResult& result) {
|
|
std::cout << "path: " << result.executable.string() << '\n';
|
|
std::cout << "status: " << dts::toString(result.status) << '\n';
|
|
if (result.launcherVersion) {
|
|
std::cout << "launcher: " << result.launcherVersion->toString() << '\n';
|
|
}
|
|
if (result.editorVersion) {
|
|
std::cout << "editor: " << result.editorVersion->toString() << '\n';
|
|
}
|
|
if (!result.edition.empty()) {
|
|
std::cout << "edition: " << result.edition << '\n';
|
|
}
|
|
std::cout << "message: " << result.message << '\n';
|
|
}
|
|
|
|
void printUsage() {
|
|
std::cout << "DateToSpine technical prototype\n"
|
|
<< "Usage:\n"
|
|
<< " datetospine-cli detect\n"
|
|
<< " datetospine-cli probe <Spine.app|executable> [timeout-ms]\n"
|
|
<< " datetospine-cli inspect-data <skeleton.json|skeleton.skel>\n";
|
|
}
|
|
|
|
} // namespace
|
|
|
|
int main(int argc, char** argv) {
|
|
if (argc < 2) {
|
|
printUsage();
|
|
return 2;
|
|
}
|
|
|
|
const std::string command = argv[1];
|
|
dts::SpineEditorLocator locator;
|
|
if (command == "detect") {
|
|
const auto candidates = locator.discover();
|
|
for (const auto& candidate : candidates) {
|
|
std::cout << candidate.string() << '\n';
|
|
}
|
|
return candidates.empty() ? 1 : 0;
|
|
}
|
|
|
|
if (command == "probe" && argc >= 3) {
|
|
const auto executable = locator.normalize(std::filesystem::path(argv[2]));
|
|
if (!executable) {
|
|
std::cerr << "The supplied path does not contain a Spine executable.\n";
|
|
return 1;
|
|
}
|
|
|
|
auto timeout = std::chrono::milliseconds(10000);
|
|
if (argc >= 4) {
|
|
try {
|
|
timeout = std::chrono::milliseconds(std::stoll(argv[3]));
|
|
} catch (...) {
|
|
std::cerr << "Invalid timeout.\n";
|
|
return 2;
|
|
}
|
|
}
|
|
auto runner = dts::createDefaultProcessRunner();
|
|
dts::SpineProbe probe(*runner);
|
|
const auto result = probe.inspect(*executable, timeout);
|
|
printProbe(result);
|
|
return result.status == dts::EditorProbeStatus::Available ? 0 : 1;
|
|
}
|
|
|
|
if (command == "inspect-data" && argc >= 3) {
|
|
const auto result = dts::SpineDataVersionDetector{}.inspect(argv[2]);
|
|
std::cout << "format: " << dts::toString(result.format) << '\n';
|
|
std::cout << "status: " << dts::toString(result.status) << '\n';
|
|
if (result.version) {
|
|
std::cout << "version: " << result.version->toString() << '\n';
|
|
}
|
|
std::cout << "message: " << result.message << '\n';
|
|
return result.status == dts::VersionDetectionStatus::Detected ? 0 : 1;
|
|
}
|
|
|
|
printUsage();
|
|
return 2;
|
|
}
|