コード例 #1
0
        private bool LoadSubDirectories(DirectoryLoadOptions options, string path)
        {
            DirectoryInfo[] folderinfos;
            if (StringHandler.IsSpecialFolder(path))
            {
                var specialFolder = SpecialFolderLoader.LoadSpecialFolder(path);
                folderinfos = new DirectoryInfo[specialFolder.FolderPaths.Count];
                for (int i = 0; i < specialFolder.FolderPaths.Count; i++)
                {
                    folderinfos[i] = new DirectoryInfo(specialFolder.FolderPaths[i]);
                }
            }
            else
            {
                try
                {
                    var directoryInfo = new DirectoryInfo(path);

                    folderinfos = directoryInfo.GetDirectories();
                }
                catch (Exception e)
                {
                    ImpError error = new ImpError(ErrorType.FailedToOpenFolder, e.Message);
                    mainC.EventC.ShowError(error);
                    return(true);
                }
            }


            foreach (var folderinfo in folderinfos)
            {
                AddFolderToPlayList(options, folderinfo.FullName);
            }
            return(false);
        }
コード例 #2
0
        private bool LoadSubDirectories(DirectoryLoadOptions options, string path)
        {
            DirectoryInfo[] folderinfos;
            if (StringHandler.IsSpecialFolder(path))
            {
                var specialFolder = SpecialFolderLoader.LoadSpecialFolder(path);
                folderinfos = new DirectoryInfo[specialFolder.FolderPaths.Count];
                for (var i = 0; i < specialFolder.FolderPaths.Count; i++)
                {
                    folderinfos[i] = new DirectoryInfo(specialFolder.FolderPaths[i]);
                }
            }
            else
            {
                try
                {
                    var directoryInfo = new DirectoryInfo(path);

                    folderinfos = directoryInfo.GetDirectories();
                }
                catch (Exception e)
                {
                    var error = new ImpError(ErrorType.FailedToOpenFolder, e.Message);
                    mainC.EventC.ShowError(error);
                    return(true);
                }
            }

            if (path == options.RootPath && options.FilterOptions.HasFlag(FilterOptions.ChildFolders))
            {
                foreach (var folderinfo in folderinfos)
                {
                    if (StringHandler.FindFound(folderinfo.FullName, options.FindDirectoriesWords))
                    {
                        // Add only when going through filter
                        AddFolderToPlayList(options, folderinfo.FullName);
                    }
                }
            }
            else
            {
                foreach (var folderinfo in folderinfos)
                {
                    AddFolderToPlayList(options, folderinfo.FullName);
                }
            }

            return(false);
        }
コード例 #3
0
        private void AddFolderToPlayList(DirectoryLoadOptions options, string path)
        {
            if (options.SearchOption == SearchOption.AllDirectories)
            {
                if (LoadSubDirectories(options, path))
                {
                    return;
                }
                if (options.FilterOptions.HasFlag(FilterOptions.ChildFolders) && path == options.RootPath)
                {
                    return;
                }
            }

            FileInfo[] fileInfos;
            if (StringHandler.IsSpecialFolder(path))
            {
                var specialFolder = SpecialFolderLoader.LoadSpecialFolder(path);
                fileInfos = new FileInfo[specialFolder.FilePaths.Count];
                for (var i = 0; i < specialFolder.FilePaths.Count; i++)
                {
                    fileInfos[i] = new FileInfo(specialFolder.FilePaths[i]);
                }
            }
            else
            {
                try
                {
                    //files = Directory.GetFiles(path);
                    var directoryInfo = new DirectoryInfo(path);

                    fileInfos = directoryInfo.GetFiles();
                }
                catch (Exception e)
                {
                    // doesn't matter why path choosing failed, no files available in this folder
                    var error = new ImpError(ErrorType.FailedToOpenFolder, e.Message);
                    mainC.EventC.ShowError(error);
                    return;
                }
            }
            if (fileInfos.Length < 1)
            {
                return;
            }

            var files = options.FilterFiles(fileInfos, options.FilterOptions.HasFlag(FilterOptions.Files));

            IComparer <FileImpInfo> comparer;

            switch ((FileSortMode)ButtonSort.CurrentState)
            {
            case FileSortMode.Name:
                comparer = new ComparerFileName();
                break;

            case FileSortMode.Date:
                comparer = new ComparerFileDate();
                break;

            case FileSortMode.LastUsage:
                comparer = new ComparerViewThenName();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            Array.Sort(files, comparer);

            foreach (var fileInfo in files)
            {
                if (options.PlayFirstFile)
                {
                    mainC.Exec(ImpCommand.AddFile, fileInfo);

                    object[] args = { ImpCommand.OpenFile, fileInfo };
                    Dispatcher.BeginInvoke(new ExecDelegate <ImpCommand>(mainC.Exec), DispatcherPriority.Normal, args);

                    options.PlayFirstFile = false;
                }
                else
                {
                    mainC.Exec(ImpCommand.AddFile, fileInfo);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Sets the path.
        /// </summary>
        /// <param name="path">
        /// The path. Custom paths are formatted like "$$C:\movies\", special folders should like "$Music" and
        /// normal paths "C:\movies" or "C:\Movies\" </param>
        public void SetPath(string pathData)
        {
            path = pathData;
            ImpFolder select = null;
            // it's rather rare to have smaller structure than 10, so skip start list capacity at 16
            var list = new List <ImpFolder>(16);

            var specialFolder = SpecialFolderLoader.LoadSpecialFolder(pathData);

            if (specialFolder != null)
            {
                controller.Clear();

                // special folder
                select = new ImpFolder(pathData, pathData.Replace("$", ""));
                controller.AddItemUnfiltered(@select);
                //list.Add(select);

                foreach (var folderPath in specialFolder.FolderPaths)
                {
                    list.Add(new ImpFolder(folderPath, "  " + StringHandler.GetFilename(folderPath)));
                }

                list.Sort(new ComparerFolderSmart());

                controller.AddItems(list);
            }
            else
            {
                // normal folders:
                controller.Clear();

                // add drive
                var firstCharacter = pathData.Substring(0, 1);
                var newPath        = firstCharacter.ToUpper() + @":\";
                controller.AddItemUnfiltered(new ImpFolder(newPath, newPath));

                var index     = 3;
                var lastIndex = 2;
                var depth     = 1;
                if (path.Length > 3)
                {
                    do
                    {
                        if (path[index] == '\\')
                        {
                            controller.AddItemUnfiltered(CreatePathItem(path, index, depth, lastIndex));
                            //list.Add(CreatePathItem(path, index, depth, lastIndex));
                            lastIndex = index;
                            depth++;
                        }
                        index++;
                    } while (index < path.Length);

                    if (path[index - 1] != '\\')
                    {
                        select = CreatePathItem(path, index, depth, lastIndex);
                        controller.AddItemUnfiltered(@select);
                        //list.Add(select);
                        depth++;
                    }
                }

                try
                {
                    foreach (var directory in Directory.GetDirectories(path))
                    {
                        lastIndex = directory.LastIndexOf('\\');
                        list.Add(CreatePathItem(directory, directory.Length, depth, lastIndex));
                    }
                }
                catch (Exception) {}

                list.Sort(new ComparerFolderSmart());
                controller.AddItems(list);
            }
            controller.UpdateItems();
            controller.Select(select);
        }