Plan cloud transfer requests
This commit is contained in:
@@ -194,6 +194,16 @@ struct PlanCloudUploadAllArgs {
|
||||
bool progress_ui_available = true;
|
||||
};
|
||||
|
||||
struct PlanCloudTransferArgs {
|
||||
pp::app::CloudTransferDirection direction = pp::app::CloudTransferDirection::download;
|
||||
std::string source = "https://example.invalid/demo.ppi";
|
||||
std::string destination = "D:/Paint/demo.ppi";
|
||||
bool progress_callback = false;
|
||||
bool disable_tls_verification = false;
|
||||
std::int64_t progress_total = 100;
|
||||
std::int64_t progress_current = 25;
|
||||
};
|
||||
|
||||
struct PlanRecordingSessionArgs {
|
||||
bool running = false;
|
||||
std::uint32_t frame_count = 0;
|
||||
@@ -1895,6 +1905,32 @@ const char* cloud_download_selection_action_name(pp::app::CloudDownloadSelection
|
||||
return "wait-for-selection";
|
||||
}
|
||||
|
||||
const char* cloud_transfer_direction_name(pp::app::CloudTransferDirection direction) noexcept
|
||||
{
|
||||
switch (direction) {
|
||||
case pp::app::CloudTransferDirection::download:
|
||||
return "download";
|
||||
case pp::app::CloudTransferDirection::upload:
|
||||
return "upload";
|
||||
}
|
||||
|
||||
return "download";
|
||||
}
|
||||
|
||||
const char* cloud_transfer_action_name(pp::app::CloudTransferAction action) noexcept
|
||||
{
|
||||
switch (action) {
|
||||
case pp::app::CloudTransferAction::reject_missing_source:
|
||||
return "reject-missing-source";
|
||||
case pp::app::CloudTransferAction::reject_missing_destination:
|
||||
return "reject-missing-destination";
|
||||
case pp::app::CloudTransferAction::start_transfer:
|
||||
return "start-transfer";
|
||||
}
|
||||
|
||||
return "reject-missing-source";
|
||||
}
|
||||
|
||||
const char* recording_start_action_name(pp::app::RecordingStartAction action) noexcept
|
||||
{
|
||||
switch (action) {
|
||||
@@ -2074,6 +2110,20 @@ pp::foundation::Result<int> parse_i32_arg(std::string_view text)
|
||||
return pp::foundation::Result<int>::success(value);
|
||||
}
|
||||
|
||||
pp::foundation::Result<std::int64_t> parse_i64_arg(std::string_view text)
|
||||
{
|
||||
std::int64_t value = 0;
|
||||
const auto* begin = text.data();
|
||||
const auto* end = begin + text.size();
|
||||
const auto [ptr, ec] = std::from_chars(begin, end, value);
|
||||
if (ec != std::errc {} || ptr != end) {
|
||||
return pp::foundation::Result<std::int64_t>::failure(
|
||||
pp::foundation::Status::invalid_argument("invalid signed integer value"));
|
||||
}
|
||||
|
||||
return pp::foundation::Result<std::int64_t>::success(value);
|
||||
}
|
||||
|
||||
void print_help()
|
||||
{
|
||||
std::cout
|
||||
@@ -2096,6 +2146,7 @@ void print_help()
|
||||
<< " plan-cloud-upload [--no-canvas] [--new-document] [--unsaved]\n"
|
||||
<< " plan-cloud-browse [--no-canvas] [--selected-file FILE]\n"
|
||||
<< " plan-cloud-upload-all [--file-count N] [--no-progress-ui]\n"
|
||||
<< " plan-cloud-transfer [--direction download|upload] [--source TEXT] [--destination FILE] [--progress] [--disable-tls-verification] [--progress-total N] [--progress-current N]\n"
|
||||
<< " plan-recording-session [--running] [--frame-count N] [--platform-deletes-recorded-files] [--no-encoder] [--no-canvas]\n"
|
||||
<< " plan-app-preferences [--ui-scale N] [--display-density N] [--current-scale N] [--scale-option N] [--viewport-scale N] [--rtl] [--timelapse-disabled] [--recording-running] [--vr-controllers-disabled] [--cursor-mode N]\n"
|
||||
<< " plan-app-startup [--run-counter N] [--auto-timelapse-disabled] [--vr-controllers-disabled] [--license-invalid]\n"
|
||||
@@ -3525,6 +3576,105 @@ int plan_cloud_upload_all(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_cloud_transfer_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
PlanCloudTransferArgs& args)
|
||||
{
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
const std::string_view key(argv[i]);
|
||||
if (key == "--direction") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
const std::string_view value(argv[++i]);
|
||||
if (value == "download") {
|
||||
args.direction = pp::app::CloudTransferDirection::download;
|
||||
} else if (value == "upload") {
|
||||
args.direction = pp::app::CloudTransferDirection::upload;
|
||||
} else {
|
||||
return pp::foundation::Status::invalid_argument("unknown transfer direction");
|
||||
}
|
||||
} else if (key == "--source") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
args.source = argv[++i];
|
||||
} else if (key == "--destination") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
args.destination = argv[++i];
|
||||
} else if (key == "--progress") {
|
||||
args.progress_callback = true;
|
||||
} else if (key == "--disable-tls-verification") {
|
||||
args.disable_tls_verification = true;
|
||||
} else if (key == "--progress-total") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
const auto value = parse_i64_arg(argv[++i]);
|
||||
if (!value) {
|
||||
return value.status();
|
||||
}
|
||||
args.progress_total = value.value();
|
||||
} else if (key == "--progress-current") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
const auto value = parse_i64_arg(argv[++i]);
|
||||
if (!value) {
|
||||
return value.status();
|
||||
}
|
||||
args.progress_current = value.value();
|
||||
} else {
|
||||
return pp::foundation::Status::invalid_argument("unknown option");
|
||||
}
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
int plan_cloud_transfer(int argc, char** argv)
|
||||
{
|
||||
PlanCloudTransferArgs args;
|
||||
const auto status = parse_plan_cloud_transfer_args(argc, argv, args);
|
||||
if (!status.ok()) {
|
||||
print_error("plan-cloud-transfer", status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto transfer = args.direction == pp::app::CloudTransferDirection::download
|
||||
? pp::app::plan_cloud_download_transfer(
|
||||
args.source,
|
||||
args.destination,
|
||||
args.progress_callback,
|
||||
args.disable_tls_verification)
|
||||
: pp::app::plan_cloud_upload_transfer(
|
||||
args.source,
|
||||
args.progress_callback,
|
||||
args.disable_tls_verification);
|
||||
const auto progress = pp::app::plan_cloud_transfer_progress(
|
||||
args.progress_total,
|
||||
args.progress_current);
|
||||
std::cout << "{\"ok\":true,\"command\":\"plan-cloud-transfer\""
|
||||
<< ",\"state\":{\"direction\":\"" << cloud_transfer_direction_name(args.direction)
|
||||
<< "\",\"source\":\"" << json_escape(args.source)
|
||||
<< "\",\"destination\":\"" << json_escape(args.destination)
|
||||
<< "\",\"progressCallback\":" << json_bool(args.progress_callback)
|
||||
<< ",\"disableTlsVerification\":" << json_bool(args.disable_tls_verification)
|
||||
<< ",\"progressTotal\":" << args.progress_total
|
||||
<< ",\"progressCurrent\":" << args.progress_current
|
||||
<< "},\"plan\":{\"direction\":\"" << cloud_transfer_direction_name(transfer.direction)
|
||||
<< "\",\"action\":\"" << cloud_transfer_action_name(transfer.action)
|
||||
<< "\",\"enableProgress\":" << json_bool(transfer.enable_progress)
|
||||
<< ",\"disableTlsVerification\":" << json_bool(transfer.disable_tls_verification)
|
||||
<< "},\"progress\":{\"notify\":" << json_bool(progress.notify)
|
||||
<< ",\"fraction\":" << progress.fraction
|
||||
<< "}}\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_recording_session_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
@@ -10725,6 +10875,10 @@ int main(int argc, char** argv)
|
||||
return plan_cloud_upload_all(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-cloud-transfer") {
|
||||
return plan_cloud_transfer(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-recording-session") {
|
||||
return plan_recording_session(argc, argv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user