Printables.com support (associate prusaslicer:// link explicitly) (#5416)

* Enable ability to open `prusaslicer://` links

* Add needed function to miniz

* Import Zip Functionality

Allows zip file to be drag and dropped or imported via the menu option

Based on prusa3d/PrusaSlicer@ce38e57 and current master branch files

* Update dialog style to match Orca

* Ensure link is from printables

* add toggle option in preferences

doesn't actually control anything yet

* Add Downloader classes

As-is from PS master

* Create Orca Styled Variant of Icons

* Add Icons to ImGui

* Use PS's Downloader impl for `prusaslicer://` links

* Implement URL Registering on Windows

* Implement prusaslicer:// link on macOS

* Remove unnecessary class name qualifier in Plater.hpp

* Add downloader desktop integration registration and undo

* Revert Info.plist

* register prusaslicer:// on user request only

* fix build error

* fix single instance problem

* format

* add orcalicer:// handler for Mac
Attempt to add Linux support but seems not working

---------

Co-authored-by: Ocraftyone <Ocraftyone@users.noreply.github.com>
This commit is contained in:
SoftFever 2024-05-22 15:26:52 +08:00 committed by GitHub
parent a764d836e1
commit 7725fbeb90
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 111 additions and 60 deletions

View file

@ -821,7 +821,8 @@ void GUI_App::post_init()
(boost::starts_with(this->init_params->input_files.front(), "orcaslicer://open") ||
boost::starts_with(this->init_params->input_files.front(), "prusaslicer://open"))) {
if (boost::starts_with(this->init_params->input_files.front(), "prusaslicer://open")) {
if (boost::starts_with(this->init_params->input_files.front(), "orcaslicer://open")||
boost::starts_with(this->init_params->input_files.front(), "prusaslicer://open")) {
switch_to_3d = true;
start_download(this->init_params->input_files.front());
} else if (vector<string> input_str_arr = split_str(this->init_params->input_files.front(), "orcaslicer://open/?file="); input_str_arr.size() > 1) {
@ -1098,7 +1099,7 @@ GUI_App::GUI_App()
, m_em_unit(10)
, m_imgui(new ImGuiWrapper())
, m_removable_drive_manager(std::make_unique<RemovableDriveManager>())
, m_downloader(std::make_unique<Downloader>())
, m_downloader(std::make_unique<Downloader>())
, m_other_instance_message_handler(std::make_unique<OtherInstanceMessageHandler>())
{
//app config initializes early becasuse it is used in instance checking in OrcaSlicer.cpp
@ -2371,10 +2372,8 @@ bool GUI_App::on_init_inner()
associate_files(L"step");
associate_files(L"stp");
}
// Orca: add PS url functionality
if (app_config->get_bool("ps_url_registered")) {
associate_url(L"prusaslicer");
}
associate_url(L"orcaslicer");
if (app_config->get("associate_gcode") == "true")
associate_files(L"gcode");
#endif // __WXMSW__
@ -5533,10 +5532,7 @@ void GUI_App::open_preferences(size_t open_on_tab, const std::string& highlight_
associate_files(L"step");
associate_files(L"stp");
}
// Orca: add PS url functionality
if (app_config->get_bool("ps_url_registered")) {
associate_url(L"prusaslicer");
}
associate_url(L"orcaslicer");
}
else {
if (app_config->get("associate_gcode") == "true")
@ -6577,9 +6573,11 @@ static bool del_win_registry(HKEY hkeyHive, const wchar_t *pszVar, const wchar_t
return false;
}
#endif // __WXMSW__
void GUI_App::associate_files(std::wstring extend)
{
#ifdef WIN32
wchar_t app_path[MAX_PATH];
::GetModuleFileNameW(nullptr, app_path, sizeof(app_path));
@ -6599,10 +6597,12 @@ void GUI_App::associate_files(std::wstring extend)
if (is_new)
// notify Windows only when any of the values gets changed
::SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nullptr, nullptr);
#endif // WIN32
}
void GUI_App::disassociate_files(std::wstring extend)
{
#ifdef WIN32
wchar_t app_path[MAX_PATH];
::GetModuleFileNameW(nullptr, app_path, sizeof(app_path));
@ -6629,12 +6629,33 @@ void GUI_App::disassociate_files(std::wstring extend)
if (is_new)
::SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nullptr, nullptr);
#endif // WIN32
}
bool GUI_App::check_url_association(std::wstring url_prefix, std::wstring& reg_bin)
{
reg_bin = L"";
#ifdef WIN32
wxRegKey key_full(wxRegKey::HKCU, "Software\\Classes\\" + url_prefix + "\\shell\\open\\command");
if (!key_full.Exists()) {
return false;
}
reg_bin = key_full.QueryDefaultValue().ToStdWstring();
boost::filesystem::path binary_path(boost::filesystem::canonical(boost::dll::program_location()));
// wxString wbinary = wxString::FromUTF8(binary_path.string());
// std::string binary_string = (boost::format("%1%") % wbinary).str();
std::wstring key_string = L"\"" + binary_path.wstring() + L"\" L\"%1\"";
// return boost::iequals(key_string,(boost::format("%1%") % reg_bin).str());
return key_string == reg_bin;
#else
return false;
#endif // WIN32
}
void GUI_App::associate_url(std::wstring url_prefix)
{
// Registry key creation for "prusaslicer://" URL
#ifdef WIN32
boost::filesystem::path binary_path(boost::filesystem::canonical(boost::dll::program_location()));
// the path to binary needs to be correctly saved in string with respect to localized characters
wxString wbinary = wxString::FromUTF8(binary_path.string());
@ -6654,18 +6675,22 @@ void GUI_App::associate_url(std::wstring url_prefix)
key_full.Create(false);
}
key_full = key_string;
#elif defined(__linux__) && defined(SLIC3R_DESKTOP_INTEGRATION)
DesktopIntegrationDialog::perform_downloader_desktop_integration();
#endif // WIN32
}
void GUI_App::disassociate_url(std::wstring url_prefix)
{
#ifdef WIN32
wxRegKey key_full(wxRegKey::HKCU, "Software\\Classes\\" + url_prefix + "\\shell\\open\\command");
if (!key_full.Exists()) {
return;
}
key_full = "";
#endif // WIN32
}
#endif // __WXMSW__
void GUI_App::start_download(std::string url)
{