mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-28 06:53:58 +00:00
- Look for files in Mac-like places on Macs.
- Fixed: The non-Windows CreatePath can fail if part of the path already exists, because mkdir will return an error code for trying to recreate an existing directory. SVN r1814 (trunk)
This commit is contained in:
parent
12576d2eb5
commit
66920536d9
9 changed files with 119 additions and 100 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
September 9, 2009
|
||||||
|
- Look for files in Mac-like places on Macs.
|
||||||
|
- Fixed: The non-Windows CreatePath can fail if part of the path already
|
||||||
|
exists, because mkdir will return an error code for trying to recreate
|
||||||
|
an existing directory.
|
||||||
|
|
||||||
September 8, 2009
|
September 8, 2009
|
||||||
- Because entryway timed it, here is a new version of R_PointToAngle2 that is
|
- Because entryway timed it, here is a new version of R_PointToAngle2 that is
|
||||||
closer to the original. The old code was shorter but a little slower. The
|
closer to the original. The old code was shorter but a little slower. The
|
||||||
|
|
|
@ -512,12 +512,17 @@ void CreatePath(const char *fn)
|
||||||
{
|
{
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
}
|
}
|
||||||
printf("%s\n", copy);
|
struct stat info;
|
||||||
|
if (stat(copy, &info) == 0)
|
||||||
|
{
|
||||||
|
if (info.st_mode & S_IFDIR)
|
||||||
|
goto exists;
|
||||||
|
}
|
||||||
if (mkdir(copy, 0755) == -1)
|
if (mkdir(copy, 0755) == -1)
|
||||||
{ // failed
|
{ // failed
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (p != NULL)
|
exists: if (p != NULL)
|
||||||
{
|
{
|
||||||
*p = '/';
|
*p = '/';
|
||||||
}
|
}
|
||||||
|
|
|
@ -396,34 +396,6 @@ static int CheckIWAD (const char *doomwaddir, WadStuff *wads)
|
||||||
return numfound;
|
return numfound;
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
|
||||||
//
|
|
||||||
// CheckIWADinEnvDir
|
|
||||||
//
|
|
||||||
// Checks for an IWAD in a path that contains one or more environment
|
|
||||||
// variables.
|
|
||||||
//
|
|
||||||
//==========================================================================
|
|
||||||
|
|
||||||
static int CheckIWADinEnvDir (const char *str, WadStuff *wads)
|
|
||||||
{
|
|
||||||
FString expanded = ExpandEnvVars (str);
|
|
||||||
|
|
||||||
if (!expanded.IsEmpty())
|
|
||||||
{
|
|
||||||
char *dir = expanded.LockBuffer ();
|
|
||||||
FixPathSeperator (dir);
|
|
||||||
expanded.UnlockBuffer ();
|
|
||||||
if (expanded[expanded.Len() - 1] != '/')
|
|
||||||
{
|
|
||||||
expanded += '/';
|
|
||||||
}
|
|
||||||
return CheckIWAD (expanded, wads);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// IdentifyVersion
|
// IdentifyVersion
|
||||||
|
@ -484,21 +456,10 @@ static EIWADType IdentifyVersion (const char *zdoom_wad)
|
||||||
{
|
{
|
||||||
if (stricmp (key, "Path") == 0)
|
if (stricmp (key, "Path") == 0)
|
||||||
{
|
{
|
||||||
if (strchr (value, '$') != NULL)
|
FString nice = NicePath(value);
|
||||||
{
|
FixPathSeperator(nice.LockBuffer());
|
||||||
CheckIWADinEnvDir (value, wads);
|
nice.UnlockBuffer();
|
||||||
}
|
CheckIWAD(nice, wads);
|
||||||
#ifdef unix
|
|
||||||
else if (*value == '~' && (*(value + 1) == 0 || *(value + 1) == '/'))
|
|
||||||
{
|
|
||||||
FString homepath = GetUserFile (*(value + 1) ? value + 2 : value + 1, true);
|
|
||||||
CheckIWAD (homepath, wads);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CheckIWAD (value, wads);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1426,34 +1426,12 @@ static const char *BaseFileSearch (const char *file, const char *ext, bool lookf
|
||||||
{
|
{
|
||||||
if (stricmp (key, "Path") == 0)
|
if (stricmp (key, "Path") == 0)
|
||||||
{
|
{
|
||||||
const char *dir;
|
FString dir;
|
||||||
FString homepath;
|
|
||||||
|
|
||||||
if (*value == '$')
|
dir = NicePath(value);
|
||||||
|
if (dir.IsNotEmpty())
|
||||||
{
|
{
|
||||||
if (stricmp (value + 1, "progdir") == 0)
|
mysnprintf (wad, countof(wad), "%s%s%s", dir.GetChars(), dir[dir.Len() - 1] != '/' ? "/" : "", file);
|
||||||
{
|
|
||||||
dir = progdir;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dir = getenv (value + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#ifdef unix
|
|
||||||
else if (*value == '~' && (*(value + 1) == 0 || *(value + 1) == '/'))
|
|
||||||
{
|
|
||||||
homepath = GetUserFile (*(value + 1) ? value + 2 : value + 1, true);
|
|
||||||
dir = homepath;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dir = value;
|
|
||||||
}
|
|
||||||
if (dir != NULL)
|
|
||||||
{
|
|
||||||
mysnprintf (wad, countof(wad), "%s%s%s", dir, dir[strlen (dir) - 1] != '/' ? "/" : "", file);
|
|
||||||
if (DirEntryExists (wad))
|
if (DirEntryExists (wad))
|
||||||
{
|
{
|
||||||
return wad;
|
return wad;
|
||||||
|
@ -1862,7 +1840,7 @@ void D_DoomMain (void)
|
||||||
Printf ("%s", GStrings("D_DEVSTR"));
|
Printf ("%s", GStrings("D_DEVSTR"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef unix
|
#if !defined(unix) && !defined(__APPLE__)
|
||||||
// We do not need to support -cdrom under Unix, because all the files
|
// We do not need to support -cdrom under Unix, because all the files
|
||||||
// that would go to c:\\zdoomdat are already stored in .zdoom inside
|
// that would go to c:\\zdoomdat are already stored in .zdoom inside
|
||||||
// the user's home directory.
|
// the user's home directory.
|
||||||
|
|
|
@ -27,6 +27,9 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include <CoreServices/CoreServices.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "templates.h"
|
#include "templates.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
@ -1812,7 +1815,7 @@ FString G_BuildSaveName (const char *prefix, int slot)
|
||||||
leader = Args->CheckValue ("-savedir");
|
leader = Args->CheckValue ("-savedir");
|
||||||
if (leader.IsEmpty())
|
if (leader.IsEmpty())
|
||||||
{
|
{
|
||||||
#ifndef unix
|
#if !defined(unix) && !defined(__APPLE__)
|
||||||
if (Args->CheckParm ("-cdrom"))
|
if (Args->CheckParm ("-cdrom"))
|
||||||
{
|
{
|
||||||
leader = CDROM_DIR "/";
|
leader = CDROM_DIR "/";
|
||||||
|
@ -1827,6 +1830,18 @@ FString G_BuildSaveName (const char *prefix, int slot)
|
||||||
{
|
{
|
||||||
leader = "~/" GAME_DIR;
|
leader = "~/" GAME_DIR;
|
||||||
}
|
}
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
if (leader.IsEmpty())
|
||||||
|
{
|
||||||
|
char cpath[PATH_MAX];
|
||||||
|
FSRef folder;
|
||||||
|
|
||||||
|
if (noErr == FSFindFolder(kUserDomain, kDocumentsFolderType, kCreateFolder, &folder) &&
|
||||||
|
noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
|
||||||
|
{
|
||||||
|
leader << cpath << "/" GAME_DIR "/Savegames/";
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
size_t len = leader.Len();
|
size_t len = leader.Len();
|
||||||
|
|
|
@ -78,6 +78,9 @@ EXTERN_CVAR (Bool, wi_percents)
|
||||||
|
|
||||||
FGameConfigFile::FGameConfigFile ()
|
FGameConfigFile::FGameConfigFile ()
|
||||||
{
|
{
|
||||||
|
#ifdef __APPLE__
|
||||||
|
FString user_docs, user_app_support, local_app_support;
|
||||||
|
#endif
|
||||||
FString pathname;
|
FString pathname;
|
||||||
|
|
||||||
bMigrating = false;
|
bMigrating = false;
|
||||||
|
@ -102,11 +105,38 @@ FGameConfigFile::FGameConfigFile ()
|
||||||
SetSection ("IWADSearch.Directories", true);
|
SetSection ("IWADSearch.Directories", true);
|
||||||
SetValueForKey ("Path", ".", true);
|
SetValueForKey ("Path", ".", true);
|
||||||
SetValueForKey ("Path", "$DOOMWADDIR", true);
|
SetValueForKey ("Path", "$DOOMWADDIR", true);
|
||||||
#ifndef unix
|
#ifdef __APPLE__
|
||||||
|
char cpath[PATH_MAX];
|
||||||
|
FSRef folder;
|
||||||
|
|
||||||
|
if (noErr == FSFindFolder(kUserDomain, kDocumentsFolderType, kCreateFolder, &folder) &&
|
||||||
|
noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
|
||||||
|
{
|
||||||
|
user_docs << cpath << "/" GAME_DIR;
|
||||||
|
SetValueForKey("Path", user_docs, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetValueForKey("Path", "~/" GAME_DIR, true);
|
||||||
|
}
|
||||||
|
if (noErr == FSFindFolder(kUserDomain, kApplicationSupportFolderType, kCreateFolder, &folder) &&
|
||||||
|
noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
|
||||||
|
{
|
||||||
|
user_app_support << cpath << "/" GAME_DIR;
|
||||||
|
SetValueForKey("Path", user_app_support, true);
|
||||||
|
}
|
||||||
|
SetValueForKey ("Path", "$PROGDIR", true);
|
||||||
|
if (noErr == FSFindFolder(kLocalDomain, kApplicationSupportFolderType, kCreateFolder, &folder) &&
|
||||||
|
noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
|
||||||
|
{
|
||||||
|
local_app_support << cpath << "/" GAME_DIR;
|
||||||
|
SetValueForKey("Path", local_app_support, true);
|
||||||
|
}
|
||||||
|
#elif !defined(unix)
|
||||||
SetValueForKey ("Path", "$HOME", true);
|
SetValueForKey ("Path", "$HOME", true);
|
||||||
SetValueForKey ("Path", "$PROGDIR", true);
|
SetValueForKey ("Path", "$PROGDIR", true);
|
||||||
#else
|
#else
|
||||||
SetValueForKey ("Path", HOME_DIR, true);
|
SetValueForKey ("Path", "~/" GAME_DIR, true);
|
||||||
SetValueForKey ("Path", SHARE_DIR, true);
|
SetValueForKey ("Path", SHARE_DIR, true);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -115,7 +145,12 @@ FGameConfigFile::FGameConfigFile ()
|
||||||
if (!SetSection ("FileSearch.Directories"))
|
if (!SetSection ("FileSearch.Directories"))
|
||||||
{
|
{
|
||||||
SetSection ("FileSearch.Directories", true);
|
SetSection ("FileSearch.Directories", true);
|
||||||
#ifndef unix
|
#ifdef __APPLE__
|
||||||
|
SetValueForKey ("Path", user_docs, true);
|
||||||
|
SetValueForKey ("Path", user_app_support, true);
|
||||||
|
SetValueForKey ("Path", "$PROGDIR", true);
|
||||||
|
SetValueForKey ("Path", local_app_support, true);
|
||||||
|
#elif !defined(unix)
|
||||||
SetValueForKey ("Path", "$PROGDIR", true);
|
SetValueForKey ("Path", "$PROGDIR", true);
|
||||||
#else
|
#else
|
||||||
SetValueForKey ("Path", SHARE_DIR, true);
|
SetValueForKey ("Path", SHARE_DIR, true);
|
||||||
|
@ -576,7 +611,16 @@ void FGameConfigFile::CreateStandardAutoExec(const char *section, bool start)
|
||||||
if (!SetSection(section))
|
if (!SetSection(section))
|
||||||
{
|
{
|
||||||
FString path;
|
FString path;
|
||||||
#ifndef unix
|
#ifdef __APPLE__
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
#elif !defined(unix)
|
||||||
path = "$PROGDIR/autoexec.cfg";
|
path = "$PROGDIR/autoexec.cfg";
|
||||||
#else
|
#else
|
||||||
path = GetUserFile ("autoexec.cfg");
|
path = GetUserFile ("autoexec.cfg");
|
||||||
|
|
|
@ -31,6 +31,9 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include <CoreServices/CoreServices.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "doomtype.h"
|
#include "doomtype.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
@ -299,16 +302,9 @@ static long ParseCommandLine (const char *args, int *argc, char **argv)
|
||||||
|
|
||||||
|
|
||||||
#if defined(unix)
|
#if defined(unix)
|
||||||
FString GetUserFile (const char *file, bool nodir)
|
FString GetUserFile (const char *file)
|
||||||
{
|
{
|
||||||
FString path;
|
FString path;
|
||||||
|
|
||||||
if (nodir)
|
|
||||||
{
|
|
||||||
path = NicePath("~/");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
struct stat info;
|
struct stat info;
|
||||||
|
|
||||||
path = NicePath("~/" GAME_DIR "/");
|
path = NicePath("~/" GAME_DIR "/");
|
||||||
|
@ -327,7 +323,6 @@ FString GetUserFile (const char *file, bool nodir)
|
||||||
I_FatalError ("%s must be a directory", path.GetChars());
|
I_FatalError ("%s must be a directory", path.GetChars());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
path += file;
|
path += file;
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
@ -638,7 +633,7 @@ void M_ScreenShot (const char *filename)
|
||||||
// find a file name to save it to
|
// find a file name to save it to
|
||||||
if (filename == NULL || filename[0] == '\0')
|
if (filename == NULL || filename[0] == '\0')
|
||||||
{
|
{
|
||||||
#ifndef unix
|
#if !defined(unix) && !defined(__APPLE__)
|
||||||
if (Args->CheckParm ("-cdrom"))
|
if (Args->CheckParm ("-cdrom"))
|
||||||
{
|
{
|
||||||
autoname = CDROM_DIR "\\";
|
autoname = CDROM_DIR "\\";
|
||||||
|
@ -652,11 +647,24 @@ void M_ScreenShot (const char *filename)
|
||||||
{
|
{
|
||||||
autoname = screenshot_dir;
|
autoname = screenshot_dir;
|
||||||
}
|
}
|
||||||
dirlen = strlen(autoname);
|
dirlen = autoname.Len();
|
||||||
if (dirlen == 0)
|
if (dirlen == 0)
|
||||||
{
|
{
|
||||||
#ifdef unix
|
#ifdef unix
|
||||||
autoname = "~/.zdoom/screenshots/";
|
autoname = "~/.zdoom/screenshots/";
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
char cpath[PATH_MAX];
|
||||||
|
FSRef folder;
|
||||||
|
|
||||||
|
if (noErr == FSFindFolder(kUserDomain, kDocumentsFolderType, kCreateFolder, &folder) &&
|
||||||
|
noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
|
||||||
|
{
|
||||||
|
autoname << cpath << "/" GAME_DIR "/Screenshots/";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
autoname = "~";
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
autoname = progdir;
|
autoname = progdir;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -43,6 +43,7 @@ void M_LoadDefaults ();
|
||||||
bool M_SaveDefaults (const char *filename);
|
bool M_SaveDefaults (const char *filename);
|
||||||
void M_SaveCustomKeys (FConfigFile *config, char *section, char *subsection, size_t sublen);
|
void M_SaveCustomKeys (FConfigFile *config, char *section, char *subsection, size_t sublen);
|
||||||
|
|
||||||
FString GetUserFile (const char *path, bool nodir=false);
|
// Prepends ~/.zdoom to path
|
||||||
|
FString GetUserFile (const char *path);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -112,8 +112,9 @@ static inline const char *MakeSaveSig()
|
||||||
#define BUGS_FORUM_URL "http://forum.zdoom.org/index.php?c=3"
|
#define BUGS_FORUM_URL "http://forum.zdoom.org/index.php?c=3"
|
||||||
|
|
||||||
#ifdef unix
|
#ifdef unix
|
||||||
#define HOME_DIR "~/.zdoom"
|
|
||||||
#define GAME_DIR ".zdoom"
|
#define GAME_DIR ".zdoom"
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
#define GAME_DIR GAMENAME
|
||||||
#else
|
#else
|
||||||
#define CDROM_DIR "C:\\ZDOOMDAT"
|
#define CDROM_DIR "C:\\ZDOOMDAT"
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue