From ed8d170791139d555879d1a38ff098ad16ae6503 Mon Sep 17 00:00:00 2001 From: Alexandre Ferreira de Lima Date: Tue, 19 Dec 2023 14:37:17 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Add=20textures=20to=20install=20?= =?UTF-8?q?and=20uninstall=20commands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 14 +-- README.en.md | 37 ++++-- README.md | 41 +++++-- config/toml/cli.toml | 5 +- config/toml/github.toml | 16 ++- config/toml/settings.toml | 41 ++++++- config/toml/typer.toml | 15 +-- poetry.lock | 14 ++- pyproject.toml | 1 + src/commands/translation_builder/generate.py | 9 +- src/commands/translation_manager/__init__.py | 1 - src/commands/translation_manager/install.py | 106 +++++++++++++----- src/commands/translation_manager/manager.py | 6 +- src/commands/translation_manager/uninstall.py | 42 +++++-- src/commands/translation_manager/update.py | 56 --------- src/miscellaneous/__init__.py | 1 + src/miscellaneous/nier_path.py | 35 +++++- src/miscellaneous/translation.py | 27 +++++ src/translator_engine/chat_gpt_translator.py | 2 +- src/utils/http_request_utils.py | 3 + src/utils/path_utils.py | 2 +- src/utils/zip_utils.py | 14 +++ 22 files changed, 330 insertions(+), 158 deletions(-) delete mode 100644 src/commands/translation_manager/update.py create mode 100644 src/miscellaneous/translation.py diff --git a/Makefile b/Makefile index 5acfc68..405ed6b 100644 --- a/Makefile +++ b/Makefile @@ -13,23 +13,17 @@ google-translate: generate: python main.py builder generate -update: - python main.py manager update - -update-local: - python main.py manager update --local +translation-folder: + python main.py builder make-translation-folder -install: +update: python main.py manager install -install-local: +update-local: python main.py manager install --local uninstall: python main.py manager uninstall -reimport-texts: - python main.py reimport texts - pack-gui: auto-py-to-exe diff --git a/README.en.md b/README.en.md index 0f0aa29..b55c5fc 100644 --- a/README.en.md +++ b/README.en.md @@ -104,12 +104,13 @@ Here, I'll describe **two ways** to install the translation, using the installer > NieR Replicant™ ver. 1.22 - PT-BR Translation [![NieR Replicant™ ver. 1.22 - PT-BR Translation](https://i.imgur.com/SYK4rgx.png)](https://www.youtube.com/watch?v=3BiVi_KfGbA) +> It's worth noting that this installation method will automatically install SpecialK to your game. 1. Download the application executable here: [Release][release] 2. Extract the zipped `.zip` file to a preferred folder. -3. Run the `install.bat` file. +3. Run the `instalar e atualizar.bat` file. 4. The program will execute and prompt for the directory path to NieR Replicant ver.1.22474487139. > **Example** of path @@ -122,6 +123,8 @@ Here, I'll describe **two ways** to install the translation, using the installer
### Tutorial without the installer + +#### Text Files 1. Download the necessary files here: [data][data] 2. Extract the zipped `.zip` file to a preferred folder. @@ -139,20 +142,30 @@ Here, I'll describe **two ways** to install the translation, using the installer 6. That's it, now just start the game. 🎉 +#### Texture Files +> **This step is not mandatory; only do it if you want the textures to be translated as well.** + +1. Download the necessary textures here: [textures][textures] + +2. Download SpecialK here: [SpecialK][specialk] + +3. Place the `dxgi.dll` file inside the root folder of your NieR: Replicant. + +4. Create the directory `SK_Res\inject\textures` within the root folder. + +5. Within the created directory, unzip all the `.dds` files you downloaded in step 1. *(the textures folder must contain these `.dds` files)* + +6. That's it! Now you can start the game. 🎉 + ## Useful commands list 1. Install ```cmd - nier-translator.exe manager install + nier-translator.exe manager install --specialk ``` 2. Uninstall ```cmd - nier-translator.exe manager uninstall - ``` - -3. Update the translation - ```cmd - nier-translator.exe manager update + nier-translator.exe manager uninstall --specialk ```
@@ -168,6 +181,7 @@ Here, I'll describe **two ways** to install the translation, using the installer This project was made possible thanks to these two repositories: * Tool for asset extraction - [kaine][kaine] * Tool for text extraction - [NieR-Text-Tool][ntt] +* Tool for texture extraction and injection - [SpecialK][specialk_tool]
@@ -324,8 +338,10 @@ I've set up some commands to ease the translation creation process; I'll list an | :---: | :---: | :---: | -[release]: https://github.com/Arekushi/nier-replicant-pt-br-translation/releases/download/2.0.0/nier-translator.zip -[data]: https://github.com/Arekushi/nier-replicant-pt-br-translation/releases/download/2.0.0/data.zip +[release]: https://github.com/Arekushi/nier-replicant-pt-br-translation/releases/download/2.1.0/nier-translator.zip +[data]: https://raw.githubusercontent.com/Arekushi/nier-replicant-pt-br-translation/master/patch/data.zip +[textures]: https://raw.githubusercontent.com/Arekushi/nier-replicant-pt-br-translation/master/patch/textures.zip +[specialk]: https://raw.githubusercontent.com/Arekushi/nier-replicant-pt-br-translation/master/patch/dxgi.zip [python]: https://www.python.org/downloads/ @@ -336,6 +352,7 @@ I've set up some commands to ease the translation creation process; I'll list an [kaine]: https://github.com/yretenai/kaine [ntt]: https://github.com/lehieugch68/NieR-Text-Tool [chrome_drive_url]: https://googlechromelabs.github.io/chrome-for-testing/#stable +[specialk_tool]: https://www.special-k.info/ [arekushi]: https://github.com/Arekushi diff --git a/README.md b/README.md index cba0917..c59cfbd 100644 --- a/README.md +++ b/README.md @@ -105,14 +105,15 @@ Aqui irei descrever **duas formas** de instalar a tradução, usando o instalado > NieR Replicant™ ver. 1.22 - Tradução para PT-BR [![NieR Replicant™ ver. 1.22 - Tradução para PT-BR](https://i.imgur.com/SYK4rgx.png)](https://www.youtube.com/watch?v=3BiVi_KfGbA) +> É válido apontar que essa forma de instalar irá instalar o SpecialK automaticamente ao seu jogo. 1. Baixe o executável da aplicação aqui: [Release][release] 2. Extraia o arquivo zipado `.zip` para alguma pasta de sua preferência. -3. Execute o arquivo `install.bat` +3. Execute o arquivo `instalar e atualizar.bat` -4. O programa irá executar e solicitar o caminho até o diretório do NieR Replicant ver.1.22474487139 +4. O programa irá procurar pela pasta onde está instalado o NieR: Replicant. Caso não encontre irá ser solicitado o caminho. > **Exemplo** de caminho ``` C:\SteamLibrary\steamapps\common\NieR Replicant ver.1.22474487139 @@ -123,7 +124,9 @@ Aqui irei descrever **duas formas** de instalar a tradução, usando o instalado
### Tutorial sem o instalador -1. Baixe os arquivos necessários aqui: [data][data] + +#### Arquivos de Texto +1. Baixe os arquivos de texto necessários aqui: [data][data] 2. Extraia o arquivo zipado `.zip` para alguma pasta de sua preferência. @@ -140,20 +143,30 @@ Aqui irei descrever **duas formas** de instalar a tradução, usando o instalado 6. Prontinho, agora é só iniciar o jogo. 🎉 +#### Arquivos de Texturas +> **Essa etapa não é obrigatório, faça somente se desejar as texturas também traduzidas.** + +1. Baixe as texturas necessárias aqui: [textures][textures] + +2. Baixe o SpecialK aqui: [SpecialK][specialk] + +3. Coloque o arquivo `dxgi.dll` dentro da pasta raíz do seu NieR: Replicant. + +4. Crie dentro da pasta raíz o diretório `SK_Res\inject\textures` + +5. Dentro do diretório criado descompacte todos os arquivos `.dds` que baixou na etapa 1. *(a pasta textures precisa ter esses arquivos `.dds`)* + +6. Prontinho, agora é só iniciar o jogo. 🎉 + ## Lista de comandos uteis 1. Instalar ```cmd - nier-translator.exe manager install + nier-translator.exe manager install --specialk ``` 2. Desinstalar ```cmd - nier-translator.exe manager uninstall - ``` - -3. Atualizar a tradução - ```cmd - nier-translator.exe manager update + nier-translator.exe manager uninstall --specialk ```
@@ -169,6 +182,7 @@ Aqui irei descrever **duas formas** de instalar a tradução, usando o instalado Esse projeto só foi possível graças a esses dois repositórios * Ferramenta para extração dos assets - [kaine][kaine] * Ferramenta para extração dos textos - [NieR-Text-Tool][ntt] +* Ferramenta para extração e injeção de texturas - [SpecialK][specialk_tool]
@@ -325,8 +339,10 @@ Eu deixei alguns comandos prontos para facilitar a criação de uma tradução, | :---: | :---: | :---: | -[release]: https://github.com/Arekushi/nier-replicant-pt-br-translation/releases/download/2.0.0/nier-translator.zip -[data]: https://github.com/Arekushi/nier-replicant-pt-br-translation/releases/download/2.0.0/data.zip +[release]: https://github.com/Arekushi/nier-replicant-pt-br-translation/releases/download/2.1.0/nier-translator.zip +[data]: https://raw.githubusercontent.com/Arekushi/nier-replicant-pt-br-translation/master/patch/data.zip +[textures]: https://raw.githubusercontent.com/Arekushi/nier-replicant-pt-br-translation/master/patch/textures.zip +[specialk]: https://raw.githubusercontent.com/Arekushi/nier-replicant-pt-br-translation/master/patch/dxgi.zip [python]: https://www.python.org/downloads/ @@ -337,6 +353,7 @@ Eu deixei alguns comandos prontos para facilitar a criação de uma tradução, [kaine]: https://github.com/yretenai/kaine [ntt]: https://github.com/lehieugch68/NieR-Text-Tool [chrome_drive_url]: https://googlechromelabs.github.io/chrome-for-testing/#stable +[specialk_tool]: https://www.special-k.info/ [arekushi]: https://github.com/Arekushi diff --git a/config/toml/cli.toml b/config/toml/cli.toml index 675816a..8915de8 100644 --- a/config/toml/cli.toml +++ b/config/toml/cli.toml @@ -33,7 +33,7 @@ file_failed = 'Não foi possível adicionar na lista para traduzir: ' [CLI.NIERPATH] -not_found = ''':stop_sign: A pasta onde o [i]NieR Replicant[/] está instalado [white on red] não [/] foi definida! +not_found = ''':stop_sign: A pasta onde o [i]NieR Replicant[/] está instalado [white on red] não [/] foi encontrada ou definida! :mag_right: [b]EXEMPLO[/] de caminho: [#d1d8e6 on #79a4f4] C:\SteamLibrary\steamapps\common\NieR Replicant ver.1.22474487139 [/] ''' write_path = ':file_folder: Escreva o [b green]caminho[/] para o [i]NieR: Replicant[/], por favor: ' @@ -48,6 +48,9 @@ status = 'Instalando...' finish = ':white_check_mark: Instalação feita com [white on green] sucesso! [/]' failed = ':x: Instalação [white on red] falhou... [/]' update_version = ':rocket: Identificamos [white on green] atualizações [/] nos textos da tradução, iremos [b]fazer[/] a atualização automaticamente... ' +specialk = ':airplane: Será realizada a instalação do [white on green] SpecialK [/] localmente no diretório do NieR: Replicant.' +backup = ':arrow_backward: Será realizado [white on green] o backup [/] dos arquivos que serão modificados.' +backup_file_failed = ':x: [white on red] NÃO [/] foi possível realizar o backup de um dos arquivos!' [CLI.UNINSTALL] diff --git a/config/toml/github.toml b/config/toml/github.toml index 213a94d..060113c 100644 --- a/config/toml/github.toml +++ b/config/toml/github.toml @@ -1,10 +1,16 @@ [GITHUB] -current_commit_sha = "d0f6cfeba59992b7fb49e70e2894988f9fee0134" -current_release_version = "2.0.0" +current_commit_sha = "0aba0cfcff8c94484c5cf2027629f01c49346eeb" +current_release_version = "2.1.0" master_url = "https://github.com/Arekushi/nier-replicant-pt-br-translation/archive/master.zip" last_release_url = "https://api.github.com/repos/Arekushi/nier-replicant-pt-br-translation/releases/latest" commits_url = "https://api.github.com/repos/Arekushi/nier-replicant-pt-br-translation/commits" -data_files_urls = [ - "https://raw.githubusercontent.com/Arekushi/nier-replicant-pt-br-translation/master/patch/data/common.arc", - "https://raw.githubusercontent.com/Arekushi/nier-replicant-pt-br-translation/master/patch/data/info.arc", +files_to_update_urls = [ + [ + "https://raw.githubusercontent.com/Arekushi/nier-replicant-pt-br-translation/master/patch/data.zip", + "patch", + ], + [ + "https://raw.githubusercontent.com/Arekushi/nier-replicant-pt-br-translation/master/patch/textures.zip", + "patch", + ], ] diff --git a/config/toml/settings.toml b/config/toml/settings.toml index fd83028..6be02b2 100644 --- a/config/toml/settings.toml +++ b/config/toml/settings.toml @@ -8,23 +8,46 @@ paths_to_translate = [ [FOLDERS] +nier_folder_name = 'NieR Replicant ver.1.22474487139' raw_texts_folder_name = 'raw' translation_folder_name = 'translation' -backup_arc_folder_name = 'backup' +backup_folder_name = 'backup' +tmp_folder_name = 'tmp' [FILES] +secrets_file_name = '.secrets.toml' +translation_toml_file = 'translation.toml' required_checkout = [ 'steam_api64.dll', 'NieR Replicant ver.1.22474487139.exe' ] +special_k_zip = 'patch\\dxgi.zip' text_without_pattern = [ 'text_common\nier_text.txd.csv', 'talk_all\talker_name.tnd.csv' ] -backup_arc = [ - 'common.arc', - 'info.arc' +to_backup = [ + 'data\\common.arc', + 'data\\info.arc' +] +textures_to_delete = [ + '0C812038.dds', + '8B34C860.dds', + '76E5BE6A.dds', + '887C8923.dds', + 'D19BD2AB.dds', + 'E166F83B.dds' +] +specialk_files = [ + 'dxgi.dll', + 'dxgi.ini' +] +to_install = [ + # 0: File Path + # 1: Destination Path + ['patch\\data.zip', 'data'], + ['patch\\textures.zip', 'SK_Res\\inject'] ] @@ -45,13 +68,19 @@ tools_array = [ [DEFAULT_PATHS] -tmp = 'tmp' -tmp_error = 'tmp\\error' tomls = 'config\\toml' extracted_assets = 'build_assets\\rom\\pc' extracted_texts = 'snow\\text' patch_data = 'patch\\data' patch_source = 'patch\\source' +patch_textures = 'patch\\textures' +nier_possible_paths = [ + 'Program Files (x86)\\Steam\\steamapps\\common', + 'Program Files\\Steam\\steamapps\\common', + 'SteamLibrary\\steamapps\\common', + 'Steam\\SteamLibrary\\steamapps\\common', + 'Steam\\steamapps\\common' +] [COLUMNS] diff --git a/config/toml/typer.toml b/config/toml/typer.toml index 11e548e..737b6d7 100644 --- a/config/toml/typer.toml +++ b/config/toml/typer.toml @@ -12,21 +12,14 @@ texts_help = 'Uni os textos traduzidos e os originais e os copia para a pasta do [TYPER.INSTALL] -help = 'Comando que realizará o processo de instalação da tradução.' -delete_data_help = 'Flag para indicar se o usuário deseja ou não apagar a pasta [data] dos arquivos do jogo. É necessário remover a pasta [data] para dar andamento com a tradução, porém podemos apenas mudar o nome da pasta para qualquer outra coisa.' -delete_data_prompt = 'Você deseja deletar a pasta [data] do NieR: Replicant? 📂 Se decidir apagar NÃO há como reverter a tradução, você irá precisar baixar o jogo novamente...' -update_texts_help = 'Indica se você deseja fazer o download das atualizações mais recentes do repositório remoto.' -do_update_help = 'Esse marcador define se será realizado o update do repositório remoto do Github ou não.' +help = 'Comando que realizará o processo de instalação/atualização da tradução.' +use_local_files_help = 'Esse marcador define que serão utilizados os arquivos locais e não os arquivos do repositório remoto do Github.' +specialk_help = 'Esse marcador define que será instalado o Mod SpecialK localmente na pasta do NieR: Replicant, com o objetivo de utilizar as texturas traduzidas.' [TYPER.UNINSTALL] help = 'Comando que realizará o processo de desinstalação da tradução.' - - -[TYPER.UPDATE] -help = 'Comando que realizará a atualização da tradução, baixando os arquivos do repositório remoto.' -do_download_help = 'Esse marcador define que não será baixado os textos do repositório remoto do Github, ele utiliza o textos locais.' -redownload_help = 'Caso não queria, também é possível fazer a atualização com os arquivos locais.' +specialk_help = 'Esse mercador define que o Mod SpecialK será desinstalado junto com a tradução.' [TYPER.MANAGER] diff --git a/poetry.lock b/poetry.lock index d1ab3d9..53e485e 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1658,6 +1658,18 @@ files = [ {file = "soupsieve-2.4.tar.gz", hash = "sha256:e28dba9ca6c7c00173e34e4ba57448f0688bb681b7c5e8bf4971daafc093d69a"}, ] +[[package]] +name = "toml" +version = "0.10.2" +description = "Python Library for Tom's Obvious, Minimal Language" +category = "main" +optional = false +python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" +files = [ + {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, + {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, +] + [[package]] name = "tqdm" version = "4.65.0" @@ -2083,4 +2095,4 @@ testing = ["coverage (>=5.0.3)", "zope.event", "zope.testing"] [metadata] lock-version = "2.0" python-versions = ">=3.9,<3.12" -content-hash = "dbf25a8647080dac79626179c7083ab1b7bf6074c5b62dda9f5100fa41bc0db1" +content-hash = "267b58186bb3cc8a9f2f40893a0b775aa98eaf98cb422a1ba2bceb032d2f9061" diff --git a/pyproject.toml b/pyproject.toml index 16bbfca..8ac1bcd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,6 +22,7 @@ typer = {extras = ["all"], version = "^0.7.0"} pyinstaller = "^5.9.0" auto-py-to-exe = "^2.33.0" unlimitedgpt = "^0.1.9.3" +toml = "^0.10.2" [build-system] diff --git a/src/commands/translation_builder/generate.py b/src/commands/translation_builder/generate.py index 3743fbb..e37bf94 100644 --- a/src/commands/translation_builder/generate.py +++ b/src/commands/translation_builder/generate.py @@ -4,7 +4,8 @@ from rich.console import Console from config.config import settings, ROOT_DIR -from src.utils import make_dir, copy_folder, merge_translated_files, get_folders_name, remove +from src.utils import make_dir, copy_folder, merge_translated_files, \ + get_folders_name, remove, zip_folder console = Console() @@ -15,8 +16,8 @@ translation_folder_name = settings.FOLDERS.translation_folder_name raw_texts_folder_name = settings.FOLDERS.raw_texts_folder_name +patch_path = f'{ROOT_DIR}\\patch' patch_source_path = settings.DEFAULT_PATHS.patch_source -patch_data_path = settings.DEFAULT_PATHS.patch_data arc_path = settings.TOOLS.arc_path arc_source_path = f'{arc_path}\\source' @@ -24,7 +25,7 @@ arc_data_path = f'{arc_path}\\data' texts_path = f'{ROOT_DIR}\\texts' -tmp_path = f'{ROOT_DIR}\\tmp' +tmp_path = f'{ROOT_DIR}\\{settings.FOLDERS.tmp_folder_name}' ntt_exe = f'{ROOT_DIR}\\{settings.TOOLS.ntt_exe}' reptext_exe = f'{ROOT_DIR}\\{settings.TOOLS.reptext_exe}' zstd_exe = f'{ROOT_DIR}\\{settings.TOOLS.zstd_exe}' @@ -67,7 +68,7 @@ def generate_arc_files(): stderr=subprocess.DEVNULL ) - copy_folder(arc_data_path, patch_data_path) + zip_folder('data.zip', arc_data_path, patch_path) def reimport_texts(result_folder_path): diff --git a/src/commands/translation_manager/__init__.py b/src/commands/translation_manager/__init__.py index 4c92d9c..c35a6a7 100644 --- a/src/commands/translation_manager/__init__.py +++ b/src/commands/translation_manager/__init__.py @@ -1,4 +1,3 @@ -from .update import * from .uninstall import * from .install import * from .manager import * diff --git a/src/commands/translation_manager/install.py b/src/commands/translation_manager/install.py index 000ab1d..da8e04d 100644 --- a/src/commands/translation_manager/install.py +++ b/src/commands/translation_manager/install.py @@ -1,59 +1,115 @@ import typer +import zipfile from rich.console import Console from config import settings, ROOT_DIR -from .update import update from src.miscellaneous import local_has_latest_commit -from src.utils import make_dir, copy_files, copy_folder +from src.utils import make_dir, copy_file, download_file, unzip_file, remove +from src.miscellaneous import has_special_k, has_installed_translation, write_flag_installed console = Console() app = typer.Typer(help=settings.TYPER.INSTALL.help) nier_path = settings.PATHS.nier_replicant_path -nier_data_path = f'{nier_path}\\data' -patch_data = settings.DEFAULT_PATHS.patch_data +tmp_path = f'{ROOT_DIR}\\{settings.FOLDERS.tmp_folder_name}' +specialk_zip = f'{ROOT_DIR}\\{settings.FILES.special_k_zip}' -backup_arc_folder_name = settings.FOLDERS.backup_arc_folder_name -backup_arc_files = settings.FILES.backup_arc -backup_path = f'{nier_data_path}\\{backup_arc_folder_name}' +files_to_update_urls = settings.GITHUB.files_to_update_urls +files_to_install = settings.FILES.to_install +files_to_backup = settings.FILES.to_backup + +backup_path = f'{nier_path}\\{settings.FOLDERS.backup_folder_name}' @app.command('install', help=settings.TYPER.INSTALL.help) def install_command( - do_update: bool = typer.Option( - True, + use_local_files: bool = typer.Option( + False, '--local', - help=settings.TYPER.INSTALL.do_update_help + help=settings.TYPER.INSTALL.use_local_files_help + ), + install_specialk: bool = typer.Option( + False, + '--specialk', + help=settings.TYPER.INSTALL.specialk_help ) ): - console.rule(settings.CLI.INSTALL.rule) + typer_state = 'INSTALL' if not has_installed_translation() else 'UPDATE' + console.rule(settings.CLI[typer_state].rule) try: - with console.status(settings.CLI.INSTALL.status, spinner='moon'): - install(do_update) + with console.status(settings.CLI[typer_state].status, spinner='moon'): + install(use_local_files, install_specialk) - console.print(settings.CLI.INSTALL.finish) + console.print(settings.CLI[typer_state].finish) console.print(settings.CLI.thanks, justify='center') except Exception: - console.print(settings.CLI.INSTALL.failed) + console.print(settings.CLI[typer_state].failed) console.print_exception(show_locals=True) -def install(do_update: bool): - do_backup_files() +def install( + use_local_files: bool, + install_specialk: bool +): + if install_specialk: + if not has_special_k(nier_path): + console.print(settings.CLI.INSTALL.specialk) + install_special_k() - if (do_update): + if not has_installed_translation(): + console.print(settings.CLI.INSTALL.backup) + backup_files() + + if not use_local_files: if not local_has_latest_commit(): console.print(settings.CLI.INSTALL.update_version) - update(do_download=True) - else: - copy_folder(patch_data, nier_data_path) + files = download_updated_files() + update_files_to_install(files) + + for file_path, dest in files_to_install: + file_path = f'{ROOT_DIR}\\{file_path}' + new_file_path = copy_file(file_path, f'{nier_path}\\{dest}') + + if zipfile.is_zipfile(file_path): + unzip_file(file_path, f'{nier_path}\\{dest}') + remove(new_file_path) + + write_flag_installed(True) + +def backup_files(): + try: + for file in files_to_backup: + folder_name = '\\'.join(file.split('\\')[:-1]) + folder_inside_backup_path = f'{backup_path}\\{folder_name}' + make_dir(folder_inside_backup_path) + copy_file(f'{nier_path}\\{file}', folder_inside_backup_path) + except FileNotFoundError: + console.print( + settings.CLI.INSTALL.backup_file_failed + ) -def do_backup_files(): - files_to_backup = [f'{nier_data_path}\\{arc_file}' for arc_file in backup_arc_files] + +def update_files_to_install(files): + for i in range(len(files_to_install)): + files_to_install[i][0] = files[i] + + +def download_updated_files(): + files = list() - make_dir(backup_path) - copy_files(files_to_backup, backup_path) + for file_url, tmp_folder in files_to_update_urls: + file_path = download_file(file_url, f'{tmp_path}\\{tmp_folder}') + files.append(file_path) + + console.print(settings.CLI.UPDATE.download_finished) + return files + + +def install_special_k(): + specialk_zip_path = copy_file(specialk_zip, nier_path) + unzip_file(specialk_zip_path, nier_path) + remove(specialk_zip_path) diff --git a/src/commands/translation_manager/manager.py b/src/commands/translation_manager/manager.py index d0192fb..a6bcc58 100644 --- a/src/commands/translation_manager/manager.py +++ b/src/commands/translation_manager/manager.py @@ -3,11 +3,11 @@ from config import settings from .install import install_command from .uninstall import uninstall_command -from .update import update_command -app = typer.Typer(help=settings.TYPER.MANAGER.help) +app = typer.Typer( + help=settings.TYPER.MANAGER.help +) app.command('install', help=settings.TYPER.INSTALL.help)(install_command) app.command('uninstall', help=settings.TYPER.UNINSTALL.help)(uninstall_command) -app.command('update', help=settings.TYPER.UPDATE.help)(update_command) diff --git a/src/commands/translation_manager/uninstall.py b/src/commands/translation_manager/uninstall.py index aacf3a7..c4ef5ca 100644 --- a/src/commands/translation_manager/uninstall.py +++ b/src/commands/translation_manager/uninstall.py @@ -1,30 +1,39 @@ import typer +import contextlib from rich.console import Console from config import settings -from src.utils import remove, copy_folder +from src.utils import remove, copy_folder, has_folder +from src.miscellaneous import write_flag_installed console = Console() app = typer.Typer(help=settings.TYPER.UNINSTALL.help) nier_path = settings.PATHS.nier_replicant_path -nier_data_path = f'{nier_path}\\data' +files_to_delete = { + '.\SK_Res\\inject\\textures': settings.FILES.textures_to_delete +} -backup_arc_folder_name = settings.FOLDERS.backup_arc_folder_name -backup_path = f'{nier_data_path}\\{backup_arc_folder_name}' +backup_path = f'{nier_path}\\{settings.FOLDERS.backup_folder_name}' @app.command( 'uninstall', help=settings.TYPER.UNINSTALL.help ) -def uninstall_command(): +def uninstall_command( + uninstall_specialk: bool = typer.Option( + False, + '--specialk', + help=settings.TYPER.UNINSTALL.specialk_help + ) +): console.rule(settings.CLI.UNINSTALL.rule) try: with console.status(settings.CLI.UNINSTALL.status, spinner='moon'): - uninstall() + uninstall(uninstall_specialk) console.print(settings.CLI.UNINSTALL.finish) console.print(settings.CLI.thanks, justify='center') @@ -33,6 +42,23 @@ def uninstall_command(): console.print_exception(show_locals=True) -def uninstall(): - copy_folder(backup_path, nier_data_path) +def uninstall( + uninstall_specialk: bool +): + if uninstall_specialk: + files_to_delete['\\'] = settings.FILES.specialk_files + + if not has_folder(backup_path): + raise Exception() + + copy_folder(backup_path, nier_path) + delete_files() remove(backup_path) + write_flag_installed(False) + + +def delete_files(): + for path, files in files_to_delete.items(): + for file in files: + with contextlib.suppress(ValueError): + remove(f'{nier_path}\\{path}\\{file}') diff --git a/src/commands/translation_manager/update.py b/src/commands/translation_manager/update.py deleted file mode 100644 index 619e5fc..0000000 --- a/src/commands/translation_manager/update.py +++ /dev/null @@ -1,56 +0,0 @@ -import requests -import typer -from rich.console import Console -from contextlib import suppress - -from config import settings, ROOT_DIR -from src.utils import remove, unzip_file, copy_folder, make_dir, download_file -from src.miscellaneous import update_commit_sha - - -console = Console() -app = typer.Typer(help=settings.TYPER.UPDATE.help) - -nier_path = settings.PATHS.nier_replicant_path -nier_data_path = f'{nier_path}\\data' -patch_data_path = f'{ROOT_DIR}\\{settings.DEFAULT_PATHS.patch_data}' -data_files_urls = settings.GITHUB.data_files_urls - - -@app.command( - 'update', - help=settings.TYPER.UPDATE.help -) -def update_command( - do_download: bool = typer.Option( - True, - '--local', - help=settings.TYPER.UPDATE.do_download_help - ) -): - console.rule(settings.CLI.UPDATE.rule) - - try: - with console.status(settings.CLI.UPDATE.status, spinner='moon'): - update(do_download) - - console.print(settings.CLI.UPDATE.finish) - console.print(settings.CLI.thanks, justify='center') - except Exception: - console.print(settings.CLI.UPDATE.failed) - console.print_exception(show_locals=True) - - -def update(do_download=True): - if do_download: - download_updated_data() - update_commit_sha() - - copy_folder(patch_data_path, nier_data_path) - - -def download_updated_data(): - for file_url in data_files_urls: - download_file(file_url, patch_data_path) - - console.print(settings.CLI.UPDATE.download_finished) diff --git a/src/miscellaneous/__init__.py b/src/miscellaneous/__init__.py index 297fcc5..8393027 100644 --- a/src/miscellaneous/__init__.py +++ b/src/miscellaneous/__init__.py @@ -1,2 +1,3 @@ from .github import * from .nier_path import * +from .translation import * diff --git a/src/miscellaneous/nier_path.py b/src/miscellaneous/nier_path.py index df0f896..e8dcc3d 100644 --- a/src/miscellaneous/nier_path.py +++ b/src/miscellaneous/nier_path.py @@ -4,11 +4,18 @@ from config import settings, ROOT_DIR from src.utils import get_all_files_from_path +from string import ascii_lowercase as alc console = Console() tomls = settings.DEFAULT_PATHS.tomls +secrets_file_name = settings.FILES.secrets_file_name + files_required_checkout = settings.FILES.required_checkout +special_k_files_checkout = settings.FILES.specialk_files + +nier_folder_name = settings.FOLDERS.nier_folder_name +nier_possible_paths = settings.DEFAULT_PATHS.nier_possible_paths def check_nier_path(): @@ -16,10 +23,15 @@ def check_nier_path(): if not is_a_nier_path(settings.PATHS.nier_replicant_path): raise Exception() except (Exception, BoxKeyError): - update_nier_path() + nier_path = find_nier_path() + + if nier_path: + write_nier_path(nier_path) + else: + input_nier_path() -def update_nier_path(): +def input_nier_path(): console.print(settings.CLI.NIERPATH.not_found) while True: @@ -45,12 +57,29 @@ def write_nier_path(path): } } - write(F'{ROOT_DIR}\\{tomls}\\.secrets.toml', obj, merge=True) + write(F'{ROOT_DIR}\\{tomls}\\{secrets_file_name}', obj, merge=True) settings.update(obj) return obj +def find_nier_path(): + for volume in alc: + for possible_path in nier_possible_paths: + full_path = f'{volume.upper()}:\\{possible_path}\\{nier_folder_name}' + + if is_a_nier_path(full_path): + return full_path + + return None + + +def has_special_k(path): + files = get_all_files_from_path(path) + files = [file.split('\\')[-1] for file in files] + return set(special_k_files_checkout).issubset(set(files)) + + def is_a_nier_path(path): files = get_all_files_from_path(path) files = [file.split('\\')[-1] for file in files] diff --git a/src/miscellaneous/translation.py b/src/miscellaneous/translation.py new file mode 100644 index 0000000..a49bb29 --- /dev/null +++ b/src/miscellaneous/translation.py @@ -0,0 +1,27 @@ +import toml +from config import settings + + +translation_toml_file = settings.FILES.translation_toml_file + + +def has_installed_translation(): + nier_path = settings.PATHS.nier_replicant_path + + try: + with open(f'{nier_path}\\{translation_toml_file}', 'r') as file: + return toml.load(file)['FLAGS']['installed'] + + except (Exception) as e: + return False + + +def write_flag_installed(flag: bool): + nier_path = settings.PATHS.nier_replicant_path + + with open(f'{nier_path}\\{translation_toml_file}', 'w+') as file: + toml.dump({ + 'FLAGS': { + 'installed': flag + } + }, file) diff --git a/src/translator_engine/chat_gpt_translator.py b/src/translator_engine/chat_gpt_translator.py index 69c9897..23c3ed4 100644 --- a/src/translator_engine/chat_gpt_translator.py +++ b/src/translator_engine/chat_gpt_translator.py @@ -38,7 +38,7 @@ async def _translate_single_file(self, file_path, df, columns_to_translate): bar.next() df_temp = update_df_with_translation(df, column, translated_phrases_column) - save_df(df_temp, f'{ROOT_DIR}\\{settings.DEFAULT_PATHS.tmp}\\{file_name}') + save_df(df_temp, f'{ROOT_DIR}\\{settings.FOLDERS.tmp_folder_name}\\{file_name}') df = update_df_with_translation(df, column, translated_phrases_column) save_df(df, file_path, True) diff --git a/src/utils/http_request_utils.py b/src/utils/http_request_utils.py index b4af0fc..38817c1 100644 --- a/src/utils/http_request_utils.py +++ b/src/utils/http_request_utils.py @@ -15,3 +15,6 @@ def download_file(url: str, dest_path: str): for chunk in response.iter_content(chunk_size=8192): if chunk: file.write(chunk) + + + return f'{dest_path}\\{file_name}' diff --git a/src/utils/path_utils.py b/src/utils/path_utils.py index 1323d5e..37abfde 100644 --- a/src/utils/path_utils.py +++ b/src/utils/path_utils.py @@ -73,7 +73,7 @@ def make_dir(path): def copy_file(file_path, dest_path): - shutil.copy(file_path, dest_path) + return shutil.copy(file_path, dest_path) def copy_files(files_path, dest_path): diff --git a/src/utils/zip_utils.py b/src/utils/zip_utils.py index 46acbb8..eea866d 100644 --- a/src/utils/zip_utils.py +++ b/src/utils/zip_utils.py @@ -1,10 +1,24 @@ import zipfile +import os from src.utils import has_file, has_folder def check_and_extract_zip(zip_file, extract_path): if not has_folder(zip_file[0:-4]): unzip_file(zip_file, extract_path) + + +def zip_folder(zip_name, folder_path, destination_path): + zip_full_path = os.path.join(destination_path, zip_name) + + with zipfile.ZipFile(zip_full_path, 'w', zipfile.ZIP_DEFLATED) as zip_ref: + for folder_name, subfolders, filenames in os.walk(folder_path): + for filename in filenames: + file_path = os.path.join(folder_name, filename) + arcname = os.path.relpath(file_path, folder_path) + zip_ref.write(file_path, arcname=arcname) + + return zip_full_path def unzip_file(zip_file_path, extract_path):