Remove a bunch of pointless consts from agi::Path and rename the windows implementation so that it's actually used

Originally committed to SVN as r5442.
This commit is contained in:
Thomas Goyne 2011-07-15 04:03:28 +00:00
parent 9d1cdab638
commit 67e9384ef4
5 changed files with 44 additions and 56 deletions

View File

@ -291,10 +291,6 @@
RelativePath="..\..\libaegisub\common\log.cpp"
>
</File>
<File
RelativePath="..\..\libaegisub\common\util.cpp"
>
</File>
<File
RelativePath="..\..\libaegisub\common\mru.cpp"
>
@ -315,6 +311,10 @@
RelativePath="..\..\libaegisub\common\path.cpp"
>
</File>
<File
RelativePath="..\..\libaegisub\common\util.cpp"
>
</File>
<File
RelativePath="..\..\libaegisub\common\validator.cpp"
>
@ -341,10 +341,6 @@
RelativePath="..\..\libaegisub\windows\io.cpp"
>
</File>
<File
RelativePath="..\..\libaegisub\windows\path.cpp"
>
</File>
<File
RelativePath="..\..\libaegisub\windows\lagi_pre.cpp"
>
@ -401,6 +397,10 @@
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\libaegisub\windows\path_win.cpp"
>
</File>
<File
RelativePath="..\..\libaegisub\windows\util.cpp"
>

View File

@ -42,7 +42,7 @@ Path::~Path() {
}
const std::string Path::Get(const char *name) {
std::string Path::Get(const char *name) {
std::string path;
try {
path = std::string(opt->Get(name)->GetString());

View File

@ -48,7 +48,7 @@ public:
/// @brief Get a path, this is automatically decoded.
/// @param name Path to get
/// @return Full path name in UTF-8
const std::string Get(const char *name);
std::string Get(const char *name);
/// @brief Set a path, this will be automaticalled encoded if a cookie matches.
/// @param[in] name Path name to save to.
@ -70,14 +70,14 @@ public:
/// Windows: Documents folder
/// OS X: ~/Documents
/// Unix: ~ or Documents folder if set in the environment
const std::string Default();
std::string Default();
/// @brief Decode a path
/// @param path Decode a path in-place.
void Decode(std::string &path);
/// Configuration directory
static const std::string Config();
static std::string Config();
private:
/// Location of path config file.
@ -102,13 +102,13 @@ private:
/// @brief Locale files
/// @return Locale location
/// This is directly assessibly as the Locale directory will never change on any platform.
const std::string Locale();
std::string Locale();
protected:
const std::string Data(); ///< Shared resources
const std::string Doc(); ///< Documents
const std::string User(); ///< User config directory
const std::string Temp(); ///< Temporary storage
std::string Data(); ///< Shared resources
std::string Doc(); ///< Documents
std::string User(); ///< User config directory
std::string Temp(); ///< Temporary storage
};
} // namespace agi

View File

@ -35,42 +35,41 @@
namespace agi {
const std::string home() {
std::string home() {
char *ehome;
ehome = getenv("HOME");
if (ehome == NULL) {
printf("The HOME environment variable must be set\n");
exit(1);
}
std::string home(ehome);
return home;
return ehome;
}
const std::string Path::Data() {
std::string Path::Data() {
return P_DATA;
}
const std::string Path::Doc() {
std::string Path::Doc() {
return P_DOC;
}
const std::string Path::User() {
std::string Path::User() {
return home();
}
const std::string Path::Locale() {
std::string Path::Locale() {
return P_LOCALE;
}
const std::string Path::Config() {
std::string Path::Config() {
std::string tmp(home());
tmp.append("/.aegisub-");
tmp.append(AEGISUB_VERSION_DATA);
return tmp.append("/");
}
const std::string Path::Temp() {
std::string Path::Temp() {
return "/tmp/";
}

View File

@ -18,14 +18,12 @@
/// @brief Common paths.
/// @ingroup libaegisub
#include "config.h"
#ifndef LAGI_PRE
#include <string>
#endif
#include <libaegisub/path.h>
#include <libaegisub/charset_conv_win.h>
#include <libaegisub/util_win.h>
@ -34,7 +32,7 @@ namespace {
#include <Shlobj.h>
#include <Shellapi.h>
const std::string WinGetFolderPath(int folder) {
std::string WinGetFolderPath(int folder) {
wchar_t path[MAX_PATH+1] = {0};
HRESULT res = SHGetFolderPathW(
0, // hwndOwner
@ -44,16 +42,14 @@ const std::string WinGetFolderPath(int folder) {
path // pszPath
);
if (FAILED(res))
throw new agi::PathErrorInternal("SHGetFolderPath() failed"); //< @fixme error message?
else
return agi::charset::ConvertW(std::wstring(path));
throw agi::PathErrorInternal("SHGetFolderPath() failed"); //< @fixme error message?
return agi::charset::ConvertW(path);
}
std::string get_install_path() {
static std::string install_path;
static bool install_path_valid = false;
if (install_path_valid == false) {
if (install_path.empty()) {
// Excerpt from <http://msdn.microsoft.com/en-us/library/bb776391.aspx>:
// lpCmdLine [in]
// If this parameter is an empty string the function returns
@ -69,53 +65,46 @@ std::string get_install_path() {
if (res > 0 && GetLastError() == 0) {
*fn = '\0'; // fn points to filename part of path, set an end marker there
install_path = agi::charset::ConvertW(std::wstring(path));
install_path_valid = true;
} else {
throw new agi::PathErrorInternal(agi::util::ErrorString(GetLastError()));
throw agi::PathErrorInternal(agi::util::ErrorString(GetLastError()));
}
}
return install_path;
}
};
}
namespace agi {
const std::string Path::Data() {
std::string Path::Data() {
return get_install_path();
}
const std::string Path::Doc() {
std::string path = Data();
path.append("docs\\");
return path;
std::string Path::Doc() {
return Data() + "docs\\";
}
const std::string Path::User() {
std::string Path::User() {
return WinGetFolderPath(CSIDL_PERSONAL);
}
const std::string Path::Locale() {
std::string path = Data();
path.append("locale\\");
return path;
std::string Path::Locale() {
return Data() + "locale\\";
}
const std::string Path::Config() {
std::string path = WinGetFolderPath(CSIDL_APPDATA);
path.append("Aegisub3");
std::string Path::Config() {
return WinGetFolderPath(CSIDL_APPDATA) + "Aegisub3";
/// @fixme should get version number in a more dynamic manner
return path;
}
const std::string Path::Temp() {
std::string Path::Temp() {
wchar_t path[MAX_PATH+1] = {0};
if (GetTempPath(MAX_PATH, path) == 0)
throw new PathErrorInternal(util::ErrorString(GetLastError()));
throw PathErrorInternal(util::ErrorString(GetLastError()));
else
return charset::ConvertW(std::wstring(path));
return charset::ConvertW(path);
}
} // namespace agi