+
+(* View a single file. *)
+let rec view_file ({ model = model } as t) path opener () =
+ let row = model#get_iter path in
+ let src, pathname = get_pathname t row in
+ debug "view_file %s" pathname;
+
+ (* Download the file into a temporary directory. *)
+ let ext = extension pathname in
+ let localfile = tmpdir // string_of_int (unique ()) ^ ext in
+ Slave.download_file src pathname localfile
+ (when_downloaded_file_for_view t path opener localfile)
+
+and when_downloaded_file_for_view ({ model = model } as t) path
+ opener localfile () =
+ let row = model#get_iter path in
+ set_visited t row;
+
+ let cmd =
+ sprintf "%s %s" (Filename.quote opener) (Filename.quote localfile) in
+ Slave.run_command cmd Slave.no_callback
+
+(* Compute the checksum of a file. *)
+let rec checksum_file ({ model = model } as t) path csumtype () =
+ let row = model#get_iter path in
+ let src, pathname = get_pathname t row in
+ debug "checksum_file %s" pathname;
+
+ (* See if this node already has an Info "checksum" child
+ * node. If so they don't recreate it.
+ *)
+ let content = Info ("checksum:" ^ csumtype) in
+ if not (has_child_node_equals t row content) then (
+ let row = model#insert ~parent:row 0 in
+ let hdata =
+ { state=IsLeaf; content=content; visited=false; hiveh=None } in
+ store_hdata t row hdata;
+ model#set ~row ~column:t.name_col
+ (sprintf "<i>Calculating %s ...</i>" csumtype);
+
+ t.view#expand_row path;
+
+ Slave.checksum_file src pathname csumtype
+ (when_checksum_file t path pathname csumtype)
+ )
+
+and when_checksum_file ({ model = model } as t) path pathname csumtype checksum=
+ let row = model#get_iter path in
+ set_visited t row;
+
+ (* Find the child node added above, and replace the text. *)
+ try
+ let content = Info ("checksum:" ^ csumtype) in
+ let row = find_child_node_by_content t row content in
+ let msg = sprintf "%s: %s" csumtype checksum in
+ model#set ~row ~column:t.name_col msg
+ with
+ Not_found -> ()
+
+(* Compute the file information of a file. *)
+let rec file_information ({ model = model } as t) path () =
+ let row = model#get_iter path in
+ let src, pathname = get_pathname t row in
+ debug "file_information %s" pathname;
+
+ (* See if this node already has an Info "file_information" child
+ * node. If so they don't recreate it.
+ *)
+ let content = Info "file_information" in
+ if not (has_child_node_equals t row content) then (
+ let row = model#insert ~parent:row 0 in
+ let hdata =
+ { state=IsLeaf; content=content; visited=false; hiveh=None } in
+ store_hdata t row hdata;
+ model#set ~row ~column:t.name_col "<i>Calculating file information ...</i>";
+
+ t.view#expand_row path;
+
+ Slave.file_information src pathname (when_file_information t path pathname)
+ )
+
+and when_file_information ({ model = model } as t) path pathname info =
+ let row = model#get_iter path in
+ set_visited t row;
+
+ (* Find the child node added above, and replace the text. *)
+ try
+ let content = Info "file_information" in
+ let row = find_child_node_by_content t row content in
+ model#set ~row ~column:t.name_col (markup_escape info)
+ with
+ Not_found -> ()
+
+(* Export a registry key/subkey tree as a reg file. This is pretty
+ * effortless with hivexregedit.
+ *)
+let download_as_reg ({ model = model } as t) path hivexregedit () =
+ let row = model#get_iter path in
+ let hdata = get_hdata t row in
+
+ (* Get path to the top of the registry tree. *)
+ let (_, rootkey, _, cachefile), nodes = get_registry_path t row in
+ let regpath = String.concat "\\" (List.rev nodes) in
+ debug "download_as_reg: %s %s %s" cachefile rootkey regpath;
+
+ let do_dialog () =
+ (* Put up the dialog. *)
+ let title = "Download as .reg file" in
+ let dlg = GWindow.file_chooser_dialog
+ ~action:`SAVE ~title ~modal:true () in
+ dlg#add_button_stock `CANCEL `CANCEL;
+ dlg#add_select_button_stock `SAVE `SAVE;
+ let name = match nodes with [] -> rootkey | (name::_) -> name in
+ dlg#set_current_name (name ^ ".reg");
+
+ match dlg#run () with
+ | `DELETE_EVENT | `CANCEL ->
+ dlg#destroy ()
+ | `SAVE ->
+ match dlg#filename with
+ | None -> ()
+ | Some localfile ->
+ dlg#destroy ();
+
+ (* Use hivexregedit to save it. *)
+ let cmd =
+ sprintf "%s --export --prefix %s %s %s > %s"
+ (Filename.quote hivexregedit)
+ (Filename.quote rootkey) (Filename.quote cachefile)
+ (Filename.quote regpath) (Filename.quote localfile) in
+ Slave.run_command cmd Slave.no_callback
+ in
+
+ match hdata with
+ | { content=RegKey _ } ->
+ do_dialog ()
+
+ | { content=TopWinReg (src, _, remotefile, cachefile) } ->
+ (* There's a subtle problem here: If the top node has not been
+ * opened, the registry cachefile won't have been downloaded. If
+ * the top node has been opened, the registry might still be
+ * being downloaded as we are running here. Either way we can't
+ * trust the cachefile. Tell the slave thread to download the
+ * file if it's not downloaded already (since the slave thread
+ * runs in a serial loop, this is always race free).
+ *)
+ cache_registry_file t path src remotefile cachefile do_dialog
+
+ | _ -> () (* not a registry key, ignore *)