private static void ImportFile(IDataReader reader, long volumeID, long minFileID, string rootPath, MetadataStore metaData, VolumeDatabase db, BufferedVolumeItemWriter writer, long[] counters) { FileSystemVolumeItem item; if ((string)reader["type"] == "directory") { item = new DirectoryVolumeItem(db); counters[TOTAL_DIRS]++; } else { item = new FileVolumeItem(db); long size = (long)reader["size"]; ((FileVolumeItem)item).SetFileVolumeItemFields(size, null); counters[TOTAL_FILES]++; counters[TOTAL_SIZE] += size; } string path = (string)reader["path"]; Debug.Assert(path.StartsWith("file://"), "path starts with 'file://'"); string name = (string)reader["name"]; string location = DecoderUtility.UrlDecode(path); location = location.Substring(rootPath.Length); location = location.Substring(0, location.Length - name.Length - 1); if (location.Length == 0) { location = "/"; } long itemID = 2 + (long)reader["id"] - minFileID; // id 1 is the root item long parentID = Math.Max(1, 2 + (long)reader["idparent"] - minFileID); item.SetFileSystemVolumeItemFields(location, DateTime.MinValue, VolumeDatabase.ID_NONE); item.SetVolumeItemFields(volumeID, itemID, parentID, name, Util.ReplaceDBNull <string>(reader["mime"], null), metaData, Util.ReplaceDBNull <string>(reader["comment"], null), null); writer.Write(item); }
private void ImportFile(XmlNode node, string comment, long volumeID, long parentID, long itemID, Stack <string> path, MetadataStore metaData) { FileSystemVolumeItem item; string location = "/" + string.Join("/", path.Reverse()); string name = node.Attributes["name"].Value; string mimeType; DateTime lastWriteTime; if (node.Name == "directory") { item = new DirectoryVolumeItem(targetDb); mimeType = VolumeScanner.FilesystemVolumeScanner.MIME_TYPE_DIRECTORY; counters[TOTAL_DIRS]++; } else { item = new FileVolumeItem(targetDb); // prepend a non-existing path to ensure the file doesn't actually exist // in the current environment directory mimeType = MimeType.GetMimeTypeForFile(mimePathPrefix + name); long size = ConvertSize(node.Attributes["size"].Value); ((FileVolumeItem)item).SetFileVolumeItemFields(size, null); counters[TOTAL_FILES]++; counters[TOTAL_SIZE] += size; } if (!DateTime.TryParseExact(node.Attributes["time"].Value, DATETIME_FORMAT, ci.DateTimeFormat, DateTimeStyles.None, out lastWriteTime)) { lastWriteTime = DateTime.MinValue; } item.SetFileSystemVolumeItemFields(location, lastWriteTime, VolumeDatabase.ID_NONE); item.SetVolumeItemFields(volumeID, itemID, parentID, name, mimeType, metaData, comment, null); writer.Write(item); }
public static void GetFSItemProperties(FileSystemVolumeItem item, out ItemProperty[] properties, out Dictionary <string, string> nameProperty) { List <ItemProperty> tmp; GetCommonItemProperties(item, out tmp, out nameProperty); tmp.Add(new ItemProperty(S._("Location"), item.Location, 202)); if (item.LastWriteTime.Ticks > 0L) { tmp.Add(new ItemProperty(S._("Last write time"), item.LastWriteTime.ToString(), 205)); } if (item.IsSymLink) { FileSystemVolumeItem targetItem = item.GetSymLinkTargetItem(); string symlinkTargetPath = null; if (targetItem.Location != "/" && targetItem.Name != "/") { symlinkTargetPath = string.Format("{0}/{1}", targetItem.Location, targetItem.Name); } else { symlinkTargetPath = targetItem.Location + targetItem.Name; } tmp.Add(new ItemProperty(S._("Symlink target"), symlinkTargetPath, 203)); } if (item is FileVolumeItem) { FileVolumeItem fvi = (FileVolumeItem)item; string sizeStr = Util.GetSizeStr(fvi.Size); string hash = fvi.Hash; tmp.Add(new ItemProperty(S._("Size"), sizeStr, 204)); if (!string.IsNullOrEmpty(hash)) { tmp.Add(new ItemProperty(S._("Hash"), hash, 207)); } } if (!string.IsNullOrEmpty(item.MimeType)) { tmp.Add(new ItemProperty(S._("Filetype"), item.MimeType, 206)); } tmp.Sort(); // sort by priority properties = tmp.ToArray(); }
protected override void LoadFromObject(VolumeDB.VolumeItem item) { if (!(item is FileVolumeItem)) { throw new ArgumentException(string.Format("must be of type {0}", typeof(FileVolumeItem)), "item"); } base.LoadFromObject(item); FileVolumeItem fvi = (FileVolumeItem)item; UpdateLabel(lblSize, Util.GetSizeStr(fvi.Size)); UpdateLabel(lblHash, string.IsNullOrEmpty(fvi.Hash) ? "-" : fvi.Hash); }
private long InsertFile(string rootPath, FileInfo file, BufferedVolumeItemWriter writer, long parentID, string mimeType, MetadataStore metaData, string hash) { /* if scanner has no db associated, just update the counters * and return */ if (!this.HasDB) { Interlocked.Increment(ref VolumeInfo.files); Interlocked.Add(ref VolumeInfo.size, file.Length); return(VolumeDatabase.ID_NONE); } DateTime lastWriteTime = GetLastWriteTime(file); FileVolumeItem item = GetNewVolumeItem <FileVolumeItem>(parentID, file.Name, mimeType, metaData, VolumeItemType.FileVolumeItem); item.SetFileSystemVolumeItemFields(GetLocation(file.FullName, rootPath), lastWriteTime, VolumeDatabase.ID_NONE); item.SetFileVolumeItemFields(file.Length, hash); //item.Name = file.Name; // set the items name (defined on VolumeItem baseclass) writer.Write(item); Interlocked.Increment(ref VolumeInfo.files); Interlocked.Add(ref VolumeInfo.size, file.Length); if (!Options.DiscardSymLinks) { symLinkHelper.AddFile(file.FullName, item.ItemID); } return(item.ItemID); }
private static void ImportFile(IDataReader reader, long volumeID, long minFileID, string rootPath, MetadataStore metaData, VolumeDatabase db, BufferedVolumeItemWriter writer, long[] counters) { FileSystemVolumeItem item; if ((string)reader["type"] == "directory") { item = new DirectoryVolumeItem(db); counters[TOTAL_DIRS]++; } else { item = new FileVolumeItem(db); long size = (long)reader["size"]; ((FileVolumeItem)item).SetFileVolumeItemFields(size, null); counters[TOTAL_FILES]++; counters[TOTAL_SIZE] += size; } string path = (string)reader["path"]; Debug.Assert(path.StartsWith("file://"), "path starts with 'file://'"); string name = (string)reader["name"]; string location = DecoderUtility.UrlDecode(path); location = location.Substring(rootPath.Length); location = location.Substring(0, location.Length - name.Length - 1); if (location.Length == 0) location = "/"; long itemID = 2 + (long)reader["id"] - minFileID; // id 1 is the root item long parentID = Math.Max(1, 2 + (long)reader["idparent"] - minFileID); item.SetFileSystemVolumeItemFields(location, DateTime.MinValue, VolumeDatabase.ID_NONE); item.SetVolumeItemFields(volumeID, itemID, parentID, name, Util.ReplaceDBNull<string>(reader["mime"], null), metaData, Util.ReplaceDBNull<string>(reader["comment"], null), null); writer.Write(item); }