OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::instance_id::anonymous_namespace{InstanceID.cpp} Namespace Reference

Functions

std::mutex & cache_mutex ()
std::string & cached_iid ()
bool & cache_ready ()
std::optional< std::string > normalize_uuid (std::string value)
std::optional< std::string > read_config_value (AppConfig &config)
void write_config_value (AppConfig &config, const std::string &value)
void prune_config_value (AppConfig &config)
boost::filesystem::path storage_path ()
std::optional< std::string > read_storage_file ()
bool write_storage_file (const std::string &value)
std::optional< std::string > read_secure ()
bool write_secure (const std::string &value)
std::string generate_uuid ()

Variables

constexpr const char * CONFIG_KEY = "updater_iid"
constexpr const char * LEGACY_KEY = "iid"

Function Documentation

◆ cache_mutex()

std::mutex & Slic3r::instance_id::anonymous_namespace{InstanceID.cpp}::cache_mutex ( )
36{
37 static std::mutex mtx;
38 return mtx;
39}

References cache_mutex().

Referenced by cache_mutex().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cache_ready()

bool & Slic3r::instance_id::anonymous_namespace{InstanceID.cpp}::cache_ready ( )
48{
49 static bool ready = false;
50 return ready;
51}

References cache_ready().

Referenced by cache_ready().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cached_iid()

std::string & Slic3r::instance_id::anonymous_namespace{InstanceID.cpp}::cached_iid ( )
42{
43 static std::string value;
44 return value;
45}

References cached_iid().

Referenced by cached_iid().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generate_uuid()

std::string Slic3r::instance_id::anonymous_namespace{InstanceID.cpp}::generate_uuid ( )
163{
164 const auto uuid = boost::uuids::random_generator()();
165 return boost::uuids::to_string(uuid);
166}

References generate_uuid().

Referenced by generate_uuid().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ normalize_uuid()

std::optional< std::string > Slic3r::instance_id::anonymous_namespace{InstanceID.cpp}::normalize_uuid ( std::string value)
54{
55 boost::algorithm::trim(value);
56 boost::algorithm::to_lower(value);
57 if (value.size() != 36)
58 return std::nullopt;
59 try {
60 const boost::uuids::uuid parsed = boost::uuids::string_generator()(value);
61 if (parsed.version() != boost::uuids::uuid::version_random_number_based)
62 return std::nullopt;
63 return value;
64 } catch (...) {
65 return std::nullopt;
66 }
67}

References normalize_uuid().

Referenced by normalize_uuid(), read_config_value(), and read_storage_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ prune_config_value()

void Slic3r::instance_id::anonymous_namespace{InstanceID.cpp}::prune_config_value ( AppConfig & config)
93{
94 if (config.has(CONFIG_KEY))
95 config.erase("app", CONFIG_KEY);
96 if (config.has(LEGACY_KEY))
97 config.erase("app", LEGACY_KEY);
98}
bool has(const std::string &section, const std::string &key) const
Definition AppConfig.hpp:222
void erase(const std::string &section, const std::string &key)
Definition AppConfig.hpp:233
constexpr const char * LEGACY_KEY
Definition InstanceID.cpp:33
constexpr const char * CONFIG_KEY
Definition InstanceID.cpp:32

References CONFIG_KEY, Slic3r::AppConfig::erase(), Slic3r::AppConfig::has(), LEGACY_KEY, and prune_config_value().

Referenced by prune_config_value().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_config_value()

std::optional< std::string > Slic3r::instance_id::anonymous_namespace{InstanceID.cpp}::read_config_value ( AppConfig & config)
70{
71 const auto read_key = [&](const char* key) -> std::optional<std::string> {
72 const std::string raw = config.get(key);
73 if (raw.empty())
74 return std::nullopt;
75 if (auto normalized = normalize_uuid(raw))
76 return normalized;
77 return std::nullopt;
78 };
79
80 if (auto value = read_key(CONFIG_KEY))
81 return value;
82 return read_key(LEGACY_KEY);
83}
bool get(const std::string &section, const std::string &key, std::string &value) const
Definition AppConfig.hpp:147
std::optional< std::string > normalize_uuid(std::string value)
Definition InstanceID.cpp:53

References CONFIG_KEY, Slic3r::AppConfig::get(), LEGACY_KEY, normalize_uuid(), and read_config_value().

Referenced by read_config_value().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_secure()

std::optional< std::string > Slic3r::instance_id::anonymous_namespace{InstanceID.cpp}::read_secure ( )
153{
154 return read_storage_file();
155}
std::optional< std::string > read_storage_file()
Definition InstanceID.cpp:108

References read_secure(), and read_storage_file().

Referenced by read_secure().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_storage_file()

std::optional< std::string > Slic3r::instance_id::anonymous_namespace{InstanceID.cpp}::read_storage_file ( )
109{
110 const auto path = storage_path();
111 if (path.empty() || !boost::filesystem::exists(path))
112 return std::nullopt;
113
114 boost::nowide::ifstream file(path.string());
115 if (!file)
116 return std::nullopt;
117
118 std::string value;
119 std::getline(file, value);
120 file.close();
121
122 return normalize_uuid(value);
123}
boost::filesystem::path storage_path()
Definition InstanceID.cpp:100

References normalize_uuid(), read_storage_file(), and storage_path().

Referenced by read_secure(), and read_storage_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ storage_path()

boost::filesystem::path Slic3r::instance_id::anonymous_namespace{InstanceID.cpp}::storage_path ( )
101{
102 const std::string& base_dir = Slic3r::data_dir();
103 if (base_dir.empty())
104 return {};
105 return boost::filesystem::path(base_dir) / ".orcaslicer_machine_id";
106}
const std::string & data_dir()
Definition utils.cpp:365

References Slic3r::data_dir(), and storage_path().

Referenced by read_storage_file(), storage_path(), and write_storage_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_config_value()

void Slic3r::instance_id::anonymous_namespace{InstanceID.cpp}::write_config_value ( AppConfig & config,
const std::string & value )
86{
87 config.set(CONFIG_KEY, value);
88 if (config.get(LEGACY_KEY) != value)
89 config.set(LEGACY_KEY, value);
90}
void set(const std::string &section, const std::string &key, const std::string &value)
Definition AppConfig.hpp:167

References CONFIG_KEY, Slic3r::AppConfig::get(), LEGACY_KEY, Slic3r::AppConfig::set(), and write_config_value().

Referenced by write_config_value().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_secure()

bool Slic3r::instance_id::anonymous_namespace{InstanceID.cpp}::write_secure ( const std::string & value)
158{
159 return write_storage_file(value);
160}
bool write_storage_file(const std::string &value)
Definition InstanceID.cpp:125

References write_secure(), and write_storage_file().

Referenced by write_secure().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_storage_file()

bool Slic3r::instance_id::anonymous_namespace{InstanceID.cpp}::write_storage_file ( const std::string & value)
126{
127 if (value.empty())
128 return false;
129
130 const auto path = storage_path();
131 if (path.empty())
132 return false;
133
134 const auto parent = path.parent_path();
135 boost::system::error_code ec;
136 if (!parent.empty() && !boost::filesystem::exists(parent))
137 boost::filesystem::create_directories(parent, ec);
138
139 if (ec)
140 return false;
141
142 boost::nowide::ofstream file(path.string(), std::ios::trunc);
143 if (!file)
144 return false;
145
146 file << value;
147 file.close();
148
149 return file.good();
150}

References storage_path(), and write_storage_file().

Referenced by write_secure(), and write_storage_file().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ CONFIG_KEY

const char* Slic3r::instance_id::anonymous_namespace{InstanceID.cpp}::CONFIG_KEY = "updater_iid"
constexpr

◆ LEGACY_KEY

const char* Slic3r::instance_id::anonymous_namespace{InstanceID.cpp}::LEGACY_KEY = "iid"
constexpr