Misc: Remove unused code
This commit is contained in:
@ -23,19 +23,6 @@
|
||||
#include <share.h>
|
||||
#include <shlobj.h>
|
||||
#include <winioctl.h>
|
||||
|
||||
#if defined(_UWP)
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#include <winrt/Windows.ApplicationModel.h>
|
||||
#include <winrt/Windows.Devices.Enumeration.h>
|
||||
#include <winrt/Windows.Foundation.Collections.h>
|
||||
#include <winrt/Windows.Foundation.h>
|
||||
#include <winrt/Windows.Storage.FileProperties.h>
|
||||
#include <winrt/Windows.Storage.Search.h>
|
||||
#include <winrt/Windows.Storage.h>
|
||||
#endif
|
||||
|
||||
#else
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
@ -514,7 +501,7 @@ std::vector<std::string> FileSystem::GetRootDirectoryList()
|
||||
{
|
||||
std::vector<std::string> results;
|
||||
|
||||
#if defined(_WIN32) && !defined(_UWP)
|
||||
#if defined(_WIN32)
|
||||
char buf[256];
|
||||
const DWORD size = GetLogicalDriveStringsA(sizeof(buf), buf);
|
||||
if (size != 0 && size < (sizeof(buf) - 1))
|
||||
@ -527,28 +514,6 @@ std::vector<std::string> FileSystem::GetRootDirectoryList()
|
||||
ptr += len + 1u;
|
||||
}
|
||||
}
|
||||
#elif defined(_UWP)
|
||||
if (const auto install_location = winrt::Windows::ApplicationModel::Package::Current().InstalledLocation();
|
||||
install_location)
|
||||
{
|
||||
if (const auto path = install_location.Path(); !path.empty())
|
||||
results.push_back(StringUtil::WideStringToUTF8String(path));
|
||||
}
|
||||
|
||||
if (const auto local_location = winrt::Windows::Storage::ApplicationData::Current().LocalFolder(); local_location)
|
||||
{
|
||||
if (const auto path = local_location.Path(); !path.empty())
|
||||
results.push_back(StringUtil::WideStringToUTF8String(path));
|
||||
}
|
||||
|
||||
const auto devices = winrt::Windows::Storage::KnownFolders::RemovableDevices();
|
||||
const auto folders_task(devices.GetFoldersAsync());
|
||||
for (const auto& storage_folder : folders_task.get())
|
||||
{
|
||||
const auto path = storage_folder.Path();
|
||||
if (!path.empty())
|
||||
results.push_back(StringUtil::WideStringToUTF8String(path));
|
||||
}
|
||||
#else
|
||||
const char* home_path = std::getenv("HOME");
|
||||
if (home_path)
|
||||
@ -588,127 +553,6 @@ std::string Path::Combine(const std::string_view& base, const std::string_view&
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef _UWP
|
||||
static std::FILE* OpenCFileUWP(const wchar_t* wfilename, const wchar_t* mode, FileSystem::FileShareMode share_mode)
|
||||
{
|
||||
DWORD access = 0;
|
||||
DWORD share = 0;
|
||||
DWORD disposition = 0;
|
||||
|
||||
switch (share_mode)
|
||||
{
|
||||
case FileSystem::FileShareMode::DenyNone:
|
||||
share = FILE_SHARE_READ | FILE_SHARE_WRITE;
|
||||
break;
|
||||
case FileSystem::FileShareMode::DenyRead:
|
||||
share = FILE_SHARE_WRITE;
|
||||
break;
|
||||
case FileSystem::FileShareMode::DenyWrite:
|
||||
share = FILE_SHARE_READ;
|
||||
break;
|
||||
case FileSystem::FileShareMode::DenyReadWrite:
|
||||
default:
|
||||
share = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
int flags = 0;
|
||||
const wchar_t* tmode = mode;
|
||||
while (*tmode)
|
||||
{
|
||||
if (*tmode == L'r' && *(tmode + 1) == L'+')
|
||||
{
|
||||
access = GENERIC_READ | GENERIC_WRITE;
|
||||
disposition = OPEN_EXISTING;
|
||||
flags |= _O_RDWR;
|
||||
tmode += 2;
|
||||
}
|
||||
else if (*tmode == L'w' && *(tmode + 1) == L'+')
|
||||
{
|
||||
access = GENERIC_READ | GENERIC_WRITE;
|
||||
disposition = CREATE_ALWAYS;
|
||||
flags |= _O_RDWR | _O_CREAT | _O_TRUNC;
|
||||
tmode += 2;
|
||||
}
|
||||
else if (*tmode == L'a' && *(tmode + 1) == L'+')
|
||||
{
|
||||
access = GENERIC_READ | GENERIC_WRITE;
|
||||
disposition = CREATE_ALWAYS;
|
||||
flags |= _O_RDWR | _O_APPEND | _O_CREAT | _O_TRUNC;
|
||||
tmode += 2;
|
||||
}
|
||||
else if (*tmode == L'r')
|
||||
{
|
||||
access = GENERIC_READ;
|
||||
disposition = OPEN_EXISTING;
|
||||
flags |= _O_RDONLY;
|
||||
tmode++;
|
||||
}
|
||||
else if (*tmode == L'w')
|
||||
{
|
||||
access = GENERIC_WRITE;
|
||||
disposition = CREATE_ALWAYS;
|
||||
flags |= _O_WRONLY | _O_CREAT | _O_TRUNC;
|
||||
tmode++;
|
||||
}
|
||||
else if (*tmode == L'a')
|
||||
{
|
||||
access = GENERIC_READ | GENERIC_WRITE;
|
||||
disposition = CREATE_ALWAYS;
|
||||
flags |= _O_WRONLY | _O_APPEND | _O_CREAT | _O_TRUNC;
|
||||
tmode++;
|
||||
}
|
||||
else if (*tmode == L'b')
|
||||
{
|
||||
flags |= _O_BINARY;
|
||||
tmode++;
|
||||
}
|
||||
else if (*tmode == L'S')
|
||||
{
|
||||
flags |= _O_SEQUENTIAL;
|
||||
tmode++;
|
||||
}
|
||||
else if (*tmode == L'R')
|
||||
{
|
||||
flags |= _O_RANDOM;
|
||||
tmode++;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log_ErrorPrintf("Unknown mode flags: '%s'", StringUtil::WideStringToUTF8String(mode).c_str());
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
HANDLE hFile = CreateFileFromAppW(wfilename, access, share, nullptr, disposition, 0, nullptr);
|
||||
if (hFile == INVALID_HANDLE_VALUE)
|
||||
return nullptr;
|
||||
|
||||
if (flags & _O_APPEND && !SetFilePointerEx(hFile, LARGE_INTEGER{}, nullptr, FILE_END))
|
||||
{
|
||||
Log_ErrorPrintf("SetFilePointerEx() failed: %08X", GetLastError());
|
||||
CloseHandle(hFile);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int fd = _open_osfhandle(reinterpret_cast<intptr_t>(hFile), flags);
|
||||
if (fd < 0)
|
||||
{
|
||||
CloseHandle(hFile);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::FILE* fp = _wfdopen(fd, mode);
|
||||
if (!fp)
|
||||
{
|
||||
_close(fd);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return fp;
|
||||
}
|
||||
#endif // _UWP
|
||||
|
||||
std::FILE* FileSystem::OpenCFile(const char* filename, const char* mode)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
@ -718,13 +562,7 @@ std::FILE* FileSystem::OpenCFile(const char* filename, const char* mode)
|
||||
{
|
||||
std::FILE* fp;
|
||||
if (_wfopen_s(&fp, wfilename.c_str(), wmode.c_str()) != 0)
|
||||
{
|
||||
#ifdef _UWP
|
||||
return OpenCFileUWP(wfilename.c_str(), wmode.c_str(), FileShareMode::DenyReadWrite);
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
return fp;
|
||||
}
|
||||
@ -744,10 +582,7 @@ int FileSystem::OpenFDFile(const char* filename, int flags, int mode)
|
||||
#ifdef _WIN32
|
||||
const std::wstring wfilename(StringUtil::UTF8StringToWideString(filename));
|
||||
if (!wfilename.empty())
|
||||
{
|
||||
// TODO: UWP
|
||||
return _wopen(wfilename.c_str(), flags, mode);
|
||||
}
|
||||
|
||||
return -1;
|
||||
#else
|
||||
@ -792,11 +627,7 @@ std::FILE* FileSystem::OpenSharedCFile(const char* filename, const char* mode, F
|
||||
if (fp)
|
||||
return fp;
|
||||
|
||||
#ifdef _UWP
|
||||
return OpenCFileUWP(wfilename.c_str(), wmode.c_str(), share_mode);
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
#else
|
||||
return std::fopen(filename, mode);
|
||||
#endif
|
||||
@ -1023,19 +854,6 @@ static u32 TranslateWin32Attributes(u32 Win32Attributes)
|
||||
return r;
|
||||
}
|
||||
|
||||
static DWORD WrapGetFileAttributes(const wchar_t* path)
|
||||
{
|
||||
#ifndef _UWP
|
||||
return GetFileAttributesW(path);
|
||||
#else
|
||||
WIN32_FILE_ATTRIBUTE_DATA fad;
|
||||
if (!GetFileAttributesExFromAppW(path, GetFileExInfoStandard, &fad))
|
||||
return INVALID_FILE_ATTRIBUTES;
|
||||
|
||||
return fad.dwFileAttributes;
|
||||
#endif
|
||||
}
|
||||
|
||||
static u32 RecursiveFindFiles(const char* origin_path, const char* parent_path, const char* path, const char* pattern,
|
||||
u32 flags, FileSystem::FindResultsArray* results)
|
||||
{
|
||||
@ -1057,12 +875,7 @@ static u32 RecursiveFindFiles(const char* origin_path, const char* parent_path,
|
||||
std::string utf8_filename;
|
||||
utf8_filename.reserve((sizeof(wfd.cFileName) / sizeof(wfd.cFileName[0])) * 2);
|
||||
|
||||
#ifndef _UWP
|
||||
HANDLE hFind = FindFirstFileW(StringUtil::UTF8StringToWideString(tempStr).c_str(), &wfd);
|
||||
#else
|
||||
HANDLE hFind = FindFirstFileExFromAppW(StringUtil::UTF8StringToWideString(tempStr).c_str(), FindExInfoBasic, &wfd,
|
||||
FindExSearchNameMatch, nullptr, 0);
|
||||
#endif
|
||||
|
||||
if (hFind == INVALID_HANDLE_VALUE)
|
||||
return 0;
|
||||
@ -1244,7 +1057,6 @@ bool FileSystem::StatFile(const char* path, FILESYSTEM_STAT_DATA* sd)
|
||||
if (wpath.empty())
|
||||
return false;
|
||||
|
||||
#ifndef _UWP
|
||||
// determine attributes for the path. if it's a directory, things have to be handled differently..
|
||||
DWORD fileAttributes = GetFileAttributesW(wpath.c_str());
|
||||
if (fileAttributes == INVALID_FILE_ATTRIBUTES)
|
||||
@ -1284,17 +1096,6 @@ bool FileSystem::StatFile(const char* path, FILESYSTEM_STAT_DATA* sd)
|
||||
sd->ModificationTime = ConvertFileTimeToUnixTime(bhfi.ftLastWriteTime);
|
||||
sd->Size = static_cast<s64>(((u64)bhfi.nFileSizeHigh) << 32 | (u64)bhfi.nFileSizeLow);
|
||||
return true;
|
||||
#else
|
||||
WIN32_FILE_ATTRIBUTE_DATA fad;
|
||||
if (!GetFileAttributesExFromAppW(wpath.c_str(), GetFileExInfoStandard, &fad))
|
||||
return false;
|
||||
|
||||
sd->Attributes = TranslateWin32Attributes(fad.dwFileAttributes);
|
||||
sd->CreationTime = ConvertFileTimeToUnixTime(fad.ftCreationTime);
|
||||
sd->ModificationTime = ConvertFileTimeToUnixTime(fad.ftLastWriteTime);
|
||||
sd->Size = static_cast<s64>(((u64)fad.nFileSizeHigh) << 32 | (u64)fad.nFileSizeLow);
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool FileSystem::StatFile(std::FILE* fp, FILESYSTEM_STAT_DATA* sd)
|
||||
@ -1335,7 +1136,7 @@ bool FileSystem::FileExists(const char* path)
|
||||
return false;
|
||||
|
||||
// determine attributes for the path. if it's a directory, things have to be handled differently..
|
||||
DWORD fileAttributes = WrapGetFileAttributes(wpath.c_str());
|
||||
DWORD fileAttributes = GetFileAttributesW(wpath.c_str());
|
||||
if (fileAttributes == INVALID_FILE_ATTRIBUTES)
|
||||
return false;
|
||||
|
||||
@ -1357,7 +1158,7 @@ bool FileSystem::DirectoryExists(const char* path)
|
||||
return false;
|
||||
|
||||
// determine attributes for the path. if it's a directory, things have to be handled differently..
|
||||
DWORD fileAttributes = WrapGetFileAttributes(wpath.c_str());
|
||||
DWORD fileAttributes = GetFileAttributesW(wpath.c_str());
|
||||
if (fileAttributes == INVALID_FILE_ATTRIBUTES)
|
||||
return false;
|
||||
|
||||
@ -1373,11 +1174,7 @@ bool FileSystem::DirectoryIsEmpty(const char* path)
|
||||
wpath += L"\\*";
|
||||
|
||||
WIN32_FIND_DATAW wfd;
|
||||
#ifndef _UWP
|
||||
HANDLE hFind = FindFirstFileW(wpath.c_str(), &wfd);
|
||||
#else
|
||||
HANDLE hFind = FindFirstFileExFromAppW(wpath.c_str(), FindExInfoBasic, &wfd, FindExSearchNameMatch, nullptr, 0);
|
||||
#endif
|
||||
|
||||
if (hFind == INVALID_HANDLE_VALUE)
|
||||
return true;
|
||||
@ -1406,14 +1203,9 @@ bool FileSystem::CreateDirectory(const char* Path, bool Recursive)
|
||||
if (wpath.empty())
|
||||
return false;
|
||||
|
||||
// try just flat-out, might work if there's no other segments that have to be made
|
||||
#ifndef _UWP
|
||||
// try just flat-out, might work if there's no other segments that have to be made
|
||||
if (CreateDirectoryW(wpath.c_str(), nullptr))
|
||||
return true;
|
||||
#else
|
||||
if (CreateDirectoryFromAppW(wpath.c_str(), nullptr))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
if (!Recursive)
|
||||
return false;
|
||||
@ -1423,7 +1215,7 @@ bool FileSystem::CreateDirectory(const char* Path, bool Recursive)
|
||||
if (lastError == ERROR_ALREADY_EXISTS)
|
||||
{
|
||||
// check the attributes
|
||||
u32 Attributes = WrapGetFileAttributes(wpath.c_str());
|
||||
u32 Attributes = GetFileAttributesW(wpath.c_str());
|
||||
if (Attributes != INVALID_FILE_ATTRIBUTES && Attributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
return true;
|
||||
else
|
||||
@ -1442,11 +1234,7 @@ bool FileSystem::CreateDirectory(const char* Path, bool Recursive)
|
||||
{
|
||||
if (wpath[i] == L'\\' || wpath[i] == L'/')
|
||||
{
|
||||
#ifndef _UWP
|
||||
const BOOL result = CreateDirectoryW(tempPath.c_str(), nullptr);
|
||||
#else
|
||||
const BOOL result = CreateDirectoryFromAppW(tempPath.c_str(), nullptr);
|
||||
#endif
|
||||
if (!result)
|
||||
{
|
||||
lastError = GetLastError();
|
||||
@ -1466,11 +1254,7 @@ bool FileSystem::CreateDirectory(const char* Path, bool Recursive)
|
||||
// re-create the end if it's not a separator, check / as well because windows can interpret them
|
||||
if (wpath[pathLength - 1] != L'\\' && wpath[pathLength - 1] != L'/')
|
||||
{
|
||||
#ifndef _UWP
|
||||
const BOOL result = CreateDirectoryW(wpath.c_str(), nullptr);
|
||||
#else
|
||||
const BOOL result = CreateDirectoryFromAppW(wpath.c_str(), nullptr);
|
||||
#endif
|
||||
if (!result)
|
||||
{
|
||||
lastError = GetLastError();
|
||||
@ -1495,15 +1279,11 @@ bool FileSystem::DeleteFile(const char* path)
|
||||
return false;
|
||||
|
||||
const std::wstring wpath(StringUtil::UTF8StringToWideString(path));
|
||||
const DWORD fileAttributes = WrapGetFileAttributes(wpath.c_str());
|
||||
const DWORD fileAttributes = GetFileAttributesW(wpath.c_str());
|
||||
if (fileAttributes == INVALID_FILE_ATTRIBUTES || fileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
return false;
|
||||
|
||||
#ifndef _UWP
|
||||
return (DeleteFileW(wpath.c_str()) == TRUE);
|
||||
#else
|
||||
return (DeleteFileFromAppW(wpath.c_str()) == TRUE);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool FileSystem::RenamePath(const char* old_path, const char* new_path)
|
||||
@ -1511,29 +1291,11 @@ bool FileSystem::RenamePath(const char* old_path, const char* new_path)
|
||||
const std::wstring old_wpath(StringUtil::UTF8StringToWideString(old_path));
|
||||
const std::wstring new_wpath(StringUtil::UTF8StringToWideString(new_path));
|
||||
|
||||
#ifndef _UWP
|
||||
if (!MoveFileExW(old_wpath.c_str(), new_wpath.c_str(), MOVEFILE_REPLACE_EXISTING))
|
||||
{
|
||||
Log_ErrorPrintf("MoveFileEx('%s', '%s') failed: %08X", old_path, new_path, GetLastError());
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
// try moving if it doesn't exist, since ReplaceFile fails on non-existing destinations
|
||||
if (WrapGetFileAttributes(new_wpath.c_str()) != INVALID_FILE_ATTRIBUTES)
|
||||
{
|
||||
if (!DeleteFileFromAppW(new_wpath.c_str()))
|
||||
{
|
||||
Log_ErrorPrintf("DeleteFileFromAppW('%s') failed: %08X", new_wpath.c_str(), GetLastError());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!MoveFileFromAppW(old_wpath.c_str(), new_wpath.c_str()))
|
||||
{
|
||||
Log_ErrorPrintf("MoveFileFromAppW('%s', '%s') failed: %08X", old_path, new_path, GetLastError());
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1551,10 +1313,8 @@ std::string FileSystem::GetProgramPath()
|
||||
|
||||
// Fall back to the main module if this fails.
|
||||
HMODULE module = nullptr;
|
||||
#ifndef _UWP
|
||||
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
||||
reinterpret_cast<LPCWSTR>(&GetProgramPath), &module);
|
||||
#endif
|
||||
|
||||
for (;;)
|
||||
{
|
||||
@ -1610,13 +1370,8 @@ bool FileSystem::SetPathCompression(const char* path, bool enable)
|
||||
const bool isFile = !(attrs & FILE_ATTRIBUTE_DIRECTORY);
|
||||
const DWORD flags = isFile ? FILE_ATTRIBUTE_NORMAL : (FILE_FLAG_BACKUP_SEMANTICS | FILE_ATTRIBUTE_DIRECTORY);
|
||||
|
||||
#ifndef _UWP
|
||||
const HANDLE handle = CreateFileW(wpath.c_str(), FILE_GENERIC_WRITE | FILE_GENERIC_READ,
|
||||
FILE_SHARE_READ | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, flags, nullptr);
|
||||
#else
|
||||
const HANDLE handle = CreateFileFromAppW(wpath.c_str(), FILE_GENERIC_WRITE | FILE_GENERIC_READ,
|
||||
FILE_SHARE_READ | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, flags, nullptr);
|
||||
#endif
|
||||
if (handle == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user