解决国产系统按键扫描工具安装完成后下一次打开软件失败的问题;

This commit is contained in:
yangjiaxuan 2024-08-27 14:28:49 +08:00
parent f07b166326
commit 098bc172a4
1 changed files with 22 additions and 19 deletions

View File

@ -2,12 +2,14 @@
#include <QApplication> #include <QApplication>
#include "base/HGDef.h" #include "base/HGDef.h"
#include <QTranslator> #include <QTranslator>
#include <QFile>
#if !defined (HG_CMP_MSC) #if !defined (HG_CMP_MSC)
#include <stdio.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <sys/file.h> #include <sys/file.h>
#include <sys/stat.h>
#include <sys/types.h>
#endif #endif
#include "log/log.h" #include "log/log.h"
@ -27,6 +29,10 @@ const char* oem = "UniScan";
const char* oem = "NeuScan"; const char* oem = "NeuScan";
#elif defined(OEM_DELI) #elif defined(OEM_DELI)
const char* oem = "DeliScan"; const char* oem = "DeliScan";
#elif defined(OEM_MEISONGDA)
const char *oem = "MaxsoundScan";
#elif defined(OEM_GUANGDIANTONG)
const char *oem = "ToecScan";
#else #else
const char* oem = "HuaGoScan"; const char* oem = "HuaGoScan";
#endif #endif
@ -46,22 +52,18 @@ int main(int argc, char *argv[])
return -1; return -1;
} }
#else #else
const QString lockFilePath = "/tmp/HGScanTool.lock"; const char* lockFilePath = "/tmp/HGScanTool.lock";
QFile lockFile(lockFilePath); int fd = open(lockFilePath, O_RDONLY | O_CREAT, 666);
chmod(lockFilePath, 666);
if (!lockFile.open(QIODevice::ReadWrite | QIODevice::Unbuffered))
{
return 0;
}
int fd = lockFile.handle();
struct flock lock; struct flock lock;
lock.l_type = F_WRLCK; lock.l_type = F_RDLCK;
lock.l_whence = SEEK_SET; lock.l_whence = SEEK_SET;
lock.l_start = 0; lock.l_start = 0;
lock.l_len = 0; lock.l_len = 0;
if (fcntl(fd, F_SETLK, &lock) == -1) if (fcntl(fd, F_SETLK, &lock) == -1)
{ {
lockFile.close(); close(fd);
return 0; return 0;
} }
#endif #endif
@ -85,7 +87,8 @@ int main(int argc, char *argv[])
#else #else
lock.l_type = F_UNLCK; lock.l_type = F_UNLCK;
fcntl(fd, F_SETLK, &lock); fcntl(fd, F_SETLK, &lock);
lockFile.close(); close(fd);
unlink(lockFilePath);
#endif #endif
return ret; return ret;
} }