mirror of
https://github.com/aclist/dztui.git
synced 2026-08-25 17:32:36 +02:00
fix: more robust version/config file check
This commit is contained in:
parent
0a0d36c4e8
commit
b5a62a9815
@ -48,6 +48,8 @@ WINDOW_DEFAULT_X = 1400
|
||||
WINDOW_DEFAULT_Y = 800
|
||||
|
||||
LEGACY_CONFIG_PATH = ".config/dztui/dztuirc"
|
||||
LEGACY_COLS_PATH = ".local/state/dzgui/dzg.cols.json"
|
||||
LEGACY_IPS_PATH = ".local/share/dzgui/helpers/ips.csv"
|
||||
|
||||
DEBUG_LOG = f"{APP_NAME}_DEBUG.LOG"
|
||||
SYSTEM_LOG = f"{APP_NAME}_SYSTEM.LOG"
|
||||
|
||||
@ -34,7 +34,7 @@ from dzgui.const.enum import (
|
||||
ContextMenu,
|
||||
)
|
||||
|
||||
from dzgui.const.constants import LIBRARYFOLDERS_PATH, APPID_DAYZ, APPID_DAYZ_EXP, HEX_RED
|
||||
from dzgui.const.constants import LIBRARYFOLDERS_PATH, APPID_DAYZ, APPID_DAYZ_EXP, HEX_RED, WINDOW_DEFAULT_X, WINDOW_DEFAULT_Y
|
||||
from dzgui.controllers.model import ModelManager
|
||||
|
||||
from dzgui.config import update
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
from pathlib import Path
|
||||
from dzgui.const.constants import LEGACY_CONFIG_PATH
|
||||
from dzgui.const.constants import LEGACY_CONFIG_PATH, LEGACY_COLS_PATH, LEGACY_IPS_PATH
|
||||
from dzgui.config.convert import rc2json
|
||||
from dzgui.util._json import read_json, write_json
|
||||
|
||||
|
||||
def test_legacy_conf(config: Path) -> None:
|
||||
if config.exists() is True:
|
||||
return
|
||||
def migrate_legacy_conf(config: Path) -> None:
|
||||
old_conf = Path.home() / LEGACY_CONFIG_PATH
|
||||
if old_conf.is_file():
|
||||
j = rc2json(old_conf)
|
||||
@ -18,20 +18,36 @@ def test_legacy_conf(config: Path) -> None:
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def move_state_files(state_path: Path) -> None:
|
||||
def has_new_config(config: Path) -> bool:
|
||||
return config.exists()
|
||||
|
||||
|
||||
def migrate_cols_file(res: Path) -> None:
|
||||
old_res = Path.home() / LEGACY_COLS_PATH
|
||||
if old_res.is_file():
|
||||
j = read_json(old_res)
|
||||
cols = j["cols"]
|
||||
if "View" in cols:
|
||||
return
|
||||
cols["View"] = cols.pop("Perspective")
|
||||
cols["Max"] = cols.pop("Maximum")
|
||||
write_json(j, res)
|
||||
|
||||
|
||||
def copy_state_files(state_path: Path) -> None:
|
||||
home = Path.home()
|
||||
legacy = home / ".local/state/dzgui"
|
||||
if state_path == legacy:
|
||||
# TODO: log this
|
||||
return
|
||||
for file in legacy.iterdir():
|
||||
file.rename(state_path / file.name)
|
||||
shutil.copy(file, state_path / file.name)
|
||||
|
||||
|
||||
def move_ipdb(ips_path: Path) -> None:
|
||||
def copy_ipdb(ips_path: Path) -> None:
|
||||
home = Path.home()
|
||||
name = "ips.csv"
|
||||
legacy = home / ".local/share/helpers/dzgui" / name
|
||||
legacy = home / LEGACY_IPS_PATH
|
||||
if ips_path == legacy:
|
||||
return
|
||||
legacy.rename(ips_path)
|
||||
shutil.copy(legacy, ips_path)
|
||||
|
||||
@ -17,7 +17,13 @@ from dzgui.const.update import ALLOW_UPDATES
|
||||
from dzgui.init.coords import get_local_coords
|
||||
from dzgui.init.dayz import is_dayz_installed
|
||||
from dzgui.init.flock import lock_acquire, lock_release
|
||||
from dzgui.init.migrate import test_legacy_conf, move_state_files, move_ipdb
|
||||
from dzgui.init.migrate import (
|
||||
has_new_config,
|
||||
migrate_cols_file,
|
||||
migrate_legacy_conf,
|
||||
copy_state_files,
|
||||
copy_ipdb,
|
||||
)
|
||||
from dzgui.init.prefix import get_version
|
||||
from dzgui.init.prereqs import has_steam_client
|
||||
from dzgui.init.proc import is_dayz_running, is_steam_running
|
||||
@ -61,11 +67,11 @@ def main() -> None:
|
||||
xdg_paths = get_xdg_paths()
|
||||
XDG = parse_filepaths(xdg_paths)
|
||||
|
||||
# NOTE: one-time operation when upgrading
|
||||
if Version(version) < Version("7.0.0"):
|
||||
test_legacy_conf(XDG.config)
|
||||
move_state_files(xdg_paths["XDG_STATE_HOME"])
|
||||
move_ipdb(XDG.ips)
|
||||
if has_new_config(XDG.config) is False:
|
||||
migrate_legacy_conf(XDG.config)
|
||||
migrate_cols_file(XDG.columns)
|
||||
copy_state_files(xdg_paths["XDG_STATE_HOME"])
|
||||
copy_ipdb(XDG.ips)
|
||||
|
||||
_format = "%(asctime)s␞%(levelname)s␞%(filename)s::%(funcName)s::%(lineno)s␞%(message)s"
|
||||
logging.basicConfig(filename=XDG.debug, format=_format, level=logging.DEBUG)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user