mirror of
https://github.com/RedDeadDepresso/KKAFIO.git
synced 2026-02-22 06:12:31 +00:00
added files
This commit is contained in:
0
modules/__init__.py
Normal file
0
modules/__init__.py
Normal file
26
modules/create_backup.py
Normal file
26
modules/create_backup.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import os
|
||||
|
||||
class CreateBackup:
|
||||
def __init__(self, config, file_manager):
|
||||
"""Initializes the Bounty module.
|
||||
|
||||
Args:
|
||||
config (Config): BAAuto Config instance
|
||||
"""
|
||||
self.config = config
|
||||
self.file_manager = file_manager
|
||||
self.backup_folders = self.config.create_backup["GameFolders"]
|
||||
self.filename = self.config.create_backup["Filename"]
|
||||
self.output_path = self.config.create_backup["OutputPath"]
|
||||
self.game_path = self.config.game_path
|
||||
|
||||
def logic_wrapper(self):
|
||||
selected_folders = [self.game_path[folder] for folder in self.backup_folders if self.backup_folders[folder]]
|
||||
output_path = os.path.join(self.output_path, self.filename)
|
||||
self.file_manager.create_archive(selected_folders, output_path)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
186
modules/example.py
Normal file
186
modules/example.py
Normal file
@@ -0,0 +1,186 @@
|
||||
import os
|
||||
import re as regex
|
||||
import codecs
|
||||
import shutil
|
||||
import tkinter
|
||||
from tkinter import Tk, filedialog, messagebox, ttk
|
||||
|
||||
path = os.getcwd()
|
||||
png_list = []
|
||||
png_count = 0
|
||||
kks_card_list = []
|
||||
kks_folder = "_KKS_card_"
|
||||
kks_folder2 = "_KKS_to_KK_"
|
||||
do_convert_default = True
|
||||
|
||||
|
||||
def get_list(folder_path):
|
||||
new_list = []
|
||||
for (_, _, files) in os.walk(folder_path):
|
||||
for filename in files:
|
||||
if regex.match(r".*(\.png)$", filename):
|
||||
new_list.append(filename)
|
||||
return new_list
|
||||
|
||||
|
||||
def check_png(card_path):
|
||||
with codecs.open(card_path, "rb") as card:
|
||||
data = card.read()
|
||||
card_type = 0
|
||||
if data.find(b"KoiKatuChara") != -1:
|
||||
card_type = 1
|
||||
if data.find(b"KoiKatuCharaSP") != -1:
|
||||
card_type = 2
|
||||
elif data.find(b"KoiKatuCharaSun") != -1:
|
||||
card_type = 3
|
||||
print(f"[{card_type}] {card_path}")
|
||||
return card_type
|
||||
|
||||
|
||||
def do_convert_check_event():
|
||||
print(f"convert = {do_convert.get()}")
|
||||
|
||||
|
||||
def convert_kk(card_name, card_path, destination_path):
|
||||
with codecs.open(card_path, mode="rb") as card:
|
||||
data = card.read()
|
||||
|
||||
replace_list = [
|
||||
[b"\x15\xe3\x80\x90KoiKatuCharaSun", b"\x12\xe3\x80\x90KoiKatuChara"],
|
||||
[b"Parameter\xa7version\xa50.0.6", b"Parameter\xa7version\xa50.0.5"],
|
||||
[b"version\xa50.0.6\xa3sex", b"version\xa50.0.5\xa3sex"],
|
||||
]
|
||||
|
||||
for text in replace_list:
|
||||
data = data.replace(text[0], text[1])
|
||||
|
||||
new_file_path = os.path.normpath(os.path.join(destination_path, f"KKS2KK_{card_name}"))
|
||||
# print(f"new_file_path {new_file_path}")
|
||||
|
||||
with codecs.open(new_file_path, "wb") as new_card:
|
||||
new_card.write(data)
|
||||
|
||||
|
||||
def c_get_list():
|
||||
global path, png_list, png_count, png_count_t
|
||||
b_sel['state'] = 'disabled'
|
||||
path = filedialog.askdirectory(title="Select target path (folder contain cards)", mustexist=True)
|
||||
|
||||
if path:
|
||||
print(f"path: {path}")
|
||||
os.chdir(path)
|
||||
else:
|
||||
print("no path")
|
||||
b_sel['state'] = 'normal'
|
||||
return
|
||||
|
||||
png_list = get_list(path)
|
||||
png_count = len(png_list)
|
||||
png_count_t.set(f"png found: {png_count}")
|
||||
|
||||
if png_count > 0:
|
||||
b_p['state'] = 'normal'
|
||||
else:
|
||||
b_p['state'] = 'disabled'
|
||||
|
||||
b_sel['state'] = 'normal'
|
||||
|
||||
|
||||
def process_png():
|
||||
global path, png_list, kks_folder, kks_folder2, kks_card_list, window, png_count, png_count_t
|
||||
|
||||
count = len(png_list)
|
||||
if count > 0:
|
||||
bar = ttk.Progressbar(window, maximum=count, length=250)
|
||||
bar.pack(pady=10)
|
||||
bar_val = 0
|
||||
print("0: unknown / 1: kk / 2: kksp / 3: kks")
|
||||
for png in png_list:
|
||||
if check_png(png) == 3:
|
||||
kks_card_list.append(png)
|
||||
bar_val = bar_val + 1
|
||||
bar['value'] = bar_val
|
||||
window.update()
|
||||
bar.destroy()
|
||||
else:
|
||||
messagebox.showinfo("Done", f"no PNG found")
|
||||
return
|
||||
|
||||
count = len(kks_card_list)
|
||||
if count > 0:
|
||||
print(kks_card_list)
|
||||
|
||||
target_folder = os.path.normpath(os.path.join(path, kks_folder))
|
||||
target_folder2 = os.path.normpath(os.path.join(path, kks_folder2))
|
||||
if not os.path.isdir(target_folder):
|
||||
os.mkdir(kks_folder)
|
||||
|
||||
is_convert = do_convert.get()
|
||||
if is_convert:
|
||||
print(f"do convert is [{is_convert}]")
|
||||
if not os.path.isdir(target_folder2):
|
||||
os.mkdir(target_folder2)
|
||||
|
||||
for card in kks_card_list:
|
||||
source = os.path.normpath(os.path.join(path, card))
|
||||
target = os.path.normpath(os.path.join(target_folder, card))
|
||||
|
||||
# copy & convert before move
|
||||
if is_convert:
|
||||
convert_kk(card, source, target_folder2)
|
||||
|
||||
# move file
|
||||
shutil.move(source, target)
|
||||
|
||||
if is_convert:
|
||||
messagebox.showinfo("Done", f"[{count}] cards\nmove to [{kks_folder}] folder\nconvert and save to [{kks_folder2}] folder")
|
||||
else:
|
||||
messagebox.showinfo("Done", f"[{count}] cards\nmove to [{kks_folder}] folder")
|
||||
else:
|
||||
messagebox.showinfo("Done", f"no KKS card found")
|
||||
|
||||
# reset
|
||||
png_list = []
|
||||
kks_card_list = []
|
||||
png_count = 0
|
||||
png_count_t.set(f"png found: 0")
|
||||
b_p['state'] = 'disabled'
|
||||
|
||||
|
||||
window = Tk()
|
||||
# window.withdraw()
|
||||
window.title("KKSCF")
|
||||
w = 300
|
||||
h = 350
|
||||
ltx = int((window.winfo_screenwidth() - w) / 2)
|
||||
lty = int((window.winfo_screenheight() - h) / 2)
|
||||
window.geometry(f'{w}x{h}+{ltx}+{lty}')
|
||||
|
||||
tkinter.Label(window, text=" ", pady=5).pack()
|
||||
|
||||
b_sel = tkinter.Button(window, text="Select folder contain cards", padx=10, pady=10, relief="raised", bd=3, command=c_get_list)
|
||||
b_sel.pack()
|
||||
|
||||
tkinter.Label(window, text=" ", pady=5).pack()
|
||||
|
||||
png_count_t = tkinter.StringVar()
|
||||
png_count_t.set(f"png found: {png_count}")
|
||||
tkinter.Label(window, textvariable=png_count_t, pady=10).pack()
|
||||
|
||||
tkinter.Label(window, text=" ", pady=5).pack()
|
||||
|
||||
do_convert = tkinter.BooleanVar()
|
||||
do_convert.set(do_convert_default)
|
||||
do_convert_check = tkinter.Checkbutton(window, text='copy & convert KKS to KK', variable=do_convert, command=do_convert_check_event)
|
||||
do_convert_check.pack()
|
||||
|
||||
tkinter.Label(window, text=" ", pady=5).pack()
|
||||
|
||||
b_p = tkinter.Button(window, text="Process", relief="raised", padx=10, pady=10, bd=3, command=process_png)
|
||||
b_p.pack()
|
||||
b_p['state'] = 'disabled'
|
||||
|
||||
tkinter.Label(window, text=" ", pady=5).pack()
|
||||
|
||||
window.mainloop()
|
||||
exit(0)
|
||||
107
modules/fc_kks.py
Normal file
107
modules/fc_kks.py
Normal file
@@ -0,0 +1,107 @@
|
||||
import os
|
||||
import re as regex
|
||||
import codecs
|
||||
import shutil
|
||||
from util.logger import Logger
|
||||
|
||||
class FilterConvertKKS:
|
||||
def __init__(self, config, file_manager):
|
||||
"""Initializes the Bounty module.
|
||||
|
||||
Args:
|
||||
config (Config): BAAuto Config instance
|
||||
"""
|
||||
self.config = config
|
||||
self.file_manager = file_manager
|
||||
self.convert = self.config.fc_kks["Convert"]
|
||||
|
||||
def get_list(self, folder_path):
|
||||
new_list = []
|
||||
for root, dirs, files in os.walk(folder_path):
|
||||
for filename in files:
|
||||
if regex.match(r".*(\.png)$", filename):
|
||||
new_list.append(os.path.join(root, filename))
|
||||
return new_list
|
||||
|
||||
def check_png(self, card_path):
|
||||
with codecs.open(card_path, "rb") as card:
|
||||
data = card.read()
|
||||
card_type = 0
|
||||
if data.find(b"KoiKatuChara") != -1:
|
||||
card_type = 1
|
||||
if data.find(b"KoiKatuCharaSP") != -1:
|
||||
card_type = 2
|
||||
elif data.find(b"KoiKatuCharaSun") != -1:
|
||||
card_type = 3
|
||||
Logger.log_info(f"[{card_type}]", f"{card_path}")
|
||||
return card_type
|
||||
|
||||
def convert_kk(self, card_name, card_path, destination_path):
|
||||
with codecs.open(card_path, mode="rb") as card:
|
||||
data = card.read()
|
||||
|
||||
replace_list = [
|
||||
[b"\x15\xe3\x80\x90KoiKatuCharaSun", b"\x12\xe3\x80\x90KoiKatuChara"],
|
||||
[b"Parameter\xa7version\xa50.0.6", b"Parameter\xa7version\xa50.0.5"],
|
||||
[b"version\xa50.0.6\xa3sex", b"version\xa50.0.5\xa3sex"],
|
||||
]
|
||||
|
||||
for text in replace_list:
|
||||
data = data.replace(text[0], text[1])
|
||||
|
||||
new_file_path = os.path.normpath(os.path.join(destination_path, f"KKS2KK_{card_name}"))
|
||||
# print(f"new_file_path {new_file_path}")
|
||||
|
||||
with codecs.open(new_file_path, "wb") as new_card:
|
||||
new_card.write(data)
|
||||
|
||||
def logic_wrapper(self):
|
||||
path = self.config.fc_kks["InputPath"]
|
||||
kks_card_list = []
|
||||
kks_folder = "_KKS_card_"
|
||||
kks_folder2 = "_KKS_to_KK_"
|
||||
|
||||
png_list = self.get_list(path)
|
||||
|
||||
count = len(png_list)
|
||||
if count > 0:
|
||||
Logger.log_info("SCRIPT", "0: unknown / 1: kk / 2: kksp / 3: kks")
|
||||
for png in png_list:
|
||||
if self.check_png(png) == 3:
|
||||
kks_card_list.append(png)
|
||||
else:
|
||||
Logger.log_success("SCRIPT", f"no PNG found")
|
||||
return
|
||||
|
||||
count = len(kks_card_list)
|
||||
if count > 0:
|
||||
print(kks_card_list)
|
||||
|
||||
target_folder = os.path.normpath(os.path.join(path, kks_folder))
|
||||
target_folder2 = os.path.normpath(os.path.join(path, kks_folder2))
|
||||
if not os.path.isdir(target_folder):
|
||||
os.mkdir(target_folder)
|
||||
|
||||
if self.convert:
|
||||
Logger.log_info("SCRIPT", f"Conversion to KK is [{self.convert}]")
|
||||
if not os.path.isdir(target_folder2):
|
||||
os.mkdir(target_folder2)
|
||||
|
||||
for card_path in kks_card_list:
|
||||
source = card_path
|
||||
card = os.path.basename(card_path)
|
||||
target = os.path.normpath(os.path.join(target_folder, card))
|
||||
|
||||
# copy & convert before move
|
||||
if self.convert:
|
||||
self.convert_kk(card, source, target_folder2)
|
||||
|
||||
# move file
|
||||
shutil.move(source, target)
|
||||
|
||||
if self.convert:
|
||||
Logger.log_success("SCRIPT", f"[{count}] cards moved to [{kks_folder}] folder, converted and save to [{kks_folder2}] folder")
|
||||
else:
|
||||
Logger.log_success("SCRIPT", f"[{count}] cards moved to [{kks_folder}] folder")
|
||||
else:
|
||||
Logger.log_success("SCRIPT", f"no KKS card found")
|
||||
56
modules/install_chara.py
Normal file
56
modules/install_chara.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import os
|
||||
import codecs
|
||||
from util.logger import Logger
|
||||
|
||||
class InstallChara:
|
||||
def __init__(self, config, file_manager):
|
||||
"""Initializes the Bounty module.
|
||||
|
||||
Args:
|
||||
config (Config): BAAuto Config instance
|
||||
"""
|
||||
self.config = config
|
||||
self.file_manager = file_manager
|
||||
self.game_path = self.config.game_path
|
||||
self.input_path = self.config.install_chara["InputPath"]
|
||||
|
||||
def resolve_png(self, image_path):
|
||||
with codecs.open(image_path[0], "rb") as card:
|
||||
data = card.read()
|
||||
if data.find(b"KoiKatuChara") != -1:
|
||||
if data.find(b"KoiKatuCharaSP") != -1 or data.find(b"KoiKatuCharaSun") != -1:
|
||||
basename = os.path.basename(image_path[0])
|
||||
Logger.log_error("CHARA", f"{basename} is a KKS card")
|
||||
return
|
||||
self.file_manager.copy_and_paste("CHARA", image_path, self.game_path["chara"])
|
||||
elif data.find(b"KoiKatuClothes") != -1:
|
||||
self.file_manager.copy_and_paste("COORD",image_path, self.game_path["coordinate"])
|
||||
else:
|
||||
self.file_manager.copy_and_paste("OVERLAYS", image_path, self.game_path["Overlays"])
|
||||
|
||||
def logic_wrapper(self, folder_path=None):
|
||||
if folder_path is None:
|
||||
folder_path = self.input_path
|
||||
foldername = os.path.basename(folder_path)
|
||||
Logger.log_msg("FOLDER", foldername)
|
||||
file_list, compressed_file_list = self.file_manager.find_all_files(folder_path)
|
||||
|
||||
for file in file_list:
|
||||
file_extension = file[2]
|
||||
match file_extension:
|
||||
case ".zipmod":
|
||||
self.file_manager.copy_and_paste("MODS", file, self.game_path["mods"])
|
||||
case ".png":
|
||||
self.resolve_png(file)
|
||||
case _:
|
||||
basename = os.path.basename(file[0])
|
||||
Logger.log_error("UKNOWN", f"Cannot classify {basename}")
|
||||
print("[MSG]")
|
||||
|
||||
for compressed in compressed_file_list:
|
||||
extract_path = self.file_manager.extract_archive(compressed[0])
|
||||
if extract_path is not None:
|
||||
self.logic_wrapper(extract_path)
|
||||
|
||||
|
||||
|
||||
47
modules/remove_chara.py
Normal file
47
modules/remove_chara.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import os
|
||||
import codecs
|
||||
from util.logger import Logger
|
||||
|
||||
class RemoveChara:
|
||||
def __init__(self, config, file_manager):
|
||||
"""Initializes the Bounty module.
|
||||
|
||||
Args:
|
||||
config (Config): BAAuto Config instance
|
||||
"""
|
||||
self.config = config
|
||||
self.file_manager = file_manager
|
||||
self.game_path = self.config.game_path
|
||||
self.input_path = self.config.remove_chara["InputPath"]
|
||||
|
||||
def resolve_png(self, image_path):
|
||||
with codecs.open(image_path[0], "rb") as card:
|
||||
data = card.read()
|
||||
if data.find(b"KoiKatuChara") != -1:
|
||||
if data.find(b"KoiKatuCharaSP") != -1 or data.find(b"KoiKatuCharaSun") != -1:
|
||||
return
|
||||
self.file_manager.find_and_remove("CHARA", image_path, self.game_path["chara"])
|
||||
elif data.find(b"KoiKatuClothes") != -1:
|
||||
self.file_manager.find_and_remove("COORD",image_path, self.game_path["coordinate"])
|
||||
else:
|
||||
self.file_manager.find_and_remove("OVERLAYS", image_path, self.game_path["Overlays"])
|
||||
|
||||
def logic_wrapper(self):
|
||||
foldername = os.path.basename(self.input_path)
|
||||
Logger.log_msg("FOLDER", foldername)
|
||||
file_list, archive_list = self.file_manager.find_all_files(self.input_path)
|
||||
|
||||
for file in file_list:
|
||||
file_extension = file[2]
|
||||
match file_extension:
|
||||
case ".zipmod":
|
||||
self.file_manager.find_and_remove("MODS", file, self.game_path["mods"])
|
||||
case ".png":
|
||||
self.resolve_png(file)
|
||||
case _:
|
||||
pass
|
||||
print("[MSG]")
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user