Remove MAX_PATH limit from:

- GetTempFilenameForAtomicWrite
- SetUserDirectory
This commit is contained in:
Silent 2019-10-06 21:37:51 +02:00
parent b6545ea285
commit 3b21d32865
No known key found for this signature in database
GPG Key ID: AE53149BB0C45AF1
3 changed files with 36 additions and 23 deletions

View File

@ -639,19 +639,21 @@ std::string CreateTempDir()
#endif
}
std::string GetTempFilenameForAtomicWrite(const std::string& path)
std::string GetTempFilenameForAtomicWrite(std::string path)
{
std::string abs = path;
#ifdef _WIN32
TCHAR absbuf[MAX_PATH];
if (_tfullpath(absbuf, UTF8ToTStr(path).c_str(), MAX_PATH) != nullptr)
abs = TStrToUTF8(absbuf);
std::unique_ptr<TCHAR[], decltype(&std::free)> absbuf{
_tfullpath(nullptr, UTF8ToTStr(path).c_str(), 0), std::free};
if (absbuf != nullptr)
{
path = TStrToUTF8(absbuf.get());
}
#else
char absbuf[PATH_MAX];
if (realpath(path.c_str(), absbuf) != nullptr)
abs = absbuf;
path = absbuf;
#endif
return abs + ".xxx";
return std::move(path) + ".xxx";
}
#if defined(__APPLE__)

View File

@ -172,7 +172,7 @@ bool SetCurrentDir(const std::string& directory);
std::string CreateTempDir();
// Get a filename that can hopefully be atomically renamed to the given path.
std::string GetTempFilenameForAtomicWrite(const std::string& path);
std::string GetTempFilenameForAtomicWrite(std::string path);
// Gets a set user directory path
// Don't call prior to setting the base user directory

View File

@ -211,46 +211,57 @@ void SetUserDirectory(const std::string& custom_path)
// -> Use GetExeDirectory()\User
// Check our registry keys
// TODO: Maybe use WIL when it's available?
HKEY hkey;
DWORD local = 0;
TCHAR configPath[MAX_PATH] = {0};
std::unique_ptr<TCHAR[]> configPath;
if (RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Dolphin Emulator"), 0, KEY_QUERY_VALUE,
&hkey) == ERROR_SUCCESS)
{
DWORD size = 4;
if (RegQueryValueEx(hkey, TEXT("LocalUserConfig"), nullptr, nullptr,
reinterpret_cast<LPBYTE>(&local), &size) != ERROR_SUCCESS)
{
local = 0;
}
size = 0;
RegQueryValueEx(hkey, TEXT("UserConfigPath"), nullptr, nullptr, nullptr, &size);
configPath = std::make_unique<TCHAR[]>(size / sizeof(TCHAR));
if (RegQueryValueEx(hkey, TEXT("UserConfigPath"), nullptr, nullptr,
reinterpret_cast<LPBYTE>(configPath.get()), &size) != ERROR_SUCCESS)
{
configPath.reset();
}
size = MAX_PATH;
if (RegQueryValueEx(hkey, TEXT("UserConfigPath"), nullptr, nullptr, (LPBYTE)configPath,
&size) != ERROR_SUCCESS)
configPath[0] = 0;
RegCloseKey(hkey);
}
local = local || File::Exists(File::GetExeDirectory() + DIR_SEP "portable.txt");
local = local != 0 || File::Exists(File::GetExeDirectory() + DIR_SEP "portable.txt");
// Get Program Files path in case we need it.
TCHAR my_documents[MAX_PATH];
bool my_documents_found = SUCCEEDED(
SHGetFolderPath(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, my_documents));
// Get Documents path in case we need it.
// TODO: Maybe use WIL when it's available?
PWSTR my_documents = nullptr;
bool my_documents_found =
SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_DEFAULT, nullptr, &my_documents));
if (local) // Case 1-2
user_path = File::GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP;
else if (configPath[0]) // Case 3
user_path = TStrToUTF8(configPath);
else if (configPath) // Case 3
user_path = TStrToUTF8(configPath.get());
else if (my_documents_found) // Case 4
user_path = TStrToUTF8(my_documents) + DIR_SEP "Dolphin Emulator" DIR_SEP;
else // Case 5
user_path = File::GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP;
CoTaskMemFree(my_documents);
// Prettify the path: it will be displayed in some places, we don't want a mix
// of \ and /.
user_path = ReplaceAll(user_path, "\\", DIR_SEP);
user_path = ReplaceAll(std::move(user_path), "\\", DIR_SEP);
// Make sure it ends in DIR_SEP.
if (*user_path.rbegin() != DIR_SEP_CHR)
if (user_path.back() != DIR_SEP_CHR)
user_path += DIR_SEP;
#else
@ -325,7 +336,7 @@ void SetUserDirectory(const std::string& custom_path)
#endif
}
#endif
File::SetUserPath(D_USER_IDX, user_path);
File::SetUserPath(D_USER_IDX, std::move(user_path));
}
void SaveWiimoteSources()