Skip to content

Commit

Permalink
Merge pull request #385 from Hpero4/master
Browse files Browse the repository at this point in the history
bugfix & perf
  • Loading branch information
Zzaphkiel authored Jun 2, 2024
2 parents 8de46cb + fd1cc47 commit 2ba699d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
30 changes: 30 additions & 0 deletions app/common/util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import json
import os
import re
import winreg
from functools import lru_cache, wraps
from pathlib import Path

import requests
import base64
Expand All @@ -13,6 +15,8 @@
from app.common.logger import logger


TAG = "Util"

class Github:
def __init__(self, user="Zzaphkiel", repositories="Seraphine"):
self.githubApi = "http://api.github.com"
Expand Down Expand Up @@ -234,6 +238,32 @@ def __checkUpdate(self):
github = Github()


def getLoLPathByRegistry() -> str:
"""
从注册表获取LOL的安装路径
** 只能获取到国服的路径, 外服不支持 **
无法获取时返回空串
"""
mainKey = winreg.HKEY_CURRENT_USER
subKey = "SOFTWARE\Tencent\LOL"
valueName = "InstallPath"

try:
with winreg.OpenKey(mainKey, subKey) as k:
installPath, _ = winreg.QueryValueEx(k, valueName)
return str(Path(f"{installPath}\TCLS").absolute()).replace("\\", "/")
except FileNotFoundError:
logger.warning("reg path or val does not exist.", TAG)
except WindowsError as e:
logger.warning(f"occurred while reading the registry: {e}", TAG)
except Exception as e:
logger.exception("unknown error reading registry", e, TAG)

return ""


def getTasklistPath():
for path in ['tasklist',
'C:/Windows/System32/tasklist.exe']:
Expand Down
5 changes: 4 additions & 1 deletion app/view/auxiliary_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,10 @@ def __onCheckedChanged(self, isChecked: bool):
duration=5000,
parent=self.window().auxiliaryFuncInterface,
)
self.setValue(not isChecked)

self.switchButton.checkedChanged.disconnect()
self.switchButton.setChecked(not isChecked)
self.switchButton.checkedChanged.connect(self.__onCheckedChanged)

def setConfigFileReadOnlyEnabled(self, enable):
path = f"{cfg.get(cfg.lolFolder)}/../Game/Config/PersistedSettings.json"
Expand Down
12 changes: 11 additions & 1 deletion app/view/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import traceback
import time
import webbrowser
from pathlib import Path

import pyperclip

import asyncio
Expand All @@ -22,7 +24,8 @@
from .search_interface import SearchInterface
from .game_info_interface import GameInfoInterface
from .auxiliary_interface import AuxiliaryInterface
from ..common.util import github, getLolClientPid, getTasklistPath, getLolClientPidSlowly, AramHome
from ..common.util import github, getLolClientPid, getTasklistPath, getLolClientPidSlowly, AramHome, \
getLoLPathByRegistry
from ..components.avatar_widget import NavigationAvatarWidget
from ..components.temp_system_tray_menu import TmpSystemTrayMenu
from ..common.icons import Icon
Expand Down Expand Up @@ -57,6 +60,7 @@ def __init__(self):
super().__init__()

logger.critical(f"Seraphine started, version: {VERSION}", TAG)
self.__initConfig()

self.__initWindow()
self.__initSystemTray()
Expand Down Expand Up @@ -104,6 +108,12 @@ def __init__(self):

logger.critical("Seraphine initialized", TAG)

def __initConfig(self):
if cfg.get(cfg.lolFolder) == str(Path("").absolute()).replace("\\", "/"):
tmpPath = getLoLPathByRegistry()
if tmpPath:
cfg.set(cfg.lolFolder, tmpPath)

def __initInterface(self):
self.__lockInterface()

Expand Down

0 comments on commit 2ba699d

Please sign in to comment.