Skip to content

Commit

Permalink
Separate XMLRegistry's shutdown from its saveToDisk routine
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jul 10, 2017
1 parent e983b5e commit 4e01460
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 32 deletions.
4 changes: 4 additions & 0 deletions include/iregistry.h
Expand Up @@ -59,6 +59,10 @@ class Registry :
// Dumps the whole XML content to std::out for debugging purposes
virtual void dump() const = 0;

// Exports the data which has been modified during this session
// to XML files in the user's settings path
virtual void saveToDisk() = 0;

// Saves the specified node and all its children into the file <filename>
virtual void exportToFile(const std::string& key, const std::string& filename = "-") = 0;

Expand Down
68 changes: 37 additions & 31 deletions plugins/xmlregistry/XMLRegistry.cpp
Expand Up @@ -16,9 +16,23 @@ XMLRegistry::XMLRegistry() :
_shutdown(false)
{}

void XMLRegistry::shutdown()
{
rMessage() << "XMLRegistry Shutdown: " << _queryCounter << " queries processed." << std::endl;

saveToDisk();

_shutdown = true;
}

void XMLRegistry::saveToDisk()
{
rMessage() << "XMLRegistry Shutdown: " << _queryCounter << " queries processed." << std::endl;
// Save the user tree to the settings path, this contains all
// settings that have been modified during runtime
if (!get(RKEY_SKIP_REGISTRY_SAVE).empty())
{
return;
}

// Make a deep copy of the user tree by copy-constructing it
RegistryTree copiedTree(_userTree);
Expand All @@ -30,42 +44,34 @@ void XMLRegistry::saveToDisk()
copiedTree.deleteXPath(RKEY_BITMAPS_PATH);

// Application-relative on other OS
std::string settingsPath =
module::GlobalModuleRegistry().getApplicationContext().getSettingsPath();
std::string settingsPath = module::GlobalModuleRegistry().getApplicationContext().getSettingsPath();

// Save the user tree to the settings path, this contains all
// settings that have been modified during runtime
if (get(RKEY_SKIP_REGISTRY_SAVE).empty())
{
// Replace the version tag and set it to the current DarkRadiant version
copiedTree.deleteXPath("user//version");
copiedTree.set("user/version", RADIANT_VERSION);

// Export the user-defined filter definitions to a separate file
copiedTree.exportToFile("user/ui/filtersystem/filters", settingsPath + "filters.xml");
copiedTree.deleteXPath("user/ui/filtersystem/filters");
// Replace the version tag and set it to the current DarkRadiant version
copiedTree.deleteXPath("user//version");
copiedTree.set("user/version", RADIANT_VERSION);

// Export the colour schemes and remove them from the registry
copiedTree.exportToFile("user/ui/colourschemes", settingsPath + "colours.xml");
copiedTree.deleteXPath("user/ui/colourschemes");
// Export the user-defined filter definitions to a separate file
copiedTree.exportToFile("user/ui/filtersystem/filters", settingsPath + "filters.xml");
copiedTree.deleteXPath("user/ui/filtersystem/filters");

// Export the input definitions into the user's settings folder and remove them as well
copiedTree.exportToFile("user/ui/input", settingsPath + "input.xml");
copiedTree.deleteXPath("user/ui/input");
// Export the colour schemes and remove them from the registry
copiedTree.exportToFile("user/ui/colourschemes", settingsPath + "colours.xml");
copiedTree.deleteXPath("user/ui/colourschemes");

// Delete all nodes marked as "transient", they are NOT exported into the user's xml file
copiedTree.deleteXPath("user/*[@transient='1']");
// Export the input definitions into the user's settings folder and remove them as well
copiedTree.exportToFile("user/ui/input", settingsPath + "input.xml");
copiedTree.deleteXPath("user/ui/input");

// Remove any remaining upgradePaths (from older registry files)
copiedTree.deleteXPath("user/upgradePaths");
// Remove legacy <interface> node
copiedTree.deleteXPath("user/ui/interface");
// Delete all nodes marked as "transient", they are NOT exported into the user's xml file
copiedTree.deleteXPath("user/*[@transient='1']");

// Save the remaining /darkradiant/user tree to user.xml so that the current settings are preserved
copiedTree.exportToFile("user", settingsPath + "user.xml");
}
// Remove any remaining upgradePaths (from older registry files)
copiedTree.deleteXPath("user/upgradePaths");
// Remove legacy <interface> node
copiedTree.deleteXPath("user/ui/interface");

_shutdown = true;
// Save the remaining /darkradiant/user tree to user.xml so that the current settings are preserved
copiedTree.exportToFile("user", settingsPath + "user.xml");
}

xml::NodeList XMLRegistry::findXPath(const std::string& path)
Expand Down Expand Up @@ -287,5 +293,5 @@ void XMLRegistry::initialiseModule(const ApplicationContext& ctx)

// Subscribe to the post-module-shutdown signal to save changes to disk
module::GlobalModuleRegistry().signal_allModulesUninitialised().connect(
sigc::mem_fun(this, &XMLRegistry::saveToDisk));
sigc::mem_fun(this, &XMLRegistry::shutdown));
}
5 changes: 4 additions & 1 deletion plugins/xmlregistry/XMLRegistry.h
Expand Up @@ -99,6 +99,9 @@ class XMLRegistry :
// Dumps the current registry to std::out, for debugging purposes
void dump() const override;

// Exports the user-tree to XML files in the user's settings path
void saveToDisk() override;

/* Saves a specified path from the user tree to the file <filename>.
* Use "-" as <filename> if you want to write to std::out.
*/
Expand All @@ -118,6 +121,6 @@ class XMLRegistry :
void emitSignalForKey(const std::string& changedKey);

// Invoked after all modules have been uninitialised
void saveToDisk();
void shutdown();
};
typedef std::shared_ptr<XMLRegistry> XMLRegistryPtr;

0 comments on commit 4e01460

Please sign in to comment.