fix iOS save picker
This commit is contained in:
@@ -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];
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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<void(std::string path)> callback);
|
||||
void pick_file(std::vector<std::string> types, std::function<void(std::string path)> callback);
|
||||
#if __IOS__ || __WEB__
|
||||
void pick_file_save(const std::string& type, std::function<void(std::string path)> writer,
|
||||
std::function<void(bool saved)> callback);
|
||||
void pick_file_save(const std::string& type, const std::string& default_name,
|
||||
std::function<void(std::string path)> writer, std::function<void(const std::string& path, bool saved)> callback);
|
||||
#else
|
||||
void pick_file_save(std::vector<std::string> types, std::function<void(std::string path)> callback);
|
||||
#endif
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,41 +236,29 @@ void App::pick_file(std::vector<std::string> types, std::function<void (std::str
|
||||
}
|
||||
|
||||
#if __IOS__
|
||||
void App::pick_file_save(const std::string& type, std::function<void(std::string)> writer,
|
||||
std::function<void(bool saved)> callback)
|
||||
void App::pick_file_save(const std::string& type, const std::string& default_name,
|
||||
std::function<void(std::string)> writer, std::function<void(const std::string& path, bool saved)> 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<void(std::string)> writer,
|
||||
std::function<void(bool saved)> callback)
|
||||
void App::pick_file_save(const std::string& type, const std::string& default_name,
|
||||
std::function<void(std::string)> writer, std::function<void(const std::string& path, bool saved)> 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<std::string> types, std::function<void(std::string)> callback)
|
||||
|
||||
Reference in New Issue
Block a user