mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-01 07:22:00 +08:00
Merge branch 'dk_app_updater'
This commit is contained in:
commit
b1546fa77a
@ -176,26 +176,21 @@ void FileGet::priv::get_perform()
|
|||||||
}
|
}
|
||||||
|
|
||||||
boost::filesystem::path dest_path = m_dest_folder / m_filename;
|
boost::filesystem::path dest_path = m_dest_folder / m_filename;
|
||||||
|
|
||||||
wxString temp_path_wstring(m_tmp_path.wstring());
|
|
||||||
|
|
||||||
//std::cout << "dest_path: " << dest_path.string() << std::endl;
|
|
||||||
//std::cout << "m_tmp_path: " << m_tmp_path.string() << std::endl;
|
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(info) << GUI::format("Starting download from %1% to %2%. Temp path is %3%",m_url, dest_path, m_tmp_path);
|
BOOST_LOG_TRIVIAL(info) << GUI::format("Starting download from %1% to %2%. Temp path is %3%",m_url, dest_path, m_tmp_path);
|
||||||
|
|
||||||
FILE* file;
|
FILE* file;
|
||||||
// open file for writting
|
// open file for writting
|
||||||
if (m_written == 0)
|
if (m_written == 0)
|
||||||
file = fopen(temp_path_wstring.c_str(), "wb");
|
file = boost::nowide::fopen(m_tmp_path.string().c_str(), "wb");
|
||||||
else
|
else
|
||||||
file = fopen(temp_path_wstring.c_str(), "ab");
|
file = boost::nowide::fopen(m_tmp_path.string().c_str(), "ab");
|
||||||
|
|
||||||
//assert(file != NULL);
|
//assert(file != NULL);
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
wxCommandEvent* evt = new wxCommandEvent(EVT_DWNLDR_FILE_ERROR);
|
wxCommandEvent* evt = new wxCommandEvent(EVT_DWNLDR_FILE_ERROR);
|
||||||
// TRN %1% = file path
|
// TRN %1% = file path
|
||||||
evt->SetString(GUI::format_wxstr(_L("Can't create file at %1%"), temp_path_wstring));
|
evt->SetString(GUI::format_wxstr(_L("Can't create file at %1%"), m_tmp_path.string()));
|
||||||
evt->SetInt(m_id);
|
evt->SetInt(m_id);
|
||||||
m_evt_handler->QueueEvent(evt);
|
m_evt_handler->QueueEvent(evt);
|
||||||
return;
|
return;
|
||||||
|
@ -3227,7 +3227,7 @@ wxString GUI_App::current_language_code_safe() const
|
|||||||
|
|
||||||
void GUI_App::open_web_page_localized(const std::string &http_address)
|
void GUI_App::open_web_page_localized(const std::string &http_address)
|
||||||
{
|
{
|
||||||
open_browser_with_warning_dialog(http_address + "&lng=" + this->current_language_code_safe(), nullptr, false);
|
open_browser_with_warning_dialog(from_u8(http_address + "&lng=") + this->current_language_code_safe(), nullptr, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we are switching from the FFF-preset to the SLA, we should to control the printed objects if they have a part(s).
|
// If we are switching from the FFF-preset to the SLA, we should to control the printed objects if they have a part(s).
|
||||||
@ -3544,42 +3544,64 @@ bool GUI_App::check_updates(const bool invoked_by_user)
|
|||||||
// Applicaiton will continue.
|
// Applicaiton will continue.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
namespace {
|
||||||
|
bool open_dialog_hyperlink_checkbox(wxWindow* parent, AppConfig* app_config)
|
||||||
|
{
|
||||||
|
RichMessageDialog dialog(parent, _L("Open hyperlink in default browser?"), _L("PrusaSlicer: Open hyperlink"), wxICON_QUESTION | wxYES_NO);
|
||||||
|
dialog.ShowCheckBox(_L("Remember my choice"));
|
||||||
|
auto answer = dialog.ShowModal();
|
||||||
|
bool launch = answer == wxID_YES;
|
||||||
|
if (dialog.IsCheckBoxChecked()) {
|
||||||
|
wxString preferences_item = _L("Suppress to open hyperlink in browser");
|
||||||
|
wxString msg =
|
||||||
|
_L("PrusaSlicer will remember your choice.") + "\n\n" +
|
||||||
|
_L("You will not be asked about it again on hyperlinks hovering.") + "\n\n" +
|
||||||
|
format_wxstr(_L("Visit \"Preferences\" and check \"%1%\"\nto changes your choice."), preferences_item);
|
||||||
|
|
||||||
|
MessageDialog msg_dlg(parent, msg, _L("PrusaSlicer: Don't ask me again"), wxOK | wxCANCEL | wxICON_INFORMATION);
|
||||||
|
if (msg_dlg.ShowModal() == wxID_CANCEL)
|
||||||
|
return false;
|
||||||
|
app_config->set("suppress_hyperlinks", answer == wxID_NO ? "1" : "0");
|
||||||
|
}
|
||||||
|
return launch;
|
||||||
|
}
|
||||||
|
bool open_dialog_hyperlink(wxWindow* parent)
|
||||||
|
{
|
||||||
|
MessageDialog dialog(parent, _L("Open hyperlink in default browser?"), _L("PrusaSlicer: Open hyperlink"), wxICON_QUESTION | wxYES_NO);
|
||||||
|
return dialog.ShowModal() == wxID_YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
bool GUI_App::open_browser_with_warning_dialog(const wxString& url, wxWindow* parent/* = nullptr*/, bool force_remember_choice /*= true*/, int flags/* = 0*/)
|
bool GUI_App::open_browser_with_warning_dialog(const wxString& url, wxWindow* parent/* = nullptr*/, bool force_remember_choice /*= true*/, int flags/* = 0*/)
|
||||||
{
|
{
|
||||||
|
enum class SupressHyperLinksOption{
|
||||||
|
SHLO_UNCHECKED,
|
||||||
|
SHLO_ALWAYS_SUPRESS,
|
||||||
|
SHLO_ALWAYS_ALLOW
|
||||||
|
};
|
||||||
|
bool empty = app_config->get("suppress_hyperlinks").empty();
|
||||||
|
bool checked = app_config->get_bool("suppress_hyperlinks");
|
||||||
|
SupressHyperLinksOption opt_val =
|
||||||
|
(empty
|
||||||
|
? SupressHyperLinksOption::SHLO_UNCHECKED
|
||||||
|
: (checked
|
||||||
|
? SupressHyperLinksOption::SHLO_ALWAYS_SUPRESS
|
||||||
|
: SupressHyperLinksOption::SHLO_ALWAYS_ALLOW));
|
||||||
bool launch = true;
|
bool launch = true;
|
||||||
|
if (opt_val == SupressHyperLinksOption::SHLO_UNCHECKED) {
|
||||||
// warning dialog containes a "Remember my choice" checkbox
|
// no previous action from user
|
||||||
std::string option_key = "suppress_hyperlinks";
|
// open dialog with remember checkbox
|
||||||
if (force_remember_choice || app_config->get(option_key).empty()) {
|
launch = open_dialog_hyperlink_checkbox(parent, app_config);
|
||||||
if (app_config->get(option_key).empty()) {
|
} else if (opt_val == SupressHyperLinksOption::SHLO_ALWAYS_ALLOW) {
|
||||||
RichMessageDialog dialog(parent, _L("Open hyperlink in default browser?"), _L("PrusaSlicer: Open hyperlink"), wxICON_QUESTION | wxYES_NO);
|
// user already set checkbox to always open
|
||||||
dialog.ShowCheckBox(_L("Remember my choice"));
|
launch = true;
|
||||||
auto answer = dialog.ShowModal();
|
} else if (opt_val == SupressHyperLinksOption::SHLO_ALWAYS_SUPRESS && force_remember_choice) {
|
||||||
launch = answer == wxID_YES;
|
// user already set checkbox or preferences to always supress
|
||||||
if (dialog.IsCheckBoxChecked()) {
|
launch = false;
|
||||||
wxString preferences_item = _L("Suppress to open hyperlink in browser");
|
} else if (opt_val == SupressHyperLinksOption::SHLO_ALWAYS_SUPRESS && !force_remember_choice) {
|
||||||
wxString msg =
|
// user already set checkbox or preferences to always supress but it is overriden
|
||||||
_L("PrusaSlicer will remember your choice.") + "\n\n" +
|
// no checkbox in dialog
|
||||||
_L("You will not be asked about it again on hyperlinks hovering.") + "\n\n" +
|
launch = open_dialog_hyperlink(parent);
|
||||||
format_wxstr(_L("Visit \"Preferences\" and check \"%1%\"\nto changes your choice."), preferences_item);
|
}
|
||||||
|
|
||||||
MessageDialog msg_dlg(parent, msg, _L("PrusaSlicer: Don't ask me again"), wxOK | wxCANCEL | wxICON_INFORMATION);
|
|
||||||
if (msg_dlg.ShowModal() == wxID_CANCEL)
|
|
||||||
return false;
|
|
||||||
app_config->set(option_key, answer == wxID_NO ? "1" : "0");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (launch)
|
|
||||||
launch = !app_config->get_bool(option_key);
|
|
||||||
}
|
|
||||||
// warning dialog doesn't containe a "Remember my choice" checkbox
|
|
||||||
// and will be shown only when "Suppress to open hyperlink in browser" is ON.
|
|
||||||
else if (app_config->get_bool(option_key)) {
|
|
||||||
MessageDialog dialog(parent, _L("Open hyperlink in default browser?"), _L("PrusaSlicer: Open hyperlink"), wxICON_QUESTION | wxYES_NO);
|
|
||||||
launch = dialog.ShowModal() == wxID_YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
return launch && wxLaunchDefaultBrowser(url, flags);
|
return launch && wxLaunchDefaultBrowser(url, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3701,7 +3723,7 @@ void GUI_App::app_updater(bool from_user)
|
|||||||
assert(!app_data.target_path.empty());
|
assert(!app_data.target_path.empty());
|
||||||
|
|
||||||
// dialog with new version info
|
// dialog with new version info
|
||||||
AppUpdateAvailableDialog dialog(*Semver::parse(SLIC3R_VERSION), *app_data.version, from_user);
|
AppUpdateAvailableDialog dialog(*Semver::parse(SLIC3R_VERSION), *app_data.version, from_user, app_data.action == AppUpdaterURLAction::AUUA_OPEN_IN_BROWSER);
|
||||||
auto dialog_result = dialog.ShowModal();
|
auto dialog_result = dialog.ShowModal();
|
||||||
// checkbox "do not show again"
|
// checkbox "do not show again"
|
||||||
if (dialog.disable_version_check()) {
|
if (dialog.disable_version_check()) {
|
||||||
@ -3711,6 +3733,10 @@ void GUI_App::app_updater(bool from_user)
|
|||||||
if (dialog_result != wxID_OK) {
|
if (dialog_result != wxID_OK) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (app_data.action == AppUpdaterURLAction::AUUA_OPEN_IN_BROWSER) {
|
||||||
|
open_browser_with_warning_dialog(from_u8(app_data.url), nullptr, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
// dialog with new version download (installer or app dependent on system) including path selection
|
// dialog with new version download (installer or app dependent on system) including path selection
|
||||||
AppUpdateDownloadDialog dwnld_dlg(*app_data.version, app_data.target_path);
|
AppUpdateDownloadDialog dwnld_dlg(*app_data.version, app_data.target_path);
|
||||||
dialog_result = dwnld_dlg.ShowModal();
|
dialog_result = dwnld_dlg.ShowModal();
|
||||||
|
@ -99,7 +99,7 @@ bool MsgUpdateSlic3r::disable_version_check() const
|
|||||||
|
|
||||||
wxSize AppUpdateAvailableDialog::AUAD_size;
|
wxSize AppUpdateAvailableDialog::AUAD_size;
|
||||||
// AppUpdater
|
// AppUpdater
|
||||||
AppUpdateAvailableDialog::AppUpdateAvailableDialog(const Semver& ver_current, const Semver& ver_online, bool from_user)
|
AppUpdateAvailableDialog::AppUpdateAvailableDialog(const Semver& ver_current, const Semver& ver_online, bool from_user, bool browser_on_next)
|
||||||
: MsgDialog(nullptr, _(L("App Update available")), wxString::Format(_(L("New version of %s is available.\nDo you wish to download it?")), SLIC3R_APP_NAME))
|
: MsgDialog(nullptr, _(L("App Update available")), wxString::Format(_(L("New version of %s is available.\nDo you wish to download it?")), SLIC3R_APP_NAME))
|
||||||
{
|
{
|
||||||
auto* versions = new wxFlexGridSizer(1, 0, VERT_SPACING);
|
auto* versions = new wxFlexGridSizer(1, 0, VERT_SPACING);
|
||||||
@ -116,6 +116,12 @@ AppUpdateAvailableDialog::AppUpdateAvailableDialog(const Semver& ver_current, co
|
|||||||
}
|
}
|
||||||
content_sizer->AddSpacer(VERT_SPACING);
|
content_sizer->AddSpacer(VERT_SPACING);
|
||||||
|
|
||||||
|
if (browser_on_next)
|
||||||
|
{
|
||||||
|
content_sizer->Add(new wxStaticText(this, wxID_ANY, _(L("Clicking \'Next\' will open a browser window to select your download."))));
|
||||||
|
content_sizer->AddSpacer(VERT_SPACING);
|
||||||
|
}
|
||||||
|
|
||||||
AUAD_size = content_sizer->GetSize();
|
AUAD_size = content_sizer->GetSize();
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ private:
|
|||||||
class AppUpdateAvailableDialog : public MsgDialog
|
class AppUpdateAvailableDialog : public MsgDialog
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AppUpdateAvailableDialog(const Semver& ver_current, const Semver& ver_online, bool from_user);
|
AppUpdateAvailableDialog(const Semver& ver_current, const Semver& ver_online, bool from_user, bool browser_on_next);
|
||||||
AppUpdateAvailableDialog(AppUpdateAvailableDialog&&) = delete;
|
AppUpdateAvailableDialog(AppUpdateAvailableDialog&&) = delete;
|
||||||
AppUpdateAvailableDialog(const AppUpdateAvailableDialog&) = delete;
|
AppUpdateAvailableDialog(const AppUpdateAvailableDialog&) = delete;
|
||||||
AppUpdateAvailableDialog& operator=(AppUpdateAvailableDialog&&) = delete;
|
AppUpdateAvailableDialog& operator=(AppUpdateAvailableDialog&&) = delete;
|
||||||
|
@ -294,7 +294,7 @@ void WifiConfigDialog::on_ok(wxCommandEvent& e)
|
|||||||
|
|
||||||
m_used_path = boost::nowide::widen(file_path.string());
|
m_used_path = boost::nowide::widen(file_path.string());
|
||||||
FILE* file;
|
FILE* file;
|
||||||
file = fopen(file_path.string().c_str(), "w");
|
file = boost::nowide::fopen(file_path.string().c_str(), "w");
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
BOOST_LOG_TRIVIAL(error) << "Failed to write to file " << file_path;
|
BOOST_LOG_TRIVIAL(error) << "Failed to write to file " << file_path;
|
||||||
// TODO show error
|
// TODO show error
|
||||||
|
@ -45,7 +45,7 @@ namespace {
|
|||||||
bool res = GUI::create_process(path, std::wstring(), msg);
|
bool res = GUI::create_process(path, std::wstring(), msg);
|
||||||
if (!res) {
|
if (!res) {
|
||||||
std::string full_message = GUI::format(_u8L("Running downloaded instaler of %1% has failed:\n%2%"), SLIC3R_APP_NAME, msg);
|
std::string full_message = GUI::format(_u8L("Running downloaded instaler of %1% has failed:\n%2%"), SLIC3R_APP_NAME, msg);
|
||||||
BOOST_LOG_TRIVIAL(error) << full_message; // lm: maybe UI error msg? // dk: bellow. (maybe some general show error evt would be better?)
|
BOOST_LOG_TRIVIAL(error) << full_message;
|
||||||
wxCommandEvent* evt = new wxCommandEvent(EVT_SLIC3R_APP_DOWNLOAD_FAILED);
|
wxCommandEvent* evt = new wxCommandEvent(EVT_SLIC3R_APP_DOWNLOAD_FAILED);
|
||||||
evt->SetString(full_message);
|
evt->SetString(full_message);
|
||||||
GUI::wxGetApp().QueueEvent(evt);
|
GUI::wxGetApp().QueueEvent(evt);
|
||||||
@ -165,7 +165,7 @@ AppUpdater::priv::priv() :
|
|||||||
if (!downloads_path.empty()) {
|
if (!downloads_path.empty()) {
|
||||||
m_default_dest_folder = std::move(downloads_path);
|
m_default_dest_folder = std::move(downloads_path);
|
||||||
}
|
}
|
||||||
BOOST_LOG_TRIVIAL(trace) << "App updater default download path: " << m_default_dest_folder; //lm:Is this an error? // dk: changed to trace
|
BOOST_LOG_TRIVIAL(trace) << "App updater default download path: " << m_default_dest_folder;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,8 +221,7 @@ boost::filesystem::path AppUpdater::priv::download_file(const DownloadAppData& d
|
|||||||
boost::filesystem::path tmp_path = dest_path;
|
boost::filesystem::path tmp_path = dest_path;
|
||||||
tmp_path += format(".%1%%2%", std::to_string(GUI::GLCanvas3D::timestamp_now()), ".download");
|
tmp_path += format(".%1%%2%", std::to_string(GUI::GLCanvas3D::timestamp_now()), ".download");
|
||||||
FILE* file;
|
FILE* file;
|
||||||
wxString temp_path_wstring(tmp_path.wstring());
|
file = boost::nowide::fopen(tmp_path.string().c_str(), "wb");
|
||||||
file = fopen(temp_path_wstring.c_str(), "wb");
|
|
||||||
assert(file != NULL);
|
assert(file != NULL);
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
std::string line1 = GUI::format(_u8L("Download from %1% couldn't start:"), data.url);
|
std::string line1 = GUI::format(_u8L("Download from %1% couldn't start:"), data.url);
|
||||||
@ -236,7 +235,7 @@ boost::filesystem::path AppUpdater::priv::download_file(const DownloadAppData& d
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string error_message;
|
std::string error_message;
|
||||||
bool res = http_get_file(data.url, 130 * 1024 * 1024 //2.4.0 windows installer is 65MB //lm:I don't know, but larger. The binaries will grow. // dk: changed to 130, to have 100% more space. We should put this information into version file.
|
bool res = http_get_file(data.url, 256 * 1024 * 1024
|
||||||
// on_progress
|
// on_progress
|
||||||
, [&last_gui_progress, expected_size](Http::Progress progress) {
|
, [&last_gui_progress, expected_size](Http::Progress progress) {
|
||||||
// size check
|
// size check
|
||||||
@ -333,10 +332,6 @@ void AppUpdater::priv::version_check(const std::string& version_check_url)
|
|||||||
}
|
}
|
||||||
, error_message
|
, error_message
|
||||||
);
|
);
|
||||||
//lm:In case the internet is not available, it will report no updates if run by user.
|
|
||||||
// We might save a flag that we don't know or try to run the version_check again, reporting
|
|
||||||
// the failure.
|
|
||||||
// dk: changed to download version every time. Dialog will show if m_triggered_by_user.
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
std::string message = GUI::format("Downloading %1% version file has failed:\n%2%", SLIC3R_APP_NAME, error_message);
|
std::string message = GUI::format("Downloading %1% version file has failed:\n%2%", SLIC3R_APP_NAME, error_message);
|
||||||
BOOST_LOG_TRIVIAL(error) << message;
|
BOOST_LOG_TRIVIAL(error) << message;
|
||||||
@ -390,19 +385,21 @@ void AppUpdater::priv::parse_version_string(const std::string& body)
|
|||||||
#else
|
#else
|
||||||
"release:linux"
|
"release:linux"
|
||||||
#endif
|
#endif
|
||||||
//lm:Related to the ifdefs. We should also support BSD, which behaves similar to Linux in most cases.
|
|
||||||
// Unless you have a reason not to, I would consider doing _WIN32, elif __APPLE__, else ... Not just here.
|
|
||||||
// dk: so its ok now or we need to specify BSD?
|
|
||||||
) {
|
) {
|
||||||
for (const auto& data : section.second) {
|
for (const auto& data : section.second) {
|
||||||
if (data.first == "url") {
|
if (data.first == "url") {
|
||||||
new_data.url = data.second.data();
|
new_data.url = data.second.data();
|
||||||
new_data.target_path = m_default_dest_folder / AppUpdater::get_filename_from_url(new_data.url);
|
new_data.target_path = m_default_dest_folder / AppUpdater::get_filename_from_url(new_data.url);
|
||||||
BOOST_LOG_TRIVIAL(info) << format("parsing version string: url: %1%", new_data.url);
|
BOOST_LOG_TRIVIAL(info) << format("parsing version string: url: %1%", new_data.url);
|
||||||
} else if (data.first == "size"){
|
} else if (data.first == "size") {
|
||||||
new_data.size = std::stoi(data.second.data());
|
new_data.size = std::stoi(data.second.data());
|
||||||
BOOST_LOG_TRIVIAL(info) << format("parsing version string: expected size: %1%", new_data.size);
|
BOOST_LOG_TRIVIAL(info) << format("parsing version string: expected size: %1%", new_data.size);
|
||||||
}
|
} else if (data.first == "action") {
|
||||||
|
std::string action = data.second.data();
|
||||||
|
if (action == "browser") {
|
||||||
|
new_data.action = AppUpdaterURLAction::AUUA_OPEN_IN_BROWSER;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,10 @@ namespace Slic3r {
|
|||||||
std::string get_downloads_path_mac();
|
std::string get_downloads_path_mac();
|
||||||
#endif //__APPLE__
|
#endif //__APPLE__
|
||||||
|
|
||||||
|
enum class AppUpdaterURLAction {
|
||||||
|
AUUA_DOWNLOAD,
|
||||||
|
AUUA_OPEN_IN_BROWSER
|
||||||
|
};
|
||||||
struct DownloadAppData
|
struct DownloadAppData
|
||||||
{
|
{
|
||||||
std::string url;
|
std::string url;
|
||||||
@ -26,6 +30,7 @@ struct DownloadAppData
|
|||||||
boost::optional<Semver> version;
|
boost::optional<Semver> version;
|
||||||
size_t size;
|
size_t size;
|
||||||
boost::filesystem::path target_path;
|
boost::filesystem::path target_path;
|
||||||
|
AppUpdaterURLAction action { AppUpdaterURLAction::AUUA_DOWNLOAD };
|
||||||
};
|
};
|
||||||
|
|
||||||
class AppUpdater
|
class AppUpdater
|
||||||
|
Loading…
x
Reference in New Issue
Block a user