diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index f956e9a4b..96dc21721 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -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") diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 0e290030e..870ea4f1a 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -691,6 +691,7 @@ wxWindow* PreferencesDialog::create_general_page() auto title_sync_settings = create_item_title(_L("User sync"), page, _L("User sync")); auto item_user_sync = create_item_checkbox(_L("Auto sync user presets(Printer/Filament/Process)"), page, _L("User Sync"), 50, "sync_user_preset"); +#ifdef _WIN32 auto title_associate_file = create_item_title(_L("Associate files to BambuStudio"), page, _L("Associate files to BambuStudio")); // associate file @@ -700,6 +701,7 @@ wxWindow* PreferencesDialog::create_general_page() _L("If enabled, sets BambuStudio as default application to open .stl files"), 50, "associate_stl"); auto item_associate_step = create_item_checkbox(_L("Associate .step/.stp files to BambuStudio"), page, _L("If enabled, sets BambuStudio as default application to open .step files"), 50, "associate_step"); +#endif // _WIN32 auto title_backup = create_item_title(_L("Backup"), page, _L("Backup")); @@ -713,10 +715,12 @@ wxWindow* PreferencesDialog::create_general_page() sizer_page->Add(item_currency, 0, wxTOP, FromDIP(3)); sizer_page->Add(title_sync_settings, 0, wxTOP | wxEXPAND, FromDIP(20)); sizer_page->Add(item_user_sync, 0, wxTOP, FromDIP(3)); +#ifdef _WIN32 sizer_page->Add(title_associate_file, 0, wxTOP| wxEXPAND, FromDIP(20)); sizer_page->Add(item_associate_3mf, 0, wxTOP, FromDIP(3)); sizer_page->Add(item_associate_stl, 0, wxTOP, FromDIP(3)); sizer_page->Add(item_associate_step, 0, wxTOP, FromDIP(3)); +#endif // _WIN32 sizer_page->Add(title_backup, 0, wxTOP| wxEXPAND, FromDIP(20)); sizer_page->Add(item_backup, 0, wxTOP,FromDIP(3)); sizer_page->Add(item_backup_interval, 0, wxTOP,FromDIP(3));