Ticket #1145: windows_osx_path+bundle_fixes-03212012.patch

File windows_osx_path+bundle_fixes-03212012.patch, 25.6 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    // Check for the existence of bundle with correct identifier property
     42    //  (can't just use mainBundle because that can return a bundle reference
     43    //  even for a loose binary!)
     44    NSBundle *bundle = [NSBundle bundleWithIdentifier: [NSString stringWithUTF8String: BUNDLE_ID_STR]];
     45
     46    return bundle != nil;
     47}
     48
     49std::string osx_GetBundleResourcesPath()
     50{
     51    std::string path;
     52
     53    NSBundle *bundle = [NSBundle bundleWithIdentifier: [NSString stringWithUTF8String: BUNDLE_ID_STR]];
     54    if (bundle != nil)
     55    {
     56        // Retrieve NSURL and convert to POSIX path, then get C-string
     57        //  encoded as UTF-8, and use it to construct std::string
     58        // NSURL:path "If the receiver does not conform to RFC 1808, returns nil."
     59        NSString *pathStr = [[bundle resourceURL] path];
     60        if (pathStr != nil)
     61        {
     62            path = std::string([pathStr UTF8String]);
     63        }
     64    }
     65
     66    return path;
     67}
     68
     69std::string osx_GetBundleFrameworksPath()
     70{
     71    std::string path;
     72
     73    NSBundle *bundle = [NSBundle bundleWithIdentifier: [NSString stringWithUTF8String: BUNDLE_ID_STR]];
     74    if (bundle != nil)
     75    {
     76        // Retrieve NSURL and convert to POSIX path, then get C-string
     77        //  encoded as UTF-8, and use it to construct std::string
     78        // NSURL:path "If the receiver does not conform to RFC 1808, returns nil."
     79        NSString *pathStr = [[bundle privateFrameworksURL] path];
     80        if (pathStr != nil)
     81        {
     82            path = std::string([pathStr UTF8String]);
     83        }
     84    }
     85
     86    return path;
     87}
  • 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#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
     33    // Returns array of NSURL objects which are preferred for file paths
     34    NSArray* paths = [[NSFileManager defaultManager] URLsForDirectory:directory inDomains:NSUserDomainMask];
     35    if ([paths count] > 0)
     36    {
     37        // Retrieve first NSURL and convert to POSIX path, then get C-string
     38        //  encoded as UTF-8, and use it to construct std::string
     39        // NSURL:path "If the receiver does not conform to RFC 1808, returns nil."
     40        NSString* pathStr = [[paths objectAtIndex:0] path];
     41        if (pathStr != nil)
     42            result = std::string([pathStr UTF8String]);
     43    }
     44
     45    return result;
     46}
     47
     48std::string osx_GetAppSupportPath()
     49{
     50    return getUserDirectoryPath(NSApplicationSupportDirectory);
     51}
     52
     53std::string osx_GetCachesPath()
     54{
     55    return getUserDirectoryPath(NSCachesDirectory);
     56}
  • 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// Helper to avoid duplicating this setup
     284static OsPath* GetFolderPath(int csidl)
     285{
     286    HWND hwnd = 0;  // ignored unless a dial-up connection is needed to access the folder
     287    HANDLE token = 0;
     288    wchar_t path[MAX_PATH]; // mandated by SHGetFolderPathW
     289    const HRESULT ret = SHGetFolderPathW(hwnd, csidl, token, 0, path);
     290    ENSURE(SUCCEEDED(ret));
     291    if(GetLastError() == ERROR_NO_TOKEN)    // avoid polluting last error
     292        SetLastError(0);
     293    return new(wutil_Allocate(sizeof(OsPath))) OsPath(path);
     294}
     295
    272296static void GetDirectories()
    273297{
    274298    WinScopedPreserveLastError s;
     
    286310    // executable's directory
    287311    executablePath = new(wutil_Allocate(sizeof(OsPath))) OsPath(sys_ExecutablePathname().Parent());
    288312
    289     // application data
    290     {
    291         HWND hwnd = 0;  // ignored unless a dial-up connection is needed to access the folder
    292         HANDLE token = 0;
    293         wchar_t path[MAX_PATH]; // mandated by SHGetFolderPathW
    294         const HRESULT ret = SHGetFolderPathW(hwnd, CSIDL_APPDATA, token, 0, path);
    295         ENSURE(SUCCEEDED(ret));
    296         if(GetLastError() == ERROR_NO_TOKEN)    // avoid polluting last error
    297             SetLastError(0);
    298         appdataPath = new(wutil_Allocate(sizeof(OsPath))) OsPath(path);
    299     }
     313    // roaming application data
     314    roamingAppdataPath = GetFolderPath(CSIDL_APPDATA);
     315
     316    // local application data
     317    localAppdataPath = GetFolderPath(CSIDL_LOCAL_APPDATA);
     318
     319    // my documents
     320    personalPath = GetFolderPath(CSIDL_PERSONAL);
    300321}
    301322
    302323
     
    306327    wutil_Free(systemPath);
    307328    executablePath->~OsPath();
    308329    wutil_Free(executablePath);
    309     appdataPath->~OsPath();
    310     wutil_Free(appdataPath);
     330    localAppdataPath->~OsPath();
     331    wutil_Free(localAppdataPath);
     332    roamingAppdataPath->~OsPath();
     333    wutil_Free(roamingAppdataPath);
     334    personalPath->~OsPath();
     335    wutil_Free(personalPath);
    311336}
    312337
    313338
  • 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"/"", VFS_MOUNT_WATCH);
     456    g_VFS->Mount(L"screenshots/", paths.UserData()/"screenshots"/"");
     457    g_VFS->Mount(L"saves/", paths.UserData()/"saves"/"", VFS_MOUNT_WATCH);
    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
     
    3134{
    3235    m_root = Root(args.GetArg0());
    3336
    34 #ifdef INSTALLED_DATADIR
    35     m_rdata = OsPath(STRINGIZE(INSTALLED_DATADIR))/"";
    36 #else
    37     m_rdata = m_root/"data"/"";
    38 #endif
     37    m_rdata = RootData(args.GetArg0());
    3938
    4039    const char* subdirectoryName = args.Has("writableRoot")? 0 : "0ad";
    4140
    42     // everything is a subdirectory of the root
    4341    if(!subdirectoryName)
    4442    {
    45         m_data = m_rdata;
    46         m_config = m_data/"config"/"";
    47         m_cache = m_data/"cache"/"";
    48         m_logs = m_root/"logs"/"";
     43        // Note: if writableRoot option is passed to the game, then
     44        //  all the data is a subdirectory of the root
     45        m_gameData = m_rdata;
     46        m_userData = m_gameData;
     47        m_config = m_gameData / "config"/"";
     48        m_cache = m_gameData / "cache"/"";
     49        m_logs = m_root / "logs"/"";
    4950    }
    50     else
     51    else // OS-specific path handling
    5152    {
     53
    5254#if OS_ANDROID
     55
    5356        const OsPath appdata = OsPath("/sdcard/0ad/appdata");
    54         m_data = appdata/"data"/"";
     57
     58        // We don't make the game vs. user data distinction on Android
     59        m_gameData = appdata/"data"/"";
     60        m_userData = m_gameData;
    5561        m_config = appdata/"config"/"";
    5662        m_cache = appdata/"cache"/"";
    5763        m_logs = appdata/"logs"/"";
     64
    5865#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
     66
     67        /* For reasoning behind our Windows paths, see the discussion here:
     68         * http://www.wildfiregames.com/forum/index.php?showtopic=14759
     69         *
     70         * Summary:
     71         *  1. Local appdata: for bulky unfriendly data like the cache,
     72         *      which can be recreated if deleted; doesn't need backing up.
     73         *  2. Roaming appdata: for slightly less unfriendly data like config
     74         *      files that might theoretically be shared between different
     75         *      machines on a domain.
     76         *  3. Personal / My Documents: for data explicitly created by the user,
     77         *      and which should be visible and easily accessed. We use a non-
     78         *      localized My Games subfolder for improved organization.
     79         */
     80
     81        // %localappdata%/0ad/
     82        const OsPath localAppdata = wutil_LocalAppdataPath() / subdirectoryName/"";
     83        // %appdata%/0ad/
     84        const OsPath roamingAppData = wutil_RoamingAppdataPath() / subdirectoryName/"";
     85        // My Documents/My Games/0ad/
     86        const OsPath personalData = wutil_PersonalPath() / "My Games" / subdirectoryName/"";
     87
     88        m_cache = localAppdata / "cache"/"";
     89        m_gameData = roamingAppData / "data"/"";
     90        m_userData = personalData/"";
     91        m_config = roamingAppData / "config"/"";
     92        m_logs = localAppdata / "logs"/"";
     93
     94#elif OS_MACOSX
     95
     96        /* For reasoning behind our OS X paths, see the discussion here:
     97         * http://www.wildfiregames.com/forum/index.php?showtopic=15511
     98         *
     99         * Summary:
     100         *  1. Application Support: most data associated with the app
     101         *      should be stored here, with few exceptions (e.g. temporary
     102         *      data, cached data, and managed media files).
     103         *  2. Caches: used for non-critial app data that can be easily
     104         *      regenerated if this directory is deleted. It is not
     105         *      included in backups by default.
     106         *
     107         * Note: the paths returned by osx_Get*Path are not guaranteed to exist,
     108         *     but that's OK since we always create them on demand.
     109         */
     110
     111        // We probably want to use the same subdirectoryName regardless
     112        //  of whether running a bundle or from SVN. Apple recommends using
     113        //  company name, bundle name or bundle identifier.
     114        OsPath appSupportPath;  // ~/Library/Application Support/0ad
     115        OsPath cachePath;       // ~/Library/Caches/0ad
     116
     117        {
     118            std::string path = osx_GetAppSupportPath();
     119            ENSURE(!path.empty());
     120            appSupportPath = OsPath(path) / subdirectoryName;
     121        }
     122        {
     123            std::string path = osx_GetCachesPath();
     124            ENSURE(!path.empty());
     125            cachePath = OsPath(path) / subdirectoryName;
     126        }
     127
     128        // We don't make the game vs. user data distinction on OS X
     129        m_gameData = appSupportPath / "data"/"";
     130        m_userData = m_gameData;
     131        m_cache = cachePath/"";
     132        m_config = appSupportPath / "config"/"";
     133        m_logs = appSupportPath / "logs"/"";
     134
     135#else // OS_UNIX
     136
    65137        const char* envHome = getenv("HOME");
    66138        ENSURE(envHome);
    67139        const OsPath home(envHome);
    68140        const OsPath xdgData   = XDG_Path("XDG_DATA_HOME",   home, home/".local/share/") / subdirectoryName;
    69141        const OsPath xdgConfig = XDG_Path("XDG_CONFIG_HOME", home, home/".config/"     ) / subdirectoryName;
    70142        const OsPath xdgCache  = XDG_Path("XDG_CACHE_HOME",  home, home/".cache/"      ) / subdirectoryName;
    71         m_data   = xdgData/"";
     143
     144        // We don't make the game vs. user data distinction on Unix
     145        m_gameData = xdgData/"";
     146        m_userData = m_gameData;
    72147        m_cache  = xdgCache/"";
    73         m_config = xdgConfig/"config"/"";
    74         m_logs   = xdgConfig/"logs"/"";
     148        m_config = xdgConfig / "config"/"";
     149        m_logs   = xdgConfig / "logs"/"";
     150
    75151#endif
    76152    }
    77153}
     
    107183#endif
    108184}
    109185
     186/*static*/ OsPath Paths::RootData(const OsPath& argv0)
     187{
    110188
     189#ifdef INSTALLED_DATADIR
     190    return OsPath(STRINGIZE(INSTALLED_DATADIR))/"";
     191#else
     192
     193# if OS_MACOSX
     194    if (osx_IsAppBundleValid())
     195    {
     196        debug_printf(L"Valid app bundle detected\n");
     197
     198        std::string resourcesPath = osx_GetBundleResourcesPath();
     199        // Ensure we have a valid resources path
     200        ENSURE(!resourcesPath.empty());
     201
     202        return OsPath(resourcesPath)/"data"/"";
     203    }
     204# endif // OS_MACOSX
     205
     206    return Root(argv0)/"data"/"";
     207
     208#endif // INSTALLED_DATADIR
     209}
     210
    111211/*static*/ OsPath Paths::XDG_Path(const char* envname, const OsPath& home, const OsPath& defaultPath)
    112212{
    113213    const char* path = getenv(envname);
  • 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 response 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;
     
    5889
    5990private:
    6091    static OsPath Root(const OsPath& argv0);
     92    static OsPath RootData(const OsPath& argv0);
    6193    static OsPath XDG_Path(const char* envname, const OsPath& home, const OsPath& defaultPath);
    6294
    6395    // read-only directories, fixed paths relative to executable
     
    6597    OsPath m_rdata;
    6698
    6799    // writable directories
    68     OsPath m_data;
     100    OsPath m_gameData;
     101    OsPath m_userData;
    69102    OsPath m_config;
    70103    OsPath m_cache;
    71104    OsPath m_logs;  // special-cased in single-root-folder installations
  • source/tools/dist/0ad.nsi

     
    179179
    180180  RMDir "$INSTDIR"
    181181
    182   RMDir /r "$APPDATA\0ad\cache"
    183   RMDir /r "$APPDATA\0ad\logs"
     182  RMDir /r "$LOCALAPPDATA\0ad\cache"
     183  RMDir /r "$LOCALAPPDATA\0ad\logs"
    184184  ; leave the other directories (screenshots, config files, etc)
    185185
    186186  !insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder