diff --git a/comicapi/comicarchive.py b/comicapi/comicarchive.py index c7fd0b1..1914b61 100644 --- a/comicapi/comicarchive.py +++ b/comicapi/comicarchive.py @@ -368,7 +368,7 @@ class RarArchiver(UnknownArchiver): def __init__(self, path: pathlib.Path | str, rar_exe_path: str = "rar") -> None: super().__init__(path) - self.rar_exe_path = rar_exe_path + self.rar_exe_path = shutil.which(rar_exe_path) or "" # windows only, keeps the cmd.exe from popping up if platform.system() == "Windows": @@ -687,7 +687,7 @@ class ComicArchive: self.page_count: int | None = None self.page_list: list[str] = [] - self.rar_exe_path = rar_exe_path + self.rar_exe_path = shutil.which(rar_exe_path or "rar") or "" self.ci_xml_filename = "ComicInfo.xml" self.comet_default_filename = "CoMet.xml" self.reset_cache() diff --git a/comictaggerlib/fileselectionlist.py b/comictaggerlib/fileselectionlist.py index aeb6dd4..e0974d8 100644 --- a/comictaggerlib/fileselectionlist.py +++ b/comictaggerlib/fileselectionlist.py @@ -17,13 +17,16 @@ from __future__ import annotations import logging import os +import platform from typing import Callable, cast from PyQt5 import QtCore, QtWidgets, uic from comicapi import utils from comicapi.comicarchive import ComicArchive +from comictaggerlib.optionalmsgdialog import OptionalMessageDialog from comictaggerlib.settings import ComicTaggerSettings +from comictaggerlib.settingswindow import linuxRarHelp, macRarHelp, windowsRarHelp from comictaggerlib.ui.qtutils import center_window_on_parent, reduce_widget_font_size logger = logging.getLogger(__name__) @@ -88,6 +91,7 @@ class FileSelectionList(QtWidgets.QWidget): self.addAction(self.separator) self.dirty_flag_verification = dirty_flag_verification + self.rar_ro_shown = False def get_sorting(self) -> tuple[int, int]: col = self.twList.horizontalHeader().sortIndicatorSection() @@ -190,6 +194,7 @@ class FileSelectionList(QtWidgets.QWidget): QtCore.QCoreApplication.processEvents() first_added = None + rar_added = False self.twList.setSortingEnabled(False) for idx, f in enumerate(filelist): QtCore.QCoreApplication.processEvents() @@ -200,8 +205,12 @@ class FileSelectionList(QtWidgets.QWidget): center_window_on_parent(progdialog) QtCore.QCoreApplication.processEvents() row = self.add_path_item(f) - if first_added is None and row is not None: - first_added = row + if row is not None: + ca = self.get_archive_by_row(row) + if ca and ca.is_rar(): + rar_added = True + if first_added is None: + first_added = row progdialog.hide() QtCore.QCoreApplication.processEvents() @@ -216,6 +225,9 @@ class FileSelectionList(QtWidgets.QWidget): else: QtWidgets.QMessageBox.information(self, "File/Folder Open", "No readable comic archives were found.") + if rar_added and not utils.which(self.settings.rar_exe_path or "rar"): + self.rar_ro_message() + self.twList.setSortingEnabled(True) # Adjust column size @@ -229,6 +241,26 @@ class FileSelectionList(QtWidgets.QWidget): if self.twList.columnWidth(FileSelectionList.folderColNum) > 200: self.twList.setColumnWidth(FileSelectionList.folderColNum, 200) + def rar_ro_message(self) -> None: + if not self.rar_ro_shown: + if platform.system() == "Windows": + rar_help = windowsRarHelp + + elif platform.system() == "Linux": + rar_help = linuxRarHelp + + elif platform.system() == "Darwin": + rar_help = macRarHelp + + OptionalMessageDialog.msg_no_checkbox( + self, + "RAR Files are Read-Only", + "It looks like you have opened a RAR/CBR archive,\n" + "however ComicTagger cannot currently write to them without the rar program and are marked read only!\n\n" + f"{rar_help}", + ) + self.rar_ro_shown = True + def is_list_dupe(self, path: str) -> bool: return self.get_current_list_row(path) >= 0 diff --git a/comictaggerlib/optionalmsgdialog.py b/comictaggerlib/optionalmsgdialog.py index 6ba86b2..23c2de3 100644 --- a/comictaggerlib/optionalmsgdialog.py +++ b/comictaggerlib/optionalmsgdialog.py @@ -112,3 +112,14 @@ class OptionalMessageDialog(QtWidgets.QDialog): d.exec() return d.was_accepted, d.theCheckBox.isChecked() + + @staticmethod + def msg_no_checkbox( + parent: QtWidgets.QWidget, title: str, msg: str, checked: bool = False, check_text: str = "" + ) -> bool: + + d = OptionalMessageDialog(parent, StyleMessage, title, msg, checked=checked, check_text=check_text) + d.theCheckBox.hide() + + d.exec() + return d.theCheckBox.isChecked() diff --git a/comictaggerlib/settings.py b/comictaggerlib/settings.py index 26a75d1..9f3c983 100644 --- a/comictaggerlib/settings.py +++ b/comictaggerlib/settings.py @@ -163,7 +163,7 @@ class ComicTaggerSettings: # see if it's in the path of unix user rarpath = utils.which("rar") if rarpath is not None: - self.rar_exe_path = rarpath + self.rar_exe_path = "rar" if self.rar_exe_path != "": self.save() if self.rar_exe_path != "": diff --git a/comictaggerlib/settingswindow.py b/comictaggerlib/settingswindow.py index b32fc93..8597af6 100644 --- a/comictaggerlib/settingswindow.py +++ b/comictaggerlib/settingswindow.py @@ -34,29 +34,29 @@ from comictaggerlib.settings import ComicTaggerSettings logger = logging.getLogger(__name__) windowsRarHelp = """ -

To write to CBR/RAR archives, - you will need to have the tools from - - WINRar - installed. (ComicTagger only uses the command-line rar tool, - which is free to use.)

+

To write to CBR/RAR archives, + you will need to have the tools from + + WINRar + installed. (ComicTagger only uses the command-line rar tool.) +

""" linuxRarHelp = """ -

To write to CBR/RAR archives, - you will need to have the shareware rar tool from RARLab installed. - Your package manager should have rar (e.g. "apt-get install rar"). If not, download it - - here, - and install in your path.

- """ +

To write to CBR/RAR archives, + you will need to have the shareware rar tool from RARLab installed. + Your package manager should have rar (e.g. "apt-get install rar"). If not, download it + + here, + and install in your path.

+ """ macRarHelp = """ -

To write to CBR/RAR archives, - you will need the rar tool. The easiest way to get this is - to install - homebrew. -

Once homebrew is installed, run: brew install caskroom/cask/rar +

To write to CBR/RAR archives, + you will need the rar tool. The easiest way to get this is + to install + homebrew. +

Once homebrew is installed, run: brew install caskroom/cask/rar """