4 Commits

Author SHA1 Message Date
e1333ccb78 v1.1.2 修复:启动脚本使用 ANSI (GBK) 编码
修复问题:
- Windows CMD 默认使用 ANSI 编码(GBK)
- UTF-8 编码的 bat 文件在中文 Windows 上会显示乱码

修改内容:
- 启动监控.bat 转换为 GBK 编码
- 使用 chcp 936 设置代码页为简体中文
2026-03-20 18:04:32 +08:00
e3b36d958d v1.1.1 修复:UnboundLocalError logger 作用域问题
修复问题:
- main() 函数内 logger = setup_logging() 导致作用域错误
- 改用 _apply_log_config() 函数更新日志等级,不重新赋值 logger
2026-03-20 17:50:43 +08:00
3b6a5fe2a0 v1.1.0 修复:转换启动脚本为 Windows CRLF 换行符 2026-03-20 17:18:53 +08:00
f4569093d7 v1.1.0 修复:启动脚本和日志等级配置
修复问题:
1. 启动监控.bat 添加窗口设置(title/mode/color),修复 Windows 换行符问题
2. 日志等级现在按配置文件 [logging] level 设置
3. 移除启动脚本的 Python 依赖自动安装功能

优化:
- 启动脚本初始化时设置窗口标题、大小和颜色
- 日志配置支持从配置文件动态读取等级
2026-03-20 16:55:11 +08:00
2 changed files with 82 additions and 51 deletions

View File

@@ -1,39 +1,29 @@
@echo off
chcp 65001 >nul
echo ========================================
echo 远程连接音量自动调节器
echo Remote Volume Monitor
echo ========================================
echo.
REM 检查 Python
python --version >nul 2>&1
if errorlevel 1 (
echo [错误] 未找到 Python请先安装 Python 3.8+
pause
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 [提示] 按 Ctrl+C 停止监控
echo.
REM 启动监控程序(从 scripts 目录调用 src 和 config
python "%~dp0..\src\remote_volume_monitor.py" --config "%~dp0..\config\config.ini"
pause
@echo off
title 远程连接音量自动调节器 -By:LeeQwQ
mode con cols=65 lines=18
color 0B
chcp 936 >nul
cls
echo ========================================
echo 远程连接音量自动调节器
echo Remote Volume Monitor
echo ========================================
echo.
REM 检查 Python
python --version >nul 2>&1
if errorlevel 1 (
echo [错误] 未找到 Python请先安装 Python 3.8+
pause
exit /b 1
)
echo.
echo [启动] 开始监控远程连接...
echo [提示] 按 Ctrl+C 停止监控
echo.
REM 启动监控程序(从 scripts 目录调用 src 和 config
python "%~dp0..\src\remote_volume_monitor.py" --config "%~dp0..\config\config.ini"
pause

View File

@@ -20,19 +20,54 @@ from pathlib import Path
# 日志配置
# ============================================================================
log_dir = Path('logs')
log_dir.mkdir(exist_ok=True)
log_file = log_dir / 'remote_volume.log'
def setup_logging(config_path=None):
"""根据配置文件设置日志等级"""
log_dir = Path('logs')
log_dir.mkdir(exist_ok=True)
log_file = log_dir / 'remote_volume.log'
# 默认日志等级
log_level = logging.INFO
# 从配置文件读取日志等级
if config_path and Path(config_path).exists():
try:
config = configparser.ConfigParser()
config.read(config_path, encoding='utf-8')
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__)
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler(log_file, encoding='utf-8'),
logging.StreamHandler()
]
)
logger = logging.getLogger(__name__)
def _apply_log_config(config_path):
"""根据配置文件更新日志等级(不重新创建 logger"""
if not Path(config_path).exists():
return
try:
config = configparser.ConfigParser()
config.read(config_path, encoding='utf-8')
if 'logging' in config and 'level' in config['logging']:
level_str = config['logging']['level'].upper()
log_level = getattr(logging, level_str, logging.INFO)
logger.setLevel(log_level)
logger.info(f"📝 日志等级:{level_str}")
except Exception as e:
pass # 读取失败保持当前等级
logger = setup_logging()
# ============================================================================
@@ -534,6 +569,7 @@ def main():
return
config = configparser.ConfigParser()
config_path = None
if args.config:
config_path = Path(args.config)
if not config_path.exists():
@@ -541,11 +577,16 @@ def main():
sys.exit(1)
config.read(config_path, encoding='utf-8')
logger.info(f"✓ 已加载:{config_path}")
# 重新配置日志等级(使用配置文件中的日志等级)
_apply_log_config(str(config_path))
else:
default_config = Path(__file__).parent.parent / 'config' / 'config.ini'
if default_config.exists():
config.read(default_config, encoding='utf-8')
logger.info(f"✓ 已加载默认:{default_config}")
config_path = str(default_config)
# 重新配置日志等级(使用配置文件中的日志等级)
_apply_log_config(config_path)
else:
config['volume'] = {'remote_volume': str(args.volume)}