IconThemeCache

Class representation of icon-theme.cache file contained icon theme cache.

Constructors

this
this(string fileName)

Read icon theme cache from memory mapped file and validate it.

this
this(immutable(void)[] data, string fileName)

Read icon theme cache from data and validate it.

Members

Functions

containsIcon
bool containsIcon(const(char)[] iconName)

Test if icon is listed in cache.

containsIcon
bool containsIcon(const(char)[] iconName, const(char)[] directory)

Test if icon is listed in cache and belongs to specified subdirectory.

directories
auto directories()

Sub directories of icon theme listed in cache.

fileName
fileName()

Path of cache file.

iconDirectories
auto iconDirectories(const(char)[] iconName)

Find all sub directories the icon belongs to according to cache.

icons
auto icons()

All icon names listed in cache.

isOutdated
bool isOutdated()

Test if icon theme file is outdated, i.e. modification time of cache file is older than modification time of icon theme directory.

Static functions

isOutdated
bool isOutdated(string fileName)

Test if icon theme file is outdated, i.e. modification time of cache file is older than modification time of icon theme directory.

Examples

string cachePath = "./test/Tango/icon-theme.cache";
assert(cachePath.exists);

const(IconThemeCache) cache = new IconThemeCache(cachePath);
assert(cache.fileName == cachePath);
assert(cache.containsIcon("folder"));
assert(cache.containsIcon("folder", "24x24/places"));
assert(cache.containsIcon("edit-copy", "32x32/actions"));
assert(cache.iconDirectories("text-x-generic").canFind("32x32/mimetypes"));
assert(cache.directories().canFind("32x32/devices"));

auto icons = cache.icons();
assert(icons.canFind("folder"));
assert(icons.canFind("text-x-generic"));

try {
    SysTime pathAccessTime, pathModificationTime;
    SysTime fileAccessTime, fileModificationTime;

    getTimes(cachePath, fileAccessTime, fileModificationTime);
    getTimes(cachePath.dirName, pathAccessTime, pathModificationTime);

    setTimes(cachePath, pathAccessTime, pathModificationTime);
    assert(!IconThemeCache.isOutdated(cachePath));
}
catch(Exception e) {
    // some environmental error, just ignore
}

try {
    auto fileData = assumeUnique(std.file.read(cachePath));
    assertNotThrown(new IconThemeCache(fileData, cachePath));
} catch(FileException e) {

}

immutable(ubyte)[] data = [0,2,0,0];
IconThemeCacheException thrown = collectException!IconThemeCacheException(new IconThemeCache(data, cachePath));
assert(thrown !is null, "Invalid cache must throw");
assert(thrown.context == "major version");

data = [0,1,0,1];
thrown = collectException!IconThemeCacheException(new IconThemeCache(data, cachePath));
assert(thrown !is null, "Invalid cache must throw");
assert(thrown.context == "minor version");

Meta