mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-07 15:51:08 +00:00
* Stop Leaking json Through Headers and Drop Includes Kept Only for the Name AppConfig.hpp, DeviceManager.hpp and UserManager.hpp carried a global "using namespace nlohmann;", json_diff.hpp a global "using json = nlohmann::json;" and PrinterFileSystem.h a global "using nlohmann::json;". Every file that included one of them, directly or not, could write a bare json, and 63 did without declaring it. The last two also made the include checker treat json_diff.hpp and PrinterFileSystem.h as the headers that provide json, so they were included from files that use nothing else from them: 57 of the 59 includers of json_diff.hpp never name json_diff. The five statements are removed. Headers that use the type now spell nlohmann::json, source files declare their own "using json = nlohmann::json;", and the includes that only supplied the name are dropped or replaced by <nlohmann/json.hpp>. Eight files reached json_diff.hpp only through an include that is now gone and with it lost that header's "using namespace std;". The std names they used unqualified are qualified. * Declare json in OrcaSlicer.cpp on Every Platform OrcaSlicer.cpp had its "using namespace nlohmann;" and the json include inside the Linux-only include block, so on Windows and macOS it took json from AppConfig.hpp's global directive, which is gone. The include and a "using json = nlohmann::json;" now sit outside the block.
83 lines
2.1 KiB
C++
83 lines
2.1 KiB
C++
#include <nlohmann/json.hpp>
|
|
#include "UserManager.hpp"
|
|
#include "BindDialog.hpp"
|
|
#include "GUI_App.hpp"
|
|
#include "I18N.hpp"
|
|
#include "MsgDialog.hpp"
|
|
|
|
#include "DeviceCore/DevManager.h"
|
|
#include <string>
|
|
#include <wx/string.h>
|
|
|
|
|
|
using json = nlohmann::json;
|
|
|
|
namespace Slic3r {
|
|
|
|
UserManager::UserManager(NetworkAgent* agent)
|
|
{
|
|
m_agent = agent;
|
|
}
|
|
|
|
UserManager::~UserManager()
|
|
{
|
|
}
|
|
|
|
void UserManager::set_agent(NetworkAgent* agent)
|
|
{
|
|
m_agent = agent;
|
|
}
|
|
|
|
int UserManager::parse_json(std::string payload)
|
|
{
|
|
bool restored_json = false;
|
|
json j;
|
|
|
|
//bind/unbind
|
|
|
|
try {
|
|
json j_pre = json::parse(payload);
|
|
if (j_pre.empty()) {
|
|
return -1;
|
|
}
|
|
|
|
if (j_pre.contains("bind")) {
|
|
if (j_pre["bind"].contains("command")) {
|
|
|
|
//bind
|
|
if (j_pre["bind"]["command"].get<std::string>() == "bind") {
|
|
std::string dev_id;
|
|
std::string result;
|
|
|
|
if (j_pre["bind"].contains("dev_id")) {
|
|
dev_id = j_pre["bind"]["dev_id"].get<std::string>();
|
|
}
|
|
|
|
if (j_pre["bind"].contains("result")) {
|
|
result = j_pre["bind"]["result"].get<std::string>();
|
|
}
|
|
|
|
if (result == "success") {
|
|
DeviceManager* dev = GUI::wxGetApp().getDeviceManager();
|
|
if (!dev) {return -1;}
|
|
|
|
if (GUI::wxGetApp().m_ping_code_binding_dialog && GUI::wxGetApp().m_ping_code_binding_dialog->IsShown()) {
|
|
GUI::wxGetApp().m_ping_code_binding_dialog->EndModal(wxCLOSE);
|
|
GUI::MessageDialog msgdialog(nullptr, _L("Log in successful."), "", wxAPPLY | wxOK);
|
|
msgdialog.ShowModal();
|
|
}
|
|
dev->update_user_machine_list_info(GUI::wxGetApp().get_printer_cloud_provider());
|
|
dev->set_selected_machine(dev_id);
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (...){}
|
|
|
|
return -1;
|
|
}
|
|
|
|
} // namespace Slic3r
|