forked from cromer/pamac-classic
add to possibility to change syncfirst, ignorepkg and mirrors into preferences
This commit is contained in:
@@ -20,24 +20,28 @@
|
||||
namespace Pamac {
|
||||
public class Config: Object {
|
||||
string conf_path;
|
||||
public uint64 refresh_period;
|
||||
public int refresh_period;
|
||||
public bool enable_aur;
|
||||
public bool recurse;
|
||||
|
||||
public Config (string path) {
|
||||
conf_path = path;
|
||||
// set default options
|
||||
// set default option
|
||||
refresh_period = 4;
|
||||
enable_aur = false;
|
||||
recurse = false;
|
||||
// parse conf file
|
||||
parse_include_file (conf_path);
|
||||
reload ();
|
||||
}
|
||||
|
||||
public void parse_include_file (string path) {
|
||||
public void reload () {
|
||||
// set default options
|
||||
enable_aur = false;
|
||||
recurse = false;
|
||||
parse_file (conf_path);
|
||||
}
|
||||
|
||||
public void parse_file (string path) {
|
||||
var file = GLib.File.new_for_path (path);
|
||||
if (file.query_exists () == false)
|
||||
GLib.stderr.printf ("File '%s' doesn't exist.\n", file.get_path ());
|
||||
GLib.stderr.printf ("File '%s' doesn't exist.\n", path);
|
||||
else {
|
||||
try {
|
||||
// Open file for reading and wrap returned FileInputStream into a
|
||||
@@ -55,7 +59,7 @@ namespace Pamac {
|
||||
if (splitted[1] != null)
|
||||
_value = splitted[1].strip ();
|
||||
if (_key == "RefreshPeriod")
|
||||
refresh_period = uint64.parse (_value);
|
||||
refresh_period = int.parse (_value);
|
||||
else if (_key == "EnableAUR")
|
||||
enable_aur = true;
|
||||
else if (_key == "RemoveUnrequiredDeps")
|
||||
@@ -67,10 +71,10 @@ namespace Pamac {
|
||||
}
|
||||
}
|
||||
|
||||
public void write (HashTable<string,string> new_conf) {
|
||||
public void write (HashTable<string,Variant> new_conf) {
|
||||
var file = GLib.File.new_for_path (conf_path);
|
||||
if (file.query_exists () == false)
|
||||
GLib.stderr.printf ("File '%s' doesn't exist.\n", file.get_path ());
|
||||
GLib.stderr.printf ("File '%s' doesn't exist.\n", conf_path);
|
||||
else {
|
||||
try {
|
||||
// Open file for reading and wrap returned FileInputStream into a
|
||||
@@ -80,31 +84,29 @@ namespace Pamac {
|
||||
string[] data = {};
|
||||
// Read lines until end of file (null) is reached
|
||||
while ((line = dis.read_line (null)) != null) {
|
||||
if (line.length == 0) continue;
|
||||
if (line.contains ("RefreshPeriod")) {
|
||||
if (new_conf.contains ("RefreshPeriod")) {
|
||||
string _value = new_conf.get ("RefreshPeriod");
|
||||
data += "RefreshPeriod = %s\n".printf (_value);
|
||||
refresh_period = uint64.parse (_value);
|
||||
int _value = new_conf.get ("RefreshPeriod").get_int32 ();
|
||||
data += "RefreshPeriod = %u\n".printf (_value);
|
||||
} else
|
||||
data += line + "\n";
|
||||
} else if (line.contains ("EnableAUR")) {
|
||||
if (new_conf.contains ("EnableAUR")) {
|
||||
bool _value = bool.parse (new_conf.get ("EnableAUR"));
|
||||
bool _value = new_conf.get ("EnableAUR").get_boolean ();
|
||||
if (_value == true)
|
||||
data += "EnableAUR\n";
|
||||
else
|
||||
data += "#EnableAUR\n";
|
||||
enable_aur = _value;
|
||||
} else
|
||||
data += line + "\n";
|
||||
} else if (line.contains ("RemoveUnrequiredDeps")) {
|
||||
if (new_conf.contains ("RemoveUnrequiredDeps")) {
|
||||
bool _value = bool.parse (new_conf.get ("RemoveUnrequiredDeps"));
|
||||
bool _value = new_conf.get ("RemoveUnrequiredDeps").get_boolean ();
|
||||
if (_value == true)
|
||||
data += "RemoveUnrequiredDeps\n";
|
||||
else
|
||||
data += "#RemoveUnrequiredDeps\n";
|
||||
enable_aur = _value;
|
||||
} else
|
||||
data += line + "\n";
|
||||
} else
|
||||
@@ -123,11 +125,5 @@ namespace Pamac {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void reload () {
|
||||
enable_aur = false;
|
||||
recurse = false;
|
||||
parse_include_file (conf_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user