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
@ -177,25 +177,20 @@ void FileGet::priv::get_perform()
|
||||
|
||||
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);
|
||||
|
||||
FILE* file;
|
||||
// open file for writting
|
||||
if (m_written == 0)
|
||||
file = fopen(temp_path_wstring.c_str(), "wb");
|
||||
file = boost::nowide::fopen(m_tmp_path.string().c_str(), "wb");
|
||||
else
|
||||
file = fopen(temp_path_wstring.c_str(), "ab");
|
||||
file = boost::nowide::fopen(m_tmp_path.string().c_str(), "ab");
|
||||
|
||||
//assert(file != NULL);
|
||||
if (file == NULL) {
|
||||
wxCommandEvent* evt = new wxCommandEvent(EVT_DWNLDR_FILE_ERROR);
|
||||
// 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);
|
||||
m_evt_handler->QueueEvent(evt);
|
||||
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)
|
||||
{
|
||||
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).
|
||||
@ -3544,19 +3544,13 @@ bool GUI_App::check_updates(const bool invoked_by_user)
|
||||
// Applicaiton will continue.
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GUI_App::open_browser_with_warning_dialog(const wxString& url, wxWindow* parent/* = nullptr*/, bool force_remember_choice /*= true*/, int flags/* = 0*/)
|
||||
namespace {
|
||||
bool open_dialog_hyperlink_checkbox(wxWindow* parent, AppConfig* app_config)
|
||||
{
|
||||
bool launch = true;
|
||||
|
||||
// warning dialog containes a "Remember my choice" checkbox
|
||||
std::string option_key = "suppress_hyperlinks";
|
||||
if (force_remember_choice || app_config->get(option_key).empty()) {
|
||||
if (app_config->get(option_key).empty()) {
|
||||
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();
|
||||
launch = answer == wxID_YES;
|
||||
bool launch = answer == wxID_YES;
|
||||
if (dialog.IsCheckBoxChecked()) {
|
||||
wxString preferences_item = _L("Suppress to open hyperlink in browser");
|
||||
wxString msg =
|
||||
@ -3567,19 +3561,47 @@ bool GUI_App::open_browser_with_warning_dialog(const wxString& url, wxWindow* pa
|
||||
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");
|
||||
app_config->set("suppress_hyperlinks", answer == wxID_NO ? "1" : "0");
|
||||
}
|
||||
return launch;
|
||||
}
|
||||
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)) {
|
||||
bool open_dialog_hyperlink(wxWindow* parent)
|
||||
{
|
||||
MessageDialog dialog(parent, _L("Open hyperlink in default browser?"), _L("PrusaSlicer: Open hyperlink"), wxICON_QUESTION | wxYES_NO);
|
||||
launch = dialog.ShowModal() == wxID_YES;
|
||||
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*/)
|
||||
{
|
||||
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;
|
||||
if (opt_val == SupressHyperLinksOption::SHLO_UNCHECKED) {
|
||||
// no previous action from user
|
||||
// open dialog with remember checkbox
|
||||
launch = open_dialog_hyperlink_checkbox(parent, app_config);
|
||||
} else if (opt_val == SupressHyperLinksOption::SHLO_ALWAYS_ALLOW) {
|
||||
// user already set checkbox to always open
|
||||
launch = true;
|
||||
} else if (opt_val == SupressHyperLinksOption::SHLO_ALWAYS_SUPRESS && force_remember_choice) {
|
||||
// user already set checkbox or preferences to always supress
|
||||
launch = false;
|
||||
} else if (opt_val == SupressHyperLinksOption::SHLO_ALWAYS_SUPRESS && !force_remember_choice) {
|
||||
// user already set checkbox or preferences to always supress but it is overriden
|
||||
// no checkbox in dialog
|
||||
launch = open_dialog_hyperlink(parent);
|
||||
}
|
||||
|
||||
return launch && wxLaunchDefaultBrowser(url, flags);
|
||||
}
|
||||
|
||||
@ -3701,7 +3723,7 @@ void GUI_App::app_updater(bool from_user)
|
||||
assert(!app_data.target_path.empty());
|
||||
|
||||
// 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();
|
||||
// checkbox "do not show again"
|
||||
if (dialog.disable_version_check()) {
|
||||
@ -3711,6 +3733,10 @@ void GUI_App::app_updater(bool from_user)
|
||||
if (dialog_result != wxID_OK) {
|
||||
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
|
||||
AppUpdateDownloadDialog dwnld_dlg(*app_data.version, app_data.target_path);
|
||||
dialog_result = dwnld_dlg.ShowModal();
|
||||
|
@ -99,7 +99,7 @@ bool MsgUpdateSlic3r::disable_version_check() const
|
||||
|
||||
wxSize AppUpdateAvailableDialog::AUAD_size;
|
||||
// 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))
|
||||
{
|
||||
auto* versions = new wxFlexGridSizer(1, 0, VERT_SPACING);
|
||||
@ -116,6 +116,12 @@ AppUpdateAvailableDialog::AppUpdateAvailableDialog(const Semver& ver_current, co
|
||||
}
|
||||
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();
|
||||
|
||||
|
||||
|
@ -46,7 +46,7 @@ private:
|
||||
class AppUpdateAvailableDialog : public MsgDialog
|
||||
{
|
||||
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(const 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());
|
||||
FILE* file;
|
||||
file = fopen(file_path.string().c_str(), "w");
|
||||
file = boost::nowide::fopen(file_path.string().c_str(), "w");
|
||||
if (file == NULL) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Failed to write to file " << file_path;
|
||||
// TODO show error
|
||||
|
@ -45,7 +45,7 @@ namespace {
|
||||
bool res = GUI::create_process(path, std::wstring(), msg);
|
||||
if (!res) {
|
||||
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);
|
||||
evt->SetString(full_message);
|
||||
GUI::wxGetApp().QueueEvent(evt);
|
||||
@ -165,7 +165,7 @@ AppUpdater::priv::priv() :
|
||||
if (!downloads_path.empty()) {
|
||||
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;
|
||||
tmp_path += format(".%1%%2%", std::to_string(GUI::GLCanvas3D::timestamp_now()), ".download");
|
||||
FILE* file;
|
||||
wxString temp_path_wstring(tmp_path.wstring());
|
||||
file = fopen(temp_path_wstring.c_str(), "wb");
|
||||
file = boost::nowide::fopen(tmp_path.string().c_str(), "wb");
|
||||
assert(file != NULL);
|
||||
if (file == NULL) {
|
||||
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;
|
||||
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
|
||||
, [&last_gui_progress, expected_size](Http::Progress progress) {
|
||||
// size check
|
||||
@ -333,10 +332,6 @@ void AppUpdater::priv::version_check(const std::string& version_check_url)
|
||||
}
|
||||
, 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) {
|
||||
std::string message = GUI::format("Downloading %1% version file has failed:\n%2%", SLIC3R_APP_NAME, error_message);
|
||||
BOOST_LOG_TRIVIAL(error) << message;
|
||||
@ -390,9 +385,6 @@ void AppUpdater::priv::parse_version_string(const std::string& body)
|
||||
#else
|
||||
"release:linux"
|
||||
#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) {
|
||||
if (data.first == "url") {
|
||||
@ -402,6 +394,11 @@ void AppUpdater::priv::parse_version_string(const std::string& body)
|
||||
} else if (data.first == "size") {
|
||||
new_data.size = std::stoi(data.second.data());
|
||||
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();
|
||||
#endif //__APPLE__
|
||||
|
||||
enum class AppUpdaterURLAction {
|
||||
AUUA_DOWNLOAD,
|
||||
AUUA_OPEN_IN_BROWSER
|
||||
};
|
||||
struct DownloadAppData
|
||||
{
|
||||
std::string url;
|
||||
@ -26,6 +30,7 @@ struct DownloadAppData
|
||||
boost::optional<Semver> version;
|
||||
size_t size;
|
||||
boost::filesystem::path target_path;
|
||||
AppUpdaterURLAction action { AppUpdaterURLAction::AUUA_DOWNLOAD };
|
||||
};
|
||||
|
||||
class AppUpdater
|
||||
|
Loading…
x
Reference in New Issue
Block a user