Пример #1
0
        private async Task CreateThumbnails(string selected, AbstractMediaProvider provider)
        {
            cancellationTokenSource = new CancellationTokenSource();
            var token = cancellationTokenSource.Token;

            thumbnailGrid.Items.Clear();
            fileList = await provider.GetChildEntries(selected);

            Array.Sort(fileList, (string s1, string s2) =>
            {
                int i1, i2;
                string s1WithoutExtension = s1.Substring(0, s1.LastIndexOf("."));
                string s2WithoutExtension = s2.Substring(0, s2.LastIndexOf("."));

                if (Int32.TryParse(s1WithoutExtension, out i1) && Int32.TryParse(s2WithoutExtension, out i2))
                {
                    return(i1.CompareTo(i2));
                }
                return(s1.CompareTo(s2));
            });

            try
            {
                foreach (var file in fileList)
                {
                    var stream = await provider.OpenEntryAsRandomAccessStreamAsync(file);

                    SoftwareBitmap bitmap = await CreateResizedBitmap(stream, 200, 200);

                    var source        = new SoftwareBitmapSource();
                    var setSourceTask = source.SetBitmapAsync(bitmap);

                    var thumbnail = new Thumbnail();
                    thumbnail.Image.Source = source;
                    thumbnail.Click       += Thumbnail_Click;

                    thumbnail.Label.Text = ExtractFilename(file);

                    thumbnail.UserData = file;

                    token.ThrowIfCancellationRequested();
                    thumbnailGrid.Items.Add(thumbnail);

                    await setSourceTask;
                    await Task.Delay(1);
                }
            }
            catch { }
            finally { cancellationTokenSource = null; }
        }
Пример #2
0
        public async void SetMediaProvider(AbstractMediaProvider provider)
        {
            if (this.provider != null)
            {
                this.provider.Dispose();
            }
            this.provider = provider;
            subFolderListCtrl.Items.Clear();
            folderList = await provider.GetFolderEntries();

            RebuildSubFolderList();

            subFolderListCtrl.SelectedIndex = 0;
            imageControl.Visibility         = Visibility.Collapsed;
            imageControl.AutoEnabled        = false;
            imageBorder.Visibility          = Visibility.Collapsed;
            loadingBorder.Visibility        = Visibility.Collapsed;
            thumbnailGrid.IsEnabled         = true;
            this.IsEnabled = true;
        }
Пример #3
0
        private async Task <Exception> ChangeMediaProvider(AbstractMediaProvider provider)
        {
            if (this.NavigationPane.SelectedItem is NavigationViewItem selectedItem)
            {
                if (selectedItem.Content is FolderListItem item)
                {
                    var page = this.thumbnailPages.Find((p) => p.Entry == item.FolderEntry);
                    if (page != null)
                    {
                        page.CancellationToken.Cancel();
                    }
                }
            }

            FolderReadingDialog dialog = new FolderReadingDialog();

            _ = dialog.ShowAsync(ContentDialogPlacement.Popup);

            Exception error;

            error = await MediaManager.ChangeProvider(provider);

            if (error != null)
            {
                dialog.Hide();
                return(error);
            }

            await this.RebuildSubFolderList(dialog);

            GC.Collect();
            this.ThumbnailBorder.Opacity = 0;

            this.HideImageControl();
            this.IsEnabled = true;
            dialog.Hide();
            return(null);
        }
Пример #4
0
        private async void openFileButton_Click(object sender, RoutedEventArgs e)
        {
            this.IsEnabled = false;
            var picker = new FileOpenPicker();

            picker.FileTypeFilter.Add(".zip");
            picker.FileTypeFilter.Add(".rar");
            picker.FileTypeFilter.Add(".7z");
            picker.FileTypeFilter.Add("*");
            var selected = await picker.PickSingleFileAsync();

            if (selected == null)
            {
                this.IsEnabled = true;
                return;
            }

            var stream = await selected.OpenStreamForReadAsync();

            AbstractMediaProvider provider = null;

            try
            {
                provider = new ArchiveMediaProvider(stream);
            }
            catch
            {
                var dialog = new MessageDialog(String.Format("Cannot open file: {0}.", selected.Name), "Error");
                await dialog.ShowAsync();

                stream.Dispose();
                this.IsEnabled = true;
                return;
            }
            filenameTextBlock.Text = selected.Name;
            SetMediaProvider(provider);
        }