diff --git a/PanoPainter/GameViewController.m b/PanoPainter/GameViewController.m index 74712f1..8231d21 100644 --- a/PanoPainter/GameViewController.m +++ b/PanoPainter/GameViewController.m @@ -121,6 +121,13 @@ std::recursive_mutex lock_mutex; { LOG("error creating rec path: %s", [[err localizedDescription] cStringUsingEncoding:NSASCIIStringEncoding]); } + // tmp + NSString* tmppath = [docpath stringByAppendingString:@"/tmp"]; + App::I->tmp_path = [tmppath cStringUsingEncoding:NSASCIIStringEncoding]; + if (![[NSFileManager defaultManager] createDirectoryAtPath:tmppath withIntermediateDirectories:YES attributes:nil error:&err]) + { + LOG("error creating rec path: %s", [[err localizedDescription] cStringUsingEncoding:NSASCIIStringEncoding]); + } // brushes if (![[NSFileManager defaultManager] createDirectoryAtPath:[docpath stringByAppendingString:@"/brushes"] withIntermediateDirectories:YES attributes:nil error:&err]) { @@ -189,7 +196,7 @@ std::recursive_mutex lock_mutex; - (void)pick_file_save:(std::string)path { NSURL* url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:path.c_str()]]; - GameFilePicker *picker = [[GameFilePicker alloc] initWithURL:url inMode:UIDocumentPickerModeMoveToService]; + GameFilePicker *picker = [[GameFilePicker alloc] initWithURL:url inMode:UIDocumentPickerModeExportToService]; picker.delegate = self; [self presentViewController:picker animated:YES completion:NULL]; } diff --git a/src/app.cpp b/src/app.cpp index 37132f4..ae9b143 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -781,7 +781,7 @@ void App::rec_export(std::string path) }); #endif */ - Canvas::I->m_encoder->write_mp4(data_path + "/export.mp4"); + Canvas::I->m_encoder->write_mp4(path); pb->destroy(); } diff --git a/src/app.h b/src/app.h index 7cf7753..99b1560 100644 --- a/src/app.h +++ b/src/app.h @@ -90,6 +90,7 @@ public: std::string data_path{ "." }; std::string work_path{ "." }; std::string rec_path{ "." }; + std::string tmp_path{ "." }; std::thread rec_thread; bool rec_running = false; int rec_count = 0; @@ -174,8 +175,8 @@ public: void pick_image(std::function callback); void pick_file(std::vector types, std::function callback); #if __IOS__ || __WEB__ - void pick_file_save(const std::string& type, std::function writer, - std::function callback); + void pick_file_save(const std::string& type, const std::string& default_name, + std::function writer, std::function callback); #else void pick_file_save(std::vector types, std::function callback); #endif diff --git a/src/app_dialogs.cpp b/src/app_dialogs.cpp index a3b4d1b..031aec4 100644 --- a/src/app_dialogs.cpp +++ b/src/app_dialogs.cpp @@ -624,11 +624,11 @@ void App::dialog_ppbr_export() if (dialog->export_check) info.export_data = dialog->export_check->checked; #if __IOS__ || __WEB__ - App::I->pick_file_save("ppbr", + App::I->pick_file_save("ppbr", "exported-brushes", [this, dialog, info] (std::string path) { presets->export_ppbr(path, info); }, - [dialog] (bool saved) { + [dialog] (const std::string& path, bool saved) { if (saved) dialog->destroy(); } @@ -649,11 +649,11 @@ void App::dialog_ppbr_export() void App::dialog_timelapse_export() { #if __IOS__ || __WEB__ - pick_file_save("mp4", + pick_file_save("mp4", doc_name + "-timelapse", [this](std::string path) { rec_export(path); }, - [this](bool saved) { + [this](const std::string& path, bool saved) { message_box("Export Timelapse", "Timelapse exported succesfully."); } ); @@ -837,4 +837,4 @@ void App::dialog_export_mp4() pb->destroy(); }).detach(); -} \ No newline at end of file +} diff --git a/src/app_events.cpp b/src/app_events.cpp index ff3244f..a91745c 100644 --- a/src/app_events.cpp +++ b/src/app_events.cpp @@ -236,41 +236,29 @@ void App::pick_file(std::vector types, std::function writer, - std::function callback) +void App::pick_file_save(const std::string& type, const std::string& default_name, + std::function writer, std::function callback) { redraw = true; - auto mb = input_box("Insert", "File name"); - std::string placeholder = "name." + type; - mb->m_field_text->set_text(placeholder.c_str()); - mb->on_submit = [this, writer, type, callback, mb] (Node* target, std::string name) { - std::string ext = "." + type; - std::string path = data_path + "/" + name; - if (name.find(ext) == std::string::npos) - path += ext; - std::thread([=]{ - writer(path); - dispatch_async(dispatch_get_main_queue(), ^{ - [ios_view pick_file_save:path]; - }); - mb->destroy(); - callback(true); - }).detach(); - }; - mb->btn_cancel->on_click = [=] (Node* target) { - callback(false); - mb->destroy(); - }; + std::string ext = "." + type; + std::string path = tmp_path + "/" + default_name + ext; + std::thread([=]{ + writer(path); + dispatch_async(dispatch_get_main_queue(), ^{ + [ios_view pick_file_save:path]; + }); + callback(path, true); + }).detach(); } #elif __WEB__ -void App::pick_file_save(const std::string& type, std::function writer, - std::function callback) +void App::pick_file_save(const std::string& type, const std::string& default_name, + std::function writer, std::function callback) { redraw = true; - auto path = data_path + "/file-save." + type; + auto path = data_path + "/" + default_name + "." + type; LOG("App::pick_file_save %s", path.c_str()); writer(path); - webgl_pick_file_save(path, "file." + type, callback); + webgl_pick_file_save(path, default_name + "." + type, callback); } #else void App::pick_file_save(std::vector types, std::function callback)