Skip to content

Commit

Permalink
Add roaming and savedGames as StandardPath enum constants
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeSlave committed Oct 11, 2017
1 parent 2b35760 commit a6fe5a6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
6 changes: 6 additions & 0 deletions examples/getpath/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/printdirs/dub.selections.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"isfreedesktop": "0.1.0",
"xdgpaths": "0.2.2"
}
}
}
4 changes: 2 additions & 2 deletions examples/printdirs/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
52 changes: 35 additions & 17 deletions source/standardpaths.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down Expand Up @@ -320,15 +328,15 @@ 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.
* Note: This is common path for games. One should use subfolder for their game saves.
* 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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit a6fe5a6

Please sign in to comment.