private bool OpenLines(IEnumerable <string> list)
        {
            var files = new List <FileImpInfo>();

            foreach (var path in list)
            {
                if (Directory.Exists(path))
                {
                    // path is a directory

                    var options = new DirectoryLoadOptions(path, SearchOption.TopDirectoryOnly,
                                                           FileTypes.Music | FileTypes.Videos | FileTypes.Pictures, string.Empty);
                    FileInfo[] fileInfos;
                    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);
                        this.mainC.EventC.ShowError(error);
                        return(true);
                    }


                    if (fileInfos.Length < 1)
                    {
                        return(true);
                    }

                    files.AddRange(options.FilterFiles(fileInfos, false));
                }
                else if (File.Exists(path))
                {
                    files.Add(new FileImpInfo(path));
                }
                else
                {
                    // File or folder could not be identified
                    var error = new ImpError(path, ErrorType.FileNotFound);
                    this.mainC.EventC.ShowError(error);
                }
            }
            if (files.Count == 1)
            {
                this.mainC.Exec(ImpCommand.OpenFile, files[0]);
            }
            else
            {
                foreach (var fileInfo in files)
                {
                    this.mainC.Exec(ImpCommand.AddFile, fileInfo);
                }
            }
            return(false);
        }
        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);
        }
예제 #3
0
 /// <summary>
 /// Call dispatcher to switch to main thread so we can call load failed event
 /// </summary>
 /// <param name="errorMessage"></param>
 public void RaiseLoadFailed(ImpError errorMessage)
 {
     if (LoadFailed != null)
     {
         this.dispatcher.BeginInvoke(this.loadFailedMainEvent, DispatcherPriority.Normal, errorMessage);
     }
 }
        private void LoadFailed(ImpError error)
        {
            this.AllowedStyles = PlayerStyle.MediaPlayer;
            this.EventC.ShowError(error);
            this.MediaC.MediaClosed();

            this.playingItem = null;
            this.loadingItem = null;

            ClearPlayers();

            ResetTitle();
        }
예제 #5
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);
        }
예제 #6
0
        protected override bool Load(string path, out ImpError error)
        {
            var result = this.player.StartLoad(path);

            while (result.IsLoading)
            {
                Thread.Sleep(5);
            }

            error = result.Error;

            this.player.FinalizeLoad(result);

            return(result.Error != null);
        }
예제 #7
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);
                }
            }
        }
 public void ShowError(ImpError error)
 {
     SetEvent(new EventText("Error " + (int)error.Type + ": " + error.Text, 2, EventType.Delayed));
 }
예제 #9
0
 /// <summary>
 /// Using Main thread, raise the load failed event
 /// </summary>
 /// <param name="errorMessage"></param>
 public void RaiseLoadFailedMainThread(ImpError errorMessage)
 {
     LoadFailed(errorMessage);
 }
예제 #10
0
 protected abstract T Load(string path, out ImpError error);
예제 #11
0
        protected override ImpImage Load(string path, out ImpError error)
        {
            error = null;
            var myUri = new Uri(path, UriKind.RelativeOrAbsolute);
            var type  = GetType(path);

            BitmapDecoder decoder = null;

            try
            {
                switch (type)
                {
                case ImageType.Jpg:
                    try
                    {
                        decoder = new JpegBitmapDecoder(myUri, BitmapCreateOptions.PreservePixelFormat,
                                                        BitmapCacheOption.OnLoad);
                    }
                    catch (Exception)
                    {
                        var impJpgDecoder = new ImpJpgDecoder(myUri);
                        return(new ImpImage(impJpgDecoder.Source));
                    }
                    break;

                case ImageType.Png:
                    try
                    {
                        decoder = new PngBitmapDecoder(myUri, BitmapCreateOptions.PreservePixelFormat,
                                                       BitmapCacheOption.OnLoad);
                    }
                    catch (Exception)
                    {
                        var impPngDecoder = new ImpPngDecoder(myUri, BitmapCreateOptions.PreservePixelFormat,
                                                              BitmapCacheOption.OnLoad);
                        return(new ImpImage(impPngDecoder.Source));
                    }
                    break;

                case ImageType.Gif:
                    decoder = new GifBitmapDecoder(myUri, BitmapCreateOptions.PreservePixelFormat,
                                                   BitmapCacheOption.OnLoad);

                    if (decoder.Frames.Count > 1)
                    {
                        using (var stream = new FileStream(myUri.AbsolutePath, FileMode.Open))
                        {
                            var gifFile = GifFile.ReadGifFile(stream, true);
                            return(new ImpImage((GifBitmapDecoder)decoder, gifFile));
                        }
                    }
                    break;

                case ImageType.Bmp:
                    decoder = new BmpBitmapDecoder(myUri, BitmapCreateOptions.PreservePixelFormat,
                                                   BitmapCacheOption.OnLoad);
                    break;

                case ImageType.Tiff:
                    decoder = new TiffBitmapDecoder(myUri, BitmapCreateOptions.PreservePixelFormat,
                                                    BitmapCacheOption.OnLoad);
                    break;

                case ImageType.Tga:
                    error = new ImpError(ErrorType.NotSupportedFile);
                    break;

                case ImageType.Icon:
                    decoder = new IconBitmapDecoder(myUri, BitmapCreateOptions.PreservePixelFormat,
                                                    BitmapCacheOption.OnLoad);
                    break;

                case ImageType.WindowsMediaPhoto:
                    decoder = new WmpBitmapDecoder(myUri, BitmapCreateOptions.PreservePixelFormat,
                                                   BitmapCacheOption.OnLoad);
                    break;

                default:
                    error = new ImpError(ErrorType.UnknownFileType);
                    break;
                }
            }
            catch (Exception)
            {
                error = new ImpError(ErrorType.FailedToOpenFile);
            }

            if (error != null)
            {
                return(null);
            }

            return(new ImpImage(decoder));
        }