mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-10 10:47:16 +00:00
Merge pull request #110 from Snapmaker/dev_crash_fixed_alves
fix code format for read config file data.
This commit is contained in:
@@ -78,13 +78,19 @@ namespace common
|
|||||||
std::string versionFilePath = "";
|
std::string versionFilePath = "";
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
wchar_t appDataPath[MAX_PATH] = {0};
|
PWSTR pszPath = nullptr;
|
||||||
auto hr = SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appDataPath);
|
char* path = new char[MAX_PATH]();
|
||||||
char* path = new char[MAX_PATH];
|
size_t pathLength = 0;
|
||||||
size_t pathLength;
|
HRESULT hr = SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, nullptr, &pszPath);
|
||||||
wcstombs_s(&pathLength, path, MAX_PATH, appDataPath, MAX_PATH);
|
if (SUCCEEDED(hr)) {
|
||||||
|
wcstombs_s(&pathLength, path, MAX_PATH, pszPath, MAX_PATH);
|
||||||
|
CoTaskMemFree(pszPath);
|
||||||
|
}
|
||||||
|
|
||||||
std::string filePath = path;
|
std::string filePath = path;
|
||||||
versionFilePath = filePath + "\\" + std::string("Snapmaker_Orca\\web\\flutter_web\\version.json");
|
versionFilePath = filePath + "\\" + std::string("Snapmaker_Orca\\web\\flutter_web\\version.json");
|
||||||
|
|
||||||
|
delete[] path;
|
||||||
#elif __APPLE__
|
#elif __APPLE__
|
||||||
const char* home_env = getenv("HOME");
|
const char* home_env = getenv("HOME");
|
||||||
versionFilePath = home_env;
|
versionFilePath = home_env;
|
||||||
@@ -114,17 +120,26 @@ namespace common
|
|||||||
{
|
{
|
||||||
std::string localArea = "";
|
std::string localArea = "";
|
||||||
std::string cfgfile = "";
|
std::string cfgfile = "";
|
||||||
|
std::string versionFilePath = "";
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
wchar_t appDataPath[MAX_PATH] = {0};
|
|
||||||
auto hr = SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appDataPath);
|
PWSTR pszPath = nullptr;
|
||||||
char* path = new char[MAX_PATH];
|
char* path = new char[MAX_PATH]();
|
||||||
size_t pathLength;
|
size_t pathLength = 0;
|
||||||
wcstombs_s(&pathLength, path, MAX_PATH, appDataPath, MAX_PATH);
|
HRESULT hr = SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, nullptr, &pszPath);
|
||||||
|
if (SUCCEEDED(hr)) {
|
||||||
|
wcstombs_s(&pathLength, path, MAX_PATH, pszPath, MAX_PATH);
|
||||||
|
CoTaskMemFree(pszPath);
|
||||||
|
}
|
||||||
|
|
||||||
std::string filePath = path;
|
std::string filePath = path;
|
||||||
cfgfile = filePath + "\\" + std::string("Snapmaker_Orca\\Snapmaker_Orca.conf");
|
cfgfile = filePath + "\\" + std::string("Snapmaker_Orca\\Snapmaker_Orca.conf");
|
||||||
|
delete[] path;
|
||||||
|
|
||||||
#elif __APPLE__
|
#elif __APPLE__
|
||||||
const char* home_env = getenv("HOME");
|
const char* home_env = getenv("HOME");
|
||||||
cfgfile = home_env;
|
versionFilePath = home_env;
|
||||||
cfgfile = versionFilePath + "/Library/Application Support/Snapmaker_Orca/Snapmaker_Orca.conf";
|
cfgfile = versionFilePath + "/Library/Application Support/Snapmaker_Orca/Snapmaker_Orca.conf";
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@@ -147,19 +162,26 @@ namespace common
|
|||||||
std::string getLanguage()
|
std::string getLanguage()
|
||||||
{
|
{
|
||||||
std::string localLanguage = "";
|
std::string localLanguage = "";
|
||||||
|
std::string versionFilePath = "";
|
||||||
std::string cfgfile = "";
|
std::string cfgfile = "";
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
wchar_t appDataPath[MAX_PATH] = {0};
|
|
||||||
auto hr = SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appDataPath);
|
PWSTR pszPath = nullptr;
|
||||||
char* path = new char[MAX_PATH];
|
char* path = new char[MAX_PATH]();
|
||||||
size_t pathLength;
|
size_t pathLength = 0;
|
||||||
wcstombs_s(&pathLength, path, MAX_PATH, appDataPath, MAX_PATH);
|
HRESULT hr = SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, nullptr, &pszPath);
|
||||||
|
if (SUCCEEDED(hr)) {
|
||||||
|
wcstombs_s(&pathLength, path, MAX_PATH, pszPath, MAX_PATH);
|
||||||
|
CoTaskMemFree(pszPath);
|
||||||
|
}
|
||||||
|
|
||||||
std::string filePath = path;
|
std::string filePath = path;
|
||||||
cfgfile = filePath + "\\" + std::string("Snapmaker_Orca\\Snapmaker_Orca.conf");
|
cfgfile = filePath + "\\" + std::string("Snapmaker_Orca\\Snapmaker_Orca.conf");
|
||||||
|
delete[] path;
|
||||||
|
|
||||||
#elif __APPLE__
|
#elif __APPLE__
|
||||||
const char* home_env = getenv("HOME");
|
const char* home_env = getenv("HOME");
|
||||||
cfgfile = home_env;
|
versionFilePath = home_env;
|
||||||
cfgfile = versionFilePath + "/Library/Application Support/Snapmaker_Orca/Snapmaker_Orca.conf";
|
cfgfile = versionFilePath + "/Library/Application Support/Snapmaker_Orca/Snapmaker_Orca.conf";
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,9 @@
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <shlobj.h>
|
#include <shlobj.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <iphlpapi.h>
|
||||||
|
#pragma comment(lib, "iphlpapi.lib")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
@@ -174,14 +177,20 @@ void initSentryEx()
|
|||||||
|
|
||||||
handlerDir = wstringTostring(desDir);
|
handlerDir = wstringTostring(desDir);
|
||||||
|
|
||||||
wchar_t appDataPath[MAX_PATH] = {0};
|
PWSTR pszPath = nullptr;
|
||||||
auto hr = SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appDataPath);
|
char* path = new char[MAX_PATH]();
|
||||||
char* path = new char[MAX_PATH];
|
size_t pathLength = 0;
|
||||||
size_t pathLength;
|
HRESULT hr = SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, nullptr, &pszPath);
|
||||||
wcstombs_s(&pathLength, path, MAX_PATH, appDataPath, MAX_PATH);
|
|
||||||
|
if (SUCCEEDED(hr)) {
|
||||||
|
wcstombs_s(&pathLength, path, MAX_PATH, pszPath, MAX_PATH);
|
||||||
|
CoTaskMemFree(pszPath);
|
||||||
|
}
|
||||||
|
|
||||||
std::string filePath = path;
|
std::string filePath = path;
|
||||||
std::string appName = "\\" + std::string("Snapmaker_Orca\\");
|
std::string appName = "\\" + std::string("Snapmaker_Orca\\");
|
||||||
dataBaseDir = filePath + appName;
|
dataBaseDir = filePath + appName;
|
||||||
|
delete[] path;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!handlerDir.empty())
|
if (!handlerDir.empty())
|
||||||
@@ -276,48 +285,63 @@ void sentryReportLogEx(SENTRY_LOG_LEVEL logLevel,
|
|||||||
sentry_value_t attr = sentry_value_new_attribute(sentry_value_new_string(pcName.c_str()), NULL);
|
sentry_value_t attr = sentry_value_new_attribute(sentry_value_new_string(pcName.c_str()), NULL);
|
||||||
sentry_value_set_by_key(tags, "pc_name", attr);
|
sentry_value_set_by_key(tags, "pc_name", attr);
|
||||||
}
|
}
|
||||||
std::string machineID = common::getMachineId();
|
static std::string machineID = "";
|
||||||
|
if (machineID.empty())
|
||||||
|
machineID = common::getMachineId();
|
||||||
|
|
||||||
if (!machineID.empty()) {
|
if (!machineID.empty()) {
|
||||||
sentry_value_t attr = sentry_value_new_attribute(sentry_value_new_string(machineID.c_str()), NULL);
|
sentry_value_t attr = sentry_value_new_attribute(sentry_value_new_string(machineID.c_str()), NULL);
|
||||||
sentry_value_set_by_key(tags, "machine_id", attr);
|
sentry_value_set_by_key(tags, "machine_id", attr);
|
||||||
}
|
}
|
||||||
std::string currentLanguage = common::getLanguage();
|
|
||||||
|
static std::string currentLanguage = "";
|
||||||
|
if (currentLanguage.empty())
|
||||||
|
currentLanguage = common::getLanguage();
|
||||||
|
|
||||||
if (!currentLanguage.empty()) {
|
if (!currentLanguage.empty()) {
|
||||||
sentry_value_t attr = sentry_value_new_attribute(sentry_value_new_string(currentLanguage.c_str()), NULL);
|
sentry_value_t attr = sentry_value_new_attribute(sentry_value_new_string(currentLanguage.c_str()), NULL);
|
||||||
sentry_value_set_by_key(tags, "current_language", attr);
|
sentry_value_set_by_key(tags, "current_language", attr);
|
||||||
}
|
}
|
||||||
std::string localArea = common::getLocalArea();
|
|
||||||
|
static std::string localArea = "";
|
||||||
|
if (localArea.empty())
|
||||||
|
localArea = common::getLocalArea();
|
||||||
|
|
||||||
if (!localArea.empty())
|
if (!localArea.empty())
|
||||||
{
|
{
|
||||||
sentry_value_t attr = sentry_value_new_attribute(sentry_value_new_string(localArea.c_str()), NULL);
|
sentry_value_t attr = sentry_value_new_attribute(sentry_value_new_string(localArea.c_str()), NULL);
|
||||||
sentry_value_set_by_key(tags, "local_area", attr);
|
sentry_value_set_by_key(tags, "local_area", attr);
|
||||||
}
|
}
|
||||||
switch (logLevel) {
|
switch (logLevel) {
|
||||||
case SENTRY_LOG_TRACE:
|
case SENTRY_LOG_TRACE: {
|
||||||
sentry_msg_level = SENTRY_LEVEL_TRACE;
|
sentry_msg_level = SENTRY_LEVEL_TRACE;
|
||||||
sentry_value_t attr = sentry_value_new_attribute(sentry_value_new_string("snapmaker_bury_point"), NULL);
|
sentry_value_t attr = sentry_value_new_attribute(sentry_value_new_string("snapmaker_bury_point"), NULL);
|
||||||
sentry_value_set_by_key(tags, BURY_POINT, attr);
|
sentry_value_set_by_key(tags, BURY_POINT, attr);
|
||||||
sentry_log_trace(logContent.c_str(), tags);
|
sentry_log_trace(logContent.c_str(), tags);
|
||||||
break;
|
} break;
|
||||||
case SENTRY_LOG_DEBUG:
|
case SENTRY_LOG_DEBUG: {
|
||||||
sentry_msg_level = SENTRY_LEVEL_DEBUG;
|
sentry_msg_level = SENTRY_LEVEL_DEBUG;
|
||||||
sentry_log_debug(logContent.c_str(), tags);
|
sentry_log_debug(logContent.c_str(), tags);
|
||||||
break;
|
} break;
|
||||||
case SENTRY_LOG_INFO:
|
case SENTRY_LOG_INFO: {
|
||||||
sentry_msg_level = SENTRY_LEVEL_INFO;
|
sentry_msg_level = SENTRY_LEVEL_INFO;
|
||||||
sentry_log_info(logContent.c_str(), tags);
|
sentry_log_info(logContent.c_str(), tags);
|
||||||
break;
|
} break;
|
||||||
case SENTRY_LOG_WARNING:
|
case SENTRY_LOG_WARNING: {
|
||||||
sentry_msg_level = SENTRY_LEVEL_WARNING;
|
sentry_msg_level = SENTRY_LEVEL_WARNING;
|
||||||
sentry_log_warn(logContent.c_str(), tags);
|
sentry_log_warn(logContent.c_str(), tags);
|
||||||
break;
|
} break;
|
||||||
case SENTRY_LOG_ERROR:
|
case SENTRY_LOG_ERROR:
|
||||||
|
{
|
||||||
sentry_msg_level = SENTRY_LEVEL_ERROR;
|
sentry_msg_level = SENTRY_LEVEL_ERROR;
|
||||||
sentry_log_error(logContent.c_str(), tags);
|
sentry_log_error(logContent.c_str(), tags);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case SENTRY_LOG_FATAL:
|
case SENTRY_LOG_FATAL:
|
||||||
|
{
|
||||||
sentry_msg_level = SENTRY_LEVEL_FATAL;
|
sentry_msg_level = SENTRY_LEVEL_FATAL;
|
||||||
sentry_log_fatal(logContent.c_str(), tags);
|
sentry_log_fatal(logContent.c_str(), tags);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default: return;
|
default: return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user