Implement save/load for user options

In preparation for renaming the project and supparting multiple
notification services, there needs to be a simple method for migrating
user options to the new module name.  Using the built-in dictionary
read/write mechanism, migrating to a new module name would be as simple
as issuing `/msg *notifo save foo` and `/msg *notify load foo`.
This commit is contained in:
John Reese 2011-09-28 16:23:00 -04:00
parent e2ddfe78e9
commit 60632d42fb
2 changed files with 75 additions and 0 deletions

View File

@ -90,6 +90,15 @@ Commands
Allows you to reset a configuration option back to the default value.
* `save <filename>`
Writes your options to a file with the given path and name.
* `load <filename>`
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 [<context>]`
Check the status of current conditions. Specifying the "context" of either a channel

View File

@ -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 <filepath>");
}
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 <filename>");
}
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")
{