Skip to content

Commit

Permalink
Add a fallback method (in windows) for getting the current exe path t…
Browse files Browse the repository at this point in the history
…o open the gcodeviewer (or the opposite)

#1778
  • Loading branch information
supermerill committed Nov 7, 2021
1 parent ca79555 commit d0ed35d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/slic3r/Utils/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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__)
Expand Down

0 comments on commit d0ed35d

Please sign in to comment.