Skip to content
API Documentation
BastionGuard™
AppGtk Class Reference
Inheritance diagram for AppGtk:

Static Public Member Functions

static int main (string[] args)
static bool parse_arguments (string[] args)
static string help_message ()
static void check_if_admin ()
static void start_application (bool recovery_mode=false)

Static Private Member Functions

static void set_locale ()
static string version_message ()
static bool is_kernel_recovery_boot ()

Detailed Description

Definition at line 36 of file AppGtk.vala.

Member Function Documentation

◆ check_if_admin()

void AppGtk.check_if_admin ( )
inlinestatic

Definition at line 138 of file AppGtk.vala.

138 {
139 if (!user_is_admin()) {
140 var msg = _("Admin access is required to backup and restore system files.") + "\n";
141 msg += _("Please re-run the application as admin (using 'sudo' or 'su')");
142 log_error(msg);
143 string title = _("Admin Access Required");
144 gtk_messagebox(title, msg, null, true);
145 exit(1);
146 }
147 }
void exit(int exit_code)
#define _(s)
void log_error(string message, bool highlight=false, bool is_warning=false)

References _, exit(), TeeJee.Logging.log_error(), and TeeJee.System.user_is_admin().

Referenced by main().

◆ help_message()

string AppGtk.help_message ( )
inlinestatic

Definition at line 122 of file AppGtk.vala.

122 {
123 string msg = "\n%s v%s by BastionGuard (%s)\n".printf(AppName, AppVersion, AppAuthorEmail);
124 msg += "\n";
125 msg += _("Syntax") + ": bastionguard-backup-gtk [options]\n";
126 msg += "\n";
127 msg += _("Options") + ":\n";
128 msg += "\n";
129 msg += " --debug " + _("Print debug information") + "\n";
130 msg += " --recovery " + _("Start in recovery mode") + "\n";
131 msg += " --h[elp] " + _("Show all options") + "\n";
132 msg += " --version " + _("Print version number") + "\n";
133 msg += "\n\n";
134 msg += "\n%s\n".printf(_("Run 'bastionguard-backup' for the command-line version of this tool"));
135 return msg;
136 }
const string AppName
Definition AppGtk.vala:24
const string AppVersion
Definition AppGtk.vala:26
const string AppAuthorEmail
Definition AppGtk.vala:28

References _, AppAuthorEmail, AppName, and AppVersion.

Referenced by main(), and parse_arguments().

◆ is_kernel_recovery_boot()

bool AppGtk.is_kernel_recovery_boot ( )
inlinestaticprivate

Definition at line 169 of file AppGtk.vala.

169 {
170 try {
171 string cmdline;
172 FileUtils.get_contents("/proc/cmdline", out cmdline);
173 return BASTIONGUARD_RECOVERY_FLAG in cmdline;
174 } catch {
175 return false;
176 }
177 }
const string BASTIONGUARD_RECOVERY_FLAG
Definition AppGtk.vala:31

References BASTIONGUARD_RECOVERY_FLAG.

Referenced by main().

◆ main()

int AppGtk.main ( string[] args)
inlinestatic

Definition at line 38 of file AppGtk.vala.

38 {
39
40 set_locale();
41
42 // Rileva --recovery o parametro kernel bastionguard.recovery=1
43 bool recovery_mode = false;
44 foreach (var arg in args) {
45 if (arg == "--recovery") { recovery_mode = true; break; }
46 }
47 if (!recovery_mode && is_kernel_recovery_boot()) {
48 recovery_mode = true;
49 }
50
51 if (args.length > 1) {
52 switch (args[1].down()) {
53 case "--help":
54 case "--h":
55 case "-h":
56 stdout.printf(help_message());
57 return 0;
58 case "--version":
59 stdout.printf(version_message());
60 return 0;
61 }
62 }
63
64 Main.setup_env();
65
66 Gtk.init();
67
68 GTK_INITIALIZED = true;
69
70 init_tmp();
71
73
74 App = new Main(args, true);
75
76 // In recovery mode: imposta app_mode così live_system() ritorna false
77 // e tutte le funzioni (Crea, Ripristina, Wizard) restano disponibili
78 if (recovery_mode) {
79 App.app_mode = "recovery";
80 }
81
82 parse_arguments(args);
84 start_application(recovery_mode);
85
86 App.exit_app();
87
88 return 0;
89 }
Main App
Definition AppGtk.vala:23
bool GTK_INITIALIZED
Definition Main.vala:37
static string help_message()
Definition AppGtk.vala:122
static bool is_kernel_recovery_boot()
Definition AppGtk.vala:169
static void set_locale()
Definition AppGtk.vala:91
static void check_if_admin()
Definition AppGtk.vala:138
static void start_application(bool recovery_mode=false)
Definition AppGtk.vala:149
static bool parse_arguments(string[] args)
Definition AppGtk.vala:99
static string version_message()
Definition AppGtk.vala:118
Main(string[] args, bool gui_mode)
Definition Main.vala:186
void initialize()
Definition Main.vala:337
void exit_app(int exit_code=0)
Definition Main.vala:4574

References App, check_if_admin(), Main.exit_app(), GTK_INITIALIZED, help_message(), Main.initialize(), is_kernel_recovery_boot(), Main.Main(), parse_arguments(), set_locale(), Main.setup_env(), start_application(), and version_message().

◆ parse_arguments()

bool AppGtk.parse_arguments ( string[] args)
inlinestatic

Definition at line 99 of file AppGtk.vala.

99 {
100 for (int k = 1; k < args.length; k++) {
101 switch (args[k].down()) {
102 case "--debug":
103 LOG_DEBUG = true;
104 break;
105 case "--recovery":
106 // già gestito sopra
107 break;
108 default:
109 log_error(_("Unknown option") + ": %s".printf(args[k]));
111 App.exit_app(1);
112 return false;
113 }
114 }
115 return true;
116 }
void log_msg(string message, bool highlight=false)

References _, App, Main.exit_app(), help_message(), TeeJee.Logging.LOG_DEBUG, TeeJee.Logging.log_error(), and TeeJee.Logging.log_msg().

Referenced by main().

◆ set_locale()

void AppGtk.set_locale ( )
inlinestaticprivate

Definition at line 91 of file AppGtk.vala.

91 {
92 log_debug("setting locale...");
93 Intl.setlocale(GLib.LocaleCategory.MESSAGES, "bastionguard-backup");
94 Intl.textdomain(GETTEXT_PACKAGE);
95 Intl.bind_textdomain_codeset(GETTEXT_PACKAGE, "utf-8");
96 Intl.bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR);
97 }
const string GETTEXT_PACKAGE
Definition AppGtk.vala:30
const string LOCALE_DIR
Definition AppGtk.vala:32
void log_debug(string message)

References GETTEXT_PACKAGE, LOCALE_DIR, and TeeJee.Logging.log_debug().

Referenced by main().

◆ start_application()

void AppGtk.start_application ( bool recovery_mode = false)
inlinestatic

Definition at line 149 of file AppGtk.vala.

149 {
150
151 var window = new MainWindow();
152 var loop = new GLib.MainLoop(null, false);
153 window.close_request.connect(() => { loop.quit(); return false; });
154
155 // Mostra dialog recovery DOPO che la finestra è pronta
156 if (recovery_mode) {
157 window.present();
158 BastionGuardRecovery.show_recovery_banner(window);
159 } else {
160 // Controlla se c'è BastionGuardBackup da importare
161 ImportDialog.check_and_show_if_needed(window);
162 window.present();
163 }
164
165 loop.run();
166 }

References ImportDialog.check_and_show_if_needed(), and MainWindow.MainWindow().

Referenced by main().

◆ version_message()

string AppGtk.version_message ( )
inlinestaticprivate

Definition at line 118 of file AppGtk.vala.

118 {
119 return "%s %s\n".printf(AppName, AppVersion);
120 }

References AppName, and AppVersion.

Referenced by main().


The documentation for this class was generated from the following file:
  • BastionGuard/thirdparty/bastionguard-backup/src/AppGtk.vala