Пример #1
0
    def collection_append(self, mod_name, mod_id, hash_key=None):
        """
                    Функция находит все переводимые файлы выбранной модификации,
                    создает для каждого временную папку в Коллекции
                    и сохраняет данные в базу данных
        """
        mod_path = get_mods_from_playset('get_mod_path', mod_name)[0][0].replace('/', '\\')
        images = get_info_from_db('get_images', ())
        for image_data in images:
            if image_data[2] == mod_id:
                hash_key = image_data[0]
                break
        archive = [file for file in listdir(mod_path) if '.zip' in file]
        if archive:
            open_zip_file(f'{mod_path}\\{archive[0]}')

        try:
            for file_path in scan_for_files(mod_path):
                parser_main(mod_path, mod_id, file_path)
                collection_append(mod_id, hash_key, mod_name)
            message = 'files_was_added'
            call_success_message(self, message)
            self.findChild(QtWidgets.QDialog).close()
            self.close()

        except FileNotFoundError:
            message = 'files_not_found'
            call_error_message(self, message)
            self.findChild(QtWidgets.QDialog).close()

        if archive:
            remove_unpacked_files(mod_path)
Пример #2
0
 def set_translation_language(self, translation_language):
     with open("Properties.json", 'r', encoding='utf-8') as prop:
         properties = load(prop)
         properties["tool_language"] = translation_language
     with open("Properties.json", 'w', encoding='utf-8') as prop:
         dump(properties, prop)
     message = 'language_was_changed'
     call_success_message(self, message)
     self.close()
Пример #3
0
    def update_localisation_using_chosen_file(self, localisation_file):
        chosen_file_path = QtWidgets.QFileDialog.getOpenFileName(
            directory=f'{drive}:\\Users\\{user}\\Desktop')[0]

        if chosen_file_path and chosen_file_path.split(
                '.')[-1] in '.txt.yml.yaml':
            log = update_translation((chosen_file_path, localisation_file),
                                     'external_way')

            if log is not False:
                call_success_message(self, 'file_was_updated')
                self.paint_elements()
        else:  # If file choosing was canceled
            call_error_message(self, 'invalid_file')

        self.findChild(QtWidgets.QDialog).close()
Пример #4
0
 def make_sort(self):
     for mod in self.modList:
         mod.isEnabled = mod.checkboxes[0][0].isChecked()
         mod.sortRequired = mod.checkboxes[0][1].isChecked()
     try:
         status = sorting(self.modList, self.game_data, self.dlc_load, self.playset,
                          self.ReverseSortingButton.isChecked())
         if status in 'mods_was_sorted':
             message = status
             call_success_message(self, message)
         else:
             message = status
             call_error_message(self, message)
     except FileNotFoundError as error:
         message = 'FileNotFoundError'
         self.message = error.args[0]
         call_error_message(self, message)
     self.update_mod_list()
Пример #5
0
    def save_localisation(self):
        try:
            self.file.tr_status = round((self.bar[0].value() / self.bar[0].maximum()) * 100) \
                                    if self.bar[0].value() != self.bar[0].maximum() \
                                    else 100    # meaning it's Complete
            self.file.pointer_pos = self.pointer
            collection_update(self.file, self.machine_text, self.user_text)

            message = 'file_was_updated'
            call_success_message(self, message)

            if self.file.tr_status == 100:
                put_lines(self.file)
                pop_stack()

            self.clean_state()

        except AttributeError:
            message = 'no_translation'
            call_error_message(self, message)
Пример #6
0
    def compare(self):
        if not self.files:
            self.message = 'Вы не выбрали файлы'
            call_error_message(self, 'files_not_choosen')
            return False
        try:
            old_tr_file_path = self.files['ChooseOldTrFileButton']
            new_ver_file_path = self.files['ChooseNewVerFileButton']

            if old_tr_file_path.split('.')[-1] == new_ver_file_path.split('.')[-1]:
                update_lines(old_tr_file_path, new_ver_file_path)
                # self.close()
            else:
                raise KeyError

        except KeyError:
            self.clean_state()
            call_error_message(self, 'files_not_choosen')
        else:
            call_success_message(self, 'files_was_compared')
            self.close()
Пример #7
0
    def update_localisation_files_version(self, localisation_files):
        localisation_files = copy(localisation_files)
        mod_path = get_mods_from_playset(
            'get_mod_path',
            localisation_files[0].mod_name)[0][0].replace('/', '\\')
        mod_properties, files_for_compare = localisation_files[0], []
        start, new_files, log = False, False, False

        archive = [file for file in listdir(mod_path) if '.zip' in file]
        if archive:
            open_zip_file(f'{mod_path}\\{archive[0]}')

        original_files = scan_for_files(mod_path)
        for original_file_path in copy(original_files):
            for localisation_file in localisation_files:
                localisation_file_path = localisation_file.original_file_path.rsplit(
                    '\\', 2)
                del localisation_file_path[-2]
                localisation_file_path = '\\'.join(localisation_file_path)
                if original_file_path in localisation_file_path:
                    files_for_compare.append(
                        (f'{mod_path}\\{original_file_path}',
                         localisation_file))
                    original_files.remove(original_file_path)
                    localisation_files.remove(localisation_file)
                    break

        for files_pair in files_for_compare:
            log = update_translation(files_pair, 'internal_way')

            if start is False and log is not False:
                start = True

        if original_files:
            # На случай, если в локализации отсутствуют актуальные для мода файлы
            start, new_files = True, True
            for original_file_path in original_files:
                parser_main(mod_path, mod_properties.mod_id,
                            original_file_path)
                collection_append(mod_properties.mod_id,
                                  mod_properties.hash_key,
                                  mod_properties.mod_name)
        if localisation_files:
            # На случай, если в локализации имеются неактуальные для мода файлы
            start, new_files = True, True
            for localisation_file in localisation_files:
                remove_data_from_collection(
                    collection_path, (localisation_file.original_file_path, ),
                    'file')
                rmtree(
                    localisation_file.original_file_path.rsplit('\\',
                                                                1)[0].replace(
                                                                    '\\', '/'))
        if archive:
            remove_unpacked_files(mod_path)
        self.findChild(QtWidgets.QDialog).close()

        if start is True:
            call_success_message(self, 'mod_was_updated')
            if new_files:
                self.collection = get_collection_data()
            self.paint_elements()
        else:
            call_success_message(self, 'all_files_are_up_to_date')