diff --git a/doomsday/libdeng2/include/de/core/app.h b/doomsday/libdeng2/include/de/core/app.h index db3c5db033..9a5f1cda29 100644 --- a/doomsday/libdeng2/include/de/core/app.h +++ b/doomsday/libdeng2/include/de/core/app.h @@ -61,11 +61,15 @@ class DENG2_PUBLIC App : DENG2_OBSERVES(Clock, TimeChange) { public: enum SubsystemInitFlag { - DefaultSubsystems = 0x0, - DisablePlugins = 0x1 + DefaultSubsystems = 0x0, + DisablePlugins = 0x1, + DisablePersistentData = 0x2 }; Q_DECLARE_FLAGS(SubsystemInitFlags, SubsystemInitFlag) + /// Throws if attempting to access persistent data when it has been disabled at init. + DENG2_ERROR(PersistentDataNotAvailable); + /** * Notified when application startup has been fully completed. */ diff --git a/doomsday/libdeng2/src/core/app.cpp b/doomsday/libdeng2/src/core/app.cpp index f323b09762..ef0783a7b7 100644 --- a/doomsday/libdeng2/src/core/app.cpp +++ b/doomsday/libdeng2/src/core/app.cpp @@ -438,9 +438,12 @@ NativePath App::nativeHomePath() Archive &App::persistentData() { - DENG2_ASSERT(DENG2_APP->d->persistentData != 0); - - return *DENG2_APP->d->persistentData; + Archive *persist = DENG2_APP->d->persistentData; + if(!persist) + { + throw PersistentDataNotAvailable("App::persistentData", "Persistent data is disabled"); + } + return *persist; } NativePath App::currentWorkPath() @@ -485,17 +488,20 @@ void App::initSubsystems(SubsystemInitFlags flags) d->initFileSystem(allowPlugins); - if(!homeFolder().has("persist.pack") || commandLine().has("-reset")) + if(!flags.testFlag(DisablePersistentData)) { - // Recreate the persistent state data package. - ZipArchive arch; - arch.add("Info", String(QString("# Package for %1's persistent state.\n").arg(d->appName)).toUtf8()); - Writer(homeFolder().replaceFile("persist.pack")) << arch; + if(!homeFolder().has("persist.pack") || commandLine().has("-reset")) + { + // Recreate the persistent state data package. + ZipArchive arch; + arch.add("Info", String(QString("# Package for %1's persistent state.\n").arg(d->appName)).toUtf8()); + Writer(homeFolder().replaceFile("persist.pack")) << arch; - homeFolder().populate(Folder::PopulateOnlyThisFolder); - } + homeFolder().populate(Folder::PopulateOnlyThisFolder); + } - d->persistentData = &homeFolder().locate("persist.pack").archive(); + d->persistentData = &homeFolder().locate("persist.pack").archive(); + } // The configuration. d->config = new Config(d->configPath);