feature add common function for soft

This commit is contained in:
alves
2025-12-17 11:42:07 +08:00
parent 399fbc7a33
commit 5ed729e27c
23 changed files with 116 additions and 60 deletions

View File

@@ -6,7 +6,7 @@ add_library(nlohmann_json INTERFACE)
target_include_directories(nlohmann_json SYSTEM target_include_directories(nlohmann_json SYSTEM
INTERFACE INTERFACE
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/..
) )
target_sources(nlohmann_json INTERFACE target_sources(nlohmann_json INTERFACE

View File

@@ -115,9 +115,9 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/dev-utils/platform/msw/Snapmaker_Orca
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/dev-utils/platform/msw/Snapmaker_Orca.manifest.in ${CMAKE_CURRENT_BINARY_DIR}/Snapmaker_Orca.manifest @ONLY) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/dev-utils/platform/msw/Snapmaker_Orca.manifest.in ${CMAKE_CURRENT_BINARY_DIR}/Snapmaker_Orca.manifest @ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/dev-utils/platform/osx/Info.plist.in ${CMAKE_CURRENT_BINARY_DIR}/Info.plist @ONLY) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/dev-utils/platform/osx/Info.plist.in ${CMAKE_CURRENT_BINARY_DIR}/Info.plist @ONLY)
if (WIN32) if (WIN32)
add_library(Snapmaker_Orca SHARED Snapmaker_Orca.cpp Snapmaker_Orca.hpp dev-utils/BaseException.cpp dev-utils/BaseException.h dev-utils/StackWalker.cpp dev-utils/StackWalker.h sentry_wrapper/SentryWrapper.hpp sentry_wrapper/SentryWrapper.cpp bury_cfg/bury_point.hpp bury_cfg/bury_point.cpp) add_library(Snapmaker_Orca SHARED Snapmaker_Orca.cpp Snapmaker_Orca.hpp dev-utils/BaseException.cpp dev-utils/BaseException.h dev-utils/StackWalker.cpp dev-utils/StackWalker.h sentry_wrapper/SentryWrapper.hpp sentry_wrapper/SentryWrapper.cpp bury_cfg/bury_point.hpp bury_cfg/bury_point.cpp common_func/common_func.hpp common_func/common_func.cpp)
else () else ()
add_executable(Snapmaker_Orca Snapmaker_Orca.cpp Snapmaker_Orca.hpp sentry_wrapper/SentryWrapper.hpp sentry_wrapper/SentryWrapper.cpp bury_cfg/bury_point.hpp bury_cfg/bury_point.cpp) add_executable(Snapmaker_Orca Snapmaker_Orca.cpp Snapmaker_Orca.hpp sentry_wrapper/SentryWrapper.hpp sentry_wrapper/SentryWrapper.cpp bury_cfg/bury_point.hpp bury_cfg/bury_point.cpp common_func/common_func.hpp common_func/common_func.cpp)
endif () endif ()
if (MINGW) if (MINGW)
@@ -181,7 +181,7 @@ if (WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -municode") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -municode")
endif() endif()
add_executable(Snapmaker_Orca_app_gui WIN32 Snapmaker_Orca_app_msvc.cpp sentry_wrapper/SentryWrapper.cpp bury_cfg/bury_point.cpp ${CMAKE_CURRENT_BINARY_DIR}/Snapmaker_Orca.rc) add_executable(Snapmaker_Orca_app_gui WIN32 Snapmaker_Orca_app_msvc.cpp sentry_wrapper/SentryWrapper.cpp bury_cfg/bury_point.cpp common_func/common_func.cpp ${CMAKE_CURRENT_BINARY_DIR}/Snapmaker_Orca.rc)
# Generate debug symbols even in release mode. # Generate debug symbols even in release mode.
if(MSVC) if(MSVC)
target_link_options(Snapmaker_Orca_app_gui PUBLIC "$<$<CONFIG:RELEASE>:/DEBUG>") target_link_options(Snapmaker_Orca_app_gui PUBLIC "$<$<CONFIG:RELEASE>:/DEBUG>")
@@ -190,9 +190,9 @@ if (WIN32)
add_dependencies(Snapmaker_Orca_app_gui Snapmaker_Orca) add_dependencies(Snapmaker_Orca_app_gui Snapmaker_Orca)
set_target_properties(Snapmaker_Orca_app_gui PROPERTIES OUTPUT_NAME "snapmaker-orca") set_target_properties(Snapmaker_Orca_app_gui PROPERTIES OUTPUT_NAME "snapmaker-orca")
if (SLIC3R_SENTRY) if (SLIC3R_SENTRY)
target_link_libraries(Snapmaker_Orca_app_gui PRIVATE boost_headeronly sentry::sentry) target_link_libraries(Snapmaker_Orca_app_gui PRIVATE boost_headeronly sentry::sentry nlohmann_json)
else() else()
target_link_libraries(Snapmaker_Orca_app_gui PRIVATE boost_headeronly) target_link_libraries(Snapmaker_Orca_app_gui PRIVATE boost_headeronly nlohmann_json)
endif() endif()
if (SLIC3R_SENTRY) if (SLIC3R_SENTRY)
target_compile_definitions(Snapmaker_Orca_app_gui PRIVATE SLIC3R_SENTRY) target_compile_definitions(Snapmaker_Orca_app_gui PRIVATE SLIC3R_SENTRY)

View File

@@ -0,0 +1,59 @@
#include "common_func.hpp"
#include <boost/asio/ip/host_name.hpp>
#ifdef _WIN32
#include <windows.h>
#include <Shlobj.h>
#elif __APPLE__
#include <stdlib.h>
#endif
#include <fstream>
#include <nlohmann/json.hpp>
namespace common
{
std::string get_pc_name()
{
return boost::asio::ip::host_name();
}
std::string get_flutter_version()
{
std::string versionFilePath = "";
#ifdef _WIN32
wchar_t appDataPath[MAX_PATH] = {0};
auto hr = SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appDataPath);
char* path = new char[MAX_PATH];
size_t pathLength;
wcstombs_s(&pathLength, path, MAX_PATH, appDataPath, MAX_PATH);
std::string filePath = path;
versionFilePath = filePath + "\\" + std::string("Snapmaker_Orca\\web\\flutter_web\\version.json");
#elif __APPLE__
const char* home_env = getenv("HOME");
versionFilePath = home_env;
versionFilePath = versionFilePath + "/Library/Application Support/Snapmaker_Orca/web/flutter_web/version.json";
#else
#endif
std::ifstream json_file(versionFilePath);
if (!json_file.is_open()) {
std::ifstream json_file(versionFilePath);
return "";
}
nlohmann::json json_data;
json_file >> json_data;
std::string str_version = json_data["version"];
std::string str_build_number = json_data["build_number"];
std::string flutter_version = std::string("flutter_version: ") + str_version + std::string(" ") + std::string("build_number: ") +
str_build_number;
return flutter_version;
}
}

View File

@@ -0,0 +1,27 @@
#ifndef _common_func_hppp_
#define _common_func_hppp_
#include <iostream>
#define SLIC3R_APP_NAME "Snapmaker Orca"
#define SLIC3R_APP_KEY "Snapmaker_Orca"
#define SLIC3R_VERSION "01.10.01.50"
#define Snapmaker_VERSION "2.2.0"
#define MIN_FIRM_VER "0.8.4"
#ifndef GIT_COMMIT_HASH
#define GIT_COMMIT_HASH "0000000" // 0000000 means uninitialized
#endif
#define SLIC3R_BUILD_ID ""
// #define SLIC3R_RC_VERSION "01.10.01.50"
#define BBL_RELEASE_TO_PUBLIC 1
#define BBL_INTERNAL_TESTING 0
#define ORCA_CHECK_GCODE_PLACEHOLDERS 0
namespace common
{
std::string get_pc_name();
std::string get_flutter_version();
} // namespace common
#endif

View File

@@ -6,7 +6,7 @@
#include "Utils.hpp" #include "Utils.hpp"
#include "Model.hpp" #include "Model.hpp"
#include "format.hpp" #include "format.hpp"
#include "libslic3r_version.h" #include "common_func/common_func.hpp"
#include <algorithm> #include <algorithm>
#include <set> #include <set>

View File

@@ -1,7 +1,7 @@
#ifndef _libslic3r_h_ #ifndef _libslic3r_h_
#define _libslic3r_h_ #define _libslic3r_h_
#include "libslic3r_version.h" #include "common_func/common_func.hpp"
#define SLIC3R_APP_FULL_NAME "Snapmaker Orca" #define SLIC3R_APP_FULL_NAME "Snapmaker Orca"
#define GCODEVIEWER_APP_NAME "Snapmaker_Orca G-code Viewer" #define GCODEVIEWER_APP_NAME "Snapmaker_Orca G-code Viewer"
#define GCODEVIEWER_APP_KEY "Snapmaker_OrcaGcodeViewer" #define GCODEVIEWER_APP_KEY "Snapmaker_OrcaGcodeViewer"

View File

@@ -125,7 +125,7 @@
#include "SVG.hpp" #include "SVG.hpp"
#include "libslic3r.h" #include "libslic3r.h"
#include "libslic3r_version.h" #include "common_func/common_func.hpp"
#include <Shiny/Shiny.h> #include <Shiny/Shiny.h>

View File

@@ -27,6 +27,7 @@
#include <cstdlib> #include <cstdlib>
#include <atomic> #include <atomic>
#include <random> #include <random>
#include "common_func/common_func.hpp"
namespace Slic3r { namespace Slic3r {
@@ -193,6 +194,7 @@ void initSentryEx()
#endif #endif
sentry_options_set_environment(options, "develop"); sentry_options_set_environment(options, "develop");
//sentry_options_set_environment(options, "Release");
sentry_options_set_auto_session_tracking(options, 0); sentry_options_set_auto_session_tracking(options, 0);
sentry_options_set_symbolize_stacktraces(options, 1); sentry_options_set_symbolize_stacktraces(options, 1);
@@ -202,6 +204,12 @@ void initSentryEx()
sentry_options_set_sample_rate(options, 1.0); sentry_options_set_sample_rate(options, 1.0);
sentry_options_set_traces_sample_rate(options, 1.0); sentry_options_set_traces_sample_rate(options, 1.0);
sentry_set_tag("version", Snapmaker_VERSION);
std::string flutterVersion = common::get_flutter_version();
if (!flutterVersion.empty())
set_sentry_tags("flutter_version", flutterVersion);
sentry_init(options); sentry_init(options);
sentry_start_session(); sentry_start_session();

View File

@@ -16,7 +16,7 @@
#include "FileHelp.hpp" #include "FileHelp.hpp"
#include "Tab.hpp" #include "Tab.hpp"
#include "MainFrame.hpp" #include "MainFrame.hpp"
#include "libslic3r_version.h" #include "common_func/common_func.hpp"
#define NAME_OPTION_COMBOBOX_SIZE wxSize(FromDIP(200), FromDIP(24)) #define NAME_OPTION_COMBOBOX_SIZE wxSize(FromDIP(200), FromDIP(24))
#define FILAMENT_PRESET_COMBOBOX_SIZE wxSize(FromDIP(300), FromDIP(24)) #define FILAMENT_PRESET_COMBOBOX_SIZE wxSize(FromDIP(300), FromDIP(24))

View File

@@ -6,7 +6,7 @@
#include "slic3r/GUI/UserManager.hpp" #include "slic3r/GUI/UserManager.hpp"
#include "slic3r/GUI/TaskManager.hpp" #include "slic3r/GUI/TaskManager.hpp"
#include "format.hpp" #include "format.hpp"
#include "libslic3r_version.h" #include "common_func/common_func.hpp"
#include "Downloader.hpp" #include "Downloader.hpp"
#include "slic3r/GUI/WebUrlDialog.hpp" #include "slic3r/GUI/WebUrlDialog.hpp"

View File

@@ -72,9 +72,9 @@
#include <dbt.h> #include <dbt.h>
#include <shlobj.h> #include <shlobj.h>
#include <shellapi.h> #include <shellapi.h>
#include "sentry_wrapper/SentryWrapper.hpp"
#endif // _WIN32 #endif // _WIN32
#include <slic3r/GUI/CreatePresetsDialog.hpp> #include <slic3r/GUI/CreatePresetsDialog.hpp>
#include "sentry_wrapper/SentryWrapper.hpp"
namespace Slic3r { namespace Slic3r {
@@ -1008,41 +1008,6 @@ void MainFrame::show_option(bool show)
} }
} }
} }
void MainFrame::get_local_webview_version()
{
std::string versionFilePath = "";
#ifdef _WIN32
wchar_t appDataPath[MAX_PATH] = {0};
auto hr = SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appDataPath);
char* path = new char[MAX_PATH];
size_t pathLength;
wcstombs_s(&pathLength, path, MAX_PATH, appDataPath, MAX_PATH);
std::string filePath = path;
versionFilePath = filePath + "\\" + std::string("Snapmaker_Orca\\web\\flutter_web\\version.json");
#elif __APPLE__
const char* home_env = getenv("HOME");
versionFilePath = home_env;
versionFilePath = versionFilePath + "/Library/Application Support/Snapmaker_Orca/web/flutter_web/version.json";
#else
#endif
std::ifstream json_file(versionFilePath);
if (!json_file.is_open()) {
std::ifstream json_file(versionFilePath);
BOOST_LOG_TRIVIAL(error) << "check flutter version error with file path:" << versionFilePath;
return;
}
nlohmann::json json_data;
json_file >> json_data;
std::string str_version = json_data["version"];
std::string str_build_number = json_data["build_number"];
std::string tag = std::string("flutter_version: ") + str_version + std::string(" ") + std::string("build_number: ") + str_build_number;
set_sentry_tags("flutter_version", tag);
}
void MainFrame::init_tabpanel() { void MainFrame::init_tabpanel() {
// wxNB_NOPAGETHEME: Disable Windows Vista theme for the Notebook background. The theme performance is terrible on // wxNB_NOPAGETHEME: Disable Windows Vista theme for the Notebook background. The theme performance is terrible on
@@ -1126,7 +1091,6 @@ void MainFrame::init_tabpanel() {
m_param_panel = new ParamsPanel(m_tabpanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL); m_param_panel = new ParamsPanel(m_tabpanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL);
} }
get_local_webview_version();
m_plater = new Plater(this, this); m_plater = new Plater(this, this);
m_plater->SetBackgroundColour(*wxWHITE); m_plater->SetBackgroundColour(*wxWHITE);
m_plater->Hide(); m_plater->Hide();

View File

@@ -264,7 +264,6 @@ public:
void update_title_colour_after_set_title(); void update_title_colour_after_set_title();
void show_option(bool show); void show_option(bool show);
void init_tabpanel(); void init_tabpanel();
void get_local_webview_version();
void create_preset_tabs(); void create_preset_tabs();
//BBS: GUI refactor //BBS: GUI refactor
void add_created_tab(Tab* panel, const std::string& bmp_name = ""); void add_created_tab(Tab* panel, const std::string& bmp_name = "");

View File

@@ -1,6 +1,6 @@
#include "Plater.hpp" #include "Plater.hpp"
#include "libslic3r/Config.hpp" #include "libslic3r/Config.hpp"
#include "libslic3r_version.h" #include "common_func/common_func.hpp"
#include <cstddef> #include <cstddef>
#include <algorithm> #include <algorithm>

View File

@@ -5,7 +5,7 @@
#include "slic3r/GUI/wxExtensions.hpp" #include "slic3r/GUI/wxExtensions.hpp"
#include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/GUI_App.hpp"
#include "slic3r/GUI/MainFrame.hpp" #include "slic3r/GUI/MainFrame.hpp"
#include "libslic3r_version.h" #include "common_func/common_func.hpp"
#include <wx/sizer.h> #include <wx/sizer.h>
#include <wx/string.h> #include <wx/string.h>

View File

@@ -91,7 +91,6 @@ bool WCP_Logger::set_level(wxString& level)
} }
} }
std::string WCP_Logger::get_pc_name() { return boost::asio::ip::host_name(); }
// Add a log message to the queue // Add a log message to the queue
void WCP_Logger::add_log(const wxString& content, bool is_web = false, wxString time = "", wxString module = "Default", wxString level = "debug") void WCP_Logger::add_log(const wxString& content, bool is_web = false, wxString time = "", wxString module = "Default", wxString level = "debug")

View File

@@ -6,7 +6,7 @@
#include "libslic3r/AppConfig.hpp" #include "libslic3r/AppConfig.hpp"
#include "slic3r/GUI/wxExtensions.hpp" #include "slic3r/GUI/wxExtensions.hpp"
#include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/GUI_App.hpp"
#include "libslic3r_version.h" #include "common_func/common_func.hpp"
#include <wx/sizer.h> #include <wx/sizer.h>
#include <wx/toolbar.h> #include <wx/toolbar.h>

View File

@@ -10,7 +10,7 @@
#include "libslic3r/PresetBundle.hpp" #include "libslic3r/PresetBundle.hpp"
#include "slic3r/GUI/wxExtensions.hpp" #include "slic3r/GUI/wxExtensions.hpp"
#include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/GUI_App.hpp"
#include "libslic3r_version.h" #include "common_func/common_func.hpp"
#include <wx/sizer.h> #include <wx/sizer.h>
#include <wx/toolbar.h> #include <wx/toolbar.h>

View File

@@ -6,7 +6,7 @@
#include "libslic3r/AppConfig.hpp" #include "libslic3r/AppConfig.hpp"
#include "slic3r/GUI/wxExtensions.hpp" #include "slic3r/GUI/wxExtensions.hpp"
#include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/GUI_App.hpp"
#include "libslic3r_version.h" #include "common_func/common_func.hpp"
#include <wx/sizer.h> #include <wx/sizer.h>
#include <wx/toolbar.h> #include <wx/toolbar.h>

View File

@@ -5,7 +5,7 @@
#include "libslic3r/AppConfig.hpp" #include "libslic3r/AppConfig.hpp"
#include "slic3r/GUI/wxExtensions.hpp" #include "slic3r/GUI/wxExtensions.hpp"
#include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/GUI_App.hpp"
#include "libslic3r_version.h" #include "common_func/common_func.hpp"
#include <wx/sizer.h> #include <wx/sizer.h>
#include <wx/toolbar.h> #include <wx/toolbar.h>

View File

@@ -5,7 +5,7 @@
#include "libslic3r/AppConfig.hpp" #include "libslic3r/AppConfig.hpp"
#include "slic3r/GUI/wxExtensions.hpp" #include "slic3r/GUI/wxExtensions.hpp"
#include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/GUI_App.hpp"
#include "libslic3r_version.h" #include "common_func/common_func.hpp"
#include <wx/sizer.h> #include <wx/sizer.h>
#include <wx/toolbar.h> #include <wx/toolbar.h>

View File

@@ -4,7 +4,7 @@
#include "slic3r/GUI/wxExtensions.hpp" #include "slic3r/GUI/wxExtensions.hpp"
#include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/GUI_App.hpp"
#include "slic3r/GUI/MainFrame.hpp" #include "slic3r/GUI/MainFrame.hpp"
#include "libslic3r_version.h" #include "common_func/common_func.hpp"
#include "../Utils/Http.hpp" #include "../Utils/Http.hpp"
#include "SSWCP.hpp" #include "SSWCP.hpp"

View File

@@ -9,7 +9,7 @@
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
#include "libslic3r/Exception.hpp" #include "libslic3r/Exception.hpp"
#include "libslic3r_version.h" #include "common_func/common_func.hpp"
#define MAX_SIZE_TO_FILE 3*1024 #define MAX_SIZE_TO_FILE 3*1024

View File

@@ -25,7 +25,7 @@
#include "libslic3r/format.hpp" #include "libslic3r/format.hpp"
#include "libslic3r/Utils.hpp" #include "libslic3r/Utils.hpp"
#include "libslic3r/PresetBundle.hpp" #include "libslic3r/PresetBundle.hpp"
#include "libslic3r_version.h" #include "common_func/common_func.hpp"
#include "slic3r/GUI/GUI.hpp" #include "slic3r/GUI/GUI.hpp"
#include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/GUI_App.hpp"
#include "slic3r/GUI/I18N.hpp" #include "slic3r/GUI/I18N.hpp"