diff --git a/doomsday/apps/client/src/dd_main.cpp b/doomsday/apps/client/src/dd_main.cpp index 71a7a20c92..ca60454140 100644 --- a/doomsday/apps/client/src/dd_main.cpp +++ b/doomsday/apps/client/src/dd_main.cpp @@ -62,7 +62,6 @@ #include #include #include -#include #include #include #include @@ -319,12 +318,12 @@ static void createPackagesScheme() #ifdef UNIX // There may be an iwaddir specified in a system-level config file. - filename_t fn; - if (UnixInfo_GetConfigValue("paths", "iwaddir", fn, FILENAME_T_MAXLEN)) + if (char *fn = UnixInfo_GetConfigValue("paths", "iwaddir")) { NativePath path = de::App::commandLine().startupPath() / fn; scheme.addSearchPath(SearchPath(de::Uri::fromNativeDirPath(path), SearchPath::NoDescend)); LOG_RES_NOTE("Using paths.iwaddir: %s") << path.pretty(); + free(fn); } #endif @@ -996,37 +995,6 @@ static void initialize() BusyMode_RunNewTaskWithName(BUSYF_STARTUP | BUSYF_PROGRESS_BAR | (verbose? BUSYF_CONSOLE_OUTPUT : 0), DD_DummyWorker, 0, "Buffering..."); -#if 0 - // Add resource paths specified using -iwad on the command line. - FS1::Scheme &scheme = App_FileSystem().scheme(App_ResourceClass("RC_PACKAGE").defaultScheme()); - for (dint p = 0; p < CommandLine_Count(); ++p) - { - if (!CommandLine_IsMatchingAlias("-iwad", CommandLine_At(p))) - { - continue; - } - - while (++p != CommandLine_Count() && !CommandLine_IsOption(p)) - { - /// @todo Do not add these as search paths, publish them directly to - /// the "Packages" scheme. - - // CommandLine_PathAt() always returns an absolute path. - directory_t *dir = Dir_FromText(CommandLine_PathAt(p)); - de::Uri uri = de::Uri::fromNativeDirPath(Dir_Path(dir), RC_PACKAGE); - - LOG_RES_NOTE("User-supplied IWAD path: \"%s\"") << Dir_Path(dir); - - scheme.addSearchPath(SearchPath(uri, SearchPath::NoDescend)); - - Dir_Delete(dir); - } - - p--;/* For ArgIsOption(p) necessary, for p==Argc() harmless */ - } - - App_ResourceSystem().updateOverrideIWADPathFromConfig(); -#endif // // Try to locate all required data files for all registered games. // diff --git a/doomsday/apps/client/src/def_main.cpp b/doomsday/apps/client/src/def_main.cpp index d234a9539c..275052dc6c 100644 --- a/doomsday/apps/client/src/def_main.cpp +++ b/doomsday/apps/client/src/def_main.cpp @@ -44,7 +44,6 @@ #include #include #include -#include #include #include #include @@ -425,6 +424,7 @@ static void readDefinitionFile(String path) Def_ReadProcessDED(&defs, path); } +#if 0 /** * Attempt to prepend the current work path. If @a src is already absolute do nothing. * @@ -437,10 +437,13 @@ static void prependWorkPath(ddstring_t *dst, ddstring_t const *src) if (!F_IsAbsolute(src)) { - char *curPath = Dir_CurrentPath(); - Str_Prepend(dst, curPath); - Dir_CleanPathStr(dst); - M_Free(curPath); + NativePath prepended = NativePath::workPath() / Str_Text(src); + + //char *curPath = Dir_CurrentPath(); + //Str_Prepend(dst, curPath.); + //Dir_CleanPathStr(dst); + //M_Free(curPath); + return; } @@ -450,6 +453,7 @@ static void prependWorkPath(ddstring_t *dst, ddstring_t const *src) Str_Set(dst, Str_Text(src)); } } +#endif /** * Returns a URN list (in load order) for all lumps whose name matches the pattern "MAPINFO.lmp". @@ -619,7 +623,6 @@ static void readAllDefinitions() } // Next are any definition files specified on the command line. - AutoStr *buf = AutoStr_NewStd(); for (dint p = 0; p < CommandLine_Count(); ++p) { char const *arg = CommandLine_At(p); @@ -628,16 +631,17 @@ static void readAllDefinitions() while (++p != CommandLine_Count() && !CommandLine_IsOption(p)) { - char const *searchPath = CommandLine_PathAt(p); + // CommandLine cleans the path, expands symbols, and makes it absolute. + NativePath searchPath(CommandLine_PathAt(p)); - Str_Clear(buf); Str_Set(buf, searchPath); - F_FixSlashes(buf, buf); - F_ExpandBasePath(buf, buf); + //Str_Clear(buf); Str_Set(buf, searchPath); + //F_FixSlashes(buf, buf); + //F_ExpandBasePath(buf, buf); // We must have an absolute path. If we still do not have one then // prepend the current working directory if necessary. - prependWorkPath(buf, buf); + //prependWorkPath(buf, buf); - readDefinitionFile(String(Str_Text(buf))); + readDefinitionFile(searchPath.withSeparators('/')); } p--; /* For ArgIsOption(p) necessary, for p==Argc() harmless */ } @@ -1072,7 +1076,7 @@ static void configureMaterial(world::Material &mat, Record const &definition) { res::TextureManifest *maskTexture = &resSys().textures().textureScheme("Masks") .findByResourceUri(*shineDef->stage.maskTexture); - + slayer->addStage(world::ShineTextureMaterialLayer::AnimationStage (texture.composeUri(), stage.tics, stage.variance, maskTexture->composeUri(), shineDef->stage.blendMode, diff --git a/doomsday/apps/client/src/network/net_demo.cpp b/doomsday/apps/client/src/network/net_demo.cpp index 3e1c571bed..9ae5b242a0 100644 --- a/doomsday/apps/client/src/network/net_demo.cpp +++ b/doomsday/apps/client/src/network/net_demo.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include "client/cl_player.h" @@ -59,7 +58,7 @@ struct demopacket_header_t extern dfloat netConnectTime; -filename_t demoPath = "/home/demo/"; +static char const *demoPath = "/home/demo/"; LZFILE *playdemo; dint playback; diff --git a/doomsday/apps/client/src/unix/dd_uinit.cpp b/doomsday/apps/client/src/unix/dd_uinit.cpp index b9ca5db2ea..a17d7b6ffa 100644 --- a/doomsday/apps/client/src/unix/dd_uinit.cpp +++ b/doomsday/apps/client/src/unix/dd_uinit.cpp @@ -26,7 +26,6 @@ #include #include -#include #include #include #include diff --git a/doomsday/apps/libdoomsday/include/doomsday/filesys/fs_main.h b/doomsday/apps/libdoomsday/include/doomsday/filesys/fs_main.h index eeb4fc3b7e..a687551605 100644 --- a/doomsday/apps/libdoomsday/include/doomsday/filesys/fs_main.h +++ b/doomsday/apps/libdoomsday/include/doomsday/filesys/fs_main.h @@ -39,6 +39,16 @@ # include "fs_windows.h" #endif +#ifdef WIN32 +# define DENG_DIR_SEP_CHAR '\\' +# define DENG_DIR_SEP_STR "\\" +# define DENG_DIR_WRONG_SEP_CHAR '/' +#else +# define DENG_DIR_SEP_CHAR '/' +# define DENG_DIR_SEP_STR "/" +# define DENG_DIR_WRONG_SEP_CHAR '\\' +#endif + #ifdef __cplusplus #include diff --git a/doomsday/apps/libdoomsday/include/doomsday/filesys/sys_direc.h b/doomsday/apps/libdoomsday/include/doomsday/filesys/sys_direc.h deleted file mode 100644 index fc5657bec2..0000000000 --- a/doomsday/apps/libdoomsday/include/doomsday/filesys/sys_direc.h +++ /dev/null @@ -1,116 +0,0 @@ -/** @file sys_direc.h - * - * @authors Copyright © 2003-2013 Jaakko Keränen - * @authors Copyright © 2009-2013 Daniel Swanson - * - * @par License - * GPL: http://www.gnu.org/licenses/gpl.html - * - * This program 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. This program 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 this program; if not, see: - * http://www.gnu.org/licenses - */ - -/** - * Directory Utilities. - */ - -#ifndef LIBDENG_DIREC_H -#define LIBDENG_DIREC_H - -#include "../libdoomsday.h" -#include "dd_types.h" - -#ifdef WIN32 -# define DENG_DIR_SEP_CHAR '\\' -# define DENG_DIR_SEP_STR "\\" -# define DENG_DIR_WRONG_SEP_CHAR '/' -#else -# define DENG_DIR_SEP_CHAR '/' -# define DENG_DIR_SEP_STR "/" -# define DENG_DIR_WRONG_SEP_CHAR '\\' -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#define FILENAME_T_MAXLEN 256 -#define FILENAME_T_LASTINDEX 255 -typedef char filename_t[FILENAME_T_MAXLEN]; - -typedef struct directory_s { -#if defined(WIN32) - int drive; -#endif - filename_t path; -} directory_t; - -/// Construct using the specified path. -LIBDOOMSDAY_PUBLIC directory_t* Dir_New(const char* path); - -/// Construct using the current working directory path. -LIBDOOMSDAY_PUBLIC directory_t* Dir_NewFromCWD(void); - -/** - * Construct by extracting the path from @a path. - * \note if not absolute then it will be interpeted as relative to the current - * working directory path. - */ -LIBDOOMSDAY_PUBLIC directory_t* Dir_FromText(const char* path); - -LIBDOOMSDAY_PUBLIC void Dir_Delete(directory_t* dir); - -/** - * @return "Raw" version of the present path. - */ -LIBDOOMSDAY_PUBLIC const char* Dir_Path(directory_t* dir); - -/// Class-Static Members: - -/** - * Clean up given path. Whitespace is trimmed. Path separators are converted - * into their system-specific form. On Unix '~' expansion is applied. - */ -LIBDOOMSDAY_PUBLIC void Dir_CleanPath(char* path, size_t len); -LIBDOOMSDAY_PUBLIC void Dir_CleanPathStr(ddstring_t* str); - -/** - * @return Absolute path to the current working directory for the default drive. - * Always ends with a '/'. Path must be released with M_Free() - * @c NULL if we are out of memory. - */ -LIBDOOMSDAY_PUBLIC char* Dir_CurrentPath(void); - -/** - * Convert a path into an absolute path. If @a path is relative it is considered - * relative to the current working directory. On Unix '~' expansion is applied. - * - * @param path Path to be translated. - * @param len Length of the buffer used for @a path (in bytes). - */ -LIBDOOMSDAY_PUBLIC void Dir_MakeAbsolutePath(char* path, size_t len); - -/* - * Check that the given directory exists. If it doesn't, create it. - * @return @c true if successful. - */ -//LIBDOOMSDAY_PUBLIC dd_bool Dir_mkpath(const char* path); - -/* - * Attempt to change the current working directory to the path defined. - * @return @c true if the change was successful. - */ -//LIBDOOMSDAY_PUBLIC dd_bool Dir_SetCurrent(const char* path); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif /* LIBDENG_DIREC_H */ diff --git a/doomsday/apps/libdoomsday/src/defs/dedparser.cpp b/doomsday/apps/libdoomsday/src/defs/dedparser.cpp index ba315145ca..60ec252778 100644 --- a/doomsday/apps/libdoomsday/src/defs/dedparser.cpp +++ b/doomsday/apps/libdoomsday/src/defs/dedparser.cpp @@ -65,7 +65,6 @@ #include "doomsday/defs/sky.h" #include "doomsday/filesys/fs_main.h" #include "doomsday/filesys/fs_util.h" -#include "doomsday/filesys/sys_direc.h" #include "doomsday/uri.h" #include "doomsday/world/xgclass.h" diff --git a/doomsday/apps/libdoomsday/src/doomsdayapp.cpp b/doomsday/apps/libdoomsday/src/doomsdayapp.cpp index ef44f023f7..1f9961685a 100644 --- a/doomsday/apps/libdoomsday/src/doomsdayapp.cpp +++ b/doomsday/apps/libdoomsday/src/doomsdayapp.cpp @@ -20,7 +20,6 @@ #include "doomsday/games.h" #include "doomsday/gameprofiles.h" #include "doomsday/console/exec.h" -#include "doomsday/filesys/sys_direc.h" #include "doomsday/filesys/fs_util.h" #include "doomsday/resource/resources.h" #include "doomsday/resource/bundles.h" @@ -48,6 +47,7 @@ #include #include #include +#include #include #include @@ -241,10 +241,10 @@ DENG2_PIMPL(DoomsdayApp) #ifdef UNIX // There may be an iwaddir specified in a system-level config file. - filename_t fn; - if (UnixInfo_GetConfigValue("paths", "iwaddir", fn, FILENAME_T_MAXLEN)) + if (char *fn = UnixInfo_GetConfigValue("paths", "iwaddir")) { attachWadFeed("UnixInfo " _E(i) "paths.iwaddir" _E(.), startupPath / fn); + free(fn); } #endif @@ -279,11 +279,11 @@ DENG2_PIMPL(DoomsdayApp) #ifdef UNIX // There may be an iwaddir specified in a system-level config file. - filename_t fn; - if (UnixInfo_GetConfigValue("paths", "packsdir", fn, FILENAME_T_MAXLEN)) + if (char *fn = UnixInfo_GetConfigValue("paths", "packsdir")) { attachPacksFeed("UnixInfo " _E(i) "paths.packsdir" _E(.), cmdLine.startupPath() / fn); + free(fn); } #endif @@ -501,30 +501,12 @@ std::string const &DoomsdayApp::doomsdayBasePath() const void DoomsdayApp::setDoomsdayBasePath(NativePath const &path) { - /// @todo Unfortunately the legacy Dir/fs_util assumes fixed-size strings, so we - /// can't take advantage of std::string. -jk - filename_t temp; - strncpy(temp, path.toUtf8(), FILENAME_T_MAXLEN); + NativePath cleaned = App::commandLine().startupPath() / path; // In case it's relative. + cleaned.addTerminatingSeparator(); - Dir_CleanPath(temp, FILENAME_T_MAXLEN); - Dir_MakeAbsolutePath(temp, FILENAME_T_MAXLEN); - - // Ensure it ends with a directory separator. - F_AppendMissingSlashCString(temp, FILENAME_T_MAXLEN); - - d->ddBasePath = temp; -} - -/*std::string const &DoomsdayApp::doomsdayRuntimePath() const -{ - return d->ddRuntimePath; + d->ddBasePath = cleaned.toString().toStdString(); } -void DoomsdayApp::setDoomsdayRuntimePath(NativePath const &path) -{ - d->ddRuntimePath = path.toUtf8().constData(); -}*/ - #ifdef WIN32 void *DoomsdayApp::moduleHandle() const { diff --git a/doomsday/apps/libdoomsday/src/filesys/fs_util.cpp b/doomsday/apps/libdoomsday/src/filesys/fs_util.cpp index ee95d1063b..a4564f7aa2 100644 --- a/doomsday/apps/libdoomsday/src/filesys/fs_util.cpp +++ b/doomsday/apps/libdoomsday/src/filesys/fs_util.cpp @@ -43,7 +43,6 @@ #include "doomsday/DoomsdayApp" #include "doomsday/filesys/fs_main.h" #include "doomsday/filesys/fs_util.h" -#include "doomsday/filesys/sys_direc.h" #include "doomsday/filesys/lumpindex.h" #include diff --git a/doomsday/apps/libdoomsday/src/filesys/sys_direc.cpp b/doomsday/apps/libdoomsday/src/filesys/sys_direc.cpp deleted file mode 100644 index 85a28df6e0..0000000000 --- a/doomsday/apps/libdoomsday/src/filesys/sys_direc.cpp +++ /dev/null @@ -1,424 +0,0 @@ -/** @file sys_direc.cpp Native file system directories. - * @ingroup system - * - * @todo Rewrite using libcore's NativePath (and Qt). - * @deprecated Should use FS2 for all file access. - * - * @authors Copyright © 2003-2013 Jaakko Keränen - * @authors Copyright © 2007-2013 Daniel Swanson - * - * @par License - * GPL: http://www.gnu.org/licenses/gpl.html - * - * This program 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. This program 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 this program; if not, see: - * http://www.gnu.org/licenses - */ - -#include -#include -#include - -#if defined(WIN32) -# include -# include -# define strdup _strdup -#endif - -#if defined(UNIX) -# include -# include -# include -# include -# include -# include -#endif - -#include -#include -#include -#include - -#include "doomsday/DoomsdayApp" -#include "doomsday/filesys/sys_direc.h" -#include "doomsday/filesys/fs_util.h" - -static void setPathFromPathDir(directory_t* dir, const char* path); - -static void prependBasePath(char* newPath, const char* path, size_t maxLen); -static void resolveAppRelativeDirectives(char* translated, const char* path, size_t maxLen); -#if defined(UNIX) -static void resolveHomeRelativeDirectives(char* path, size_t maxLen); -#endif -static void resolvePathRelativeDirectives(char* path); - -static void Dir_SetPath(directory_t* dir, const char *path); - -/** - * Extract just the file name including any extension from @a path. - */ -static void Dir_FileName(char* name, const char* path, size_t len); - -/** - * Convert directory separators in @a path to their system-specifc form. - */ -static void Dir_ToNativeSeparators(char* path, size_t len); - -/** - * Convert directory separators in @a path to our internal '/' form. - */ -static void Dir_FixSeparators(char* path, size_t len); - -/// @return @c true if @a path is absolute. -static int Dir_IsAbsolutePath(const char* path); - -directory_t* Dir_New(const char* path) -{ - directory_t* dir = (directory_t*) M_Calloc(sizeof *dir); - Dir_SetPath(dir, path); - return dir; -} - -directory_t* Dir_NewFromCWD(void) -{ - directory_t* dir = (directory_t*) M_Calloc(sizeof *dir); - size_t lastIndex; - char* cwd; - - cwd = Dir_CurrentPath(); - lastIndex = strlen(cwd); - lastIndex = MIN_OF(lastIndex, FILENAME_T_LASTINDEX); - -#if defined(WIN32) - dir->drive = _getdrive(); -#endif - memcpy(dir->path, cwd, lastIndex); - dir->path[lastIndex] = '\0'; - free(cwd); - return dir; -} - -directory_t* Dir_FromText(const char* path) -{ - directory_t* dir; - if (!path || !path[0]) - return Dir_NewFromCWD(); - - dir = (directory_t*) M_Calloc(sizeof *dir); - setPathFromPathDir(dir, path); - return dir; -} - -void Dir_Delete(directory_t* dir) -{ - DENG_ASSERT(NULL != dir); - M_Free(dir); -} - -const char* Dir_Path(directory_t* dir) -{ - DENG_ASSERT(NULL != dir); - return dir->path; -} - -static void Dir_SetPath(directory_t* dir, const char* path) -{ - filename_t fileName; - DENG_ASSERT(dir); - - setPathFromPathDir(dir, path); - Dir_FileName(fileName, path, FILENAME_T_MAXLEN); - M_StrCat(dir->path, fileName, FILENAME_T_MAXLEN); - // Ensure we've a well-formed path. - Dir_CleanPath(dir->path, FILENAME_T_MAXLEN); -} - -static void setPathFromPathDir(directory_t* dir, const char* path) -{ - filename_t temp, transPath; - DENG_ASSERT(dir && path && path[0]); - - resolveAppRelativeDirectives(transPath, path, FILENAME_T_MAXLEN); -#ifdef UNIX - resolveHomeRelativeDirectives(transPath, FILENAME_T_MAXLEN); -#endif - Dir_ToNativeSeparators(transPath, FILENAME_T_MAXLEN); - - _fullpath(temp, transPath, FILENAME_T_MAXLEN); - _splitpath(temp, dir->path, transPath, 0, 0); - M_StrCat(dir->path, transPath, FILENAME_T_MAXLEN); -#if defined(WIN32) - dir->drive = toupper(dir->path[0]) - 'A' + 1; -#endif - Dir_FixSeparators(dir->path, FILENAME_T_MAXLEN); -} - -/// Class-Static Members: - -static void prependBasePath(char* newPath, const char* path, size_t maxLen) -{ - DENG_ASSERT(newPath && path); - // Cannot prepend to absolute paths. - if (!Dir_IsAbsolutePath(path)) - { - filename_t buf; - dd_snprintf(buf, maxLen, "%s%s", DoomsdayApp::app().doomsdayBasePath().c_str(), path); - memcpy(newPath, buf, maxLen); - return; - } - strncpy(newPath, path, maxLen); -} - -static void resolveAppRelativeDirectives(char* translated, const char* path, size_t maxLen) -{ - filename_t buf; - DENG_ASSERT(translated && path); - - if (path[0] == '>' || path[0] == '}') - { - path++; - if (!Dir_IsAbsolutePath(path)) - prependBasePath(buf, path, maxLen); - else - strncpy(buf, path, maxLen); - strncpy(translated, buf, maxLen); - } - else if (translated != path) - { - strncpy(translated, path, maxLen); - } -} - -#if defined(UNIX) -static void resolveHomeRelativeDirectives(char* path, size_t maxLen) -{ - filename_t buf; - DENG_ASSERT(path); - - if (!path[0] || 0 == maxLen || path[0] != '~') return; - - memset(buf, 0, sizeof(buf)); - - if (path[1] == '/') - { - // Replace it with the HOME environment variable. - strncpy(buf, getenv("HOME"), FILENAME_T_MAXLEN); - if (DENG_LAST_CHAR(buf) != '/') - M_StrCat(buf, "/", FILENAME_T_MAXLEN); - - // Append the rest of the original path. - M_StrCat(buf, path + 2, FILENAME_T_MAXLEN); - } - else - { - char userName[4096], *end = NULL; - struct passwd *pw; - - end = strchr(path + 1, '/'); - strncpy(userName, path, end - path - 1); - userName[end - path - 1] = 0; - - pw = getpwnam(userName); - if (pw) - { - strncpy(buf, pw->pw_dir, FILENAME_T_MAXLEN); - if (DENG_LAST_CHAR(buf) != '/') - M_StrCat(buf, "/", FILENAME_T_MAXLEN); - } - - M_StrCat(buf, path + 1, FILENAME_T_MAXLEN); - } - - // Replace the original. - strncpy(path, buf, maxLen - 1); -} -#endif - -static void resolvePathRelativeDirectives(char* path) -{ - DENG_ASSERT(NULL != path); - - char* ch = path; - char* end = path + strlen(path); - char* prev = path; // Assume an absolute path. - - for (; *ch; ch++) - { - if (ch[0] == '/' && ch[1] == '.') - { - if (ch[2] == '/') - { - memmove(ch, ch + 2, end - ch - 1); - ch--; - } - else if (ch[2] == '.' && ch[3] == '/') - { - memmove(prev, ch + 3, end - ch - 2); - // Must restart from the beginning. - // This is a tad inefficient, though. - ch = path - 1; - continue; - } - } - if (*ch == '/') - prev = ch; - } -} - -void Dir_CleanPath(char* path, size_t len) -{ - if (!path || 0 == len) return; - - M_Strip(path, len); -#if defined(UNIX) - resolveHomeRelativeDirectives(path, len); -#endif - Dir_FixSeparators(path, len); - resolvePathRelativeDirectives(path); -} - -void Dir_CleanPathStr(ddstring_t* str) -{ - size_t len = Str_Length(str); - char* path = strdup(Str_Text(str)); - Dir_CleanPath(path, len); - Str_Set(str, path); - free(path); -} - -char* Dir_CurrentPath(void) -{ - de::String path = de::App::currentWorkPath(); - // FS1 generally assumes that paths end with a separator. - if (!path.endsWith(de::NativePath::separator())) - { - path += de::NativePath::separator(); - } - return strdup(path.toLatin1()); -} - -static void Dir_FileName(char* name, const char* path, size_t len) -{ - char ext[100]; /// @todo Use dynamic string. - if (!path || !name || 0 == len) return; - _splitpath(path, 0, 0, name, ext); - M_StrCat(name, ext, len); -} - -static int Dir_IsAbsolutePath(const char* path) -{ - if (!path || !path[0]) return 0; - if (path[0] == '/' || path[1] == ':') - return true; -#if defined(UNIX) - if (path[0] == '~') - return true; -#endif - return false; -} - -#if 0 -dd_bool Dir_mkpath(const char* path) -{ -#if !defined(WIN32) && !defined(UNIX) -# error Dir_mkpath has no implementation for this platform. -#endif - - filename_t full, buf; - char* ptr, *endptr; - - if (!path || !path[0]) return false; - - // Convert all backslashes to normal slashes. - strncpy(full, path, FILENAME_T_MAXLEN); - Dir_ToNativeSeparators(full, FILENAME_T_MAXLEN); - - // Does this path already exist? - if (0 == access(full, 0)) - return true; - - // Check and create the path in segments. - ptr = full; - memset(buf, 0, sizeof(buf)); - do - { - endptr = strchr(ptr, DENG_DIR_SEP_CHAR); - if (!endptr) - M_StrCat(buf, ptr, FILENAME_T_MAXLEN); - else - M_StrnCat(buf, ptr, endptr - ptr, FILENAME_T_MAXLEN); - - if (buf[0] && access(buf, 0)) - { - // Path doesn't exist, create it. -#if defined(WIN32) - mkdir(buf); -#elif defined(UNIX) - mkdir(buf, 0775); -#endif - } - M_StrCat(buf, DENG_DIR_SEP_STR, FILENAME_T_MAXLEN); - ptr = endptr + 1; - - } while (endptr); - - return (0 == access(full, 0)); -} -#endif - -void Dir_MakeAbsolutePath(char* path, size_t len) -{ - filename_t buf; - if (!path || !path[0] || 0 == len) return; - -#if defined(UNIX) - resolveHomeRelativeDirectives(path, len); -#endif - _fullpath(buf, path, FILENAME_T_MAXLEN); - strncpy(path, buf, len); - Dir_FixSeparators(path, len); -} - -static void Dir_ToNativeSeparators(char* path, size_t len) -{ - size_t i; - if (!path || !path[0] || 0 == len) return; - - for (i = 0; i < len && path[i]; ++i) - { - if (path[i] == DENG_DIR_WRONG_SEP_CHAR) - path[i] = DENG_DIR_SEP_CHAR; - } -} - -static void Dir_FixSeparators(char* path, size_t len) -{ - size_t i; - if (!path || !path[0] || 0 == len) return; - - for (i = 0; i < len && path[i]; ++i) - { - if (path[i] == '\\') - path[i] = '/'; - } -} - -/*dd_bool Dir_SetCurrent(const char* path) -{ - LOG_AS("Dir"); - - bool success = false; - if (path && path[0]) - { - success = de::NativePath::setWorkPath(path); - } - LOG_RES_VERBOSE("Changing current directory to \"%s\" %s") << path << (success? "succeeded" : "failed"); - return success; -} -*/ diff --git a/doomsday/apps/plugins/fluidsynth/src/driver_fluidsynth.cpp b/doomsday/apps/plugins/fluidsynth/src/driver_fluidsynth.cpp index 97da6dabec..7932dd496f 100644 --- a/doomsday/apps/plugins/fluidsynth/src/driver_fluidsynth.cpp +++ b/doomsday/apps/plugins/fluidsynth/src/driver_fluidsynth.cpp @@ -73,16 +73,17 @@ int DS_Init(void) #ifndef FLUIDSYNTH_NOT_A_DLL // Create the output driver that will play the music. - char driverName[50]; - if(!UnixInfo_GetConfigValue("defaults", "fluidsynth:driver", driverName, sizeof(driverName) - 1)) + std::string driverName = FLUIDSYNTH_DEFAULT_DRIVER_NAME; + if (char *cfgValue = UnixInfo_GetConfigValue("defaults", "fluidsynth:driver")) { - strcpy(driverName, FLUIDSYNTH_DEFAULT_DRIVER_NAME); + driverName = cfgValue; + free(cfgValue); } - fluid_settings_setstr(fsConfig, "audio.driver", driverName); + fluid_settings_setstr(fsConfig, "audio.driver", driverName.c_str()); fsDriver = new_fluid_audio_driver(fsConfig, fsSynth); if(!fsDriver) { - App_Log(DE2_AUDIO_ERROR, "[FluidSynth] Failed to load audio driver '%s'", driverName); + App_Log(DE2_AUDIO_ERROR, "[FluidSynth] Failed to load audio driver '%s'", driverName.c_str()); return false; } #else diff --git a/doomsday/sdk/libcore/include/de/c_wrapper.h b/doomsday/sdk/libcore/include/de/c_wrapper.h index 4b94aa74ac..5b7144bb94 100644 --- a/doomsday/sdk/libcore/include/de/c_wrapper.h +++ b/doomsday/sdk/libcore/include/de/c_wrapper.h @@ -242,7 +242,7 @@ DENG2_PUBLIC int Info_FindValue(Info *info, char const *path, char *buffer, size /* * UnixInfo */ -DENG2_PUBLIC int UnixInfo_GetConfigValue(char const *configFile, char const *key, char *dest, size_t destLen); +DENG2_PUBLIC char *UnixInfo_GetConfigValue(char const *configFile, char const *key); // caller must free() returned /* * ByteOrder diff --git a/doomsday/sdk/libcore/include/de/data/path.h b/doomsday/sdk/libcore/include/de/data/path.h index 2c73e41422..aeb71316f8 100644 --- a/doomsday/sdk/libcore/include/de/data/path.h +++ b/doomsday/sdk/libcore/include/de/data/path.h @@ -354,6 +354,11 @@ class DENG2_PUBLIC Path : public ISerializable, public LogEntry::Arg::Base */ QChar separator() const; + /** + * Adds a separator in the end of the path, if one is not there already. + */ + void addTerminatingSeparator(); + /** * Returns the file name portion of the path, i.e., the last segment. */ diff --git a/doomsday/sdk/libcore/src/c_wrapper.cpp b/doomsday/sdk/libcore/src/c_wrapper.cpp index db482b769a..53aea92078 100644 --- a/doomsday/sdk/libcore/src/c_wrapper.cpp +++ b/doomsday/sdk/libcore/src/c_wrapper.cpp @@ -108,7 +108,7 @@ void App_FatalError(char const *msgFormat, ...) va_end(args); DENG2_APP->handleUncaughtException(buffer); - + // Let's make sure this is the end. exit(-1); } @@ -274,7 +274,7 @@ int Info_FindValue(Info *info, char const *path, char *buffer, size_t bufSize) } } -int UnixInfo_GetConfigValue(char const *configFile, char const *key, char *dest, size_t destLen) +char *UnixInfo_GetConfigValue(char const *configFile, char const *key) { de::UnixInfo &info = de::App::unixInfo(); @@ -284,8 +284,7 @@ int UnixInfo_GetConfigValue(char const *configFile, char const *key, char *dest, de::NativePath foundValue; if (info.path(key, foundValue)) { - qstrncpy(dest, foundValue.toString().toUtf8().constData(), uint(destLen)); - return true; + return qstrdup(foundValue.toString().toUtf8().constData()); } } else if (!qstrcmp(configFile, "defaults")) @@ -293,11 +292,10 @@ int UnixInfo_GetConfigValue(char const *configFile, char const *key, char *dest, de::String foundValue; if (info.defaults(key, foundValue)) { - qstrncpy(dest, foundValue.toUtf8().constData(), uint(destLen)); - return true; + return qstrdup(foundValue.toUtf8().constData()); } } - return false; + return nullptr; } dint16 LittleEndianByteOrder_ToForeignInt16(dint16 value) diff --git a/doomsday/sdk/libcore/src/data/path.cpp b/doomsday/sdk/libcore/src/data/path.cpp index 1eaa89cdd2..137ba22171 100644 --- a/doomsday/sdk/libcore/src/data/path.cpp +++ b/doomsday/sdk/libcore/src/data/path.cpp @@ -92,6 +92,9 @@ String Path::Segment::toString() const struct Path::Impl { + DENG2_NO_ASSIGN(Impl) + DENG2_NO_COPY (Impl) + String path; /// The character in Impl::path that acts as the segment separator. @@ -240,9 +243,6 @@ struct Path::Impl DENG2_ASSERT(segmentCount > 0); } - - Impl &operator = (Impl const &) = delete; // no assignment - Impl(Impl const &) = delete; // no copying }; Path::Path() : d(new Impl) @@ -473,6 +473,18 @@ QChar Path::separator() const return d->separator; } +void Path::addTerminatingSeparator() +{ + if (!isEmpty()) + { + if (last() != d->separator) + { + d->path.append(d->separator); + d->clearSegments(); + } + } +} + String Path::fileName() const { if (last() == d->separator) return "";