private void OnRowExpanded(object o, RowExpandedArgs args) { switch (CurrentVolumeType) { case VolumeType.FileSystemVolume: TreeStore store = (TreeStore)Model; // get child node of expanded node TreeIter child; store.IterChildren(out child, args.Iter); // test if the first child is the "loading" child node if ((GetItem(child) == null) && ((string)Model.GetValue(child, 1) == STR_LOADING)) { // append dir children DirectoryVolumeItem dir = (DirectoryVolumeItem)GetItem(args.Iter); AppendDirRows(store, args.Iter, dir); // remove "loading" child node store.Remove(ref child); } break; default: throw new NotImplementedException("View for this VolumeType has not been implemented yet"); } }
private void AppendDirRows(TreeStore store, TreeIter parent, DirectoryVolumeItem item) { bool parentIsRoot = (parent.Stamp == TreeIter.Zero.Stamp); DirectoryVolumeItem[] dirs = item.GetDirectories(); FileVolumeItem[] files = item.GetFiles(); // if no files or dirs have been found, add an empty node if (dirs.Length == 0 && files.Length == 0) { AppendDirValues(store, parent, parentIsRoot, null, STR_EMPTY, null); } else { foreach (DirectoryVolumeItem dir in dirs) { TreeIter iter = AppendDirValues(store, parent, parentIsRoot, GetImage(dir), dir.Name, dir); if (iter.Stamp != TreeIter.Zero.Stamp) { AppendDirValues(store, iter, false, loadingIcon, STR_LOADING, null); } } foreach (FileVolumeItem file in files) { AppendDirValues(store, parent, parentIsRoot, GetImage(file), file.Name, file); } } }
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); }
private void ImportMedia(XmlNode node, string borrow, string comment, long volumeID) { FileSystemVolume v = new FileSystemVolume(targetDb); VolumeDriveType driveType = driveTypeMapping[node.Attributes["type"].Value]; DateTime added; if (!DateTime.TryParseExact(node.Attributes["time"].Value, DATETIME_FORMAT, ci.DateTimeFormat, DateTimeStyles.None, out added)) { added = DateTime.MinValue; } v.SetVolumeFields(volumeID, node.Attributes["name"].Value, added, false, node.Attributes["number"].Value, driveType, borrow, DateTime.MinValue, DateTime.MinValue, null, comment, null); v.SetFileSystemVolumeFields(counters[TOTAL_FILES], counters[TOTAL_DIRS], counters[TOTAL_SIZE]); v.InsertIntoDB(); // insert root item DirectoryVolumeItem item = new DirectoryVolumeItem(targetDb); item.SetFileSystemVolumeItemFields(null, DateTime.MinValue, VolumeDatabase.ID_NONE); item.SetVolumeItemFields(volumeID, 1L, 0L, "/", VolumeScanner.FilesystemVolumeScanner.MIME_TYPE_DIRECTORY, MetadataStore.Empty, null, null); item.InsertIntoDB(); }
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 static void ImportDisk(IDataReader reader, long volumeID, VolumeDatabase db, long[] counters) { FileSystemVolume v = new FileSystemVolume(db); // try to guess the drivetype VolumeDriveType driveType; string root = (string)reader["root"]; if (root.ToUpper().Contains("CDROM") || root.ToUpper().Contains("DVD")) driveType = VolumeDriveType.CDRom; else if (root.StartsWith("/media")) driveType = VolumeDriveType.Removable; else driveType = VolumeDriveType.Harddisk; v.SetVolumeFields(volumeID, Util.ReplaceDBNull<string>(reader["name"], null), DateTime.Now, false, null, driveType, Util.ReplaceDBNull<string>(reader["borrow"], null), DateTime.MinValue, DateTime.MinValue, null, Util.ReplaceDBNull<string>(reader["comment"], null), null); v.SetFileSystemVolumeFields(counters[TOTAL_FILES], counters[TOTAL_DIRS], counters[TOTAL_SIZE]); v.InsertIntoDB(); // insert root item DirectoryVolumeItem item = new DirectoryVolumeItem(db); item.SetFileSystemVolumeItemFields(null, DateTime.MinValue, VolumeDatabase.ID_NONE); item.SetVolumeItemFields(volumeID, 1L, 0L, "/", VolumeScanner.FilesystemVolumeScanner.MIME_TYPE_DIRECTORY, MetadataStore.Empty, null, null); item.InsertIntoDB(); }
public void FillRoot(Volume volume, VolumeDatabase db) { if (volume == null) { throw new ArgumentNullException("volume"); } if (db == null) { throw new ArgumentNullException("db"); } this.database = db; TreeModel model; VolumeType volType = volume.GetVolumeType(); ResetView(); switch (volType) { case VolumeType.FileSystemVolume: InitView(volType, out model); // load volume root FileSystemVolume fsv = (FileSystemVolume)volume; DirectoryVolumeItem item = fsv.GetRoot(); AppendDirRows((TreeStore)model, TreeIter.Zero, item); Model = model; /*ColumnsAutosize();*/ break; case VolumeType.AudioCdVolume: InitView(volType, out model); // load volume root AudioCdVolume avol = (AudioCdVolume)volume; AudioCdRootVolumeItem root = avol.GetRoot(); AudioTrackVolumeItem[] tracks = root.GetTracks(); ListStore store = (ListStore)model; if (tracks.Length == 0) { store.AppendValues(null, STR_EMPTY, STR_EMPTY, STR_EMPTY); } else { foreach (AudioTrackVolumeItem track in tracks) { store.AppendValues(GetImage(track), track.Name, (track.Artist.Length == 0 ? S._("Unknown") : track.Artist), string.Format("{0:D2}:{1:D2}", track.Duration.Minutes, track.Duration.Seconds), track); } } Model = model; /*ColumnsAutosize();*/ break; default: throw new NotImplementedException("Items view has not been implemented for this volumetype"); } }
private static void ImportDisk(IDataReader reader, long volumeID, VolumeDatabase db, long[] counters) { FileSystemVolume v = new FileSystemVolume(db); // try to guess the drivetype VolumeDriveType driveType; string root = (string)reader["root"]; if (root.ToUpper().Contains("CDROM") || root.ToUpper().Contains("DVD")) { driveType = VolumeDriveType.CDRom; } else if (root.StartsWith("/media")) { driveType = VolumeDriveType.Removable; } else { driveType = VolumeDriveType.Harddisk; } v.SetVolumeFields(volumeID, Util.ReplaceDBNull <string>(reader["name"], null), DateTime.Now, false, null, driveType, Util.ReplaceDBNull <string>(reader["borrow"], null), DateTime.MinValue, DateTime.MinValue, null, Util.ReplaceDBNull <string>(reader["comment"], null), null); v.SetFileSystemVolumeFields(counters[TOTAL_FILES], counters[TOTAL_DIRS], counters[TOTAL_SIZE]); v.InsertIntoDB(); // insert root item DirectoryVolumeItem item = new DirectoryVolumeItem(db); item.SetFileSystemVolumeItemFields(null, DateTime.MinValue, VolumeDatabase.ID_NONE); item.SetVolumeItemFields(volumeID, 1L, 0L, "/", VolumeScanner.FilesystemVolumeScanner.MIME_TYPE_DIRECTORY, MetadataStore.Empty, null, null); item.InsertIntoDB(); }
private long InsertDir(string rootPath, DirectoryInfo dir, BufferedVolumeItemWriter writer, long parentID) { /* if scanner has no db associated, just update the counters * and return */ if (!this.HasDB) { // TODO : // increase dircounter for symlink to dirs as well? // nautilus refers to selected symlinks to dirs as dirs too. Interlocked.Increment(ref VolumeInfo.directories); return(VolumeDatabase.ID_NONE); } string location; string name; /* if parentID is ID_NONE, the directory is the volumes root dir * -> location = null, name = "/" (analog System.IO.DirectoryInfo) */ if (parentID == VolumeDatabase.ID_NONE) { location = null; name = PATH_SEPARATOR.ToString(); } else { location = GetLocation(dir.FullName, rootPath); name = dir.Name; } DateTime lastWriteTime = GetLastWriteTime(dir); DirectoryVolumeItem item = GetNewVolumeItem <DirectoryVolumeItem>(parentID, name, MIME_TYPE_DIRECTORY, MetadataStore.Empty, VolumeItemType.DirectoryVolumeItem); item.SetFileSystemVolumeItemFields(location, lastWriteTime, VolumeDatabase.ID_NONE); //item.Name = name; // set the items name (defined on VolumeItem baseclass) // if (isSymlink) { // /* don't dump symlink dirs directly into the database, // * they're required to have a target item assigned. // * target items are resolved in an additional step. // */ // symLinkItems.add(symLinkTarget, item); // } else { writer.Write(item); // } // TODO : // increase dircounter for symlink to dirs as well? // nautilus refers to selected symlinks to dirs as dirs too. Interlocked.Increment(ref VolumeInfo.directories); if (!Options.DiscardSymLinks) { symLinkHelper.AddFile(dir.FullName, item.ItemID); } return(item.ItemID); }