Setting parameters in any order, leaving not mentioned ones in default state.
Set policy about desktop action groups. By default they are all preserved. Note that all groups still need to be preserved if desktop file must be rewritten.
Base inilike.file.IniLikeFile.ReadOptions.
Set policy about extension groups. By default they are all preserved. Set it to skip if you're not willing to support any extensions in your applications. Note that all groups still need to be preserved if desktop file must be rewritten.
Set policy about unknown groups. By default they are skipped without errors. Note that all groups still need to be preserved if desktop file must be rewritten.
1 string contents = 2 `[Desktop Entry] 3 Key=Value 4 Actions=Action1; 5 [Desktop Action Action1] 6 Key=Value`; 7 8 alias DesktopFile.DesktopReadOptions DesktopReadOptions; 9 10 auto df = new DesktopFile(iniLikeStringReader(contents), DesktopReadOptions(ActionGroupPolicy.skip)); 11 assert(df.action("Action1") is null); 12 13 contents = 14 `[Desktop Entry] 15 Key=Value 16 Actions=Action1; 17 [X-SomeGroup] 18 Key=Value`; 19 20 df = new DesktopFile(iniLikeStringReader(contents)); 21 assert(df.group("X-SomeGroup") !is null); 22 23 df = new DesktopFile(iniLikeStringReader(contents), DesktopReadOptions(ExtensionGroupPolicy.skip)); 24 assert(df.group("X-SomeGroup") is null); 25 26 contents = 27 `[Desktop Entry] 28 Valid=Key 29 $=Invalid`; 30 31 auto thrown = collectException!IniLikeReadException(new DesktopFile(iniLikeStringReader(contents))); 32 assert(thrown !is null); 33 assert(thrown.entryException !is null); 34 assert(thrown.entryException.key == "$"); 35 assert(thrown.entryException.value == "Invalid"); 36 37 assertNotThrown(new DesktopFile(iniLikeStringReader(contents), DesktopReadOptions(IniLikeGroup.InvalidKeyPolicy.skip))); 38 39 df = new DesktopFile(iniLikeStringReader(contents), DesktopReadOptions(IniLikeGroup.InvalidKeyPolicy.save)); 40 assert(df.desktopEntry.escapedValue("$") == "Invalid"); 41 42 contents = 43 `[Desktop Entry] 44 Name=Name 45 [Unknown] 46 Key=Value`; 47 48 assertThrown(new DesktopFile(iniLikeStringReader(contents), DesktopReadOptions(UnknownGroupPolicy.throwError))); 49 50 assertNotThrown(df = new DesktopFile(iniLikeStringReader(contents), DesktopReadOptions(UnknownGroupPolicy.preserve))); 51 assert(df.group("Unknown") !is null); 52 53 df = new DesktopFile(iniLikeStringReader(contents), DesktopReadOptions(UnknownGroupPolicy.skip)); 54 assert(df.group("Unknown") is null); 55 56 contents = 57 `[Desktop Entry] 58 Name=One 59 [Desktop Entry] 60 Name=Two`; 61 62 df = new DesktopFile(iniLikeStringReader(contents), DesktopReadOptions(DuplicateGroupPolicy.preserve)); 63 assert(df.displayName() == "One"); 64 assert(df.byGroup().map!(g => g["Name"]).equal(["One", "Two"])); 65
Options to manage desktop file reading