Cosmetics in standard_paths.cpp

Originally committed to SVN as r6233.
This commit is contained in:
Thomas Goyne 2012-01-08 01:34:43 +00:00
parent 01646d7cf4
commit 43d4e785fb
2 changed files with 22 additions and 47 deletions

View File

@ -34,9 +34,6 @@
/// @ingroup utility
///
///////////
// Headers
#include "config.h"
#ifndef AGI_PRE
@ -46,19 +43,11 @@
#include "standard_paths.h"
/// @brief Get instance
/// @return
///
StandardPaths &StandardPaths::GetInstance() {
static StandardPaths instance;
return instance;
}
/// @brief Constructor
///
StandardPaths::StandardPaths() {
wxStandardPathsBase &paths = wxStandardPaths::Get();
@ -82,53 +71,40 @@ StandardPaths::StandardPaths() {
wxString tempDir = paths.GetTempDir();
// Set paths
DoSetPathValue("?data",dataDir);
DoSetPathValue("?user",userDir);
DoSetPathValue("?temp",tempDir);
DoSetPathValue("?data", dataDir);
DoSetPathValue("?user", userDir);
DoSetPathValue("?temp", tempDir);
// Create paths if they don't exist
wxFileName folder(userDir + "/");
if (!folder.DirExists()) folder.Mkdir(0777,wxPATH_MKDIR_FULL);
}
/// @brief Decode path
/// @param path
/// @return
///
wxString StandardPaths::DoDecodePath(wxString path) {
// Decode
if (path[0] == '?') {
// Split ?part from rest
path.Replace("\\","/");
int pos = path.Find("/");
wxString path1,path2;
if (pos == wxNOT_FOUND) path1 = path;
else {
path1 = path.Left(pos);
path2 = path.Mid(pos+1);
}
if (!path || path[0] != '?')
return path;
// Replace ?part if valid
std::map<wxString,wxString>::iterator iter = paths.find(path1);
if (iter == paths.end()) return path;
wxString final = iter->second + "/" + path2;
final.Replace("//","/");
#ifdef WIN32
final.Replace("/","\\");
#endif
return final;
// Split ?part from rest
path.Replace("\\","/");
int pos = path.Find("/");
wxString path1,path2;
if (pos == wxNOT_FOUND) path1 = path;
else {
path1 = path.Left(pos);
path2 = path.Mid(pos+1);
}
// Nothing to decode
else return path;
// Replace ?part if valid
std::map<wxString,wxString>::iterator iter = paths.find(path1);
if (iter == paths.end()) return path;
wxString final = iter->second + "/" + path2;
final.Replace("//","/");
#ifdef WIN32
final.Replace("/","\\");
#endif
return final;
}
/// @brief Set value of a ? path
/// @param path
/// @param value
///
void StandardPaths::DoSetPathValue(const wxString &path, const wxString &value) {
paths[path] = value;
}

View File

@ -58,7 +58,6 @@ class StandardPaths {
void DoSetPathValue(const wxString &path, const wxString &value);
public:
static wxString DecodePath(const wxString &path) { return GetInstance().DoDecodePath(path); }
static void SetPathValue(const wxString &path, const wxString &value) { GetInstance().DoSetPathValue(path,value); }
};