Skip to content

Commit

Permalink
Refactor|Console|libdoomsday: Use de::Path for the default config path
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jun 19, 2014
1 parent ca9db5b commit feafb82
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
7 changes: 4 additions & 3 deletions doomsday/client/include/con_config.h
@@ -1,8 +1,8 @@
/** @file con_config.h Config file IO.
* @ingroup console
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2003-2014 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2014 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand All @@ -22,13 +22,14 @@
#define DENG_CONSOLE_CONFIG_H

#include "dd_share.h"
#include <de/Path>

// Flags for Con_ParseCommands:
#define CPCF_SET_DEFAULT 0x1
#define CPCF_ALLOW_SAVE_STATE 0x2
#define CPCF_ALLOW_SAVE_BINDINGS 0x4

bool Con_ParseCommands(char const *fileName, int flags = 0);
bool Con_ParseCommands(de::Path const &fileName, int flags = 0);

/**
* Saves all bindings, aliases and archiveable console variables.
Expand Down
7 changes: 3 additions & 4 deletions doomsday/client/src/con_config.cpp
Expand Up @@ -44,7 +44,7 @@

using namespace de;

static filename_t cfgFile;
static Path cfgFile;
static int flagsAllow;

static void writeHeaderComment(FILE *file)
Expand Down Expand Up @@ -225,15 +225,14 @@ static bool writeState(Path const &filePath, Path const &bindingsFileName = "")
return true;
}

bool Con_ParseCommands(char const *fileName, int flags)
bool Con_ParseCommands(Path const &fileName, int flags)
{
bool const setDefault = (flags & CPCF_SET_DEFAULT) != 0;

// Is this supposed to be the default?
if(setDefault)
{
strncpy(cfgFile, fileName, FILENAME_T_MAXLEN);
cfgFile[FILENAME_T_LASTINDEX] = '\0';
cfgFile = fileName;
}

// Update the allowed operations.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/dd_main.cpp
Expand Up @@ -1207,14 +1207,14 @@ static int DD_ActivateGameWorker(void *context)
}

LOG_SCR_MSG("Parsing primary config \"%s\"...") << NativePath(configFile).pretty();
Con_ParseCommands(configFile.toUtf8().constData(), CPCF_SET_DEFAULT | CPCF_ALLOW_SAVE_STATE);
Con_ParseCommands(configFile, CPCF_SET_DEFAULT | CPCF_ALLOW_SAVE_STATE);

#ifdef __CLIENT__
// Apply default control bindings for this game.
B_BindGameDefaults();

// Read bindings for this game and merge with the working set.
Con_ParseCommands(App_CurrentGame().bindingConfig().toUtf8().constData(), CPCF_ALLOW_SAVE_BINDINGS);
Con_ParseCommands(App_CurrentGame().bindingConfig(), CPCF_ALLOW_SAVE_BINDINGS);
#endif
}

Expand Down
3 changes: 2 additions & 1 deletion doomsday/libdoomsday/include/doomsday/console/exec.h
Expand Up @@ -24,6 +24,7 @@
#include "dd_share.h"
#include "dd_types.h"
#include <de/game/Game>
#include <de/Path>

#include <de/shell/Lexicon> // known words
#include <cstdio>
Expand Down Expand Up @@ -69,7 +70,7 @@ LIBDOOMSDAY_PUBLIC void Con_Ticker(timespan_t time);
LIBDOOMSDAY_PUBLIC int Con_Execute(byte src, char const *command, int silent, dd_bool netCmd);
LIBDOOMSDAY_PUBLIC int Con_Executef(byte src, int silent, char const *command, ...) PRINTF_F(3,4);

LIBDOOMSDAY_PUBLIC dd_bool Con_Parse(char const *fileName, dd_bool silently);
LIBDOOMSDAY_PUBLIC dd_bool Con_Parse(de::Path const &fileName, dd_bool silently);

#ifdef __cplusplus
} // extern "C"
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libdoomsday/src/console/exec.cpp
Expand Up @@ -869,7 +869,7 @@ static void readLine(char *buffer, size_t len, FileHandle *file)
}
}

dd_bool Con_Parse(char const *fileName, dd_bool silently)
dd_bool Con_Parse(Path const &fileName, dd_bool silently)
{
try
{
Expand Down Expand Up @@ -906,7 +906,7 @@ dd_bool Con_Parse(char const *fileName, dd_bool silently)
}
catch(FS1::NotFoundError const &)
{} // Ignore.
LOG_SCR_WARNING("Failed to open \"%s\" for write") << fileName;
LOG_SCR_WARNING("Failed to open \"%s\" for write") << NativePath(fileName).pretty();
return false;
}

Expand Down

0 comments on commit feafb82

Please sign in to comment.