mirror of https://github.com/odrling/Aegisub
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:
parent
9d1cdab638
commit
67e9384ef4
|
@ -291,10 +291,6 @@
|
||||||
RelativePath="..\..\libaegisub\common\log.cpp"
|
RelativePath="..\..\libaegisub\common\log.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath="..\..\libaegisub\common\util.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\libaegisub\common\mru.cpp"
|
RelativePath="..\..\libaegisub\common\mru.cpp"
|
||||||
>
|
>
|
||||||
|
@ -315,6 +311,10 @@
|
||||||
RelativePath="..\..\libaegisub\common\path.cpp"
|
RelativePath="..\..\libaegisub\common\path.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\libaegisub\common\util.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\libaegisub\common\validator.cpp"
|
RelativePath="..\..\libaegisub\common\validator.cpp"
|
||||||
>
|
>
|
||||||
|
@ -341,10 +341,6 @@
|
||||||
RelativePath="..\..\libaegisub\windows\io.cpp"
|
RelativePath="..\..\libaegisub\windows\io.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath="..\..\libaegisub\windows\path.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\libaegisub\windows\lagi_pre.cpp"
|
RelativePath="..\..\libaegisub\windows\lagi_pre.cpp"
|
||||||
>
|
>
|
||||||
|
@ -401,6 +397,10 @@
|
||||||
/>
|
/>
|
||||||
</FileConfiguration>
|
</FileConfiguration>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\libaegisub\windows\path_win.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\libaegisub\windows\util.cpp"
|
RelativePath="..\..\libaegisub\windows\util.cpp"
|
||||||
>
|
>
|
||||||
|
|
|
@ -42,7 +42,7 @@ Path::~Path() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const std::string Path::Get(const char *name) {
|
std::string Path::Get(const char *name) {
|
||||||
std::string path;
|
std::string path;
|
||||||
try {
|
try {
|
||||||
path = std::string(opt->Get(name)->GetString());
|
path = std::string(opt->Get(name)->GetString());
|
||||||
|
|
|
@ -48,7 +48,7 @@ public:
|
||||||
/// @brief Get a path, this is automatically decoded.
|
/// @brief Get a path, this is automatically decoded.
|
||||||
/// @param name Path to get
|
/// @param name Path to get
|
||||||
/// @return Full path name in UTF-8
|
/// @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.
|
/// @brief Set a path, this will be automaticalled encoded if a cookie matches.
|
||||||
/// @param[in] name Path name to save to.
|
/// @param[in] name Path name to save to.
|
||||||
|
@ -70,14 +70,14 @@ public:
|
||||||
/// Windows: Documents folder
|
/// Windows: Documents folder
|
||||||
/// OS X: ~/Documents
|
/// OS X: ~/Documents
|
||||||
/// Unix: ~ or Documents folder if set in the environment
|
/// Unix: ~ or Documents folder if set in the environment
|
||||||
const std::string Default();
|
std::string Default();
|
||||||
|
|
||||||
/// @brief Decode a path
|
/// @brief Decode a path
|
||||||
/// @param path Decode a path in-place.
|
/// @param path Decode a path in-place.
|
||||||
void Decode(std::string &path);
|
void Decode(std::string &path);
|
||||||
|
|
||||||
/// Configuration directory
|
/// Configuration directory
|
||||||
static const std::string Config();
|
static std::string Config();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Location of path config file.
|
/// Location of path config file.
|
||||||
|
@ -102,13 +102,13 @@ private:
|
||||||
/// @brief Locale files
|
/// @brief Locale files
|
||||||
/// @return Locale location
|
/// @return Locale location
|
||||||
/// This is directly assessibly as the Locale directory will never change on any platform.
|
/// This is directly assessibly as the Locale directory will never change on any platform.
|
||||||
const std::string Locale();
|
std::string Locale();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const std::string Data(); ///< Shared resources
|
std::string Data(); ///< Shared resources
|
||||||
const std::string Doc(); ///< Documents
|
std::string Doc(); ///< Documents
|
||||||
const std::string User(); ///< User config directory
|
std::string User(); ///< User config directory
|
||||||
const std::string Temp(); ///< Temporary storage
|
std::string Temp(); ///< Temporary storage
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace agi
|
} // namespace agi
|
||||||
|
|
|
@ -35,42 +35,41 @@
|
||||||
namespace agi {
|
namespace agi {
|
||||||
|
|
||||||
|
|
||||||
const std::string home() {
|
std::string home() {
|
||||||
char *ehome;
|
char *ehome;
|
||||||
ehome = getenv("HOME");
|
ehome = getenv("HOME");
|
||||||
if (ehome == NULL) {
|
if (ehome == NULL) {
|
||||||
printf("The HOME environment variable must be set\n");
|
printf("The HOME environment variable must be set\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
std::string home(ehome);
|
return ehome;
|
||||||
return home;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const std::string Path::Data() {
|
std::string Path::Data() {
|
||||||
return P_DATA;
|
return P_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string Path::Doc() {
|
std::string Path::Doc() {
|
||||||
return P_DOC;
|
return P_DOC;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string Path::User() {
|
std::string Path::User() {
|
||||||
return home();
|
return home();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string Path::Locale() {
|
std::string Path::Locale() {
|
||||||
return P_LOCALE;
|
return P_LOCALE;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string Path::Config() {
|
std::string Path::Config() {
|
||||||
std::string tmp(home());
|
std::string tmp(home());
|
||||||
tmp.append("/.aegisub-");
|
tmp.append("/.aegisub-");
|
||||||
tmp.append(AEGISUB_VERSION_DATA);
|
tmp.append(AEGISUB_VERSION_DATA);
|
||||||
return tmp.append("/");
|
return tmp.append("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string Path::Temp() {
|
std::string Path::Temp() {
|
||||||
return "/tmp/";
|
return "/tmp/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,14 +18,12 @@
|
||||||
/// @brief Common paths.
|
/// @brief Common paths.
|
||||||
/// @ingroup libaegisub
|
/// @ingroup libaegisub
|
||||||
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#ifndef LAGI_PRE
|
#ifndef LAGI_PRE
|
||||||
#include <string>
|
#include <string>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <libaegisub/path.h>
|
#include <libaegisub/path.h>
|
||||||
|
|
||||||
#include <libaegisub/charset_conv_win.h>
|
#include <libaegisub/charset_conv_win.h>
|
||||||
#include <libaegisub/util_win.h>
|
#include <libaegisub/util_win.h>
|
||||||
|
|
||||||
|
@ -34,7 +32,7 @@ namespace {
|
||||||
#include <Shlobj.h>
|
#include <Shlobj.h>
|
||||||
#include <Shellapi.h>
|
#include <Shellapi.h>
|
||||||
|
|
||||||
const std::string WinGetFolderPath(int folder) {
|
std::string WinGetFolderPath(int folder) {
|
||||||
wchar_t path[MAX_PATH+1] = {0};
|
wchar_t path[MAX_PATH+1] = {0};
|
||||||
HRESULT res = SHGetFolderPathW(
|
HRESULT res = SHGetFolderPathW(
|
||||||
0, // hwndOwner
|
0, // hwndOwner
|
||||||
|
@ -44,16 +42,14 @@ const std::string WinGetFolderPath(int folder) {
|
||||||
path // pszPath
|
path // pszPath
|
||||||
);
|
);
|
||||||
if (FAILED(res))
|
if (FAILED(res))
|
||||||
throw new agi::PathErrorInternal("SHGetFolderPath() failed"); //< @fixme error message?
|
throw agi::PathErrorInternal("SHGetFolderPath() failed"); //< @fixme error message?
|
||||||
else
|
|
||||||
return agi::charset::ConvertW(std::wstring(path));
|
return agi::charset::ConvertW(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string get_install_path() {
|
std::string get_install_path() {
|
||||||
static std::string install_path;
|
static std::string install_path;
|
||||||
static bool install_path_valid = false;
|
if (install_path.empty()) {
|
||||||
|
|
||||||
if (install_path_valid == false) {
|
|
||||||
// Excerpt from <http://msdn.microsoft.com/en-us/library/bb776391.aspx>:
|
// Excerpt from <http://msdn.microsoft.com/en-us/library/bb776391.aspx>:
|
||||||
// lpCmdLine [in]
|
// lpCmdLine [in]
|
||||||
// If this parameter is an empty string the function returns
|
// If this parameter is an empty string the function returns
|
||||||
|
@ -69,53 +65,46 @@ std::string get_install_path() {
|
||||||
if (res > 0 && GetLastError() == 0) {
|
if (res > 0 && GetLastError() == 0) {
|
||||||
*fn = '\0'; // fn points to filename part of path, set an end marker there
|
*fn = '\0'; // fn points to filename part of path, set an end marker there
|
||||||
install_path = agi::charset::ConvertW(std::wstring(path));
|
install_path = agi::charset::ConvertW(std::wstring(path));
|
||||||
install_path_valid = true;
|
|
||||||
} else {
|
} else {
|
||||||
throw new agi::PathErrorInternal(agi::util::ErrorString(GetLastError()));
|
throw agi::PathErrorInternal(agi::util::ErrorString(GetLastError()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return install_path;
|
return install_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace agi {
|
namespace agi {
|
||||||
|
|
||||||
const std::string Path::Data() {
|
std::string Path::Data() {
|
||||||
return get_install_path();
|
return get_install_path();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string Path::Doc() {
|
std::string Path::Doc() {
|
||||||
std::string path = Data();
|
return Data() + "docs\\";
|
||||||
path.append("docs\\");
|
|
||||||
return path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string Path::User() {
|
std::string Path::User() {
|
||||||
return WinGetFolderPath(CSIDL_PERSONAL);
|
return WinGetFolderPath(CSIDL_PERSONAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string Path::Locale() {
|
std::string Path::Locale() {
|
||||||
std::string path = Data();
|
return Data() + "locale\\";
|
||||||
path.append("locale\\");
|
|
||||||
return path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string Path::Config() {
|
std::string Path::Config() {
|
||||||
std::string path = WinGetFolderPath(CSIDL_APPDATA);
|
return WinGetFolderPath(CSIDL_APPDATA) + "Aegisub3";
|
||||||
path.append("Aegisub3");
|
|
||||||
/// @fixme should get version number in a more dynamic manner
|
/// @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};
|
wchar_t path[MAX_PATH+1] = {0};
|
||||||
if (GetTempPath(MAX_PATH, path) == 0)
|
if (GetTempPath(MAX_PATH, path) == 0)
|
||||||
throw new PathErrorInternal(util::ErrorString(GetLastError()));
|
throw PathErrorInternal(util::ErrorString(GetLastError()));
|
||||||
else
|
else
|
||||||
return charset::ConvertW(std::wstring(path));
|
return charset::ConvertW(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace agi
|
} // namespace agi
|
Loading…
Reference in New Issue