From 453408143ff267de0be6989a7cddae056ac4266b Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 14 Oct 2020 08:46:30 +0200 Subject: [PATCH] switching from slicer to gcode viewer - unlocking lock file --- src/PrusaSlicer.cpp | 2 +- src/slic3r/GUI/GUI_App.cpp | 1 + src/slic3r/GUI/InstanceCheck.cpp | 20 ++++++++++++++++++++ src/slic3r/GUI/InstanceCheck.hpp | 2 ++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/PrusaSlicer.cpp b/src/PrusaSlicer.cpp index 8b5aa538c..b41894ebb 100644 --- a/src/PrusaSlicer.cpp +++ b/src/PrusaSlicer.cpp @@ -578,7 +578,7 @@ int CLI::run(int argc, char **argv) GUI::GUI_App *gui = new GUI::GUI_App(); #endif // ENABLE_GCODE_VIEWER - if(!start_as_gcodeviewer) { // gcode viewer is currently not performing instance check + if(gui->get_app_mode() != GUI::GUI_App::EAppMode::GCodeViewer){ // gcode viewer is currently not performing instance check bool gui_single_instance_setting = gui->app_config->get("single_instance") == "1"; if (Slic3r::instance_check(argc, argv, gui_single_instance_setting)) { //TODO: do we have delete gui and other stuff? diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 3f3570c6a..d11ca1f38 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -1718,6 +1718,7 @@ void GUI_App::OSXStoreOpenFiles(const wxArrayString &fileNames) // Opening PrusaSlicer by drag & dropping a G-Code onto PrusaSlicer icon in Finder, // just G-codes were passed. Switch to G-code viewer mode. m_app_mode = EAppMode::GCodeViewer; + unlock_lockfile(get_instance_hash_string() + ".lock", data_dir() + "/cache/"); if(app_config != nullptr) delete app_config; app_config = nullptr; diff --git a/src/slic3r/GUI/InstanceCheck.cpp b/src/slic3r/GUI/InstanceCheck.cpp index 9af1f591f..abcdea254 100644 --- a/src/slic3r/GUI/InstanceCheck.cpp +++ b/src/slic3r/GUI/InstanceCheck.cpp @@ -264,6 +264,26 @@ bool instance_check(int argc, char** argv, bool app_config_single_instance) return false; } +#ifdef __APPLE__ +bool unlock_lockfile(const std::string& name, const std::string& path) +{ + std::string dest_dir = path + name; + //BOOST_LOG_TRIVIAL(debug) << "full lock path: " << dest_dir; + struct flock fl; + int fdlock; + fl.l_type = F_UNLCK; + fl.l_whence = SEEK_SET; + fl.l_start = 0; + fl.l_len = 1; + if ((fdlock = open(dest_dir.c_str(), O_WRONLY | O_CREAT, 0666)) == -1) + return false; + + if (fcntl(fdlock, F_SETLK, &fl) == -1) + return false; + + return true; +} +#endif //__APPLE__ namespace GUI { wxDEFINE_EVENT(EVT_LOAD_MODEL_OTHER_INSTANCE, LoadFromOtherInstanceEvent); diff --git a/src/slic3r/GUI/InstanceCheck.hpp b/src/slic3r/GUI/InstanceCheck.hpp index c4831df2e..9fb74b0a9 100644 --- a/src/slic3r/GUI/InstanceCheck.hpp +++ b/src/slic3r/GUI/InstanceCheck.hpp @@ -28,6 +28,8 @@ bool instance_check(int argc, char** argv, bool app_config_single_instance); // apple implementation of inner functions of instance_check // in InstanceCheckMac.mm void send_message_mac(const std::string& msg, const std::string& version); + +bool unlock_lockfile(const std::string& name, const std::string& path); #endif //__APPLE__ namespace GUI {