Ticket #1145: windows_osx_path_fixes-02042012.patch
File windows_osx_path_fixes-02042012.patch, 17.2 KB (added by , 12 years ago) |
---|
-
source/lib/sysdep/os/osx/osxpaths.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 24 #ifndef INCLUDE_OSXPATHS_H 25 #define INCLUDE_OSXPATHS_H 26 27 #include <CoreFoundation/CoreFoundation.h> 28 #include <CoreFoundation/CFString.h> 29 30 CFStringRef osx_AppSupportPath(); 31 32 CFStringRef osx_CachesPath(); 33 34 CFStringRef osx_DocumentsPath(); 35 36 #endif // INCLUDE_OSXPATHS_H -
source/lib/sysdep/os/osx/osxpaths.h
-
source/lib/sysdep/os/osx/osxpaths.mm
Property changes on: source/lib/sysdep/os/osx/osxpaths.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 25 #import "osxpaths.h" 26 27 28 // Find ~/Library/Application Support/ directory 29 CFStringRef osx_AppSupportPath() 30 { 31 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 32 33 NSArray* paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES); 34 35 if ([paths count] == 0) 36 { 37 return NULL; 38 } 39 40 CFStringRef path = (CFStringRef)CFArrayGetValueAtIndex((CFArrayRef)paths, 0); 41 42 // Caller will be responsible for freeing the string with CFRelease 43 CFRetain(path); 44 45 [pool release]; 46 47 return path; 48 } 49 50 // Find ~/Library/Caches/ directory 51 CFStringRef osx_CachesPath() 52 { 53 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 54 55 NSArray* paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); 56 57 if ([paths count] == 0) 58 { 59 return NULL; 60 } 61 62 CFStringRef path = (CFStringRef)CFArrayGetValueAtIndex((CFArrayRef)paths, 0); 63 64 // Caller will be responsible for freeing the string with CFRelease 65 CFRetain(path); 66 67 [pool release]; 68 69 return path; 70 } 71 72 // Find ~/Documents/ directory 73 CFStringRef osx_DocumentsPath() 74 { 75 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 76 77 NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 78 79 if ([paths count] == 0) 80 { 81 return NULL; 82 } 83 84 CFStringRef path = (CFStringRef)CFArrayGetValueAtIndex((CFArrayRef)paths, 0); 85 86 // Caller will be responsible for freeing the string with CFRelease 87 CFRetain(path); 88 89 [pool release]; 90 91 return path; 92 } -
source/lib/sysdep/os/win/wutil.cpp
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/GameSetup/GameSetup.cpp
441 441 const size_t cacheSize = ChooseCacheSize(); 442 442 g_VFS = CreateVfs(cacheSize); 443 443 444 g_VFS->Mount(L"screenshots/", paths. Data()/"screenshots"/"");445 g_VFS->Mount(L"saves/", paths. Data()/"saves"/"");444 g_VFS->Mount(L"screenshots/", paths.UserData()/"screenshots"/""); 445 g_VFS->Mount(L"saves/", paths.UserData()/"saves"/""); 446 446 const OsPath readonlyConfig = paths.RData()/"config"/""; 447 447 g_VFS->Mount(L"config/", readonlyConfig); 448 448 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/osxpaths.h" // osx_*Path 26 28 #endif 27 29 28 30 … … 38 40 39 41 const char* subdirectoryName = args.Has("writableRoot")? 0 : "0ad"; 40 42 41 // everything is a subdirectory of the root 43 // Note: Only if writableRoot option is passed to the game, then 44 // all the data is a subdirectory of the root 42 45 if(!subdirectoryName) 43 46 { 44 m_data = m_rdata; 45 m_config = m_data/"config"/""; 46 m_cache = m_data/"cache"/""; 47 m_logs = m_root/"logs"/""; 47 m_gameData = m_rdata; 48 m_userData = m_gameData; 49 m_config = m_gameData / "config"/""; 50 m_cache = m_gameData / "cache"/""; 51 m_logs = m_root / "logs"/""; 48 52 } 49 else 53 else // OS-specific path handling 50 54 { 55 51 56 #if OS_WIN 52 const OsPath appdata = wutil_AppdataPath() / subdirectoryName/""; 53 m_data = appdata/"data"/""; 54 m_config = appdata/"config"/""; 55 m_cache = appdata/"cache"/""; 56 m_logs = appdata/"logs"/""; 57 #else 57 58 /* For reasoning behind our Windows paths, see the discussion here: 59 * http://www.wildfiregames.com/forum/index.php?showtopic=14759 60 * 61 * Summary: 62 * 1. Local appdata: for bulky unfriendly data like the cache, 63 * which can be recreated if deleted; doesn't need backing up. 64 * 2. Roaming appdata: for slightly less unfriendly data like config 65 * files that might theoretically be shared between different 66 * machines on a domain. 67 * 3. Personal / My Documents: for data explicitly created by the user, 68 * and which should be visible and easily accessed. We use a non- 69 * localized My Games subfolder for improved organization. 70 */ 71 72 // %localappdata%/0ad/ 73 const OsPath localAppdata = wutil_LocalAppdataPath() / subdirectoryName/""; 74 // %appdata%/0ad/ 75 const OsPath roamingAppData = wutil_RoamingAppdataPath() / subdirectoryName/""; 76 // My Documents/My Games/0ad/ 77 const OsPath personalData = wutil_PersonalPath() / "My Games" / subdirectoryName/""; 78 79 m_cache = localAppdata / "cache"/""; 80 m_gameData = roamingAppData / "data"/""; 81 m_userData = personalData/""; 82 m_config = roamingAppData / "config"/""; 83 m_logs = personalData / "logs"/""; 84 85 #elif OS_MACOSX 86 87 /* For reasoning behind our OS X paths, see the discussion here: 88 * http://www.wildfiregames.com/forum/index.php?showtopic=15511 89 * 90 * Summary: 91 * 1. Application Support - This is where data created by the app 92 * is supposed to be stored, with a few exceptions. However, 93 * on Lion this folder is hidden in Finder, it doesn't make sense 94 * to store screenshots and saved games in a hidden location! 95 * 2. Caches - This is where cached data for the app is stored, 96 * and unlike App Support it is not automatically backed up. 97 * 3. Documents - This is a friendly easy-to-access folder that seems 98 * appropriate for files created on-demand by the user and which 99 * they want to access directory e.g. screenshots. 100 * 101 * Note: the paths returned by osx_*Path are not guaranteed to exist, 102 * but that's OK since we always create them on demand. 103 * The returned CStringRef is our responsibility to release 104 * (so it's not automatically cleaned up when leaving Cocoa) 105 */ 106 107 // TODO: Use bundle name instead of 0ad? 108 OsPath appSupportPath; // ~/Library/Application Support/0ad 109 OsPath cachePath; // ~/Library/Caches/0ad 110 OsPath documentsPath; // ~/Documents/0ad 111 { 112 CFStringRef pathRef = osx_AppSupportPath(); 113 ENSURE(pathRef != NULL && CFStringGetLength(pathRef) > 0); 114 // There's no PATH_MAX on OS X 115 char path[CFStringGetMaximumSizeOfFileSystemRepresentation(pathRef)]; 116 // Convert path CFStringRef to char* 117 CFStringGetFileSystemRepresentation(pathRef, path, sizeof(path)); 118 CFRelease(pathRef); 119 appSupportPath = OsPath(path) / subdirectoryName; 120 } 121 { 122 CFStringRef pathRef = osx_CachesPath(); 123 ENSURE(pathRef != NULL && CFStringGetLength(pathRef) > 0); 124 char path[CFStringGetMaximumSizeOfFileSystemRepresentation(pathRef)]; 125 CFStringGetFileSystemRepresentation(pathRef, path, sizeof(path)); 126 CFRelease(pathRef); 127 cachePath = OsPath(path) / subdirectoryName; 128 } 129 { 130 CFStringRef pathRef = osx_DocumentsPath(); 131 ENSURE(pathRef != NULL && CFStringGetLength(pathRef) > 0); 132 char path[CFStringGetMaximumSizeOfFileSystemRepresentation(pathRef)]; 133 CFStringGetFileSystemRepresentation(pathRef, path, sizeof(path)); 134 CFRelease(pathRef); 135 documentsPath = OsPath(path) / subdirectoryName; 136 } 137 138 m_gameData = appSupportPath / "data"/""; 139 m_userData = documentsPath/""; 140 m_cache = cachePath/""; 141 m_config = appSupportPath / "config"/""; 142 m_logs = appSupportPath / "logs"/""; 143 144 #else // OS_UNIX 145 58 146 const char* envHome = getenv("HOME"); 59 147 ENSURE(envHome); 60 148 const OsPath home(envHome); 61 149 const OsPath xdgData = XDG_Path("XDG_DATA_HOME", home, home/".local/share/") / subdirectoryName; 62 150 const OsPath xdgConfig = XDG_Path("XDG_CONFIG_HOME", home, home/".config/" ) / subdirectoryName; 63 151 const OsPath xdgCache = XDG_Path("XDG_CACHE_HOME", home, home/".cache/" ) / subdirectoryName; 64 m_data = xdgData/""; 152 153 // We don't make the game vs. user data distinction on Unix 154 m_gameData = xdgData/""; 155 m_userData = m_gameData; 65 156 m_cache = xdgCache/""; 66 m_config = xdgConfig /"config"/"";67 m_logs = xdgConfig /"logs"/"";157 m_config = xdgConfig / "config"/""; 158 m_logs = xdgConfig / "logs"/""; 68 159 #endif 69 160 } 70 161 } -
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 (e.g. screenshots) 58 * Only things created in reponse to an explicit user action should go here. 59 */ 60 const OsPath& UserData() const 61 { 62 return m_userData; 63 } 64 65 /** 66 * Returns config file directory 67 */ 44 68 const OsPath& Config() const 45 69 { 46 70 return m_config; 47 71 } 48 72 73 /** 74 * Returns cache directory 75 */ 49 76 const OsPath& Cache() const 50 77 { 51 78 return m_cache; 52 79 } 53 80 81 /** 82 * Returns logs directory 83 */ 54 84 const OsPath& Logs() const 55 85 { 56 86 return m_logs; … … 65 95 OsPath m_rdata; 66 96 67 97 // writable directories 68 OsPath m_data; 98 OsPath m_gameData; 99 OsPath m_userData; 69 100 OsPath m_config; 70 101 OsPath m_cache; 71 102 OsPath m_logs; // special-cased in single-root-folder installations