1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-13 00:57:33 -05:00

Windows tools: assorted '-demo' options.

Using a new screenshot-taking module I just added in windows/utils,
these new options allow me to start up one of the tools with
demonstration window contents and automatically save a .BMP screenshot
to disk. This will allow me to keep essentially the same set of demo
images and update them easily to keep pace with the current appearance
of the real tools as PuTTY - and Windows itself - both evolve.
This commit is contained in:
Simon Tatham
2022-04-02 16:18:08 +01:00
parent 9294ee3496
commit bc7e06c494
11 changed files with 279 additions and 12 deletions

View File

@ -1,10 +1,16 @@
#include "putty.h"
#include "storage.h"
extern bool sesslist_demo_mode;
extern const char *dialog_box_demo_screenshot_filename;
static strbuf *demo_terminal_data = NULL;
static const char *terminal_demo_screenshot_filename;
void gui_term_process_cmdline(Conf *conf, char *cmdline)
{
char *p;
bool special_launchable_argument = false;
bool demo_config_box = false;
settings_set_default_protocol(be_default_protocol);
/* Find the appropriate default port. */
@ -81,6 +87,29 @@ void gui_term_process_cmdline(Conf *conf, char *cmdline)
} else if (!strcmp(p, "-pgpfp")) {
pgp_fingerprints_msgbox(NULL);
exit(1);
} else if (!strcmp(p, "-demo-config-box")) {
if (i+1 >= argc) {
cmdline_error("%s expects an output filename", p);
} else {
demo_config_box = true;
dialog_box_demo_screenshot_filename = argv[++i];
}
} else if (!strcmp(p, "-demo-terminal")) {
if (i+2 >= argc) {
cmdline_error("%s expects input and output filenames", p);
} else {
const char *infile = argv[++i];
terminal_demo_screenshot_filename = argv[++i];
FILE *fp = fopen(infile, "rb");
if (!fp)
cmdline_error("can't open input file '%s'", infile);
demo_terminal_data = strbuf_new();
char buf[4096];
int retd;
while ((retd = fread(buf, 1, sizeof(buf), fp)) > 0)
put_data(demo_terminal_data, buf, retd);
fclose(fp);
}
} else if (*p != '-') {
cmdline_error("unexpected argument \"%s\"", p);
} else {
@ -91,13 +120,26 @@ void gui_term_process_cmdline(Conf *conf, char *cmdline)
cmdline_run_saved(conf);
/*
* Bring up the config dialog if the command line hasn't
* (explicitly) specified a launchable configuration.
*/
if (!(special_launchable_argument || cmdline_host_ok(conf))) {
if (!do_config(conf))
cleanup_exit(0);
if (demo_config_box) {
sesslist_demo_mode = true;
load_open_settings(NULL, conf);
conf_set_str(conf, CONF_host, "demo-server.example.com");
do_config(conf);
cleanup_exit(0);
} else if (demo_terminal_data) {
/* Ensure conf will cause an immediate session launch */
load_open_settings(NULL, conf);
conf_set_str(conf, CONF_host, "demo-server.example.com");
conf_set_int(conf, CONF_close_on_exit, FORCE_OFF);
} else {
/*
* Bring up the config dialog if the command line hasn't
* (explicitly) specified a launchable configuration.
*/
if (!(special_launchable_argument || cmdline_host_ok(conf))) {
if (!do_config(conf))
cleanup_exit(0);
}
}
prepare_session(conf);
@ -105,6 +147,10 @@ void gui_term_process_cmdline(Conf *conf, char *cmdline)
const struct BackendVtable *backend_vt_from_conf(Conf *conf)
{
if (demo_terminal_data) {
return &null_backend;
}
/*
* Select protocol. This is farmed out into a table in a
* separate file to enable an ssh-free variant.
@ -125,3 +171,19 @@ const wchar_t *get_app_user_model_id(void)
{
return L"SimonTatham.PuTTY";
}
static void demo_terminal_screenshot(void *ctx, unsigned long now)
{
HWND hwnd = (HWND)ctx;
save_screenshot(hwnd, terminal_demo_screenshot_filename);
cleanup_exit(0);
}
void gui_terminal_ready(HWND hwnd, Seat *seat, Backend *backend)
{
if (demo_terminal_data) {
ptrlen data = ptrlen_from_strbuf(demo_terminal_data);
seat_stdout(seat, data.ptr, data.len);
schedule_timer(TICKSPERSEC, demo_terminal_screenshot, (void *)hwnd);
}
}