mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-03 13:31:27 +12:00
Changes done by [DH] rewritten
Added rsx_program_decompiler submodule Added fs::dir iterator Added fmt::match
This commit is contained in:
parent
e8310e6c50
commit
3ed603074c
105 changed files with 339 additions and 117 deletions
|
@ -797,6 +797,24 @@ bool fs::dir::read(std::string& name, stat_t& info)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool fs::dir::first(std::string& name, stat_t& info)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (m_path && m_dd != -1)
|
||||
{
|
||||
CHECK_ASSERTION(FindClose((HANDLE)m_dd));
|
||||
m_dd = -1;
|
||||
}
|
||||
#else
|
||||
if (m_path)
|
||||
{
|
||||
::rewinddir((DIR*)m_dd);
|
||||
}
|
||||
#endif
|
||||
|
||||
return read(name, info);
|
||||
}
|
||||
|
||||
std::string fs::get_config_dir()
|
||||
{
|
||||
// Use magic static for dir initialization
|
||||
|
|
|
@ -289,6 +289,78 @@ namespace fs
|
|||
|
||||
// Get next directory entry (UTF-8 name and file stat)
|
||||
bool read(std::string& name, stat_t& info);
|
||||
|
||||
bool first(std::string& name, stat_t& info);
|
||||
|
||||
struct entry
|
||||
{
|
||||
std::string name;
|
||||
stat_t info;
|
||||
};
|
||||
|
||||
class iterator
|
||||
{
|
||||
entry m_entry;
|
||||
dir* m_parent;
|
||||
|
||||
public:
|
||||
enum class mode
|
||||
{
|
||||
from_first,
|
||||
from_current
|
||||
};
|
||||
|
||||
iterator(dir* parent, mode mode_ = mode::from_first)
|
||||
: m_parent(parent)
|
||||
{
|
||||
if (!m_parent)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool is_ok;
|
||||
|
||||
if (mode_ == mode::from_first)
|
||||
{
|
||||
is_ok = m_parent->first(m_entry.name, m_entry.info);
|
||||
}
|
||||
else
|
||||
{
|
||||
is_ok = m_parent->read(m_entry.name, m_entry.info);
|
||||
}
|
||||
|
||||
if (!is_ok)
|
||||
{
|
||||
m_parent = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
entry& operator *()
|
||||
{
|
||||
return m_entry;
|
||||
}
|
||||
|
||||
iterator& operator++()
|
||||
{
|
||||
*this = { m_parent, mode::from_current };
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator !=(const iterator& rhs) const
|
||||
{
|
||||
return m_parent != rhs.m_parent;
|
||||
}
|
||||
};
|
||||
|
||||
iterator begin()
|
||||
{
|
||||
return{ this };
|
||||
}
|
||||
|
||||
iterator end()
|
||||
{
|
||||
return{ nullptr };
|
||||
}
|
||||
};
|
||||
|
||||
// Get configuration directory
|
||||
|
|
|
@ -259,3 +259,42 @@ std::string fmt::escape(std::string source)
|
|||
|
||||
return source;
|
||||
}
|
||||
|
||||
bool fmt::match(const std::string &source, const std::string &mask)
|
||||
{
|
||||
std::size_t source_position = 0, mask_position = 0;
|
||||
|
||||
for (; source_position < source.size() && mask_position < mask.size(); ++mask_position, ++source_position)
|
||||
{
|
||||
switch (mask[mask_position])
|
||||
{
|
||||
case '?': break;
|
||||
|
||||
case '*':
|
||||
for (std::size_t test_source_position = source_position; test_source_position < source.size(); ++test_source_position)
|
||||
{
|
||||
if (match(source.substr(test_source_position), mask.substr(mask_position + 1)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
default:
|
||||
if (source[source_position] != mask[mask_position])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (source_position != source.size())
|
||||
return false;
|
||||
|
||||
if (mask_position != mask.size())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -354,4 +354,5 @@ namespace fmt
|
|||
std::string tolower(std::string source);
|
||||
std::string toupper(std::string source);
|
||||
std::string escape(std::string source);
|
||||
bool match(const std::string &source, const std::string &mask);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue