From 464277798705a7e1ac3c1ca5361d6ac265dfe550 Mon Sep 17 00:00:00 2001 From: Hugh Sanderson Date: Thu, 30 Nov 2023 15:43:15 +0800 Subject: [PATCH] Better setup default filename in windows save dialogs --- project/src/windows/System.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/project/src/windows/System.cpp b/project/src/windows/System.cpp index 29abcfa91..702d97c8b 100644 --- a/project/src/windows/System.cpp +++ b/project/src/windows/System.cpp @@ -173,8 +173,33 @@ static unsigned __stdcall dialog_proc( void *inSpec ) ofn.nMaxFile = path.size(); ofn.lpstrDefExt = "*"; - if (spec->defaultPath[0]) - ofn.lpstrInitialDir = spec->defaultPath.c_str(); + const char *path0 = spec->defaultPath.c_str(); + if (*path0) + { + const char *lastWord = path0; + bool hasDot = false; + for(const char *p=lastWord; *p; p++) + { + if (*p=='\\' || *p=='/') + { + lastWord = p + 1; + hasDot = false; + } + else if (*p=='.') + hasDot = true; + } + if (lastWord && hasDot) + { + size_t len = spec->defaultPath.size(); + memcpy(ofn.lpstrFile, spec->defaultPath.c_str(), len ); + for(size_t i=0; iflags & flagSave) ? GetSaveFileName(&ofn) : GetOpenFileName(&ofn); if (result)