コード例 #1
0
def save_json(json_full, file):
    content = json.dumps(json_full, sort_keys=True, indent=4).encode("utf-8")
    return pck_tools.save_file(content, file[:file.rfind("/")],
                               file[file.rfind("/") + 1:])
コード例 #2
0
ファイル: locale_to_json.py プロジェクト: iDevLA/pck-tools
from tkinter.filedialog import *

file = None
if len(sys.argv) > 1:
    file = sys.argv[1]
else:
    Tk().withdraw()
    file = askopenfilename(title="Open file...")

if file:
    file = file.replace("\\", "/")
    pck = pck_tools.unpack_pck(file)
    if pck:
        json_full = {
            "name": file[file.rfind("/") + 1:],
            "date": time.strftime("%x"),
            "files": {}
        }
        for pck_file in pck.get_files():
            json_full["files"][pck_file.hash] = pck_file.to_json()
        content = json.dumps(json_full,
                             sort_keys=False,
                             indent=4,
                             ensure_ascii=False).encode("utf-8")
        print(
            pck_tools.save_file(
                content, file[:file.rfind("/")],
                file[file.rfind("/") + 1:file.rfind(".")] + ".json"))
        #pck_tools.clean_up(file)

input()
コード例 #3
0
ファイル: json_to_locale.py プロジェクト: LokiCoder/pck-tools
from tkinter.filedialog import *

file = None
if len(sys.argv) > 1:
    file = sys.argv[1]
else:
    Tk().withdraw()
    file = askopenfilename(title="Open file...")

if file:
    file = file.replace("\\", "/")
    folder = file[:file.rfind(".")]

    jsonFiles = pck_tools.read_json(file)
    pck = pck_struct.Pck(folder, "50434B00CDCCCC3E", len(jsonFiles["files"]),
                         "new en")
    for i, jsonFile in enumerate(jsonFiles["files"]):
        jsonFile = jsonFiles["files"][jsonFile]
        print(jsonFile["hash"])

        newfile = pck_tools.form_dict(jsonFile["dict"], jsonFile["line_type"],
                                      jsonFile["hash"])
        newfile_path = pck_tools.save_file(newfile, folder, "{:08d}".format(i))
        pck.add_file(newfile_path, jsonFile["hash"], 00, 00)

    print("packing locale!!!")
    pck_path = pck_tools.save_file(
        pck_tools.pack_pck(pck), folder[:folder.rfind("/")],
        file[file.rfind("/") + 1:].replace(".json", "") + "_new.pck")
    print(pck_path)
コード例 #4
0
    action = 1
    if args[2] in args_format:
        format = 1

if action is None:
    print('Pick either (-p/--pack) or (-u/--unpack)')
    sys.exit(0)

files = args[2 + format:]
for file in files:
    try:
        file = file.replace('\\', '/')
        if os.path.isfile(file):
            if action == 0:
                pck = pck_tools.from_header(file)
                pck_path = pck_tools.save_file(
                    pck_tools.pack_pck(pck), pck.path,
                    pck.path[pck.path.rfind("/") + 1:] + ".pck")
                print('Packed to: ' + os.path.basename(pck_path))
            elif action == 1:
                pck_tools.clean_up(file)
                pck = pck_tools.unpack_pck(file)
                if format == 1:
                    pck_tools.pck_to_model(pck)
        else:
            print('Skipping non-file: ' + file)
    except Exception as e:
        print("Error at: " + file)
        print(e)
        print(e.args)