Beispiel #1
0
 public void BroadcastCurrentDirectoryChanging(DirectoryInfoEx newDirectory)
 {
     foreach (DirectoryTreeItemViewModel rootmodel in _rootDirectoryModelList)
     {
         rootmodel.BroascastCurrentDirectoryChanging(newDirectory);
     }
 }
Beispiel #2
0
        void MoveDirectory(DirectoryInfoEx srcDir, DirectoryInfoEx destDir)
        {
            FileInfoEx[] files = srcDir.GetFiles();
            AddTotalCount(files.Length);
            foreach (FileInfoEx fi in files)
                if (!Aborted)
                {
                    CheckPause();
                    AddCompletedCount(fi.FullName);
                    MoveFile(fi, destDir);
                }
            files = null;

            DirectoryInfoEx[] dirs = srcDir.GetDirectories();
            AddTotalCount(dirs.Length);
            foreach (DirectoryInfoEx di in dirs)
                if (!Aborted)
                {
                    CheckPause();
                    AddCompletedCount(di.FullName);
                    DirectoryInfoEx destSubDir = PrepateDirectoryForMove(di, destDir, di.Name);
                    if (destSubDir != null)
                        MoveDirectory(di, destSubDir);
                }
            dirs = null;

            if (srcDir.Exists && srcDir.GetFileSystemInfos().Length == 0)
                srcDir.Delete();
        }
Beispiel #3
0
 private static void GeneratConfigFilePath(Type type, ref string configFilePath)
 {
     if (string.IsNullOrWhiteSpace(configFilePath))
     {
         configFilePath = Path.Combine(DirectoryInfoEx.GetAssemblyDirectory(type), DEFAULT_CONFIGFILE_NAME);
     }
 }
Beispiel #4
0
        public static string GetDisplayName(DirectoryInfoEx dx)
        {
            IntPtr pidl;
            uint   pchEaten = 0;
            var    sfgao    = new ShellAPI.SFGAO();

            DirectoryInfoEx.DesktopDirectory.ShellFolder.ParseDisplayName(IntPtr.Zero, IntPtr.Zero, dx.FullName, ref pchEaten, out pidl, ref sfgao);

            var ptrStr = Marshal.AllocCoTaskMem(ShellAPI.MAX_PATH * 2 + 4);

            Marshal.WriteInt32(ptrStr, 0, 0);
            var buf = new StringBuilder(ShellAPI.MAX_PATH);

            try
            {
                DirectoryInfoEx.DesktopDirectory.ShellFolder.GetDisplayNameOf(pidl, ShellAPI.SHGNO.NORMAL, ptrStr);
                ShellAPI.StrRetToBuf(ptrStr, pidl, buf, ShellAPI.MAX_PATH);
            }
            finally
            {
                if (ptrStr != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(ptrStr);
                }
                ptrStr = IntPtr.Zero;
            }

            return(buf.ToString());
        }
Beispiel #5
0
        private static void SetLabel(DirectoryInfoEx directory, SpecialDirectoryEntry directoryEntry)
        {
            if (directory.Name != directory.Label)
            {
                directoryEntry.Label = directory.Label;
            }

            if (directory.TryGetKnownFolderType(out var knownFolder))
            {
                var definition = knownFolder.Definition;
                if (!string.IsNullOrEmpty(definition.LocalizedName))
                {
                    var parts = definition.LocalizedName.TrimStart('@').Split(',');
                    if (parts.Length == 2 && int.TryParse(parts[1], out var id))
                    {
                        directoryEntry.LabelPath = parts[0];
                        directoryEntry.LabelId   = id;
                        return;
                    }
                }
            }

            //http://archives.miloush.net/michkap/archive/2007/01/18/1487464.html
            var sb  = new StringBuilder(500);
            var len = (uint)sb.Capacity;

            if (NativeMethods.SHGetLocalizedName(directory.FullName, sb, ref len, out var pidsRes) == IntPtr.Zero)
            {
                directoryEntry.LabelPath = sb.ToString();
                directoryEntry.LabelId   = pidsRes;
            }
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            var d = DirectoryInfoEx.FromString(@"C:\Users\lycj\Downloads") as DirectoryInfoEx;

            var    runCount  = 0;
            int    iteration = 1;
            string line      = Console.ReadLine();

            while (line == "" || Int32.TryParse(line, out runCount))
            {
                if (line == "")
                {
                    runCount = 1;
                }
                for (int i = 0; i < runCount; i++)
                {
                    var count = d.EnumerateFileSystemInfos().Count();
                    Console.WriteLine(String.Format("{0} - {1} listed", iteration++, count));
                }
                GC.Collect(0, GCCollectionMode.Forced);
                Console.WriteLine(
                    String.Format("AllocatedCount - PIDL={0} DirEx={1}", PIDL.Counter, FileSystemInfoEx.counter));
                line = Console.ReadLine();
            }
        }
        public static void InvokeCommand(DirectoryInfoEx parent, IntPtr[] pidls, uint cmd, Point ptInvoke)
        {
            IntPtr       icontextMenuPtr;
            IContextMenu iContextMenu;

            //0.15: Fixed ShellFolder not freed.
            using (ShellFolder2 parentShellFolder = parent.ShellFolder)
                if (GetIContextMenu(parentShellFolder, pidls, out icontextMenuPtr, out iContextMenu))
                {
                    try
                    {
                        InvokeCommand(
                            iContextMenu,
                            cmd,
                            parent.FullName,
                            ptInvoke);
                    }
                    catch (Exception) { }
                    finally
                    {
                        if (iContextMenu != null)
                        {
                            Marshal.ReleaseComObject(iContextMenu);
                        }

                        if (icontextMenuPtr != IntPtr.Zero)
                        {
                            Marshal.Release(icontextMenuPtr);
                        }
                    }
                }
        }
Beispiel #8
0
        //#region IStream/IStorage

        //public static bool GetIStream(ShellItem item, out IntPtr streamPtr, out IStream stream)
        //{
        //    if (item.ParentItem.ShellFolder.BindToStorage(
        //                item.PIDLRel.Ptr,
        //                IntPtr.Zero,
        //                ref ShellAPI.IID_IStream,
        //                out streamPtr) == ShellAPI.S_OK)
        //    {
        //        stream = (IStream)Marshal.GetTypedObjectForIUnknown(streamPtr, typeof(IStream));
        //        return true;
        //    }
        //    else
        //    {
        //        stream = null;
        //        streamPtr = IntPtr.Zero;
        //        return false;
        //    }
        //}

        //public static bool GetIStorage(ShellItem item, out IntPtr storagePtr, out IStorage storage)
        //{
        //    if (item.ParentItem.ShellFolder.BindToStorage(
        //                item.PIDLRel.Ptr,
        //                IntPtr.Zero,
        //                ref ShellAPI.IID_IStorage,
        //                out storagePtr) == ShellAPI.S_OK)
        //    {
        //        storage = (IStorage)Marshal.GetTypedObjectForIUnknown(storagePtr, typeof(IStorage));
        //        return true;
        //    }
        //    else
        //    {
        //        storage = null;
        //        storagePtr = IntPtr.Zero;
        //        return false;
        //    }
        //}

        //#endregion

        #region Drag/Drop

        /// <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);
                }
        }
Beispiel #9
0
        protected override void DoWork()
        {
            ReportStart();
            CheckPause();

            AddTotalCount(_copyFrom.Length);
            foreach (FileSystemInfoEx item in _copyFrom)
            {
                if (!Aborted)
                {
                    CheckPause();
                    AddCompletedCount(item.FullName);
                    if (item is FileInfoEx)
                    {
                        CopyFile(item as FileInfoEx, _dest);
                    }
                    else
                    {
                        DirectoryInfoEx dest = PrepateDirectoryForCopy(item as DirectoryInfoEx, _dest, item.Name);
                        if (dest != null)
                        {
                            CopyDirectory(item as DirectoryInfoEx, dest);
                        }
                    }
                }
            }
            ReportCompleted();
        }
Beispiel #10
0
        void CopyDirectory(DirectoryInfoEx srcDir, DirectoryInfoEx destDir)
        {
            FileInfoEx[] files = srcDir.GetFiles();
            AddTotalCount(files.Length);
            foreach (FileInfoEx fi in files)
            {
                if (!Aborted)
                {
                    CheckPause();
                    AddCompletedCount(fi.FullName);
                    CopyFile(fi, destDir);
                }
            }
            files = null;

            DirectoryInfoEx[] dirs = srcDir.GetDirectories();
            AddTotalCount(dirs.Length);
            foreach (DirectoryInfoEx di in dirs)
            {
                if (!Aborted)
                {
                    CheckPause();
                    AddCompletedCount(di.FullName);
                    DirectoryInfoEx destSubDir = PrepateDirectoryForCopy(di, destDir, di.Name);
                    if (destSubDir != null)
                    {
                        CopyDirectory(di, destSubDir);
                    }
                }
            }

            dirs = null;
        }
Beispiel #11
0
        public BblLibrary(DirectoryInfoEx root)
        {
            if (mainThread == null)
            {
                mainThread = TaskScheduler.FromCurrentSynchronizationContext();
            }

            _root = new BblLibraryRootNode(root);

            _progress = new Progress <BookOperationData>((bookOperationData) => { OnBookOperation(bookOperationData); });

            _populatingTask = Task.Run(() => BuildLibrary(_progress), _populatingCancelTokenSrc.Token);
            _populatingTask.ContinueWith((t1) => { OnPopulatingCompleted(); },
                                         _populatingCancelTokenSrc.Token, TaskContinuationOptions.OnlyOnRanToCompletion, mainThread);

            _fileWatcher.Path = root.FullName;
            _dirWatcher.Path  = root.FullName;

            _fileWatcher.IncludeSubdirectories = true;
            _dirWatcher.IncludeSubdirectories  = true;

            _fileWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName;
            _dirWatcher.NotifyFilter  = NotifyFilters.DirectoryName;

            _fileWatcher.Created += OnFileCreated;
            _fileWatcher.Deleted += OnFileDeleted;
            _fileWatcher.Renamed += OnFileRenamed;
            _dirWatcher.Created  += OnDirectoryCreated;
            _dirWatcher.Deleted  += OnDirectoryDeleted;
            _dirWatcher.Renamed  += OnDirectoryRenamed;

            // Begin watching.
            _fileWatcher.EnableRaisingEvents = true;
            _dirWatcher.EnableRaisingEvents  = true;
        }
Beispiel #12
0
        void CopyDirectory(DirectoryInfoEx srcDir, DirectoryInfoEx destDir)
        {
            FileInfoEx[] files = srcDir.GetFiles();
            AddTotalCount(files.Length);
            foreach (FileInfoEx fi in files)
                if (!Aborted)
                {
                    CheckPause();
                    AddCompletedCount(fi.FullName);
                    CopyFile(fi, destDir);
                }
            files = null;

            DirectoryInfoEx[] dirs = srcDir.GetDirectories();
            AddTotalCount(dirs.Length);
            foreach (DirectoryInfoEx di in dirs)
                if (!Aborted)
                {
                    CheckPause();
                    AddCompletedCount(di.FullName);
                    DirectoryInfoEx destSubDir = PrepateDirectoryForCopy(di, destDir, di.Name);
                    if (destSubDir != null)
                        CopyDirectory(di, destSubDir);
                }

            dirs = null;
        }
Beispiel #13
0
        //Load a directory when TabViewModel.SelectedFolder is changed.
        public void Open(DirectoryInfoEx dir)
        {
            if (!Directory.Exists(dir.FullName))
            {
                return;
            }
            if (_model != null)
            {
                CloseLibrary();
            }

            //open
            _model = new BblLibrary(dir);
            _model.LibraryLoaded += OnLibraryLoaded;

            Tab.ProgressValue         = 0;
            Tab.ProgressMaximum       = 100;
            Tab.ProgressIsDeterminate = true;

            _books = new VmCollection <BookViewModel, BblBook>(_model.Books, this);
            NotifyOfPropertyChange(() => Books);


            _booksCV = (ListCollectionView)CollectionViewSource.GetDefaultView(_books);
            ((INotifyCollectionChanged)(_booksCV)).CollectionChanged += OnBooksCollectionChanged;
            NotifyOfPropertyChange(() => BooksCV);

            Tab.ResetSortUI();
            Tab.TabState.currentBookmark.libraryPath = dir.FullName;
            _booksCV.CustomSort = comparer;
        }
Beispiel #14
0
        internal DirectoryListEx(DirectoryInfoEx dir)
        {
            rootDir = dir;
            invalidate();

            var handler = (FileSystemEventHandlerEx) delegate(object sender, FileSystemEventArgsEx args)
            {
                string path1 = args.FullPath;
                if (String.Equals(path1, rootDir.FullName, StringComparison.InvariantCultureIgnoreCase) ||
                    String.Equals(PathEx.GetDirectoryName(path1), rootDir.FullName, StringComparison.InvariantCultureIgnoreCase))
                {
                    invalidate();
                }
            };

            var renamehandler = (RenameEventHandlerEx) delegate(object sender, RenameEventArgsEx args)
            {
                string path1 = args.OldFullPath;

                if (String.Equals(path1, rootDir.FullName, StringComparison.InvariantCultureIgnoreCase) ||
                    String.Equals(PathEx.GetDirectoryName(path1), rootDir.FullName, StringComparison.InvariantCultureIgnoreCase))
                {
                    invalidate();
                }
            };

            //watcher.OnChanged += handler;
            watcher.OnCreated += handler;
            watcher.OnDeleted += handler;
            watcher.OnRenamed += renamehandler;
        }
        public DirectoryInfoEx NewFolder()
        {
            string template   = "New Folder{0}";
            string folderName = String.Format(template, "").Trim(' ');
            int    idx        = 1;

            while (EmbeddedDirectoryModel.EmbeddedDirectoryEntry[folderName] != null)
            {
                folderName = String.Format(template, "(" + idx++.ToString() + ")");
            }

            DirectoryInfoEx retDir = this.EmbeddedDirectoryModel.EmbeddedDirectoryEntry.CreateDirectory(folderName);

            //Hook select the new item after refreshed.
            EventHandler <EventArgs> handler = null;

            handler = (EventHandler <EventArgs>) delegate(object sender, EventArgs args)
            {
                Select(retDir);
                bgWorker_LoadSubEntries.BackgroundTaskCompleted -= handler;
            };
            bgWorker_LoadSubEntries.BackgroundTaskCompleted += handler;
            //Refresh
            Refresh();

            return(retDir);
        }
        static void OnDrop(object s, DragEventArgs e)
        {
            DependencyObject sender     = (DependencyObject)s;
            DirectoryInfoEx  currentDir = locateCurrentDirectory(sender, e);

            if (currentDir == null)
            {
                return;
            }

            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                (sender as FrameworkElement).Cursor = Cursors.Wait;
                bool refreshFolder = false;
                try
                {
                    string[] addList =
                        e.Data.GetDataPresent(DataObjectEx.DataFormats_EntryString) ?
                        (string[])e.Data.GetData(DataObjectEx.DataFormats_EntryString) :
                        (string[])e.Data.GetData(DataFormats.FileDrop);

                    //0.2: Fixed DropDropHelper strange drag behavior. (folder dropped to itself, caused by OnDragOver skipped)
                    if (CanDrop(currentDir.FullName, addList[0]))
                    {
                        string queryText = String.Format("Add {0} items to {1}?", addList.Length, currentDir.FullName);
                        if (!GetConfirmDrop(sender) ||
                            MessageBox.Show(queryText, "Add", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                        {
                            foreach (string item in addList)
                            {
                                //FileSystemInfoEx parsedItem = FileSystemInfoEx.FromString(item);
                                //IOTools.Copy(parsedItem.FullName, PathEx.Combine(currentDir.FullName, parsedItem.Name));
                                //if (parsedItem is DirectoryInfoEx) refreshFolder = true;

                                FileSystemInfoEx[] addListExA = stringToEx(addList);
                                int id = WorkSpawner.SpawnCopyWork(addListExA, currentDir, true);
                                System.IO.Tools.WorkFinishedEventHandler handler = null;
                                handler = (System.IO.Tools.WorkFinishedEventHandler) delegate(object send, System.IO.Tools.WorkFinishedEventArgs args)
                                {
                                    refresh(sender, e, refreshFolder);
                                    WorkSpawner.Works[id].WorkFinished -= handler;
                                };


                                WorkSpawner.Works[id].WorkFinished += handler;
                                WorkSpawner.Start(id);
                            }
                        }
                    }
                }
                finally
                {
                    (sender as FrameworkElement).Cursor = Cursors.Arrow;
                    SetIsDragOver(null);
                }

                refresh(sender, e, refreshFolder);
            }
        }
Beispiel #17
0
 public ListWork(int id, DirectoryInfoEx[] dirs, bool listDir, bool listFile, string fileMask)
     : base(id, dirs.Length > 0 ? dirs[0] : null, null)
 {
     init(dirs);
     _listDir = listDir;
     _listFile = listFile;
     _fileMask = fileMask;
 }
Beispiel #18
0
 public IActionResult GetDirectory([FromQuery] string path)
 {
     using (var directory = new DirectoryInfoEx(path))
     {
         var directoryEntry = new DirectoryHelper().GetDirectoryEntry(directory, null);
         return(Ok(directoryEntry));
     }
 }
Beispiel #19
0
 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 async Task <IEnumerable <FileExplorerEntry> > GetEntriesKeepOrder(this DirectoryHelper directoryHelper,
                                                                                 string directoryPath, CancellationToken token)
 {
     using (var directory = new DirectoryInfoEx(directoryPath))
     {
         return(await directoryHelper.GetEntriesKeepOrder(directory, token));
     }
 }
Beispiel #21
0
 public void LoadPhotoAlbums()
 {
     foreach (string photoAblumDirectory in DirectoryInfoEx.GetChildDirectories(_rootDirectory))
     {
         var photoAlbumLoader = new AlbumLoader(_context, _placeRegister, photoAblumDirectory);
         photoAlbumLoader.Load();
     }
 }
Beispiel #22
0
        private static bool SetSpecialFolderAttributes(DirectoryInfoEx directory, SpecialDirectoryEntry specialDirectory)
        {
            SetLabel(directory, specialDirectory);
            specialDirectory.IconId = GetFolderIcon(directory);

            return(specialDirectory.IconId != 0 || specialDirectory.Label != null || specialDirectory.LabelId != 0 ||
                   specialDirectory.LabelPath != null);
        }
Beispiel #23
0
 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 int SpawnMoveWork(FileSystemInfoEx[] src, DirectoryInfoEx dest, bool showProgressDialog)
 {
     lock (onGoingWorkList)
     {
         IExWork retVal = new MoveWork(newKey(), src, dest);
         retVal.IsProgressDialogEnabled = showProgressDialog;
         hookWorkEvent(retVal);
         return(addWork(retVal.ID, retVal));
     }
 }
Beispiel #25
0
        public Task <IEnumerable <DirectoryEntry> > GetDirectoryEntries(DirectoryInfoEx directory, CancellationToken token)
        {
            var entries = directory.EnumerateDirectories("*", SearchOption.TopDirectoryOnly,
                                                         () => token.IsCancellationRequested);

            return(TaskCombinators.ThrottledAsync(entries, (entry, _) => Task.Run(() =>
            {
                using (entry)
                    return GetDirectoryEntry(entry, directory);
            }), token));
        }
 public static DirectoryModel FromExEntry(DirectoryInfoEx entry)
 {
     if (entry.FullName.EndsWith(":\\"))
     {
         return(new DriveModel(entry));
     }
     else
     {
         return(new DirectoryModel(entry as DirectoryInfoEx));
     }
 }
Beispiel #27
0
        public bool DeleteDirectory(string path)
        {
            DirectoryInfoEx d    = new DirectoryInfoEx(path);
            BblLibraryNode  node = FindChild(d);

            if (node != null)
            {
                node.OnFileSystemEntryDeleted();
            }
            return(false);
        }
        public static bool GetNewContextMenu(DirectoryInfoEx item, out IntPtr iContextMenuPtr, out IContextMenu iContextMenu)
        {
            if (ShellAPI.CoCreateInstance(
                    ref ShellAPI.CLSID_NewMenu,
                    IntPtr.Zero,
                    ShellAPI.CLSCTX.INPROC_SERVER,
                    ref ShellAPI.IID_IContextMenu,
                    out iContextMenuPtr) == ShellAPI.S_OK)
            {
                iContextMenu = Marshal.GetTypedObjectForIUnknown(iContextMenuPtr, typeof(IContextMenu)) as IContextMenu;

                IntPtr iShellExtInitPtr;
                if (Marshal.QueryInterface(
                        iContextMenuPtr,
                        ref ShellAPI.IID_IShellExtInit,
                        out iShellExtInitPtr) == ShellAPI.S_OK)
                {
                    IShellExtInit iShellExtInit = Marshal.GetTypedObjectForIUnknown(
                        iShellExtInitPtr, typeof(IShellExtInit)) as IShellExtInit;

                    item.RequestPIDL(pidlLookup =>
                    {
                        iShellExtInit.Initialize(pidlLookup.Ptr, IntPtr.Zero, 0);

                        Marshal.ReleaseComObject(iShellExtInit);
                        Marshal.Release(iShellExtInitPtr);
                    });

                    return(true);
                }
                else
                {
                    if (iContextMenu != null)
                    {
                        Marshal.ReleaseComObject(iContextMenu);
                        iContextMenu = null;
                    }

                    if (iContextMenuPtr != IntPtr.Zero)
                    {
                        Marshal.Release(iContextMenuPtr);
                        iContextMenuPtr = IntPtr.Zero;
                    }

                    return(false);
                }
            }
            else
            {
                iContextMenuPtr = IntPtr.Zero;
                iContextMenu    = null;
                return(false);
            }
        }
Beispiel #29
0
        public BblLibraryNode AddDirectory(string path)
        {
            BblLibraryNode  node   = null;
            DirectoryInfoEx d      = new DirectoryInfoEx(path);
            BblLibraryNode  parent = FindChild(d.Parent);

            if (parent != null)
            {
                node = parent.AddChildDirectory(d);
            }
            return(null);
        }
Beispiel #30
0
 public static string ParseNameEx(this DirectoryInfoEx dx)
 {
     if (dx.Name.StartsWith("::{") && (dx.Name.EndsWith("}")))
     {
         return(GetDisplayName(dx));
     }
     if (dx.Name.EndsWith(".library-ms"))
     {
         return(dx.Name.Substring(0, dx.Name.Length - 11));
     }
     return(dx.Name);
 }
        public TreeNode BuildTreeUI()
        {
            this.RootNode = new TreeNode();

            if ((!string.IsNullOrWhiteSpace(this.RootFolder)) && Directory.Exists(this.RootFolder))
            {
                var rootDirectoryInfo = new DirectoryInfoEx(this.RootFolder);
                this.RootNode.Nodes.Add(CreateDirectoryNode(rootDirectoryInfo));
            }

            return(this.RootNode);
        }
Beispiel #32
0
        /// <summary>
        /// 写配置对象到xml文件
        /// </summary>
        /// <param name="config">配置对象</param>
        /// <param name="configFilePath">配置文件存放路径</param>
        public static void WriteConfigToXmlFile(object config, string configFilePath)
        {
            if (configFilePath == null)
            {
                throw new ArgumentNullException(nameof(configFilePath));
            }

            XDocument xdoc = WriteConfigToXDocument(config);

            DirectoryInfoEx.CheckFilePathDirectory(configFilePath);
            xdoc.Save(configFilePath);
        }
Beispiel #33
0
        public BblLibraryNode RenameDirectory(string newPath, string oldPath)
        {
            DirectoryInfoEx d    = new DirectoryInfoEx(newPath);
            DirectoryInfoEx old  = new DirectoryInfoEx(oldPath);
            BblLibraryNode  node = FindChild(old);

            if (node != null)
            {
                return(node.OnFileSystemEntryRenamed(d));
            }
            return(null);
        }
Beispiel #34
0
        /// <summary>
        /// 创建数据库拼接连接字符串
        /// </summary>
        /// <param name="config">数据库配置</param>
        /// <param name="visitType">数据库访问类型</param>
        /// <returns>数据库连接字符串</returns>
        protected override string CreateDBSpliceConStr(DatabaseConfig config, DBVisitType visitType)
        {
            var scsb = new SQLiteConnectionStringBuilder();

            scsb.Pooling    = true;
            scsb.DataSource = DirectoryInfoEx.GetFullPath(config.DatabaseName);
            if (!string.IsNullOrEmpty(config.Password))
            {
                scsb.Password = config.Password;
            }

            return(this.CreateSQLiteDBConStr(scsb));
        }
Beispiel #35
0
        private void ListDir(DirectoryInfoEx dir)
        {
            foreach (FileInfoEx fi in dir.GetFiles())
                if (_listFile && (String.IsNullOrEmpty(_fileMask) || IOTools.MatchFileMask(fi.Name, _fileMask)))
                    ReportWorkList(fi);

            DirectoryInfoEx[] dirs = dir.GetDirectories();
            AddTotalCount(dirs.Length);
            foreach (DirectoryInfoEx di in dirs)
            {
                if (_listDir)
                    ReportWorkList(di);
                ListDir(di);
                AddCompletedCount(di.FullName);
            }

            dirs = null;
        }
Beispiel #36
0
 public ListWork(int id, DirectoryInfoEx dir)
     : base(id, dir, null)
 {
     init(new DirectoryInfoEx[] { dir });
 }
 public static int SpawnListWork(DirectoryInfoEx[] dirs, bool listDir, bool listFile, string fileMask, bool showProgressDialog)
 {
     lock (onGoingWorkList)
     {
         IExWork retVal = new ListWork(newKey(), dirs, listDir, listFile, fileMask);
         retVal.IsProgressDialogEnabled = showProgressDialog;
         hookWorkEvent(retVal);
         return addWork(retVal.ID, retVal);
     }
 }
 public static int SpawnMoveWork(FileSystemInfoEx[] src, DirectoryInfoEx dest, bool showProgressDialog)
 {
     lock (onGoingWorkList)
     {
         IExWork retVal = new MoveWork(newKey(), src, dest);
         retVal.IsProgressDialogEnabled = showProgressDialog;
         hookWorkEvent(retVal);
         return addWork(retVal.ID, retVal);
     }
 }
 public static CollumnInfo[] GetCollumnInfo(DirectoryInfoEx dir)
 {
     using (ShellFolder2 sf2 = dir.ShellFolder)
         return GetCollumnInfo(sf2);
 }
Beispiel #40
0
        void MoveFile(FileInfoEx item, DirectoryInfoEx destDir)
        {
            FileSystemInfoEx lookupItem = destDir[item.Name];

            OverwriteMode overwrite = OverwriteMode.Replace;
            if (lookupItem != null)
                overwrite = AskOverwrite(item, lookupItem);

            switch (overwrite)
            {
                case OverwriteMode.Replace:
                    if (lookupItem != null)
                        lookupItem.Delete();
                    IOTools.Move(item.FullName, PathEx.Combine(destDir.FullName, item.Name));
                    break;
            }
        }
Beispiel #41
0
 public ListWork(int id, DirectoryInfoEx[] dirs)
     : base(id, dirs.Length > 0 ? dirs[0] : null, null)
 {
     init(dirs);
 }
 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);
         }
     }
 }
        public static void InvokeCommand(DirectoryInfoEx parent, IntPtr[] pidls, uint cmd, Point ptInvoke)
        {
            IntPtr icontextMenuPtr;
            IContextMenu iContextMenu;

            //0.15: Fixed ShellFolder not freed.
            using (ShellFolder2 parentShellFolder = parent.ShellFolder)
                if (GetIContextMenu(parentShellFolder, pidls, out icontextMenuPtr, out iContextMenu))
                {
                    try
                    {
                        InvokeCommand(
                            iContextMenu,
                            cmd,
                            parent.FullName,
                            ptInvoke);
                    }
                    catch (Exception) { }
                    finally
                    {
                        if (iContextMenu != null)
                            Marshal.ReleaseComObject(iContextMenu);

                        if (icontextMenuPtr != IntPtr.Zero)
                            Marshal.Release(icontextMenuPtr);
                    }
                }
        }
        public static bool GetNewContextMenu(DirectoryInfoEx item, out IntPtr iContextMenuPtr, out IContextMenu iContextMenu)
        {
            if (ShellAPI.CoCreateInstance(
                    ref ShellAPI.CLSID_NewMenu,
                    IntPtr.Zero,
                    ShellAPI.CLSCTX.INPROC_SERVER,
                    ref ShellAPI.IID_IContextMenu,
                    out iContextMenuPtr) == ShellAPI.S_OK)
            {
                iContextMenu = Marshal.GetTypedObjectForIUnknown(iContextMenuPtr, typeof(IContextMenu)) as IContextMenu;

                IntPtr iShellExtInitPtr;
                if (Marshal.QueryInterface(
                    iContextMenuPtr,
                    ref ShellAPI.IID_IShellExtInit,
                    out iShellExtInitPtr) == ShellAPI.S_OK)
                {
                    IShellExtInit iShellExtInit = Marshal.GetTypedObjectForIUnknown(
                        iShellExtInitPtr, typeof(IShellExtInit)) as IShellExtInit;

                    PIDL pidlLookup = item.PIDL;
                    try
                    {
                        iShellExtInit.Initialize(pidlLookup.Ptr, IntPtr.Zero, 0);

                        Marshal.ReleaseComObject(iShellExtInit);
                        Marshal.Release(iShellExtInitPtr);

                        return true;
                    }
                    finally
                    {
                        if (pidlLookup != null)
                            pidlLookup.Free();
                        pidlLookup = null;
                    }
                }
                else
                {
                    if (iContextMenu != null)
                    {
                        Marshal.ReleaseComObject(iContextMenu);
                        iContextMenu = null;
                    }

                    if (iContextMenuPtr != IntPtr.Zero)
                    {
                        Marshal.Release(iContextMenuPtr);
                        iContextMenuPtr = IntPtr.Zero;
                    }

                    return false;
                }
            }
            else
            {
                iContextMenuPtr = IntPtr.Zero;
                iContextMenu = null;
                return false;
            }
        }
Beispiel #45
0
        void CopyFile(FileInfoEx item, DirectoryInfoEx destDir)
        {
            FileSystemInfoEx lookupItem = destDir[item.Name];

            if (lookupItem is FileInfoEx)
            {
                if (item.Length == (lookupItem as FileInfoEx).Length)
                {
                    string srcCRC = Helper.GetFileCRC(item.FullName);
                    string destCRC = Helper.GetFileCRC(lookupItem.FullName);
                    if (srcCRC == destCRC && item.Length == (lookupItem as FileInfoEx).Length)
                        return; //Same file, no copy needed.
                }
            }

            OverwriteMode overwrite = OverwriteMode.Replace;
            if (lookupItem != null)
                overwrite = AskOverwrite(item, lookupItem);

            switch (overwrite)
            {
                case OverwriteMode.Replace :
                    if (lookupItem != null)
                        lookupItem.Delete();
                    FileCancelDelegate cancel = delegate { return Aborted; };
                    IOTools.CopyFile(item.FullName, PathEx.Combine(destDir.FullName, item.Name), cancel);
                break;
            }
        }
Beispiel #46
0
 void init(DirectoryInfoEx[] dirs)
 {
     _dirsToList = dirs;
     WorkType = WorkType.List;
 }
Beispiel #47
0
        DirectoryInfoEx PrepateDirectoryForCopy(DirectoryInfoEx srcDir, DirectoryInfoEx baseDir, string dirName)
        {
            bool isDirectory;
            if (!baseDir.Exists)
                baseDir.Create();
            if (baseDir.Contains(dirName, out isDirectory))
            {
                FileSystemInfoEx destSubItem = baseDir[dirName];

                if (!isDirectory)
                {
                    OverwriteMode overwrite = AskOverwrite(srcDir, destSubItem);
                    switch (overwrite)
                    {
                        case OverwriteMode.KeepOriginal :
                            return null;
                        case OverwriteMode.Replace :
                            destSubItem.Delete();
                            return baseDir.CreateDirectory(dirName);
                    }
                    throw new NotImplementedException("OverwriteMode");
                }
                else return destSubItem as DirectoryInfoEx;
            }
            else return baseDir.CreateDirectory(dirName);
        }