From a6fe5a6281f047a6cc541e61de10ec2b5f720c63 Mon Sep 17 00:00:00 2001 From: Roman Chistokhodov Date: Wed, 11 Oct 2017 18:21:03 +0300 Subject: [PATCH] Add roaming and savedGames as StandardPath enum constants --- examples/getpath/source/app.d | 6 +++ examples/printdirs/dub.selections.json | 2 +- examples/printdirs/source/app.d | 4 +- source/standardpaths.d | 52 +++++++++++++++++--------- 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/examples/getpath/source/app.d b/examples/getpath/source/app.d index 52e7181..ec8cb87 100644 --- a/examples/getpath/source/app.d +++ b/examples/getpath/source/app.d @@ -44,6 +44,12 @@ bool stringToType(string typeStr, out StandardPath type) case "startup" : type = StandardPath.startup; return true; + case "roaming": + type = StandardPath.roaming; + return true; + case "savedGames": + type = StandardPath.savedGames; + return true; default: break; } diff --git a/examples/printdirs/dub.selections.json b/examples/printdirs/dub.selections.json index 02e61bb..6c9ca2e 100644 --- a/examples/printdirs/dub.selections.json +++ b/examples/printdirs/dub.selections.json @@ -4,4 +4,4 @@ "isfreedesktop": "0.1.0", "xdgpaths": "0.2.2" } -} \ No newline at end of file +} diff --git a/examples/printdirs/source/app.d b/examples/printdirs/source/app.d index 530a5d8..bbc06a3 100644 --- a/examples/printdirs/source/app.d +++ b/examples/printdirs/source/app.d @@ -26,8 +26,8 @@ int main() version(Windows) { writeln("\nSpecific functions for Windows:"); - writeln("Roaming data: ", roamingPath()); - writeln("Saved games: ", savedGames()); + writeln("Roaming data: ", writablePath(StandardPath.roaming)); + writeln("Saved games: ", writablePath(StandardPath.savedGames)); } else version(linux) { writeln("\nSpecific functions for Linux:"); writeln("Runtime: ", xdgRuntimeDir()); diff --git a/source/standardpaths.d b/source/standardpaths.d index 6f4f2e9..ca96edb 100644 --- a/source/standardpaths.d +++ b/source/standardpaths.d @@ -162,7 +162,15 @@ enum StandardPath { * On OSX it's not available. * On Freedesktop it's directory where autostarted .desktop files are stored. */ - startup + startup, + /** + * Roaming directory that stores a user data which should be shared between user profiles on different machines. Windows-only. + */ + roaming, + /** + * Common directory for game save files. Windows-only. + */ + savedGames } /** @@ -320,7 +328,7 @@ version(D_Ddoc) * Returns: User's Roaming directory. On fail returns an empty string. * See_Also: $(D writablePath), $(D FolderFlag) */ - string roamingPath(FolderFlag params = FolderFlag.none) nothrow @safe; + deprecated string roamingPath(FolderFlag params = FolderFlag.none) nothrow @safe; /** * Location where games may store their saves. Windows only. @@ -328,7 +336,7 @@ version(D_Ddoc) * Returns: User's Saved Games directory. On fail returns an empty string. * See_Also: $(D writablePath), $(D FolderFlag) */ - string savedGames(FolderFlag params = FolderFlag.none) nothrow @safe; + deprecated string savedGames(FolderFlag params = FolderFlag.none) nothrow @safe; } version(Windows) { @@ -525,24 +533,14 @@ version(Windows) { return null; } - string roamingPath(FolderFlag params = FolderFlag.none) nothrow @safe + deprecated("use writablePath(StandardPath.roaming)") string roamingPath(FolderFlag params = FolderFlag.none) nothrow @safe { - if (hasSHGetKnownFolderPath()) { - return getKnownFolder(FOLDERID_RoamingAppData, params); - } else if (hasSHGetSpecialFolderPath()) { - return getCSIDLFolder(CSIDL_APPDATA, params); - } else { - return null; - } + return writablePath(StandardPath.roaming, params); } - string savedGames(FolderFlag params = FolderFlag.none) nothrow @safe + deprecated("use writablePath(StandardPath.savedGames)") string savedGames(FolderFlag params = FolderFlag.none) nothrow @safe { - if (hasSHGetKnownFolderPath()) { - return getKnownFolder(FOLDERID_SavedGames, params); - } else { - return null; - } + return writablePath(StandardPath.savedGames, params); } string writablePath(StandardPath type, FolderFlag params = FolderFlag.none) nothrow @safe @@ -576,6 +574,10 @@ version(Windows) { return getKnownFolder(FOLDERID_Programs, params); case StandardPath.startup: return getKnownFolder(FOLDERID_Startup, params); + case StandardPath.roaming: + return getKnownFolder(FOLDERID_RoamingAppData, params); + case StandardPath.savedGames: + return getKnownFolder(FOLDERID_SavedGames, params); } } else if (hasSHGetSpecialFolderPath()) { final switch(type) { @@ -606,6 +608,10 @@ version(Windows) { return getCSIDLFolder(CSIDL_PROGRAMS, params); case StandardPath.startup: return getCSIDLFolder(CSIDL_STARTUP, params); + case StandardPath.roaming: + return getCSIDLFolder(CSIDL_APPDATA, params); + case StandardPath.savedGames: + return null; } } else { return null; @@ -993,6 +999,10 @@ version(Windows) { return domainDir(NSApplicationDirectory, NSUserDomainMask, shouldCreate); case StandardPath.startup: return null; + case StandardPath.roaming: + return null; + case StandardPath.savedGames: + return null; } } else { final switch(type) { @@ -1024,6 +1034,10 @@ version(Windows) { return fsPath(kUserDomain, kApplicationsFolderType, shouldCreate); case StandardPath.startup: return null; + case StandardPath.roaming: + return null; + case StandardPath.savedGames: + return null; } } } @@ -1253,6 +1267,10 @@ PICTURES=Images return xdgDataHome("applications", shouldCreate); case StandardPath.startup: return xdgConfigHome("autostart", shouldCreate); + case StandardPath.roaming: + return null; + case StandardPath.savedGames: + return null; } }