NetworkCaptureLogger: Allow PCAP shared read access on Windows

This commit is contained in:
Sepalani
2022-09-24 20:25:23 +04:00
parent 69ad2cc4d0
commit 481ddd1308
3 changed files with 26 additions and 8 deletions

View File

@ -35,9 +35,10 @@ IOFile::IOFile(std::FILE* file) : m_file(file), m_good(true)
{
}
IOFile::IOFile(const std::string& filename, const char openmode[]) : m_file(nullptr), m_good(true)
IOFile::IOFile(const std::string& filename, const char openmode[], SharedAccess sh)
: m_file(nullptr), m_good(true)
{
Open(filename, openmode);
Open(filename, openmode, sh);
}
IOFile::~IOFile()
@ -62,12 +63,21 @@ void IOFile::Swap(IOFile& other) noexcept
std::swap(m_good, other.m_good);
}
bool IOFile::Open(const std::string& filename, const char openmode[])
bool IOFile::Open(const std::string& filename, const char openmode[],
[[maybe_unused]] SharedAccess sh)
{
Close();
#ifdef _WIN32
m_good = _tfopen_s(&m_file, UTF8ToTStr(filename).c_str(), UTF8ToTStr(openmode).c_str()) == 0;
if (sh == SharedAccess::Default)
{
m_good = _tfopen_s(&m_file, UTF8ToTStr(filename).c_str(), UTF8ToTStr(openmode).c_str()) == 0;
}
else if (sh == SharedAccess::Read)
{
m_file = _tfsopen(UTF8ToTStr(filename).c_str(), UTF8ToTStr(openmode).c_str(), SH_DENYWR);
m_good = m_file != nullptr;
}
#else
#ifdef ANDROID
if (IsPathAndroidContent(filename))