Class MimeInfoCacheFile

Class represenation of single mimeinfo.cache file containing information about MIME type associations.

class MimeInfoCacheFile
  : IniLikeFile ;

Constructors

NameDescription
this Read MIME Cache from file.
this Constructs MimeInfoCacheFile with empty MIME Cache group.
this Read MIME Cache from IniLikeReader, e.g. acquired from iniLikeFileReader or iniLikeStringReader.

Methods

NameDescription
mimeCache Access "MIME Cache" group.
addGenericGroup Create new group using groupName.
appendLeadingComment Add leading comment. This will be appended to the list of leadingComments.
byGroup Range of groups in order how they were defined in file.
byNode Iterate over GroupNodes.
clearLeadingComments Remove all coments met before groups.
escapedValue Shortcut to IniLikeGroup.escapedValue of given group. Returns null if the group does not exist.
escapedValue ditto, localized version
fileName File path where the object was loaded from.
getNode Get GroupNode by groupName.
group Get group by name.
leadingComments Leading comments.
moveGroupAfter Move group after other.
moveGroupBefore Move group before other.
moveGroupToBack Move the group to make it the last.
moveGroupToFront Move the group to make it the first.
prependLeadingComment Prepend leading comment (e.g. for setting shebang line).
removeGroup Remove group by name. Do nothing if group with such name does not exist.
save Use Output range or delegate to retrieve strings line by line. Those strings can be written to the file or be showed in text area.
saveToFile Save object to the file using .ini-like format.
saveToString Save object to string using .ini like format.
unescapedValue Shortcut to IniLikeGroup.unescapedValue of given group. Returns null if the group does not exist.
createEmptyGroup Can be used in derived classes to create instance of IniLikeGroup.
createGroupByName Reimplement in derive class.
insertGroup Insert group into IniLikeFile object and use its name as key.
onCommentInGroup Add comment for group. This function is called only in constructor and can be reimplemented in derived classes.
onGroup Create IniLikeGroup by groupName during file parsing.
onKeyValue Add key/value pair for group. This function is called only in constructor and can be reimplemented in derived classes.
onLeadingComment Add comment before groups. This function is called only in constructor and can be reimplemented in derived classes.
putGroup Append group to group list without associating group name with it. Can be used to add groups with duplicated names.

Inner structs

NameDescription
GroupNode Wrapper for internal ListMap node.
ReadOptions Behavior of ini-like file reading.
WriteOptions Behavior of ini-like file saving.

Enums

NameDescription
DuplicateGroupPolicy Behavior on group with duplicate name in the file.
DuplicateKeyPolicy Behavior on duplicate key in the group.

Note

Unlike MimeAppsListFile this class does not provide functions for associations update. This is because mimeinfo.cache files should be updated by update-desktop-database utility from desktop-file-utils.

Example

string content =
`[Some group]
Key=Value
`;
assertThrown!IniLikeReadException(new MimeInfoCacheFile(iniLikeStringReader(content)));

content =
`[MIME Cache]
text/plain=geany.desktop;kde4-kwrite.desktop;
image/png=kde4-gwenview.desktop;gthumb.desktop;
`;

auto mimeInfoCache = new MimeInfoCacheFile(iniLikeStringReader(content));
assert(mimeInfoCache.appsForMimeType("text/plain").equal(["geany.desktop", "kde4-kwrite.desktop"]));
assert(mimeInfoCache.appsForMimeType("image/png").equal(["kde4-gwenview.desktop", "gthumb.desktop"]));
assert(mimeInfoCache.appsForMimeType("application/nonexistent").empty);

content =
`[MIME Cache]
text/plain=geany.desktop;
notmimetype=value
`;
assertThrown!IniLikeReadException(new MimeInfoCacheFile(iniLikeStringReader(content)));
assertNotThrown(mimeInfoCache = new MimeInfoCacheFile(iniLikeStringReader(content), null, IniLikeFile.ReadOptions(IniLikeGroup.InvalidKeyPolicy.save)));
assert(mimeInfoCache.mimeCache.escapedValue("notmimetype") == "value");