+ let item = factory#add_item "Open" in
+ item#misc#set_sensitive false;
+
+ let rec add_file_items path =
+ 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 (factory#add_separator ());
+ let item = factory#add_item "Download ..." in
+ ignore (item#connect#activate ~callback:(download_file t path));
+
+ and add_directory_items path =
+ let item = factory#add_item "Directory information" in
+ item#misc#set_sensitive false;
+ let item = factory#add_item "Calculate disk usage" in
+ ignore (item#connect#activate ~callback:(disk_usage t path));
+ ignore (factory#add_separator ());
+ let item = factory#add_item "Download ..." in
+ 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));
+ let item = factory#add_item "Download as .tar.gz ..." in
+ ignore (item#connect#activate
+ ~callback:(download_dir_tarball t Slave.TGZ path));
+ let item = factory#add_item "Download as .tar.xz ..." in
+ ignore (item#connect#activate
+ ~callback:(download_dir_tarball t Slave.TXZ path));
+ let item = factory#add_item "Download list of filenames ..." in
+ ignore (item#connect#activate ~callback:(download_dir_find0 t path));
+
+ and add_os_items path =
+ let item = factory#add_item "Operating system information" in
+ ignore (item#connect#activate ~callback:(display_inspection_data t path));
+ ignore (factory#add_separator ());
+ add_volume_items path
+
+ and add_volume_items path =
+ let item = factory#add_item "Filesystem used & free" in
+ item#misc#set_sensitive false;
+ let item = factory#add_item "Block device information" in
+ item#misc#set_sensitive false;
+ ignore (factory#add_separator ());
+ add_directory_items path
+ in
+
+ (match paths with
+ (* single selection *)
+ | [path, { content=Top (Slave.OS os)} ] -> (* top level operating system *)
+ add_os_items path
+
+ | [path, { content=Top (Slave.Volume dev) }] -> (* top level volume *)
+ add_volume_items path
+
+ | [path, { content=Directory direntry }] -> (* directory *)
+ add_directory_items path
+
+ | [path, { content=File direntry }] -> (* file *)
+ add_file_items path
+
+ | [_, { content=Loading }]
+ | [_, { content=ErrorMessage _ }] -> ()
+
+ | _ ->
+ (* At the moment multiple selection is disabled. When/if we
+ * enable it we should do something intelligent here. XXX
+ *)
+ ()
+ );
+
+ menu
+
+let clear { model = model; hash = hash } =
+ model#clear ();
+ Hashtbl.clear hash
+
+let rec add ({ model = model } as t) name data =
+ clear t;
+
+ (* Populate the top level of the filetree. If there are operating
+ * systems from inspection, these have their own top level entries
+ * followed by only unreferenced filesystems. If we didn't get
+ * anything from inspection, then at the top level we just show
+ * filesystems.
+ *)
+ let other_filesystems =
+ DeviceSet.of_list (List.map fst data.Slave.insp_all_filesystems) in
+ let other_filesystems =
+ List.fold_left (fun set { Slave.insp_filesystems = fses } ->
+ DeviceSet.subtract set (DeviceSet.of_array fses))
+ other_filesystems data.Slave.insp_oses in
+
+ (* Add top level operating systems. *)
+ List.iter (add_top_level_os t name) data.Slave.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.Slave.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
+ | Some filename ->
+ add_top_level_winreg t name os "HKEY_LOCAL_MACHINE\\SECURITY"
+ filename
+ | None -> ()
+ );
+ (match os.Slave.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
+ | Some filename ->
+ add_top_level_winreg t name os "HKEY_LOCAL_MACHINE\\SYSTEM"
+ filename
+ | None -> ()
+ );
+ (match os.Slave.insp_winreg_DEFAULT with
+ | Some filename ->
+ add_top_level_winreg t name os "HKEY_USERS\\.DEFAULT" filename
+ | None -> ()
+ );
+ ) data.Slave.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.Slave.insp_hostname)
+ (markup_escape os.Slave.insp_product_name) in
+
+ let row = model#append () in
+ make_node t row (Top (Slave.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 (Slave.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 (Slave.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.
+ *)
+ Slave.download_file ~fail:(when_downloaded_registry_fail 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) } -> ()
+
+ (* These are not nodes so it should never be possible to open them. *)
+ | { content=(File _ | RegValue _) } | { state=IsLeaf } -> assert false
+
+ (* 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
+
+ (* Add the entries. *)
+ List.iter (
+ fun direntry ->
+ let { Slave.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
+ make_node t row (Directory direntry) None
+ else
+ make_leaf t row (File direntry) None;
+ model#set ~row ~column:t.name_col (markup_of_name direntry);
+ model#set ~row ~column:t.mode_col (markup_of_mode stat.G.mode);
+ model#set ~row ~column:t.size_col (markup_of_size stat.G.size);
+ model#set ~row ~column:t.date_col (markup_of_date stat.G.mtime);
+ ) entries;
+
+ (* Remove the placeholder "Loading" entry. NB. Must be done AFTER
+ * adding the other entries, or else Gtk will unexpand the row.