/// <summary> /// This method will use the GetUIObjectOf method of IShellFolder to obtain the IDataObject of a /// ShellItem. /// </summary> /// <param name="item">The item for which to obtain the IDataObject</param> /// <param name="dataObjectPtr">A pointer to the returned IDataObject</param> /// <returns>the IDataObject the ShellItem</returns> public static IntPtr GetIDataObject(FileSystemInfoEx[] items) { DirectoryInfoEx parent = items[0].Parent != null ? items[0].Parent : DirectoryInfoEx.DesktopDirectory; IntPtr[] pidls = new IntPtr[items.Length]; for (int i = 0; i < items.Length; i++) pidls[i] = items[i].PIDLRel.Ptr; IntPtr dataObjectPtr; //0.15: Fixed ShellFolder not freed. using (ShellFolder2 parentShellFolder = parent.ShellFolder) if (parentShellFolder.GetUIObjectOf( IntPtr.Zero, (uint)pidls.Length, pidls, ref ShellAPI.IID_IDataObject, IntPtr.Zero, out dataObjectPtr) == ShellAPI.S_OK) { return dataObjectPtr; } else { return IntPtr.Zero; } }
public DeleteWork(int id, FileSystemInfoEx[] items) : base(id, items.Length > 0 ? items[0].Parent : null, null) { _deleteItems = items; WorkType = WorkType.Delete; }
public CopyWork(int id, FileSystemInfoEx[] src, DirectoryInfoEx dest) : base(id, src.Length > 0 ? src[0].Parent : null, dest) { _copyFrom = src; _dest = dest; WorkType = WorkType.Copy; }
public static bool Exists(string path) { try { FileSystemInfoEx fsInfo = new FileSystemInfoEx(path); return fsInfo != null && !fsInfo.IsFolder && fsInfo.Exists; } catch { return false; } }
public FileTreeViewModel(FileSystemInfoEx root) { FileExtensionFilter = new List<string>(); Children = new List<FileTreeViewModel>(); Path = root; if (!Path.IsFolder) return; _isEnumerationRequired = true; Children.Add(null); }
protected OverwriteMode AskOverwrite(FileSystemInfoEx srcEntry, FileSystemInfoEx destEntry) { if (ApplyToAll) return DefaultOverwriteMode; if (WorkOverwrite != null) { WorkOverwriteEventArgs e = new WorkOverwriteEventArgs(ID, srcEntry, destEntry, OverwriteMode.Replace, false); WorkOverwrite(this, e); if (e.ApplyToAll) SetDefaultOverwriteMode(e.Overwrite); return e.Overwrite; } return OverwriteMode.Replace; }
public static void AskOverwriteDialog(FileSystemInfoEx srcEntry, FileSystemInfoEx destEntry, ref bool overwrite, ref bool applyAll) { string destName = destEntry.Name; long destSize = (destEntry is FileInfoEx) ? (destEntry as FileInfoEx).Length : 0; DateTime destTime = destEntry.LastWriteTime; string destCRC = ""; //if (!destEntry.IsFolder || srcEntry.IsArchiveRoot) // destCRC = destEntry.CRC; string srcName = srcEntry.Name; long srcSize = (srcEntry is FileInfoEx) ? (srcEntry as FileInfoEx).Length : 0; DateTime srcTime = srcEntry.LastWriteTime; string srcCRC = ""; //if (!srcEntry.IsFolder || srcEntry.IsArchiveRoot) // srcCRC = srcEntry.CRC; overwrite = AskOverwriteDialog(srcName, srcSize, srcTime, srcCRC, destName, destSize, destTime, destCRC); }
protected ExModel(FileSystemInfoEx entry) { if (entry == null) return; //TODO Добавить длину файла Name = entry.Name; Label = entry.Label; FullName = entry.FullName; //0.2 LastAccessTime = entry.LastAccessTime; LastWriteTime = entry.LastWriteTime; CreationTime = entry.CreationTime; EntryType = entry.IsFolder ? entry.FullName.EndsWith(":\\") ? "Drive" : "Directory" : FileTypeInfoProvider.GetFileTypeInfo(PathEx.GetExtension(Name)).FileType; //if (FullName.StartsWith("\\\\") || //Network directory // (FullName.IndexOf('\\') == -1 && !FullName.StartsWith("::")) //Directory without path and not guid. // || entry.IsVirtual) //Virtual directory IsEditable = (entry.Attributes | System.IO.FileAttributes.ReadOnly) != 0; _embeddedEntry = entry; //+AK Attribs = (entry.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly ? "r" : "-"; Attribs += (entry.Attributes & FileAttributes.Archive) == FileAttributes.Archive ? "a" : ""; }
protected ExModel(FileSystemInfoEx entry) { Name = entry.Name; Label = entry.Label; FullName = entry.FullName; //0.2 LastAccessTime = entry.LastAccessTime; LastWriteTime = entry.LastWriteTime; CreationTime = entry.CreationTime; EntryType = entry.IsFolder ? entry.FullName.EndsWith(":\\") ? "Drive" : "Directory" : FileTypeInfoProvider.GetFileTypeInfo(PathEx.GetExtension(Name)).FileType; //if (FullName.StartsWith("\\\\") || //Network directory // (FullName.IndexOf('\\') == -1 && !FullName.StartsWith("::")) //Directory without path and not guid. // || entry.IsVirtual) //Virtual directory _embeddedEntry = entry; IsEditable = (entry.Attributes | System.IO.FileAttributes.ReadOnly) != 0; }
public QueryMenuItemsEventArgs(FileSystemInfoEx[] selectedItems) { ExtraMenuItems = new string[] { }; SelectedItems = selectedItems; DefaultItem = -1; QueryContextMenu = true; QueryContextMenu2 = true; QueryContextMenu3 = true; }
public string Popup(FileSystemInfoEx[] items, Point pt) { if (items.Length > 0 && !_contextMenuVisible) { //0.15: Fixed ShellFolder not freed correctly. try { using (ShellFolder2 parentShellFolder = items[0].Parent != null ? items[0].Parent.ShellFolder : DirectoryInfoEx.DesktopDirectory.ShellFolder) try { _contextMenuVisible = true; ///Debug.WriteLine(items[0].Parent.FullName); IntPtr ptrContextMenu = IntPtr.Zero; IntPtr ptrContextMenu2 = IntPtr.Zero; IntPtr PtrContextMenu3 = IntPtr.Zero; IntPtr contextMenu = IntPtr.Zero; List<IntPtr> menuPtrConstructed = new List<IntPtr>(); List<IntPtr> imgPtrConstructed = new List<IntPtr>(); PIDL[] pidls = IOTools.GetPIDL(items, true); if (ContextMenuHelper.GetIContextMenu(parentShellFolder, IOTools.GetPIDLPtr(pidls), out ptrContextMenu, out _iContextMenu)) try { queryMenuItemsEventArgs = new QueryMenuItemsEventArgs(items); if (OnQueryMenuItems != null) OnQueryMenuItems(this, queryMenuItemsEventArgs); contextMenu = ShellAPI.CreatePopupMenu(); if (queryMenuItemsEventArgs.QueryContextMenu) _iContextMenu.QueryContextMenu(contextMenu, 0, ShellAPI.CMD_FIRST, ShellAPI.CMD_LAST, ShellAPI.CMF.EXPLORE | ShellAPI.CMF.CANRENAME | ((Control.ModifierKeys & Keys.Shift) != 0 ? ShellAPI.CMF.EXTENDEDVERBS : 0)); #region obsolute //for (uint i = 0; i < queryMenuItemsEventArgs.ExtraMenuItems.Length; i++) //{ // string caption = queryMenuItemsEventArgs.ExtraMenuItems[i]; // if (caption != "---") // { // ShellAPI.InsertMenu(contextMenu, i, ShellAPI.MFT.BYPOSITION, // ShellAPI.CMD_LAST + i + 1, caption); // if (queryMenuItemsEventArgs.DefaultItem == i) // ShellAPI.SetMenuDefaultItem(contextMenu, i, true); // } // else ShellAPI.InsertMenu(contextMenu, i, ShellAPI.MFT.BYPOSITION | // ShellAPI.MFT.SEPARATOR, 0, "-"); //} #endregion //0.11: Added ContextMenuWrapper OnQueryMenuItems event now support multilevel directory. (e.g. @"Tools\Add") ContextMenuHelperEx.ConstructCustomMenu(contextMenu, queryMenuItemsEventArgs.ExtraMenuItems, out menuPtrConstructed, out imgPtrConstructed); if (queryMenuItemsEventArgs.QueryContextMenu2) try { Marshal.QueryInterface(ptrContextMenu, ref ShellAPI.IID_IContextMenu2, out ptrContextMenu2); _iContextMenu2 = (IContextMenu2)Marshal.GetTypedObjectForIUnknown( ptrContextMenu2, typeof(IContextMenu2)); } catch (Exception) { } if (queryMenuItemsEventArgs.QueryContextMenu3) try { Marshal.QueryInterface(ptrContextMenu, ref ShellAPI.IID_IContextMenu3, out PtrContextMenu3); _iContextMenu3 = (IContextMenu3)Marshal.GetTypedObjectForIUnknown( PtrContextMenu3, typeof(IContextMenu3)); } catch (Exception) { } uint GMDI_USEDISABLED = 0x0001; //uint GMDI_GOINTOPOPUPS = 0x0002; uint intDefaultItem = (uint)ShellAPI.GetMenuDefaultItem(contextMenu, false, GMDI_USEDISABLED); string strDefaultCommand = intDefaultItem >= ShellAPI.CMD_FIRST ? ContextMenuHelper.GetCommandString(_iContextMenu, intDefaultItem - ShellAPI.CMD_FIRST, true) : null; if (queryMenuItemsEventArgs.QueryContextMenu) //No need to Disable if query is not carried out in first place. { //0.11: Added queryMenuItemsEventArgs.GrayedItems / HiddenItems ContextMenuHelperEx.DisableMenuItems(contextMenu, _iContextMenu, queryMenuItemsEventArgs.GrayedItems, ContextMenuHelperEx.DisabledMethods.Gray); ContextMenuHelperEx.DisableMenuItems(contextMenu, _iContextMenu, queryMenuItemsEventArgs.HiddenItems, ContextMenuHelperEx.DisabledMethods.Remove); } //0.17: Added DefaultItem and DefaultCommand in BeforePopup bool cont = true; if (OnBeforePopup != null) { BeforePopupEventArgs args = new BeforePopupEventArgs (contextMenu, _iContextMenu, intDefaultItem - ShellAPI.CMD_FIRST, strDefaultCommand); OnBeforePopup(this, args); cont = args.ContinuePopup; } if (cont) { //0.18 Fixed Context menu disappear in some case. (By cwharmon) //http://www.codeproject.com/KB/files/DirectoryInfoEx.aspx#xx3475961xx ShellAPI.SetForegroundWindow(this.Handle); uint selected = ShellAPI.TrackPopupMenuEx(contextMenu, ShellAPI.TPM.RETURNCMD, pt.X, pt.Y, this.Handle, IntPtr.Zero); uint msg = 0; ShellAPI.PostMessage(this.Handle, msg, IntPtr.Zero, IntPtr.Zero); if (OnMouseHover != null) OnMouseHover(this, new MouseHoverEventArgs("", "", 0)); if (selected >= ShellAPI.CMD_LAST) { return removeCheckedSymbol(queryMenuItemsEventArgs.ExtraMenuItems[selected - ShellAPI.CMD_LAST]); } if (selected >= ShellAPI.CMD_FIRST) { string command = ContextMenuHelper.GetCommandString(_iContextMenu, selected - ShellAPI.CMD_FIRST, true); if (command == null) return null; if (OnBeforeInvokeCommand != null) { InvokeCommandEventArgs args = new InvokeCommandEventArgs(command, "", selected, items); OnBeforeInvokeCommand(this, args); if (!args.ContinueInvoke) return command; } if (command == "rename") return "rename"; else { //if (items.Length == 1 && items[0] is DirectoryInfoEx) ContextMenuHelper.InvokeCommand(_iContextMenu, selected - ShellAPI.CMD_FIRST, (items[0].Parent != null) ? items[0].Parent.FullName : items[0].FullName, pt); //else //ContextMenuHelper.InvokeCommand(items[0].Parent, // IOTools.GetPIDLPtr(items, true), selected - ShellAPI.CMD_FIRST, // pt); } } } } finally { IOTools.FreePIDL(pidls); if (_iContextMenu != null) { Marshal.ReleaseComObject(_iContextMenu); _iContextMenu = null; } if (_iContextMenu2 != null) { Marshal.ReleaseComObject(_iContextMenu2); _iContextMenu2 = null; } if (_iContextMenu3 != null) { Marshal.ReleaseComObject(_iContextMenu3); _iContextMenu3 = null; } foreach (IntPtr menuPtr in menuPtrConstructed) ShellAPI.DestroyMenu(menuPtr); menuPtrConstructed.Clear(); if (contextMenu != null) ShellAPI.DestroyMenu(contextMenu); if (ptrContextMenu != IntPtr.Zero) Marshal.Release(ptrContextMenu); if (ptrContextMenu2 != IntPtr.Zero) Marshal.Release(ptrContextMenu2); if (PtrContextMenu3 != IntPtr.Zero) Marshal.Release(PtrContextMenu3); } } finally { _contextMenuVisible = false; } } catch { } } return null; }
public FileTreeViewModel(FileTreeViewModel parent, FileSystemInfoEx path) : this(path) { _parent = parent; }
public BblBookPdf(BblLibraryRootNode root, BblLibraryNode parent, FileSystemInfoEx info) : base(root, parent, info, BookType.Pdf) { }
public WorkListEventArgs(int id, FileSystemInfoEx listedEntry) { this.ID = id; this.ListedEntry = listedEntry; }
public static bool LoadFileFromClArgs() { InstanceManager.Instance.CommmandLineArgs.RemoveAt(0); if (InstanceManager.Instance.CommmandLineArgs.Count == 0) { return(false); } var file = InstanceManager.Instance.CommmandLineArgs.Find(s => !s.StartsWith("--")); if (file == default(string)) { return(false); } var addOnly = InstanceManager.Instance.CommmandLineArgs.Find(s => s.ToLowerInvariant() == "--add") != default(string); var fsi = FileSystemInfoEx.FromString(file); if (fsi.IsFolder) { var l = PlaybackManager.Instance.Playlist.Count; AddFolderQuery(fsi as DirectoryInfoEx); if (l < PlaybackManager.Instance.Playlist.Count && !addOnly) { PlaybackManager.Instance.NowPlayingId = l; } } else if (!fsi.Exists) { MessageBox.Show("Invalid command line argument or file/directory not found: " + file, "Non-critical error, everything is ok!", MessageBoxButton.OK, MessageBoxImage.Asterisk); return(false); } else { var ext = file.GetExt(); if (PlaylistDataManager.Instance.HasReader(ext)) { if (addOnly) { PlaybackManager.Instance.Playlist.AddRange(file, DefaultLoadErrorCallback); } else if (InstanceManager.Instance.PlaylistEditorInstance.ClosePlaylistQuery()) { InstanceManager.Instance.PlaylistEditorInstance.InternalOpenPlaylist(file); } else { return(false); } } else if (PlaybackManager.Instance.HasSupportingPlayer(ext)) { var m = MusicInfo.Create(file, DefaultLoadErrorCallback); if (m == null) { return(false); } PlaybackManager.Instance.Playlist.Add(m); if (!addOnly) { PlaybackManager.Instance.NowPlayingId = PlaybackManager.Instance.Playlist.Count - 1; } } else { MessageBox.Show("Unsupported file type: " + ext, "Non-critical error, everything is ok!", MessageBoxButton.OK, MessageBoxImage.Exclamation); return(false); } } // by now we have determined that the stuff has been successfully added if (PlaybackManager.Instance.CurrentState != PlaybackState.Playing && !addOnly) { PlaybackManager.Instance.PlayPauseResume(); } return(true); }
public ExWorkBase(int id, FileSystemInfoEx source) : base(id) { Source = source; }
/// <summary> /// Rename a file or folder in an directory. /// </summary> public static void Rename(string source, string destName) { //DirectoryInfoEx srcDir = new DirectoryInfoEx(Path.GetDirectoryName(source)); FileSystemInfoEx srcElement = new FileSystemInfoEx(source); string srcName = Path.GetFileName(source); if (!srcElement.Exists || srcElement.Parent == null) throw new IOException("Source not exists"); //0.15: Fixed ShellFolder not freed. using (ShellFolder2 srcParentShellFolder = srcElement.Parent.ShellFolder) { if (srcParentShellFolder == null) throw new IOException("Source directory does not support IShellFolder"); IntPtr tmpPtr; int hr = srcParentShellFolder.SetNameOf(IntPtr.Zero, srcElement.PIDLRel.Ptr, destName, ShellAPI.SHGNO.FORPARSING, out tmpPtr); PIDL tmpPIDL = new PIDL(tmpPtr, false); //consume the IntPtr, and free it. tmpPIDL.Free(); if (hr != ShellAPI.S_OK) Marshal.ThrowExceptionForHR(hr); } }
public static IModelIconExtractor <IEntryModel> Create() { Func <IEntryModel, string> keyFunc = (m) => { if (m.IsDirectory) { //if (model.FullPath.StartsWith("::")) return("GetFromSystemImageList - " + m.FullPath); } //else return "GetFromSystemImageList - Directory"; else { string extension = m.GetExtension().ToLower(); if (String.IsNullOrEmpty(extension)) { //Without extension. if (m.FullPath.StartsWith("::")) { return("GetFromSystemImageList - " + m.FullPath); } else { return("GetFromSystemImageList - File"); } } else { if (excludedExtensions.Contains(extension)) { return("GetFromSystemImageList - " + m.FullPath); } return("GetFromSystemImageList - " + extension); } } }; Func <IEntryModel, byte[]> getIconFunc = em => { if (em != null && !String.IsNullOrEmpty(em.FullPath)) { using (FileSystemInfoEx fsi = FileSystemInfoEx.FromString(em.FullPath)) { Bitmap bitmap = null; if (fsi != null && fsi.Exists) { return(fsi.RequestPIDL(pidl => { if (pidl != null) { bitmap = _iconExtractor.GetBitmap(QuickZip.Converters.IconSize.extraLarge, pidl.Ptr, em.IsDirectory, false); if (bitmap != null) { return bitmap.ToByteArray(); } } return new byte[] {}; })); } } } return(null); }; return(ModelIconExtractor <IEntryModel> .FromFuncCachable( keyFunc, (em) => getIconFunc(em) )); }
public BblBookDirectory(BblLibraryRootNode root, BblLibraryNode parent, FileSystemInfoEx info) : base(root, parent, info, BookType.Directory) { }
public void Select(FileSystemInfoEx itemToSelect) { Select(new FileSystemInfoEx[] { itemToSelect }); }
public MultiExWork(int id, FileSystemInfoEx source, FileSystemInfoEx target, IEnumerable <IExWork> workList) : base(id, source, target) { _workList = new List <IExWork>(workList); }
protected bool ReportWorkList(FileSystemInfoEx itemList) { if (WorkList != null) { WorkListEventArgs args = new WorkListEventArgs(ID, itemList); WorkList(this, args); if (args.Cancel) Abort(); return !args.Cancel; } else return true; }
public override FileSystemInfoEx ConstructEntry(string parseName) { return(FileSystemInfoEx.FromString(parseName)); }
public ExWorkBase(int id, FileSystemInfoEx source, FileSystemInfoEx target) : base(id) { Source = source; Target = target; }
public BblBookArchive(BblLibraryRootNode root, BblLibraryNode parent, FileSystemInfoEx info) : base(root, parent, info, BookType.Archive) { }
//public override object GetData(String format) //{ // Object obj = base.GetData(format); // if (format == System.Windows.Forms.DataFormats.FileDrop && // !InDragLoop() && !_isExtracted) // { // string s; // foreach (FileSystemInfoEx entity in _entityList) // s = entity.FullName; // //if (entity.Parent is IVirtualDirectoryInfoExA) // //{ // // if (entity is IVirtualFileSystemInfoExA) // // { // // string outPath = (entity as IVirtualFileSystemInfoExA).TempPath; // // outPath = entity.FullName; // // } // //} // _isExtracted = true; // } // return obj; //} public DataObjectEx(FileSystemInfoEx[] entityList) { _entityList = entityList; }
public DragDropEffects StartDrag(MouseButtons startButton, FileSystemInfoEx[] selectedItems) { ReleaseCom(); if (selectedItems.Length == 0) return DragDropEffects.None; this.startButton = startButton; dataObjectPtr = ShellHelper.GetIDataObject(selectedItems); if (dataObjectPtr != IntPtr.Zero) { DragDropEffects effects; ShellAPI.DoDragDrop(dataObjectPtr, this, DragDropEffects.Copy | DragDropEffects.Link /*| DragDropEffects.Move*/, out effects); return effects; } return DragDropEffects.None; }
public WorkOverwriteEventArgs(int id, FileSystemInfoEx srcEntry, FileSystemInfoEx destEntry, OverwriteMode defOverwrite, bool defApplyToAll) { this.ID = id; this.SrcEntry = srcEntry; this.DestEntry = destEntry; this.Overwrite = defOverwrite; this.ApplyToAll = defApplyToAll; }
public override string GetDiskPath(FileSystemInfoEx entry, out bool isDir, bool createNowIfNotExist = true) { isDir = (entry is DirectoryInfoEx); return(entry.FullName); }
protected BblLibraryNode(BblLibraryRootNode root, BblLibraryNode parent, FileSystemInfoEx info) { Root = root; Parent = parent; LoadInfo(info); }
static FileSystemInfoEx[] getSelectedItems(object sender) { FileSystemInfoEx[] retVal = null; if (sender is ListBox) { ListBox lbSender = (ListBox)sender; if (lbSender.SelectedValue is FileSystemInfoEx) retVal = (from FileSystemInfoEx item in lbSender.SelectedItems select item).ToArray(); else { IValueConverter converter = GetConverter(lbSender); if (converter != null) retVal = (from object item in lbSender.SelectedItems select converter.Convert(item, null, null, null) as FileSystemInfoEx).ToArray(); } } if (sender is TreeView) { TreeView tvSender = (TreeView)sender; if (tvSender.SelectedValue is FileSystemInfoEx) retVal = new FileSystemInfoEx[] { tvSender.SelectedValue as FileSystemInfoEx }; else { IValueConverter converter = GetConverter(tvSender); if (converter != null) retVal = new FileSystemInfoEx[] { converter.Convert(tvSender.SelectedValue, null, null, null) as FileSystemInfoEx }; } } List<FileSystemInfoEx> retList = new List<FileSystemInfoEx>(); if (retVal != null) { foreach (FileSystemInfoEx ex in retVal) if (!ex.FullName.StartsWith("::")) retList.Add(ex); return retList.ToArray(); } else return new FileSystemInfoEx[] { }; }
public void Select(FileSystemInfoEx itemToSelect) { RootModel.CurrentDirectoryModel[itemToSelect].IsSelected = true; }
/// <summary> /// Centralized method to return hash code. /// </summary> /// <param name="fullPath"></param> /// <returns></returns> public static int GetHashCode(FileSystemInfoEx item) { return GetHashCode(item.FullName); }
public static void InvokeCommand(DirectoryInfoEx parent, FileSystemInfoEx[] entries, uint cmd, Point ptInvoke) { PIDL[] pidls = IOTools.GetPIDL(entries, true); IntPtr[] ptrs = IOTools.GetPIDLPtr(pidls); using (ShellFolder2 parentShellFolder = parent.ShellFolder) { try { InvokeCommand(parent, ptrs, cmd, ptInvoke); } finally { IOTools.FreePIDL(pidls); } } }
/// <summary> /// Return a PIDL List from one or more FileSystemInfoExs /// </summary> /// <param name="item"></param> /// <param name="relative"></param> /// <returns></returns> public static PIDL[] GetPIDL(FileSystemInfoEx[] items, bool relative) { List<PIDL> retVal = new List<PIDL>(); foreach (FileSystemInfoEx fi in items) if (fi.Exists) retVal.Add(relative ? fi.PIDLRel : fi.PIDL); return retVal.ToArray(); }
public InvokeCommandEventArgs(string command, string info, uint cmdID, FileSystemInfoEx[] selectedItems) : base(command, info, cmdID) { SelectedItems = selectedItems; ContinueInvoke = true; }
/// <summary> /// Return a PIDL List from one or more FileSystemInfoExs /// </summary> /// <param name="item"></param> /// <param name="relative"></param> /// <returns></returns> public static PIDL[] GetPIDL(FileSystemInfoEx item, bool relative) { return GetPIDL(new FileSystemInfoEx[] { item }, relative); }
/// <summary> /// Get relative path of a entry based on baseDirectory. /// e.g. C:\Temp\AbC\1.txt (entry), C:\Temp\ (baseDirectory) will return ABC\1.txt /// </summary> /// <param name="entry"></param> /// <param name="baseDirectory"></param> /// <returns></returns> public static string GetRelativePath(FileSystemInfoEx entry, DirectoryInfoEx baseDirectory) { if (entry.FullName.IndexOf(baseDirectory.FullName, StringComparison.InvariantCultureIgnoreCase) == -1) { if (Debugger.IsAttached) Debugger.Break(); return entry.Name; } else return entry.FullName.Substring(baseDirectory.FullName.Length + 1); }
//0.13: Added HasParent /// <summary> /// Return whether parent directory contain child directory. /// Aware Library, UserFiles and Public directory too. /// </summary> /// <param name="child"></param> /// <param name="parent"></param> /// <returns></returns> public static bool HasParent(FileSystemInfoEx child, DirectoryInfoEx parent) { if (parent == null) { //if (Debugger.IsAttached) // Debugger.Break(); return false; } //::{031E4825-7B94-4DC3-B131-E946B44C8DD5}\Music.library-ms if (parent.FullName.StartsWith(IOTools.IID_Library) && parent.FullName.EndsWith(".library-ms")) { //Reverse foreach (DirectoryInfoEx subDir in parent.GetDirectories()) if (subDir.Equals(child) || HasParent(child, subDir)) return true; return false; } else { if (child.FullName.StartsWith(parent.FullName.TrimEnd('\\') + "\\", StringComparison.InvariantCultureIgnoreCase)) return true; if (child.FullName.StartsWith(IID_UserFiles) || child.FullName.StartsWith(IID_Public)) return false; FileSystemInfoEx current = child.Parent; while (current != null && !parent.Equals(current)) current = current.Parent; return (current != null); } }
private static string[] FSListToStringList(FileSystemInfoEx[] fsList) { string[] retVal = new string[fsList.Length]; for (int i = 0; i < fsList.Length; i++) retVal[i] = fsList[i].FullName; return retVal; }
//0.13: Added HasParent /// <summary> /// Return whether parent directory contain child directory. /// Aware UserFiles and Public directory too. /// </summary> /// <param name="child"></param> /// <param name="parentFullName"></param> /// <returns></returns> public static bool HasParent(FileSystemInfoEx child, string parentFullName) { if (child.FullName.StartsWith(parentFullName, StringComparison.InvariantCultureIgnoreCase)) return true; if (child.FullName.StartsWith(IID_UserFiles) || child.FullName.StartsWith(IID_Public)) return false; FileSystemInfoEx current = child.Parent; while (current != null && parentFullName != current.FullName) current = current.Parent; return (current != null); }
//0.3 public static ExModel FromExEntry(FileSystemInfoEx entry) { if (entry is DirectoryInfoEx) return FromExEntry(entry as DirectoryInfoEx); else return FromExEntry(entry as FileInfoEx); }
protected BblBook(BblLibraryRootNode root, BblLibraryNode parent, FileSystemInfoEx info, BookType type) : base(root, parent, info) { Initialize(type); }