Rewrite FileSearch and improve ScanDirectoryTree.
- FileSearch is now just one function, and it converts the original glob into a regex on all platforms rather than relying on native Windows pattern matching on there and a complete hack elsewhere. It now supports recursion out of the box rather than manually expanding into a full list of directories in multiple call sites. - This adds a GCC >= 4.9 dependency due to older versions having outright broken <regex>. MSVC is fine with it. - ScanDirectoryTree returns the parent entry rather than filling parts of it in via reference. The count is now stored in the entry like it was for subdirectories. - .glsl file search is now done with DoFileSearch. - IOCTLV_READ_DIR now uses ScanDirectoryTree directly and sorts the results after replacements for better determinism.
This commit is contained in:
parent
6ff3fcee59
commit
a225426510
|
@ -2,101 +2,60 @@
|
|||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#if !__clang__ && __GNUC__ == 4 && __GNUC_MINOR__ < 9
|
||||
#error <regex> is broken in GCC < 4.9; please upgrade
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <regex>
|
||||
|
||||
#include "Common/CommonPaths.h"
|
||||
#include "Common/FileSearch.h"
|
||||
#include "Common/StringUtil.h"
|
||||
#include "Common/FileUtil.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <dirent.h>
|
||||
#else
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
CFileSearch::CFileSearch(const CFileSearch::XStringVector& _rSearchStrings, const CFileSearch::XStringVector& _rDirectories)
|
||||
static std::vector<std::string> FileSearchWithTest(const std::vector<std::string>& directories, bool recursive, std::function<bool(const File::FSTEntry &)> callback)
|
||||
{
|
||||
// Reverse the loop order for speed?
|
||||
for (auto& _rSearchString : _rSearchStrings)
|
||||
std::vector<std::string> result;
|
||||
for (const std::string& directory : directories)
|
||||
{
|
||||
for (auto& _rDirectory : _rDirectories)
|
||||
{
|
||||
FindFiles(_rSearchString, _rDirectory);
|
||||
}
|
||||
File::FSTEntry top = File::ScanDirectoryTree(directory, recursive);
|
||||
|
||||
std::function<void(File::FSTEntry&)> DoEntry;
|
||||
DoEntry = [&](File::FSTEntry& entry) {
|
||||
if (callback(entry))
|
||||
result.push_back(entry.physicalName);
|
||||
for (auto& child : entry.children)
|
||||
DoEntry(child);
|
||||
};
|
||||
DoEntry(top);
|
||||
}
|
||||
// remove duplicates
|
||||
std::sort(result.begin(), result.end());
|
||||
result.erase(std::unique(result.begin(), result.end()), result.end());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void CFileSearch::FindFiles(const std::string& _searchString, const std::string& _strPath)
|
||||
std::vector<std::string> DoFileSearch(const std::vector<std::string>& globs, const std::vector<std::string>& directories, bool recursive)
|
||||
{
|
||||
std::string GCMSearchPath;
|
||||
BuildCompleteFilename(GCMSearchPath, _strPath, _searchString);
|
||||
#ifdef _WIN32
|
||||
WIN32_FIND_DATA findData;
|
||||
HANDLE FindFirst = FindFirstFile(UTF8ToTStr(GCMSearchPath).c_str(), &findData);
|
||||
|
||||
if (FindFirst != INVALID_HANDLE_VALUE)
|
||||
std::string regex_str = "^(";
|
||||
for (const auto& str : globs)
|
||||
{
|
||||
bool bkeepLooping = true;
|
||||
|
||||
while (bkeepLooping)
|
||||
{
|
||||
if (findData.cFileName[0] != '.')
|
||||
{
|
||||
std::string strFilename;
|
||||
BuildCompleteFilename(strFilename, _strPath, TStrToUTF8(findData.cFileName));
|
||||
m_FileNames.push_back(strFilename);
|
||||
}
|
||||
|
||||
bkeepLooping = FindNextFile(FindFirst, &findData) ? true : false;
|
||||
}
|
||||
if (regex_str.size() != 2)
|
||||
regex_str += "|";
|
||||
// convert glob to regex
|
||||
regex_str += std::regex_replace(std::regex_replace(str, std::regex("\\."), "\\."), std::regex("\\*"), ".*");
|
||||
}
|
||||
FindClose(FindFirst);
|
||||
|
||||
|
||||
#else
|
||||
// TODO: super lame/broken
|
||||
|
||||
auto end_match(_searchString);
|
||||
|
||||
// assuming we have a "*.blah"-like pattern
|
||||
if (!end_match.empty() && end_match[0] == '*')
|
||||
end_match.erase(0, 1);
|
||||
|
||||
// ugly
|
||||
if (end_match == ".*")
|
||||
end_match.clear();
|
||||
|
||||
DIR* dir = opendir(_strPath.c_str());
|
||||
|
||||
if (!dir)
|
||||
return;
|
||||
|
||||
while (auto const dp = readdir(dir))
|
||||
{
|
||||
std::string found(dp->d_name);
|
||||
|
||||
if ((found != ".") && (found != "..") &&
|
||||
(found.size() >= end_match.size()) &&
|
||||
std::equal(end_match.rbegin(), end_match.rend(), found.rbegin()))
|
||||
{
|
||||
std::string full_name;
|
||||
if (_strPath.c_str()[_strPath.size() - 1] == DIR_SEP_CHR)
|
||||
full_name = _strPath + found;
|
||||
else
|
||||
full_name = _strPath + DIR_SEP + found;
|
||||
|
||||
m_FileNames.push_back(full_name);
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
#endif
|
||||
regex_str += ")$";
|
||||
std::regex regex(regex_str);
|
||||
return FileSearchWithTest(directories, recursive, [&](const File::FSTEntry& entry) {
|
||||
return std::regex_match(entry.virtualName, regex);
|
||||
});
|
||||
}
|
||||
|
||||
const CFileSearch::XStringVector& CFileSearch::GetFileNames() const
|
||||
std::vector<std::string> FindSubdirectories(const std::vector<std::string>& directories, bool recursive)
|
||||
{
|
||||
return m_FileNames;
|
||||
return FileSearchWithTest(directories, true, [&](const File::FSTEntry& entry) {
|
||||
return entry.isDirectory;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -7,18 +7,5 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class CFileSearch
|
||||
{
|
||||
public:
|
||||
typedef std::vector<std::string>XStringVector;
|
||||
|
||||
CFileSearch(const XStringVector& _rSearchStrings, const XStringVector& _rDirectories);
|
||||
const XStringVector& GetFileNames() const;
|
||||
|
||||
private:
|
||||
|
||||
void FindFiles(const std::string& _searchString, const std::string& _strPath);
|
||||
|
||||
XStringVector m_FileNames;
|
||||
};
|
||||
|
||||
std::vector<std::string> DoFileSearch(const std::vector<std::string>& globs, const std::vector<std::string>& directories, bool recursive = false);
|
||||
std::vector<std::string> FindSubdirectories(const std::vector<std::string>& directories, bool recursive);
|
||||
|
|
|
@ -453,11 +453,14 @@ bool CreateEmptyFile(const std::string &filename)
|
|||
|
||||
// Scans the directory tree gets, starting from _Directory and adds the
|
||||
// results into parentEntry. Returns the number of files+directories found
|
||||
u32 ScanDirectoryTree(const std::string &directory, FSTEntry& parentEntry)
|
||||
FSTEntry ScanDirectoryTree(const std::string &directory, bool recursive)
|
||||
{
|
||||
INFO_LOG(COMMON, "ScanDirectoryTree: directory %s", directory.c_str());
|
||||
// How many files + directories we found
|
||||
u32 foundEntries = 0;
|
||||
FSTEntry parent_entry;
|
||||
parent_entry.physicalName = directory;
|
||||
parent_entry.isDirectory = true;
|
||||
parent_entry.size = 0;
|
||||
#ifdef _WIN32
|
||||
// Find the first file in the directory.
|
||||
WIN32_FIND_DATA ffd;
|
||||
|
@ -466,59 +469,55 @@ u32 ScanDirectoryTree(const std::string &directory, FSTEntry& parentEntry)
|
|||
if (hFind == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
FindClose(hFind);
|
||||
return foundEntries;
|
||||
return parent_entry;
|
||||
}
|
||||
// Windows loop
|
||||
do
|
||||
{
|
||||
FSTEntry entry;
|
||||
const std::string virtualName(TStrToUTF8(ffd.cFileName));
|
||||
const std::string virtual_name(TStrToUTF8(ffd.cFileName));
|
||||
#else
|
||||
struct dirent dirent, *result = nullptr;
|
||||
|
||||
DIR *dirp = opendir(directory.c_str());
|
||||
if (!dirp)
|
||||
return 0;
|
||||
return parent_entry;
|
||||
|
||||
// non Windows loop
|
||||
while (!readdir_r(dirp, &dirent, &result) && result)
|
||||
{
|
||||
FSTEntry entry;
|
||||
const std::string virtualName(result->d_name);
|
||||
#endif
|
||||
// check for "." and ".."
|
||||
if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
|
||||
((virtualName[0] == '.') && (virtualName[1] == '.') &&
|
||||
(virtualName[2] == '\0')))
|
||||
continue;
|
||||
entry.virtualName = virtualName;
|
||||
entry.physicalName = directory;
|
||||
entry.physicalName += DIR_SEP + entry.virtualName;
|
||||
|
||||
if (IsDirectory(entry.physicalName))
|
||||
// non Windows loop
|
||||
while (!readdir_r(dirp, &dirent, &result) && result)
|
||||
{
|
||||
entry.isDirectory = true;
|
||||
// is a directory, lets go inside
|
||||
entry.size = ScanDirectoryTree(entry.physicalName, entry);
|
||||
foundEntries += (u32)entry.size;
|
||||
}
|
||||
else
|
||||
{ // is a file
|
||||
entry.isDirectory = false;
|
||||
entry.size = GetSize(entry.physicalName.c_str());
|
||||
}
|
||||
++foundEntries;
|
||||
// Push into the tree
|
||||
parentEntry.children.push_back(entry);
|
||||
#ifdef _WIN32
|
||||
} while (FindNextFile(hFind, &ffd) != 0);
|
||||
const std::string virtual_name(result->d_name);
|
||||
#endif
|
||||
if (virtual_name == "." || virtual_name == "..")
|
||||
continue;
|
||||
auto physical_name = directory + DIR_SEP + virtual_name;
|
||||
FSTEntry entry;
|
||||
entry.isDirectory = IsDirectory(physical_name);
|
||||
if (entry.isDirectory)
|
||||
{
|
||||
if (recursive)
|
||||
entry = ScanDirectoryTree(physical_name, true);
|
||||
else
|
||||
entry.size = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
entry.size = GetSize(physical_name);
|
||||
}
|
||||
entry.virtualName = virtual_name;
|
||||
entry.physicalName = physical_name;
|
||||
|
||||
++parent_entry.size;
|
||||
// Push into the tree
|
||||
parent_entry.children.push_back(entry);
|
||||
#ifdef _WIN32
|
||||
} while (FindNextFile(hFind, &ffd) != 0);
|
||||
FindClose(hFind);
|
||||
#else
|
||||
}
|
||||
closedir(dirp);
|
||||
#endif
|
||||
// Return number of entries found.
|
||||
return foundEntries;
|
||||
return parent_entry;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -107,9 +107,8 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename);
|
|||
// creates an empty file filename, returns true on success
|
||||
bool CreateEmptyFile(const std::string &filename);
|
||||
|
||||
// Scans the directory tree gets, starting from _Directory and adds the
|
||||
// results into parentEntry. Returns the number of files+directories found
|
||||
u32 ScanDirectoryTree(const std::string &directory, FSTEntry& parentEntry);
|
||||
// Recursive or non-recursive list of files under directory.
|
||||
FSTEntry ScanDirectoryTree(const std::string &directory, bool recursive);
|
||||
|
||||
// deletes the given directory and anything under it. Returns true on success.
|
||||
bool DeleteDirRecursively(const std::string &directory);
|
||||
|
|
|
@ -151,16 +151,7 @@ GCMemcardDirectory::GCMemcardDirectory(const std::string& directory, int slot, u
|
|||
hdrfile.ReadBytes(&m_hdr, BLOCK_SIZE);
|
||||
}
|
||||
|
||||
File::FSTEntry FST_Temp;
|
||||
File::ScanDirectoryTree(m_SaveDirectory, FST_Temp);
|
||||
|
||||
CFileSearch::XStringVector Directory;
|
||||
Directory.push_back(m_SaveDirectory);
|
||||
CFileSearch::XStringVector Extensions;
|
||||
Extensions.push_back("*.gci");
|
||||
|
||||
CFileSearch FileSearch(Extensions, Directory);
|
||||
const CFileSearch::XStringVector& rFilenames = FileSearch.GetFileNames();
|
||||
std::vector<std::string> rFilenames = DoFileSearch({"*.gci"}, {m_SaveDirectory});
|
||||
|
||||
if (rFilenames.size() > 112)
|
||||
{
|
||||
|
@ -170,7 +161,7 @@ GCMemcardDirectory::GCMemcardDirectory(const std::string& directory, int slot, u
|
|||
4000);
|
||||
}
|
||||
|
||||
for (auto gciFile : rFilenames)
|
||||
for (const std::string& gciFile : rFilenames)
|
||||
{
|
||||
if (m_saves.size() == DIRLEN)
|
||||
{
|
||||
|
|
|
@ -67,9 +67,8 @@ void CWiiSaveCrypted::ExportAllSaves()
|
|||
const u32 path_mask = 0x00010000;
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
File::FSTEntry fst_tmp;
|
||||
std::string folder = StringFromFormat("%s/%08x/", title_folder.c_str(), path_mask | i);
|
||||
File::ScanDirectoryTree(folder, fst_tmp);
|
||||
File::FSTEntry fst_tmp = File::ScanDirectoryTree(folder, false);
|
||||
|
||||
for (const File::FSTEntry& entry : fst_tmp.children)
|
||||
{
|
||||
|
@ -627,8 +626,7 @@ void CWiiSaveCrypted::ScanForFiles(const std::string& save_directory, std::vecto
|
|||
file_list.push_back(directories[i]);
|
||||
}
|
||||
|
||||
File::FSTEntry fst_tmp;
|
||||
File::ScanDirectoryTree(directories[i], fst_tmp);
|
||||
File::FSTEntry fst_tmp = File::ScanDirectoryTree(directories[i], false);
|
||||
for (const File::FSTEntry& elem : fst_tmp.children)
|
||||
{
|
||||
if (elem.virtualName != "banner.bin")
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#include "Common/ChunkFile.h"
|
||||
#include "Common/CommonPaths.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/FileSearch.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/NandPaths.h"
|
||||
#include "Common/StringUtil.h"
|
||||
|
@ -106,25 +105,28 @@ IPCCommandResult CWII_IPC_HLE_Device_fs::IOCtlV(u32 _CommandAddress)
|
|||
break;
|
||||
}
|
||||
|
||||
// make a file search
|
||||
CFileSearch::XStringVector Directories;
|
||||
Directories.push_back(DirName);
|
||||
|
||||
CFileSearch::XStringVector Extensions;
|
||||
Extensions.push_back("*.*");
|
||||
|
||||
CFileSearch FileSearch(Extensions, Directories);
|
||||
File::FSTEntry entry = File::ScanDirectoryTree(DirName, false);
|
||||
|
||||
// it is one
|
||||
if ((CommandBuffer.InBuffer.size() == 1) && (CommandBuffer.PayloadBuffer.size() == 1))
|
||||
{
|
||||
size_t numFile = FileSearch.GetFileNames().size();
|
||||
size_t numFile = entry.children.size();
|
||||
INFO_LOG(WII_IPC_FILEIO, "\t%lu files found", (unsigned long)numFile);
|
||||
|
||||
Memory::Write_U32((u32)numFile, CommandBuffer.PayloadBuffer[0].m_Address);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (File::FSTEntry& child : entry.children)
|
||||
{
|
||||
// Decode entities of invalid file system characters so that
|
||||
// games (such as HP:HBP) will be able to find what they expect.
|
||||
for (const Common::replace_t& r : replacements)
|
||||
child.virtualName = ReplaceAll(child.virtualName, r.second, {r.first});
|
||||
}
|
||||
|
||||
std::sort(entry.children.begin(), entry.children.end(), [](const File::FSTEntry& one, const File::FSTEntry& two) { return one.virtualName < two.virtualName; });
|
||||
|
||||
u32 MaxEntries = Memory::Read_U32(CommandBuffer.InBuffer[0].m_Address);
|
||||
|
||||
memset(Memory::GetPointer(CommandBuffer.PayloadBuffer[0].m_Address), 0, CommandBuffer.PayloadBuffer[0].m_Size);
|
||||
|
@ -132,22 +134,10 @@ IPCCommandResult CWII_IPC_HLE_Device_fs::IOCtlV(u32 _CommandAddress)
|
|||
size_t numFiles = 0;
|
||||
char* pFilename = (char*)Memory::GetPointer((u32)(CommandBuffer.PayloadBuffer[0].m_Address));
|
||||
|
||||
for (size_t i=0; i<FileSearch.GetFileNames().size(); i++)
|
||||
for (size_t i=0; i < entry.children.size() && i < MaxEntries; i++)
|
||||
{
|
||||
if (i >= MaxEntries)
|
||||
break;
|
||||
const std::string& FileName = entry.children[i].virtualName;
|
||||
|
||||
std::string name, ext;
|
||||
SplitPath(FileSearch.GetFileNames()[i], nullptr, &name, &ext);
|
||||
std::string FileName = name + ext;
|
||||
|
||||
// Decode entities of invalid file system characters so that
|
||||
// games (such as HP:HBP) will be able to find what they expect.
|
||||
for (const Common::replace_t& r : replacements)
|
||||
{
|
||||
for (size_t j = 0; (j = FileName.find(r.second, j)) != FileName.npos; ++j)
|
||||
FileName.replace(j, r.second.length(), 1, r.first);
|
||||
}
|
||||
|
||||
strcpy(pFilename, FileName.c_str());
|
||||
pFilename += FileName.length();
|
||||
|
@ -192,10 +182,9 @@ IPCCommandResult CWII_IPC_HLE_Device_fs::IOCtlV(u32 _CommandAddress)
|
|||
}
|
||||
else
|
||||
{
|
||||
File::FSTEntry parentDir;
|
||||
// add one for the folder itself, allows some games to create their save files
|
||||
// R8XE52 (Jurassic: The Hunted), STEETR (Tetris Party Deluxe) now create their saves with this change
|
||||
iNodes = 1 + File::ScanDirectoryTree(path, parentDir);
|
||||
File::FSTEntry parentDir = File::ScanDirectoryTree(path, true);
|
||||
// add one for the folder itself
|
||||
iNodes = 1 + (u32)parentDir.size;
|
||||
|
||||
u64 totalSize = ComputeTotalFileSize(parentDir); // "Real" size, to be converted to nand blocks
|
||||
|
||||
|
@ -542,8 +531,7 @@ void CWII_IPC_HLE_Device_fs::DoState(PointerWrap& p)
|
|||
{
|
||||
//recurse through tmp and save dirs and files
|
||||
|
||||
File::FSTEntry parentEntry;
|
||||
File::ScanDirectoryTree(Path, parentEntry);
|
||||
File::FSTEntry parentEntry = File::ScanDirectoryTree(Path, true);
|
||||
std::deque<File::FSTEntry> todo;
|
||||
todo.insert(todo.end(), parentEntry.children.begin(),
|
||||
parentEntry.children.end());
|
||||
|
|
|
@ -339,7 +339,7 @@ void CVolumeDirectory::BuildFST()
|
|||
File::FSTEntry rootEntry;
|
||||
|
||||
// read data from physical disk to rootEntry
|
||||
u32 totalEntries = AddDirectoryEntries(m_rootDirectory, rootEntry) + 1;
|
||||
u64 totalEntries = AddDirectoryEntries(m_rootDirectory, rootEntry) + 1;
|
||||
|
||||
m_fstNameOffset = totalEntries * ENTRY_SIZE; // offset in FST nameTable
|
||||
m_FSTData.resize(m_fstNameOffset + m_totalNameSize);
|
||||
|
@ -423,7 +423,7 @@ void CVolumeDirectory::Write32(u32 data, u32 offset, std::vector<u8>* const buff
|
|||
(*buffer)[offset] = (data) & 0xff;
|
||||
}
|
||||
|
||||
void CVolumeDirectory::WriteEntryData(u32& entryOffset, u8 type, u32 nameOffset, u64 dataOffset, u32 length)
|
||||
void CVolumeDirectory::WriteEntryData(u32& entryOffset, u8 type, u32 nameOffset, u64 dataOffset, u64 length)
|
||||
{
|
||||
m_FSTData[entryOffset++] = type;
|
||||
|
||||
|
@ -451,7 +451,7 @@ void CVolumeDirectory::WriteEntry(const File::FSTEntry& entry, u32& fstOffset, u
|
|||
{
|
||||
u32 myOffset = fstOffset;
|
||||
u32 myEntryNum = myOffset / ENTRY_SIZE;
|
||||
WriteEntryData(fstOffset, DIRECTORY_ENTRY, nameOffset, parentEntryNum, (u32)(myEntryNum + entry.size + 1));
|
||||
WriteEntryData(fstOffset, DIRECTORY_ENTRY, nameOffset, parentEntryNum, myEntryNum + entry.size + 1);
|
||||
WriteEntryName(nameOffset, entry.virtualName);
|
||||
|
||||
for (const auto& child : entry.children)
|
||||
|
@ -462,7 +462,7 @@ void CVolumeDirectory::WriteEntry(const File::FSTEntry& entry, u32& fstOffset, u
|
|||
else
|
||||
{
|
||||
// put entry in FST
|
||||
WriteEntryData(fstOffset, FILE_ENTRY, nameOffset, dataOffset, (u32)entry.size);
|
||||
WriteEntryData(fstOffset, FILE_ENTRY, nameOffset, dataOffset, entry.size);
|
||||
WriteEntryName(nameOffset, entry.virtualName);
|
||||
|
||||
// write entry to virtual disk
|
||||
|
@ -490,11 +490,11 @@ static u32 ComputeNameSize(const File::FSTEntry& parentEntry)
|
|||
return nameSize;
|
||||
}
|
||||
|
||||
u32 CVolumeDirectory::AddDirectoryEntries(const std::string& _Directory, File::FSTEntry& parentEntry)
|
||||
u64 CVolumeDirectory::AddDirectoryEntries(const std::string& _Directory, File::FSTEntry& parentEntry)
|
||||
{
|
||||
u32 foundEntries = ScanDirectoryTree(_Directory, parentEntry);
|
||||
parentEntry = File::ScanDirectoryTree(_Directory, true);
|
||||
m_totalNameSize += ComputeNameSize(parentEntry);
|
||||
return foundEntries;
|
||||
return parentEntry.size;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -75,12 +75,12 @@ private:
|
|||
void Write32(u32 data, u32 offset, std::vector<u8>* const buffer);
|
||||
|
||||
// FST creation
|
||||
void WriteEntryData(u32& entryOffset, u8 type, u32 nameOffset, u64 dataOffset, u32 length);
|
||||
void WriteEntryData(u32& entryOffset, u8 type, u32 nameOffset, u64 dataOffset, u64 length);
|
||||
void WriteEntryName(u32& nameOffset, const std::string& name);
|
||||
void WriteEntry(const File::FSTEntry& entry, u32& fstOffset, u32& nameOffset, u64& dataOffset, u32 parentEntryNum);
|
||||
|
||||
// returns number of entries found in _Directory
|
||||
u32 AddDirectoryEntries(const std::string& _Directory, File::FSTEntry& parentEntry);
|
||||
u64 AddDirectoryEntries(const std::string& _Directory, File::FSTEntry& parentEntry);
|
||||
|
||||
std::string m_rootDirectory;
|
||||
|
||||
|
|
|
@ -25,9 +25,9 @@ void AbstractGameList::RemoveGames(QList<GameFile*> items)
|
|||
|
||||
DGameTracker::DGameTracker(QWidget* parent_widget)
|
||||
: QStackedWidget(parent_widget),
|
||||
m_watcher(this)
|
||||
m_watcher(new QFileSystemWatcher(this))
|
||||
{
|
||||
connect(&m_watcher, SIGNAL(directoryChanged(QString)), this, SLOT(ScanForGames()));
|
||||
connect(m_watcher, SIGNAL(directoryChanged(QString)), this, SLOT(ScanForGames()));
|
||||
|
||||
m_tree_widget = new DGameTree(this);
|
||||
addWidget(m_tree_widget);
|
||||
|
@ -78,38 +78,20 @@ void DGameTracker::ScanForGames()
|
|||
{
|
||||
setDisabled(true);
|
||||
|
||||
CFileSearch::XStringVector dirs(SConfig::GetInstance().m_ISOFolder);
|
||||
|
||||
delete m_watcher;
|
||||
m_watcher = new QFileSystemWatcher(this);
|
||||
if (SConfig::GetInstance().m_RecursiveISOFolder)
|
||||
{
|
||||
for (u32 i = 0; i < dirs.size(); i++)
|
||||
{
|
||||
File::FSTEntry FST_Temp;
|
||||
File::ScanDirectoryTree(dirs[i], FST_Temp);
|
||||
for (auto& entry : FST_Temp.children)
|
||||
{
|
||||
if (entry.isDirectory)
|
||||
{
|
||||
bool duplicate = false;
|
||||
for (auto& dir : dirs)
|
||||
{
|
||||
if (dir == entry.physicalName)
|
||||
{
|
||||
duplicate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!duplicate)
|
||||
dirs.push_back(entry.physicalName);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (std::string dir : FindSubdirectories(SConfig::GetInstance().m_ISOFolder, /*recursive*/ true))
|
||||
m_watcher->addPath(QString::fromStdString(dir));
|
||||
}
|
||||
else
|
||||
{
|
||||
for (std::string dir : SConfig::GetInstance().m_ISOFolder)
|
||||
m_watcher->addPath(QString::fromStdString(dir));
|
||||
}
|
||||
|
||||
for (std::string& dir : dirs)
|
||||
m_watcher.addPath(QString::fromStdString(dir));
|
||||
|
||||
CFileSearch::XStringVector exts;
|
||||
std::vector<std::string> exts;
|
||||
if (SConfig::GetInstance().m_ListGC)
|
||||
{
|
||||
exts.push_back("*.gcm");
|
||||
|
@ -124,8 +106,7 @@ void DGameTracker::ScanForGames()
|
|||
if (SConfig::GetInstance().m_ListWad)
|
||||
exts.push_back("*.wad");
|
||||
|
||||
CFileSearch FileSearch(exts, dirs);
|
||||
const CFileSearch::XStringVector& rFilenames = FileSearch.GetFileNames();
|
||||
auto rFilenames = DoFileSearch(exts, SConfig::GetInstance().m_ISOFolder, SConfig::GetInstance().m_RecursiveISOFolder);
|
||||
QList<GameFile*> newItems;
|
||||
QStringList allItems;
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ public slots:
|
|||
|
||||
private:
|
||||
QMap<QString, GameFile*> m_games;
|
||||
QFileSystemWatcher m_watcher;
|
||||
QFileSystemWatcher* m_watcher;
|
||||
|
||||
GameListStyle m_current_style;
|
||||
DGameGrid* m_grid_widget = nullptr;
|
||||
|
|
|
@ -162,12 +162,10 @@ void InterfaceConfigPane::LoadGUIValues()
|
|||
|
||||
void InterfaceConfigPane::LoadThemes()
|
||||
{
|
||||
CFileSearch::XStringVector theme_dirs;
|
||||
theme_dirs.push_back(File::GetUserPath(D_THEMES_IDX));
|
||||
theme_dirs.push_back(File::GetSysDirectory() + THEMES_DIR);
|
||||
|
||||
CFileSearch cfs(CFileSearch::XStringVector(1, "*"), theme_dirs);
|
||||
auto const& sv = cfs.GetFileNames();
|
||||
auto sv = DoFileSearch({"*"}, {
|
||||
File::GetUserPath(D_THEMES_IDX),
|
||||
File::GetSysDirectory() + THEMES_DIR
|
||||
}, /*recursive*/ false);
|
||||
for (const std::string& filename : sv)
|
||||
{
|
||||
std::string name, ext;
|
||||
|
|
|
@ -1966,15 +1966,9 @@ void CFrame::GameListChanged(wxCommandEvent& event)
|
|||
SConfig::GetInstance().m_ListDrives = event.IsChecked();
|
||||
break;
|
||||
case IDM_PURGE_CACHE:
|
||||
CFileSearch::XStringVector Directories;
|
||||
Directories.push_back(File::GetUserPath(D_CACHE_IDX));
|
||||
CFileSearch::XStringVector Extensions;
|
||||
Extensions.push_back("*.cache");
|
||||
std::vector<std::string> rFilenames = DoFileSearch({"*.cache"}, {File::GetUserPath(D_CACHE_IDX)});
|
||||
|
||||
CFileSearch FileSearch(Extensions, Directories);
|
||||
const CFileSearch::XStringVector& rFilenames = FileSearch.GetFileNames();
|
||||
|
||||
for (auto& rFilename : rFilenames)
|
||||
for (const std::string& rFilename : rFilenames)
|
||||
{
|
||||
File::Delete(rFilename);
|
||||
}
|
||||
|
|
|
@ -466,35 +466,7 @@ void CGameListCtrl::ScanForISOs()
|
|||
{
|
||||
ClearIsoFiles();
|
||||
|
||||
CFileSearch::XStringVector Directories(SConfig::GetInstance().m_ISOFolder);
|
||||
|
||||
if (SConfig::GetInstance().m_RecursiveISOFolder)
|
||||
{
|
||||
for (u32 i = 0; i < Directories.size(); i++)
|
||||
{
|
||||
File::FSTEntry FST_Temp;
|
||||
File::ScanDirectoryTree(Directories[i], FST_Temp);
|
||||
for (auto& Entry : FST_Temp.children)
|
||||
{
|
||||
if (Entry.isDirectory)
|
||||
{
|
||||
bool duplicate = false;
|
||||
for (auto& Directory : Directories)
|
||||
{
|
||||
if (Directory == Entry.physicalName)
|
||||
{
|
||||
duplicate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!duplicate)
|
||||
Directories.push_back(Entry.physicalName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CFileSearch::XStringVector Extensions;
|
||||
std::vector<std::string> Extensions;
|
||||
|
||||
if (SConfig::GetInstance().m_ListGC)
|
||||
Extensions.push_back("*.gcm");
|
||||
|
@ -508,8 +480,7 @@ void CGameListCtrl::ScanForISOs()
|
|||
if (SConfig::GetInstance().m_ListWad)
|
||||
Extensions.push_back("*.wad");
|
||||
|
||||
CFileSearch FileSearch(Extensions, Directories);
|
||||
const CFileSearch::XStringVector& rFilenames = FileSearch.GetFileNames();
|
||||
auto rFilenames = DoFileSearch(Extensions, SConfig::GetInstance().m_ISOFolder, SConfig::GetInstance().m_RecursiveISOFolder);
|
||||
|
||||
if (rFilenames.size() > 0)
|
||||
{
|
||||
|
|
|
@ -172,18 +172,14 @@ void InputConfigDialog::UpdateProfileComboBox()
|
|||
pname += PROFILES_PATH;
|
||||
pname += m_config.profile_name;
|
||||
|
||||
CFileSearch::XStringVector exts;
|
||||
exts.push_back("*.ini");
|
||||
CFileSearch::XStringVector dirs;
|
||||
dirs.push_back(pname);
|
||||
CFileSearch cfs(exts, dirs);
|
||||
const CFileSearch::XStringVector& sv = cfs.GetFileNames();
|
||||
std::vector<std::string> sv = DoFileSearch({"*.ini"}, {pname});
|
||||
|
||||
wxArrayString strs;
|
||||
for (auto si = sv.cbegin(); si != sv.cend(); ++si)
|
||||
for (const std::string& filename : sv)
|
||||
{
|
||||
std::string str(si->begin() + si->find_last_of('/') + 1 , si->end() - 4) ;
|
||||
strs.push_back(StrToWxStr(str));
|
||||
std::string base;
|
||||
SplitPath(filename, nullptr, &base, nullptr);
|
||||
strs.push_back(StrToWxStr(base));
|
||||
}
|
||||
|
||||
for (GamepadPage* page : m_padpages)
|
||||
|
|
|
@ -38,9 +38,11 @@ Make AA apply instantly during gameplay if possible
|
|||
|
||||
#include <algorithm>
|
||||
#include <cstdarg>
|
||||
#include <regex>
|
||||
|
||||
#include "Common/Atomic.h"
|
||||
#include "Common/CommonPaths.h"
|
||||
#include "Common/FileSearch.h"
|
||||
#include "Common/Thread.h"
|
||||
#include "Common/Logging/LogManager.h"
|
||||
|
||||
|
@ -95,39 +97,16 @@ std::string VideoBackend::GetDisplayName() const
|
|||
return "OpenGL";
|
||||
}
|
||||
|
||||
static void GetShaders(std::vector<std::string> &shaders, const std::string &sub_dir = "")
|
||||
static std::vector<std::string> GetShaders(const std::string &sub_dir = "")
|
||||
{
|
||||
std::set<std::string> already_found;
|
||||
|
||||
shaders.clear();
|
||||
const std::string directories[] = {
|
||||
std::vector<std::string> paths = DoFileSearch({"*.glsl"}, {
|
||||
File::GetUserPath(D_SHADERS_IDX) + sub_dir,
|
||||
File::GetSysDirectory() + SHADERS_DIR DIR_SEP + sub_dir,
|
||||
};
|
||||
for (auto& directory : directories)
|
||||
{
|
||||
if (!File::IsDirectory(directory))
|
||||
continue;
|
||||
|
||||
File::FSTEntry entry;
|
||||
File::ScanDirectoryTree(directory, entry);
|
||||
for (auto& file : entry.children)
|
||||
{
|
||||
std::string name = file.virtualName;
|
||||
if (name.size() < 5)
|
||||
continue;
|
||||
if (strcasecmp(name.substr(name.size() - 5).c_str(), ".glsl"))
|
||||
continue;
|
||||
|
||||
name = name.substr(0, name.size() - 5);
|
||||
if (already_found.find(name) != already_found.end())
|
||||
continue;
|
||||
|
||||
already_found.insert(name);
|
||||
shaders.push_back(name);
|
||||
}
|
||||
}
|
||||
std::sort(shaders.begin(), shaders.end());
|
||||
File::GetSysDirectory() + SHADERS_DIR DIR_SEP + sub_dir
|
||||
});
|
||||
std::vector<std::string> result;
|
||||
for (std::string path : paths)
|
||||
result.push_back(std::regex_replace(path, std::regex("^.*/(.*)\\.glsl$"), "$1"));
|
||||
return result;
|
||||
}
|
||||
|
||||
static void InitBackendInfo()
|
||||
|
@ -146,8 +125,8 @@ static void InitBackendInfo()
|
|||
g_Config.backend_info.AAModes.assign(caamodes, caamodes + sizeof(caamodes)/sizeof(*caamodes));
|
||||
|
||||
// pp shaders
|
||||
GetShaders(g_Config.backend_info.PPShaders);
|
||||
GetShaders(g_Config.backend_info.AnaglyphShaders, std::string(ANAGLYPH_DIR DIR_SEP));
|
||||
g_Config.backend_info.PPShaders = GetShaders("");
|
||||
g_Config.backend_info.AnaglyphShaders = GetShaders(ANAGLYPH_DIR DIR_SEP);
|
||||
}
|
||||
|
||||
void VideoBackend::ShowConfig(void *_hParent)
|
||||
|
|
|
@ -79,38 +79,12 @@ void HiresTexture::Update()
|
|||
s_textureCache.clear();
|
||||
}
|
||||
|
||||
CFileSearch::XStringVector Directories;
|
||||
std::vector<std::string> Directories;
|
||||
const std::string& gameCode = SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID;
|
||||
|
||||
std::string szDir = StringFromFormat("%s%s", File::GetUserPath(D_HIRESTEXTURES_IDX).c_str(), gameCode.c_str());
|
||||
Directories.push_back(szDir);
|
||||
|
||||
for (u32 i = 0; i < Directories.size(); i++)
|
||||
{
|
||||
File::FSTEntry FST_Temp;
|
||||
File::ScanDirectoryTree(Directories[i], FST_Temp);
|
||||
for (auto& entry : FST_Temp.children)
|
||||
{
|
||||
if (entry.isDirectory)
|
||||
{
|
||||
bool duplicate = false;
|
||||
|
||||
for (auto& Directory : Directories)
|
||||
{
|
||||
if (Directory == entry.physicalName)
|
||||
{
|
||||
duplicate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!duplicate)
|
||||
Directories.push_back(entry.physicalName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CFileSearch::XStringVector Extensions = {
|
||||
std::vector<std::string> Extensions {
|
||||
"*.png",
|
||||
"*.bmp",
|
||||
"*.tga",
|
||||
|
@ -118,8 +92,7 @@ void HiresTexture::Update()
|
|||
"*.jpg" // Why not? Could be useful for large photo-like textures
|
||||
};
|
||||
|
||||
CFileSearch FileSearch(Extensions, Directories);
|
||||
const CFileSearch::XStringVector& rFilenames = FileSearch.GetFileNames();
|
||||
auto rFilenames = DoFileSearch(Extensions, {szDir}, /*recursive*/ true);
|
||||
|
||||
const std::string code = StringFromFormat("%s_", gameCode.c_str());
|
||||
const std::string code2 = "";
|
||||
|
@ -129,13 +102,8 @@ void HiresTexture::Update()
|
|||
std::string FileName;
|
||||
SplitPath(rFilename, nullptr, &FileName, nullptr);
|
||||
|
||||
if (FileName.substr(0, code.length()) == code)
|
||||
{
|
||||
s_textureMap[FileName] = rFilename;
|
||||
s_check_native_format = true;
|
||||
}
|
||||
|
||||
if (FileName.substr(0, s_format_prefix.length()) == s_format_prefix)
|
||||
if (FileName.substr(0, code.length()) == code ||
|
||||
FileName.substr(0, s_format_prefix.length()) == s_format_prefix)
|
||||
{
|
||||
s_textureMap[FileName] = rFilename;
|
||||
s_check_new_format = true;
|
||||
|
|
Loading…
Reference in New Issue