Ticket #1145: windows_osx_path+bundle_fixes-03062012.patch

File windows_osx_path+bundle_fixes-03062012.patch, 25.7 KB (added by historic_bruno, 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 */
     37bool 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 */
     45std::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 */
     53std::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
     33static const char* BUNDLE_ID_STR = STRINGIZE(BUNDLE_IDENTIFIER);
     34#else
     35static const char* BUNDLE_ID_STR = "";
     36#endif
     37
     38
     39bool 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
     52std::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
     74std::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 */
     37std::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 */
     45std::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 */
     53std::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 */
     61std::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
     29static 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
     50std::string osx_GetAppSupportPath()
     51{
     52    return getUserDirectoryPath(NSApplicationSupportDirectory);
     53}
     54
     55std::string osx_GetCachesPath()
     56{
     57    return getUserDirectoryPath(NSCachesDirectory);
     58}
     59
     60std::string osx_GetLibraryPath()
     61{
     62    return getUserDirectoryPath(NSLibraryDirectory);
     63}
     64
     65std::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) 2010 Wildfire Games
     1/* Copyright (c) 2012 Wildfire Games
    22 *
    33 * Permission is hereby granted, free of charge, to any person obtaining
    44 * a copy of this software and associated documentation files (the
     
    251251// (NB: wutil_Init is called before static ctors => use placement new)
    252252static OsPath* systemPath;
    253253static OsPath* executablePath;
    254 static OsPath* appdataPath;
     254static OsPath* localAppdataPath;
     255static OsPath* roamingAppdataPath;
     256static OsPath* personalPath;
    255257
    256258const OsPath& wutil_SystemPath()
    257259{
     
    263265    return *executablePath;
    264266}
    265267
    266 const OsPath& wutil_AppdataPath()
     268const OsPath& wutil_LocalAppdataPath()
    267269{
    268     return *appdataPath;
     270    return *localAppdataPath;
    269271}
    270272
     273const OsPath& wutil_RoamingAppdataPath()
     274{
     275    return *roamingAppdataPath;
     276}
    271277
     278const OsPath& wutil_PersonalPath()
     279{
     280    return *personalPath;
     281}
     282
     283
    272284static void GetDirectories()
    273285{
    274286    WinScopedPreserveLastError s;
     
    286298    // executable's directory
    287299    executablePath = new(wutil_Allocate(sizeof(OsPath))) OsPath(sys_ExecutablePathname().Parent());
    288300
    289     // application data
     301    // roaming application data
    290302    {
    291303        HWND hwnd = 0;  // ignored unless a dial-up connection is needed to access the folder
    292304        HANDLE token = 0;
     
    295307        ENSURE(SUCCEEDED(ret));
    296308        if(GetLastError() == ERROR_NO_TOKEN)    // avoid polluting last error
    297309            SetLastError(0);
    298         appdataPath = new(wutil_Allocate(sizeof(OsPath))) OsPath(path);
     310        roamingAppdataPath = new(wutil_Allocate(sizeof(OsPath))) OsPath(path);
    299311    }
     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    }
    300336}
    301337
    302338
     
    306342    wutil_Free(systemPath);
    307343    executablePath->~OsPath();
    308344    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);
    311351}
    312352
    313353
  • source/lib/sysdep/os/win/wutil.h

     
    1 /* Copyright (c) 2010 Wildfire Games
     1/* Copyright (c) 2012 Wildfire Games
    22 *
    33 * Permission is hereby granted, free of charge, to any person obtaining
    44 * a copy of this software and associated documentation files (the
     
    159159
    160160extern const OsPath& wutil_SystemPath();
    161161extern const OsPath& wutil_ExecutablePath();
    162 extern const OsPath& wutil_AppdataPath();
     162extern const OsPath& wutil_LocalAppdataPath();
     163extern const OsPath& wutil_RoamingAppdataPath();
     164extern const OsPath& wutil_PersonalPath();
    163165
    164166
    165167//-----------------------------------------------------------------------------
  • source/ps/DllLoader.cpp

     
    1 /* Copyright (C) 2011 Wildfire Games.
     1/* Copyright (C) 2012 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    2525#include "ps/CLogger.h"
    2626#include "ps/GameSetup/Config.h"
    2727
     28#if OS_MACOSX
     29# include "lib/sysdep/os/osx/osx_bundle.h"
     30#endif
     31
    2832static void* const HANDLE_UNAVAILABLE = (void*)-1;
    2933
    3034// directory to search for libraries (optionally set by --libdir at build-time,
     
    7074static CStr GenerateFilename(const CStr& name, const CStr& suffix, const CStr& extension)
    7175{
    7276    CStr n;
     77
    7378    if (!g_Libdir.empty())
    7479        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
    7594    n += prefix + name + suffix + extension;
    7695    return n;
    7796}
  • source/ps/GameSetup/GameSetup.cpp

     
    453453    const size_t cacheSize = ChooseCacheSize();
    454454    g_VFS = CreateVfs(cacheSize);
    455455
    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"/"");
    458458    const OsPath readonlyConfig = paths.RData()/"config"/"";
    459459    g_VFS->Mount(L"config/", readonlyConfig);
    460460    if(readonlyConfig != paths.Config())
  • source/ps/GameSetup/Paths.cpp

     
    1 /* Copyright (C) 2009 Wildfire Games.
     1/* Copyright (C) 2012 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    2222#include "lib/sysdep/sysdep.h"  // sys_get_executable_name
    2323#include "lib/sysdep/filesystem.h"  // wrealpath
    2424#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"
    2629#endif
    2730#include "ps/CLogger.h"
    2831
     
    3437#ifdef INSTALLED_DATADIR
    3538    m_rdata = OsPath(STRINGIZE(INSTALLED_DATADIR))/"";
    3639#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");
    3944
     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
    4058    const char* subdirectoryName = args.Has("writableRoot")? 0 : "0ad";
    4159
    42     // everything is a subdirectory of the root
    4360    if(!subdirectoryName)
    4461    {
    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"/"";
    4969    }
    50     else
     70    else // OS-specific path handling
    5171    {
     72
    5273#if OS_ANDROID
     74
    5375        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;
    5580        m_config = appdata/"config"/"";
    5681        m_cache = appdata/"cache"/"";
    5782        m_logs = appdata/"logs"/"";
     83
    5884#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
    65156        const char* envHome = getenv("HOME");
    66157        ENSURE(envHome);
    67158        const OsPath home(envHome);
    68159        const OsPath xdgData   = XDG_Path("XDG_DATA_HOME",   home, home/".local/share/") / subdirectoryName;
    69160        const OsPath xdgConfig = XDG_Path("XDG_CONFIG_HOME", home, home/".config/"     ) / subdirectoryName;
    70161        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;
    72166        m_cache  = xdgCache/"";
    73         m_config = xdgConfig/"config"/"";
    74         m_logs   = xdgConfig/"logs"/"";
     167        m_config = xdgConfig / "config"/"";
     168        m_logs   = xdgConfig / "logs"/"";
     169
    75170#endif
    76171    }
    77172}
  • source/ps/GameSetup/Paths.h

     
    1 /* Copyright (C) 2009 Wildfire Games.
     1/* Copyright (C) 2012 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    2121#include "lib/os_path.h"
    2222#include "CmdLineArgs.h"
    2323
     24/**
     25 * Wrapper class for OS paths used by the game
     26 */
    2427class Paths
    2528{
    2629public:
    2730    Paths(const CmdLineArgs& args);
    2831
     32    /**
     33     * Returns the game's root directory
     34     */
    2935    const OsPath& Root() const
    3036    {
    3137        return m_root;
    3238    }
    3339
     40    /**
     41     * Returns directory for read-only data installed with the game
     42     */
    3443    const OsPath& RData() const
    3544    {
    3645        return m_rdata;
    3746    }
    3847
    39     const OsPath& Data() const
     48    /**
     49     * Returns directory for game-managed data and mods
     50     */
     51    const OsPath& GameData() const
    4052    {
    41         return m_data;
     53        return m_gameData;
    4254    }
    4355
     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     */
    4469    const OsPath& Config() const
    4570    {
    4671        return m_config;
    4772    }
    4873
     74    /**
     75     * Returns cache directory
     76     */
    4977    const OsPath& Cache() const
    5078    {
    5179        return m_cache;
    5280    }
    5381
     82    /**
     83     * Returns logs directory
     84     */
    5485    const OsPath& Logs() const
    5586    {
    5687        return m_logs;
     
    6596    OsPath m_rdata;
    6697
    6798    // writable directories
    68     OsPath m_data;
     99    OsPath m_gameData;
     100    OsPath m_userData;
    69101    OsPath m_config;
    70102    OsPath m_cache;
    71103    OsPath m_logs;  // special-cased in single-root-folder installations