2 * Drivers acquiring installation utility
3 * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; exactly version 2 of June 1991 is required
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <glib/gmessages.h>
28 #include <glib/ghash.h>
29 #include <glib/gstrfuncs.h>
33 #include <libgnomevfs/gnome-vfs-init.h>
35 #include "microsoftcom.h"
36 #include <libgnomevfs/gnome-vfs-uri.h>
38 #include "moduriload.h"
39 #include <libgnome/gnome-program.h>
40 #include <libgnomeui/gnome-ui-init.h>
44 #ifdef ENABLE_STANDALONE
45 #include "standalone-libntfs.h"
48 #include <captive/macros.h>
49 #include <captive/client.h>
50 #include <captive/captivemodid.h>
53 CaptiveCaptivemodidObject *captivemodid;
57 static int optarg_microsoft_com;
58 static int optarg_scan_disks;
59 static int optarg_scan_disks_quick;
60 static int optarg_text;
61 static GList *optarg_scan_path_list; /* of (char *) */
63 static void acquire_popt_callback
64 (poptContext con,enum poptCallbackReason reason,const struct poptOption *opt,const char *arg,const void *data);
66 static const struct poptOption popt_table[]={
67 { argInfo:POPT_ARG_CALLBACK,arg:(void *)acquire_popt_callback },
69 #define BUG_ACQUIRE_POPT(shortname,longname,argInfoP,argP,valP,descripP,argDescripP) \
71 longName: (longname), \
72 shortName: (shortname), \
73 argInfo: (argInfoP)|(!(valP) ? 0 : POPT_ARG_VAL), \
76 descrip: (descripP), \
77 argDescrip: (argDescripP), \
80 BUG_ACQUIRE_POPT(0 ,"text" ,POPT_ARG_NONE ,&optarg_text ,0,
81 N_("Disable Gnome UI; --text must be first argument"),NULL),
82 BUG_ACQUIRE_POPT('v',"verbose" ,POPT_ARG_NONE ,&optarg_verbose,0,N_("Display additional debug information"),NULL),
83 BUG_ACQUIRE_POPT('n',"dry" ,POPT_ARG_NONE ,&optarg_dry ,0,N_("No modifications, no files written"),NULL),
84 BUG_ACQUIRE_POPT(0 ,"scan-disks" ,POPT_ARG_NONE ,&optarg_scan_disks,0,N_("Scan all files on local disks"),NULL),
85 BUG_ACQUIRE_POPT(0 ,"scan-disks-quick",POPT_ARG_NONE ,&optarg_scan_disks_quick,0,
86 N_("Scan MS-Windows directories on local disks"),NULL),
87 BUG_ACQUIRE_POPT(0 ,"scan-path" ,POPT_ARG_STRING,NULL ,0,
88 N_("Scan specified disk path or web URL"),N_("path/URI")),
89 BUG_ACQUIRE_POPT(0 ,"microsoft-com" ,POPT_ARG_NONE ,&optarg_microsoft_com,0,
90 N_("Download from microsoft.com; Legal: You may need to have valid Microsoft Windows XP license."),NULL),
92 #undef BUG_ACQUIRE_POPT
96 static const struct poptOption popt_table_autohelp[]={
97 { NULL,'\0',POPT_ARG_INCLUDE_TABLE,(struct poptOption *)&popt_table,0,PACKAGE },
102 /* poptCallbackType captive_popt_callback */
103 static void acquire_popt_callback
104 (poptContext con,enum poptCallbackReason reason,const struct poptOption *opt,const char *arg,const void *data)
106 g_return_if_fail(reason==POPT_CALLBACK_REASON_OPTION);
108 if (opt->longName && !strcmp(opt->longName,"scan-path")) {
109 optarg_scan_path_list=g_list_append(optarg_scan_path_list,gnome_vfs_uri_new(arg));
114 void (*ui_interactive)(void);
116 static gboolean ui_progress_dummy(GnomeVFSURI *uri)
118 /* 'uri' may be NULL */
120 return FALSE; /* not aborted */
123 gboolean (*ui_progress)(GnomeVFSURI *uri)=ui_progress_dummy;
124 void (*ui_progress_bar)(gint done,gint length);
126 static GList *mod_uri_list_local;
127 static void mod_uri_list_local_init(void)
129 if (mod_uri_list_local)
131 mod_uri_list_local=mod_uri_list();
134 void scan_disks_quick(void)
136 GList *mod_uri_list_quick_local,*mod_uri_l;
138 mod_uri_list_local_init();
139 mod_uri_list_quick_local=NULL;
140 for (mod_uri_l=mod_uri_list_local;mod_uri_l;mod_uri_l=mod_uri_l->next) {
141 mod_uri_list_quick_local=g_list_prepend(mod_uri_list_quick_local,
142 gnome_vfs_uri_append_path(mod_uri_l->data,"windows/system32"));
144 mod_uri_list_quick_local=g_list_reverse(mod_uri_list_quick_local);
145 g_list_foreach(mod_uri_list_quick_local,(GFunc)mod_uri_load,NULL);
146 gnome_vfs_uri_list_free(mod_uri_list_quick_local);
149 void scan_disks(void)
151 mod_uri_list_local_init();
152 g_list_foreach(mod_uri_list_local,(GFunc)mod_uri_load,NULL);
155 void microsoft_com(void)
157 g_list_foreach(mod_uri_microsoftcom_list(),(GFunc)mod_uri_load_base_reporting,NULL);
160 static void scan_batch(void)
162 g_list_foreach(optarg_scan_path_list,(GFunc)mod_uri_load_base_reporting,NULL);
164 if (optarg_scan_disks_quick)
166 if (optarg_scan_disks)
168 if (optarg_microsoft_com)
172 static jmp_buf gnome_init_atexit_jmpbuf;
173 static gboolean gnome_init_atexit_disable;
175 static void gnome_init_atexit_handler(void)
177 if (gnome_init_atexit_disable)
180 longjmp(gnome_init_atexit_jmpbuf,1);
181 g_assert_not_reached();
185 gboolean gnome_init_g_log_handler_hit;
186 static void gnome_init_g_log_handler(const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,gpointer user_data)
188 gnome_init_g_log_handler_hit=TRUE;
189 g_log_default_handler(log_domain,log_level,message,user_data);
192 int main(int argc,char **argv)
196 gboolean is_interactive;
200 g_log_set_always_fatal(~(0
207 captive_standalone_init();
209 if (!gnome_vfs_init())
210 g_error(_("GnomeVFS failed to initialize"));
212 #ifdef ENABLE_STANDALONE
213 standalone_libntfs_init();
216 if (argv[1] && !strcmp(argv[1],"--text"))
219 no_gnome=(optarg_text || !getenv("DISPLAY") || !*getenv("DISPLAY"));
222 context=poptGetContext(
224 argc,(/*en-const*/const char **)argv, /* argc,argv */
225 popt_table_autohelp, /* options */
226 POPT_CONTEXT_POSIXMEHARDER); /* flags; && !POPT_CONTEXT_KEEP_FIRST */
228 g_assert_not_reached(); /* argument recognization args_error */
231 errint=poptReadDefaultConfig(context,
234 g_assert_not_reached(); /* argument recognization args_error */
237 errint=poptGetNextOpt(context);
239 g_assert_not_reached(); /* some non-callbacked argument reached */
242 if (poptPeekArg(context)) {
243 g_error(_("No arguments expected"));
248 GnomeProgram *gnome_program;
251 captive_standalone_gnome_init();
252 gnome_init_atexit_disable=FALSE;
253 g_atexit(gnome_init_atexit_handler);
254 gnome_init_g_log_handler_hit=FALSE;
255 handler_id=g_log_set_handler(
256 "Gtk", /* log_domain */
257 G_LOG_LEVEL_WARNING, /* log_levels */
258 gnome_init_g_log_handler, /* log_func */
259 NULL); /* user_data */
260 if (!setjmp(gnome_init_atexit_jmpbuf))
261 gnome_program=gnome_program_init(PACKAGE,VERSION,LIBGNOMEUI_MODULE,argc,argv,
262 GNOME_PARAM_POPT_TABLE,popt_table,
263 GNOME_PARAM_POPT_FLAGS,(int)POPT_CONTEXT_POSIXMEHARDER,
267 /* No message: (captive-install-acquire:3693): Gtk-WARNING **: cannot open display:
268 * was reported, probably only '--help' message was shown.
270 if (!gnome_init_g_log_handler_hit)
273 gnome_init_atexit_disable=TRUE;
274 g_log_remove_handler(
275 "Gtk", /* log_domain */
276 handler_id); /* handler_id */
280 && ! optarg_scan_path_list
281 && ! optarg_scan_disks_quick
282 && ! optarg_scan_disks
283 && ! optarg_microsoft_com);
285 /* Initialize UI here to catch all GLog errors below. */
287 && (no_gnome || !ui_gnome_init())
289 g_error(_("No UI interface could be initialized"));
291 captivemodid=captive_captivemodid_load_default(TRUE);
293 mod_uri_load_base_reporting(gnome_vfs_uri_new("file://" G_STRINGIFY(VARLIBCAPTIVEDIR)));
300 gnome_vfs_shutdown();