FIX: sync associate file after installation

Change-Id: Ib68f292b81b3d57ee44fb1548a50d04faea5dfb1
This commit is contained in:
zhimin.zeng 2022-09-28 18:39:40 +08:00 committed by Lane.Wei
parent d7a8219a8f
commit c37f489f35
2 changed files with 49 additions and 2 deletions

View file

@ -163,6 +163,31 @@ static std::string convert_studio_language_to_api(std::string lang_code)
return "en";*/
}
#ifdef _WIN32
bool is_associate_files(std::wstring extend)
{
wchar_t app_path[MAX_PATH];
::GetModuleFileNameW(nullptr, app_path, sizeof(app_path));
std::wstring prog_id = L" Bambu.Studio.1";
std::wstring reg_base = L"Software\\Classes";
std::wstring reg_extension = reg_base + L"\\." + extend;
wchar_t szValueCurrent[1000];
DWORD dwType;
DWORD dwSize = sizeof(szValueCurrent);
int iRC = ::RegGetValueW(HKEY_CURRENT_USER, reg_extension.c_str(), nullptr, RRF_RT_ANY, &dwType, szValueCurrent, &dwSize);
bool bDidntExist = iRC == ERROR_FILE_NOT_FOUND;
if (!bDidntExist && ::wcscmp(szValueCurrent, prog_id.c_str()) == 0)
return true;
return false;
}
#endif
class BBLSplashScreen : public wxSplashScreen
{
public:
@ -1791,6 +1816,20 @@ void GUI_App::init_app_config()
// Save orig_version here, so its empty if no app_config existed before this run.
m_last_config_version = app_config->orig_version();//parse_semver_from_ini(app_config->config_path());
}
else {
#ifdef _WIN32
// update associate files from registry information
if (is_associate_files(L"3mf")) {
app_config->set("associate_3mf", "true");
}
if (is_associate_files(L"stl")) {
app_config->set("associate_stl", "true");
}
if (is_associate_files(L"step") && is_associate_files(L"stp")) {
app_config->set("associate_step", "true");
}
#endif // _WIN32
}
}
// returns true if found newer version and user agreed to use it
@ -2019,8 +2058,10 @@ bool GUI_App::on_init_inner()
associate_files(L"3mf");
if (app_config->get("associate_stl") == "true")
associate_files(L"stl");
if (app_config->get("associate_step") == "true")
if (app_config->get("associate_step") == "true") {
associate_files(L"step");
associate_files(L"stp");
}
if (app_config->get("associate_gcode") == "true")
associate_files(L"gcode");
#endif // __WXMSW__
@ -4264,8 +4305,10 @@ void GUI_App::open_preferences(size_t open_on_tab, const std::string& highlight_
associate_files(L"3mf");
if (app_config->get("associate_stl") == "true")
associate_files(L"stl");
if (app_config->get("associate_step") == "true")
if (app_config->get("associate_step") == "true") {
associate_files(L"step");
associate_files(L"stp");
}
}
else {
if (app_config->get("associate_gcode") == "true")