2013-09-01 14:27:21 +00:00
|
|
|
/*
|
|
|
|
** filesystem.cpp
|
|
|
|
**
|
|
|
|
** This file is part of mkxp.
|
|
|
|
**
|
|
|
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
|
|
**
|
|
|
|
** mkxp is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 2 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** mkxp is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "filesystem.h"
|
|
|
|
|
2014-07-23 20:57:39 +00:00
|
|
|
#include "rgssad.h"
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
#include "font.h"
|
2013-09-01 14:27:21 +00:00
|
|
|
#include "util.h"
|
|
|
|
#include "exception.h"
|
2014-08-29 01:33:46 +00:00
|
|
|
#include "sharedstate.h"
|
2013-12-11 19:46:54 +00:00
|
|
|
#include "boost-hash.h"
|
|
|
|
#include "debugwriter.h"
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2013-12-04 16:48:37 +00:00
|
|
|
#include <physfs.h>
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2013-11-30 11:00:11 +00:00
|
|
|
#include <SDL_sound.h>
|
|
|
|
|
2013-12-04 16:48:37 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2013-12-08 12:19:22 +00:00
|
|
|
#include <algorithm>
|
2013-12-26 19:18:33 +00:00
|
|
|
#include <vector>
|
2015-07-09 11:00:56 +00:00
|
|
|
#include <stack>
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2014-08-19 14:57:03 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <iconv.h>
|
|
|
|
#endif
|
|
|
|
|
2015-01-02 13:50:14 +00:00
|
|
|
struct SDLRWIoContext
|
|
|
|
{
|
|
|
|
SDL_RWops *ops;
|
|
|
|
std::string filename;
|
|
|
|
|
|
|
|
SDLRWIoContext(const char *filename)
|
|
|
|
: ops(SDL_RWFromFile(filename, "r")),
|
|
|
|
filename(filename)
|
|
|
|
{
|
|
|
|
if (!ops)
|
|
|
|
throw Exception(Exception::SDLError,
|
|
|
|
"Failed to open file: %s", SDL_GetError());
|
|
|
|
}
|
|
|
|
|
|
|
|
~SDLRWIoContext()
|
|
|
|
{
|
|
|
|
SDL_RWclose(ops);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static PHYSFS_Io *createSDLRWIo(const char *filename);
|
|
|
|
|
|
|
|
static SDL_RWops *getSDLRWops(PHYSFS_Io *io)
|
|
|
|
{
|
|
|
|
return static_cast<SDLRWIoContext*>(io->opaque)->ops;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PHYSFS_sint64 SDLRWIoRead(struct PHYSFS_Io *io, void *buf, PHYSFS_uint64 len)
|
|
|
|
{
|
|
|
|
return SDL_RWread(getSDLRWops(io), buf, 1, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int SDLRWIoSeek(struct PHYSFS_Io *io, PHYSFS_uint64 offset)
|
|
|
|
{
|
|
|
|
return (SDL_RWseek(getSDLRWops(io), offset, RW_SEEK_SET) != -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PHYSFS_sint64 SDLRWIoTell(struct PHYSFS_Io *io)
|
|
|
|
{
|
|
|
|
return SDL_RWseek(getSDLRWops(io), 0, RW_SEEK_CUR);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PHYSFS_sint64 SDLRWIoLength(struct PHYSFS_Io *io)
|
|
|
|
{
|
|
|
|
return SDL_RWsize(getSDLRWops(io));
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct PHYSFS_Io *SDLRWIoDuplicate(struct PHYSFS_Io *io)
|
|
|
|
{
|
|
|
|
SDLRWIoContext *ctx = static_cast<SDLRWIoContext*>(io->opaque);
|
|
|
|
int64_t offset = io->tell(io);
|
|
|
|
PHYSFS_Io *dup = createSDLRWIo(ctx->filename.c_str());
|
|
|
|
|
|
|
|
if (dup)
|
|
|
|
SDLRWIoSeek(dup, offset);
|
|
|
|
|
|
|
|
return dup;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SDLRWIoDestroy(struct PHYSFS_Io *io)
|
|
|
|
{
|
|
|
|
delete static_cast<SDLRWIoContext*>(io->opaque);
|
|
|
|
delete io;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PHYSFS_Io SDLRWIoTemplate =
|
|
|
|
{
|
|
|
|
0, 0, /* version, opaque */
|
|
|
|
SDLRWIoRead,
|
|
|
|
0, /* write */
|
|
|
|
SDLRWIoSeek,
|
|
|
|
SDLRWIoTell,
|
|
|
|
SDLRWIoLength,
|
|
|
|
SDLRWIoDuplicate,
|
|
|
|
0, /* flush */
|
|
|
|
SDLRWIoDestroy
|
|
|
|
};
|
|
|
|
|
|
|
|
static PHYSFS_Io *createSDLRWIo(const char *filename)
|
|
|
|
{
|
|
|
|
SDLRWIoContext *ctx;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
ctx = new SDLRWIoContext(filename);
|
|
|
|
}
|
|
|
|
catch (const Exception &e)
|
|
|
|
{
|
|
|
|
Debug() << "Failed mounting" << filename;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
PHYSFS_Io *io = new PHYSFS_Io;
|
|
|
|
*io = SDLRWIoTemplate;
|
|
|
|
io->opaque = ctx;
|
|
|
|
|
|
|
|
return io;
|
|
|
|
}
|
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
static inline PHYSFS_File *sdlPHYS(SDL_RWops *ops)
|
|
|
|
{
|
|
|
|
return static_cast<PHYSFS_File*>(ops->hidden.unknown.data1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Sint64 SDL_RWopsSize(SDL_RWops *ops)
|
|
|
|
{
|
|
|
|
PHYSFS_File *f = sdlPHYS(ops);
|
|
|
|
|
|
|
|
if (!f)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return PHYSFS_fileLength(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Sint64 SDL_RWopsSeek(SDL_RWops *ops, int64_t offset, int whence)
|
|
|
|
{
|
|
|
|
PHYSFS_File *f = sdlPHYS(ops);
|
|
|
|
|
|
|
|
if (!f)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
int64_t base;
|
|
|
|
|
|
|
|
switch (whence)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case RW_SEEK_SET :
|
|
|
|
base = 0;
|
|
|
|
break;
|
|
|
|
case RW_SEEK_CUR :
|
|
|
|
base = PHYSFS_tell(f);
|
|
|
|
break;
|
|
|
|
case RW_SEEK_END :
|
|
|
|
base = PHYSFS_fileLength(f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
int result = PHYSFS_seek(f, base + offset);
|
|
|
|
|
|
|
|
return (result != 0) ? PHYSFS_tell(f) : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t SDL_RWopsRead(SDL_RWops *ops, void *buffer, size_t size, size_t maxnum)
|
|
|
|
{
|
|
|
|
PHYSFS_File *f = sdlPHYS(ops);
|
|
|
|
|
|
|
|
if (!f)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
PHYSFS_sint64 result = PHYSFS_readBytes(f, buffer, size*maxnum);
|
|
|
|
|
|
|
|
return (result != -1) ? (result / size) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t SDL_RWopsWrite(SDL_RWops *ops, const void *buffer, size_t size, size_t num)
|
|
|
|
{
|
|
|
|
PHYSFS_File *f = sdlPHYS(ops);
|
|
|
|
|
|
|
|
if (!f)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
PHYSFS_sint64 result = PHYSFS_writeBytes(f, buffer, size*num);
|
|
|
|
|
|
|
|
return (result != -1) ? (result / size) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int SDL_RWopsClose(SDL_RWops *ops)
|
|
|
|
{
|
|
|
|
PHYSFS_File *f = sdlPHYS(ops);
|
|
|
|
|
|
|
|
if (!f)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
int result = PHYSFS_close(f);
|
2014-09-23 15:26:30 +00:00
|
|
|
ops->hidden.unknown.data1 = 0;
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
|
|
|
|
return (result != 0) ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int SDL_RWopsCloseFree(SDL_RWops *ops)
|
|
|
|
{
|
|
|
|
int result = SDL_RWopsClose(ops);
|
|
|
|
|
|
|
|
SDL_FreeRW(ops);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-02-17 00:42:11 +00:00
|
|
|
/* Copies the first srcN characters from src into dst,
|
|
|
|
* or the full string if srcN == -1. Never writes more
|
|
|
|
* than dstMax, and guarantees dst to be null terminated.
|
|
|
|
* Returns copied bytes (minus terminating null) */
|
|
|
|
static size_t
|
|
|
|
strcpySafe(char *dst, const char *src,
|
|
|
|
size_t dstMax, int srcN)
|
|
|
|
{
|
|
|
|
if (srcN < 0)
|
|
|
|
srcN = strlen(src);
|
|
|
|
|
|
|
|
size_t cpyMax = std::min<size_t>(dstMax-1, srcN);
|
|
|
|
|
|
|
|
memcpy(dst, src, cpyMax);
|
|
|
|
dst[cpyMax] = '\0';
|
|
|
|
|
|
|
|
return cpyMax;
|
|
|
|
}
|
|
|
|
|
2015-07-09 11:00:56 +00:00
|
|
|
/* Attempt to locate an extension string in a filename.
|
|
|
|
* Either a pointer into the input string pointing at the
|
|
|
|
* extension, or null is returned */
|
|
|
|
static const char *
|
|
|
|
findExt(const char *filename)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2015-07-09 11:00:56 +00:00
|
|
|
size_t len;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2015-07-09 11:00:56 +00:00
|
|
|
for (len = strlen(filename); len > 0; --len)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2015-07-09 11:00:56 +00:00
|
|
|
if (filename[len] == '/')
|
|
|
|
return 0;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2015-07-09 11:00:56 +00:00
|
|
|
if (filename[len] == '.')
|
|
|
|
return &filename[len+1];
|
2013-11-30 11:00:11 +00:00
|
|
|
}
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2015-07-09 11:00:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-01-16 03:19:22 +00:00
|
|
|
|
2015-07-09 11:00:56 +00:00
|
|
|
static void
|
|
|
|
initReadOps(PHYSFS_File *handle,
|
|
|
|
SDL_RWops &ops,
|
|
|
|
bool freeOnClose)
|
|
|
|
{
|
|
|
|
ops.size = SDL_RWopsSize;
|
|
|
|
ops.seek = SDL_RWopsSeek;
|
|
|
|
ops.read = SDL_RWopsRead;
|
|
|
|
ops.write = SDL_RWopsWrite;
|
2013-09-30 19:19:43 +00:00
|
|
|
|
2015-07-09 11:00:56 +00:00
|
|
|
if (freeOnClose)
|
|
|
|
ops.close = SDL_RWopsCloseFree;
|
|
|
|
else
|
|
|
|
ops.close = SDL_RWopsClose;
|
2015-02-17 00:42:11 +00:00
|
|
|
|
2015-07-09 11:00:56 +00:00
|
|
|
ops.type = SDL_RWOPS_PHYSFS;
|
|
|
|
ops.hidden.unknown.data1 = handle;
|
|
|
|
}
|
2015-02-17 00:42:11 +00:00
|
|
|
|
2015-07-09 11:00:56 +00:00
|
|
|
static void strTolower(std::string &str)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < str.size(); ++i)
|
|
|
|
str[i] = tolower(str[i]);
|
|
|
|
}
|
2015-02-17 00:42:11 +00:00
|
|
|
|
2015-07-09 11:00:56 +00:00
|
|
|
const Uint32 SDL_RWOPS_PHYSFS = SDL_RWOPS_UNKNOWN+10;
|
2015-02-17 00:42:11 +00:00
|
|
|
|
2015-07-09 11:00:56 +00:00
|
|
|
struct FileSystemPrivate
|
|
|
|
{
|
|
|
|
/* Maps: lower case full filepath,
|
|
|
|
* To: mixed case full filepath */
|
|
|
|
BoostHash<std::string, std::string> pathCache;
|
|
|
|
/* Maps: lower case directory path,
|
|
|
|
* To: list of lower case filenames */
|
|
|
|
BoostHash<std::string, std::vector<std::string> > fileLists;
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
|
2015-07-09 11:00:56 +00:00
|
|
|
/* This is for compatibility with games that take Windows'
|
|
|
|
* case insensitivity for granted */
|
|
|
|
bool havePathCache;
|
2013-09-30 19:19:43 +00:00
|
|
|
};
|
|
|
|
|
2013-10-20 20:38:46 +00:00
|
|
|
FileSystem::FileSystem(const char *argv0,
|
|
|
|
bool allowSymlinks)
|
2013-09-30 19:19:43 +00:00
|
|
|
{
|
|
|
|
p = new FileSystemPrivate;
|
2014-01-01 06:07:18 +00:00
|
|
|
p->havePathCache = false;
|
|
|
|
|
2013-09-30 19:19:43 +00:00
|
|
|
PHYSFS_init(argv0);
|
2014-07-23 21:05:24 +00:00
|
|
|
|
|
|
|
PHYSFS_registerArchiver(&RGSS1_Archiver);
|
|
|
|
PHYSFS_registerArchiver(&RGSS2_Archiver);
|
2014-07-23 22:43:04 +00:00
|
|
|
PHYSFS_registerArchiver(&RGSS3_Archiver);
|
2013-10-20 20:38:46 +00:00
|
|
|
|
|
|
|
if (allowSymlinks)
|
|
|
|
PHYSFS_permitSymbolicLinks(1);
|
2013-09-30 19:19:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FileSystem::~FileSystem()
|
|
|
|
{
|
|
|
|
delete p;
|
|
|
|
|
|
|
|
if (PHYSFS_deinit() == 0)
|
2013-12-11 19:46:54 +00:00
|
|
|
Debug() << "PhyFS failed to deinit.";
|
2013-09-30 19:19:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileSystem::addPath(const char *path)
|
|
|
|
{
|
2015-01-02 13:50:14 +00:00
|
|
|
/* Try the normal mount first */
|
|
|
|
if (!PHYSFS_mount(path, 0, 1))
|
|
|
|
{
|
|
|
|
/* If it didn't work, try mounting via a wrapped
|
|
|
|
* SDL_RWops */
|
|
|
|
PHYSFS_Io *io = createSDLRWIo(path);
|
|
|
|
|
|
|
|
if (io)
|
|
|
|
PHYSFS_mountIo(io, path, 0, 1);
|
|
|
|
}
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
2015-07-09 11:00:56 +00:00
|
|
|
struct CacheEnumData
|
2014-08-19 14:57:03 +00:00
|
|
|
{
|
|
|
|
FileSystemPrivate *p;
|
2015-07-09 11:00:56 +00:00
|
|
|
std::stack<std::vector<std::string>*> fileLists;
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
2014-08-19 14:57:03 +00:00
|
|
|
iconv_t nfd2nfc;
|
2015-07-09 11:00:56 +00:00
|
|
|
char buf[512];
|
|
|
|
#endif
|
2014-08-19 14:57:03 +00:00
|
|
|
|
2015-07-09 11:00:56 +00:00
|
|
|
CacheEnumData(FileSystemPrivate *p)
|
|
|
|
: p(p)
|
2014-08-19 14:57:03 +00:00
|
|
|
{
|
2015-07-09 11:00:56 +00:00
|
|
|
#ifdef __APPLE__
|
2014-08-19 14:57:03 +00:00
|
|
|
nfd2nfc = iconv_open("utf-8", "utf-8-mac");
|
2015-07-09 11:00:56 +00:00
|
|
|
#endif
|
2014-08-19 14:57:03 +00:00
|
|
|
}
|
|
|
|
|
2015-07-09 11:00:56 +00:00
|
|
|
~CacheEnumData()
|
2014-08-19 14:57:03 +00:00
|
|
|
{
|
2015-07-09 11:00:56 +00:00
|
|
|
#ifdef __APPLE__
|
2014-08-19 14:57:03 +00:00
|
|
|
iconv_close(nfd2nfc);
|
2015-07-09 11:00:56 +00:00
|
|
|
#endif
|
2014-08-19 14:57:03 +00:00
|
|
|
}
|
|
|
|
|
2015-07-09 11:00:56 +00:00
|
|
|
/* Converts in-place */
|
|
|
|
void toNFC(char *inout)
|
2014-08-19 14:57:03 +00:00
|
|
|
{
|
2015-07-09 11:00:56 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
size_t srcSize = strlen(inout);
|
|
|
|
size_t bufSize = sizeof(buf);
|
|
|
|
char *bufPtr = buf;
|
|
|
|
char *inoutPtr = inout;
|
|
|
|
|
2014-08-19 14:57:03 +00:00
|
|
|
/* Reserve room for null terminator */
|
2015-07-09 11:00:56 +00:00
|
|
|
--bufSize;
|
|
|
|
|
2014-08-19 14:57:03 +00:00
|
|
|
iconv(nfd2nfc,
|
2015-07-09 11:00:56 +00:00
|
|
|
&inoutPtr, &srcSize,
|
|
|
|
&bufPtr, &bufSize);
|
2014-08-19 14:57:03 +00:00
|
|
|
/* Null-terminate */
|
2015-07-09 11:00:56 +00:00
|
|
|
*bufPtr = 0;
|
|
|
|
strcpy(inout, buf);
|
|
|
|
#else
|
|
|
|
(void) inout;
|
|
|
|
#endif
|
2014-08-19 14:57:03 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-10-08 21:11:18 +00:00
|
|
|
static PHYSFS_EnumerateCallbackResult
|
|
|
|
cacheEnumCB(void *d, const char *origdir, const char *fname)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2015-07-09 11:00:56 +00:00
|
|
|
CacheEnumData &data = *static_cast<CacheEnumData*>(d);
|
|
|
|
char fullPath[512];
|
2013-09-30 19:19:43 +00:00
|
|
|
|
2015-07-09 11:00:56 +00:00
|
|
|
if (!*origdir)
|
|
|
|
snprintf(fullPath, sizeof(fullPath), "%s", fname);
|
2014-01-15 00:51:56 +00:00
|
|
|
else
|
2015-07-09 11:00:56 +00:00
|
|
|
snprintf(fullPath, sizeof(fullPath), "%s/%s", origdir, fname);
|
2014-01-15 00:51:56 +00:00
|
|
|
|
2015-07-09 11:00:56 +00:00
|
|
|
/* Deal with OSX' weird UTF-8 standards */
|
|
|
|
data.toNFC(fullPath);
|
2013-09-30 19:19:43 +00:00
|
|
|
|
2015-07-09 11:00:56 +00:00
|
|
|
std::string mixedCase(fullPath);
|
|
|
|
std::string lowerCase = mixedCase;
|
|
|
|
strTolower(lowerCase);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2015-07-09 11:00:56 +00:00
|
|
|
PHYSFS_Stat stat;
|
|
|
|
PHYSFS_stat(fullPath, &stat);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2015-07-09 11:00:56 +00:00
|
|
|
if (stat.filetype == PHYSFS_FILETYPE_DIRECTORY)
|
2015-02-17 00:42:11 +00:00
|
|
|
{
|
2015-07-09 11:00:56 +00:00
|
|
|
/* Create a new list for this directory */
|
|
|
|
std::vector<std::string> &list = data.p->fileLists[lowerCase];
|
2015-02-17 00:42:11 +00:00
|
|
|
|
2015-07-09 11:00:56 +00:00
|
|
|
/* Iterate over its contents */
|
|
|
|
data.fileLists.push(&list);
|
2017-10-08 21:11:18 +00:00
|
|
|
PHYSFS_enumerate(fullPath, cacheEnumCB, d);
|
2015-07-09 11:00:56 +00:00
|
|
|
data.fileLists.pop();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Get the file list for the directory we're currently
|
|
|
|
* traversing and append this filename to it */
|
|
|
|
std::vector<std::string> &list = *data.fileLists.top();
|
|
|
|
std::string lowerFilename(fname);
|
|
|
|
strTolower(lowerFilename);
|
|
|
|
list.push_back(lowerFilename);
|
|
|
|
|
|
|
|
/* Add the lower -> mixed mapping of the file's full path */
|
|
|
|
data.p->pathCache.insert(lowerCase, mixedCase);
|
2015-02-17 00:42:11 +00:00
|
|
|
}
|
2017-10-08 21:11:18 +00:00
|
|
|
|
|
|
|
return PHYSFS_ENUM_OK;
|
2013-09-30 19:19:43 +00:00
|
|
|
}
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2013-09-30 19:19:43 +00:00
|
|
|
void FileSystem::createPathCache()
|
|
|
|
{
|
2015-07-09 11:00:56 +00:00
|
|
|
CacheEnumData data(p);
|
|
|
|
data.fileLists.push(&p->fileLists[""]);
|
2017-10-08 21:11:18 +00:00
|
|
|
PHYSFS_enumerate("", cacheEnumCB, &data);
|
2014-01-01 06:07:18 +00:00
|
|
|
|
|
|
|
p->havePathCache = true;
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
struct FontSetsCBData
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
FileSystemPrivate *p;
|
|
|
|
SharedFontState *sfs;
|
|
|
|
};
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2017-10-08 21:11:18 +00:00
|
|
|
static PHYSFS_EnumerateCallbackResult
|
|
|
|
fontSetEnumCB (void *data, const char *dir, const char *fname)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
FontSetsCBData *d = static_cast<FontSetsCBData*>(data);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
/* Only consider filenames with font extensions */
|
2015-07-09 11:00:56 +00:00
|
|
|
const char *ext = findExt(fname);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
if (!ext)
|
2018-10-07 20:07:58 +00:00
|
|
|
return PHYSFS_ENUM_OK;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2015-02-17 00:42:11 +00:00
|
|
|
char lowExt[8];
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(lowExt)-1 && ext[i]; ++i)
|
|
|
|
lowExt[i] = tolower(ext[i]);
|
|
|
|
lowExt[i] = '\0';
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2015-02-17 00:42:11 +00:00
|
|
|
if (strcmp(lowExt, "ttf") && strcmp(lowExt, "otf"))
|
2018-10-07 20:07:58 +00:00
|
|
|
return PHYSFS_ENUM_OK;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2015-02-17 00:42:11 +00:00
|
|
|
char filename[512];
|
2017-03-08 15:30:07 +00:00
|
|
|
snprintf(filename, sizeof(filename), "%s/%s", dir, fname);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2015-02-17 00:42:11 +00:00
|
|
|
PHYSFS_File *handle = PHYSFS_openRead(filename);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
if (!handle)
|
2017-10-08 21:11:18 +00:00
|
|
|
return PHYSFS_ENUM_ERROR;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
SDL_RWops ops;
|
2015-07-09 11:00:56 +00:00
|
|
|
initReadOps(handle, ops, false);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
d->sfs->initFontSetCB(ops, filename);
|
2013-09-04 11:32:11 +00:00
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
SDL_RWclose(&ops);
|
2017-10-08 21:11:18 +00:00
|
|
|
|
|
|
|
return PHYSFS_ENUM_OK;
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
2017-03-08 15:30:07 +00:00
|
|
|
/* Basically just a case-insensitive search
|
|
|
|
* for the folder "Fonts"... */
|
2017-10-08 21:11:18 +00:00
|
|
|
static PHYSFS_EnumerateCallbackResult
|
|
|
|
findFontsFolderCB(void *data, const char *, const char *fname)
|
2017-03-08 15:30:07 +00:00
|
|
|
{
|
|
|
|
size_t i = 0;
|
|
|
|
char buffer[512];
|
|
|
|
const char *s = fname;
|
|
|
|
|
2018-01-22 09:54:21 +00:00
|
|
|
while (*s && i < sizeof(buffer))
|
2017-03-08 15:30:07 +00:00
|
|
|
buffer[i++] = tolower(*s++);
|
|
|
|
|
|
|
|
buffer[i] = '\0';
|
|
|
|
|
|
|
|
if (strcmp(buffer, "fonts") == 0)
|
2017-10-08 21:11:18 +00:00
|
|
|
PHYSFS_enumerate(fname, fontSetEnumCB, data);
|
|
|
|
|
|
|
|
return PHYSFS_ENUM_OK;
|
2017-03-08 15:30:07 +00:00
|
|
|
}
|
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
void FileSystem::initFontSets(SharedFontState &sfs)
|
2013-09-10 02:18:58 +00:00
|
|
|
{
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
FontSetsCBData d = { p, &sfs };
|
2013-09-10 02:18:58 +00:00
|
|
|
|
2017-12-12 21:45:01 +00:00
|
|
|
PHYSFS_enumerate("", findFontsFolderCB, &d);
|
2013-09-10 02:18:58 +00:00
|
|
|
}
|
|
|
|
|
2015-07-09 11:00:56 +00:00
|
|
|
struct OpenReadEnumData
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2015-07-09 11:00:56 +00:00
|
|
|
FileSystem::OpenHandler &handler;
|
|
|
|
SDL_RWops ops;
|
|
|
|
|
|
|
|
/* The filename (without directory) we're looking for */
|
|
|
|
const char *filename;
|
|
|
|
size_t filenameN;
|
|
|
|
|
|
|
|
/* Optional hash to translate full filepaths
|
|
|
|
* (used with path cache) */
|
|
|
|
BoostHash<std::string, std::string> *pathTrans;
|
|
|
|
|
|
|
|
/* Number of files we've attempted to read and parse */
|
|
|
|
size_t matchCount;
|
|
|
|
bool stopSearching;
|
|
|
|
|
|
|
|
/* In case of a PhysFS error, save it here so it
|
|
|
|
* doesn't get changed before we get back into our code */
|
|
|
|
const char *physfsError;
|
|
|
|
|
|
|
|
OpenReadEnumData(FileSystem::OpenHandler &handler,
|
|
|
|
const char *filename, size_t filenameN,
|
|
|
|
BoostHash<std::string, std::string> *pathTrans)
|
|
|
|
: handler(handler), filename(filename), filenameN(filenameN),
|
|
|
|
pathTrans(pathTrans), matchCount(0), stopSearching(false),
|
|
|
|
physfsError(0)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2017-10-08 21:11:18 +00:00
|
|
|
static PHYSFS_EnumerateCallbackResult
|
|
|
|
openReadEnumCB(void *d, const char *dirpath, const char *filename)
|
2015-07-09 11:00:56 +00:00
|
|
|
{
|
|
|
|
OpenReadEnumData &data = *static_cast<OpenReadEnumData*>(d);
|
|
|
|
char buffer[512];
|
|
|
|
const char *fullPath;
|
|
|
|
|
|
|
|
if (data.stopSearching)
|
2017-10-08 21:11:18 +00:00
|
|
|
return PHYSFS_ENUM_STOP;
|
2015-07-09 11:00:56 +00:00
|
|
|
|
|
|
|
/* If there's not even a partial match, continue searching */
|
|
|
|
if (strncmp(filename, data.filename, data.filenameN) != 0)
|
2017-10-08 21:11:18 +00:00
|
|
|
return PHYSFS_ENUM_OK;
|
2015-07-09 11:00:56 +00:00
|
|
|
|
|
|
|
if (!*dirpath)
|
|
|
|
{
|
|
|
|
fullPath = filename;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
snprintf(buffer, sizeof(buffer), "%s/%s", dirpath, filename);
|
|
|
|
fullPath = buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
char last = filename[data.filenameN];
|
|
|
|
|
|
|
|
/* If fname matches up to a following '.' (meaning the rest is part
|
|
|
|
* of the extension), or up to a following '\0' (full match), we've
|
|
|
|
* found our file */
|
|
|
|
if (last != '.' && last != '\0')
|
2017-10-08 21:11:18 +00:00
|
|
|
return PHYSFS_ENUM_STOP;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2015-07-09 11:00:56 +00:00
|
|
|
/* If the path cache is active, translate from lower case
|
|
|
|
* to mixed case path */
|
|
|
|
if (data.pathTrans)
|
|
|
|
fullPath = (*data.pathTrans)[fullPath].c_str();
|
|
|
|
|
|
|
|
PHYSFS_File *phys = PHYSFS_openRead(fullPath);
|
|
|
|
|
|
|
|
if (!phys)
|
|
|
|
{
|
|
|
|
/* Failing to open this file here means there must
|
|
|
|
* be a deeper rooted problem somewhere within PhysFS.
|
|
|
|
* Just abort alltogether. */
|
|
|
|
data.stopSearching = true;
|
2017-10-08 21:11:18 +00:00
|
|
|
data.physfsError = PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode());
|
2015-07-09 11:00:56 +00:00
|
|
|
|
2017-10-08 21:11:18 +00:00
|
|
|
return PHYSFS_ENUM_ERROR;
|
2015-07-09 11:00:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
initReadOps(phys, data.ops, false);
|
|
|
|
|
|
|
|
const char *ext = findExt(filename);
|
|
|
|
|
|
|
|
if (data.handler.tryRead(data.ops, ext))
|
|
|
|
data.stopSearching = true;
|
|
|
|
|
|
|
|
++data.matchCount;
|
2017-10-08 21:11:18 +00:00
|
|
|
return PHYSFS_ENUM_OK;
|
2015-07-09 11:00:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileSystem::openRead(OpenHandler &handler, const char *filename)
|
|
|
|
{
|
|
|
|
char buffer[512];
|
|
|
|
size_t len = strcpySafe(buffer, filename, sizeof(buffer), -1);
|
|
|
|
char *delim;
|
|
|
|
|
|
|
|
if (p->havePathCache)
|
|
|
|
for (size_t i = 0; i < len; ++i)
|
|
|
|
buffer[i] = tolower(buffer[i]);
|
|
|
|
|
|
|
|
/* Find the deliminator separating directory and file name */
|
|
|
|
for (delim = buffer + len; delim > buffer; --delim)
|
|
|
|
if (*delim == '/')
|
|
|
|
break;
|
|
|
|
|
|
|
|
const bool root = (delim == buffer);
|
|
|
|
|
|
|
|
const char *file = buffer;
|
|
|
|
const char *dir = "";
|
|
|
|
|
|
|
|
if (!root)
|
|
|
|
{
|
|
|
|
/* Cut the buffer in half so we can use it
|
|
|
|
* for both filename and directory path */
|
|
|
|
*delim = '\0';
|
|
|
|
file = delim+1;
|
|
|
|
dir = buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
OpenReadEnumData data(handler, file, len + buffer - delim - !root,
|
|
|
|
p->havePathCache ? &p->pathCache : 0);
|
|
|
|
|
|
|
|
if (p->havePathCache)
|
|
|
|
{
|
|
|
|
/* Get the list of files contained in this directory
|
|
|
|
* and manually iterate over them */
|
|
|
|
const std::vector<std::string> &fileList = p->fileLists[dir];
|
|
|
|
|
|
|
|
for (size_t i = 0; i < fileList.size(); ++i)
|
|
|
|
openReadEnumCB(&data, dir, fileList[i].c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-08 21:11:18 +00:00
|
|
|
PHYSFS_enumerate(dir, openReadEnumCB, &data);
|
2015-07-09 11:00:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (data.physfsError)
|
|
|
|
throw Exception(Exception::PHYSFSError, "PhysFS: %s", data.physfsError);
|
|
|
|
|
|
|
|
if (data.matchCount == 0)
|
|
|
|
throw Exception(Exception::NoFileError, "%s", filename);
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
}
|
2013-09-10 02:18:58 +00:00
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
void FileSystem::openReadRaw(SDL_RWops &ops,
|
|
|
|
const char *filename,
|
|
|
|
bool freeOnClose)
|
|
|
|
{
|
|
|
|
PHYSFS_File *handle = PHYSFS_openRead(filename);
|
|
|
|
assert(handle);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2015-07-09 11:00:56 +00:00
|
|
|
initReadOps(handle, ops, freeOnClose);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
2015-02-17 00:42:11 +00:00
|
|
|
bool FileSystem::exists(const char *filename)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2015-07-09 11:00:56 +00:00
|
|
|
return PHYSFS_exists(filename);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|