Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f4569093d7 |
@@ -1,5 +1,9 @@
|
|||||||
@echo off
|
@echo off
|
||||||
|
title 远程连接音量自动调节器 -By:LeeQwQ
|
||||||
|
mode con cols=65 lines=18
|
||||||
|
color 0B
|
||||||
chcp 65001 >nul
|
chcp 65001 >nul
|
||||||
|
cls
|
||||||
echo ========================================
|
echo ========================================
|
||||||
echo 远程连接音量自动调节器
|
echo 远程连接音量自动调节器
|
||||||
echo Remote Volume Monitor
|
echo Remote Volume Monitor
|
||||||
@@ -14,20 +18,6 @@ if errorlevel 1 (
|
|||||||
exit /b 1
|
exit /b 1
|
||||||
)
|
)
|
||||||
|
|
||||||
REM 检查依赖
|
|
||||||
echo [检查] 验证依赖库...
|
|
||||||
python -c "import pycaw" >nul 2>&1
|
|
||||||
if errorlevel 1 (
|
|
||||||
echo [安装] 正在安装依赖库...
|
|
||||||
pip install pycaw comtypes wmi
|
|
||||||
)
|
|
||||||
|
|
||||||
python -c "import wmi" >nul 2>&1
|
|
||||||
if errorlevel 1 (
|
|
||||||
echo [安装] 正在安装 WMI 库...
|
|
||||||
pip install wmi
|
|
||||||
)
|
|
||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo [启动] 开始监控远程连接...
|
echo [启动] 开始监控远程连接...
|
||||||
echo [提示] 按 Ctrl+C 停止监控
|
echo [提示] 按 Ctrl+C 停止监控
|
||||||
|
|||||||
@@ -20,19 +20,38 @@ from pathlib import Path
|
|||||||
# 日志配置
|
# 日志配置
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|
||||||
log_dir = Path('logs')
|
def setup_logging(config_path=None):
|
||||||
log_dir.mkdir(exist_ok=True)
|
"""根据配置文件设置日志等级"""
|
||||||
log_file = log_dir / 'remote_volume.log'
|
log_dir = Path('logs')
|
||||||
|
log_dir.mkdir(exist_ok=True)
|
||||||
|
log_file = log_dir / 'remote_volume.log'
|
||||||
|
|
||||||
logging.basicConfig(
|
# 默认日志等级
|
||||||
level=logging.DEBUG,
|
log_level = logging.INFO
|
||||||
format='%(asctime)s - %(levelname)s - %(message)s',
|
|
||||||
handlers=[
|
# 从配置文件读取日志等级
|
||||||
logging.FileHandler(log_file, encoding='utf-8'),
|
if config_path and Path(config_path).exists():
|
||||||
logging.StreamHandler()
|
try:
|
||||||
]
|
config = configparser.ConfigParser()
|
||||||
)
|
config.read(config_path, encoding='utf-8')
|
||||||
logger = logging.getLogger(__name__)
|
if 'logging' in config and 'level' in config['logging']:
|
||||||
|
level_str = config['logging']['level'].upper()
|
||||||
|
log_level = getattr(logging, level_str, logging.INFO)
|
||||||
|
except Exception as e:
|
||||||
|
pass # 读取失败使用默认等级
|
||||||
|
|
||||||
|
# 配置日志
|
||||||
|
logging.basicConfig(
|
||||||
|
level=log_level,
|
||||||
|
format='%(asctime)s - %(levelname)s - %(message)s',
|
||||||
|
handlers=[
|
||||||
|
logging.FileHandler(log_file, encoding='utf-8'),
|
||||||
|
logging.StreamHandler()
|
||||||
|
]
|
||||||
|
)
|
||||||
|
return logging.getLogger(__name__)
|
||||||
|
|
||||||
|
logger = setup_logging()
|
||||||
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
@@ -534,6 +553,7 @@ def main():
|
|||||||
return
|
return
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
|
config_path = None
|
||||||
if args.config:
|
if args.config:
|
||||||
config_path = Path(args.config)
|
config_path = Path(args.config)
|
||||||
if not config_path.exists():
|
if not config_path.exists():
|
||||||
@@ -541,11 +561,16 @@ def main():
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
config.read(config_path, encoding='utf-8')
|
config.read(config_path, encoding='utf-8')
|
||||||
logger.info(f"✓ 已加载:{config_path}")
|
logger.info(f"✓ 已加载:{config_path}")
|
||||||
|
# 重新初始化日志(使用配置文件中的日志等级)
|
||||||
|
logger = setup_logging(str(config_path))
|
||||||
else:
|
else:
|
||||||
default_config = Path(__file__).parent.parent / 'config' / 'config.ini'
|
default_config = Path(__file__).parent.parent / 'config' / 'config.ini'
|
||||||
if default_config.exists():
|
if default_config.exists():
|
||||||
config.read(default_config, encoding='utf-8')
|
config.read(default_config, encoding='utf-8')
|
||||||
logger.info(f"✓ 已加载默认:{default_config}")
|
logger.info(f"✓ 已加载默认:{default_config}")
|
||||||
|
config_path = str(default_config)
|
||||||
|
# 重新初始化日志(使用配置文件中的日志等级)
|
||||||
|
logger = setup_logging(config_path)
|
||||||
else:
|
else:
|
||||||
config['volume'] = {'remote_volume': str(args.volume)}
|
config['volume'] = {'remote_volume': str(args.volume)}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user