Exemplo n.º 1
0
        private async void OpenComicCollection(StorageFolder chosenFolder, StorageFolder collections)
        {
            LoadingGridVisible(true);
            List <StorageFile> files = await RecursivelySearchForFiles(chosenFolder);

            StorageFolder collectionFolder = (StorageFolder)await collections.TryGetItemAsync(chosenFolder.Name);

            if (collectionFolder == null)
            {
                collectionFolder = await collections.CreateFolderAsync(chosenFolder.Name);
            }
            else
            {
                ShowWarning("Collection already exist!", "Adding new comics");
            }

            foreach (StorageFile sourceFile in files)
            {
                StorageFolder destFolder = (StorageFolder)await collectionFolder.TryGetItemAsync(sourceFile.Name);

                if (destFolder == null)
                {
                    destFolder = await collectionFolder.CreateFolderAsync(sourceFile.Name);

                    try
                    {
                        DefaultViewModel["LoadingFile"] = sourceFile.Name;
                        if (sourceFile.FileType.Equals("cbz") || sourceFile.FileType.Equals(".cbz"))
                        {
                            await FolderZip.UnZipFile(sourceFile, destFolder);
                        }
                        else if (sourceFile.FileType.Equals("cbr") || sourceFile.FileType.Equals(".cbr"))
                        {
                            await FolderZip.UnRarFile(sourceFile, destFolder);
                        }
                    }
                    catch (InvalidFormatException exception)
                    {
                        ShowWarning("Error opening file:" + sourceFile.Name, "Please try again");
                    }
                }
                LoadingBar.Value += (1.0 / files.Count()) * 100;
            }

            await CreateCollectionTiles();

            CollectionViews.Clear();
            foreach (CollectionTile tile in CollectionTiles)
            {
                CollectionViews.Add(new CollectionView(tile));
            }
            defaultViewModel["ComicTiles"]      = ComicTiles;
            defaultViewModel["CollectionViews"] = CollectionViews;
            LoadingGridVisible(false);
        }
Exemplo n.º 2
0
        protected override async void LoadState(Object navigationParameter, Dictionary <String, Object> pageState)
        {
            if (pageState != null && pageState.ContainsKey("DataContext"))
            {
                viewModel = (FolderViewModel)pageState["DataContext"];
            }
            else if (navigationParameter is FileActivatedEventArgs)
            {
                ProggressBarVisible(true);
                FileActivatedEventArgs args = (FileActivatedEventArgs)navigationParameter;

                MarkedUp.AnalyticClient.SessionEvent("Comic opened by file");
                StorageFile   sourceFile = null;
                StorageFolder destFolder = null;
                try
                {
                    sourceFile = (StorageFile)args.Files.ToList().ElementAt(0);
                    StorageFolder recentlyOpened = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFolderAsync("Recently Opened");

                    destFolder = await recentlyOpened.CreateFolderAsync(sourceFile.Name, CreationCollisionOption.ReplaceExisting);

                    if (sourceFile.FileType.Equals("cbz") || sourceFile.FileType.Equals(".cbz"))
                    {
                        await FolderZip.UnZipFile(sourceFile, destFolder);
                    }
                    else if (sourceFile.FileType.Equals("cbr") || sourceFile.FileType.Equals(".cbr"))
                    {
                        await FolderZip.UnRarFile(sourceFile, destFolder);
                    }
                    await viewModel.Initialize(destFolder);

                    ProggressBarVisible(false);
                }
                catch (UnauthorizedAccessException e)
                {
                    ShowWarningAndClose("Cannont access files outside of Libraries", "You can copy it to documents if you want to open it");
                }
            }
            else if (navigationParameter is StorageFolder)
            {
                ProggressBarVisible(true);
                StorageFolder destFolder     = (StorageFolder)navigationParameter;
                StorageFolder recentlyOpened = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFolderAsync("Recently Opened");

                StorageFolder testFolder = (StorageFolder)await recentlyOpened.TryGetItemAsync(destFolder.Name);

                if (testFolder == null)
                {
                    testFolder = await recentlyOpened.CreateFolderAsync(destFolder.Name);

                    IReadOnlyList <StorageFile> files = await destFolder.GetFilesAsync();

                    foreach (StorageFile file in files)
                    {
                        await file.CopyAsync(testFolder);
                    }
                }
                await viewModel.Initialize(destFolder);

                ProggressBarVisible(false);
            }
            else
            {
                Windows.Storage.Pickers.FileOpenPicker filePicker = new Windows.Storage.Pickers.FileOpenPicker();
                filePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
                filePicker.FileTypeFilter.Add(".cbz");
                filePicker.FileTypeFilter.Add(".cbr");
                filePicker.CommitButtonText = "Open";

                StorageFile   sourceFile = null;
                StorageFolder destFolder = null;
                try
                {
                    sourceFile = await filePicker.PickSingleFileAsync();

                    if (sourceFile == null)
                    {
                        this.Frame.GoBack();
                    }
                    else
                    {
                        ProggressBarVisible(true);
                        StorageFolder recentlyOpened = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFolderAsync("Recently Opened");

                        destFolder = await recentlyOpened.CreateFolderAsync(sourceFile.Name, CreationCollisionOption.ReplaceExisting);

                        try
                        {
                            if (sourceFile.FileType.Equals("cbz") || sourceFile.FileType.Equals(".cbz"))
                            {
                                await FolderZip.UnZipFile(sourceFile, destFolder);
                            }
                            else if (sourceFile.FileType.Equals("cbr") || sourceFile.FileType.Equals(".cbr"))
                            {
                                await FolderZip.UnRarFile(sourceFile, destFolder);
                            }
                        }
                        catch (InvalidFormatException exception)
                        {
                            ShowWarningAndClose("Error opening file:" + sourceFile.Name, "Please restart the app and try again");
                        }
                        await viewModel.Initialize(destFolder);

                        ProggressBarVisible(false);
                    }
                }
                catch (UnauthorizedAccessException e)
                {
                    //ShowWarningAndClose("Cannont access files outside of Libraries", "You can copy it to pictures if you want to open it");
                }
                catch (Exception e)
                {
                    ShowWarningAndClose("An error has occured that has not been handled", "Error info: " + e.Message);
                }
            }


            pagesCount           = viewModel.Pictures.Count;
            pageNumberLabel.Text = "(1/" + pagesCount + ")";
        }