diff options
author | supermerill <merill@free.fr> | 2021-11-04 18:29:17 +0300 |
---|---|---|
committer | supermerill <merill@free.fr> | 2021-11-07 22:46:19 +0300 |
commit | d0ed35d71f09d01cdde1ef3938c6f6b737838517 (patch) | |
tree | 6e509c8354735cb1e2a8f4d67cbfe71e328f77ca | |
parent | ca795555ed56c7ee22e357cfc035354fb9d8c689 (diff) |
Add a fallback method (in windows) for getting the current exe path to open the gcodeviewer (or the opposite)
supermerill/SuperSlicer#1778
-rw-r--r-- | src/slic3r/Utils/Process.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/slic3r/Utils/Process.cpp b/src/slic3r/Utils/Process.cpp index a97df2138..dad671af7 100644 --- a/src/slic3r/Utils/Process.cpp +++ b/src/slic3r/Utils/Process.cpp @@ -39,6 +39,22 @@ static void start_new_slicer_or_gcodeviewer(const NewSlicerInstanceType instance #ifdef _WIN32 wxString path; wxFileName::SplitPath(wxStandardPaths::Get().GetExecutablePath(), &path, nullptr, nullptr, wxPATH_NATIVE); + //check directory exist + if (true || !boost::filesystem::is_directory(boost::filesystem::wpath(path.ToStdWstring()))) { + BOOST_LOG_TRIVIAL(info) << "Fail to find directory \"" << path << "\", trying another method."; + //try an other way + std::vector<wchar_t> pathBuf; + DWORD copied = 0; + do { + pathBuf.resize(pathBuf.size() + MAX_PATH); + copied = GetModuleFileName(0, pathBuf.data(), pathBuf.size()); + } while (copied >= pathBuf.size()); + pathBuf.resize(copied); + std::wstring path2(pathBuf.begin(), pathBuf.end()); + boost::filesystem::wpath boostpath(path2); + BOOST_LOG_TRIVIAL(info) << "get current path: \"" << into_u8(path2) << "\" which is in dir \""<< boostpath.parent_path().wstring() <<"\""; + path = boostpath.parent_path().wstring(); + } path += "\\"; path += (instance_type == NewSlicerInstanceType::Slicer) ? SLIC3R_APP_CMD ".exe" : GCODEVIEWER_APP_CMD ".exe"; std::vector<const wchar_t*> args; @@ -58,7 +74,7 @@ static void start_new_slicer_or_gcodeviewer(const NewSlicerInstanceType instance // just hang in the background. if (wxExecute(const_cast<wchar_t**>(args.data()), wxEXEC_ASYNC) <= 0) BOOST_LOG_TRIVIAL(error) << "Failed to spawn a new slicer \"" << into_u8(path); -#else +#else // Win32 (else not) // Own executable path. boost::filesystem::path bin_path = into_path(wxStandardPaths::Get().GetExecutablePath()); #if defined(__APPLE__) |