From 5601062f05392d38390a6f6480a50ea11537a8cb Mon Sep 17 00:00:00 2001 From: WuYi Date: Tue, 1 Oct 2024 16:24:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A0=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF=E6=97=B6=E7=9A=84=E5=88=A4=E6=96=AD=E8=BD=AF=E4=BB=B6?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E9=87=8D=E5=A4=8D=E5=BC=B9=E7=AA=97bug?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/yalong/site/LeagueClientHelper.java | 4 ++-- src/main/java/yalong/site/frame/MainFrame.java | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/yalong/site/LeagueClientHelper.java b/src/main/java/yalong/site/LeagueClientHelper.java index 2173d4c..637e6f7 100644 --- a/src/main/java/yalong/site/LeagueClientHelper.java +++ b/src/main/java/yalong/site/LeagueClientHelper.java @@ -28,12 +28,12 @@ public static void main(String[] args) { MainFrame.showFrame(); HotKeyService.start(); clientStarter.listenGameStatus(); + } catch (RepeatProcessException ignored) { + msg = "工具已打开请查看任务栏或系统托盘"; } catch (NoProcessException ignored) { msg = "请先启动游戏"; } catch (ConnectException ignored) { msg = "游戏客户端连接失败"; - } catch (RepeatProcessException ignored) { - msg = "工具已打开请查看任务栏或系统托盘"; } catch (Exception e) { msg = e.getMessage(); log.error(msg, e); diff --git a/src/main/java/yalong/site/frame/MainFrame.java b/src/main/java/yalong/site/frame/MainFrame.java index a665c20..028dd40 100644 --- a/src/main/java/yalong/site/frame/MainFrame.java +++ b/src/main/java/yalong/site/frame/MainFrame.java @@ -31,9 +31,9 @@ public class MainFrame extends JFrame { //用于创建后台托盘 private static TrayIcon trayIcon; private static SystemTray tray; - //用于检测软件是否重复打开 private static RandomAccessFile RAF; + private static boolean lockFlag; final static String LOCK_FILE = "lol-helper.lock"; static { SaveFrameConfig.load(); @@ -195,10 +195,13 @@ private static void restoreFromTray() { } /** - * 查看文件是否右锁 用于判断软件是否重复打开 + * 查看文件是否有锁 用于判断软件是否重复打开 */ public static void checkFileLock() { try { + if (lockFlag) { + return; + } File file = new File(LOCK_FILE); // 打开文件通道 RAF = new RandomAccessFile(file, "rw"); @@ -208,7 +211,10 @@ public static void checkFileLock() { lock = channel.tryLock(); if (lock == null) { RAF.close(); + lockFlag = false; throw new RepeatProcessException(); + } else { + lockFlag = true; } } catch (IOException e) { throw new RuntimeException(e);