mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-01 11:32:48 -05:00
Add and use cmdline_arg_to_filename().
Converting a CmdlineArg straight to a Filename allows us to make the filename out of the wide-character version of the string on Windows. So now filenames specified on the command line should generally be able to handle pathnames containing Unicode characters not in the system code page. This change also involves making some char pointers _into_ Filename structs where they weren't previously: for example, the 'openssh_config_file' variable in Windows Pageant's WinMain().
This commit is contained in:
@ -459,7 +459,7 @@ static HTREEITEM treeview_insert(struct treeview_faff *faff,
|
||||
return newitem;
|
||||
}
|
||||
|
||||
const char *dialog_box_demo_screenshot_filename = NULL;
|
||||
Filename *dialog_box_demo_screenshot_filename = NULL;
|
||||
|
||||
/* ctrltrees indices for the main dialog box */
|
||||
enum {
|
||||
|
@ -1537,7 +1537,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
|
||||
const char *command = NULL;
|
||||
const char *unixsocket = NULL;
|
||||
bool show_keylist_on_startup = false;
|
||||
const char *openssh_config_file = NULL;
|
||||
Filename *openssh_config_file = NULL;
|
||||
|
||||
typedef struct CommandLineKey {
|
||||
Filename *fn;
|
||||
@ -1612,7 +1612,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
|
||||
*/
|
||||
sgrowarray(clkeys, clkeysize, nclkeys);
|
||||
CommandLineKey *clkey = &clkeys[nclkeys++];
|
||||
clkey->fn = filename_from_str(cmdline_arg_to_str(valarg));
|
||||
clkey->fn = cmdline_arg_to_filename(valarg);
|
||||
clkey->add_encrypted = add_keys_encrypted;
|
||||
} else if (match_opt("-pgpfp")) {
|
||||
pgp_fingerprints_msgbox(NULL);
|
||||
@ -1628,8 +1628,11 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
|
||||
} else if (match_opt("-keylist")) {
|
||||
show_keylist_on_startup = true;
|
||||
} else if (match_optval("-openssh-config", "-openssh_config")) {
|
||||
openssh_config_file = cmdline_arg_to_str(valarg);
|
||||
openssh_config_file = cmdline_arg_to_filename(valarg);
|
||||
} else if (match_optval("-unix")) {
|
||||
/* UNICODE: should this be a Unicode filename? Is there a
|
||||
* Unicode version of connect() that lets you give a
|
||||
* Unicode pathname when making an AF_UNIX socket? */
|
||||
unixsocket = cmdline_arg_to_str(valarg);
|
||||
} else if (match_opt("-c")) {
|
||||
/*
|
||||
@ -1735,10 +1738,11 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
|
||||
* pointing at the named pipe, do so.
|
||||
*/
|
||||
if (openssh_config_file) {
|
||||
FILE *fp = fopen(openssh_config_file, "w");
|
||||
FILE *fp = f_open(openssh_config_file, "w", true);
|
||||
if (!fp) {
|
||||
char *err = dupprintf("Unable to write OpenSSH config "
|
||||
"file to %s", openssh_config_file);
|
||||
char *err = dupprintf(
|
||||
"Unable to write OpenSSH config file to %s",
|
||||
filename_to_str(openssh_config_file));
|
||||
MessageBox(NULL, err, "Pageant Error",
|
||||
MB_ICONERROR | MB_OK);
|
||||
return 1;
|
||||
@ -1960,7 +1964,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
|
||||
* Leave this file around, but empty it, so that it doesn't
|
||||
* refer to a pipe we aren't listening on any more.
|
||||
*/
|
||||
FILE *fp = fopen(openssh_config_file, "w");
|
||||
FILE *fp = f_open(openssh_config_file, "w", true);
|
||||
if (fp)
|
||||
fclose(fp);
|
||||
}
|
||||
|
@ -859,7 +859,7 @@ bool aux_match_opt(AuxMatchOpt *amo, CmdlineArg **val,
|
||||
const char *optname, ...);
|
||||
bool aux_match_done(AuxMatchOpt *amo);
|
||||
|
||||
char *save_screenshot(HWND hwnd, const char *outfile);
|
||||
char *save_screenshot(HWND hwnd, Filename *outfile);
|
||||
void gui_terminal_ready(HWND hwnd, Seat *seat, Backend *backend);
|
||||
|
||||
void setup_gui_timing(void);
|
||||
|
@ -2,9 +2,9 @@
|
||||
#include "storage.h"
|
||||
|
||||
extern bool sesslist_demo_mode;
|
||||
extern const char *dialog_box_demo_screenshot_filename;
|
||||
extern Filename *dialog_box_demo_screenshot_filename;
|
||||
static strbuf *demo_terminal_data = NULL;
|
||||
static const char *terminal_demo_screenshot_filename;
|
||||
static Filename *terminal_demo_screenshot_filename;
|
||||
|
||||
const unsigned cmdline_tooltype =
|
||||
TOOLTYPE_HOST_ARG |
|
||||
@ -99,7 +99,7 @@ void gui_term_process_cmdline(Conf *conf, char *cmdline)
|
||||
} else {
|
||||
demo_config_box = true;
|
||||
dialog_box_demo_screenshot_filename =
|
||||
cmdline_arg_to_str(arglist->args[arglistpos++]);
|
||||
cmdline_arg_to_filename(arglist->args[arglistpos++]);
|
||||
}
|
||||
} else if (!strcmp(p, "-demo-terminal")) {
|
||||
if (!arglist->args[arglistpos] ||
|
||||
@ -109,7 +109,7 @@ void gui_term_process_cmdline(Conf *conf, char *cmdline)
|
||||
const char *infile =
|
||||
cmdline_arg_to_str(arglist->args[arglistpos++]);
|
||||
terminal_demo_screenshot_filename =
|
||||
cmdline_arg_to_str(arglist->args[arglistpos++]);
|
||||
cmdline_arg_to_filename(arglist->args[arglistpos++]);
|
||||
FILE *fp = fopen(infile, "rb");
|
||||
if (!fp)
|
||||
cmdline_error("can't open input file '%s'", infile);
|
||||
|
@ -26,9 +26,9 @@
|
||||
#define DEFAULT_ECCURVE_INDEX 0
|
||||
#define DEFAULT_EDCURVE_INDEX 0
|
||||
|
||||
static const char *cmdline_keyfile = NULL;
|
||||
static Filename *cmdline_keyfile = NULL;
|
||||
static ptrlen cmdline_demo_keystr;
|
||||
static const char *demo_screenshot_filename = NULL;
|
||||
static Filename *demo_screenshot_filename = NULL;
|
||||
|
||||
/*
|
||||
* Print a modal (Really Bad) message box and perform a fatal exit.
|
||||
@ -1737,9 +1737,7 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg,
|
||||
* Load a key file if one was provided on the command line.
|
||||
*/
|
||||
if (cmdline_keyfile) {
|
||||
Filename *fn = filename_from_str(cmdline_keyfile);
|
||||
load_key_file(hwnd, state, fn, false);
|
||||
filename_free(fn);
|
||||
load_key_file(hwnd, state, cmdline_keyfile, false);
|
||||
} else if (cmdline_demo_keystr.ptr) {
|
||||
BinarySource src[1];
|
||||
BinarySource_BARE_INIT_PL(src, cmdline_demo_keystr);
|
||||
@ -2430,7 +2428,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
|
||||
* Assume the first argument to be a private key file, and
|
||||
* attempt to load it.
|
||||
*/
|
||||
cmdline_keyfile = cmdline_arg_to_str(valarg);
|
||||
cmdline_keyfile = cmdline_arg_to_filename(valarg);
|
||||
continue;
|
||||
} else {
|
||||
opt_error("unexpected extra argument '%s'\n",
|
||||
@ -2550,7 +2548,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
|
||||
}
|
||||
sfree(val);
|
||||
} else if (match_optval("-demo-screenshot")) {
|
||||
demo_screenshot_filename = cmdline_arg_to_str(valarg);
|
||||
demo_screenshot_filename = cmdline_arg_to_filename(valarg);
|
||||
cmdline_demo_keystr = PTRLEN_LITERAL(
|
||||
"PuTTY-User-Key-File-3: ssh-ed25519\n"
|
||||
"Encryption: none\n"
|
||||
|
@ -15,7 +15,7 @@ void out_of_memory(void) { fatal_error("out of memory"); }
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const char *outfile = NULL;
|
||||
Filename *outfile = NULL;
|
||||
|
||||
AuxMatchOpt amo = aux_match_opt_init(fatal_error);
|
||||
while (!aux_match_done(&amo)) {
|
||||
@ -28,7 +28,7 @@ int main(int argc, char **argv)
|
||||
if (aux_match_arg(&amo, &val)) {
|
||||
fatal_error("unexpected argument '%s'", cmdline_arg_to_str(val));
|
||||
} else if (match_optval("-o", "--output")) {
|
||||
outfile = cmdline_arg_to_str(val);
|
||||
outfile = cmdline_arg_to_filename(val);
|
||||
} else {
|
||||
fatal_error("unrecognised option '%s'\n",
|
||||
cmdline_arg_to_str(amo.arglist->args[amo.index]));
|
||||
@ -41,6 +41,7 @@ int main(int argc, char **argv)
|
||||
char *err = save_screenshot(NULL, outfile);
|
||||
if (err)
|
||||
fatal_error("%s", err);
|
||||
filename_free(outfile);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -162,6 +162,15 @@ const char *cmdline_arg_to_utf8(CmdlineArg *argp)
|
||||
return arg->utf8;
|
||||
}
|
||||
|
||||
Filename *cmdline_arg_to_filename(CmdlineArg *argp)
|
||||
{
|
||||
if (!argp)
|
||||
return NULL;
|
||||
|
||||
CmdlineArgWin *arg = container_of(argp, CmdlineArgWin, argp);
|
||||
return filename_from_wstr(arg->wide);
|
||||
}
|
||||
|
||||
void cmdline_arg_wipe(CmdlineArg *argp)
|
||||
{
|
||||
if (!argp)
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#include <dwmapi.h>
|
||||
|
||||
char *save_screenshot(HWND hwnd, const char *outfile)
|
||||
char *save_screenshot(HWND hwnd, Filename *outfile)
|
||||
{
|
||||
HDC dcWindow = NULL, dcSave = NULL;
|
||||
HBITMAP bmSave = NULL;
|
||||
@ -89,9 +89,9 @@ char *save_screenshot(HWND hwnd, const char *outfile)
|
||||
err = dupprintf("GetDIBits (get data): %s",
|
||||
win_strerror(GetLastError()));
|
||||
|
||||
FILE *fp = fopen(outfile, "wb");
|
||||
FILE *fp = f_open(outfile, "wb", false);
|
||||
if (!fp) {
|
||||
err = dupprintf("'%s': unable to open file", outfile);
|
||||
err = dupprintf("'%s': unable to open file", filename_to_str(outfile));
|
||||
goto out;
|
||||
}
|
||||
|
||||
@ -118,7 +118,7 @@ char *save_screenshot(HWND hwnd, const char *outfile)
|
||||
#else /* HAVE_DWMAPI_H */
|
||||
|
||||
/* Without <dwmapi.h> we can't get the right window rectangle */
|
||||
char *save_screenshot(HWND hwnd, const char *outfile)
|
||||
char *save_screenshot(HWND hwnd, Filename *outfile)
|
||||
{
|
||||
return dupstr("Demo screenshots not compiled in to this build");
|
||||
}
|
||||
|
Reference in New Issue
Block a user