diff --git a/src/slic3r/GUI/DesktopIntegrationDialog.cpp b/src/slic3r/GUI/DesktopIntegrationDialog.cpp index d8f3dc025b..639d167229 100644 --- a/src/slic3r/GUI/DesktopIntegrationDialog.cpp +++ b/src/slic3r/GUI/DesktopIntegrationDialog.cpp @@ -139,20 +139,35 @@ bool contains_path_dir(const std::string& p, const std::string& dir_name) if (p.empty() || dir_name.empty()) return false; boost::filesystem::path path(p + (p[p.size()-1] == '/' ? "" : "/") + dir_name); - if (boost::filesystem::exists(path) && boost::filesystem::is_directory(path)) { + boost::system::error_code ec; + if (boost::filesystem::exists(path, ec) && !ec) { //BOOST_LOG_TRIVIAL(debug) << path.string() << " " << std::oct << boost::filesystem::status(path).permissions(); - return true; //boost::filesystem::status(path).permissions() & boost::filesystem::owner_write; + return boost::filesystem::is_directory(path); //boost::filesystem::status(path).permissions() & boost::filesystem::owner_write; } else BOOST_LOG_TRIVIAL(debug) << path.string() << " doesnt exists"; return false; } + +boost::filesystem::path get_existing_dir(const std::string& sub, const std::string& dir_name) +{ + assert(!p.empty() && !dir_name.empty()); + boost::filesystem::path path = boost::filesystem::path(sub) / dir_name; + boost::system::error_code ec; + if (!boost::filesystem::exists(path, ec) || ec) { + return boost::filesystem::path(); + } + if (!boost::filesystem::is_directory(path, ec) || ec) { + return boost::filesystem::path(); + } + return path; +} // Creates directory in path if not exists yet void create_dir(const boost::filesystem::path& path) { - if (boost::filesystem::exists(path)) + boost::system::error_code ec; + if (boost::filesystem::exists(path, ec) && !ec) return; BOOST_LOG_TRIVIAL(debug)<< "creating " << path.string(); - boost::system::error_code ec; boost::filesystem::create_directory(path, ec); if (ec) BOOST_LOG_TRIVIAL(error)<< "create directory failed: " << ec.message(); @@ -627,6 +642,38 @@ void DesktopIntegrationDialog::undo_downloader_registration() } // There is no need to undo xdg-mime default command. It is done automatically when desktop file is deleted. } +void DesktopIntegrationDialog::undo_downloader_registration_rigid() +{ + // Try ro find any PrusaSlicerURLProtocol.desktop files including alpha and beta and get rid of them + + // $XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored. + // If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used. + // $XDG_DATA_DIRS defines the preference-ordered set of base directories to search for data files in addition to the $XDG_DATA_HOME base directory. + // The directories in $XDG_DATA_DIRS should be seperated with a colon ':'. + // If $XDG_DATA_DIRS is either not set or empty, a value equal to /usr/local/share/:/usr/share/ should be used. + std::vectortarget_candidates; + target_candidates.emplace_back(GUI::into_u8(wxFileName::GetHomeDir()) + "/.local/share"); + resolve_path_from_var("XDG_DATA_HOME", target_candidates); + resolve_path_from_var("XDG_DATA_DIRS", target_candidates); + for (const std::string cand : target_candidates) { + boost::filesystem::path apps_path = get_existing_dir(cand, "applications"); + if (apps_path.empty()) { + continue; + } + for (const std::string& suffix : {"" , "-beta", "-alpha"}) { + boost::filesystem::path file_path = apps_path / GUI::format("PrusaSlicerURLProtocol%1%.desktop", suffix); + boost::system::error_code ec; + if (!boost::filesystem::exists(file_path, ec) || ec) { + continue; + } + if (!boost::filesystem::remove(file_path, ec) || ec) { + BOOST_LOG_TRIVIAL(error) << "Failed to remove file " << file_path << " ec: " << ec.message(); + continue; + } + BOOST_LOG_TRIVIAL(info) << "Desktop File removed: " << file_path; + } + } +} DesktopIntegrationDialog::DesktopIntegrationDialog(wxWindow *parent) : wxDialog(parent, wxID_ANY, _(L("Desktop Integration")), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER) diff --git a/src/slic3r/GUI/DesktopIntegrationDialog.hpp b/src/slic3r/GUI/DesktopIntegrationDialog.hpp index 4c2263d0fd..c26ad6b8d4 100644 --- a/src/slic3r/GUI/DesktopIntegrationDialog.hpp +++ b/src/slic3r/GUI/DesktopIntegrationDialog.hpp @@ -39,6 +39,7 @@ public: static void perform_downloader_desktop_integration(); static void undo_downloader_registration(); + static void undo_downloader_registration_rigid(); private: }; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index a061d95e3a..b7f51b5fb1 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -881,9 +881,13 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) if (dialog.ShowModal() != wxID_OK) { if(!dialog_msg.empty()) { DownloaderUtils::Worker::perform_register(wxGetApp().app_config->get("url_downloader_dest")); -#ifdef __linux__ +#if defined(__linux__) && defined(SLIC3R_DESKTOP_INTEGRATION) if (DownloaderUtils::Worker::perform_registration_linux) DesktopIntegrationDialog::perform_downloader_desktop_integration(); +#elif defined(__linux__) && ! defined(SLIC3R_DESKTOP_INTEGRATION) + // ! defined(SLIC3R_DESKTOP_INTEGRATION) means the desktop integration was done elswhere f.e. by flatpack + // Remove all desktop files registering prusaslicer:// url done by previous versions. + DesktopIntegrationDialog::undo_downloader_registration_rigid(); #endif // __linux__ wxGetApp().open_login_browser_with_dialog(/*dialog_msg*/evt.data.second); }