From 8e3ef4c43a6bd8d7ada321a1eab18ebad7eec653 Mon Sep 17 00:00:00 2001 From: Skrepysh Date: Sat, 14 Oct 2023 23:35:12 +0300 Subject: [PATCH] v2.22 Updated program to version 2.22 --- main.py | 5 ++-- minesquid.py | 76 +++++++++++++++++++++++++++++++++++----------------- version.txt | 2 +- 3 files changed, 55 insertions(+), 28 deletions(-) diff --git a/main.py b/main.py index af40469..b9d6207 100644 --- a/main.py +++ b/main.py @@ -19,10 +19,9 @@ group1.add_argument("--restore", default=0, nargs='?', const=1, help="используйте --restore, чтобы восстановить бэкап") args = parser.parse_args() -program_version = "2.21" +program_version = "2.22" ok = MineSquid(program_version) logging = ok.logging - while True: try: ok.setup_logger() @@ -33,7 +32,7 @@ logging.info(f'Путь к программе: {ok.program_directory}') logging.info(f'Путь к игре: {ok.game_directory}') logging.info(f'Путь к папке с пользовательскими данными: {ok.userappdata}') - if (int(args.mpnum) != 0 and int(args.mpnum) > 0) and int(args.mpnum) < len(ok.list) - 1: + if (int(args.mpnum) != 0 and int(args.mpnum) > 0) and int(args.mpnum) < len(ok.list)+1: ok.load_modpack(modpack_number=(int(args.mpnum) - 1)) elif str(args.mpname) in ok.list: ok.load_modpack(modpack_number=ok.list.index(args.mpname)) diff --git a/minesquid.py b/minesquid.py index 93091e8..8fca02b 100644 --- a/minesquid.py +++ b/minesquid.py @@ -3,7 +3,7 @@ import logging import os from sys import exit, argv -from shutil import rmtree, copytree +from shutil import rmtree, copy from time import sleep from progress.bar import Bar from datetime import datetime @@ -23,6 +23,7 @@ class Restart(Exception): class MineSquid: def __init__(self, version): + self.username = os.getlogin() self.dt = datetime.now() self.user_choice = "" self.list = [] @@ -78,7 +79,8 @@ def read_config(self): self.repair_config() raise Restart self.config.read(f"{self.userappdata}\\config.ini") - game_directory = self.config["paths"]["game_path"].replace('"', '').replace('/', '\\') + game_directory = self.config['options']['game_path'].replace('"', '').replace('/', '\\') + custom_username = self.config['options']['custom_username'] logging.info("Конфиг прочитан") if game_directory == "default" and os.path.exists(f'{os.environ["appdata"]}\\.minecraft'): self.game_directory = f'{os.environ["appdata"]}\\.minecraft' @@ -86,6 +88,10 @@ def read_config(self): self.game_directory = game_directory else: pass + if custom_username == 'default': + pass + else: + self.username = custom_username logging.info("Конфиг обработан") def checker(self): @@ -123,7 +129,7 @@ def checker(self): def ui(self): logging.info("UI запущен") - print(f"Привет, {os.getlogin()}!") + print(f"Привет, {self.username}!") print("Версия программы: " + self.version) print(f'Путь к папке с игрой: {self.game_directory}') print("Список модпаков: ") @@ -177,13 +183,13 @@ def build_list(self): os.chdir(f"{self.userappdata}\\modpacks") self.list = [e for e in os.listdir() if os.path.isdir(e)] else: - self.list = ["Папка с игрой не назначена", "Модпаки недоступны"] + self.list = ["Папка с игрой не назначена", "Модпаки недоступны", "Для выбора папки введите set"] logging.info("Составлен список модпаков") def edit_config(self): logging.info('Запущен edit_config') logging.info("Начато редактирование config файла") - self.config.set("paths", "game_path", self.enter_path()) + self.config.set("options", "game_path", self.enter_path()) with open(f"{self.userappdata}\\config.ini", "w") as f: self.config.write(f) logging.info('Конфиг отредактирован успешно') @@ -195,8 +201,9 @@ def repair_config(self): else: pass with open(f"{self.userappdata}\\config.ini", "w") as cfg: - self.config.add_section("paths") - self.config.set("paths", "game_path", "default") + self.config.add_section("options") + self.config.set("options", "game_path", "default") + self.config.set("options", "custom_username", "default") self.config.write(cfg) self.edit_config() logging.info('Конфиг восстановлен') @@ -204,24 +211,33 @@ def repair_config(self): def load_modpack(self, modpack_number): if self.game_directory != 'не назначена': self.user_choice = self.list[modpack_number] + fileslist1 = os.listdir(f"{self.userappdata}\\modpacks\\{self.user_choice}") + fileslist2 = os.listdir(f"{self.game_directory}\\mods") print("Выбрана версия " + self.user_choice) print("работаю..") logging.info("Начата работа над модпаком...") - pb1 = Bar("Выполнение", max=4, fill='@') - rmtree(f"{self.userappdata}\\backup") + pb1 = Bar("Резервное коп-е", max=len(fileslist2), fill='@') + for file in os.listdir(f'{self.userappdata}\\backup'): + os.remove(f'{self.userappdata}\\backup\\{file}') logging.info("Удален текущий бэкап") - pb1.next() - copytree(f"{self.game_directory}\\mods", f"{self.userappdata}\\backup") + for file in fileslist2: + copy(src=f"{self.game_directory}\\mods\\{file}", dst=f"{self.userappdata}\\backup") + pb1.next() logging.info("Сделан бэкап текущих модов") - pb1.next() - rmtree(f"{self.game_directory}\\mods") - logging.info("Папка mods удалена") - pb1.next() - copytree(f"{self.userappdata}\\modpacks\\{self.user_choice}", f"{self.game_directory}\\mods\\") + pb1.finish() + pb2 = Bar("Выполнение", max=len(fileslist1)+1, fill='@') + for file in os.listdir(f"{self.game_directory}\\mods\\"): + os.remove(f"{self.game_directory}\\mods\\{file}") + logging.info("Папка mods очищена") + pb2.next() + for file in fileslist1: + copy(src=f"{self.userappdata}\\modpacks\\{self.user_choice}\\{file}", + dst=f"{self.game_directory}\\mods") + pb2.next() + # copytree(f"{self.userappdata}\\modpacks\\{self.user_choice}", f"{self.game_directory}\\mods\\") logging.info("Модпак скопирован в папку mods") logging.info("ГОТОВО!") - pb1.next() - pb1.finish() + pb2.finish() print("готово") self.finish() else: @@ -236,19 +252,31 @@ def restore_backup(self): sleep(1) raise Restart else: + fileslist = os.listdir(f"{self.game_directory}\\mods") + fileslist2 = os.listdir(f'{self.userappdata}\\backup') bob = False logging.info("Пользователь запустил восстановление бэкапа") - pb2 = Bar("Восстановление", max=3, fill='@') if os.path.exists(f"{self.game_directory}\\mods"): - pb2.next() + pb1 = Bar("Резервное коп-е", max=len(fileslist), fill='@') bob = True - copytree(f"{self.game_directory}\\mods", f"{self.userappdata}\\bob", dirs_exist_ok=True) + if not os.path.exists(f"{self.userappdata}\\bob\\"): + os.mkdir(f"{self.userappdata}\\bob\\") + # copytree(f"{self.game_directory}\\mods", f"{self.userappdata}\\bob", dirs_exist_ok=True) + for file in fileslist: + copy(f"{self.game_directory}\\mods\\{file}", f"{self.userappdata}\\bob\\") + pb1.next() logging.info("Бэкап сделан перед восстановлением бэкапа)") - rmtree(f"{self.game_directory}\\mods") - logging.info("Папка mods удалена") + for file in os.listdir(f'{self.game_directory}\\mods'): + os.remove(f'{self.game_directory}\\mods\\{file}') + logging.info("Папка mods очищена") + pb1.finish() else: + pass + pb2 = Bar('Восстановление', max=len(fileslist2)+2, fill='@') + for file in fileslist2: + copy(f'{self.userappdata}\\backup\\{file}', f'{self.game_directory}\\mods') pb2.next() - copytree(f"{self.userappdata}\\backup", f"{self.game_directory}\\mods\\") + # copytree(f"{self.userappdata}\\backup", f"{self.game_directory}\\mods\\") pb2.next() if bob: rmtree(f"{self.userappdata}\\backup") diff --git a/version.txt b/version.txt index 301843e..72ee782 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -2.21 \ No newline at end of file +2.22 \ No newline at end of file