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.
63 lines
2.4 KiB
C++
63 lines
2.4 KiB
C++
#include "DevStorage.h"
|
|
#include <nlohmann/json.hpp>
|
|
#include <string>
|
|
|
|
|
|
using json = nlohmann::json;
|
|
|
|
namespace Slic3r {
|
|
|
|
DevStorage::SdcardState Slic3r::DevStorage::set_sdcard_state(int state)
|
|
|
|
{
|
|
if (state < DevStorage::NO_SDCARD || state > DevStorage::SDCARD_STATE_NUM) {
|
|
m_sdcard_state = DevStorage::NO_SDCARD;
|
|
} else {
|
|
m_sdcard_state = DevStorage::SdcardState(state);
|
|
}
|
|
return m_sdcard_state;
|
|
}
|
|
|
|
void DevStorage::ParseV1_0(const json &print_json, DevStorage *system)
|
|
{
|
|
if (system)
|
|
{
|
|
try {
|
|
if (print_json.contains("sdcard")) {
|
|
if (print_json["sdcard"].get<bool>())
|
|
system->m_sdcard_state = DevStorage::SdcardState::HAS_SDCARD_NORMAL;
|
|
else
|
|
system->m_sdcard_state = DevStorage::SdcardState::NO_SDCARD;
|
|
} else {
|
|
system->m_sdcard_state = DevStorage::SdcardState::NO_SDCARD;
|
|
}
|
|
|
|
// parse timelapse storage space from cam push data
|
|
if (print_json.contains("device") && print_json["device"].is_object()) {
|
|
const auto& device_json = print_json["device"];
|
|
if (device_json.contains("cam") && device_json["cam"].is_object()) {
|
|
const auto& cam_data = device_json["cam"];
|
|
if (cam_data.contains("tl_internal_free_kb"))
|
|
system->tl_internal_free_kb = cam_data["tl_internal_free_kb"].get<int>();
|
|
if (cam_data.contains("tl_internal_total_kb"))
|
|
system->tl_internal_total_kb = cam_data["tl_internal_total_kb"].get<int>();
|
|
if (cam_data.contains("tl_external_free_kb"))
|
|
system->tl_external_free_kb = cam_data["tl_external_free_kb"].get<int>();
|
|
if (cam_data.contains("tl_external_total_kb"))
|
|
system->tl_external_total_kb = cam_data["tl_external_total_kb"].get<int>();
|
|
}
|
|
}
|
|
} catch (...) {}
|
|
}
|
|
}
|
|
|
|
bool DevStorage::is_timelapse_storage_low(const std::string& storage) const
|
|
{
|
|
const int THRESHOLD_KB = 20480; // Orca: 20MB (20480 KB; corrected mislabeled comment)
|
|
if (storage == "internal")
|
|
return tl_internal_free_kb >= 0 && tl_internal_free_kb < THRESHOLD_KB;
|
|
else
|
|
return tl_external_free_kb >= 0 && tl_external_free_kb < THRESHOLD_KB;
|
|
}
|
|
|
|
} // namespace Slic3r
|