Navigation Menu

Skip to content

Commit

Permalink
App: Added flag to disable App's persistent data
Browse files Browse the repository at this point in the history
If the application does not need persistent data (persist.pack in
runtime folder), it can now be disabled when the app's subsystems
are initialized.
  • Loading branch information
skyjake committed Mar 8, 2014
1 parent 5f20611 commit f19b3ef
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
8 changes: 6 additions & 2 deletions doomsday/libdeng2/include/de/core/app.h
Expand Up @@ -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.
*/
Expand Down
28 changes: 17 additions & 11 deletions doomsday/libdeng2/src/core/app.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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<PackageFolder>("persist.pack").archive();
d->persistentData = &homeFolder().locate<PackageFolder>("persist.pack").archive();
}

// The configuration.
d->config = new Config(d->configPath);
Expand Down

0 comments on commit f19b3ef

Please sign in to comment.