Skip to content

Commit

Permalink
Restore Kindle's original Chinese Word Wise db file
Browse files Browse the repository at this point in the history
  • Loading branch information
xxyzz committed May 25, 2024
1 parent ae4e869 commit 722ba52
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
5 changes: 4 additions & 1 deletion custom_lemmas.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def __init__(
) -> None:
super().__init__(parent)
self.lemma_lang = lemma_lang
self.gloss_lang = gloss_lang
self.db_path = db_path
if is_kindle:
window_title = _("Customize Kindle Word Wise")
Expand Down Expand Up @@ -198,7 +199,9 @@ def check_empty_kindle_gloss(self) -> None:
custom_db_conn.close()
return
plugin_path = get_plugin_path()
klld_path = get_kindle_klld_path(plugin_path)
klld_path = get_kindle_klld_path(
plugin_path, self.gloss_lang in ("zh", "zh_cn")
)
if klld_path is None:
gui = self.parent()
while gui.parent() is not None:
Expand Down
20 changes: 15 additions & 5 deletions send_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .error_dialogs import kindle_epub_dialog
from .parse_job import ParseJobData
from .utils import (
get_kindle_klld_path,
get_plugin_path,
get_wiktionary_klld_path,
mac_bin_path,
Expand Down Expand Up @@ -249,9 +250,12 @@ def copy_klld_from_kindle(device_manager: Any, dest_path: Path) -> None:
download_file_from_mtp(
device_manager, Path("system/kll/kll.en.en.klld"), dest_path
)
download_file_from_mtp(
device_manager, Path("system/kll/kll.en.zh.klld"), dest_path
)
else:
for klld_path in Path(f"{device_manager.device._main_prefix}/system/kll").glob(
"*.en.klld"
"*.klld"
):
shutil.copy(klld_path, dest_path)

Expand All @@ -266,10 +270,16 @@ def copy_klld_to_device(

plugin_path = get_plugin_path()
if use_kindle_ww_db(book_lang, prefs):
return
local_klld_path = get_wiktionary_klld_path(
plugin_path, book_lang, prefs["kindle_gloss_lang"]
)
if prefs["kindle_gloss_lang"] in ("zh", "zh_cn"): # restore origin ww db
local_klld_path = get_kindle_klld_path(plugin_path, True)
if local_klld_path is None:
return
else:
return
else:
local_klld_path = get_wiktionary_klld_path(
plugin_path, book_lang, prefs["kindle_gloss_lang"]
)

if adb_path is not None:
run_subprocess([adb_path, "push", str(local_klld_path), str(device_klld_path)])
Expand Down
6 changes: 3 additions & 3 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ def wiktionary_db_path(plugin_path: Path, lemma_lang: str, gloss_lang: str) -> P
)


def get_kindle_klld_path(plugin_path: Path) -> Path | None:
def get_kindle_klld_path(plugin_path: Path, zh_gloss: bool = False) -> Path | None:
custom_folder = custom_lemmas_folder(plugin_path, "en")
for path in custom_folder.glob("*.en.klld"):
for path in custom_folder.glob("*.zh.klld" if zh_gloss else "*.en.klld"):
return path
for path in custom_folder.glob("*.en.db"):
for path in custom_folder.glob("*.zh.db" if zh_gloss else "*.en.db"):
return path
return None

Expand Down

0 comments on commit 722ba52

Please sign in to comment.