(svn r22510) -Codechange: Extract filepath creation to its own function.

pull/155/head
alberth 13 years ago
parent d042417821
commit b04d69df7a

@ -141,37 +141,50 @@ const char *FiosBrowseTo(const FiosItem *item)
} }
/** /**
* Make a save game or scenario filename from a name. * Construct a filename from its components in destination buffer \a buf.
* @param buf Destination buffer for saving the filename. * @param buf Destination buffer.
* @param name Name of the file. * @param path Directory path, may be \c NULL.
* @param size Length of buffer \a buf. * @param name Filename.
* @param ext Filename extension (use \c "" for no extension).
* @param size Size of \a buf.
*/ */
void FiosMakeSavegameName(char *buf, const char *name, size_t size) static void FiosMakeFilename(char *buf, const char *path, const char *name, const char *ext, size_t size)
{ {
const char *extension, *period; const char *period;
extension = (_game_mode == GM_EDITOR) ? ".scn" : ".sav";
/* Don't append the extension if it is already there */ /* Don't append the extension if it is already there */
period = strrchr(name, '.'); period = strrchr(name, '.');
if (period != NULL && strcasecmp(period, extension) == 0) extension = ""; if (period != NULL && strcasecmp(period, ext) == 0) ext = "";
#if defined(__MORPHOS__) || defined(__AMIGAOS__) #if defined(__MORPHOS__) || defined(__AMIGAOS__)
if (_fios_path != NULL) { if (path != NULL) {
unsigned char sepchar = _fios_path[(strlen(_fios_path) - 1)]; unsigned char sepchar = path[(strlen(path) - 1)];
if (sepchar != ':' && sepchar != '/') { if (sepchar != ':' && sepchar != '/') {
snprintf(buf, size, "%s" PATHSEP "%s%s", _fios_path, name, extension); snprintf(buf, size, "%s" PATHSEP "%s%s", path, name, ext);
} else { } else {
snprintf(buf, size, "%s%s%s", _fios_path, name, extension); snprintf(buf, size, "%s%s%s", path, name, ext);
} }
} else { } else {
snprintf(buf, size, "%s%s", name, extension); snprintf(buf, size, "%s%s", name, ext);
} }
#else #else
snprintf(buf, size, "%s" PATHSEP "%s%s", _fios_path, name, extension); snprintf(buf, size, "%s" PATHSEP "%s%s", path, name, ext);
#endif #endif
} }
/**
* Make a save game or scenario filename from a name.
* @param buf Destination buffer for saving the filename.
* @param name Name of the file.
* @param size Length of buffer \a buf.
*/
void FiosMakeSavegameName(char *buf, const char *name, size_t size)
{
const char *extension = (_game_mode == GM_EDITOR) ? ".scn" : ".sav";
FiosMakeFilename(buf, _fios_path, name, extension, size);
}
/** /**
* Delete a file. * Delete a file.
* @param name Filename to delete. * @param name Filename to delete.

Loading…
Cancel
Save