Fix parser

This commit is contained in:
plant_1312 2020-01-24 22:34:51 +00:00
parent e7623353aa
commit e79228942d

View File

@ -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;