Exemplo n.º 1
0
    def load_and_apply_fix(self):
        # pick and load file
        Tk().withdraw()
        file_path = askopenfilename(title="Open fix file...")
        fix_json = pck_tools.read_json(file_path)

        for hash, items in fix_json.items():
            for key, fix in items.items():
                print(key, fix)
                # check fix can be applied
                item = self.get_item(hash + "." + key)
                if item:
                    # delete if action: 0
                    if fix["action"] == 0:
                        self.on_item_remove(item, confirm=False)
                    # move if action: 1
                    if fix["action"] == 1:
                        self.on_item_update(item, fix["hash"], fix["key"],
                                            item.value)
Exemplo n.º 2
0
import json
import time
import pck_tools
from tkinter.filedialog import *

# locale reading
Tk().withdraw()
korean_path = askopenfilename(title="Open korean json file...")
korean_json = pck_tools.read_json(korean_path)

global_path = askopenfilename(title="Open global json file...")
global_json = pck_tools.read_json(global_path)

kr_hash, gb_hash = "f80a001a49cfda65", "f80a001a49cfda65"
korean_skills = korean_json["files"][kr_hash]["dict"]
global_skills = global_json["files"][gb_hash]["dict"]

patch_skills = {
    "name": "patched_skills",
    "date": time.strftime("%x"),
    "files": {
        kr_hash: korean_json["files"][kr_hash]
    }
}
patch_skills_dict = {}

for key, value in korean_skills.items():
    if key in global_skills:
        patch_value = ""
        global_value = global_skills[key]
        for index, global_part in enumerate(global_value.split("\t")):
Exemplo n.º 3
0
    def load_and_apply_patch(self):
        # pick and load file
        Tk().withdraw()
        file_path = askopenfilename(title="Open patch file...")
        patch_json = pck_tools.read_json(file_path)

        # get parameters
        patch_add = messagebox.askyesno("Patch Options", "Add new keys?")
        patch_override = messagebox.askyesno("Patch Options",
                                             "Override existing values?")
        if not patch_override:
            patch_resolve = messagebox.askyesno("Patch Options",
                                                "Resolve conflicts manually?")
        else:
            patch_resolve = False

        # if patch add keys
        if patch_add:
            patch_new_keys = json_manipulator.get_new_keys(
                self.locale_json, patch_json)
            for hash, patch_file in patch_new_keys["files"].items():
                # make sure parent exists
                try:
                    # create group
                    new_group = GroupItem(len(self.main_group.items), hash, {},
                                          1, hash)

                    # add group
                    self.hlist.add(new_group.entry, text=new_group.text)
                    self.main_group.items.append(new_group)
                except Exception:
                    pass
                for key, val in patch_file["dict"].items():
                    # create new item
                    new_item = LineItem(len(self.get_item(hash).items), key,
                                        val, 2)
                    new_item.entry = hash + "." + key
                    new_item.mark_as_changed()

                    # add new item
                    self.hlist.add(new_item.entry,
                                   text=new_item.text,
                                   at=new_item.index,
                                   style=self.changed_style)
                    self.add_item(new_item)
                self.shlist.open(hash)

        # if patch override
        if patch_override:
            patch_new_values = json_manipulator.get_changed_values(
                self.locale_json, patch_json)
            for hash, patch_file in patch_new_values["files"].items():
                for key, val in patch_file["dict"].items():
                    # create new item
                    new_item = LineItem(len(self.get_item(hash).items), key,
                                        val, 2)
                    new_item.entry = hash + "." + key
                    new_item.mark_as_changed()

                    # update item
                    self.hlist.item_configure(new_item.entry,
                                              0,
                                              text=new_item.text)
                    self.set_item(new_item)

                    # update color for changed items
                    self.hlist.item_configure(new_item.entry,
                                              0,
                                              style=self.changed_style)
                self.shlist.open(hash)
        # if patch resolve
        elif patch_resolve:
            patch_new_values = json_manipulator.get_changed_values(
                self.locale_json, patch_json)
            for hash, patch_file in patch_new_values["files"].items():
                for key, val in patch_file["dict"].items():
                    # create new item and get current one
                    new_item = LineItem(len(self.get_item(hash).items), key,
                                        val, 2)
                    new_item.entry = hash + "." + key
                    new_item.mark_as_changed()
                    old_item = self.get_item(new_item.entry)

                    # markup current conflict
                    self.hlist.item_configure(old_item.entry,
                                              0,
                                              style=self.resolving_style)

                    # close all groups and open current
                    self.close_groups()
                    self.shlist.open(hash)
                    self.hlist.see(old_item.entry)

                    # pick which one
                    resolve_choice = messagebox.askyesno(
                        "Update to new value?",
                        old_item.text + "\n=>\n" + new_item.text)
                    if resolve_choice:
                        # update item
                        self.hlist.item_configure(new_item.entry,
                                                  0,
                                                  text=new_item.text)
                        self.set_item(new_item)

                        # update color for changed items
                        self.hlist.item_configure(new_item.entry,
                                                  0,
                                                  style=self.changed_style)
                    else:
                        # update color for default items
                        self.hlist.item_configure(new_item.entry,
                                                  0,
                                                  style=self.default_style)
Exemplo n.º 4
0
    def __str__(self):
        return self.text

    def get_parent(self):
        if "." in self.entry:
            return self.entry[:self.entry.rfind(".")]
        return None

    def mark_as_changed(self):
        self.changed = True


# locale reading
Tk().withdraw()
file_path = askopenfilename(title="Open json file...")
locale_json = pck_tools.read_json(file_path)

# assoc table
entry_item = {}
user_changes = {}

# frame fun
root = tk.Tk()
root.geometry("640x400")
root.title("Simple Editor")

shlist = tk.Tree(root, borderwidth=0, highlightthickness=0)
shlist.pack(fill=tk.BOTH, expand=True)

hlist = shlist.subwidget("hlist")
hlist.config(columns=1, selectmode=tk.BROWSE)
Exemplo n.º 5
0
from tkinter.filedialog import *


def savefile(content):
    file = asksaveasfile(mode="wb",
                         initialfile="addition",
                         defaultextension=".json")
    if file:
        file.write(content)
        file.close()


Tk().withdraw()
base_path = askopenfilename(title="Open base file...")
new_path = askopenfilename(title="Open new file...")

base_json = pck_tools.read_json(base_path)
new_json = pck_tools.read_json(new_path)

for hash in new_json["files"]:
    for key in new_json["files"][hash]["dict"]:
        if hash in base_json["files"]:
            base_json["files"][hash]["dict"][key] = new_json["files"][hash][
                "dict"][key]
        else:
            base_json["files"][hash] = new_json["files"][hash]

savefile(
    json.dumps(base_json, sort_keys=False, indent=4,
               ensure_ascii=False).encode("utf-8"))
Exemplo n.º 6
0
import pck_struct
import json
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")
Exemplo n.º 7
0
                old["files"][hash]["dict"][key] = new_val
                # print action
                print("\r\tUpdated!~")
            else:
                print("\r\tSkipped!~")

    return old


if __name__ == '__main__':
    print()
    Tk().withdraw()
    old_path = askopenfilename(title="Open first file...")
    new_path = askopenfilename(title="Open second file...")

    old_json = pck_tools.read_json(old_path)
    print("First file: [{} | {}]".format(old_json["name"], old_json["date"]))
    print(old_path)
    print()

    new_json = pck_tools.read_json(new_path)
    print("Second file: [{} | {}]".format(new_json["name"], new_json["date"]))
    print(new_path)
    print()

    print()
    print("Pick action: ")
    print("1) get new keys")
    print("2) get new changed values")
    print("3) get old changed values")
    print("4) get full difference")
Exemplo n.º 8
0
import pck_tools
import json
import time
from tkinter.filedialog import *

conversion_table = pck_tools.read_json("global_to_korean.json")
if conversion_table is None:
    exit("Conversion table not found!")

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

if file:
    file = file.replace("\\", "/")
    pck = pck_tools.unpack_pck(file)
    if pck:
        json_full = {
            "name": "global_converted",
            "date": time.strftime("%x"),
            "files": {}
        }
        for global_hash in conversion_table:
            korean_hash = conversion_table[global_hash]

            global_pck_file = pck.get_file(hash=global_hash)
            if global_pck_file:
                global_pck_file.hash = korean_hash