From 6998f53af6832317716e315d46a7738c83089e27 Mon Sep 17 00:00:00 2001 From: Anurag Aggarwal Date: Sun, 28 Jun 2020 01:58:28 +0530 Subject: [PATCH 1/2] Better path handling --- src/ui-hlp/ui_helper.cpp | 14 ++++++++++++-- src/ui/image_qt.cpp | 12 ++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/ui-hlp/ui_helper.cpp b/src/ui-hlp/ui_helper.cpp index decfc7fe..72f3935a 100644 --- a/src/ui-hlp/ui_helper.cpp +++ b/src/ui-hlp/ui_helper.cpp @@ -633,7 +633,11 @@ void uih_loadpngfile(struct uih_context *c, xio_constpath d) uih_error(c, TR("Error", "Could not open image")); return; } - uih_loadfile(c, ".xaos_temp.xpf"); + char filepath[4096]; + strcpy(filepath, xio_appdir); + strcat(filepath, XIO_PATHSEPSTR); + strcat(filepath, ".xaos_temp.xpf"); + uih_loadfile(c, filepath); if(c->errstring == NULL) { char s[256]; sprintf(s, TR("Message", "File %s loaded."), d); @@ -658,7 +662,13 @@ void uih_savepngfile(struct uih_context *c, xio_constpath d) return; } c->errstring = NULL; - uih_saveposfile(c, ".xaos_temp.xpf"); + printf("%lu", sizeof (xio_appdir)); + fflush(stdout); + char filepath[4096]; + strcpy(filepath, xio_appdir); + strcat(filepath, XIO_PATHSEPSTR); + strcat(filepath, ".xaos_temp.xpf"); + uih_saveposfile(c, filepath); s = uih_save(c, d); if (s != NULL) uih_error(c, s); diff --git a/src/ui/image_qt.cpp b/src/ui/image_qt.cpp index d6b6ab69..ff78b5f9 100644 --- a/src/ui/image_qt.cpp +++ b/src/ui/image_qt.cpp @@ -65,7 +65,11 @@ int xtextcharw(struct image */*image*/, void *font, const char c) const char *writepng(xio_constpath filename, const struct image *image) { QImage *qimage = reinterpret_cast(image->data)[image->currimage]; - QFile f(".xaos_temp.xpf"); + char filepath[4096]; + strcpy(filepath, xio_appdir); + strcat(filepath, XIO_PATHSEPSTR); + strcat(filepath, ".xaos_temp.xpf"); + QFile f(filepath); if(!f.open(QFile::ReadOnly | QFile::Text)) { @@ -90,7 +94,11 @@ const char *readpng(xio_constpath filename) if(xpf_chunk.isNull() || xpf_chunk.isEmpty()) { return "Not valid image"; } - QFile f(".xaos_temp.xpf"); + char filepath[4096]; + strcpy(filepath, xio_appdir); + strcat(filepath, XIO_PATHSEPSTR); + strcat(filepath, ".xaos_temp.xpf"); + QFile f(filepath); if(!f.open(QFile::WriteOnly | QFile::Text)) { From 9d3da98ac1eed4153ece4dcc08dc596c6b69f4af Mon Sep 17 00:00:00 2001 From: Anurag Aggarwal Date: Sun, 28 Jun 2020 02:27:39 +0530 Subject: [PATCH 2/2] Resolve paths --- src/ui-hlp/ui_helper.cpp | 8 ++------ src/ui/image_qt.cpp | 6 ++---- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/ui-hlp/ui_helper.cpp b/src/ui-hlp/ui_helper.cpp index 72f3935a..fddab10d 100644 --- a/src/ui-hlp/ui_helper.cpp +++ b/src/ui-hlp/ui_helper.cpp @@ -634,8 +634,7 @@ void uih_loadpngfile(struct uih_context *c, xio_constpath d) return; } char filepath[4096]; - strcpy(filepath, xio_appdir); - strcat(filepath, XIO_PATHSEPSTR); + strcpy(filepath, xio_getdirectory(d)); strcat(filepath, ".xaos_temp.xpf"); uih_loadfile(c, filepath); if(c->errstring == NULL) { @@ -662,11 +661,8 @@ void uih_savepngfile(struct uih_context *c, xio_constpath d) return; } c->errstring = NULL; - printf("%lu", sizeof (xio_appdir)); - fflush(stdout); char filepath[4096]; - strcpy(filepath, xio_appdir); - strcat(filepath, XIO_PATHSEPSTR); + strcpy(filepath, xio_getdirectory(d)); strcat(filepath, ".xaos_temp.xpf"); uih_saveposfile(c, filepath); s = uih_save(c, d); diff --git a/src/ui/image_qt.cpp b/src/ui/image_qt.cpp index ff78b5f9..1912f014 100644 --- a/src/ui/image_qt.cpp +++ b/src/ui/image_qt.cpp @@ -66,8 +66,7 @@ const char *writepng(xio_constpath filename, const struct image *image) { QImage *qimage = reinterpret_cast(image->data)[image->currimage]; char filepath[4096]; - strcpy(filepath, xio_appdir); - strcat(filepath, XIO_PATHSEPSTR); + strcpy(filepath, xio_getdirectory(filename)); strcat(filepath, ".xaos_temp.xpf"); QFile f(filepath); if(!f.open(QFile::ReadOnly | @@ -95,8 +94,7 @@ const char *readpng(xio_constpath filename) return "Not valid image"; } char filepath[4096]; - strcpy(filepath, xio_appdir); - strcat(filepath, XIO_PATHSEPSTR); + strcpy(filepath, xio_getdirectory(filename)); strcat(filepath, ".xaos_temp.xpf"); QFile f(filepath); if(!f.open(QFile::WriteOnly |