slave: Use slightly modified event_callback.
[guestfs-browser.git] / op_download_as_reg.ml
1 (* Guestfs Browser.
2  * Copyright (C) 2011 Red Hat Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
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.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  *)
18
19 open Utils
20
21 open Printf
22
23 let rec download_as_reg (tree : Filetree.tree) (path, hivexregedit) =
24   let model = tree#model in
25   let row = model#get_iter path in
26
27   (* Get path to the top of the registry tree. *)
28   let registry, nodes = tree#get_registry_path row in
29   let regpath = String.concat "\\" (List.rev nodes) in
30   let rootkey = Filetree.root_key_of_registry_t registry in
31   debug "download_as_reg: %s %s" rootkey regpath;
32
33   (* Force the registry to be downloaded, if not already. *)
34   tree#get_registry_file path registry
35     (when_downloaded tree path hivexregedit rootkey nodes regpath)
36
37 and when_downloaded tree path hivexregedit rootkey nodes regpath cachefile =
38   (* Put up the dialog. *)
39   let title = "Download as .reg file" in
40   let dlg = GWindow.file_chooser_dialog ~action:`SAVE ~title ~modal:true () in
41   dlg#add_button_stock `CANCEL `CANCEL;
42   dlg#add_select_button_stock `SAVE `SAVE;
43   let name = match nodes with [] -> rootkey | (name::_) -> name in
44   dlg#set_current_name (name ^ ".reg");
45
46   match dlg#run () with
47   | `DELETE_EVENT | `CANCEL ->
48       dlg#destroy ()
49   | `SAVE ->
50       match dlg#filename with
51       | None -> ()
52       | Some localfile ->
53           dlg#destroy ();
54
55           (* Use hivexregedit to save it. *)
56           let cmd =
57             sprintf "%s --export --prefix %s %s %s > %s"
58               (Filename.quote hivexregedit)
59               (Filename.quote rootkey) (Filename.quote cachefile)
60               (Filename.quote regpath) (Filename.quote localfile) in
61           Slave.run_command cmd Slave.no_callback