1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

New Windows utility function: request_file_w.

Just like the existing request_file, but wide-character oriented.
This commit is contained in:
Simon Tatham 2023-05-29 15:30:57 +01:00
parent 059f42aa56
commit e1c6f61985
2 changed files with 45 additions and 0 deletions

View File

@ -395,6 +395,8 @@ void init_common_controls(void); /* also does some DLL-loading */
*/
typedef struct filereq_tag filereq; /* cwd for file requester */
bool request_file(filereq *state, OPENFILENAME *of, bool preserve, bool save);
bool request_file_w(filereq *state, OPENFILENAMEW *of,
bool preserve, bool save);
filereq *filereq_new(void);
void filereq_free(filereq *state);
void pgp_fingerprints_msgbox(HWND owner);

View File

@ -9,6 +9,7 @@
struct filereq_tag {
TCHAR cwd[MAX_PATH];
WCHAR wcwd[MAX_PATH];
};
/*
@ -58,10 +59,52 @@ bool request_file(filereq *state, OPENFILENAME *of, bool preserve, bool save)
return ret;
}
/*
* Here's the same one again, the wide-string version
*/
bool request_file_w(filereq *state, OPENFILENAMEW *of,
bool preserve, bool save)
{
WCHAR cwd[MAX_PATH]; /* process CWD */
bool ret;
/* Get process CWD */
if (preserve) {
DWORD r = GetCurrentDirectoryW(lenof(cwd), cwd);
if (r == 0 || r >= lenof(cwd))
/* Didn't work, oh well. Stop trying to be clever. */
preserve = false;
}
/* Open the file requester, maybe setting lpstrInitialDir */
{
of->lStructSize = sizeof(*of);
of->lpstrInitialDir = (state && state->wcwd[0]) ? state->wcwd : NULL;
/* Actually put up the requester. */
ret = save ? GetSaveFileNameW(of) : GetOpenFileNameW(of);
}
/* Get CWD left by requester */
if (state) {
DWORD r = GetCurrentDirectoryW(lenof(state->wcwd), state->wcwd);
if (r == 0 || r >= lenof(state->wcwd))
/* Didn't work, oh well. */
state->wcwd[0] = L'\0';
}
/* Restore process CWD */
if (preserve)
/* If it fails, there's not much we can do. */
(void) SetCurrentDirectoryW(cwd);
return ret;
}
filereq *filereq_new(void)
{
filereq *state = snew(filereq);
state->cwd[0] = '\0';
state->wcwd[0] = L'\0';
return state;
}