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

@@ -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