From 71bf018c1a2188a2468936133f15a5bdc2900d30 Mon Sep 17 00:00:00 2001 From: cheapie Date: Mon, 22 Feb 2016 14:21:22 -0500 Subject: Openlogs ensures the file exists If the specified logs don't exist, Sparkles tries again with the network and channel swapped, and if THAT doesn't work, it displays an error --- sparkles.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/sparkles.c b/sparkles.c index d065944..aa7f383 100644 --- a/sparkles.c +++ b/sparkles.c @@ -2282,7 +2282,7 @@ static int Spark_cb(char *word[], char *word_eol[], void *userdata) { WasValid = 1; AsyncExec(word_eol[3]); } - if(!strcasecmp(word[2],"openlogs")) { + if(!strcasecmp(word[2],"openlogs") || !strcasecmp(word[2],"openlogs_")) { WasValid = 1; const char *Chan = xchat_get_info(ph, "channel"); const char *Network = xchat_get_info(ph, "network"); @@ -2300,6 +2300,20 @@ static int Spark_cb(char *word[], char *word_eol[], void *userdata) { sprintf(Buffer, "%s/logs/%s", xchat_get_info(ph, "xchatdirfs"), LogPath); else sprintf(Buffer, "%s/xchatlogs/%s", xchat_get_info(ph, "xchatdirfs"), LogPath); + + // does the file exist? + // if not, the user probably swapped the network and channel name, so try it the other way + FILE *Test = fopen(Buffer, "rb"); + if(!Test) { + if(!strcmp(word[2], "openlogs")) { // only swap if they aren't already swapped + xchat_commandf(ph, "spark openlogs_ %s %s", Network, Chan); + } else { + xchat_printf(ph, "No logs for %s:%s", Network, Chan); + } + return XCHAT_EAT_ALL; + } + fclose(Test); + xchat_commandf(ph,"spark aexec %s %s\n", TextEditor, Buffer); } -- cgit v1.2.3