diff --git a/src/slic3r/GUI/Auth.cpp b/src/slic3r/GUI/Auth.cpp index 54e1194858..0006789404 100644 --- a/src/slic3r/GUI/Auth.cpp +++ b/src/slic3r/GUI/Auth.cpp @@ -380,7 +380,6 @@ std::string CodeChalengeGenerator::sha256(const std::string& input) { HCRYPTPROV prov_handle = NULL; HCRYPTHASH hash_handle = NULL; - std::vector buffer(1024); DWORD hash_size = 0; DWORD buffer_size = sizeof(DWORD); std::string output; @@ -423,13 +422,7 @@ std::string CodeChalengeGenerator::sha256(const std::string& input) { unsigned char digest[CC_SHA256_DIGEST_LENGTH]; CC_SHA256_Final(digest, &sha256); - // Convert the result to a string - char hashString[CC_SHA256_DIGEST_LENGTH * 2 + 1]; - for (int i = 0; i < CC_SHA256_DIGEST_LENGTH; i++) { - sprintf(&hashString[i * 2], "%02x", digest[i]); - } - - return std::string(hashString); + return std::string(reinterpret_cast(digest), CC_SHA256_DIGEST_LENGTH); } #else std::string CodeChalengeGenerator::sha256(const std::string& input) { diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index c75f1a86dc..2e34055b44 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -870,7 +870,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) bring_instance_forward(); }); - this->q->Bind(EVT_OPEN_PRUSAAUTH, [this](OpenPrusaAuthEvent& evt) { + this->q->Bind(EVT_OPEN_PRUSAAUTH, [](OpenPrusaAuthEvent& evt) { BOOST_LOG_TRIVIAL(info) << "open browser: " << evt.data; // first register url to be sure to get the code back //auto downloader_worker = new DownloaderUtils::Worker(nullptr); @@ -5861,12 +5861,10 @@ void Plater::connect_gcode() return; } - // TODO: get api key from dialog_msg and upload the file - // api key is not currently in the message - std::string api_key; + // TODO: break if printer not ready - // This is private key for our printer "Loki" - DELETE! - //api_key = "PAARWQ2Ibd69fdbf"; + // get api key from dialog_msg and upload the file + std::string api_key = p->user_account->get_apikey_from_json(dialog_msg); if (api_key.empty()) { return; diff --git a/src/slic3r/GUI/UserAccount.cpp b/src/slic3r/GUI/UserAccount.cpp index 1868d35805..36b15426ca 100644 --- a/src/slic3r/GUI/UserAccount.cpp +++ b/src/slic3r/GUI/UserAccount.cpp @@ -270,4 +270,21 @@ std::string UserAccount::get_nozzle_from_json(const std::string& message) const return out; } +std::string UserAccount::get_apikey_from_json(const std::string& message) const +{ + std::string out; + try { + std::stringstream ss(message); + pt::ptree ptree; + pt::read_json(ss, ptree); + + out = parse_tree_for_param(ptree, "prusaconnect_api_key"); + //assert(!out.empty()); + } + catch (const std::exception& e) { + BOOST_LOG_TRIVIAL(error) << "Could not parse prusaconnect message. " << e.what(); + } + return out; +} + }} // namespace slic3r::GUI \ No newline at end of file diff --git a/src/slic3r/GUI/UserAccount.hpp b/src/slic3r/GUI/UserAccount.hpp index dab6fed62b..12a7d036a3 100644 --- a/src/slic3r/GUI/UserAccount.hpp +++ b/src/slic3r/GUI/UserAccount.hpp @@ -60,6 +60,7 @@ public: // standalone utility methods std::string get_model_from_json(const std::string& message) const; std::string get_nozzle_from_json(const std::string& message) const; + std::string get_apikey_from_json(const std::string& message) const; private: void set_username(const std::string& username, AppConfig* app_config); void reset(AppConfig* app_config); diff --git a/src/slic3r/GUI/WebView.cpp b/src/slic3r/GUI/WebView.cpp index 0662447d76..e9a16f3e10 100644 --- a/src/slic3r/GUI/WebView.cpp +++ b/src/slic3r/GUI/WebView.cpp @@ -154,7 +154,6 @@ bool WebView::run_script(wxWebView *webView, wxString const &javascript) return webView2->ExecuteScript(wrapJS.GetWrappedCode(), NULL) == 0; #elif defined __WXMAC__ WKWebView * wkWebView = (WKWebView *) webView->GetNativeBackend(); - int count = 0; wxJSScriptWrapper wrapJS(javascript, wxJSScriptWrapper::OutputType::JS_OUTPUT_STRING); Slic3r::GUI::WKWebView_evaluateJavaScript(wkWebView, wrapJS.GetWrappedCode(), nullptr); return true; diff --git a/src/slic3r/GUI/WebViewDialog.cpp b/src/slic3r/GUI/WebViewDialog.cpp index 01b355caec..739e1723e7 100644 --- a/src/slic3r/GUI/WebViewDialog.cpp +++ b/src/slic3r/GUI/WebViewDialog.cpp @@ -463,7 +463,7 @@ void WebViewDialog::run_script(const wxString& javascript) { if (!m_browser) return; - bool res = WebView::run_script(m_browser, javascript); + //bool res = WebView::run_script(m_browser, javascript); } diff --git a/src/slic3r/GUI/WifiConfigDialog.cpp b/src/slic3r/GUI/WifiConfigDialog.cpp index 865ed36149..d40293b3f9 100644 --- a/src/slic3r/GUI/WifiConfigDialog.cpp +++ b/src/slic3r/GUI/WifiConfigDialog.cpp @@ -208,7 +208,7 @@ void WifiConfigDialog::rescan_networks(bool select) std::string current = m_wifi_scanner->get_current_ssid(); const auto& map = m_wifi_scanner->get_map(); m_ssid_combo->Clear(); - for (const auto &pair : map) { + for (const auto& pair : map) { m_ssid_combo->Append(pair.first); // select ssid of current network (if connected) if (current == pair.first)