This repository has been archived by the owner on Jul 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
AptikGtk.vala
315 lines (245 loc) · 9 KB
/
AptikGtk.vala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
/*
* AptikGtk.vala
*
* Copyright 2012-2017 Tony George <teejeetech@gmail.com>
*
* 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 2 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 copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
using GLib;
using Gtk;
using Gee;
using Json;
using TeeJee.Logging;
using TeeJee.FileSystem;
using TeeJee.JsonHelper;
using TeeJee.ProcessHelper;
using TeeJee.System;
using TeeJee.Misc;
using TeeJee.GtkHelper;
public const string AppName = "Aptik GTK";
public const string AppShortName = "aptik-gtk";
public const string AppVersion = "18.6";
public const string AptikVersionRequired = "18.07.0";
public const string AppAuthor = "Tony George";
public const string AppAuthorEmail = "teejeetech@gmail.com";
const string GETTEXT_PACKAGE = "";
const string LOCALE_DIR = "/usr/share/locale";
extern void exit(int exit_code);
public AptikGtk App;
public class AptikGtk : GLib.Object {
public LinuxDistro distro = null;
public string basepath = "";
public Mode mode = Mode.BACKUP;
public GUIMode guimode = GUIMode.EASY;
public bool include_repos = true;
public bool include_cache = true;
public bool include_packages = true;
public bool include_users = true;
public bool include_groups = true;
public bool include_home = true;
public bool include_mounts = true;
public bool include_icons = true;
public bool include_themes = true;
public bool include_fonts = true;
public bool include_dconf = true;
public bool include_cron = true;
public bool include_files = true;
public bool include_scripts = true;
public bool exclude_pkg_icons = false;
public bool exclude_pkg_themes = false;
public bool exclude_pkg_fonts = false;
public bool include_pkg_foreign = false;
public bool exclude_home_encrypted = true;
public bool exclude_home_hidden = false;
public bool redist = false;
public MainWindow main_window;
public static int main (string[] args) {
set_locale();
Gtk.init(ref args);
init_tmp(AppShortName);
IconManager.init(args, AppShortName);
App = new AptikGtk();
App.load_settings();
App.parse_arguments(args);
var window = new MainWindow();
window.destroy.connect(Gtk.main_quit);
window.show_all();
App.main_window = window;
//start event loop
Gtk.main();
App.save_settings();
//App.exit_app();
return 0;
}
public AptikGtk(){
distro = new LinuxDistro();
}
private static void set_locale() {
Intl.setlocale(GLib.LocaleCategory.MESSAGES, "aptik");
Intl.textdomain(GETTEXT_PACKAGE);
Intl.bind_textdomain_codeset(GETTEXT_PACKAGE, "utf-8");
Intl.bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR);
}
public bool parse_arguments(string[] args) {
// parse options
for (int k = 1; k < args.length; k++) // Oth arg is app path
{
switch (args[k].down()) {
case "--debug":
LOG_DEBUG = true;
break;
case "--help":
case "--h":
case "-h":
log_msg(help_message());
exit(0);
return true;
default:
// unknown option; show help and exit
log_error("%s: %s".printf(_("Unknown option"), args[k]));
log_msg(help_message());
exit(1);
return false;
}
}
return true;
}
public static string help_message() {
string msg = "\n" + AppName + " v" + AppVersion + " by %s (%s)".printf(AppAuthor, AppAuthorEmail) + "\n";
msg += "\n";
msg += _("Syntax") + ": aptik-gtk [options]\n";
msg += "\n";
msg += _("Options") + ":\n";
msg += "\n";
msg += " --debug " + _("Print debug information") + "\n";
msg += " --h[elp] " + _("Show all options") + "\n";
msg += "\n";
return msg;
}
public void copy_deb_file(string src_file){
string backup_debs = path_combine(basepath, "debs/files");
dir_create(backup_debs);
chmod(backup_debs, "a+rwx");
string file_name = file_basename(src_file);
string dest_file = path_combine(backup_debs, file_name);
file_copy(src_file, dest_file);
chmod(dest_file, "a+rw");
}
// settings ---------------------------------
public void save_settings(){
save_param(ConfigParam.BASEPATH, basepath);
save_param(ConfigParam.INC_REPOS, include_repos.to_string());
save_param(ConfigParam.INC_CACHE, include_cache.to_string());
save_param(ConfigParam.INC_PACKAGES, include_packages.to_string());
save_param(ConfigParam.INC_USERS, include_users.to_string());
save_param(ConfigParam.INC_GROUPS, include_groups.to_string());
save_param(ConfigParam.INC_HOME, include_home.to_string());
save_param(ConfigParam.INC_MOUNTS, include_mounts.to_string());
save_param(ConfigParam.INC_ICONS, include_icons.to_string());
save_param(ConfigParam.INC_THEMES, include_themes.to_string());
save_param(ConfigParam.INC_FONTS, include_fonts.to_string());
save_param(ConfigParam.INC_DCONF, include_dconf.to_string());
save_param(ConfigParam.INC_CRON, include_cron.to_string());
save_param(ConfigParam.INC_FILES, include_files.to_string());
save_param(ConfigParam.INC_SCRIPTS, include_scripts.to_string());
save_param(ConfigParam.EXC_PKG_ICONS, exclude_pkg_icons.to_string());
save_param(ConfigParam.EXC_PKG_THEMES, exclude_pkg_themes.to_string());
save_param(ConfigParam.EXC_PKG_FONTS, exclude_pkg_fonts.to_string());
save_param(ConfigParam.EXC_PKG_FOREIGN, include_pkg_foreign.to_string());
save_param(ConfigParam.EXC_HOME_ENC, exclude_home_encrypted.to_string());
save_param(ConfigParam.EXC_HOME_HIDDEN, exclude_home_hidden.to_string());
save_param(ConfigParam.MODE, ((int)mode).to_string());
save_param(ConfigParam.GUIMODE, ((int)guimode).to_string());
save_param(ConfigParam.REDIST, redist.to_string());
}
public void save_param(ConfigParam param, string param_value){
var app_config_path = path_combine(get_user_home(), ".config/aptik");
var param_file = path_combine(app_config_path, param.to_string().replace("CONFIG_PARAM_",""));
file_write(param_file, param_value);
}
public void load_settings(){
basepath = load_param(ConfigParam.BASEPATH, "");
include_repos = load_param_bool(ConfigParam.INC_REPOS, true);
include_cache = load_param_bool(ConfigParam.INC_CACHE, true);
include_packages = load_param_bool(ConfigParam.INC_PACKAGES, true);
include_users = load_param_bool(ConfigParam.INC_USERS, true);
include_groups = load_param_bool(ConfigParam.INC_GROUPS, true);
include_home = load_param_bool(ConfigParam.INC_HOME, true);
include_mounts = load_param_bool(ConfigParam.INC_MOUNTS, true);
include_icons = load_param_bool(ConfigParam.INC_ICONS, true);
include_themes = load_param_bool(ConfigParam.INC_THEMES, true);
include_fonts = load_param_bool(ConfigParam.INC_FONTS, true);
include_dconf = load_param_bool(ConfigParam.INC_DCONF, true);
include_cron = load_param_bool(ConfigParam.INC_CRON, true);
include_files = load_param_bool(ConfigParam.INC_FILES, true);
include_scripts = load_param_bool(ConfigParam.INC_SCRIPTS, true);
exclude_pkg_icons = load_param_bool(ConfigParam.EXC_PKG_ICONS, false);
exclude_pkg_themes = load_param_bool(ConfigParam.EXC_PKG_THEMES, false);
exclude_pkg_fonts = load_param_bool(ConfigParam.EXC_PKG_FONTS, false);
include_pkg_foreign = load_param_bool(ConfigParam.EXC_PKG_FOREIGN, false);
exclude_home_encrypted = load_param_bool(ConfigParam.EXC_HOME_ENC, true);
exclude_home_hidden = load_param_bool(ConfigParam.EXC_HOME_HIDDEN, false);
mode = (Mode) load_param_int (ConfigParam.MODE, Mode.BACKUP);
guimode = (GUIMode) load_param_int (ConfigParam.GUIMODE, GUIMode.EASY);
redist = load_param_bool(ConfigParam.REDIST, false);
}
public string load_param(ConfigParam param, string default_value){
var app_config_path = path_combine(get_user_home(), ".config/aptik");
var param_file = path_combine(app_config_path, param.to_string().replace("CONFIG_PARAM_",""));
if (file_exists(param_file)){
return file_read(param_file);
}
else{
return default_value;
}
}
public bool load_param_bool(ConfigParam param, bool default_value){
string txt = load_param(param, default_value.to_string());
return bool.parse(txt);
}
public int load_param_int(ConfigParam param, int default_value){
string txt = load_param(param, default_value.to_string());
return int.parse(txt);
}
}
public enum ConfigParam {
BASEPATH,
INC_REPOS,
INC_CACHE,
INC_PACKAGES,
INC_USERS,
INC_GROUPS,
INC_HOME,
INC_MOUNTS,
INC_ICONS,
INC_THEMES,
INC_FONTS,
INC_DCONF,
INC_CRON,
INC_FILES,
INC_SCRIPTS,
EXC_PKG_ICONS,
EXC_PKG_THEMES,
EXC_PKG_FONTS,
EXC_PKG_FOREIGN,
EXC_HOME_ENC,
EXC_HOME_HIDDEN,
MODE,
GUIMODE,
REDIST
}