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 #include <captive/macros.h>
45 #include <captive/client.h>
50 static int optarg_microsoft_com;
51 static int optarg_scan_disks;
52 static int optarg_scan_disks_quick;
53 static int optarg_text;
54 static char *optarg_modid_path=G_STRINGIFY(SYSCONFDIR) "/w32-mod-id.captivemodid.xml";
55 static GList *optarg_scan_path_list; /* of (char *) */
57 static void acquire_popt_callback
58 (poptContext con,enum poptCallbackReason reason,const struct poptOption *opt,const char *arg,const void *data);
60 static const struct poptOption popt_table[]={
61 { argInfo:POPT_ARG_CALLBACK,arg:(void *)acquire_popt_callback },
63 #define BUG_ACQUIRE_POPT(shortname,longname,argInfoP,argP,valP,descripP,argDescripP) \
65 longName: (longname), \
66 shortName: (shortname), \
67 argInfo: (argInfoP)|(!(valP) ? 0 : POPT_ARG_VAL), \
70 descrip: (descripP), \
71 argDescrip: (argDescripP), \
74 BUG_ACQUIRE_POPT(0 ,"text" ,POPT_ARG_NONE ,&optarg_text ,0,
75 N_("Disable Gnome UI; --text must be first argument"),NULL),
76 BUG_ACQUIRE_POPT('v',"verbose" ,POPT_ARG_NONE ,&optarg_verbose,0,N_("Display additional debug information"),NULL),
77 BUG_ACQUIRE_POPT('n',"dry" ,POPT_ARG_NONE ,&optarg_dry ,0,N_("No modifications, no files written"),NULL),
78 BUG_ACQUIRE_POPT(0 ,"modid-path" ,POPT_ARG_STRING|POPT_ARGFLAG_SHOW_DEFAULT,&optarg_modid_path,0,
79 N_("Path to .captivemodid.xml database"),N_("path")),
80 BUG_ACQUIRE_POPT(0 ,"scan-disks" ,POPT_ARG_NONE ,&optarg_scan_disks,0,N_("Scan all files on local disks"),NULL),
81 BUG_ACQUIRE_POPT(0 ,"scan-disks-quick",POPT_ARG_NONE ,&optarg_scan_disks_quick,0,
82 N_("Scan MS-Windows directories on local disks"),NULL),
83 BUG_ACQUIRE_POPT(0 ,"scan-path" ,POPT_ARG_STRING,NULL ,0,
84 N_("Scan specified disk path or web URL"),N_("path/URI")),
85 BUG_ACQUIRE_POPT(0 ,"microsoft-com" ,POPT_ARG_NONE ,&optarg_microsoft_com,0,
86 N_("Download from microsoft.com; Legal: You may need to have valid Microsoft Windows XP license."),NULL),
88 #undef BUG_ACQUIRE_POPT
92 static const struct poptOption popt_table_autohelp[]={
93 { NULL,'\0',POPT_ARG_INCLUDE_TABLE,(struct poptOption *)&popt_table,0,PACKAGE },
98 /* poptCallbackType captive_popt_callback */
99 static void acquire_popt_callback
100 (poptContext con,enum poptCallbackReason reason,const struct poptOption *opt,const char *arg,const void *data)
102 g_return_if_fail(reason==POPT_CALLBACK_REASON_OPTION);
104 if (opt->longName && !strcmp(opt->longName,"scan-path")) {
105 optarg_scan_path_list=g_list_append(optarg_scan_path_list,gnome_vfs_uri_new(arg));
110 void (*ui_interactive)(void);
112 static gboolean ui_progress_dummy(GnomeVFSURI *uri)
114 /* 'uri' may be NULL */
116 return FALSE; /* not aborted */
119 gboolean (*ui_progress)(GnomeVFSURI *uri)=ui_progress_dummy;
120 void (*ui_progress_bar)(gint done,gint length);
122 static GList *mod_uri_list_local;
123 static void mod_uri_list_local_init(void)
125 if (mod_uri_list_local)
127 mod_uri_list_local=mod_uri_list();
130 void scan_disks_quick(void)
132 GList *mod_uri_list_quick_local,*mod_uri_l;
134 mod_uri_list_local_init();
135 mod_uri_list_quick_local=NULL;
136 for (mod_uri_l=mod_uri_list_local;mod_uri_l;mod_uri_l=mod_uri_l->next) {
137 mod_uri_list_quick_local=g_list_prepend(mod_uri_list_quick_local,
138 gnome_vfs_uri_append_path(mod_uri_l->data,"windows/system32"));
140 mod_uri_list_quick_local=g_list_reverse(mod_uri_list_quick_local);
141 g_list_foreach(mod_uri_list_quick_local,(GFunc)mod_uri_load,NULL);
142 gnome_vfs_uri_list_free(mod_uri_list_quick_local);
145 void scan_disks(void)
147 mod_uri_list_local_init();
148 g_list_foreach(mod_uri_list_local,(GFunc)mod_uri_load,NULL);
151 void microsoft_com(void)
153 g_list_foreach(mod_uri_microsoftcom_list(),(GFunc)mod_uri_load_base_reporting,NULL);
156 static void scan_batch(void)
158 g_list_foreach(optarg_scan_path_list,(GFunc)mod_uri_load_base_reporting,NULL);
160 if (optarg_scan_disks_quick)
162 if (optarg_scan_disks)
164 if (optarg_microsoft_com)
168 static jmp_buf gnome_init_atexit_jmpbuf;
169 static gboolean gnome_init_atexit_disable;
171 static void gnome_init_atexit_handler(void)
173 if (gnome_init_atexit_disable)
176 longjmp(gnome_init_atexit_jmpbuf,1);
177 g_assert_not_reached();
181 gboolean gnome_init_g_log_handler_hit;
182 static void gnome_init_g_log_handler(const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,gpointer user_data)
184 gnome_init_g_log_handler_hit=TRUE;
185 g_log_default_handler(log_domain,log_level,message,user_data);
188 int main(int argc,char **argv)
192 gboolean is_interactive;
196 g_log_set_always_fatal(~(0
203 captive_standalone_init();
205 if (!gnome_vfs_init())
206 g_error(_("GnomeVFS failed to initialize"));
208 if (argv[1] && !strcmp(argv[1],"--text"))
211 no_gnome=(optarg_text || !getenv("DISPLAY") || !*getenv("DISPLAY"));
214 context=poptGetContext(
216 argc,(/*en-const*/const char **)argv, /* argc,argv */
217 popt_table_autohelp, /* options */
218 POPT_CONTEXT_POSIXMEHARDER); /* flags; && !POPT_CONTEXT_KEEP_FIRST */
220 g_assert_not_reached(); /* argument recognization args_error */
223 errint=poptReadDefaultConfig(context,
226 g_assert_not_reached(); /* argument recognization args_error */
229 errint=poptGetNextOpt(context);
231 g_assert_not_reached(); /* some non-callbacked argument reached */
234 if (poptPeekArg(context)) {
235 g_error(_("No arguments expected"));
240 GnomeProgram *gnome_program;
243 captive_standalone_gnome_init();
244 gnome_init_atexit_disable=FALSE;
245 g_atexit(gnome_init_atexit_handler);
246 gnome_init_g_log_handler_hit=FALSE;
247 handler_id=g_log_set_handler(
248 "Gtk", /* log_domain */
249 G_LOG_LEVEL_WARNING, /* log_levels */
250 gnome_init_g_log_handler, /* log_func */
251 NULL); /* user_data */
252 if (!setjmp(gnome_init_atexit_jmpbuf))
253 gnome_program=gnome_program_init(PACKAGE,VERSION,LIBGNOMEUI_MODULE,argc,argv,
254 GNOME_PARAM_POPT_TABLE,popt_table,
255 GNOME_PARAM_POPT_FLAGS,(int)POPT_CONTEXT_POSIXMEHARDER,
259 /* No message: (captive-install-acquire:3693): Gtk-WARNING **: cannot open display:
260 * was reported, probably only '--help' message was shown.
262 if (!gnome_init_g_log_handler_hit)
265 gnome_init_atexit_disable=TRUE;
266 g_log_remove_handler(
267 "Gtk", /* log_domain */
268 handler_id); /* handler_id */
272 && ! optarg_scan_path_list
273 && ! optarg_scan_disks_quick
274 && ! optarg_scan_disks
275 && ! optarg_microsoft_com);
277 /* Initialize UI here to catch all GLog errors below. */
279 && (no_gnome || !ui_gnome_init())
281 g_error(_("No UI interface could be initialized"));
283 if (!captive_captivemodid_load(optarg_modid_path) && !captive_captivemodid_load("./w32-mod-id.captivemodid.xml"))
284 g_error(_("Unable to load modid database: %s"),optarg_modid_path);
286 mod_uri_load_base_reporting(gnome_vfs_uri_new("file://" G_STRINGIFY(VARLIBCAPTIVEDIR)));
293 gnome_vfs_shutdown();