+ if not (model#iter_has_child row) then
+ raise Not_found;
+
+ let first_child = model#iter_children (Some row) in
+ loop first_child
+
+ (* Search up to the top of the tree so we know if this directory
+ * comes from an OS or a volume, and the full path to here.
+ *
+ * The path up the tree will always look something like:
+ * Top
+ * \_ Directory
+ * \_ Directory
+ * \_ Loading <--- you are here
+ *
+ * Note this function cannot be called on registry keys. See
+ * {!get_registry_path} for that.
+ *)
+ method get_pathname row =
+ let hdata = self#get_hdata row in
+ let parent = model#iter_parent row in
+
+ match hdata, parent with
+ | { state=IsLeaf; content=(Loading|ErrorMessage _|Info _) }, Some parent ->
+ self#get_pathname parent
+ | { state=IsLeaf; content=(Loading|ErrorMessage _|Info _) }, None ->
+ assert false
+ | { content=Directory { dent_name = name }}, Some parent
+ | { content=File { dent_name = name }}, Some parent ->
+ let src, parent_name = self#get_pathname parent in
+ let path =
+ if parent_name = "/" then "/" ^ name
+ else parent_name ^ "/" ^ name in
+ src, path
+ | { content=Top src }, _ -> src, "/"
+ | { content=Directory _ }, None -> assert false
+ | { content=File _ }, None -> assert false
+ | { content=Loading }, _ -> assert false
+ | { content=ErrorMessage _ }, _ -> assert false
+ | { content=Info _ }, _ -> assert false
+ | { content=TopWinReg _ }, _ -> assert false
+ | { content=RegKey _ }, _ -> assert false
+ | { content=RegValue _ }, _ -> assert false
+
+ method get_direntry row =
+ let hdata = self#get_hdata row in
+ match hdata with
+ | { content=Directory direntry}
+ | { content=File direntry} -> direntry
+ | _ -> assert false
+
+ (* Search up to the top of the tree from a registry key.
+ *
+ * The path up the tree will always look something like:
+ * TopWinReg
+ * \_ RegKey
+ * \_ RegKey <--- you are here
+ * \_ Loading <--- or here
+ *
+ * Note this function cannot be called on ordinary paths. Use
+ * {!get_pathname} for that.
+ *)
+ method get_registry_path row =
+ let hdata = self#get_hdata row in
+ let parent = model#iter_parent row in
+
+ match hdata, parent with
+ | { state=IsLeaf; content=(Loading|ErrorMessage _|Info _) }, Some parent ->
+ self#get_registry_path parent
+ | { state=IsLeaf; content=(Loading|ErrorMessage _|Info _) }, None ->
+ assert false
+ | { content=RegKey node; hiveh = Some h }, Some parent ->
+ let top, path = self#get_registry_path parent in
+ let path = Hivex.node_name h node :: path in
+ top, path
+ | { content=TopWinReg (a,b,c,d) }, None -> (a,b,c,d), []
+ | { content=TopWinReg _ }, _ -> assert false
+ | { content=RegKey _}, _ -> assert false
+ | { content=Top _ }, _ -> assert false
+ | { content=Directory _ }, _ -> assert false
+ | { content=File _ }, _ -> assert false
+ | { content=Loading }, _ -> assert false
+ | { content=ErrorMessage _ }, _ -> assert false
+ | { content=Info _ }, _ -> assert false
+ | { content=RegValue _ }, _ -> assert false
+
+ method get_registry_value row =
+ let hdata = self#get_hdata row in
+ match hdata with
+ | { content=RegValue value; hiveh = Some h } ->
+ Hivex.value_value h value
+ | _ -> assert false (* not a registry value *)
+
+ (* This is called whenever we need the registry cache file and we
+ can't be sure that it has already been downloaded. *)
+ method get_registry_file ?fail path (src, _, remotefile, cachefile) cb =
+ let row = model#get_iter path in
+ let top =
+ let rec loop row =
+ match model#iter_parent row with
+ | None -> row
+ | Some parent -> loop parent
+ in
+ loop row in
+
+ Slave.download_file_if_not_exist ?fail src remotefile cachefile
+ (self#when_got_registry_file ?fail top cb)
+
+ method private when_got_registry_file ?fail top cb () =
+ debug "when_got_registry_file";
+ let hdata = self#get_hdata top in
+
+ match hdata with
+ | { hiveh=Some _; content=TopWinReg (_, _, _, cachefile) } ->
+ (* Hive handle already opened. *)
+ cb cachefile
+
+ | { hiveh=None; content=TopWinReg (src, rootkey, remotefile, cachefile) } ->
+ (* Hive handle not opened, open it and save it in the handle. *)
+ (try
+ let flags = if verbose () then [ Hivex.OPEN_VERBOSE ] else [] in
+ let h = Hivex.open_file cachefile flags in
+ hdata.hiveh <- Some h;
+ cb cachefile
+ with
+ Hivex.Error _ as exn ->
+ match fail with
+ | Some fail -> fail exn
+ | None -> raise exn
+ )