- 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:
Randy Heit 2009-09-09 17:12:47 +00:00
parent 12576d2eb5
commit 66920536d9
9 changed files with 119 additions and 100 deletions

View file

@ -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
- 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

View file

@ -512,12 +512,17 @@ void CreatePath(const char *fn)
{
*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)
{ // failed
return;
}
if (p != NULL)
exists: if (p != NULL)
{
*p = '/';
}

View file

@ -396,34 +396,6 @@ static int CheckIWAD (const char *doomwaddir, WadStuff *wads)
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
@ -484,21 +456,10 @@ static EIWADType IdentifyVersion (const char *zdoom_wad)
{
if (stricmp (key, "Path") == 0)
{
if (strchr (value, '$') != NULL)
{
CheckIWADinEnvDir (value, 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);
}
FString nice = NicePath(value);
FixPathSeperator(nice.LockBuffer());
nice.UnlockBuffer();
CheckIWAD(nice, wads);
}
}
}

View file

@ -1426,34 +1426,12 @@ static const char *BaseFileSearch (const char *file, const char *ext, bool lookf
{
if (stricmp (key, "Path") == 0)
{
const char *dir;
FString homepath;
FString dir;
if (*value == '$')
dir = NicePath(value);
if (dir.IsNotEmpty())
{
if (stricmp (value + 1, "progdir") == 0)
{
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);
mysnprintf (wad, countof(wad), "%s%s%s", dir.GetChars(), dir[dir.Len() - 1] != '/' ? "/" : "", file);
if (DirEntryExists (wad))
{
return wad;
@ -1862,7 +1840,7 @@ void D_DoomMain (void)
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
// that would go to c:\\zdoomdat are already stored in .zdoom inside
// the user's home directory.

View file

@ -27,6 +27,9 @@
#include <stdio.h>
#include <stddef.h>
#include <time.h>
#ifdef __APPLE__
#include <CoreServices/CoreServices.h>
#endif
#include "templates.h"
#include "version.h"
@ -1812,7 +1815,7 @@ FString G_BuildSaveName (const char *prefix, int slot)
leader = Args->CheckValue ("-savedir");
if (leader.IsEmpty())
{
#ifndef unix
#if !defined(unix) && !defined(__APPLE__)
if (Args->CheckParm ("-cdrom"))
{
leader = CDROM_DIR "/";
@ -1827,6 +1830,18 @@ FString G_BuildSaveName (const char *prefix, int slot)
{
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
}
size_t len = leader.Len();

View file

@ -78,6 +78,9 @@ EXTERN_CVAR (Bool, wi_percents)
FGameConfigFile::FGameConfigFile ()
{
#ifdef __APPLE__
FString user_docs, user_app_support, local_app_support;
#endif
FString pathname;
bMigrating = false;
@ -102,11 +105,38 @@ FGameConfigFile::FGameConfigFile ()
SetSection ("IWADSearch.Directories", true);
SetValueForKey ("Path", ".", 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", "$PROGDIR", true);
#else
SetValueForKey ("Path", HOME_DIR, true);
SetValueForKey ("Path", "~/" GAME_DIR, true);
SetValueForKey ("Path", SHARE_DIR, true);
#endif
}
@ -115,7 +145,12 @@ FGameConfigFile::FGameConfigFile ()
if (!SetSection ("FileSearch.Directories"))
{
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);
#else
SetValueForKey ("Path", SHARE_DIR, true);
@ -576,7 +611,16 @@ void FGameConfigFile::CreateStandardAutoExec(const char *section, bool start)
if (!SetSection(section))
{
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";
#else
path = GetUserFile ("autoexec.cfg");

View file

@ -31,6 +31,9 @@
#include <errno.h>
#include <stdlib.h>
#include <time.h>
#ifdef __APPLE__
#include <CoreServices/CoreServices.h>
#endif
#include "doomtype.h"
#include "version.h"
@ -299,16 +302,9 @@ static long ParseCommandLine (const char *args, int *argc, char **argv)
#if defined(unix)
FString GetUserFile (const char *file, bool nodir)
FString GetUserFile (const char *file)
{
FString path;
if (nodir)
{
path = NicePath("~/");
}
else
{
struct stat info;
path = NicePath("~/" GAME_DIR "/");
@ -327,7 +323,6 @@ FString GetUserFile (const char *file, bool nodir)
I_FatalError ("%s must be a directory", path.GetChars());
}
}
}
path += file;
return path;
}
@ -638,7 +633,7 @@ void M_ScreenShot (const char *filename)
// find a file name to save it to
if (filename == NULL || filename[0] == '\0')
{
#ifndef unix
#if !defined(unix) && !defined(__APPLE__)
if (Args->CheckParm ("-cdrom"))
{
autoname = CDROM_DIR "\\";
@ -652,11 +647,24 @@ void M_ScreenShot (const char *filename)
{
autoname = screenshot_dir;
}
dirlen = strlen(autoname);
dirlen = autoname.Len();
if (dirlen == 0)
{
#ifdef unix
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
autoname = progdir;
#endif

View file

@ -43,6 +43,7 @@ void M_LoadDefaults ();
bool M_SaveDefaults (const char *filename);
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

View file

@ -112,8 +112,9 @@ static inline const char *MakeSaveSig()
#define BUGS_FORUM_URL "http://forum.zdoom.org/index.php?c=3"
#ifdef unix
#define HOME_DIR "~/.zdoom"
#define GAME_DIR ".zdoom"
#elif defined(__APPLE__)
#define GAME_DIR GAMENAME
#else
#define CDROM_DIR "C:\\ZDOOMDAT"
#endif