FIX: use shellex to open file, avoid cmd window

Change-Id: I6ae868381003c85a319e9c3bad37b0bffc3dbdd7
This commit is contained in:
chunmao.guo 2022-10-19 09:02:19 +08:00 committed by Lane.Wei
parent 946ba89cd7
commit 48083f7c0c
4 changed files with 36 additions and 1 deletions

View file

@ -8,6 +8,9 @@
#include <wx/dcgraph.h>
#ifdef __WXMSW__
#include <shellapi.h>
#endif
#ifdef __APPLE__
#include "../Utils/MacDarkMode.hpp"
#endif
@ -149,8 +152,15 @@ void Slic3r::GUI::ImageGrid::DoAction(size_t index, int action)
auto &file = m_file_sys->GetFile(index);
if (file.IsDownload() && file.progress >= -1) {
if (file.progress >= 100) {
if (!m_file_sys->DownloadCheckFile(index)) {
wxMessageBox(wxString::Format(_L("File '%s' was lost! Please download it again."), from_u8(file.name)), _L("Error"), wxOK);
Refresh();
return;
}
#ifdef __WXMSW__
wxExecute("cmd /c start " + from_u8(file.path), wxEXEC_HIDE_CONSOLE);
auto wfile = boost::filesystem::path(file.path).wstring();
SHELLEXECUTEINFO info{sizeof(info), 0, NULL, L"open", wfile.c_str(), L"", SW_HIDE};
::ShellExecuteEx(&info);
#else
wxShell("open " + file.path);
#endif
@ -166,6 +176,11 @@ void Slic3r::GUI::ImageGrid::DoAction(size_t index, int action)
auto &file = m_file_sys->GetFile(index);
if (file.IsDownload() && file.progress >= -1) {
if (file.progress >= 100) {
if (!m_file_sys->DownloadCheckFile(index)) {
wxMessageBox(wxString::Format(_L("File '%s' was lost! Please download it again."), from_u8(file.name)), _L("Error"), wxOK);
Refresh();
return;
}
#ifdef __WIN32__
wxExecute(L"explorer.exe /select," + from_u8(file.path));
#elif __APPLE__

View file

@ -111,6 +111,7 @@ void PrinterFileSystem::ListAllFiles()
iter1->thumbnail = iter2->thumbnail;
iter1->flags = iter2->flags;
iter1->progress = iter2->progress;
iter1->path = iter2->path;
++iter1; ++iter2;
} else if (*iter1 < *iter2) {
++iter1;
@ -196,6 +197,21 @@ void PrinterFileSystem::DownloadCheckFiles(std::string const &path)
}
}
bool PrinterFileSystem::DownloadCheckFile(size_t index)
{
if (index >= m_file_list.size()) return false;
auto &file = m_file_list[index];
if ((file.flags & FF_DOWNLOAD) == 0) return false;
if (!boost::filesystem::exists(file.path)) {
file.flags &= ~FF_DOWNLOAD;
file.progress = 0;
file.path.clear();
SendChangedEvent(EVT_DOWNLOAD, index, file.path);
return false;
}
return true;
}
void PrinterFileSystem::DownloadCancel(size_t index)
{
if (index == (size_t) -1) return;

View file

@ -128,6 +128,8 @@ public:
void DownloadCheckFiles(std::string const &path);
bool DownloadCheckFile(size_t index);
void DownloadCancel(size_t index);
size_t GetCount() const;

View file

@ -54,6 +54,8 @@ void wxMediaCtrl2::Load(wxURI url)
wxRegKey key2(wxRegKey::HKCR, "bambu");
wxString clsid;
key2.QueryRawValue("Source Filter", clsid);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": clsid %1% path %2%") % clsid % path;
if (path.empty() || !wxFile::Exists(path) || clsid != CLSID_BAMBU_SOURCE) {
if (clsid != CLSID_BAMBU_SOURCE || path.empty()) {
std::string data_dir_str = Slic3r::data_dir();