Beispiel #1
0
def extract_data(json_path, json_filename):
    data = {
        "main_file": json_filename
    }
    # get json file
    if os.path.isfile(json_path):
        with open(json_path, "r") as f:
            data[json_filename] = f.read()
            f.close()
        os.remove(json_path)
        print("Removed temporary " + json_path)

    # get binaries and resources
    if json_filename in data:
        json_parsed = json.loads(data[json_filename])
        if "binaries" in json_parsed:
            for i in range(len(json_parsed["binaries"])):
                relpath = json_parsed["binaries"][i]["binfile"]
                if relpath is not None:
                    fullpath = os.path.normpath(os.path.join(\
                            os.path.dirname(json_path), relpath))
                    data[relpath] = get_encoded_binfile(fullpath)
                    os.remove(fullpath)
                    print("Removed temporary " + fullpath)

        if "images" in json_parsed:
            unpacked_img_paths = exporter.get_unpacked_img_paths()

            for i in range(len(json_parsed["images"])):
                img = json_parsed["images"][i]
                if img["source"] == "FILE":
                    fullpath = os.path.normpath(os.path.join(\
                            os.path.dirname(json_path), img["filepath"]))
                    data[img["filepath"]] = get_encoded_binfile(fullpath)

                    # remove odd unpacked image files, comparing absolute paths
                    if fullpath in unpacked_img_paths:
                        os.remove(fullpath)

        if "sounds" in json_parsed:
            for i in range(len(json_parsed["sounds"])):
                snd = json_parsed["sounds"][i]
                fullpath = os.path.normpath(os.path.join(\
                        os.path.dirname(json_path), snd["filepath"]))
                data[snd["filepath"]] = get_encoded_binfile(fullpath)
    return data
Beispiel #2
0
def clean_exported_data():
    unpacked_img_paths = exporter.get_unpacked_img_paths()
    for path in unpacked_img_paths:
        os.remove(path)