RelayFile/Util/Util.h

82 lines
1.8 KiB
C
Raw Normal View History

2025-05-05 23:22:43 +08:00
#ifndef REMOTE_TRAN_UTIL
#define REMOTE_TRAN_UTIL
#include <mutex>
#include <vector>
2025-05-09 22:31:51 +08:00
#include <wx/wx.h>
2025-05-05 23:22:43 +08:00
constexpr int MAX_BUFFER_SIZE = 1024 * 1024 * 10;
class TranUtil
{
public:
TranUtil();
};
2025-05-11 00:00:10 +08:00
class MLogFormatter : public wxLogFormatter
{
public:
wxString Format(wxLogLevel level, const wxString& msg, const wxLogRecordInfo& info) const override
{
wxDateTime time(info.timestampMS / 1000);
time.SetMillisecond(info.timestampMS % 1000);
auto timeStr = time.Format(wxT("%H:%M:%S.%l"));
wxString levelStr;
switch (level) {
case wxLOG_FatalError:
levelStr = "FATAL";
break;
case wxLOG_Error:
levelStr = "ERROR";
break;
case wxLOG_Warning:
levelStr = "WARN";
break;
case wxLOG_Message:
levelStr = "INFO";
break;
case wxLOG_Status:
levelStr = "STATUS";
break;
case wxLOG_Info:
levelStr = "INFO";
break;
case wxLOG_Debug:
levelStr = "DEBUG";
break;
case wxLOG_Trace:
levelStr = "TRACE";
break;
default:
levelStr = "OTHER";
break;
}
return wxString::Format("[%s][%s] %s", timeStr, levelStr, msg);
}
};
2025-05-05 23:22:43 +08:00
class MutBuffer
{
public:
MutBuffer() = default;
public:
void Push(const char* data, int len);
int IndexOf(const char* data, int len, int start_pos = 0);
const char* GetData() const;
int Length() const;
void RemoveOf(int start_pos, int len);
void Clear();
private:
std::vector<char> buffer_;
};
2025-05-09 22:31:51 +08:00
class wxUtil
{
public:
static wxString GetConfigDir();
static bool CreateConfigDir(const wxString& dir, const wxString& name, wxString& fullPath);
};
2025-05-05 23:22:43 +08:00
#endif // REMOTE_TRAN_UTIL