A file node.
Inheritance: FileSystemNode, IFile
Exemple #1
0
 public static FileType GetFileType(File file)
 {
     foreach (FileType type in m_Extensions.Keys) {
         if (IsFileType(file, type)) {
             return type;
         }
     }
     return FileType.Unknown;
 }
Exemple #2
0
 public RegistryHive(File file)
 {
     m_stream = file;
     try {
         m_root = new RegistryKey(m_stream);
     } catch {
         throw new Exception("Not a valid hive");
     }
 }
        public ExplorerHistoryFile(File file, Folder parent, ExplorerHistoryType type)
        {
            m_Records = new List<ExplorerHistoryRecord>();
            Path = file.Path;
            Stream = file;
            if (file != null) {
                string headerStr = Util.GetASCIIString(file, 0, HEADER_SIZE);
                if (headerStr == "Client UrlCache MMF Ver 5.2") {
                    Type = type;

                    // Read cache directories
                    List<Folder> cachedirs = new List<Folder>();
                    ulong cache_offset = 0x50;
                    string cache = Util.GetASCIIString(file, cache_offset, Util.StrLen(file, cache_offset, 8));
                    while (cache != "") {
                        foreach (FileSystemNode node in parent.GetChildren(cache)) {
                            if (node is Folder) {
                                cachedirs.Add(node as Folder);
                                break;
                            }
                        }
                        cache_offset += 12;
                        cache = Util.GetASCIIString(file, cache_offset, Util.StrLen(file, cache_offset, 8));
                    }

                    ulong offset = 0x4000;
                    while (offset < file.StreamLength) {
                        uint numBlocks = 1;
                        if (Util.GetASCIIString(file, offset, 4) == "URL ") {
                            numBlocks = Util.GetUInt32(file, offset + 4);
                            uint desc_offset = Util.GetUInt32(file, offset + 0x34);
                            uint cachedname_offset = Util.GetUInt32(file, offset + 0x3C);
                            DateTime lastAccessed;
                            DateTime lastModified;
                            GetDateTimeFields(out lastAccessed, out lastModified, file, offset + 8);
                            string desc = Util.GetASCIIString(file, offset + desc_offset, Util.StrLen(file, offset + desc_offset, 0x4000));
                            string cachedname = Util.GetASCIIString(file, offset + cachedname_offset, Util.StrLen(file, offset + cachedname_offset, 0x4000));
                            int cachenum = Util.GetByte(file, offset + 0x38);
                            if (cachedirs.Count > cachenum) {
                                m_Records.Add(new ExplorerHistoryRecord(desc, lastAccessed, lastModified, cachedirs[cachenum], cachedname));
                            } else {
                                m_Records.Add(new ExplorerHistoryRecord(desc, lastAccessed, lastModified, file.FileSystem));
                            }
                        }
                        offset += numBlocks * BLOCK_SIZE;
                    }
                }
            }
        }
Exemple #4
0
        public static bool IsFileType(File file, FileType type)
        {
            if (type == FileType.All) return true;

            if (!string.IsNullOrEmpty(file.Name)) {
                string[] bits = file.Name.ToLower().Split('.');
                if (bits.Length > 0 && m_Extensions[type].Contains(bits.Last())) {
                    return true;
                }
            }
            if (m_HeaderChecks.ContainsKey(type) && m_HeaderChecks[type](file)) {
                return true;
            }
            return false;
        }
        private void ShowContextMenu(TreeNodeMouseClickEventArgs e)
        {
            FileSystemNode fsnode = e.Node.Tag as FileSystemNode;

            if (fsnode != null)
            {
                ContextMenu menu = new ContextMenu();
                if (fsnode is Folder)
                {
                    Folder f = fsnode as Folder;
                    menu.MenuItems.Add(new MenuItem("Refresh", new EventHandler(delegate(object o, EventArgs ea) {
                        fsnode.ReloadChildren();
                        AppendChildren(e.Node, fsnode.GetChildren());
                    })));
                    menu.MenuItems.Add(new MenuItem("Save Folder...", new EventHandler(delegate(object o, EventArgs ea) {
                        SaveFileDialog saveFileDialog  = new SaveFileDialog();
                        saveFileDialog.Filter          = "Any Files|*.*";
                        saveFileDialog.Title           = "Select a Location";
                        saveFileDialog.FileName        = f.Name;
                        saveFileDialog.OverwritePrompt = true;

                        if (saveFileDialog.ShowDialog() == DialogResult.OK)
                        {
                            SaveFolder(f, saveFileDialog.FileName);
                        }
                    })));
                }
                if (fsnode is File)
                {
                    File f = fsnode as File;
                    menu.MenuItems.Add(new MenuItem("Save File...", new EventHandler(delegate(object o, EventArgs ea) {
                        SaveFileDialog saveFileDialog  = new SaveFileDialog();
                        saveFileDialog.Filter          = "Any Files|*.*";
                        saveFileDialog.Title           = "Select a Location";
                        saveFileDialog.FileName        = f.Name;
                        saveFileDialog.OverwritePrompt = true;

                        if (saveFileDialog.ShowDialog() == DialogResult.OK)
                        {
                            SaveFile(f, saveFileDialog.FileName);
                        }
                    })));
                }
                menu.Show(e.Node.TreeView, e.Location);
            }
        }
 private void GetDateTimeFields(out DateTime lastAccessed, out DateTime lastModified, File file, ulong p)
 {
     long field1 = Util.GetInt64(file, p);
     long field2 = Util.GetInt64(file, p + 8);
     switch (Type) {
         case ExplorerHistoryType.Cache:
             lastModified = DateTime.FromFileTimeUtc(field1);
             lastAccessed = DateTime.FromFileTimeUtc(field2);
             break;
         case ExplorerHistoryType.Cookie:
             lastModified = DateTime.FromFileTimeUtc(field1);
             lastAccessed = DateTime.FromFileTimeUtc(field2);
             break;
         case ExplorerHistoryType.MainHistory:
             lastModified = lastAccessed
                 = DateTime.FromFileTimeUtc(field1);
             break;
         case ExplorerHistoryType.DailyWeeklyHistory:
             lastModified = lastAccessed
                 = new DateTime(DateTime.FromFileTimeUtc(field1).Ticks, DateTimeKind.Local).ToUniversalTime();
             break;
         default:
             lastModified = DateTime.FromFileTimeUtc(field1);
             lastAccessed = DateTime.FromFileTimeUtc(field2);
             break;
     }
 }