~vcs-imports/putty/master

« back to all changes in this revision

Viewing changes to windows/putty.c

  • Committer: Simon Tatham
  • Date: 2021-05-08 16:20:50 UTC
  • Revision ID: git-v1:7167c8c77165211dd352549735a903318c78fde9
Move some parts of window.c into putty.c.

This prepares the ground for a second essentially similarly-shaped
program reusing most of window.c but handling its command line and
startup differently. A couple of large parts of WinMain() to do with
backend selection and command-line handling are now subfunctions in a
separate file putty.c.

Also, our custom AppUserModelId is defined in that file, so that it
can vary with the client application.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "putty.h"
 
2
#include "storage.h"
 
3
 
 
4
void gui_term_process_cmdline(Conf *conf, char *cmdline)
 
5
{
 
6
    char *p;
 
7
    bool special_launchable_argument = false;
 
8
 
 
9
    settings_set_default_protocol(be_default_protocol);
 
10
    /* Find the appropriate default port. */
 
11
    {
 
12
        const struct BackendVtable *vt =
 
13
            backend_vt_from_proto(be_default_protocol);
 
14
        settings_set_default_port(0); /* illegal */
 
15
        if (vt)
 
16
            settings_set_default_port(vt->default_port);
 
17
    }
 
18
    conf_set_int(conf, CONF_logtype, LGTYP_NONE);
 
19
 
 
20
    do_defaults(NULL, conf);
 
21
 
 
22
    p = handle_restrict_acl_cmdline_prefix(cmdline);
 
23
 
 
24
    if (handle_special_sessionname_cmdline(p, conf)) {
 
25
        if (!conf_launchable(conf) && !do_config(conf)) {
 
26
            cleanup_exit(0);
 
27
        }
 
28
        special_launchable_argument = true;
 
29
    } else if (handle_special_filemapping_cmdline(p, conf)) {
 
30
        special_launchable_argument = true;
 
31
    } else if (!*p) {
 
32
        /* Do-nothing case for an empty command line - or rather,
 
33
         * for a command line that's empty _after_ we strip off
 
34
         * the &R prefix. */
 
35
    } else {
 
36
        /*
 
37
         * Otherwise, break up the command line and deal with
 
38
         * it sensibly.
 
39
         */
 
40
        int argc, i;
 
41
        char **argv;
 
42
 
 
43
        split_into_argv(cmdline, &argc, &argv, NULL);
 
44
 
 
45
        for (i = 0; i < argc; i++) {
 
46
            char *p = argv[i];
 
47
            int ret;
 
48
 
 
49
            ret = cmdline_process_param(p, i+1<argc?argv[i+1]:NULL,
 
50
                                        1, conf);
 
51
            if (ret == -2) {
 
52
                cmdline_error("option \"%s\" requires an argument", p);
 
53
            } else if (ret == 2) {
 
54
                i++;               /* skip next argument */
 
55
            } else if (ret == 1) {
 
56
                continue;          /* nothing further needs doing */
 
57
            } else if (!strcmp(p, "-cleanup")) {
 
58
                /*
 
59
                 * `putty -cleanup'. Remove all registry
 
60
                 * entries associated with PuTTY, and also find
 
61
                 * and delete the random seed file.
 
62
                 */
 
63
                char *s1, *s2;
 
64
                s1 = dupprintf("This procedure will remove ALL Registry entries\n"
 
65
                               "associated with %s, and will also remove\n"
 
66
                               "the random seed file. (This only affects the\n"
 
67
                               "currently logged-in user.)\n"
 
68
                               "\n"
 
69
                               "THIS PROCESS WILL DESTROY YOUR SAVED SESSIONS.\n"
 
70
                               "Are you really sure you want to continue?",
 
71
                               appname);
 
72
                s2 = dupprintf("%s Warning", appname);
 
73
                if (message_box(NULL, s1, s2,
 
74
                                MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2,
 
75
                                HELPCTXID(option_cleanup)) == IDYES) {
 
76
                    cleanup_all();
 
77
                }
 
78
                sfree(s1);
 
79
                sfree(s2);
 
80
                exit(0);
 
81
            } else if (!strcmp(p, "-pgpfp")) {
 
82
                pgp_fingerprints_msgbox(NULL);
 
83
                exit(1);
 
84
            } else if (*p != '-') {
 
85
                cmdline_error("unexpected argument \"%s\"", p);
 
86
            } else {
 
87
                cmdline_error("unknown option \"%s\"", p);
 
88
            }
 
89
        }
 
90
    }
 
91
 
 
92
    cmdline_run_saved(conf);
 
93
 
 
94
    /*
 
95
     * Bring up the config dialog if the command line hasn't
 
96
     * (explicitly) specified a launchable configuration.
 
97
     */
 
98
    if (!(special_launchable_argument || cmdline_host_ok(conf))) {
 
99
        if (!do_config(conf))
 
100
            cleanup_exit(0);
 
101
    }
 
102
 
 
103
    prepare_session(conf);
 
104
}
 
105
 
 
106
const struct BackendVtable *backend_vt_from_conf(Conf *conf)
 
107
{
 
108
    /*
 
109
     * Select protocol. This is farmed out into a table in a
 
110
     * separate file to enable an ssh-free variant.
 
111
     */
 
112
    const struct BackendVtable *vt = backend_vt_from_proto(
 
113
        conf_get_int(conf, CONF_protocol));
 
114
    if (!vt) {
 
115
        char *str = dupprintf("%s Internal Error", appname);
 
116
        MessageBox(NULL, "Unsupported protocol number found",
 
117
                   str, MB_OK | MB_ICONEXCLAMATION);
 
118
        sfree(str);
 
119
        cleanup_exit(1);
 
120
    }
 
121
    return vt;
 
122
}
 
123
 
 
124
const wchar_t *get_app_user_model_id(void)
 
125
{
 
126
    return L"SimonTatham.PuTTY";
 
127
}