Add file and dir temporary utilities

Co-authored by @Alex2782 for the Android bindings.
Many thanks to the reviewers also.

Co-authored-by: Alex <alex.hart.278@gmail.com>
This commit is contained in:
Adam Scott
2024-10-21 15:02:08 -04:00
parent d09d82d433
commit 1b3e483899
26 changed files with 331 additions and 7 deletions

View File

@ -2068,16 +2068,37 @@ String OS_Windows::get_cache_path() const {
if (has_environment("LOCALAPPDATA")) {
cache_path_cache = get_environment("LOCALAPPDATA").replace("\\", "/");
}
if (cache_path_cache.is_empty() && has_environment("TEMP")) {
cache_path_cache = get_environment("TEMP").replace("\\", "/");
}
if (cache_path_cache.is_empty()) {
cache_path_cache = get_config_path();
cache_path_cache = get_temp_path();
}
}
return cache_path_cache;
}
String OS_Windows::get_temp_path() const {
static String temp_path_cache;
if (temp_path_cache.is_empty()) {
{
Vector<WCHAR> temp_path;
// The maximum possible size is MAX_PATH+1 (261) + terminating null character.
temp_path.resize(MAX_PATH + 2);
DWORD temp_path_length = GetTempPathW(temp_path.size(), temp_path.ptrw());
if (temp_path_length > 0 && temp_path_length < temp_path.size()) {
temp_path_cache = String::utf16((const char16_t *)temp_path.ptr());
// Let's try to get the long path instead of the short path (with tildes ~).
DWORD temp_path_long_length = GetLongPathNameW(temp_path.ptr(), temp_path.ptrw(), temp_path.size());
if (temp_path_long_length > 0 && temp_path_long_length < temp_path.size()) {
temp_path_cache = String::utf16((const char16_t *)temp_path.ptr());
}
}
}
if (temp_path_cache.is_empty()) {
temp_path_cache = get_config_path();
}
}
return temp_path_cache;
}
// Get properly capitalized engine name for system paths
String OS_Windows::get_godot_dir_name() const {
return String(VERSION_SHORT_NAME).capitalize();