implement work_path for documents and data_path for assets
This commit is contained in:
@@ -953,13 +953,13 @@ bool ui::Canvas::create(int width, int height)
|
||||
return true;
|
||||
}
|
||||
|
||||
void ui::Canvas::snapshot_save(std::string data_path)
|
||||
void ui::Canvas::snapshot_save()
|
||||
{
|
||||
LOG("SAVE SNAPSHOT");
|
||||
m_layers_snapshot.clear();
|
||||
m_layers_snapshot.resize(m_layers.size());
|
||||
for (int i = 0; i < m_layers.size(); i++)
|
||||
m_layers_snapshot[i] = m_layers[i].snapshot(data_path);
|
||||
m_layers_snapshot[i] = m_layers[i].snapshot();
|
||||
}
|
||||
|
||||
void ui::Canvas::snapshot_restore()
|
||||
@@ -968,7 +968,6 @@ void ui::Canvas::snapshot_restore()
|
||||
for (int i = 0; i < m_layers.size(); i++)
|
||||
m_layers[i].restore(m_layers_snapshot[i]);
|
||||
m_layers_snapshot.clear();
|
||||
LOG("RESTORE SNAPSHOT complete");
|
||||
}
|
||||
|
||||
void ui::Canvas::clear_context()
|
||||
@@ -1303,7 +1302,7 @@ void ui::Canvas::inject_xmp(std::string jpg_path)
|
||||
|
||||
}
|
||||
|
||||
void ui::Canvas::export_anim(std::string data_path)
|
||||
void ui::Canvas::export_anim()
|
||||
{
|
||||
if (!App::I.check_license())
|
||||
return;
|
||||
@@ -1396,7 +1395,7 @@ void ui::Canvas::export_anim(std::string data_path)
|
||||
auto latlong_data = std::make_unique<uint8_t[]>(m_latlong.bytes());
|
||||
m_latlong.readTextureData(latlong_data.get());
|
||||
static char name[128];
|
||||
sprintf(name, "%s/latlong-frame%02d.png", data_path.c_str(), seq);
|
||||
sprintf(name, "%s/latlong-frame%02d.png", App::I.work_path.c_str(), seq);
|
||||
seq++;
|
||||
LOG("writing %s", name);
|
||||
int ret = stbi_write_png(name, m_latlong.getWidth(), m_latlong.getHeight(), 4, latlong_data.get(), m_latlong.stride());
|
||||
@@ -1416,7 +1415,7 @@ void ui::Canvas::export_anim(std::string data_path)
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
|
||||
void ui::Canvas::export_cubes(std::string data_path)
|
||||
void ui::Canvas::export_cubes()
|
||||
{
|
||||
if (!App::I.check_license())
|
||||
return;
|
||||
@@ -1465,7 +1464,7 @@ void ui::Canvas::export_cubes(std::string data_path)
|
||||
}
|
||||
|
||||
static char name[128];
|
||||
sprintf(name, "%s-%02d-%d.png", data_path.c_str(), layer, plane);
|
||||
sprintf(name, "%s-%02d-%d.png", App::I.work_path.c_str(), layer, plane);
|
||||
int ret = stbi_write_png(name, m_width, m_height, 4, buffer.get(), 0);
|
||||
|
||||
|
||||
@@ -1490,7 +1489,7 @@ void ui::Canvas::export_cubes(std::string data_path)
|
||||
}
|
||||
#ifdef __OBJC__
|
||||
static char name[128];
|
||||
sprintf(name, "%s.zip", data_path.c_str());
|
||||
sprintf(name, "%s.zip", App::I.work_path.c_str());
|
||||
auto zip_path = [NSString stringWithUTF8String : name];
|
||||
//[SSZipArchive createZipFileAtPath:zip_path withFilesAtPaths:files];
|
||||
for (NSString* f : files)
|
||||
@@ -1503,7 +1502,7 @@ void ui::Canvas::project_save(std::function<void()> on_complete)
|
||||
if (App::I.check_license())
|
||||
{
|
||||
std::thread t([=] {
|
||||
project_save_thread(App::I.data_path + "/" + App::I.doc_name + ".ppi");
|
||||
project_save_thread(App::I.doc_path);
|
||||
if (on_complete)
|
||||
on_complete();
|
||||
});
|
||||
@@ -1536,7 +1535,10 @@ void ui::Canvas::project_save_thread(std::string file_path)
|
||||
// sprintf(name, "%s/latlong.ppi", data_path.c_str());
|
||||
FILE* fp;
|
||||
|
||||
std::string tmp_path = file_path.substr(0, file_path.size() - strlen(".ppi")) + ".tmp.ppi";
|
||||
auto start = file_path.rfind('/') + 1;
|
||||
std::string file_name = file_path.substr(start, file_path.length() - start - strlen(".ppi"));
|
||||
std::string tmp_path = App::I.data_path + '/' + file_name + ".tmp.ppi";
|
||||
|
||||
bool use_tmp = false;
|
||||
// check if file already exists
|
||||
if ((fp = fopen(file_path.c_str(), "rb")))
|
||||
@@ -1546,11 +1548,13 @@ void ui::Canvas::project_save_thread(std::string file_path)
|
||||
use_tmp = true;
|
||||
if (!(fp = fopen(tmp_path.c_str(), "wb")))
|
||||
{
|
||||
LOG("cannot write project to %s", file_path.c_str());
|
||||
return;
|
||||
LOG("cannot write tmp project to %s", tmp_path.c_str());
|
||||
//return;
|
||||
use_tmp = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (!fp)
|
||||
{
|
||||
// write directly to the new file
|
||||
if (!(fp = fopen(file_path.c_str(), "wb")))
|
||||
@@ -1558,6 +1562,7 @@ void ui::Canvas::project_save_thread(std::string file_path)
|
||||
LOG("cannot write project to %s", file_path.c_str());
|
||||
return;
|
||||
}
|
||||
LOG("unsafe mode saving directly to %s", file_path.c_str());
|
||||
}
|
||||
|
||||
PPIHeader ppi_header;
|
||||
@@ -1602,7 +1607,7 @@ void ui::Canvas::project_save_thread(std::string file_path)
|
||||
fwrite(m_layers[i].m_name.data(), name_len, 1, fp);
|
||||
|
||||
App::I.async_start();
|
||||
auto snap = m_layers[i].snapshot(file_path);
|
||||
auto snap = m_layers[i].snapshot();
|
||||
App::I.async_update();
|
||||
App::I.async_end();
|
||||
for (int plane_index = 0; plane_index < 6; plane_index++)
|
||||
@@ -1901,14 +1906,14 @@ ui::Image ui::Canvas::thumbnail_generate(int w, int h)
|
||||
return image;
|
||||
}
|
||||
|
||||
ui::Image ui::Canvas::thumbnail_read(std::string data_path)
|
||||
ui::Image ui::Canvas::thumbnail_read(std::string file_path)
|
||||
{
|
||||
// static char name[128];
|
||||
// sprintf(name, "%s/latlong.ppi", data_path.c_str());
|
||||
FILE* fp = fopen(data_path.c_str(), "rb");
|
||||
FILE* fp = fopen(file_path.c_str(), "rb");
|
||||
if (!fp)
|
||||
{
|
||||
LOG("cannot read project %s", data_path.c_str());
|
||||
LOG("cannot read project %s", file_path.c_str());
|
||||
return {}; // return empty image
|
||||
}
|
||||
PPIHeader ppi_header;
|
||||
@@ -1924,7 +1929,7 @@ ui::Image ui::Canvas::thumbnail_read(std::string data_path)
|
||||
thumb.create();
|
||||
fread((uint8_t*)thumb.data(), thumb.size(), 1, fp);
|
||||
fclose(fp);
|
||||
LOG("project thumbnail read from %s", data_path.c_str());
|
||||
LOG("project thumbnail read from %s", file_path.c_str());
|
||||
return thumb;
|
||||
}
|
||||
|
||||
@@ -2134,7 +2139,7 @@ void ui::Layer::restore(const Snapshot& snap)
|
||||
}
|
||||
}
|
||||
|
||||
ui::Layer::Snapshot ui::Layer::snapshot(std::string data_path)
|
||||
ui::Layer::Snapshot ui::Layer::snapshot()
|
||||
{
|
||||
Snapshot snap;
|
||||
static int counter = 0;
|
||||
@@ -2156,11 +2161,6 @@ ui::Layer::Snapshot ui::Layer::snapshot(std::string data_path)
|
||||
glReadPixels(m_dirty_box[i].x, m_dirty_box[i].y, box_sz.x, box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE, snap.image[i].get());
|
||||
m_rtt[i].unbindFramebuffer();
|
||||
//glReadBuffer(GL_NONE);
|
||||
|
||||
LOG("snapshot face %d - %d bytes (%dx%d)", i, (int)box_sz.x * (int)box_sz.y * 4, (int)box_sz.x, (int)box_sz.y);
|
||||
static char name[128];
|
||||
sprintf(name, "%s/Layer%d-%d.png", data_path.c_str(), counter, i);
|
||||
//int ret = stbi_write_png(name, m_rtt[i].getWidth(), m_rtt[i].getHeight(), 4, snap.image[i].get(), m_rtt[i].stride());
|
||||
}
|
||||
counter++;
|
||||
return snap;
|
||||
|
||||
Reference in New Issue
Block a user