forked from mia/Aegisub
Cosmetics in standard_paths.cpp
Originally committed to SVN as r6233.
This commit is contained in:
parent
01646d7cf4
commit
43d4e785fb
2 changed files with 22 additions and 47 deletions
|
@ -34,9 +34,6 @@
|
||||||
/// @ingroup utility
|
/// @ingroup utility
|
||||||
///
|
///
|
||||||
|
|
||||||
|
|
||||||
///////////
|
|
||||||
// Headers
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#ifndef AGI_PRE
|
#ifndef AGI_PRE
|
||||||
|
@ -46,19 +43,11 @@
|
||||||
|
|
||||||
#include "standard_paths.h"
|
#include "standard_paths.h"
|
||||||
|
|
||||||
|
|
||||||
/// @brief Get instance
|
|
||||||
/// @return
|
|
||||||
///
|
|
||||||
StandardPaths &StandardPaths::GetInstance() {
|
StandardPaths &StandardPaths::GetInstance() {
|
||||||
static StandardPaths instance;
|
static StandardPaths instance;
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// @brief Constructor
|
|
||||||
///
|
|
||||||
StandardPaths::StandardPaths() {
|
StandardPaths::StandardPaths() {
|
||||||
wxStandardPathsBase &paths = wxStandardPaths::Get();
|
wxStandardPathsBase &paths = wxStandardPaths::Get();
|
||||||
|
|
||||||
|
@ -82,53 +71,40 @@ StandardPaths::StandardPaths() {
|
||||||
wxString tempDir = paths.GetTempDir();
|
wxString tempDir = paths.GetTempDir();
|
||||||
|
|
||||||
// Set paths
|
// Set paths
|
||||||
DoSetPathValue("?data",dataDir);
|
DoSetPathValue("?data", dataDir);
|
||||||
DoSetPathValue("?user",userDir);
|
DoSetPathValue("?user", userDir);
|
||||||
DoSetPathValue("?temp",tempDir);
|
DoSetPathValue("?temp", tempDir);
|
||||||
|
|
||||||
// Create paths if they don't exist
|
// Create paths if they don't exist
|
||||||
wxFileName folder(userDir + "/");
|
wxFileName folder(userDir + "/");
|
||||||
if (!folder.DirExists()) folder.Mkdir(0777,wxPATH_MKDIR_FULL);
|
if (!folder.DirExists()) folder.Mkdir(0777,wxPATH_MKDIR_FULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// @brief Decode path
|
|
||||||
/// @param path
|
|
||||||
/// @return
|
|
||||||
///
|
|
||||||
wxString StandardPaths::DoDecodePath(wxString path) {
|
wxString StandardPaths::DoDecodePath(wxString path) {
|
||||||
// Decode
|
if (!path || path[0] != '?')
|
||||||
if (path[0] == '?') {
|
return path;
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Replace ?part if valid
|
// Split ?part from rest
|
||||||
std::map<wxString,wxString>::iterator iter = paths.find(path1);
|
path.Replace("\\","/");
|
||||||
if (iter == paths.end()) return path;
|
int pos = path.Find("/");
|
||||||
wxString final = iter->second + "/" + path2;
|
wxString path1,path2;
|
||||||
final.Replace("//","/");
|
if (pos == wxNOT_FOUND) path1 = path;
|
||||||
#ifdef WIN32
|
else {
|
||||||
final.Replace("/","\\");
|
path1 = path.Left(pos);
|
||||||
#endif
|
path2 = path.Mid(pos+1);
|
||||||
return final;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nothing to decode
|
// Replace ?part if valid
|
||||||
else return path;
|
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) {
|
void StandardPaths::DoSetPathValue(const wxString &path, const wxString &value) {
|
||||||
paths[path] = value;
|
paths[path] = value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,6 @@ class StandardPaths {
|
||||||
void DoSetPathValue(const wxString &path, const wxString &value);
|
void DoSetPathValue(const wxString &path, const wxString &value);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static wxString DecodePath(const wxString &path) { return GetInstance().DoDecodePath(path); }
|
static wxString DecodePath(const wxString &path) { return GetInstance().DoDecodePath(path); }
|
||||||
static void SetPathValue(const wxString &path, const wxString &value) { GetInstance().DoSetPathValue(path,value); }
|
static void SetPathValue(const wxString &path, const wxString &value) { GetInstance().DoSetPathValue(path,value); }
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue