Skip to content

Commit

Permalink
Save network log to file
Browse files Browse the repository at this point in the history
  • Loading branch information
zenden2k committed Jan 25, 2025
1 parent 8c4da64 commit be9e0a8
Show file tree
Hide file tree
Showing 9 changed files with 488 additions and 366 deletions.
368 changes: 204 additions & 164 deletions Lang/imageuploader.pot

Large diffs are not rendered by default.

370 changes: 205 additions & 165 deletions Lang/locale/ru/LC_MESSAGES/imageuploader.po

Large diffs are not rendered by default.

29 changes: 27 additions & 2 deletions Source/Gui/Dialogs/NetworkDebugDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "Core/Settings/WtlGuiSettings.h"
#include "Func/WebUtils.h"
#include "Core/3rdpart/Hexdump.hpp"
#include "Gui/Components/MyFileDialog.h"
#include "Core/Utils/IOException.h"

CNetworkDebugDlg::CNetworkDebugDlg()
: model_()
Expand All @@ -24,11 +26,12 @@ LRESULT CNetworkDebugDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM
DlgResize_Init(true, true, 0); // resizable dialog without "griper"
DoDataExchange(FALSE);
TRC(IDC_CLEARLOGBUTTON, "Clear log");
TRC(IDC_SAVETOFILEBTN, "Save to file");
TRC(IDC_DECODERESPONSEBUTTON, "Decode response");

splitterCtrl_.SubclassWindow(GetDlgItem(IDC_SPLITTER));
splitterCtrl_.SetSplitterPanes(listView_.m_hWnd, detailsEdit_.m_hWnd);


// set icons
icon_ = static_cast<HICON>(::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME),
IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR));
Expand Down Expand Up @@ -172,11 +175,33 @@ LRESULT CNetworkDebugDlg::OnDecodeResponseButtonClicked(WORD /*wNotifyCode*/, WO
return 0;
}

LRESULT CNetworkDebugDlg::OnSaveToFileButtonClicked(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
IMyFileDialog::FileFilterArray filters {
{ TR("Text files"), _T("*.txt;*.log") },
{ TR("All files"), _T("*.*") }
};

auto dlg = MyFileDialogFactory::createFileDialog(m_hWnd, {}, TR("Save log file"), filters, false, false);
dlg->setDefaultExtension(_T("txt"));

if (dlg->DoModal(m_hWnd) != IDOK) {
return 0;
}

try {
model_.saveToFile(W2U(dlg->getFile()));
} catch (const IOException& ex) {
GuiTools::LocalizedMessageBox(m_hWnd, U2WC(ex.what()), TR("Error"), MB_ICONERROR);
}

return 0;
}

BOOL CNetworkDebugDlg::PreTranslateMessage(MSG* pMsg) {
return CWindow::IsDialogMessage(pMsg);
}

bool CNetworkDebugDlg::showText(const std::string src)
bool CNetworkDebugDlg::showText(const std::string& src)
{
std::wstring s = IuCoreUtils::Utf8ToWstring(src);
bool hexDump = false;
Expand Down
4 changes: 3 additions & 1 deletion Source/Gui/Dialogs/NetworkDebugDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class CNetworkDebugDlg : public CDialogImpl<CNetworkDebugDlg>,
COMMAND_ID_HANDLER(IDC_ERRORLOGBUTTON, OnErrorLogButtonClicked)
COMMAND_HANDLER(IDC_CLEARLOGBUTTON, BN_CLICKED, OnClearLogButtonClicked)
COMMAND_HANDLER(IDC_DECODERESPONSEBUTTON, BN_CLICKED, OnDecodeResponseButtonClicked)
COMMAND_HANDLER(IDC_SAVETOFILEBTN, BN_CLICKED, OnSaveToFileButtonClicked)
NOTIFY_CODE_HANDLER(LVN_ITEMCHANGED, OnListViewItemChanged)
MESSAGE_HANDLER(WM_CLOSE, OnClose)
CHAIN_MSG_MAP(CDialogResize<CNetworkDebugDlg>)
Expand Down Expand Up @@ -65,6 +66,7 @@ class CNetworkDebugDlg : public CDialogImpl<CNetworkDebugDlg>,
LRESULT OnClearLogButtonClicked(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnListViewItemChanged(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/);
LRESULT OnDecodeResponseButtonClicked(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnSaveToFileButtonClicked(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

BOOL PreTranslateMessage(MSG* pMsg) override;
//LRESULT OnListViewNMCustomDraw(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
Expand All @@ -79,6 +81,6 @@ class CNetworkDebugDlg : public CDialogImpl<CNetworkDebugDlg>,
CIcon icon_, iconSmall_;

CFont detailsEditFont_;
bool showText(const std::string src);
bool showText(const std::string& src);
};

2 changes: 1 addition & 1 deletion Source/Gui/Dialogs/WizardDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2375,7 +2375,7 @@ LRESULT CWizardDlg::OnBnClickedHelpbutton(WORD /*wNotifyCode*/, WORD /*wID*/, HW
popupMenu.AppendMenu(MF_SEPARATOR, 99998,_T(""));
popupMenu.AppendMenu(MF_STRING, IDM_OPENSCREENSHOTS_FOLDER, TR("Open screenshots folder"));
popupMenu.AppendMenu(MF_SEPARATOR, 99999, _T(""));
popupMenu.AppendMenu(MF_STRING, IDM_NETWORKDEBUGGER, _T("Network Debugger"));
popupMenu.AppendMenu(MF_STRING, IDM_NETWORKDEBUGGER, TR("Network Debugger"));
#ifndef NDEBUG

popupMenu.AppendMenu(MF_STRING, IDM_OPENSERVERSCHECKER, _T("Servers Checker"));
Expand Down
66 changes: 37 additions & 29 deletions Source/Gui/Models/NetworkDebugModel.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#include "NetworkDebugModel.h"

#include <iomanip>
#include <fstream>
#include <sstream>
#include <filesystem>

#include <zlib.h>

#include "Core/ServiceLocator.h"
#include "Core/Network/NetworkDebugger.h"
#include "Func/MyEngineList.h"
#include "Core/Utils/IOException.h"

namespace {

Expand Down Expand Up @@ -120,27 +123,7 @@ NetworkDebugModel::~NetworkDebugModel() {
std::string NetworkDebugModel::getItemText(int row, int column) const {
//std::lock_guard<std::mutex> lk(itemsMutex_);
const auto& modelData = items_[row];
if (column == 0) {
// return std::to_string(row + 1);
} else if (column == 1) {
return modelData.threadId_;
}
else if (column == 2) {
std::stringstream ss;
ss << std::put_time(std::localtime(&modelData.time_), "%F %T");
return ss.str();
} else if (column == 3) {
return CurlTypeToString(modelData.type);
} else if (column == 4) {
if (modelData.type == CURLINFO_HEADER_IN || modelData.type == CURLINFO_HEADER_OUT || modelData.type == CURLINFO_TEXT) {
return modelData.data.substr(0, modelData.data.find_first_of("\r\n"));
}
} /* else if (column == 4) {
return modelData->extension;
} else if (column == 5) {
return modelData->badFileFormat.uploadProfile->serverName();
}*/
return {};
return getCell(modelData, row, column);
}

uint32_t NetworkDebugModel::getItemColor(int row) const {
Expand Down Expand Up @@ -194,13 +177,38 @@ void NetworkDebugModel::clear() {
items_.clear();
notifyCountChanged(0);
}
/*
size_t NetworkDebugModel::hasItemsWithStatus(NetworkDebugModelData::RowStatus status) const {
size_t count = 0;
for (auto& it : items_) {
if (it->status() == status) {
++count;

void NetworkDebugModel::saveToFile(const std::string& fileName) {
const auto COLUMN_COUNT = 5;
int i = 0;
std::ofstream out(std::filesystem::u8path(fileName));
if (!out) {
throw IOException("Failed to save debug log to file", fileName);
}
for (const auto& row : items_) {
for (int j = 0; j < COLUMN_COUNT; j++) {
out << getCell(row, i, j) << " ";
}
out << std::endl;
++i;
}
return count;
}*/
}

std::string NetworkDebugModel::getCell(const NetworkDebugModelData& modelData, int row, int column) const {
if (column == 0) {
// return std::to_string(row + 1);
} else if (column == 1) {
return modelData.threadId_;
} else if (column == 2) {
std::stringstream ss;
ss << std::put_time(std::localtime(&modelData.time_), "%F %T");
return ss.str();
} else if (column == 3) {
return CurlTypeToString(modelData.type);
} else if (column == 4) {
if (modelData.type == CURLINFO_HEADER_IN || modelData.type == CURLINFO_HEADER_OUT || modelData.type == CURLINFO_TEXT) {
return modelData.data.substr(0, modelData.data.find_first_of("\r\n"));
}
}
return {};
}
5 changes: 5 additions & 0 deletions Source/Gui/Models/NetworkDebugModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,18 @@ class NetworkDebugModel {
void setOnRowChangedCallback(std::function<void(size_t)> callback);
void setOnItemCountChangedCallback(std::function<void(size_t)> callback);
void clear();
/**
* @throws IOException
*/
void saveToFile(const std::string& fileName);

protected:
//mutable std::mutex itemsMutex_;
concurrency::concurrent_vector<NetworkDebugModelData> items_;
std::function<void(size_t)> rowChangedCallback_;
std::function<void(size_t)> itemCountChangedCallback_;
boost::signals2::scoped_connection debugMessageConnection_;
std::string getCell(const NetworkDebugModelData& item, int row, int column) const;
DISALLOW_COPY_AND_ASSIGN(NetworkDebugModel);
};
#endif
9 changes: 5 additions & 4 deletions Source/Image Uploader.rc
Original file line number Diff line number Diff line change
Expand Up @@ -1929,11 +1929,12 @@ STYLE DS_SETFONT | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
CAPTION "#network debugger"
FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN
PUSHBUTTON "#save to file",IDC_SAVETOFILEBTN,3,4,83,14
PUSHBUTTON "#Clear log",IDC_CLEARLOGBUTTON,101,4,72,14
PUSHBUTTON "Decode response",IDC_DECODERESPONSEBUTTON,294,4,85,14
CONTROL "",IDC_DEBUGLIST,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP,3,24,288,271
EDITTEXT IDC_DEBUGDETAILS,295,24,248,271,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL | WS_HSCROLL
LTEXT ".",IDC_SPLITTER,291,24,4,271
PUSHBUTTON "#Clear log",IDC_CLEARLOGBUTTON,33,7,72,14
PUSHBUTTON "Decode response",IDC_DECODERESPONSEBUTTON,294,7,77,14
LTEXT ".",IDC_SPLITTER,291,24,8,271
END


Expand Down Expand Up @@ -1965,7 +1966,7 @@ BEGIN
BEGIN
LEFTMARGIN, 3
RIGHTMARGIN, 543
TOPMARGIN, 7
TOPMARGIN, 4
BOTTOMMARGIN, 295
END
END
Expand Down
1 change: 1 addition & 0 deletions Source/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@
#define IDC_SERVERMENU 1047
#define IDC_NEWTHUMBNAIL 1047
#define IDC_CLEARFILTERS 1047
#define IDC_SAVETOFILEBTN 1047
#define IDC_UPDOWN 1048
#define IDC_PROGRESS1 1049
#define IDC_UPLOADPROGRESS 1049
Expand Down

0 comments on commit be9e0a8

Please sign in to comment.