Skip to content

Commit

Permalink
libcore|App: Compose application ID using reverse domain notation
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent bae7b01 commit ae46445
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
8 changes: 7 additions & 1 deletion doomsday/libs/core/include/de/core/app.h
Expand Up @@ -156,11 +156,17 @@ class DE_PUBLIC App : DE_OBSERVES(Clock, TimeChange)
void setUnixHomeFolderName(String const &name);

String unixHomeFolderName() const;

/**
* Returns the home folder name without the possible dot in the beginning.
*/
String unixEtcFolderName() const;

/**
* Returns the reverse domain name of the application. This is based on the
* ORG_DOMAIN metadata and the Unix home folder name.
*/
String reverseDomainIdentifier() const;

/**
* Sets a callback to be called when an uncaught exception occurs.
Expand Down
2 changes: 2 additions & 0 deletions doomsday/libs/core/include/de/data/path.h
Expand Up @@ -273,6 +273,8 @@ class DE_PUBLIC Path : public ISerializable, public LogEntry::Arg::Base
* Convert this path to a text string.
*/
String toString() const;

inline std::string toStdString() const { return toString().toStdString(); }

const char *c_str() const;

Expand Down
49 changes: 41 additions & 8 deletions doomsday/libs/core/src/core/app.cpp
Expand Up @@ -499,6 +499,17 @@ String App::unixEtcFolderName() const
return unixHome;
}

String App::reverseDomainIdentifier() const
{
const DotPath domain(metadata().gets(ORG_DOMAIN));
String rdi;
for (int i = 0; i < domain.segmentCount(); ++i)
{
rdi = rdi.concatenateMember(domain.reverseSegment(i).toString());
}
return rdi.concatenateMember(unixEtcFolderName());
}

void App::setTerminateFunc(void (*func)(char const *))
{
d->terminateFunc = func;
Expand Down Expand Up @@ -665,17 +676,38 @@ NativePath App::currentWorkPath()

NativePath App::tempPath()
{
#if defined (WIN32)
DE_ASSERT_FAIL("tempPath not implemented");
#else
return Stringf("/tmp/doomsday-%i", pid_Process(nullptr));
#endif
#if defined (WIN32)
{
DE_ASSERT_FAIL("tempPath not implemented");
}
#else
{
return Stringf("/tmp/%s-%i", app().reverseDomainIdentifier().c_str(), pid_Process(nullptr));
}
#endif
}

NativePath App::cachePath()
{
DE_ASSERT_FAIL("App::cachePath() not implemented");
return NativePath();
NativePath dir;

#if defined (MACOSX)
{
dir = NativePath::homePath() / "Library/Caches" / app().reverseDomainIdentifier();
}
#else
{
DE_ASSERT_FAIL("App::cachePath() not implemented");
return NativePath();
}
#endif

// Make sure the directory actually exists.
if (!dir.exists())
{
NativePath::createDirectory(dir);
}
return dir;
}

bool App::setCurrentWorkPath(NativePath const &cwd)
Expand Down Expand Up @@ -749,7 +781,8 @@ void App::initSubsystems(SubsystemInitFlags flags)
if (!homeFolder().has("persist.pack") || commandLine().has("-reset"))
{
ZipArchive arch;
arch.add("Info", Stringf("# Package for %s's persistent state.\n", d->metadata.gets(APP_NAME).c_str()));
arch.add("Info", Stringf("# Package for %s's persistent state.\n",
d->metadata.gets(APP_NAME).c_str()));
File &persistPack = homeFolder().replaceFile("persist.pack");
Writer(persistPack) << arch;
persistPack.reinterpret()->as<ArchiveFolder>().populate();
Expand Down

0 comments on commit ae46445

Please sign in to comment.