From e713bf34649e6a572ab156068b090a8a98eee880 Mon Sep 17 00:00:00 2001 From: plant_1312 Date: Fri, 24 Jan 2020 22:34:51 +0000 Subject: [PATCH] Simple parser With help nickey --- src/main.vala | 58 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/src/main.vala b/src/main.vala index cf01da9..19fd499 100644 --- a/src/main.vala +++ b/src/main.vala @@ -27,17 +27,11 @@ int main (string[] args) { var window = builder.get_object ("window") as Window; var browse = builder.get_object ("browse") as Button; - browse.clicked.connect (() => { - - browse.label = "Soon"; - - }); - var yggdrasil = builder.get_object ("yggdrasil") as Button; yggdrasil.clicked.connect (() => { - download (); + download (); }); @@ -65,7 +59,32 @@ int main (string[] args) { yggtk.clicked.connect (() => { - update (); + update (); + + }); + + var ip = builder.get_object ("label_ip") as Entry; + + ip.notify["text"].connect (() => { + + browse.label = "OK"; + + }); + + string yggconf; + Process.spawn_command_line_sync ("yggdrasil -genconf -json", out yggconf); + + browse.clicked.connect (() => { + + if (browse.label == "OK") { + + parse (yggconf, ip); + + } else { + + browse.label = "Soon"; + + } }); @@ -120,7 +139,9 @@ int update () { string temp_dir = Utils.mktempdir (); if (repo_url == null) { + repo_url = "https://git.macaw.me/plant_1312/Yggtk.git"; + } Process.spawn_command_line_sync (@"git clone $repo_url $temp_dir"); @@ -182,10 +203,25 @@ int start () { } -int parse (string yggconf) { +int parse (string yggconf, Entry ip) { - /*var parser = new Json.Parser (); - parser.load_from_data (yggconf, -1);*/ + try { + + var node = Json.from_string (yggconf); + var obj = node.get_object (); + obj.set_string_member ("Peers", ip.text); + string ptext = Json.to_string (node,true); + + string file = "yggdrasil.conf"; + FileUtils.set_contents (file, ptext); + + Process.spawn_command_line_sync ("pkexec cp yggdrasil.conf /etc"); + + } catch (Error e) { + + print ("Error parse JSON: %s\n", e.message); + + } return 0;