X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=filetree.ml;fp=filetree.ml;h=275c8682424ea224955d7d7157d0a1733a7f5003;hb=4fa4ca7430421c477e7f813819a8a70279de0a65;hp=2bf0b3d0cde035e7399ad545fc0354af363548f7;hpb=f09bb82de01019f24411cac2916d9567b5e9a235;p=guestfs-browser.git diff --git a/filetree.ml b/filetree.ml index 2bf0b3d..275c868 100644 --- a/filetree.ml +++ b/filetree.ml @@ -23,6 +23,7 @@ open Printf open Utils open DeviceSet +open Slave_types open Filetree_type open Filetree_markup @@ -32,8 +33,8 @@ module G = Guestfs type t = Filetree_type.t -(* Temporary directory for shared use by all instances of this widget, - * cleaned up when the program exits. +(* Temporary directory for shared use by any function in this file. + * It is cleaned up when the program exits. *) let tmpdir = tmpdir () @@ -171,10 +172,19 @@ and make_context_menu t paths = let factory = new GMenu.factory menu in let rec add_file_items path = + let item = factory#add_item "View ..." in + (match Config.opener with + | Some opener -> + ignore (item#connect#activate ~callback:(view_file t path opener)); + | None -> + item#misc#set_sensitive false + ); let item = factory#add_item "File information" in - item#misc#set_sensitive false; - let item = factory#add_item "Checksum" in - item#misc#set_sensitive false; + ignore (item#connect#activate ~callback:(file_information t path)); + let item = factory#add_item "MD5 checksum" in + ignore (item#connect#activate ~callback:(checksum_file t path "md5")); + let item = factory#add_item "SHA1 checksum" in + ignore (item#connect#activate ~callback:(checksum_file t path "sha1")); ignore (factory#add_separator ()); let item = factory#add_item "Download ..." in ignore (item#connect#activate ~callback:(download_file t path)); @@ -189,13 +199,13 @@ and make_context_menu t paths = item#misc#set_sensitive false; let item = factory#add_item "Download as .tar ..." in ignore (item#connect#activate - ~callback:(download_dir_tarball t Slave.Tar path)); + ~callback:(download_dir_tarball t Tar path)); let item = factory#add_item "Download as .tar.gz ..." in ignore (item#connect#activate - ~callback:(download_dir_tarball t Slave.TGZ path)); + ~callback:(download_dir_tarball t TGZ path)); let item = factory#add_item "Download as .tar.xz ..." in ignore (item#connect#activate - ~callback:(download_dir_tarball t Slave.TXZ path)); + ~callback:(download_dir_tarball t TXZ path)); let item = factory#add_item "Download list of filenames ..." in ignore (item#connect#activate ~callback:(download_dir_find0 t path)); @@ -221,7 +231,13 @@ and make_context_menu t paths = and add_regkey_items path = let item = factory#add_item "Download as .reg file ..." in - item#misc#set_sensitive false + (match Config.hivexregedit with + | Some hivexregedit -> + ignore (item#connect#activate + ~callback:(download_as_reg t path hivexregedit)); + | None -> + item#misc#set_sensitive false + ) and add_regvalue_items path = let item = factory#add_item "Copy value to clipboard" in @@ -234,10 +250,10 @@ and make_context_menu t paths = | [] -> false (* single selection *) - | [path, { content=Top (Slave.OS os)} ] -> (* top level operating system *) + | [path, { content=Top (OS os)} ] -> (* top level operating system *) add_top_os_items path; true - | [path, { content=Top (Slave.Volume dev) }] -> (* top level volume *) + | [path, { content=Top (Volume dev) }] -> (* top level volume *) add_top_volume_items path; true | [path, { content=Directory _ }] -> (* directory *) @@ -278,14 +294,14 @@ let rec add ({ model = model } as t) name data = * filesystems. *) let other_filesystems = - DeviceSet.of_list (List.map fst data.Slave.insp_all_filesystems) in + DeviceSet.of_list (List.map fst data.insp_all_filesystems) in let other_filesystems = - List.fold_left (fun set { Slave.insp_filesystems = fses } -> + List.fold_left (fun set { insp_filesystems = fses } -> DeviceSet.subtract set (DeviceSet.of_array fses)) - other_filesystems data.Slave.insp_oses in + other_filesystems data.insp_oses in (* Add top level operating systems. *) - List.iter (add_top_level_os t name) data.Slave.insp_oses; + List.iter (add_top_level_os t name) data.insp_oses; (* Add top level left-over filesystems. *) DeviceSet.iter (add_top_level_vol t name) other_filesystems; @@ -295,35 +311,35 @@ let rec add ({ model = model } as t) name data = *) List.iter ( fun os -> - (match os.Slave.insp_winreg_SAM with + (match os.insp_winreg_SAM with | Some filename -> add_top_level_winreg t name os "HKEY_LOCAL_MACHINE\\SAM" filename | None -> () ); - (match os.Slave.insp_winreg_SECURITY with + (match os.insp_winreg_SECURITY with | Some filename -> add_top_level_winreg t name os "HKEY_LOCAL_MACHINE\\SECURITY" filename | None -> () ); - (match os.Slave.insp_winreg_SOFTWARE with + (match os.insp_winreg_SOFTWARE with | Some filename -> add_top_level_winreg t name os "HKEY_LOCAL_MACHINE\\SOFTWARE" filename | None -> () ); - (match os.Slave.insp_winreg_SYSTEM with + (match os.insp_winreg_SYSTEM with | Some filename -> add_top_level_winreg t name os "HKEY_LOCAL_MACHINE\\SYSTEM" filename | None -> () ); - (match os.Slave.insp_winreg_DEFAULT with + (match os.insp_winreg_DEFAULT with | Some filename -> add_top_level_winreg t name os "HKEY_USERS\\.DEFAULT" filename | None -> () ); - ) data.Slave.insp_oses; + ) data.insp_oses; (* Expand the first top level node. *) match model#get_iter_first with @@ -335,11 +351,11 @@ let rec add ({ model = model } as t) name data = and add_top_level_os ({ model = model } as t) name os = let markup = sprintf "%s\n%s\n%s" - (markup_escape name) (markup_escape os.Slave.insp_hostname) - (markup_escape os.Slave.insp_product_name) in + (markup_escape name) (markup_escape os.insp_hostname) + (markup_escape os.insp_product_name) in let row = model#append () in - make_node t row (Top (Slave.OS os)) None; + make_node t row (Top (OS os)) None; model#set ~row ~column:t.name_col markup (* Add a top level volume (left over filesystem) node. *) @@ -349,7 +365,7 @@ and add_top_level_vol ({ model = model } as t) name dev = (markup_escape dev) (markup_escape name) in let row = model#append () in - make_node t row (Top (Slave.Volume dev)) None; + make_node t row (Top (Volume dev)) None; model#set ~row ~column:t.name_col markup (* Add a top level Windows Registry node. *) @@ -363,7 +379,7 @@ and add_top_level_winreg ({ model = model } as t) name os rootkey let row = model#append () in make_node t row - (TopWinReg (Slave.OS os, rootkey, remotefile, cachefile)) None; + (TopWinReg (OS os, rootkey, remotefile, cachefile)) None; model#set ~row ~column:t.name_col markup (* Generic function to make an openable node to the tree. *) @@ -429,8 +445,8 @@ and expand_row ({ model = model } as t) row _ = (* Since the user has opened this top level registry node for the * first time, we now need to download the hive. *) - Slave.download_file ~fail:(when_downloaded_registry_fail t path) - src remotefile cachefile (when_downloaded_registry t path) + cache_registry_file ~fail:(when_downloaded_registry_fail t path) + t path src remotefile cachefile (when_downloaded_registry t path) | { state=NodeNotStarted; content=RegKey node } as hdata -> (* User has opened a Windows Registry key node not previously opened. *) @@ -443,8 +459,10 @@ and expand_row ({ model = model } as t) row _ = (* Ignore when a user opens a node which is loading or has been loaded. *) | { state=(NodeLoading|IsNode) } -> () - (* These are not nodes so it should never be possible to open them. *) - | { content=(File _ | RegValue _) } | { state=IsLeaf } -> assert false + (* In some circumstances these can be nodes, eg. if we have added Info + * nodes below them. Just ignore them if opened. + *) + | { content=(File _ | RegValue _) } | { state=IsLeaf } -> () (* Node should not exist in the tree. *) | { state=NodeNotStarted; content=(Loading | ErrorMessage _ | Info _) } -> @@ -457,7 +475,7 @@ and when_read_directory ({ model = model } as t) path entries = let row = model#get_iter path in (* Sort the entries by lexicographic ordering. *) - let cmp { Slave.dent_name = n1 } { Slave.dent_name = n2 } = + let cmp { dent_name = n1 } { dent_name = n2 } = UTF8.compare n1 n2 in let entries = List.sort ~cmp entries in @@ -465,7 +483,7 @@ and when_read_directory ({ model = model } as t) path entries = (* Add the entries. *) List.iter ( fun direntry -> - let { Slave.dent_name = name; dent_stat = stat; dent_link = link } = + let { dent_name = name; dent_stat = stat; dent_link = link } = direntry in let row = model#append ~parent:row () in if is_directory stat.G.mode then @@ -522,23 +540,12 @@ and when_read_directory_fail ({ model = model } as t) path exn = and when_downloaded_registry ({ model = model } as t) path () = debug "when_downloaded_registry"; let row = model#get_iter path in - let hdata = get_hdata t row in - match hdata.content with - | TopWinReg (src, rootkey, remotefile, cachefile) -> - (try - (* Open the hive and save the hive handle in the row hdata. *) - let flags = if verbose () then [ Hivex.OPEN_VERBOSE ] else [] in - let h = Hivex.open_file cachefile flags in - hdata.hiveh <- Some h; - - (* Continue as if expanding any other hive node. *) - let root = Hivex.root h in - expand_hive_node t row root - with - Hivex.Error _ as exn -> when_downloaded_registry_fail t path exn - ) - | _ -> assert false + let h = Option.get hdata.hiveh in + + (* Continue as if expanding any other hive node. *) + let root = Hivex.root h in + expand_hive_node t row root (* Called instead of {!when_downloaded_registry} if the download failed. *) and when_downloaded_registry_fail ({ model = model } as t) path exn =