修复:
- 用户数据目录从用户主目录 ~/RRPP 迁移到 Windows 惯例位置 %LOCALAPPDATA%\RRPP(隐藏、不进备份、无同步冲突;非 Windows 环境回退主目录)
This commit is contained in:
+11
-8
@@ -73,7 +73,7 @@ def _config_val(key, default=""):
|
|||||||
_NODES = None
|
_NODES = None
|
||||||
|
|
||||||
def _load_nodes():
|
def _load_nodes():
|
||||||
"""加载 nodes.json 节点列表(~/RRPP 优先);失败或缺失时返回空列表。"""
|
"""加载 nodes.json 节点列表(用户数据目录优先);失败或缺失时返回空列表。"""
|
||||||
global _NODES
|
global _NODES
|
||||||
if _NODES is not None:
|
if _NODES is not None:
|
||||||
return _NODES
|
return _NODES
|
||||||
@@ -521,10 +521,13 @@ def _data_path(name: str):
|
|||||||
p = Path(BASE_DIR) / name
|
p = Path(BASE_DIR) / name
|
||||||
return p if p.is_file() else None
|
return p if p.is_file() else None
|
||||||
|
|
||||||
_USER_DIR = Path.home() / "RRPP" # 用户数据目录(nodes.json / PAC 数据),测试可覆盖
|
# 用户数据目录:Windows 惯例 %LOCALAPPDATA%(C:\Users\<用户>\AppData\Local),
|
||||||
|
# 非 Windows 环境回退用户主目录;测试可覆盖
|
||||||
|
_USER_DIR = (Path(os.environ["LOCALAPPDATA"]) if os.name == "nt" and os.environ.get("LOCALAPPDATA")
|
||||||
|
else Path.home()) / "RRPP"
|
||||||
|
|
||||||
def _user_path(name: str):
|
def _user_path(name: str):
|
||||||
"""用户数据文件路径:~/RRPP 优先,回退内置/源码目录(dev 模式与测试)。"""
|
"""用户数据文件路径:用户数据目录优先,回退内置/源码目录(dev 模式与测试)。"""
|
||||||
p = _USER_DIR / name
|
p = _USER_DIR / name
|
||||||
if p.is_file():
|
if p.is_file():
|
||||||
return p
|
return p
|
||||||
@@ -574,7 +577,7 @@ def _pac_validate(name, data):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def _pac_write(name, data):
|
def _pac_write(name, data):
|
||||||
"""PAC 数据原子写入 ~/RRPP(tmp+replace,写不坏旧文件)。"""
|
"""PAC 数据原子写入用户数据目录(tmp+replace,写不坏旧文件)。"""
|
||||||
import json
|
import json
|
||||||
_USER_DIR.mkdir(parents=True, exist_ok=True)
|
_USER_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
tmp = _USER_DIR / f"{name}.json.tmp"
|
tmp = _USER_DIR / f"{name}.json.tmp"
|
||||||
@@ -582,7 +585,7 @@ def _pac_write(name, data):
|
|||||||
os.replace(tmp, _USER_DIR / f"{name}.json")
|
os.replace(tmp, _USER_DIR / f"{name}.json")
|
||||||
|
|
||||||
def _user_init_local():
|
def _user_init_local():
|
||||||
"""初始化 ~/RRPP(同步):建目录,nodes.json 缺失时写入空模板。"""
|
"""初始化用户数据目录(同步):建目录,nodes.json 缺失时写入空模板。"""
|
||||||
_USER_DIR.mkdir(parents=True, exist_ok=True)
|
_USER_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
if _user_path("nodes.json") is None:
|
if _user_path("nodes.json") is None:
|
||||||
import json
|
import json
|
||||||
@@ -610,7 +613,7 @@ def _user_init_remote(base_url=None, nodes_url=None):
|
|||||||
raise ValueError(f"{name}.json 数据格式不正确")
|
raise ValueError(f"{name}.json 数据格式不正确")
|
||||||
rver = str(data.get("version") or "")
|
rver = str(data.get("version") or "")
|
||||||
rdate = str(data.get("date") or "")
|
rdate = str(data.get("date") or "")
|
||||||
# 版本只与 ~/RRPP 本地文件比对(回退文件仅用于读取,不参与更新判定)
|
# 版本只与用户数据目录本地文件比对(回退文件仅用于读取,不参与更新判定)
|
||||||
local = _USER_DIR / f"{name}.json"
|
local = _USER_DIR / f"{name}.json"
|
||||||
lver = _pac_read_version(local)[0] if local.is_file() else ""
|
lver = _pac_read_version(local)[0] if local.is_file() else ""
|
||||||
if rver:
|
if rver:
|
||||||
@@ -1099,7 +1102,7 @@ class MainWindow(QWidget):
|
|||||||
self._update_download_done.connect(self._on_update_download_done)
|
self._update_download_done.connect(self._on_update_download_done)
|
||||||
self._status_ready.connect(self._apply_status)
|
self._status_ready.connect(self._apply_status)
|
||||||
|
|
||||||
_user_init_local() # 首启初始化 ~/RRPP(节点模板),须在 init_ui 读节点之前
|
_user_init_local() # 首启初始化用户数据目录(节点模板),须在 init_ui 读节点之前
|
||||||
|
|
||||||
self.init_ui()
|
self.init_ui()
|
||||||
|
|
||||||
@@ -1111,7 +1114,7 @@ class MainWindow(QWidget):
|
|||||||
|
|
||||||
# 启动时后台检查更新,完成前禁用开启按钮
|
# 启动时后台检查更新,完成前禁用开启按钮
|
||||||
threading.Thread(target=self._check_update, daemon=True).start()
|
threading.Thread(target=self._check_update, daemon=True).start()
|
||||||
# 后台检查 PAC 数据更新(首次启动自动拉取到 ~/RRPP)
|
# 后台检查 PAC 数据更新(首次启动自动拉取到用户数据目录)
|
||||||
threading.Thread(target=_user_init_remote, daemon=True).start()
|
threading.Thread(target=_user_init_remote, daemon=True).start()
|
||||||
|
|
||||||
def init_ui(self):
|
def init_ui(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user