mirror of
https://github.com/aclist/dztui.git
synced 2026-10-30 14:42:54 +01:00
fix: parse parent dir
This commit is contained in:
1 parent
b8230cbf43
commit
b3b98aa407
4 files changed
+31
-15
No files matched your search
@@ -12,6 +12,7 @@ from dzgui.api.servers import get_rules, fqip_to_record
|
|||||||
from dzgui.const.constants import (
|
from dzgui.const.constants import (
|
||||||
APP_NAME,
|
APP_NAME,
|
||||||
APPID_DAYZ,
|
APPID_DAYZ,
|
||||||
|
DAYZ_COMMUNITY_ROOT,
|
||||||
LIBRARYFOLDERS_PATH,
|
LIBRARYFOLDERS_PATH,
|
||||||
WORKSHOP_PATH,
|
WORKSHOP_PATH,
|
||||||
)
|
)
|
||||||
@@ -50,6 +51,9 @@ def get_local_mods(workshop_path: Path) -> list[Path]:
|
|||||||
|
|
||||||
def is_mission(path: Path) -> bool:
|
def is_mission(path: Path) -> bool:
|
||||||
# TODO: parse integrity of other files
|
# TODO: parse integrity of other files
|
||||||
|
parent = path.parent.name
|
||||||
|
if parent != DAYZ_COMMUNITY_ROOT:
|
||||||
|
return False
|
||||||
file = path / "init.c"
|
file = path / "init.c"
|
||||||
return file.exists()
|
return file.exists()
|
||||||
|
|
||||||
|
|||||||
@@ -83,3 +83,5 @@ LOG_FILTERS = ("CRITICAL", "WARNING", "INFO", "DEBUG")
|
|||||||
TMP_PATH = "/tmp"
|
TMP_PATH = "/tmp"
|
||||||
TMP_TARBALL = "/tmp/dzgui.tar.gz"
|
TMP_TARBALL = "/tmp/dzgui.tar.gz"
|
||||||
TMP_EXE = "/tmp/dzgui/dzgui"
|
TMP_EXE = "/tmp/dzgui/dzgui"
|
||||||
|
|
||||||
|
DAYZ_COMMUNITY_ROOT = "Missions"
|
||||||
@@ -12,7 +12,7 @@ from dzgui.init.proc import is_dayz_running
|
|||||||
from dzgui.managers.threading import call_on_thread, StoredFunc, ThreadingManager
|
from dzgui.managers.threading import call_on_thread, StoredFunc, ThreadingManager
|
||||||
from dzgui.model.model_factory import ModelFactory
|
from dzgui.model.model_factory import ModelFactory
|
||||||
from dzgui.strings import dialogs
|
from dzgui.strings import dialogs
|
||||||
from dzgui.util.symlink import create_custom_symlinks, symlink_mission
|
from dzgui.util.symlink import create_custom_symlinks, clone_symlinks, symlink_mission
|
||||||
from dzgui.views.dialogs.filepicker import FolderPicker
|
from dzgui.views.dialogs.filepicker import FolderPicker
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
|||||||
+24
-14
@@ -2,7 +2,7 @@ import logging
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from dzgui.api.mods import get_local_mod_path, get_local_mod_ids, _hash
|
from dzgui.api.mods import get_local_mod_path, get_local_mod_ids, _hash
|
||||||
from dzgui.const.constants import APPID_DAYZ, APPID_DAYZ_EXP, APP_NAME
|
from dzgui.const.constants import APPID_DAYZ, APPID_DAYZ_EXP, APP_NAME, DAYZ_COMMUNITY_ROOT
|
||||||
from dzgui.const.enum import Preferences
|
from dzgui.const.enum import Preferences
|
||||||
from dzgui.config.query import lookup
|
from dzgui.config.query import lookup
|
||||||
|
|
||||||
@@ -11,18 +11,23 @@ import dzgui.api.pefile as PeFile
|
|||||||
logger = logging.getLogger(APP_NAME)
|
logger = logging.getLogger(APP_NAME)
|
||||||
|
|
||||||
|
|
||||||
|
def expunge_link(file: Path) -> None:
|
||||||
|
if not file.is_symlink():
|
||||||
|
return
|
||||||
|
# NOTE: unlink stale symlinks
|
||||||
|
if file.exists() is False:
|
||||||
|
file.unlink()
|
||||||
|
if str(file.stem)[:2] == "@C":
|
||||||
|
file.unlink()
|
||||||
|
|
||||||
def rebuild_symlinks(config: Path) -> None:
|
def rebuild_symlinks(config: Path) -> None:
|
||||||
# TODO: pass direct path as argument
|
# TODO: pass direct path as argument
|
||||||
path = lookup(config, Preferences.DEFAULT)
|
path = lookup(config, Preferences.DEFAULT)
|
||||||
steam_path = Path(path)
|
steam_path = Path(path)
|
||||||
dayz_path = PeFile.get_nested_app_path(steam_path, APPID_DAYZ)
|
dayz_path = PeFile.get_nested_app_path(steam_path, APPID_DAYZ)
|
||||||
for file in dayz_path.iterdir():
|
for file in dayz_path.iterdir():
|
||||||
# NOTE: unlink stale symlinks
|
expunge_link(file)
|
||||||
if file.is_symlink() and file.exists() is False:
|
|
||||||
file.unlink()
|
|
||||||
# NOTE: expunge ephemeral (custom) symlinks
|
|
||||||
if file.is_symlink() and str(file.stem)[:2] == "@C":
|
|
||||||
file.unlink()
|
|
||||||
workshop = get_local_mod_path(steam_path)
|
workshop = get_local_mod_path(steam_path)
|
||||||
# NOTE: create symlinks for missing mods
|
# NOTE: create symlinks for missing mods
|
||||||
for mod_id in get_local_mod_ids(steam_path):
|
for mod_id in get_local_mod_ids(steam_path):
|
||||||
@@ -49,16 +54,21 @@ def create_custom_symlinks(
|
|||||||
clone_symlinks(steam_path)
|
clone_symlinks(steam_path)
|
||||||
return links
|
return links
|
||||||
|
|
||||||
|
|
||||||
def symlink_mission(steam_path: Path, target: str) -> None:
|
def symlink_mission(steam_path: Path, target: str) -> None:
|
||||||
dayz_path = PeFile.get_nested_app_path(steam_path, APPID_DAYZ)
|
dayz_path = PeFile.get_nested_app_path(steam_path, APPID_DAYZ)
|
||||||
for file in dayz_path.iterdir():
|
for file in dayz_path.iterdir():
|
||||||
if file.is_symlink() and str(file.stem)[:2] == "@C":
|
expunge_link(file)
|
||||||
file.unlink()
|
path = Path(target)
|
||||||
stem = Path(target).name
|
stem = path.name
|
||||||
suffix = _hash(stem, use_custom=True)
|
parent = path.parent
|
||||||
source = dayz_path.joinpath(suffix)
|
suffix = _hash(str(parent), use_custom=True)
|
||||||
source.symlink_to(Path(target))
|
source = dayz_path.joinpath(DAYZ_COMMUNITY_ROOT)
|
||||||
return suffix
|
try:
|
||||||
|
source.symlink_to(parent)
|
||||||
|
except Exception:
|
||||||
|
return ""
|
||||||
|
return f"{DAYZ_COMMUNITY_ROOT}/{stem}"
|
||||||
|
|
||||||
|
|
||||||
def clone_symlinks(steam_path: Path) -> None:
|
def clone_symlinks(steam_path: Path) -> None:
|
||||||
|
|||||||
Reference in new issue
Block a user