+ let other_filesystems =
+ DeviceSet.of_list (List.map fst data.insp_all_filesystems) in
+ let other_filesystems =
+ List.fold_left (fun set { insp_filesystems = fses } ->
+ DeviceSet.subtract set (DeviceSet.of_array fses))
+ other_filesystems data.insp_oses in
+
+ (* Add top level operating systems. *)
+ 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;
+
+ (* If it's Windows and registry files exist, create a node for
+ * each file.
+ *)
+ List.iter (
+ fun os ->
+ (match os.insp_winreg_SAM with
+ | Some filename ->
+ add_top_level_winreg t name os "HKEY_LOCAL_MACHINE\\SAM" filename
+ | None -> ()
+ );
+ (match os.insp_winreg_SECURITY with
+ | Some filename ->
+ add_top_level_winreg t name os "HKEY_LOCAL_MACHINE\\SECURITY"
+ filename
+ | None -> ()
+ );
+ (match os.insp_winreg_SOFTWARE with
+ | Some filename ->
+ add_top_level_winreg t name os "HKEY_LOCAL_MACHINE\\SOFTWARE"
+ filename
+ | None -> ()
+ );
+ (match os.insp_winreg_SYSTEM with
+ | Some filename ->
+ add_top_level_winreg t name os "HKEY_LOCAL_MACHINE\\SYSTEM"
+ filename
+ | None -> ()
+ );
+ (match os.insp_winreg_DEFAULT with
+ | Some filename ->
+ add_top_level_winreg t name os "HKEY_USERS\\.DEFAULT" filename
+ | None -> ()
+ );
+ ) data.insp_oses;
+
+ (* Expand the first top level node. *)
+ match model#get_iter_first with
+ | None -> ()
+ | Some row ->
+ t.view#expand_row (model#get_path row)
+
+(* Add a top level operating system node. *)
+and add_top_level_os ({ model = model } as t) name os =
+ let markup =
+ sprintf "<b>%s</b>\n<small>%s</small>\n<small>%s</small>"
+ (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 (OS os)) None;
+ model#set ~row ~column:t.name_col markup
+
+(* Add a top level volume (left over filesystem) node. *)
+and add_top_level_vol ({ model = model } as t) name dev =
+ let markup =
+ sprintf "<b>%s</b>\n<small>from %s</small>"
+ (markup_escape dev) (markup_escape name) in
+
+ let row = model#append () in
+ make_node t row (Top (Volume dev)) None;
+ model#set ~row ~column:t.name_col markup
+
+(* Add a top level Windows Registry node. *)
+and add_top_level_winreg ({ model = model } as t) name os rootkey
+ remotefile =
+ let cachefile = tmpdir // string_of_int (unique ()) ^ ".hive" in
+
+ let markup =
+ sprintf "<b>%s</b>\n<small>from %s</small>"
+ (markup_escape rootkey) (markup_escape name) in
+
+ let row = model#append () in
+ make_node t row
+ (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. *)
+and make_node ({ model = model } as t) row content hiveh =
+ let hdata =
+ { state=NodeNotStarted; content=content; visited=false; hiveh=hiveh } in
+ store_hdata t row hdata;
+
+ (* Create a placeholder "loading ..." row underneath this node so
+ * the user has something to expand.
+ *)
+ let placeholder = model#append ~parent:row () in
+ let hdata = { state=IsLeaf; content=Loading; visited=false; hiveh=None } in
+ store_hdata t placeholder hdata;
+ model#set ~row:placeholder ~column:t.name_col "<i>Loading ...</i>";
+ ignore (t.view#connect#row_expanded ~callback:(expand_row t))
+
+and make_leaf ({ model = model } as t) row content hiveh =
+ let hdata = { state=IsLeaf; content=content; visited=false; hiveh=hiveh } in
+ store_hdata t row hdata
+
+(* This is called when the user expands a row. *)
+and expand_row ({ model = model } as t) row _ =
+ match get_hdata t row with
+ | { state=NodeNotStarted; content=Top src } as hdata ->
+ (* User has opened a top level node that was not previously opened. *)
+
+ (* Mark this row as loading, so we don't try to open it again. *)
+ hdata.state <- NodeLoading;
+
+ (* Get a stable path for this row. *)
+ let path = model#get_path row in
+
+ Slave.read_directory ~fail:(when_read_directory_fail t path)
+ src "/" (when_read_directory t path)
+
+ | { state=NodeNotStarted; content=Directory direntry } as hdata ->
+ (* User has opened a filesystem directory not previously opened. *)
+
+ (* Mark this row as loading. *)
+ hdata.state <- NodeLoading;
+
+ (* Get a stable path for this row. *)
+ let path = model#get_path row in
+
+ let src, pathname = get_pathname t row in
+
+ Slave.read_directory ~fail:(when_read_directory_fail t path)
+ src pathname (when_read_directory t path)
+
+ | { state=NodeNotStarted;
+ content=TopWinReg (src, rootkey, remotefile, cachefile) } as hdata ->
+ (* User has opened a Windows Registry top level node
+ * not previously opened.
+ *)
+
+ (* Mark this row as loading. *)
+ hdata.state <- NodeLoading;
+
+ (* Get a stable path for this row. *)
+ let path = model#get_path row in
+
+ (* Since the user has opened this top level registry node for the
+ * first time, we now need to download the hive.
+ *)
+ 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. *)
+
+ (* Mark this row as loading. *)
+ hdata.state <- NodeLoading;
+
+ expand_hive_node t row node
+
+ (* Ignore when a user opens a node which is loading or has been loaded. *)
+ | { state=(NodeLoading|IsNode) } -> ()
+
+ (* 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 _) } ->
+ assert false
+
+(* This is the callback when the slave has read the directory for us. *)
+and when_read_directory ({ model = model } as t) path entries =
+ debug "when_read_directory";
+
+ let row = model#get_iter path in
+
+ (* Sort the entries by lexicographic ordering. *)
+ let cmp { dent_name = n1 } { dent_name = n2 } =
+ UTF8.compare n1 n2