mirror of https://github.com/OpenTTD/OpenTTD
(svn r22510) -Codechange: Extract filepath creation to its own function.
parent
be048e05f2
commit
84f7fc32fa
55
src/fios.cpp
55
src/fios.cpp
|
@ -140,6 +140,38 @@ const char *FiosBrowseTo(const FiosItem *item)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a filename from its components in destination buffer \a buf.
|
||||||
|
* @param buf Destination buffer.
|
||||||
|
* @param path Directory path, may be \c NULL.
|
||||||
|
* @param name Filename.
|
||||||
|
* @param ext Filename extension (use \c "" for no extension).
|
||||||
|
* @param size Size of \a buf.
|
||||||
|
*/
|
||||||
|
static void FiosMakeFilename(char *buf, const char *path, const char *name, const char *ext, size_t size)
|
||||||
|
{
|
||||||
|
const char *period;
|
||||||
|
|
||||||
|
/* Don't append the extension if it is already there */
|
||||||
|
period = strrchr(name, '.');
|
||||||
|
if (period != NULL && strcasecmp(period, ext) == 0) ext = "";
|
||||||
|
#if defined(__MORPHOS__) || defined(__AMIGAOS__)
|
||||||
|
if (path != NULL) {
|
||||||
|
unsigned char sepchar = path[(strlen(path) - 1)];
|
||||||
|
|
||||||
|
if (sepchar != ':' && sepchar != '/') {
|
||||||
|
snprintf(buf, size, "%s" PATHSEP "%s%s", path, name, ext);
|
||||||
|
} else {
|
||||||
|
snprintf(buf, size, "%s%s%s", path, name, ext);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
snprintf(buf, size, "%s%s", name, ext);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
snprintf(buf, size, "%s" PATHSEP "%s%s", path, name, ext);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a save game or scenario filename from a name.
|
* Make a save game or scenario filename from a name.
|
||||||
* @param buf Destination buffer for saving the filename.
|
* @param buf Destination buffer for saving the filename.
|
||||||
|
@ -148,28 +180,9 @@ const char *FiosBrowseTo(const FiosItem *item)
|
||||||
*/
|
*/
|
||||||
void FiosMakeSavegameName(char *buf, const char *name, size_t size)
|
void FiosMakeSavegameName(char *buf, const char *name, size_t size)
|
||||||
{
|
{
|
||||||
const char *extension, *period;
|
const char *extension = (_game_mode == GM_EDITOR) ? ".scn" : ".sav";
|
||||||
|
|
||||||
extension = (_game_mode == GM_EDITOR) ? ".scn" : ".sav";
|
FiosMakeFilename(buf, _fios_path, name, extension, size);
|
||||||
|
|
||||||
/* Don't append the extension if it is already there */
|
|
||||||
period = strrchr(name, '.');
|
|
||||||
if (period != NULL && strcasecmp(period, extension) == 0) extension = "";
|
|
||||||
#if defined(__MORPHOS__) || defined(__AMIGAOS__)
|
|
||||||
if (_fios_path != NULL) {
|
|
||||||
unsigned char sepchar = _fios_path[(strlen(_fios_path) - 1)];
|
|
||||||
|
|
||||||
if (sepchar != ':' && sepchar != '/') {
|
|
||||||
snprintf(buf, size, "%s" PATHSEP "%s%s", _fios_path, name, extension);
|
|
||||||
} else {
|
|
||||||
snprintf(buf, size, "%s%s%s", _fios_path, name, extension);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
snprintf(buf, size, "%s%s", name, extension);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
snprintf(buf, size, "%s" PATHSEP "%s%s", _fios_path, name, extension);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue