mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-24 04:51:41 +00:00
Merge branch 'master' of https://github.com/rheit/zdoom
This commit is contained in:
commit
e08015a181
5 changed files with 439 additions and 331 deletions
|
@ -660,6 +660,7 @@ set( PLAT_WIN32_SOURCES
|
|||
win32/i_main.cpp
|
||||
win32/i_movie.cpp
|
||||
win32/i_system.cpp
|
||||
win32/i_specialpaths.cpp
|
||||
win32/st_start.cpp
|
||||
win32/win32gliface.cpp
|
||||
win32/win32video.cpp )
|
||||
|
@ -679,8 +680,11 @@ set( PLAT_SDL_SOURCES
|
|||
posix/sdl/sdlvideo.cpp
|
||||
posix/sdl/sdlglvideo.cpp
|
||||
posix/sdl/st_start.cpp )
|
||||
set( PLAT_UNIX_SOURCES
|
||||
posix/unix/i_specialpaths.cpp )
|
||||
set( PLAT_OSX_SOURCES
|
||||
posix/osx/iwadpicker_cocoa.mm
|
||||
posix/osx/i_specialpaths.mm
|
||||
posix/osx/zdoom.icns )
|
||||
set( PLAT_COCOA_SOURCES
|
||||
posix/cocoa/critsec.cpp
|
||||
|
@ -697,7 +701,7 @@ set( PLAT_COCOA_SOURCES
|
|||
if( WIN32 )
|
||||
set( SYSTEM_SOURCES_DIR win32 )
|
||||
set( SYSTEM_SOURCES ${PLAT_WIN32_SOURCES} )
|
||||
set( OTHER_SYSTEM_SOURCES ${PLAT_POSIX_SOURCES} ${PLAT_SDL_SOURCES} ${PLAT_OSX_SOURCES} ${PLAT_COCOA_SOURCES} )
|
||||
set( OTHER_SYSTEM_SOURCES ${PLAT_POSIX_SOURCES} ${PLAT_SDL_SOURCES} ${PLAT_OSX_SOURCES} ${PLAT_COCOA_SOURCES} ${PLAT_UNIX_SOURCES} )
|
||||
|
||||
if( ZD_CMAKE_COMPILER_IS_GNUCXX_COMPATIBLE )
|
||||
# CMake is not set up to compile and link rc files with GCC. :(
|
||||
|
@ -712,12 +716,12 @@ elseif( APPLE )
|
|||
if( OSX_COCOA_BACKEND )
|
||||
set( SYSTEM_SOURCES_DIR posix posix/cocoa )
|
||||
set( SYSTEM_SOURCES ${PLAT_COCOA_SOURCES} )
|
||||
set( OTHER_SYSTEM_SOURCES ${PLAT_WIN32_SOURCES} ${PLAT_SDL_SOURCES} )
|
||||
set( OTHER_SYSTEM_SOURCES ${PLAT_WIN32_SOURCES} ${PLAT_SDL_SOURCES} ${PLAT_UNIX_SOURCES} )
|
||||
else()
|
||||
set( SYSTEM_SOURCES_DIR posix posix/sdl )
|
||||
set( SYSTEM_SOURCES ${PLAT_SDL_SOURCES} )
|
||||
set( PLAT_OSX_SOURCES ${PLAT_OSX_SOURCES} posix/sdl/i_system.mm )
|
||||
set( OTHER_SYSTEM_SOURCES ${PLAT_WIN32_SOURCES} ${PLAT_COCOA_SOURCES} )
|
||||
set( OTHER_SYSTEM_SOURCES ${PLAT_WIN32_SOURCES} ${PLAT_COCOA_SOURCES} ${PLAT_UNIX_SOURCES} )
|
||||
endif()
|
||||
|
||||
set( SYSTEM_SOURCES ${SYSTEM_SOURCES} ${PLAT_POSIX_SOURCES} ${PLAT_OSX_SOURCES} "${FMOD_LIBRARY}" )
|
||||
|
@ -727,7 +731,7 @@ elseif( APPLE )
|
|||
set_source_files_properties( posix/osx/iwadpicker_cocoa.mm PROPERTIES COMPILE_FLAGS -fobjc-exceptions )
|
||||
else()
|
||||
set( SYSTEM_SOURCES_DIR posix posix/sdl )
|
||||
set( SYSTEM_SOURCES ${PLAT_POSIX_SOURCES} ${PLAT_SDL_SOURCES} )
|
||||
set( SYSTEM_SOURCES ${PLAT_POSIX_SOURCES} ${PLAT_SDL_SOURCES} ${PLAT_UNIX_SOURCES} )
|
||||
set( OTHER_SYSTEM_SOURCES ${PLAT_WIN32_SOURCES} ${PLAT_OSX_SOURCES} ${PLAT_COCOA_SOURCES} )
|
||||
endif()
|
||||
|
||||
|
@ -1387,7 +1391,6 @@ add_executable( zdoom WIN32 MACOSX_BUNDLE
|
|||
${FASTMATH_SOURCES}
|
||||
${PCH_SOURCES}
|
||||
x86.cpp
|
||||
m_specialpaths.cpp
|
||||
strnatcmp.c
|
||||
zstring.cpp
|
||||
math/asin.c
|
||||
|
@ -1565,6 +1568,7 @@ source_group("Resource Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/r
|
|||
source_group("POSIX Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/posix/.+")
|
||||
source_group("Cocoa Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/posix/cocoa/.+")
|
||||
source_group("OS X Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/posix/osx/.+")
|
||||
source_group("Unix Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/posix/unix/.+")
|
||||
source_group("SDL Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/posix/sdl/.+")
|
||||
source_group("SFMT" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/sfmt/.+")
|
||||
source_group("Shared Game" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/g_shared/.+")
|
||||
|
|
|
@ -4450,6 +4450,7 @@ enum EACSFunctions
|
|||
*/
|
||||
|
||||
ACSF_CheckClass = 200,
|
||||
ACSF_DamageActor, // [arookas]
|
||||
|
||||
// ZDaemon
|
||||
ACSF_GetTeamScore = 19620, // (int team)
|
||||
|
@ -6035,6 +6036,15 @@ doplaysound: if (funcIndex == ACSF_PlayActorSound)
|
|||
const char *clsname = FBehavior::StaticLookupString(args[0]);
|
||||
return !!PClass::FindActor(clsname);
|
||||
}
|
||||
|
||||
case ACSF_DamageActor: // [arookas] wrapper around P_DamageMobj
|
||||
{
|
||||
// (target, ptr_select1, inflictor, ptr_select2, amount, damagetype)
|
||||
AActor* target = COPY_AAPTR(SingleActorFromTID(args[0], activator), args[1]);
|
||||
AActor* inflictor = COPY_AAPTR(SingleActorFromTID(args[2], activator), args[3]);
|
||||
FName damagetype(FBehavior::StaticLookupString(args[5]));
|
||||
return P_DamageMobj(target, inflictor, inflictor, args[4], damagetype);
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
|
|
187
src/posix/osx/i_specialpaths.mm
Normal file
187
src/posix/osx/i_specialpaths.mm
Normal file
|
@ -0,0 +1,187 @@
|
|||
/*
|
||||
** i_specialpaths.mm
|
||||
** Gets special system folders where data should be stored. (macOS version)
|
||||
**
|
||||
**---------------------------------------------------------------------------
|
||||
** Copyright 2013-2016 Randy Heit
|
||||
** Copyright 2016 Christoph Oelckers
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions
|
||||
** are met:
|
||||
**
|
||||
** 1. Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**---------------------------------------------------------------------------
|
||||
**
|
||||
*/
|
||||
|
||||
#include <CoreServices/CoreServices.h>
|
||||
|
||||
#include "cmdlib.h"
|
||||
#include "m_misc.h"
|
||||
#include "version.h" // for GAMENAME
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// M_GetCachePath macOS
|
||||
//
|
||||
// Returns the path for cache GL nodes.
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FString M_GetCachePath(bool create)
|
||||
{
|
||||
FString path;
|
||||
|
||||
char pathstr[PATH_MAX];
|
||||
FSRef folder;
|
||||
|
||||
if (noErr == FSFindFolder(kUserDomain, kApplicationSupportFolderType, create ? kCreateFolder : 0, &folder) &&
|
||||
noErr == FSRefMakePath(&folder, (UInt8*)pathstr, PATH_MAX))
|
||||
{
|
||||
path = pathstr;
|
||||
}
|
||||
else
|
||||
{
|
||||
path = progdir;
|
||||
}
|
||||
path += "/zdoom/cache";
|
||||
return path;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// M_GetAutoexecPath macOS
|
||||
//
|
||||
// Returns the expected location of autoexec.cfg.
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FString M_GetAutoexecPath()
|
||||
{
|
||||
FString path;
|
||||
|
||||
char cpath[PATH_MAX];
|
||||
FSRef folder;
|
||||
|
||||
if (noErr == FSFindFolder(kUserDomain, kDocumentsFolderType, kCreateFolder, &folder) &&
|
||||
noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
|
||||
{
|
||||
path << cpath << "/" GAME_DIR "/autoexec.cfg";
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// M_GetCajunPath macOS
|
||||
//
|
||||
// Returns the location of the Cajun Bot definitions.
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FString M_GetCajunPath(const char *botfilename)
|
||||
{
|
||||
FString path;
|
||||
|
||||
// Just copies the Windows code. Should this be more Mac-specific?
|
||||
path << progdir << "zcajun/" << botfilename;
|
||||
if (!FileExists(path))
|
||||
{
|
||||
path = "";
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// M_GetConfigPath macOS
|
||||
//
|
||||
// Returns the path to the config file. On Windows, this can vary for reading
|
||||
// vs writing. i.e. If $PROGDIR/zdoom-<user>.ini does not exist, it will try
|
||||
// to read from $PROGDIR/zdoom.ini, but it will never write to zdoom.ini.
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FString M_GetConfigPath(bool for_reading)
|
||||
{
|
||||
char cpath[PATH_MAX];
|
||||
FSRef folder;
|
||||
|
||||
if (noErr == FSFindFolder(kUserDomain, kPreferencesFolderType, kCreateFolder, &folder) &&
|
||||
noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
|
||||
{
|
||||
FString path;
|
||||
path << cpath << "/" GAMENAMELOWERCASE ".ini";
|
||||
return path;
|
||||
}
|
||||
// Ungh.
|
||||
return GAMENAMELOWERCASE ".ini";
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// M_GetScreenshotsPath macOS
|
||||
//
|
||||
// Returns the path to the default screenshots directory.
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FString M_GetScreenshotsPath()
|
||||
{
|
||||
FString path;
|
||||
char cpath[PATH_MAX];
|
||||
FSRef folder;
|
||||
|
||||
if (noErr == FSFindFolder(kUserDomain, kDocumentsFolderType, kCreateFolder, &folder) &&
|
||||
noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
|
||||
{
|
||||
path << cpath << "/" GAME_DIR "/Screenshots/";
|
||||
}
|
||||
else
|
||||
{
|
||||
path = "~/";
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// M_GetSavegamesPath macOS
|
||||
//
|
||||
// Returns the path to the default save games directory.
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FString M_GetSavegamesPath()
|
||||
{
|
||||
FString path;
|
||||
char cpath[PATH_MAX];
|
||||
FSRef folder;
|
||||
|
||||
if (noErr == FSFindFolder(kUserDomain, kDocumentsFolderType, kCreateFolder, &folder) &&
|
||||
noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
|
||||
{
|
||||
path << cpath << "/" GAME_DIR "/Savegames/";
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
199
src/posix/unix/i_specialpaths.cpp
Normal file
199
src/posix/unix/i_specialpaths.cpp
Normal file
|
@ -0,0 +1,199 @@
|
|||
/*
|
||||
** i_specialpaths.cpp
|
||||
** Gets special system folders where data should be stored. (Unix version)
|
||||
**
|
||||
**---------------------------------------------------------------------------
|
||||
** Copyright 2013-2016 Randy Heit
|
||||
** Copyright 2016 Christoph Oelckers
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions
|
||||
** are met:
|
||||
**
|
||||
** 1. Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**---------------------------------------------------------------------------
|
||||
**
|
||||
*/
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include "i_system.h"
|
||||
|
||||
#include "version.h" // for GAMENAME
|
||||
|
||||
|
||||
FString GetUserFile (const char *file)
|
||||
{
|
||||
FString path;
|
||||
struct stat info;
|
||||
|
||||
path = NicePath("~/" GAME_DIR "/");
|
||||
|
||||
if (stat (path, &info) == -1)
|
||||
{
|
||||
struct stat extrainfo;
|
||||
|
||||
// Sanity check for ~/.config
|
||||
FString configPath = NicePath("~/.config/");
|
||||
if (stat (configPath, &extrainfo) == -1)
|
||||
{
|
||||
if (mkdir (configPath, S_IRUSR | S_IWUSR | S_IXUSR) == -1)
|
||||
{
|
||||
I_FatalError ("Failed to create ~/.config directory:\n%s", strerror(errno));
|
||||
}
|
||||
}
|
||||
else if (!S_ISDIR(extrainfo.st_mode))
|
||||
{
|
||||
I_FatalError ("~/.config must be a directory");
|
||||
}
|
||||
|
||||
// This can be removed after a release or two
|
||||
// Transfer the old zdoom directory to the new location
|
||||
bool moved = false;
|
||||
FString oldpath = NicePath("~/." GAMENAMELOWERCASE "/");
|
||||
if (stat (oldpath, &extrainfo) != -1)
|
||||
{
|
||||
if (rename(oldpath, path) == -1)
|
||||
{
|
||||
I_Error ("Failed to move old " GAMENAMELOWERCASE " directory (%s) to new location (%s).",
|
||||
oldpath.GetChars(), path.GetChars());
|
||||
}
|
||||
else
|
||||
moved = true;
|
||||
}
|
||||
|
||||
if (!moved && mkdir (path, S_IRUSR | S_IWUSR | S_IXUSR) == -1)
|
||||
{
|
||||
I_FatalError ("Failed to create %s directory:\n%s",
|
||||
path.GetChars(), strerror (errno));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!S_ISDIR(info.st_mode))
|
||||
{
|
||||
I_FatalError ("%s must be a directory", path.GetChars());
|
||||
}
|
||||
}
|
||||
path += file;
|
||||
return path;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// M_GetCachePath Unix
|
||||
//
|
||||
// Returns the path for cache GL nodes.
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FString M_GetCachePath(bool create)
|
||||
{
|
||||
// Don't use GAME_DIR and such so that ZDoom and its child ports can
|
||||
// share the node cache.
|
||||
FString path = NicePath("~/.config/zdoom/cache");
|
||||
if (create)
|
||||
{
|
||||
CreatePath(path);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// M_GetAutoexecPath Unix
|
||||
//
|
||||
// Returns the expected location of autoexec.cfg.
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FString M_GetAutoexecPath()
|
||||
{
|
||||
return GetUserFile("autoexec.cfg");
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// M_GetCajunPath Unix
|
||||
//
|
||||
// Returns the location of the Cajun Bot definitions.
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FString M_GetCajunPath(const char *botfilename)
|
||||
{
|
||||
FString path;
|
||||
|
||||
// Check first in ~/.config/zdoom/botfilename.
|
||||
path = GetUserFile(botfilename);
|
||||
if (!FileExists(path))
|
||||
{
|
||||
// Then check in SHARE_DIR/botfilename.
|
||||
path = SHARE_DIR;
|
||||
path << botfilename;
|
||||
if (!FileExists(path))
|
||||
{
|
||||
path = "";
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// M_GetConfigPath Unix
|
||||
//
|
||||
// Returns the path to the config file. On Windows, this can vary for reading
|
||||
// vs writing. i.e. If $PROGDIR/zdoom-<user>.ini does not exist, it will try
|
||||
// to read from $PROGDIR/zdoom.ini, but it will never write to zdoom.ini.
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FString M_GetConfigPath(bool for_reading)
|
||||
{
|
||||
return GetUserFile(GAMENAMELOWERCASE ".ini");
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// M_GetScreenshotsPath Unix
|
||||
//
|
||||
// Returns the path to the default screenshots directory.
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FString M_GetScreenshotsPath()
|
||||
{
|
||||
return NicePath("~/" GAME_DIR "/screenshots/");
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// M_GetSavegamesPath Unix
|
||||
//
|
||||
// Returns the path to the default save games directory.
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FString M_GetSavegamesPath()
|
||||
{
|
||||
return NicePath("~/" GAME_DIR);
|
||||
}
|
|
@ -1,27 +1,46 @@
|
|||
#ifdef __APPLE__
|
||||
#include <CoreServices/CoreServices.h>
|
||||
#endif
|
||||
/*
|
||||
** i_specialpaths.cpp
|
||||
** Gets special system folders where data should be stored. (Windows version)
|
||||
**
|
||||
**---------------------------------------------------------------------------
|
||||
** Copyright 2013-2016 Randy Heit
|
||||
** Copyright 2016 Christoph Oelckers
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions
|
||||
** are met:
|
||||
**
|
||||
** 1. Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**---------------------------------------------------------------------------
|
||||
**
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <lmcons.h>
|
||||
#include <shlobj.h>
|
||||
#define USE_WINDOWS_DWORD
|
||||
#endif
|
||||
|
||||
#include "cmdlib.h"
|
||||
#include "m_misc.h"
|
||||
|
||||
#if !defined(__APPLE__) && !defined(_WIN32)
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include "i_system.h"
|
||||
#endif
|
||||
|
||||
#include "version.h" // for GAMENAME
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
#include "i_system.h"
|
||||
|
||||
typedef HRESULT (WINAPI *GKFP)(REFKNOWNFOLDERID, DWORD, HANDLE, PWSTR *);
|
||||
|
@ -323,314 +342,3 @@ FString M_GetSavegamesPath()
|
|||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// M_GetCachePath Mac OS X
|
||||
//
|
||||
// Returns the path for cache GL nodes.
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FString M_GetCachePath(bool create)
|
||||
{
|
||||
FString path;
|
||||
|
||||
char pathstr[PATH_MAX];
|
||||
FSRef folder;
|
||||
|
||||
if (noErr == FSFindFolder(kUserDomain, kApplicationSupportFolderType, create ? kCreateFolder : 0, &folder) &&
|
||||
noErr == FSRefMakePath(&folder, (UInt8*)pathstr, PATH_MAX))
|
||||
{
|
||||
path = pathstr;
|
||||
}
|
||||
else
|
||||
{
|
||||
path = progdir;
|
||||
}
|
||||
path += "/zdoom/cache";
|
||||
return path;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// M_GetAutoexecPath Mac OS X
|
||||
//
|
||||
// Returns the expected location of autoexec.cfg.
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FString M_GetAutoexecPath()
|
||||
{
|
||||
FString path;
|
||||
|
||||
char cpath[PATH_MAX];
|
||||
FSRef folder;
|
||||
|
||||
if (noErr == FSFindFolder(kUserDomain, kDocumentsFolderType, kCreateFolder, &folder) &&
|
||||
noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
|
||||
{
|
||||
path << cpath << "/" GAME_DIR "/autoexec.cfg";
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// M_GetCajunPath Mac OS X
|
||||
//
|
||||
// Returns the location of the Cajun Bot definitions.
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FString M_GetCajunPath(const char *botfilename)
|
||||
{
|
||||
FString path;
|
||||
|
||||
// Just copies the Windows code. Should this be more Mac-specific?
|
||||
path << progdir << "zcajun/" << botfilename;
|
||||
if (!FileExists(path))
|
||||
{
|
||||
path = "";
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// M_GetConfigPath Mac OS X
|
||||
//
|
||||
// Returns the path to the config file. On Windows, this can vary for reading
|
||||
// vs writing. i.e. If $PROGDIR/zdoom-<user>.ini does not exist, it will try
|
||||
// to read from $PROGDIR/zdoom.ini, but it will never write to zdoom.ini.
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FString M_GetConfigPath(bool for_reading)
|
||||
{
|
||||
char cpath[PATH_MAX];
|
||||
FSRef folder;
|
||||
|
||||
if (noErr == FSFindFolder(kUserDomain, kPreferencesFolderType, kCreateFolder, &folder) &&
|
||||
noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
|
||||
{
|
||||
FString path;
|
||||
path << cpath << "/" GAMENAMELOWERCASE ".ini";
|
||||
return path;
|
||||
}
|
||||
// Ungh.
|
||||
return GAMENAMELOWERCASE ".ini";
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// M_GetScreenshotsPath Mac OS X
|
||||
//
|
||||
// Returns the path to the default screenshots directory.
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FString M_GetScreenshotsPath()
|
||||
{
|
||||
FString path;
|
||||
char cpath[PATH_MAX];
|
||||
FSRef folder;
|
||||
|
||||
if (noErr == FSFindFolder(kUserDomain, kDocumentsFolderType, kCreateFolder, &folder) &&
|
||||
noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
|
||||
{
|
||||
path << cpath << "/" GAME_DIR "/Screenshots/";
|
||||
}
|
||||
else
|
||||
{
|
||||
path = "~/";
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// M_GetSavegamesPath Mac OS X
|
||||
//
|
||||
// Returns the path to the default save games directory.
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FString M_GetSavegamesPath()
|
||||
{
|
||||
FString path;
|
||||
char cpath[PATH_MAX];
|
||||
FSRef folder;
|
||||
|
||||
if (noErr == FSFindFolder(kUserDomain, kDocumentsFolderType, kCreateFolder, &folder) &&
|
||||
noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
|
||||
{
|
||||
path << cpath << "/" GAME_DIR "/Savegames/";
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
#else // Linux, et al.
|
||||
|
||||
|
||||
FString GetUserFile (const char *file)
|
||||
{
|
||||
FString path;
|
||||
struct stat info;
|
||||
|
||||
path = NicePath("~/" GAME_DIR "/");
|
||||
|
||||
if (stat (path, &info) == -1)
|
||||
{
|
||||
struct stat extrainfo;
|
||||
|
||||
// Sanity check for ~/.config
|
||||
FString configPath = NicePath("~/.config/");
|
||||
if (stat (configPath, &extrainfo) == -1)
|
||||
{
|
||||
if (mkdir (configPath, S_IRUSR | S_IWUSR | S_IXUSR) == -1)
|
||||
{
|
||||
I_FatalError ("Failed to create ~/.config directory:\n%s", strerror(errno));
|
||||
}
|
||||
}
|
||||
else if (!S_ISDIR(extrainfo.st_mode))
|
||||
{
|
||||
I_FatalError ("~/.config must be a directory");
|
||||
}
|
||||
|
||||
// This can be removed after a release or two
|
||||
// Transfer the old zdoom directory to the new location
|
||||
bool moved = false;
|
||||
FString oldpath = NicePath("~/." GAMENAMELOWERCASE "/");
|
||||
if (stat (oldpath, &extrainfo) != -1)
|
||||
{
|
||||
if (rename(oldpath, path) == -1)
|
||||
{
|
||||
I_Error ("Failed to move old " GAMENAMELOWERCASE " directory (%s) to new location (%s).",
|
||||
oldpath.GetChars(), path.GetChars());
|
||||
}
|
||||
else
|
||||
moved = true;
|
||||
}
|
||||
|
||||
if (!moved && mkdir (path, S_IRUSR | S_IWUSR | S_IXUSR) == -1)
|
||||
{
|
||||
I_FatalError ("Failed to create %s directory:\n%s",
|
||||
path.GetChars(), strerror (errno));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!S_ISDIR(info.st_mode))
|
||||
{
|
||||
I_FatalError ("%s must be a directory", path.GetChars());
|
||||
}
|
||||
}
|
||||
path += file;
|
||||
return path;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// M_GetCachePath Unix
|
||||
//
|
||||
// Returns the path for cache GL nodes.
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FString M_GetCachePath(bool create)
|
||||
{
|
||||
// Don't use GAME_DIR and such so that ZDoom and its child ports can
|
||||
// share the node cache.
|
||||
FString path = NicePath("~/.config/zdoom/cache");
|
||||
if (create)
|
||||
{
|
||||
CreatePath(path);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// M_GetAutoexecPath Unix
|
||||
//
|
||||
// Returns the expected location of autoexec.cfg.
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FString M_GetAutoexecPath()
|
||||
{
|
||||
return GetUserFile("autoexec.cfg");
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// M_GetCajunPath Unix
|
||||
//
|
||||
// Returns the location of the Cajun Bot definitions.
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FString M_GetCajunPath(const char *botfilename)
|
||||
{
|
||||
FString path;
|
||||
|
||||
// Check first in ~/.config/zdoom/botfilename.
|
||||
path = GetUserFile(botfilename);
|
||||
if (!FileExists(path))
|
||||
{
|
||||
// Then check in SHARE_DIR/botfilename.
|
||||
path = SHARE_DIR;
|
||||
path << botfilename;
|
||||
if (!FileExists(path))
|
||||
{
|
||||
path = "";
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// M_GetConfigPath Unix
|
||||
//
|
||||
// Returns the path to the config file. On Windows, this can vary for reading
|
||||
// vs writing. i.e. If $PROGDIR/zdoom-<user>.ini does not exist, it will try
|
||||
// to read from $PROGDIR/zdoom.ini, but it will never write to zdoom.ini.
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FString M_GetConfigPath(bool for_reading)
|
||||
{
|
||||
return GetUserFile(GAMENAMELOWERCASE ".ini");
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// M_GetScreenshotsPath Unix
|
||||
//
|
||||
// Returns the path to the default screenshots directory.
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FString M_GetScreenshotsPath()
|
||||
{
|
||||
return NicePath("~/" GAME_DIR "/screenshots/");
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// M_GetSavegamesPath Unix
|
||||
//
|
||||
// Returns the path to the default save games directory.
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FString M_GetSavegamesPath()
|
||||
{
|
||||
return NicePath("~/" GAME_DIR);
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue