41
src/poly/fs.h
Normal file
41
src/poly/fs.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2015 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef POLY_FS_H_
|
||||
#define POLY_FS_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "poly/config.h"
|
||||
#include "poly/string.h"
|
||||
|
||||
namespace poly {
|
||||
namespace fs {
|
||||
|
||||
bool PathExists(const std::wstring& path);
|
||||
|
||||
bool CreateFolder(const std::wstring& path);
|
||||
|
||||
bool DeleteFolder(const std::wstring& path);
|
||||
|
||||
struct FileInfo {
|
||||
enum class Type {
|
||||
kFile,
|
||||
kDirectory,
|
||||
};
|
||||
Type type;
|
||||
std::wstring name;
|
||||
size_t total_size;
|
||||
};
|
||||
std::vector<FileInfo> ListFiles(const std::wstring& path);
|
||||
|
||||
} // namespace fs
|
||||
} // namespace poly
|
||||
|
||||
#endif // POLY_FS_H_
|
||||
70
src/poly/fs_win.cc
Normal file
70
src/poly/fs_win.cc
Normal file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2015 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include "poly/fs.h"
|
||||
|
||||
#include <shellapi.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "poly/platform.h"
|
||||
|
||||
namespace poly {
|
||||
namespace fs {
|
||||
|
||||
bool PathExists(const std::wstring& path) {
|
||||
DWORD attrib = GetFileAttributes(path.c_str());
|
||||
return attrib != INVALID_FILE_ATTRIBUTES;
|
||||
}
|
||||
|
||||
bool CreateFolder(const std::wstring& path) {
|
||||
wchar_t folder[MAX_PATH] = {0};
|
||||
auto end = std::wcschr(path.c_str(), L'\\');
|
||||
while (end) {
|
||||
wcsncpy(folder, path.c_str(), end - path.c_str() + 1);
|
||||
CreateDirectory(folder, NULL);
|
||||
end = wcschr(++end, L'\\');
|
||||
}
|
||||
return PathExists(path);
|
||||
}
|
||||
|
||||
bool DeleteFolder(const std::wstring& path) {
|
||||
auto double_null_path = path + L"\0";
|
||||
SHFILEOPSTRUCT op = {0};
|
||||
op.wFunc = FO_DELETE;
|
||||
op.pFrom = double_null_path.c_str();
|
||||
op.fFlags = FOF_NO_UI;
|
||||
return SHFileOperation(&op) == 0;
|
||||
}
|
||||
|
||||
std::vector<FileInfo> ListFiles(const std::wstring& path) {
|
||||
std::vector<FileInfo> result;
|
||||
|
||||
WIN32_FIND_DATA ffd;
|
||||
HANDLE handle = FindFirstFile(path.c_str(), &ffd);
|
||||
if (handle == INVALID_HANDLE_VALUE) {
|
||||
return result;
|
||||
}
|
||||
do {
|
||||
FileInfo info;
|
||||
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||||
info.type = FileInfo::Type::kDirectory;
|
||||
} else {
|
||||
info.type = FileInfo::Type::kFile;
|
||||
info.total_size = (ffd.nFileSizeHigh * (MAXDWORD + 1)) + ffd.nFileSizeLow;
|
||||
}
|
||||
result.push_back(info);
|
||||
} while (FindNextFile(handle, &ffd) != 0);
|
||||
FindClose(handle);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace fs
|
||||
} // namespace poly
|
||||
@@ -8,6 +8,7 @@
|
||||
'delegate.h',
|
||||
'config.h',
|
||||
'cxx_compat.h',
|
||||
'fs.h',
|
||||
'logging.cc',
|
||||
'logging.h',
|
||||
'main.h',
|
||||
@@ -45,6 +46,7 @@
|
||||
['OS == "win"', {
|
||||
'sources': [
|
||||
'debugging_win.cc',
|
||||
'fs_win.cc',
|
||||
'main_win.cc',
|
||||
'mapped_memory_win.cc',
|
||||
'threading_win.cc',
|
||||
|
||||
Reference in New Issue
Block a user