2014-10-22 13:44:02 -03:00
|
|
|
/*
|
|
|
|
* pamac-vala
|
|
|
|
*
|
2017-10-10 16:29:22 -03:00
|
|
|
* Copyright (C) 2017 Chris Cromer <cromer@cromnix.org>
|
2017-01-03 05:43:19 -03:00
|
|
|
* Copyright (C) 2014-2017 Guillaume Benoit <guillaume@manjaro.org>
|
2014-10-22 13:44:02 -03:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a get of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Pamac {
|
2016-04-14 13:19:20 -03:00
|
|
|
class Config {
|
|
|
|
string conf_path;
|
|
|
|
HashTable<string,string> _environment_variables;
|
|
|
|
|
|
|
|
public bool recurse { get; private set; }
|
|
|
|
public uint64 refresh_period { get; private set; }
|
|
|
|
public bool no_update_hide_icon { get; private set; }
|
2017-10-10 16:29:22 -03:00
|
|
|
#if DISABLE_AUR
|
|
|
|
#else
|
2016-04-14 13:19:20 -03:00
|
|
|
public bool enable_aur { get; private set; }
|
2017-10-02 10:23:53 -03:00
|
|
|
public bool search_aur { get; private set; }
|
2017-10-04 20:52:47 -03:00
|
|
|
public string aur_build_dir { get; private set; }
|
2016-04-14 13:19:20 -03:00
|
|
|
public bool check_aur_updates { get; private set; }
|
2017-10-10 16:29:22 -03:00
|
|
|
#endif
|
2017-10-15 17:04:01 -03:00
|
|
|
public uint64 keep_num_pkgs { get; private set; }
|
|
|
|
public bool rm_only_uninstalled { get; private set; }
|
2016-04-14 13:19:20 -03:00
|
|
|
public unowned HashTable<string,string> environment_variables {
|
|
|
|
get {
|
|
|
|
return _environment_variables;
|
|
|
|
}
|
|
|
|
}
|
2014-10-22 13:44:02 -03:00
|
|
|
|
|
|
|
public Config (string path) {
|
2014-12-03 12:02:14 -03:00
|
|
|
conf_path = path;
|
2016-02-02 05:28:07 -03:00
|
|
|
//get environment variables
|
2016-04-14 13:19:20 -03:00
|
|
|
_environment_variables = new HashTable<string,string> (str_hash, str_equal);
|
2016-02-02 05:28:07 -03:00
|
|
|
var utsname = Posix.utsname();
|
2016-04-14 13:19:20 -03:00
|
|
|
_environment_variables.insert ("HTTP_USER_AGENT", "pamac (%s %s)".printf (utsname.sysname, utsname.machine));
|
2016-02-02 05:28:07 -03:00
|
|
|
unowned string? variable = Environment.get_variable ("http_proxy");
|
|
|
|
if (variable != null) {
|
2016-04-14 13:19:20 -03:00
|
|
|
_environment_variables.insert ("http_proxy", variable);
|
2016-02-02 05:28:07 -03:00
|
|
|
}
|
|
|
|
variable = Environment.get_variable ("https_proxy");
|
|
|
|
if (variable != null) {
|
2016-04-14 13:19:20 -03:00
|
|
|
_environment_variables.insert ("https_proxy", variable);
|
2016-02-02 05:28:07 -03:00
|
|
|
}
|
|
|
|
variable = Environment.get_variable ("ftp_proxy");
|
|
|
|
if (variable != null) {
|
2016-04-14 13:19:20 -03:00
|
|
|
_environment_variables.insert ("ftp_proxy", variable);
|
2016-02-02 05:28:07 -03:00
|
|
|
}
|
|
|
|
variable = Environment.get_variable ("socks_proxy");
|
|
|
|
if (variable != null) {
|
2016-04-14 13:19:20 -03:00
|
|
|
_environment_variables.insert ("socks_proxy", variable);
|
2016-02-02 05:28:07 -03:00
|
|
|
}
|
|
|
|
variable = Environment.get_variable ("no_proxy");
|
|
|
|
if (variable != null) {
|
2016-04-14 13:19:20 -03:00
|
|
|
_environment_variables.insert ("no_proxy", variable);
|
2016-02-02 05:28:07 -03:00
|
|
|
}
|
2014-12-30 11:04:40 -03:00
|
|
|
// set default option
|
2015-08-20 10:11:18 -03:00
|
|
|
refresh_period = 6;
|
2014-12-30 11:04:40 -03:00
|
|
|
reload ();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void reload () {
|
|
|
|
// set default options
|
2014-12-03 12:02:14 -03:00
|
|
|
recurse = false;
|
2015-08-20 10:11:18 -03:00
|
|
|
no_update_hide_icon = false;
|
2017-10-10 16:29:22 -03:00
|
|
|
#if DISABLE_AUR
|
|
|
|
#else
|
2015-08-24 11:13:18 -03:00
|
|
|
enable_aur = false;
|
2017-10-02 10:23:53 -03:00
|
|
|
search_aur = false;
|
2017-10-04 20:52:47 -03:00
|
|
|
aur_build_dir = "/tmp";
|
2015-08-20 10:11:18 -03:00
|
|
|
check_aur_updates = false;
|
2017-10-10 16:29:22 -03:00
|
|
|
#endif
|
2017-10-15 17:04:01 -03:00
|
|
|
keep_num_pkgs = 3;
|
|
|
|
rm_only_uninstalled = false;
|
2014-12-30 11:04:40 -03:00
|
|
|
parse_file (conf_path);
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
2016-04-14 13:19:20 -03:00
|
|
|
void parse_file (string path) {
|
2014-10-22 13:44:02 -03:00
|
|
|
var file = GLib.File.new_for_path (path);
|
2015-08-20 10:11:18 -03:00
|
|
|
if (file.query_exists ()) {
|
2014-10-22 13:44:02 -03:00
|
|
|
try {
|
|
|
|
// Open file for reading and wrap returned FileInputStream into a
|
|
|
|
// DataInputStream, so we can read line by line
|
|
|
|
var dis = new DataInputStream (file.read ());
|
2015-08-20 10:11:18 -03:00
|
|
|
string? line;
|
2014-10-22 13:44:02 -03:00
|
|
|
// Read lines until end of file (null) is reached
|
2015-08-20 10:11:18 -03:00
|
|
|
while ((line = dis.read_line ()) != null) {
|
2015-03-04 11:55:36 -03:00
|
|
|
if (line.length == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-08-20 10:11:18 -03:00
|
|
|
// ignore whole line and end of line comments
|
|
|
|
string[] splitted = line.split ("#", 2);
|
|
|
|
line = splitted[0].strip ();
|
|
|
|
if (line.length == 0) {
|
2015-03-04 11:55:36 -03:00
|
|
|
continue;
|
|
|
|
}
|
2016-02-02 05:28:07 -03:00
|
|
|
splitted = line.split ("=", 2);
|
|
|
|
unowned string key = splitted[0]._strip ();
|
2015-08-20 10:11:18 -03:00
|
|
|
if (key == "RemoveUnrequiredDeps") {
|
2014-12-03 12:02:14 -03:00
|
|
|
recurse = true;
|
2015-08-20 10:11:18 -03:00
|
|
|
} else if (key == "RefreshPeriod") {
|
2016-02-02 05:28:07 -03:00
|
|
|
if (splitted.length == 2) {
|
|
|
|
unowned string val = splitted[1]._strip ();
|
|
|
|
refresh_period = uint64.parse (val);
|
|
|
|
}
|
2015-08-20 10:11:18 -03:00
|
|
|
} else if (key == "NoUpdateHideIcon") {
|
|
|
|
no_update_hide_icon = true;
|
2017-10-10 16:29:22 -03:00
|
|
|
#if DISABLE_AUR
|
|
|
|
#else
|
2015-08-20 10:11:18 -03:00
|
|
|
} else if (key == "EnableAUR") {
|
|
|
|
enable_aur = true;
|
2017-10-02 10:23:53 -03:00
|
|
|
} else if (key == "SearchInAURByDefault") {
|
|
|
|
search_aur = true;
|
2017-10-04 20:52:47 -03:00
|
|
|
} else if (key == "BuildDirectory") {
|
|
|
|
if (splitted.length == 2) {
|
|
|
|
aur_build_dir = splitted[1]._strip ();
|
|
|
|
}
|
2015-08-20 10:11:18 -03:00
|
|
|
} else if (key == "CheckAURUpdates") {
|
|
|
|
check_aur_updates = true;
|
2017-10-10 16:29:22 -03:00
|
|
|
#endif
|
2017-10-15 17:04:01 -03:00
|
|
|
} else if (key == "KeepNumPackages") {
|
|
|
|
if (splitted.length == 2) {
|
|
|
|
unowned string val = splitted[1]._strip ();
|
|
|
|
keep_num_pkgs = uint64.parse (val);
|
|
|
|
}
|
|
|
|
} else if (key == "OnlyRmUninstalled") {
|
|
|
|
rm_only_uninstalled = true;
|
2015-03-04 11:55:36 -03:00
|
|
|
}
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
} catch (GLib.Error e) {
|
|
|
|
GLib.stderr.printf("%s\n", e.message);
|
|
|
|
}
|
2015-08-20 10:11:18 -03:00
|
|
|
} else {
|
|
|
|
GLib.stderr.printf ("File '%s' doesn't exist.\n", path);
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|