Ticket #1145: windows_osx_path+bundle_fixes-03062012.patch
File windows_osx_path+bundle_fixes-03062012.patch, 25.7 KB (added by , 12 years ago) |
---|
-
source/lib/sysdep/os/osx/osx_bundle.h
1 /* Copyright (c) 2012 Wildfire Games 2 * 3 * Permission is hereby granted, free of charge, to any person obtaining 4 * a copy of this software and associated documentation files (the 5 * "Software"), to deal in the Software without restriction, including 6 * without limitation the rights to use, copy, modify, merge, publish, 7 * distribute, sublicense, and/or sell copies of the Software, and to 8 * permit persons to whom the Software is furnished to do so, subject to 9 * the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included 12 * in all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 */ 22 23 #ifndef OSX_BUNDLE_H 24 #define OSX_BUNDLE_H 25 26 /** 27 * @file 28 * C++ interface to Cocoa implementation for getting bundle information 29 */ 30 31 /** 32 * Check if app is running in a valid bundle 33 * 34 * @return true if valid bundle reference was found matching identifier 35 * property "com.wildfiregames.0ad" 36 */ 37 bool osx_IsAppBundleValid(); 38 39 /** 40 * Get the system path to the bundle's Resources directory 41 * 42 * @return string containing POSIX-style path in UTF-8 encoding, 43 * else empty string if an error occurred. 44 */ 45 std::string osx_GetBundleResourcesPath(); 46 47 /** 48 * Get the system path to the bundle's Frameworks directory 49 * 50 * @return string containing POSIX-style path in UTF-8 encoding, 51 * else empty string if an error occurred. 52 */ 53 std::string osx_GetBundleFrameworksPath(); 54 55 #endif // OSX_BUNDLE_H -
source/lib/sysdep/os/osx/osx_bundle.h
-
source/lib/sysdep/os/osx/osx_bundle.mm
Property changes on: source/lib/sysdep/os/osx/osx_bundle.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native
1 /* Copyright (c) 2012 Wildfire Games 2 * 3 * Permission is hereby granted, free of charge, to any person obtaining 4 * a copy of this software and associated documentation files (the 5 * "Software"), to deal in the Software without restriction, including 6 * without limitation the rights to use, copy, modify, merge, publish, 7 * distribute, sublicense, and/or sell copies of the Software, and to 8 * permit persons to whom the Software is furnished to do so, subject to 9 * the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included 12 * in all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 */ 22 23 #import <Foundation/Foundation.h> 24 #import <string> 25 26 #import "osx_bundle.h" 27 28 #define STRINGIZE2(id) # id 29 #define STRINGIZE(id) STRINGIZE2(id) 30 31 // Pass the bundle identifier string as a build option 32 #ifdef BUNDLE_IDENTIFIER 33 static const char* BUNDLE_ID_STR = STRINGIZE(BUNDLE_IDENTIFIER); 34 #else 35 static const char* BUNDLE_ID_STR = ""; 36 #endif 37 38 39 bool osx_IsAppBundleValid() 40 { 41 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 42 43 // Check for the existence of bundle with correct identifier property 44 // (can't just use mainBundle because that can return a bundle reference 45 // even for a loose binary!) 46 NSBundle *bundle = [NSBundle bundleWithIdentifier: [NSString stringWithUTF8String: BUNDLE_ID_STR]]; 47 48 [pool release]; 49 return bundle != nil; 50 } 51 52 std::string osx_GetBundleResourcesPath() 53 { 54 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 55 std::string path; 56 57 NSBundle *bundle = [NSBundle bundleWithIdentifier: [NSString stringWithUTF8String: BUNDLE_ID_STR]]; 58 if (bundle != nil) 59 { 60 // Retrieve NSURL and convert to POSIX path, then get C-string 61 // encoded as UTF-8, and use it to construct std::string 62 // NSURL:path "If the receiver does not conform to RFC 1808, returns nil." 63 NSString *pathStr = [[bundle resourceURL] path]; 64 if (pathStr != nil) 65 { 66 path = std::string([pathStr UTF8String]); 67 } 68 } 69 70 [pool release]; 71 return path; 72 } 73 74 std::string osx_GetBundleFrameworksPath() 75 { 76 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 77 std::string path; 78 79 NSBundle *bundle = [NSBundle bundleWithIdentifier: [NSString stringWithUTF8String: BUNDLE_ID_STR]]; 80 if (bundle != nil) 81 { 82 // Retrieve NSURL and convert to POSIX path, then get C-string 83 // encoded as UTF-8, and use it to construct std::string 84 // NSURL:path "If the receiver does not conform to RFC 1808, returns nil." 85 NSString *pathStr = [[bundle privateFrameworksURL] path]; 86 if (pathStr != nil) 87 { 88 path = std::string([pathStr UTF8String]); 89 } 90 } 91 92 [pool release]; 93 return path; 94 } -
source/lib/sysdep/os/osx/osx_bundle.mm
-
source/lib/sysdep/os/osx/osx_paths.h
Property changes on: source/lib/sysdep/os/osx/osx_bundle.mm ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native
1 /* Copyright (c) 2012 Wildfire Games 2 * 3 * Permission is hereby granted, free of charge, to any person obtaining 4 * a copy of this software and associated documentation files (the 5 * "Software"), to deal in the Software without restriction, including 6 * without limitation the rights to use, copy, modify, merge, publish, 7 * distribute, sublicense, and/or sell copies of the Software, and to 8 * permit persons to whom the Software is furnished to do so, subject to 9 * the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included 12 * in all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 */ 22 23 #ifndef OSX_PATHS_H 24 #define OSX_PATHS_H 25 26 /** 27 * @file 28 * C++ interface to Cocoa implementation for retrieving standard OS X paths 29 */ 30 31 /** 32 * Get the user's Application Support path (typically ~/Library/Application Support) 33 * 34 * @return string containing POSIX-style path in UTF-8 encoding, 35 * else empty string if an error occurred. 36 */ 37 std::string osx_GetAppSupportPath(); 38 39 /** 40 * Get the user's Caches path (typically ~/Library/Caches) 41 * 42 * @return string containing POSIX-style path in UTF-8 encoding, 43 * else empty string if an error occurred. 44 */ 45 std::string osx_GetCachesPath(); 46 47 /** 48 * Get the user's Library path (typically ~/Library) 49 * 50 * @return string containing POSIX-style path in UTF-8 encoding, 51 * else empty string if an error occurred. 52 */ 53 std::string osx_GetLibraryPath(); 54 55 /** 56 * Get the user's Pictures path (typically ~/Pictures) 57 * 58 * @return string containing POSIX-style path in UTF-8 encoding, 59 * else empty string if an error occurred. 60 */ 61 std::string osx_GetPicturesPath(); 62 63 #endif // OSX_PATHS_H -
source/lib/sysdep/os/osx/osx_paths.h
-
source/lib/sysdep/os/osx/osx_paths.mm
Property changes on: source/lib/sysdep/os/osx/osx_paths.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native
1 /* Copyright (c) 2012 Wildfire Games 2 * 3 * Permission is hereby granted, free of charge, to any person obtaining 4 * a copy of this software and associated documentation files (the 5 * "Software"), to deal in the Software without restriction, including 6 * without limitation the rights to use, copy, modify, merge, publish, 7 * distribute, sublicense, and/or sell copies of the Software, and to 8 * permit persons to whom the Software is furnished to do so, subject to 9 * the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included 12 * in all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 */ 22 23 #import <Foundation/Foundation.h> 24 #import <string> 25 26 #import "osx_paths.h" 27 28 // Helper function 29 static std::string getUserDirectoryPath(NSSearchPathDirectory directory) 30 { 31 std::string result; 32 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; 33 34 // Returns array of NSURL objects which are preferred for file paths 35 NSArray* paths = [[NSFileManager defaultManager] URLsForDirectory:directory inDomains:NSUserDomainMask]; 36 if ([paths count] > 0) 37 { 38 // Retrieve first NSURL and convert to POSIX path, then get C-string 39 // encoded as UTF-8, and use it to construct std::string 40 // NSURL:path "If the receiver does not conform to RFC 1808, returns nil." 41 NSString* pathStr = [[paths objectAtIndex:0] path]; 42 if (pathStr != nil) 43 result = std::string([pathStr UTF8String]); 44 } 45 46 [pool release]; 47 return result; 48 } 49 50 std::string osx_GetAppSupportPath() 51 { 52 return getUserDirectoryPath(NSApplicationSupportDirectory); 53 } 54 55 std::string osx_GetCachesPath() 56 { 57 return getUserDirectoryPath(NSCachesDirectory); 58 } 59 60 std::string osx_GetLibraryPath() 61 { 62 return getUserDirectoryPath(NSLibraryDirectory); 63 } 64 65 std::string osx_GetPicturesPath() 66 { 67 return getUserDirectoryPath(NSPicturesDirectory); 68 } -
source/lib/sysdep/os/osx/osx_paths.mm
-
source/lib/sysdep/os/win/wutil.cpp
Property changes on: source/lib/sysdep/os/osx/osx_paths.mm ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native
1 /* Copyright (c) 201 0Wildfire Games1 /* Copyright (c) 2012 Wildfire Games 2 2 * 3 3 * Permission is hereby granted, free of charge, to any person obtaining 4 4 * a copy of this software and associated documentation files (the … … 251 251 // (NB: wutil_Init is called before static ctors => use placement new) 252 252 static OsPath* systemPath; 253 253 static OsPath* executablePath; 254 static OsPath* appdataPath; 254 static OsPath* localAppdataPath; 255 static OsPath* roamingAppdataPath; 256 static OsPath* personalPath; 255 257 256 258 const OsPath& wutil_SystemPath() 257 259 { … … 263 265 return *executablePath; 264 266 } 265 267 266 const OsPath& wutil_ AppdataPath()268 const OsPath& wutil_LocalAppdataPath() 267 269 { 268 return * appdataPath;270 return *localAppdataPath; 269 271 } 270 272 273 const OsPath& wutil_RoamingAppdataPath() 274 { 275 return *roamingAppdataPath; 276 } 271 277 278 const OsPath& wutil_PersonalPath() 279 { 280 return *personalPath; 281 } 282 283 272 284 static void GetDirectories() 273 285 { 274 286 WinScopedPreserveLastError s; … … 286 298 // executable's directory 287 299 executablePath = new(wutil_Allocate(sizeof(OsPath))) OsPath(sys_ExecutablePathname().Parent()); 288 300 289 // application data301 // roaming application data 290 302 { 291 303 HWND hwnd = 0; // ignored unless a dial-up connection is needed to access the folder 292 304 HANDLE token = 0; … … 295 307 ENSURE(SUCCEEDED(ret)); 296 308 if(GetLastError() == ERROR_NO_TOKEN) // avoid polluting last error 297 309 SetLastError(0); 298 appdataPath = new(wutil_Allocate(sizeof(OsPath))) OsPath(path);310 roamingAppdataPath = new(wutil_Allocate(sizeof(OsPath))) OsPath(path); 299 311 } 312 313 // local application data 314 { 315 HWND hwnd = 0; // ignored unless a dial-up connection is needed to access the folder 316 HANDLE token = 0; 317 wchar_t path[MAX_PATH]; // mandated by SHGetFolderPathW 318 const HRESULT ret = SHGetFolderPathW(hwnd, CSIDL_LOCAL_APPDATA, token, 0, path); 319 ENSURE(SUCCEEDED(ret)); 320 if(GetLastError() == ERROR_NO_TOKEN) // avoid polluting last error 321 SetLastError(0); 322 localAppdataPath = new(wutil_Allocate(sizeof(OsPath))) OsPath(path); 323 } 324 325 // my documents 326 { 327 HWND hwnd = 0; // ignored unless a dial-up connection is needed to access the folder 328 HANDLE token = 0; 329 wchar_t path[MAX_PATH]; // mandated by SHGetFolderPathW 330 const HRESULT ret = SHGetFolderPathW(hwnd, CSIDL_PERSONAL, token, 0, path); 331 ENSURE(SUCCEEDED(ret)); 332 if(GetLastError() == ERROR_NO_TOKEN) // avoid polluting last error 333 SetLastError(0); 334 personalPath = new(wutil_Allocate(sizeof(OsPath))) OsPath(path); 335 } 300 336 } 301 337 302 338 … … 306 342 wutil_Free(systemPath); 307 343 executablePath->~OsPath(); 308 344 wutil_Free(executablePath); 309 appdataPath->~OsPath(); 310 wutil_Free(appdataPath); 345 localAppdataPath->~OsPath(); 346 wutil_Free(localAppdataPath); 347 roamingAppdataPath->~OsPath(); 348 wutil_Free(roamingAppdataPath); 349 personalPath->~OsPath(); 350 wutil_Free(personalPath); 311 351 } 312 352 313 353 -
source/lib/sysdep/os/win/wutil.h
1 /* Copyright (c) 201 0Wildfire Games1 /* Copyright (c) 2012 Wildfire Games 2 2 * 3 3 * Permission is hereby granted, free of charge, to any person obtaining 4 4 * a copy of this software and associated documentation files (the … … 159 159 160 160 extern const OsPath& wutil_SystemPath(); 161 161 extern const OsPath& wutil_ExecutablePath(); 162 extern const OsPath& wutil_AppdataPath(); 162 extern const OsPath& wutil_LocalAppdataPath(); 163 extern const OsPath& wutil_RoamingAppdataPath(); 164 extern const OsPath& wutil_PersonalPath(); 163 165 164 166 165 167 //----------------------------------------------------------------------------- -
source/ps/DllLoader.cpp
1 /* Copyright (C) 201 1Wildfire Games.1 /* Copyright (C) 2012 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 25 25 #include "ps/CLogger.h" 26 26 #include "ps/GameSetup/Config.h" 27 27 28 #if OS_MACOSX 29 # include "lib/sysdep/os/osx/osx_bundle.h" 30 #endif 31 28 32 static void* const HANDLE_UNAVAILABLE = (void*)-1; 29 33 30 34 // directory to search for libraries (optionally set by --libdir at build-time, … … 70 74 static CStr GenerateFilename(const CStr& name, const CStr& suffix, const CStr& extension) 71 75 { 72 76 CStr n; 77 73 78 if (!g_Libdir.empty()) 74 79 n = g_Libdir + "/"; 80 81 #if OS_MACOSX 82 // On OS X, we might be in a bundle in which case the lib directory is ../Frameworks 83 // relative to the binary, so we use a helper function to get the system path 84 if (osx_IsAppBundleValid()) 85 { 86 CStr frameworksPath = osx_GetBundleFrameworksPath(); 87 if (!frameworksPath.empty()) 88 { 89 n = frameworksPath + "/"; 90 } 91 } 92 #endif 93 75 94 n += prefix + name + suffix + extension; 76 95 return n; 77 96 } -
source/ps/GameSetup/GameSetup.cpp
453 453 const size_t cacheSize = ChooseCacheSize(); 454 454 g_VFS = CreateVfs(cacheSize); 455 455 456 g_VFS->Mount(L"screenshots/", paths. Data()/"screenshots"/"");457 g_VFS->Mount(L"saves/", paths. Data()/"saves"/"");456 g_VFS->Mount(L"screenshots/", paths.UserData()/"screenshots"/""); 457 g_VFS->Mount(L"saves/", paths.UserData()/"saves"/""); 458 458 const OsPath readonlyConfig = paths.RData()/"config"/""; 459 459 g_VFS->Mount(L"config/", readonlyConfig); 460 460 if(readonlyConfig != paths.Config()) -
source/ps/GameSetup/Paths.cpp
1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 2012 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 22 22 #include "lib/sysdep/sysdep.h" // sys_get_executable_name 23 23 #include "lib/sysdep/filesystem.h" // wrealpath 24 24 #if OS_WIN 25 # include "lib/sysdep/os/win/wutil.h" // wutil_AppdataPath 25 # include "lib/sysdep/os/win/wutil.h" // wutil_*Path 26 #elif OS_MACOSX 27 # include "lib/sysdep/os/osx/osx_paths.h" 28 # include "lib/sysdep/os/osx/osx_bundle.h" 26 29 #endif 27 30 #include "ps/CLogger.h" 28 31 … … 34 37 #ifdef INSTALLED_DATADIR 35 38 m_rdata = OsPath(STRINGIZE(INSTALLED_DATADIR))/""; 36 39 #else 37 m_rdata = m_root/"data"/""; 38 #endif 40 # if OS_MACOSX 41 if (osx_IsAppBundleValid()) 42 { 43 debug_printf(L"Valid app bundle detected!\n"); 39 44 45 std::string resourcesPath = osx_GetBundleResourcesPath(); 46 if (!resourcesPath.empty()) 47 { 48 m_rdata = OsPath(resourcesPath)/"data"/""; 49 } 50 } 51 else 52 # endif // OS_MACOSX 53 54 m_rdata = m_root/"data"/""; 55 56 #endif // INSTALLED_DATADIR 57 40 58 const char* subdirectoryName = args.Has("writableRoot")? 0 : "0ad"; 41 59 42 // everything is a subdirectory of the root43 60 if(!subdirectoryName) 44 61 { 45 m_data = m_rdata; 46 m_config = m_data/"config"/""; 47 m_cache = m_data/"cache"/""; 48 m_logs = m_root/"logs"/""; 62 // Note: if writableRoot option is passed to the game, then 63 // all the data is a subdirectory of the root 64 m_gameData = m_rdata; 65 m_userData = m_gameData; 66 m_config = m_gameData / "config"/""; 67 m_cache = m_gameData / "cache"/""; 68 m_logs = m_root / "logs"/""; 49 69 } 50 else 70 else // OS-specific path handling 51 71 { 72 52 73 #if OS_ANDROID 74 53 75 const OsPath appdata = OsPath("/sdcard/0ad/appdata"); 54 m_data = appdata/"data"/""; 76 77 // We don't make the game vs. user data distinction on Android 78 m_gameData = appdata/"data"/""; 79 m_userData = m_gameData; 55 80 m_config = appdata/"config"/""; 56 81 m_cache = appdata/"cache"/""; 57 82 m_logs = appdata/"logs"/""; 83 58 84 #elif OS_WIN 59 const OsPath appdata = wutil_AppdataPath() / subdirectoryName/""; 60 m_data = appdata/"data"/""; 61 m_config = appdata/"config"/""; 62 m_cache = appdata/"cache"/""; 63 m_logs = appdata/"logs"/""; 64 #else 85 86 /* For reasoning behind our Windows paths, see the discussion here: 87 * http://www.wildfiregames.com/forum/index.php?showtopic=14759 88 * 89 * Summary: 90 * 1. Local appdata: for bulky unfriendly data like the cache, 91 * which can be recreated if deleted; doesn't need backing up. 92 * 2. Roaming appdata: for slightly less unfriendly data like config 93 * files that might theoretically be shared between different 94 * machines on a domain. 95 * 3. Personal / My Documents: for data explicitly created by the user, 96 * and which should be visible and easily accessed. We use a non- 97 * localized My Games subfolder for improved organization. 98 */ 99 100 // %localappdata%/0ad/ 101 const OsPath localAppdata = wutil_LocalAppdataPath() / subdirectoryName/""; 102 // %appdata%/0ad/ 103 const OsPath roamingAppData = wutil_RoamingAppdataPath() / subdirectoryName/""; 104 // My Documents/My Games/0ad/ 105 const OsPath personalData = wutil_PersonalPath() / "My Games" / subdirectoryName/""; 106 107 m_cache = localAppdata / "cache"/""; 108 m_gameData = roamingAppData / "data"/""; 109 m_userData = personalData/""; 110 m_config = roamingAppData / "config"/""; 111 m_logs = localAppdata / "logs"/""; 112 113 #elif OS_MACOSX 114 115 /* For reasoning behind our OS X paths, see the discussion here: 116 * http://www.wildfiregames.com/forum/index.php?showtopic=15511 117 * 118 * Summary: 119 * 1. Application Support: most data associated with the app 120 * should be stored here, with few exceptions (e.g. temporary 121 * data, cached data, and managed media files). 122 * 2. Caches: used for non-critial app data that can be easily 123 * regenerated if this directory is deleted. It is not 124 * included in backups by default. 125 * 126 * Note: the paths returned by osx_Get*Path are not guaranteed to exist, 127 * but that's OK since we always create them on demand. 128 */ 129 130 // We probably want to use the same subdirectoryName regardless 131 // of whether running a bundle or from SVN. Apple recommends using 132 // company name, bundle name or bundle identifier. 133 OsPath appSupportPath; // ~/Library/Application Support/0ad 134 OsPath cachePath; // ~/Library/Caches/0ad 135 136 { 137 std::string path = osx_GetAppSupportPath(); 138 ENSURE(!path.empty()); 139 appSupportPath = OsPath(path) / subdirectoryName; 140 } 141 { 142 std::string path = osx_GetCachesPath(); 143 ENSURE(!path.empty()); 144 cachePath = OsPath(path) / subdirectoryName; 145 } 146 147 // We don't make the game vs. user data distinction on OS X 148 m_gameData = appSupportPath / "data"/""; 149 m_userData = m_gameData; 150 m_cache = cachePath/""; 151 m_config = appSupportPath / "config"/""; 152 m_logs = appSupportPath / "logs"/""; 153 154 #else // OS_UNIX 155 65 156 const char* envHome = getenv("HOME"); 66 157 ENSURE(envHome); 67 158 const OsPath home(envHome); 68 159 const OsPath xdgData = XDG_Path("XDG_DATA_HOME", home, home/".local/share/") / subdirectoryName; 69 160 const OsPath xdgConfig = XDG_Path("XDG_CONFIG_HOME", home, home/".config/" ) / subdirectoryName; 70 161 const OsPath xdgCache = XDG_Path("XDG_CACHE_HOME", home, home/".cache/" ) / subdirectoryName; 71 m_data = xdgData/""; 162 163 // We don't make the game vs. user data distinction on Unix 164 m_gameData = xdgData/""; 165 m_userData = m_gameData; 72 166 m_cache = xdgCache/""; 73 m_config = xdgConfig/"config"/""; 74 m_logs = xdgConfig/"logs"/""; 167 m_config = xdgConfig / "config"/""; 168 m_logs = xdgConfig / "logs"/""; 169 75 170 #endif 76 171 } 77 172 } -
source/ps/GameSetup/Paths.h
1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 2012 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 21 21 #include "lib/os_path.h" 22 22 #include "CmdLineArgs.h" 23 23 24 /** 25 * Wrapper class for OS paths used by the game 26 */ 24 27 class Paths 25 28 { 26 29 public: 27 30 Paths(const CmdLineArgs& args); 28 31 32 /** 33 * Returns the game's root directory 34 */ 29 35 const OsPath& Root() const 30 36 { 31 37 return m_root; 32 38 } 33 39 40 /** 41 * Returns directory for read-only data installed with the game 42 */ 34 43 const OsPath& RData() const 35 44 { 36 45 return m_rdata; 37 46 } 38 47 39 const OsPath& Data() const 48 /** 49 * Returns directory for game-managed data and mods 50 */ 51 const OsPath& GameData() const 40 52 { 41 return m_ data;53 return m_gameData; 42 54 } 43 55 56 /** 57 * Returns directory for user-created data 58 * Only things created in reponse to an explicit user action should go here. 59 * (note: only Windows currently treats this differently than GameData) 60 */ 61 const OsPath& UserData() const 62 { 63 return m_userData; 64 } 65 66 /** 67 * Returns config file directory 68 */ 44 69 const OsPath& Config() const 45 70 { 46 71 return m_config; 47 72 } 48 73 74 /** 75 * Returns cache directory 76 */ 49 77 const OsPath& Cache() const 50 78 { 51 79 return m_cache; 52 80 } 53 81 82 /** 83 * Returns logs directory 84 */ 54 85 const OsPath& Logs() const 55 86 { 56 87 return m_logs; … … 65 96 OsPath m_rdata; 66 97 67 98 // writable directories 68 OsPath m_data; 99 OsPath m_gameData; 100 OsPath m_userData; 69 101 OsPath m_config; 70 102 OsPath m_cache; 71 103 OsPath m_logs; // special-cased in single-root-folder installations