File: lipa-installer.vala

package info (click to toggle)
listaller 0.5.5-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,812 kB
  • sloc: ansic: 2,152; sh: 1,735; perl: 1,452; xml: 874; cpp: 765; java: 157; makefile: 150; cs: 48; python: 24
file content (155 lines) | stat: -rw-r--r-- 4,585 bytes parent folder | download
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
/* lipa-installer.vala -- Application setup handling in Listaller command-line tool
 *
 * Copyright (C) 2010-2012 Matthias Klumpp
 *
 * Licensed under the GNU General Public License Version 3
 *
 * 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 copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

using GLib;
using Config;
using Listaller;

public class LipaInstaller : LipaModule {
	private Setup inst;
	private bool setup_running = false;

	public LipaInstaller () {
		base ();
	}

	public void setup_error_code (ErrorItem error) {
		// End progress, if any
		progress_bar.end ();

		stderr.printf (error.details);
		error_code = (int) error.error;
	}

	public void setup_progress_changed (int progress, int sub_progress) {
		if (setup_running)
			progress_bar.set_percentage (progress);
		//stdout.printf ("%c8", 0x1B);
		//stdout.printf ("[%i]   ", progress);
		// TODO: Show sub-progress
	}

	public void setup_status_changed (StatusItem status) {
		if (status.status == StatusEnum.INSTALLATION_FINISHED) {
			progress_bar.end ();
			print ("Installation completed!\n");
			setup_running = false;
		} else if (status.status == StatusEnum.ACTION_STARTED) {
			setup_running = true;
		}
	}

	public void setup_message (MessageItem message) {
		stdout.printf ("%s\n", message.details);
	}

	public void install_package (string ipkfname) {
		bool ret;
		print ("Preparing... Please wait!");

		inst = new Setup (ipkfname, liconf);
		inst.message.connect (setup_message);
		inst.status_changed.connect (setup_status_changed);
		inst.progress_changed.connect (setup_progress_changed);
		inst.error_code.connect (setup_error_code);

		ret = inst.initialize ();
		if (!ret) {
			error_code = 8;
			return;
		}

		IPK.Control ipkmeta = inst.control;
		if (ipkmeta == null) {
			error_code = 6;
			return;
		}

		AppItem appID = ipkmeta.get_application ();
		print ("%c8", 0x1B);
		print ("==== %s ====\n\n", _("Installation of %s").printf (appID.full_name));

		print ("%s\n\n%s\n", _("Description:"), appID.description);
		string[] licenseLines = appID.license.text.split ("\n");

		// save cursor in new position
		print ("%c7", 0x1B);

		if (licenseLines.length > 1) {
			print ("%s\n\n", _("License:"));
			for (int i = 0; i < licenseLines.length; i++) {
				print ("%s\n", licenseLines[i]);
				if ((i % 2) == 1) {
					Posix.FILE? tty = console_get_tty ();
					// TODO: Text does not get erasted for some reason...
					// => Implement this properly!
					//print (" <<< Press ENTER to continue! >>>\r");
					console_wait_for_enter (tty);
				}
			}
			console_get_prompt (_("Do you accept these terms and conditions?"), false, true);
		}

		// Display security info
		IPK.PackSecurity sec = inst.get_security_info ();
		SecurityLevel secLev = sec.get_level ();
		if (secLev == SecurityLevel.HIGH)
			print ("%s %c[%dm%s\n%c[%dm", _("Security is:"), 0x1B, CONSOLE_GREEN, "HIGH", 0x1B, CONSOLE_RESET);
		else if (secLev == SecurityLevel.MEDIUM)
			print ("%s %c[%dm%s\n%c[%dm", _("Security is:"), 0x1B, CONSOLE_YELLOW, "MEDIUM", 0x1B, CONSOLE_RESET);
		else if (secLev <= SecurityLevel.LOW)
			print ("%s %c[%dm%s\n%c[%dm", _("Security is:"), 0x1B, CONSOLE_RED, "LOW", 0x1B, CONSOLE_RESET);

		// Make sure color is reset...
		print ("%c[%dm", 0x1B, CONSOLE_RESET);

		AppItem? app = inst.get_current_application ();
		if (app == null)
			error ("Did not receive valid application information!");

		ret = console_get_prompt (_("Do you want to install %s now?").printf (app.full_name), true);
		// If user doesn't want to install the application, exit
		if (!ret)
			return;

		progress_bar.start (_("Installing"));
		// Go!
		ret = inst.run_installation ();
		progress_bar.end ();

		if (ret) {
			print ("Installation of %s completed successfully!\n", app.full_name);
		} else {
			print ("Installation of %s failed!", app.full_name);
			error_code = 3;
		}

		inst = null;
	}

	public override void terminate_action () {
		if (inst != null) {
			if (setup_running)
				inst.kill_installation_process ();
			inst = null;
		}
	}

}