mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-24 23:23:59 -06:00
Own implementation of lockfile instead of wx on linux/mac. Wx version keeps poping up messege boxes after crash. Own implementation doesnt delete lockfile after use.
This commit is contained in:
parent
65a37ffaa1
commit
69e9805982
1 changed files with 11 additions and 7 deletions
|
@ -111,23 +111,23 @@ namespace instance_check_internal
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static int get_lock(const std::string& version)
|
static bool get_lock(const std::string& name, const std::string& path)
|
||||||
{
|
{
|
||||||
std::string dest_dir = data_dir();
|
std::string dest_dir = path + name;
|
||||||
|
BOOST_LOG_TRIVIAL(debug) <<"full lock path: "<< dest_dir;
|
||||||
struct flock fl;
|
struct flock fl;
|
||||||
int fdlock;
|
int fdlock;
|
||||||
fl.l_type = F_WRLCK;
|
fl.l_type = F_WRLCK;
|
||||||
fl.l_whence = SEEK_SET;
|
fl.l_whence = SEEK_SET;
|
||||||
fl.l_start = 0;
|
fl.l_start = 0;
|
||||||
fl.l_len = 1;
|
fl.l_len = 1;
|
||||||
dest_dir += "/cache/prusaslicer-" + version + ".lock";
|
|
||||||
if ((fdlock = open(dest_dir.c_str(), O_WRONLY | O_CREAT, 0666)) == -1)
|
if ((fdlock = open(dest_dir.c_str(), O_WRONLY | O_CREAT, 0666)) == -1)
|
||||||
return false;
|
return true;
|
||||||
|
|
||||||
if (fcntl(fdlock, F_SETLK, &fl) == -1)
|
if (fcntl(fdlock, F_SETLK, &fl) == -1)
|
||||||
return false;
|
return true;
|
||||||
|
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //WIN32
|
#endif //WIN32
|
||||||
|
@ -232,9 +232,13 @@ bool instance_check(int argc, char** argv, bool app_config_single_instance)
|
||||||
std::string lock_name = std::to_string(hashed_path);
|
std::string lock_name = std::to_string(hashed_path);
|
||||||
GUI::wxGetApp().set_instance_hash(hashed_path);
|
GUI::wxGetApp().set_instance_hash(hashed_path);
|
||||||
BOOST_LOG_TRIVIAL(debug) <<"full path: "<< lock_name;
|
BOOST_LOG_TRIVIAL(debug) <<"full path: "<< lock_name;
|
||||||
GUI::wxGetApp().init_single_instance_checker(lock_name + ".lock", data_dir() + "/cache/");
|
|
||||||
instance_check_internal::CommandLineAnalysis cla = instance_check_internal::process_command_line(argc, argv);
|
instance_check_internal::CommandLineAnalysis cla = instance_check_internal::process_command_line(argc, argv);
|
||||||
|
#ifdef _WIN32
|
||||||
|
GUI::wxGetApp().init_single_instance_checker(lock_name + ".lock", data_dir() + "/cache/");
|
||||||
if ((cla.should_send || app_config_single_instance) && GUI::wxGetApp().single_instance_checker()->IsAnotherRunning()) {
|
if ((cla.should_send || app_config_single_instance) && GUI::wxGetApp().single_instance_checker()->IsAnotherRunning()) {
|
||||||
|
#else // mac & linx
|
||||||
|
if (instance_check_internal::get_lock(lock_name + ".lock", data_dir() + "/cache/") && (cla.should_send || app_config_single_instance)) {
|
||||||
|
#endif
|
||||||
instance_check_internal::send_message(cla.cl_string, lock_name);
|
instance_check_internal::send_message(cla.cl_string, lock_name);
|
||||||
BOOST_LOG_TRIVIAL(info) << "instance check: Another instance found. This instance will terminate.";
|
BOOST_LOG_TRIVIAL(info) << "instance check: Another instance found. This instance will terminate.";
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue