add update color and check icon on startup

This commit is contained in:
2025-09-07 07:03:47 +02:00
parent 1d627080ce
commit 63e6386239

View File

@@ -19,8 +19,10 @@ class MediaRepository:
# dodawanie nowych kolorów
for color in disk_colors - db_colors:
has_icon = (MEDIA_DIR / color / "icon.jpg").exists()
self.db.add_color(color, has_icon=has_icon)
# has_icon = (MEDIA_DIR / color / "icon.jpg").exists()
# self.db.add_color(color, has_icon=has_icon)
# icon = MEDIA_DIR / color / "icon.jpg"
self.add_color(color)
# sprawdzanie plików dla każdego koloru
for color in disk_colors:
@@ -28,6 +30,8 @@ class MediaRepository:
if color_id is None:
continue
color_dir = MEDIA_DIR / color
icon_file = color_dir / "icon.jpg"
self.db.update_color_icon_flag(color, icon_file.exists())
disk_files = {f.name for f in color_dir.iterdir() if f.is_file() and f.name != "icon.jpg"}
db_files = {m["filename"] for m in self.db.get_media_for_color(color_id)}
@@ -48,17 +52,29 @@ class MediaRepository:
icon_file = color_dir / "icon.jpg"
if icon_path and icon_path.exists():
shutil.copy(icon_path, icon_file)
else:
shutil.copy(DEFAULT_ICON, icon_file)
self.db.add_color(name, has_icon=True)
self.db.add_color(name, icon_file.exists())
def remove_color(self, name: str):
if (MEDIA_DIR / name).exists():
shutil.rmtree(MEDIA_DIR / name)
self.db.delete_color(name)
def add_file(self, color: str, file_path: Path):
def update_color(self, old_name: str, new_name: str, icon_path: Path | None = None):
old_dir = MEDIA_DIR / old_name
new_dir = MEDIA_DIR / new_name
icon_file = new_dir / "icon.jpg"
if old_dir.exists():
old_dir.rename(new_dir)
if icon_path and icon_path.exists():
shutil.copy(icon_path, icon_file)
self.db.update_color_name(old_name, new_name)
self.db.update_color_icon_flag(new_name, icon_file.exists())
def add_media(self, color: str, file_path: Path):
target_dir = MEDIA_DIR / color
target_dir.mkdir(exist_ok=True)
target_file = target_dir / file_path.name
@@ -69,7 +85,7 @@ class MediaRepository:
if color_id is not None:
self.db.add_media(color_id, file_path.name, ftype)
def remove_file(self, color: str, filename: str):
def remove_media(self, color: str, filename: str):
file_path = MEDIA_DIR / color / filename
if file_path.exists():
file_path.unlink()