diff --git a/README.md b/README.md index e4ad91d..821a331 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,15 @@ Commands Allows you to reset a configuration option back to the default value. +* `save ` + + Writes your options to a file with the given path and name. + +* `load ` + + Loads your options from a file with the given path and name. Caution should be taken, + as this will lose any options that aren't already saved to the given file. + * `status []` Check the status of current conditions. Specifying the "context" of either a channel diff --git a/notifo.cpp b/notifo.cpp index 79d5d51..72ef807 100644 --- a/notifo.cpp +++ b/notifo.cpp @@ -912,6 +912,72 @@ class CNotifoMod : public CModule PutModule(option + CString(": \"") + options[option] + CString("\"")); } } + // SAVE command + else if (action == "save") + { + if (token_count < 2) + { + PutModule("Usage: save "); + } + + CString file_path = command.Token(1, true, " "); + MCString::status_t status = options.WriteToDisk(file_path); + + if (status == MCString::MCS_SUCCESS) + { + PutModule("Options saved to " + file_path); + } + else + { + switch (status) + { + case MCString::MCS_EOPEN: + case MCString::MCS_EWRITE: + case MCString::MCS_EWRITEFIL: + PutModule("Failed to save options to " + file_path); + break; + default: + PutModule("Failure"); + break; + } + } + } + // LOAD command + else if (action == "load") + { + if (token_count < 2) + { + PutModule("Usage: load "); + } + + CString file_path = command.Token(1, true, " "); + + if (!CFile::Exists(file_path)) + { + PutModule("File does not exist: " + file_path); + return; + } + + MCString::status_t status = options.ReadFromDisk(file_path); + + if (status == MCString::MCS_SUCCESS) + { + PutModule("Options loaded from " + file_path); + } + else + { + switch (status) + { + case MCString::MCS_EOPEN: + case MCString::MCS_EREADFIL: + PutModule("Failed to read options from " + file_path); + break; + default: + PutModule("Failure"); + break; + } + } + } // STATUS command else if (action == "status") {