Permalink
Browse files

PuTTy Tray 0.60 v3: File settings backend

  • Loading branch information...
1 parent bf98347 commit 7385cb58634a960d86b46e18d702a9cde4545ffb @FauxFaux committed Feb 5, 2011
Showing with 1,809 additions and 103 deletions.
  1. +13 −1 cmdline.c
  2. +99 −15 config.c
  3. +13 −2 putty.h
  4. +92 −3 settings.c
  5. +7 −1 storage.h
  6. +2 −2 windows/windlg.c
  7. +11 −3 windows/window.c
  8. +1,572 −76 windows/winstore.c
View
@@ -175,7 +175,19 @@ int cmdline_process_param(char *p, char *value, int need_save, Config *cfg)
cmdline_session_name = dupstr(value);
return 2;
}
- if (!strcmp(p, "-ssh")) {
+
+ /*
+ * HACK: PuttyTray / PuTTY File
+ * Load file based session from commandline
+ */
+ if (!strcmp(p, "-loadfile") || !strcmp(p, "-file") || !strcmp(p, "-fileload")) {
+ RETURN(2);
+ do_defaults_file(value, cfg);
+ loaded_session = TRUE;
+ return 2;
+ }
+
+ if (!strcmp(p, "-ssh")) {
RETURN(1);
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK);
SAVEABLE(0);
View
114 config.c
@@ -15,6 +15,19 @@
#define HOST_BOX_TITLE "Host Name (or IP address)"
#define PORT_BOX_TITLE "Port"
+/*
+ * HACK: PuttyTray / PuTTY File
+ * Define and struct moved up here so they can be used in storagetype_handler
+ */
+#define SAVEDSESSION_LEN 2048
+struct sessionsaver_data {
+ union control *editbox, *listbox, *loadbutton, *savebutton, *delbutton;
+ union control *okbutton, *cancelbutton;
+ struct sesslist sesslist;
+ int midsession;
+};
+
+
static void config_host_handler(union control *ctrl, void *dlg,
void *data, int event)
{
@@ -139,6 +152,51 @@ void config_protocolbuttons_handler(union control *ctrl, void *dlg,
}
}
+/*
+ * HACK: PuttyTray / PuTTY File
+ * Storagetype radio buttons event handler
+ */
+void storagetype_handler(union control *ctrl, void *dlg, void *data, int event)
+{
+ int button;
+ struct sessionsaver_data *ssd =(struct sessionsaver_data *)ctrl->generic.context.p;
+ Config *cfg = (Config *)data;
+
+ /*
+ * For a standard radio button set, the context parameter gives
+ * offsetof(targetfield, Config), and the extra data per button
+ * gives the value the target field should take if that button
+ * is the one selected.
+ */
+ if (event == EVENT_REFRESH) {
+ button = cfg->session_storagetype; // Button index = same as storagetype number. Set according to config
+ dlg_radiobutton_set(ctrl, dlg, button);
+ } else if (event == EVENT_VALCHANGE) {
+ button = dlg_radiobutton_get(ctrl, dlg);
+
+ // Switch between registry and file
+ if (ctrl->radio.buttondata[button].i == 0) {
+ get_sesslist(&ssd->sesslist, FALSE, 0);
+ get_sesslist(&ssd->sesslist, TRUE, 0);
+ dlg_refresh(ssd->editbox, dlg);
+ dlg_refresh(ssd->listbox, dlg);
+
+ // Save setting into config (the whole *(int *)ATOFFSET(data, ctrl->radio.context.i) = ctrl->radio.buttondata[button].i; didn't work)
+ // and I don't see why I shouldn't do it this way (it works?)
+ cfg->session_storagetype = 0;
+ } else {
+ get_sesslist(&ssd->sesslist, FALSE, 1);
+ get_sesslist(&ssd->sesslist, TRUE, 1);
+ dlg_refresh(ssd->editbox, dlg);
+ dlg_refresh(ssd->listbox, dlg);
+
+ // Here as well
+ cfg->session_storagetype = 1;
+ }
+ }
+}
+/** HACK: END **/
+
static void loggingbuttons_handler(union control *ctrl, void *dlg,
void *data, int event)
{
@@ -391,15 +449,6 @@ static void sshbug_handler(union control *ctrl, void *dlg,
}
}
-#define SAVEDSESSION_LEN 2048
-
-struct sessionsaver_data {
- union control *editbox, *listbox, *loadbutton, *savebutton, *delbutton;
- union control *okbutton, *cancelbutton;
- struct sesslist sesslist;
- int midsession;
-};
-
/*
* Helper function to load the session selected in the list box, if
* any, as this is done in more than one place below. Returns 0 for
@@ -531,8 +580,13 @@ static void sessionsaver_handler(union control *ctrl, void *dlg,
sfree(errmsg);
}
}
- get_sesslist(&ssd->sesslist, FALSE);
- get_sesslist(&ssd->sesslist, TRUE);
+ /*
+ * HACK: PuttyTray / PuTTY File
+ * Added storagetype to get_sesslist
+ */
+ get_sesslist(&ssd->sesslist, FALSE, cfg->session_storagetype);
+ get_sesslist(&ssd->sesslist, TRUE, cfg->session_storagetype);
+
dlg_refresh(ssd->editbox, dlg);
dlg_refresh(ssd->listbox, dlg);
} else if (!ssd->midsession &&
@@ -542,8 +596,14 @@ static void sessionsaver_handler(union control *ctrl, void *dlg,
dlg_beep(dlg);
} else {
del_settings(ssd->sesslist.sessions[i]);
- get_sesslist(&ssd->sesslist, FALSE);
- get_sesslist(&ssd->sesslist, TRUE);
+
+ /*
+ * HACK: PuttyTray / PuTTY File
+ * Added storagetype to get_sesslist
+ */
+ get_sesslist(&ssd->sesslist, FALSE, cfg->session_storagetype);
+ get_sesslist(&ssd->sesslist, TRUE, cfg->session_storagetype);
+
dlg_refresh(ssd->listbox, dlg);
}
} else if (ctrl == ssd->okbutton) {
@@ -1141,7 +1201,7 @@ static void portfwd_handler(union control *ctrl, void *dlg,
}
void setup_config_box(struct controlbox *b, int midsession,
- int protocol, int protcfginfo)
+ int protocol, int protcfginfo, int session_storagetype) // HACK: PuttyTray / PuTTY File - Added 'int session_storagetype'
{
struct controlset *s;
struct sessionsaver_data *ssd;
@@ -1152,6 +1212,7 @@ void setup_config_box(struct controlbox *b, int midsession,
struct portfwd_data *pfd;
union control *c;
char *str;
+ int current_storagetype; // HACK: PuttyTray / PuTTY File - stores storagetype after sess_list may or may not have switched between file/registry because registry is empty
ssd = (struct sessionsaver_data *)
ctrl_alloc(b, sizeof(struct sessionsaver_data));
@@ -1231,7 +1292,8 @@ void setup_config_box(struct controlbox *b, int midsession,
midsession ? "Save the current session settings" :
"Load, save or delete a stored session");
ctrl_columns(s, 2, 75, 25);
- get_sesslist(&ssd->sesslist, TRUE);
+
+ current_storagetype = get_sesslist(&ssd->sesslist, TRUE, (midsession ? session_storagetype : (session_storagetype + 2))); // HACK: PuttyTray / PuTTY File - The +2 triggers storagetype autoswitching
ssd->editbox = ctrl_editbox(s, "Saved Sessions", 'e', 100,
HELPCTX(session_saved),
sessionsaver_handler, P(ssd), P(NULL));
@@ -1273,6 +1335,28 @@ void setup_config_box(struct controlbox *b, int midsession,
}
ctrl_columns(s, 1, 100);
+ /*
+ * HACK: PuttyTray / PuTTY File
+ * Add radio buttons
+ *
+ * Couldn't get the default selection to switch, so I switched the button position instead.
+ * Must be the lamest solution I ever came up with.
+ *
+ * In midsession, changing causes it to be reversed again (wrong). So don't.
+ */
+ if (midsession || current_storagetype == 0) {
+ c = ctrl_radiobuttons(s, NULL, 'f', 2,
+ HELPCTX(no_help),
+ storagetype_handler,
+ P(ssd), "Sessions from registry", I(0), "Sessions from file", I(1), NULL);
+ } else {
+ c = ctrl_radiobuttons(s, NULL, 'f', 2,
+ HELPCTX(no_help),
+ storagetype_handler,
+ P(ssd), "Sessions from file", I(1), "Sessions from registry", I(0), NULL);
+ }
+ /** HACK: END **/
+
s = ctrl_getset(b, "Session", "otheropts", NULL);
c = ctrl_radiobuttons(s, "Close window on exit:", 'x', 4,
HELPCTX(session_coe),
View
15 putty.h
@@ -679,6 +679,10 @@ struct config_tag {
int wakeup_reconnect;
int failure_reconnect;
+ /*
+ * HACK: PuttyTray / PuTTY File
+ */
+ int session_storagetype;
};
/*
@@ -870,10 +874,17 @@ char *save_settings(char *section, Config * cfg);
void save_open_settings(void *sesskey, Config *cfg);
void load_settings(char *section, Config * cfg);
void load_open_settings(void *sesskey, Config *cfg);
-void get_sesslist(struct sesslist *, int allocate);
+int get_sesslist(struct sesslist *, int allocate, int storagetype); // HACK: PuTTYTray / PuTTY File - changed return type
void do_defaults(char *, Config *);
void registry_cleanup(void);
+/*
+ * HACK: PuttyTray / PuTTY File
+ * Quick hack to load defaults from file
+ */
+void do_defaults_file(char *, Config *);
+void load_settings_file(char *section, Config * cfg);
+
/*
* Functions used by settings.c to provide platform-specific
* default settings.
@@ -1174,7 +1185,7 @@ void cmdline_error(char *, ...);
*/
struct controlbox;
void setup_config_box(struct controlbox *b, int midsession,
- int protocol, int protcfginfo);
+ int protocol, int protcfginfo, int session_storagetype);
/*
* Exports from minibidi.c.
View
@@ -445,6 +445,12 @@ void save_open_settings(void *sesskey, Config *cfg)
*/
write_setting_i(sesskey, "Transparency", cfg->transparency);
+ /*
+ * HACK: PuttyTray / PuTTY File
+ * Save storagetype
+ */
+ write_setting_i(sesskey, "StorageType", cfg->session_storagetype);
+
write_setting_i(sesskey, "AltF4", cfg->alt_f4);
write_setting_i(sesskey, "AltSpace", cfg->alt_space);
write_setting_i(sesskey, "AltOnly", cfg->alt_only);
@@ -579,6 +585,19 @@ void load_settings(char *section, Config * cfg)
add_session_to_jumplist(section);
}
+/*
+ * HACK: PuttyTray / PuTTY File
+ * Quick hack to load defaults from file
+ */
+void load_settings_file(char *section, Config * cfg)
+{
+ void *sesskey;
+ set_storagetype(1);
+ sesskey = open_settings_r(section);
+ load_open_settings(sesskey, cfg);
+ close_settings_r(sesskey);
+}
+
void load_open_settings(void *sesskey, Config *cfg)
{
int i;
@@ -765,6 +784,12 @@ void load_open_settings(void *sesskey, Config *cfg)
*/
gppi(sesskey, "Transparency", 255, &cfg->transparency);
+ /*
+ * HACK: PuttyTray / PuTTY File
+ * Save storagetype
+ */
+ gppi(sesskey, "StorageType", 0, &cfg->session_storagetype);
+
gppi(sesskey, "AltF4", 1, &cfg->alt_f4);
gppi(sesskey, "AltSpace", 0, &cfg->alt_space);
gppi(sesskey, "AltOnly", 0, &cfg->alt_only);
@@ -945,6 +970,15 @@ void do_defaults(char *session, Config * cfg)
load_settings(session, cfg);
}
+/*
+ * HACK: PuttyTray / PuTTY File
+ * Quick hack to load defaults from file
+ */
+void do_defaults_file(char *session, Config * cfg)
+{
+ load_settings_file(session, cfg);
+}
+
static int sessioncmp(const void *av, const void *bv)
{
const char *a = *(const char *const *) av;
@@ -965,18 +999,28 @@ static int sessioncmp(const void *av, const void *bv)
return strcmp(a, b); /* otherwise, compare normally */
}
-void get_sesslist(struct sesslist *list, int allocate)
+/*
+ * HACK: PuttyTray / PuTTY File
+ * Updated get_sesslist with storagetype
+ */
+int get_sesslist(struct sesslist *list, int allocate, int storagetype) // HACK: PuTTYTray / PuTTY File - changed return type
{
char otherbuf[2048];
int buflen, bufsize, i;
char *p, *ret;
void *handle;
+
+ // HACK: PUTTY FILE
+ int autoswitch = 0;
+ if (storagetype > 1) {
+ storagetype = storagetype - 2;
+ autoswitch = 1;
+ }
if (allocate) {
-
buflen = bufsize = 0;
list->buffer = NULL;
- if ((handle = enum_settings_start()) != NULL) {
+ if ((handle = enum_settings_start(storagetype)) != NULL) { // HACK: PuTTYTray / PuTTY File - storagetype
do {
ret = enum_settings_next(handle, otherbuf, sizeof(otherbuf));
if (ret) {
@@ -994,6 +1038,45 @@ void get_sesslist(struct sesslist *list, int allocate)
list->buffer = sresize(list->buffer, buflen + 1, char);
list->buffer[buflen] = '\0';
+ /*
+ * HACK: PuttyTray / PuTTY File
+ * Switch to file mode if registry is empty (and in registry mode)
+ */
+ if (autoswitch == 1 && storagetype != 1 && buflen == 0) {
+ storagetype = 1;
+
+ // Ok, this is a copy of the code above. Crude but working
+ buflen = bufsize = 0;
+ list->buffer = NULL;
+ if ((handle = enum_settings_start(1)) != NULL) { // Force file storage type
+ do {
+ ret = enum_settings_next(handle, otherbuf, sizeof(otherbuf));
+ if (ret) {
+ int len = strlen(otherbuf) + 1;
+ if (bufsize < buflen + len) {
+ bufsize = buflen + len + 2048;
+ list->buffer = sresize(list->buffer, bufsize, char);
+ }
+ strcpy(list->buffer + buflen, otherbuf);
+ buflen += strlen(list->buffer + buflen) + 1;
+ }
+ } while (ret);
+ enum_settings_finish(handle);
+ }
+ list->buffer = sresize(list->buffer, buflen + 1, char);
+ list->buffer[buflen] = '\0';
+ }
+
+ /*
+ * HACK: PuttyTray / PuTTY File
+ * If registry is empty AND file store is empty, show empty registry
+ */
+ if (autoswitch == 1 && storagetype == 1 && buflen == 0) {
+ storagetype = 0;
+ set_storagetype(storagetype);
+ }
+
+
/*
* Now set up the list of sessions. Note that "Default
* Settings" must always be claimed to exist, even if it
@@ -1029,4 +1112,10 @@ void get_sesslist(struct sesslist *list, int allocate)
list->buffer = NULL;
list->sessions = NULL;
}
+
+ /*
+ * HACK: PuttyTray / PuTTY File
+ * Return storagetype
+ */
+ return storagetype;
}
Oops, something went wrong.

0 comments on commit 7385cb5

Please sign in to comment.