Common: Purge pxStreams and some other wx string routines

This commit is contained in:
Connor McLaughlin 2022-04-12 00:21:03 +10:00 committed by refractionpcsx2
parent 1bfc0f3138
commit 876ea3db52
21 changed files with 30 additions and 545 deletions

View File

@ -27,7 +27,6 @@ target_sources(common PRIVATE
PrecompiledHeader.cpp
Perf.cpp
ProgressCallback.cpp
pxStreams.cpp
pxTranslate.cpp
RwMutex.cpp
Semaphore.cpp
@ -84,7 +83,6 @@ target_sources(common PRIVATE
PrecompiledHeader.h
ProgressCallback.h
pxForwardDefs.h
pxStreams.h
RedtapeWindows.h
RwMutex.h
SafeArray.h
@ -98,7 +96,6 @@ target_sources(common PRIVATE
Threading.h
TraceLog.h
WindowInfo.h
wxBaseTools.h
emitter/cpudetect_internal.h
emitter/implement/dwshift.h
emitter/implement/group1.h

View File

@ -27,7 +27,6 @@
#include "common/Threading.h"
#include "common/ThreadingInternal.h"
#include "common/wxBaseTools.h"
// --------------------------------------------------------------------------------------
// Semaphore Implementation for Darwin/OSX

View File

@ -14,7 +14,6 @@
*/
#include "common/Threading.h"
#include "common/wxBaseTools.h"
#include "common/ThreadingInternal.h"
namespace Threading

View File

@ -16,7 +16,6 @@
#if !defined(__APPLE__)
#include "common/Threading.h"
#include "common/wxBaseTools.h"
#include "common/ThreadingInternal.h"
// --------------------------------------------------------------------------------------

View File

@ -231,23 +231,6 @@ bool TryParse(wxRect& dest, const wxString& src, const wxRect& defval, const wxS
return true;
}
// returns TRUE if the parse is valid, or FALSE if it's a comment.
bool pxParseAssignmentString(const wxString& src, wxString& ldest, wxString& rdest)
{
if (src.StartsWith(L"--") || src.StartsWith(L"//") || src.StartsWith(L";"))
return false;
ldest = src.BeforeFirst(L'=').Trim(true).Trim(false);
rdest = src.AfterFirst(L'=').Trim(true).Trim(false);
return true;
}
ParsedAssignmentString::ParsedAssignmentString(const wxString& src)
{
IsComment = pxParseAssignmentString(src, lvalue, rvalue);
}
// Performs a cross-platform puts operation, which adds CRs to naked LFs on Win32 platforms,
// so that Notepad won't throw a fit and Rama can read the logs again! On Unix and Mac platforms,
// the input string is written unmodified.

View File

@ -28,46 +28,6 @@
#define WX_STR(str) (static_cast<const char*>(str.c_str()))
#endif
// --------------------------------------------------------------------------------------
// pxToUTF8
// --------------------------------------------------------------------------------------
// Converts a string to UTF8 and provides an interface for getting its length.
class pxToUTF8
{
DeclareNoncopyableObject(pxToUTF8);
protected:
wxCharBuffer m_result;
int m_length;
public:
explicit pxToUTF8(const wxString& src)
: m_result(src.ToUTF8())
{
m_length = -1;
}
size_t Length()
{
if (-1 == m_length)
m_length = strlen(m_result);
return m_length;
}
void Convert(const wxString& src)
{
m_result = src.ToUTF8();
m_length = -1;
}
const char* data() const { return m_result; }
operator const char*() const
{
return m_result.data();
}
};
extern void px_fputs(FILE* fp, const char* src);
// wxWidgets lacks one of its own...
@ -88,28 +48,6 @@ extern bool TryParse(wxPoint& dest, const wxString& src, const wxPoint& defval =
extern bool TryParse(wxSize& dest, const wxString& src, const wxSize& defval = wxDefaultSize, const wxString& separators = L",");
extern bool TryParse(wxRect& dest, const wxString& src, const wxRect& defval = wxDefaultRect, const wxString& separators = L",");
// --------------------------------------------------------------------------------------
// ParsedAssignmentString
// --------------------------------------------------------------------------------------
// This class is a simple helper for parsing INI-style assignments, in the typical form of:
// variable = value
// filename = SomeString.txt
// integer = 15
//
// This parser supports both '//' and ';' at the head of a line as indicators of a commented
// line, and such a line will return empty strings for l- and r-value.
//
// No type handling is performed -- the user must manually parse strings into integers, etc.
// For advanced "fully functional" ini file parsing, consider using wxFileConfig instead.
//
struct ParsedAssignmentString
{
wxString lvalue;
wxString rvalue;
bool IsComment;
ParsedAssignmentString(const wxString& src);
};
// ======================================================================================
// FastFormatAscii / FastFormatUnicode (overview!)
@ -221,8 +159,6 @@ public:
FastFormatUnicode& operator+=(const char* psz);
};
extern bool pxParseAssignmentString(const wxString& src, wxString& ldest, wxString& rdest);
#define pxsFmt FastFormatUnicode().Write
#define pxsFmtV FastFormatUnicode().WriteV
#define pxsPtr(ptr) pxsFmt("0x%016" PRIXPTR, (ptr)).c_str()

View File

@ -18,7 +18,6 @@
#endif
#include "common/PersistentThread.h"
#include "common/wxBaseTools.h"
#include "common/ThreadingInternal.h"
#include "common/EventSource.inl"
#include "common/General.h"

View File

@ -61,7 +61,6 @@
<ClCompile Include="IniInterface.cpp" />
<ClCompile Include="MD5Digest.cpp" />
<ClCompile Include="ProgressCallback.cpp" />
<ClCompile Include="pxStreams.cpp" />
<ClCompile Include="pxTranslate.cpp" />
<ClCompile Include="StringUtil.cpp" />
<ClCompile Include="SettingsWrapper.cpp" />
@ -161,7 +160,6 @@
<ClInclude Include="Vulkan\Texture.h" />
<ClInclude Include="Vulkan\Util.h" />
<ClInclude Include="WindowInfo.h" />
<ClInclude Include="wxBaseTools.h" />
<ClInclude Include="Threading.h" />
<ClInclude Include="PersistentThread.h" />
<ClInclude Include="RwMutex.h" />

View File

@ -67,9 +67,6 @@
<ClCompile Include="PrecompiledHeader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="pxStreams.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="pxTranslate.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@ -309,9 +306,6 @@
<ClInclude Include="emitter\tools.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="wxBaseTools.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="emitter\x86emitter.h">
<Filter>Header Files</Filter>
</ClInclude>

View File

@ -1,257 +0,0 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2010 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <errno.h>
#include <wx/stream.h>
#include "common/wxBaseTools.h"
#include "common/pxStreams.h"
#include "common/StringHelpers.h"
// --------------------------------------------------------------------------------------
// pxStreamBase (implementations)
// --------------------------------------------------------------------------------------
pxStreamBase::pxStreamBase(const wxString& filename)
: m_filename(filename)
{
}
bool pxStreamBase::IsOk() const
{
wxStreamBase* woot = GetWxStreamBase();
return woot && woot->IsOk();
}
wxFileOffset pxStreamBase::Length() const
{
if (!GetWxStreamBase())
return 0;
return GetWxStreamBase()->GetLength();
}
// --------------------------------------------------------------------------------------
// pxInputStream (implementations)
// --------------------------------------------------------------------------------------
// Interface for reading data from a gzip stream.
//
pxInputStream::pxInputStream(const wxString& filename, std::unique_ptr<wxInputStream>& input)
: pxStreamBase(filename)
, m_stream_in(std::move(input))
{
}
pxInputStream::pxInputStream(const wxString& filename, wxInputStream* input)
: pxStreamBase(filename)
, m_stream_in(input)
{
}
wxStreamBase* pxInputStream::GetWxStreamBase() const { return m_stream_in.get(); }
wxFileOffset pxInputStream::Tell() const
{
return m_stream_in->TellI();
}
wxFileOffset pxInputStream::Seek(wxFileOffset ofs, wxSeekMode mode)
{
return m_stream_in->SeekI(ofs, mode);
}
void pxInputStream::SetStream(const wxString& filename, std::unique_ptr<wxInputStream>& stream)
{
m_filename = filename;
m_stream_in = std::move(stream);
}
void pxInputStream::SetStream(const wxString& filename, wxInputStream* stream)
{
m_filename = filename;
m_stream_in = std::unique_ptr<wxInputStream>(stream);
}
void pxInputStream::Read(void* dest, size_t size)
{
m_stream_in->Read(dest, size);
if (m_stream_in->GetLastError() == wxSTREAM_READ_ERROR)
{
int err = errno;
if (!err)
throw Exception::BadStream(m_filename).SetDiagMsg(L"Cannot read from file (bad file handle?)");
ScopedExcept ex(Exception::FromErrno(m_filename, err));
ex->SetDiagMsg(L"cannot read from file: " + ex->DiagMsg());
ex->Rethrow();
}
// IMPORTANT! The underlying file/source Eof() stuff is not really reliable, so we
// must always use the explicit check against the number of bytes read to determine
// end-of-stream conditions.
if ((size_t)m_stream_in->LastRead() < size)
throw Exception::EndOfStream(m_filename);
}
// --------------------------------------------------------------------------------------
// pxOutputStream
// --------------------------------------------------------------------------------------
pxOutputStream::pxOutputStream(const wxString& filename, std::unique_ptr<wxOutputStream>& output)
: pxStreamBase(filename)
, m_stream_out(std::move(output))
{
}
pxOutputStream::pxOutputStream(const wxString& filename, wxOutputStream* output)
: pxStreamBase(filename)
, m_stream_out(output)
{
}
wxStreamBase* pxOutputStream::GetWxStreamBase() const { return m_stream_out.get(); }
wxFileOffset pxOutputStream::Tell() const
{
return m_stream_out->TellO();
}
wxFileOffset pxOutputStream::Seek(wxFileOffset ofs, wxSeekMode mode)
{
return m_stream_out->SeekO(ofs, mode);
}
void pxOutputStream::SetStream(const wxString& filename, std::unique_ptr<wxOutputStream>& stream)
{
m_filename = filename;
m_stream_out = std::move(stream);
}
void pxOutputStream::SetStream(const wxString& filename, wxOutputStream* stream)
{
m_filename = filename;
m_stream_out = std::unique_ptr<wxOutputStream>(stream);
}
void pxOutputStream::Write(const void* src, size_t size)
{
m_stream_out->Write(src, size);
if (m_stream_out->GetLastError() == wxSTREAM_WRITE_ERROR)
{
int err = errno;
if (!err)
throw Exception::BadStream(m_filename).SetDiagMsg(L"Cannot write to file/stream.");
ScopedExcept ex(Exception::FromErrno(m_filename, err));
ex->SetDiagMsg(L"Cannot write to file: " + ex->DiagMsg());
ex->Rethrow();
}
}
// --------------------------------------------------------------------------------------
// pxTextStream
// --------------------------------------------------------------------------------------
// Returns TRUE if the source is UTF8, or FALSE if it's just ASCII crap.
bool pxReadLine(wxInputStream& input, std::string& dest)
{
dest.clear();
bool isUTF8 = false;
while (true)
{
char c;
input.Read(&c, sizeof(c));
if (c == 0)
break;
if (input.Eof())
break;
if (c == '\n')
break; // eat on UNIX
if (c == '\r')
{
input.Read(&c, sizeof(c));
if (c == 0)
break;
if (input.Eof())
break;
if (c == '\n')
break;
input.Ungetch(c);
break;
}
dest += c;
if (c & 0x80)
isUTF8 = true;
}
return isUTF8;
}
void pxReadLine(wxInputStream& input, wxString& dest, std::string& intermed)
{
dest.clear();
if (pxReadLine(input, intermed))
dest = fromUTF8(intermed.c_str());
else
{
// Optimized ToAscii conversion.
// wx3.0 : NOT COMPATIBLE!! (on linux anyway)
const char* ascii = intermed.c_str();
while (*ascii != 0)
dest += (wchar_t)(unsigned char)*ascii++;
}
}
void pxReadLine(wxInputStream& input, wxString& dest)
{
std::string line;
pxReadLine(input, dest, line);
}
wxString pxReadLine(wxInputStream& input)
{
wxString result;
pxReadLine(input, result);
return result;
}
void pxWriteLine(wxOutputStream& output)
{
output.Write("\n", 1);
}
void pxWriteLine(wxOutputStream& output, const wxString& text)
{
if (!text.IsEmpty())
{
pxToUTF8 utf8(text);
output.Write(utf8, utf8.Length());
}
pxWriteLine(output);
}
void pxWriteMultiline(wxOutputStream& output, const wxString& src)
{
if (src.IsEmpty())
return;
wxString result(src);
result.Replace(L"\r\n", L"\n");
result.Replace(L"\r", L"\n");
pxToUTF8 utf8(result);
output.Write(utf8, utf8.Length());
}

View File

@ -1,119 +0,0 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2010 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <wx/stream.h>
#include <wx/filefn.h>
#include <memory>
#include "Dependencies.h"
// --------------------------------------------------------------------------------------
// pxStreamBase
// --------------------------------------------------------------------------------------
class pxStreamBase
{
DeclareNoncopyableObject(pxStreamBase);
protected:
// Filename of the stream, provided by the creator/caller. This is typically used *only*
// for generating comprehensive error messages when an error occurs (the stream name is
// passed to the exception handlers).
wxString m_filename;
public:
pxStreamBase(const wxString& filename);
virtual ~pxStreamBase() = default;
// Implementing classes should return the base wxStream object (usually either a wxInputStream
// or wxOputStream derivative).
virtual wxStreamBase* GetWxStreamBase() const = 0;
virtual void Close() = 0;
virtual wxFileOffset Tell() const = 0;
virtual wxFileOffset Seek(wxFileOffset ofs, wxSeekMode mode = wxFromStart) = 0;
virtual wxFileOffset Length() const;
bool IsOk() const;
wxString GetStreamName() const { return m_filename; }
};
// --------------------------------------------------------------------------------------
// pxOutputStream
// --------------------------------------------------------------------------------------
class pxOutputStream : public pxStreamBase
{
DeclareNoncopyableObject(pxOutputStream);
protected:
std::unique_ptr<wxOutputStream> m_stream_out;
public:
pxOutputStream(const wxString& filename, std::unique_ptr<wxOutputStream>& output);
pxOutputStream(const wxString& filename, wxOutputStream* output);
virtual ~pxOutputStream() = default;
virtual void Write(const void* data, size_t size);
void SetStream(const wxString& filename, std::unique_ptr<wxOutputStream>& stream);
void SetStream(const wxString& filename, wxOutputStream* stream);
void Close() { m_stream_out = nullptr; }
virtual wxStreamBase* GetWxStreamBase() const;
template <typename T>
void Write(const T& data)
{
Write(&data, sizeof(data));
}
wxFileOffset Tell() const;
wxFileOffset Seek(wxFileOffset ofs, wxSeekMode mode = wxFromStart);
};
// --------------------------------------------------------------------------------------
// pxInputStream
// --------------------------------------------------------------------------------------
class pxInputStream : public pxStreamBase
{
DeclareNoncopyableObject(pxInputStream);
protected:
std::unique_ptr<wxInputStream> m_stream_in;
public:
pxInputStream(const wxString& filename, std::unique_ptr<wxInputStream>& input);
pxInputStream(const wxString& filename, wxInputStream* input);
virtual ~pxInputStream() = default;
virtual void Read(void* dest, size_t size);
void SetStream(const wxString& filename, std::unique_ptr<wxInputStream>& stream);
void SetStream(const wxString& filename, wxInputStream* stream);
void Close() { m_stream_in = nullptr; }
virtual wxStreamBase* GetWxStreamBase() const;
template <typename T>
void Read(T& dest)
{
Read(&dest, sizeof(dest));
}
wxFileOffset Tell() const;
wxFileOffset Seek(wxFileOffset ofs, wxSeekMode mode = wxFromStart);
};

View File

@ -1,65 +0,0 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2010 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "common/Dependencies.h"
// --------------------------------------------------------------------------------------
// wxBaseTools.h
//
// This file is meant to contain utility classes for users of the wxWidgets library.
// All classes in this file are strictly dependent on wxBase libraries only, meaning
// you don't need to include or link against wxCore (GUI) to build them. For tools
// which require wxCore, see wxGuiTools.h
// --------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------
// wxDoNotLogInThisScope
// --------------------------------------------------------------------------------------
// This class is used to disable wx's sometimes inappropriate amount of forced error logging
// during specific activities. For example, when using wxDynamicLibrary to detect the
// validity of DLLs, wx will log errors for missing symbols. (sigh)
//
// Usage: Basic auto-cleanup destructor class. Create an instance inside a scope, and
// logging will be re-enabled when scope is terminated. :)
//
class wxDoNotLogInThisScope
{
DeclareNoncopyableObject(wxDoNotLogInThisScope);
protected:
bool m_prev;
public:
wxDoNotLogInThisScope()
{
m_prev = wxLog::EnableLogging(false);
}
virtual ~wxDoNotLogInThisScope()
{
wxLog::EnableLogging(m_prev);
}
};
extern wxString pxReadLine(wxInputStream& input);
extern void pxReadLine(wxInputStream& input, wxString& dest);
extern void pxReadLine(wxInputStream& input, wxString& dest, std::string& intermed);
extern bool pxReadLine(wxInputStream& input, std::string& dest);
extern void pxWriteLine(wxOutputStream& output);
extern void pxWriteLine(wxOutputStream& output, const wxString& text);
extern void pxWriteMultiline(wxOutputStream& output, const wxString& src);

View File

@ -29,8 +29,6 @@
#include "Renderers/HW/GSTextureReplacements.h"
#include "GSLzma.h"
#include "common/pxStreams.h"
#include "common/pxStreams.h"
#include "common/Console.h"
#include "common/StringUtil.h"
#include "pcsx2/Config.h"

View File

@ -28,7 +28,6 @@
#include "common/Pcsx2Defs.h"
#include "bitwise.h"
#include "common/pxStreams.h"
#include "common/Console.h"
#include "common/mt_queue.h"
#include "DebugTools/Debug.h"

View File

@ -20,7 +20,6 @@
#include <wx/intl.h>
#include <wx/log.h>
#include <wx/filename.h>
#include "common/pxStreams.h"
#include "common/Console.h"
#include <stdio.h>
#include <assert.h>

View File

@ -70,7 +70,6 @@
#include "PCSX2Base.h"
#include "gui/i18n.h"
#include "common/wxBaseTools.h"
#include "common/Path.h"
#include "common/Console.h"
#include "common/MemcpyFast.h"

View File

@ -28,7 +28,6 @@
#include "Host/Dialogs.h"
#endif
#include "R3000A.h"
#include "common/pxStreams.h"
using namespace Threading;

View File

@ -20,7 +20,6 @@
#include <cassert>
#include "PrecompiledHeader.h"
#include "common/pxStreams.h"
#include "common/WindowInfo.h"
#include "USB.h"
#include "qemu-usb/USBinternal.h"

View File

@ -18,7 +18,6 @@
#include "gui/App.h"
#include "ConfigurationDialog.h"
#include "gui/Panels/ConfigurationPanels.h"
#include "common/pxStreams.h"
#include "GS/GSLzma.h"
#include <wx/wizard.h>

View File

@ -16,6 +16,7 @@
#include "PrecompiledHeader.h"
#include "i18n.h"
#include "AppConfig.h"
#include "wxGuiTools.h"
#include "common/SafeArray.h"
#include <memory>

View File

@ -776,6 +776,35 @@ public:
static void SetManualBusyCursor(BusyCursorType busytype);
};
// --------------------------------------------------------------------------------------
// wxDoNotLogInThisScope
// --------------------------------------------------------------------------------------
// This class is used to disable wx's sometimes inappropriate amount of forced error logging
// during specific activities. For example, when using wxDynamicLibrary to detect the
// validity of DLLs, wx will log errors for missing symbols. (sigh)
//
// Usage: Basic auto-cleanup destructor class. Create an instance inside a scope, and
// logging will be re-enabled when scope is terminated. :)
//
class wxDoNotLogInThisScope
{
DeclareNoncopyableObject(wxDoNotLogInThisScope);
protected:
bool m_prev;
public:
wxDoNotLogInThisScope()
{
m_prev = wxLog::EnableLogging(false);
}
virtual ~wxDoNotLogInThisScope()
{
wxLog::EnableLogging(m_prev);
}
};
// --------------------------------------------------------------------------------------
// pxFitToDigits
// --------------------------------------------------------------------------------------