private async void Recent_Click(object sender, RoutedEventArgs e)
        {
            List <StorageFile> files = new List <StorageFile>();
            var mru = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList;

            //StorageFile retrievedFile = await mru.GetFileAsync(token);

            foreach (Windows.Storage.AccessCache.AccessListEntry entry in mru.Entries)
            {
                string mruToken    = entry.Token;
                string mruMetadata = entry.Metadata;
                try
                {
                    Windows.Storage.IStorageItem item = await mru.GetItemAsync(mruToken);

                    if (item is StorageFile)
                    {
                        //StorageFile item = await mru.GetFileAsync(mruToken);
                        files.Add((StorageFile)item);
                    }
                }
                catch (FileNotFoundException)
                {}
            }

            appWindow = await AppWindow.TryCreateAsync();

            Frame appWindowContentFrame = new Frame();

            appWindowContentFrame.Navigate(typeof(RecentList), RecognizerViewModel);
            ElementCompositionPreview.SetAppWindowContent(appWindow, appWindowContentFrame);
            appWindow.RequestSize(new Size(500, 900));
            await appWindow.TryShowAsync();

            this.mainPage.IsEnabled = false;

            appWindow.Closed += delegate
            {
                //    //Task.Delay(1000);
                //    dictationTextBox.Text = "";
                //    appWindowContentFrame.Content = null;
                //    appWindow = null;
                this.mainPage.IsEnabled = true;
                //    recentFile = RecentList.openFile;
                //    RecentList.openFile = null;
                //    OpenFileDialog_Click(null, null);
                //
            };
        }
Exemple #2
0
 /// <summary>
 /// Creates an MVVM <see cref="BassClefStudio.AppModel.Storage.IStorageItem"/> from a UWP <see cref="IStorageItem"/>.
 /// </summary>
 /// <param name="item">The <see cref="IStorageItem"/> to convert.</param>
 /// <returns>Either a <see cref="UwpFile"/> or <see cref="UwpFolder"/> wrapper around the item.</returns>
 public static BassClefStudio.AppModel.Storage.IStorageItem ToMvvm(this Windows.Storage.IStorageItem item)
 {
     if (item is Windows.Storage.IStorageFolder folder)
     {
         return(new UwpFolder(folder));
     }
     else if (item is Windows.Storage.IStorageFile file)
     {
         return(new UwpFile(file));
     }
     else
     {
         throw new BassClefStudio.AppModel.Storage.StorageAccessException("Accessed an item at the specified path, but it was not a file or directory.");
     }
 }
Exemple #3
0
        /// <summary>
        /// Checks whether a folder or file exists at the given location.
        /// </summary>
        /// <param name="name">The name of the file or folder to check for.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// A task whose result is the result of the existence check.
        /// </returns>
        public async Task <ExistenceCheckResult> CheckExistsAsync(string name, CancellationToken cancellationToken)
        {
            Requires.NotNullOrEmpty(name, "name");

            // WinRT does not expose an Exists method, so we have to
            // try accessing the entity to see if it succeeds.
            // We could code this up with a catch block, but that means
            // that a file existence check requires first chance exceptions
            // are thrown and caught, which *can* slow the app down,
            // and also bugs the developer who is debugging the app.
            // So we just avoid all exceptions being *thrown*
            // by checking for exception objects carefully.
            var result = await _wrappedFolder.GetItemAsync(name).AsTaskNoThrow(cancellationToken);

            if (result.IsFaulted)
            {
                if (result.Exception.InnerException is FileNotFoundException)
                {
                    return(ExistenceCheckResult.NotFound);
                }
                else
                {
                    // rethrow unexpected exceptions.
                    result.GetAwaiter().GetResult();
                    throw result.Exception; // shouldn't reach here anyway.
                }
            }
            else if (result.IsCanceled)
            {
                throw new OperationCanceledException();
            }
            else
            {
                Windows.Storage.IStorageItem storageItem = result.Result;
                if (storageItem.IsOfType(StorageItemTypes.File))
                {
                    return(ExistenceCheckResult.FileExists);
                }
                else if (storageItem.IsOfType(StorageItemTypes.Folder))
                {
                    return(ExistenceCheckResult.FolderExists);
                }
                else
                {
                    return(ExistenceCheckResult.NotFound);
                }
            }
        }
        private async void PopulateRecentFiles()
        {
            var mru = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList;

            foreach (Windows.Storage.AccessCache.AccessListEntry entry in mru.Entries)
            {
                string mruToken = entry.Token;
                try
                {
                    Windows.Storage.IStorageItem item = await mru.GetItemAsync(mruToken);

                    if (item is StorageFile)
                    {
                        this.recentFiles.Add(new RecentFile()
                        {
                            thisFile = (StorageFile)item, Name = item.Name
                        });
                    }
                }
                catch (FileNotFoundException)
                { }
            }
        }
Exemple #5
0
        public async void PopulateRecentsList()
        {
            var              mostRecentlyUsed = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList;
            BitmapImage      ItemImage        = new BitmapImage();
            string           ItemPath         = null;
            string           ItemName;
            StorageItemTypes ItemType;
            Visibility       ItemFolderImgVis;
            Visibility       ItemEmptyImgVis;
            Visibility       ItemFileIconVis;

            if (mostRecentlyUsed.Entries.Count == 0)
            {
                Empty.Visibility = Visibility.Visible;
            }
            else
            {
                Empty.Visibility = Visibility.Collapsed;
            }
            foreach (Windows.Storage.AccessCache.AccessListEntry entry in mostRecentlyUsed.Entries)
            {
                string mruToken = entry.Token;
                try
                {
                    Windows.Storage.IStorageItem item = await mostRecentlyUsed.GetItemAsync(mruToken);

                    if (item.IsOfType(StorageItemTypes.File))
                    {
                        ItemName  = item.Name;
                        ItemPath  = item.Path;
                        ItemType  = StorageItemTypes.File;
                        ItemImage = new BitmapImage();
                        StorageFile file = await StorageFile.GetFileFromPathAsync(ItemPath);

                        var thumbnail = await file.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.ListView, 30, Windows.Storage.FileProperties.ThumbnailOptions.ResizeThumbnail);

                        if (thumbnail == null)
                        {
                            ItemEmptyImgVis = Visibility.Visible;
                        }
                        else
                        {
                            await ItemImage.SetSourceAsync(thumbnail.CloneStream());

                            ItemEmptyImgVis = Visibility.Collapsed;
                        }
                        ItemFolderImgVis = Visibility.Collapsed;
                        ItemFileIconVis  = Visibility.Visible;
                        recentItemsCollection.Add(new RecentItem()
                        {
                            path = ItemPath, name = ItemName, type = ItemType, FolderImg = ItemFolderImgVis, EmptyImgVis = ItemEmptyImgVis, FileImg = ItemImage, FileIconVis = ItemFileIconVis
                        });
                    }
                }
                catch (System.IO.FileNotFoundException)
                {
                    mostRecentlyUsed.Remove(mruToken);
                }
                catch (UnauthorizedAccessException)
                {
                    // Skip item until consent is provided
                }
            }
        }
Exemple #6
0
        public async void InitializeDataGridView()
        {
            listDostyp.Clear();
            // A TreeView can have more than 1 root node. The Pictures library
            // and the Music library will each be a root node in the tree.
            // Get Pictures library.
            try
            {
                ListCol.Clear();

                try
                {
                    StorageFolder storageFolder = await StorageFolder.GetFolderFromPathAsync(Windows.Storage.UserDataPaths.GetDefault().Desktop);

                    //var thumbnailddes =await  storageFolder.GetScaledImageAsThumbnailAsync(ThumbnailMode.SingleItem, 60, ThumbnailOptions.UseCurrentScale);

                    ListCol.Add(new ClassListStroce(storageFolder.Path, storageFolder.DisplayName, true, storageFolder.DisplayType, storageFolder.DateCreated.ToString(), Type)
                    {
                        ick = true
                    });                                                                                                                                                                        // { StorageFolder = storageFolder, FlagFolde = true, Type = Type, ThumbnailMode= thumbnailddes });
                    // ListCol.Add(new ClassListStroce() { StorageFolder = storageFolder, FlagFolde = true, Type = Type});
                }
                catch (Exception ex)
                {
                }
                try
                {
                    StorageFolder storageFolderDownloads = await StorageFolder.GetFolderFromPathAsync(Windows.Storage.UserDataPaths.GetDefault().Downloads);

                    //var thumbnailddesDownloads = await storageFolderDownloads.GetScaledImageAsThumbnailAsync(ThumbnailMode.SingleItem, 60, ThumbnailOptions.UseCurrentScale);

                    ListCol.Add(new ClassListStroce(storageFolderDownloads.Path, storageFolderDownloads.DisplayName, true, storageFolderDownloads.DisplayType, storageFolderDownloads.DateCreated.ToString(), Type)
                    {
                        ick = true
                    });                                                                                                                                                                                                             // { StorageFolder = storageFolderDownloads, FlagFolde = true, Type = Type, ThumbnailMode= thumbnailddesDownloads });
                }
                catch (Exception ex)
                {
                }
                // StorageFolder DocumentFolder = KnownFolders.DocumentsLibrary;
                StorageFolder DocumentFolder = await StorageFolder.GetFolderFromPathAsync(Windows.Storage.UserDataPaths.GetDefault().Documents);

                // var thumbnaild = await DocumentFolder.GetScaledImageAsThumbnailAsync(ThumbnailMode.SingleItem, 60, ThumbnailOptions.ResizeThumbnail);
                //Debug.WriteLine(KnownFolders.DocumentsLibrary.Path);

                ListCol.Add(new ClassListStroce(DocumentFolder.Path, DocumentFolder.DisplayName, true, DocumentFolder.DisplayType, DocumentFolder.DateCreated.ToString(), Type)
                {
                    ick = true
                });                                                                                                                                                                             // { StorageFolder = DocumentFolder, FlagFolde = true, Type = Type, ThumbnailMode= thumbnaild });


                StorageFolder picturesFolder = await StorageFolder.GetFolderFromPathAsync(Windows.Storage.UserDataPaths.GetDefault().Pictures);

                //var thumbnail = await picturesFolder.GetScaledImageAsThumbnailAsync(ThumbnailMode.SingleItem, 60, ThumbnailOptions.UseCurrentScale);

                ListCol.Add(new ClassListStroce(picturesFolder.Path, picturesFolder.DisplayName, true, picturesFolder.DisplayType, picturesFolder.DateCreated.ToString(), Type)
                {
                    ick = true
                });                                                                                                                                                                             // { StorageFolder = picturesFolder, FlagFolde = true, Type = Type, ThumbnailMode= thumbnail });


                // Get Music library.
                StorageFolder musicFolder = await StorageFolder.GetFolderFromPathAsync(Windows.Storage.UserDataPaths.GetDefault().Music);;
                // var thumbnail1 = await picturesFolder.GetScaledImageAsThumbnailAsync(ThumbnailMode.SingleItem, 60, ThumbnailOptions.UseCurrentScale);

                ListCol.Add(new ClassListStroce(musicFolder.Path, musicFolder.DisplayName, true, musicFolder.DisplayType, musicFolder.DateCreated.ToString(), Type)
                {
                    ick = true
                });                                                                                                                                                                 // { StorageFolder = musicFolder, FlagFolde = true, Type = Type, ThumbnailMode= thumbnail1 });



                var storageItemAccessList = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList;
                if (storageItemAccessList.Entries.Count != 0)
                {
                    foreach (Windows.Storage.AccessCache.AccessListEntry entry in storageItemAccessList.Entries)
                    {
                        string mruToken    = entry.Token;
                        string mruMetadata = entry.Metadata;
                        Windows.Storage.IStorageItem item = await storageItemAccessList.GetItemAsync(mruToken);

                        listDostyp.Add(mruToken);
                        StorageFolder ss = await storageItemAccessList.GetFolderAsync(mruToken);

                        //var thumbnail11 = await picturesFolder.GetScaledImageAsThumbnailAsync(ThumbnailMode.SingleItem, 60, ThumbnailOptions.UseCurrentScale);
                        ListCol.Add(new ClassListStroce(ss.Path, ss.DisplayName, true, ss.DisplayType, ss.DateCreated.ToString(), Type)
                        {
                            ick = true
                        });                                                                                                                             // { StorageFolder = ss, FlagFolde = true, ThumbnailMode = thumbnail11, Type = Type });
                    }
                }
                try
                {
                    var items = Windows.Storage.UserDataPaths.GetDefault();

                    StorageFolder storageFolder = await StorageFolder.GetFolderFromPathAsync(items.Profile);

                    var d = await storageFolder.GetFoldersAsync();

                    foreach (StorageFolder FlFolder1 in d)
                    {
                        if (FlFolder1.DisplayName == "OneDrive")
                        {
                            //var thumbnailr = await FlFolder1.GetScaledImageAsThumbnailAsync(ThumbnailMode.SingleItem, 60, ThumbnailOptions.UseCurrentScale);


                            ListCol.Add(new ClassListStroce(FlFolder1.Path, FlFolder1.DisplayName, true, FlFolder1.DisplayType, FlFolder1.DateCreated.ToString(), Type)
                            {
                                ick = true
                            });                                                                                                                                                         // { StorageFolder = FlFolder1, FlagFolde = true, Type = Type, ThumbnailMode= thumbnailr });
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                var f = GetInternalDrives();
                foreach (var d in f)
                {
                    Debug.WriteLine(d.DisplayName);
                }
                DriveInfo[] drives = DriveInfo.GetDrives();

                foreach (DriveInfo drive in drives)
                {
                    try
                    {
                        if (drive.DriveType == DriveType.Fixed && drive.DriveType != DriveType.Removable)
                        {
                            StorageFolder FolderL = await StorageFolder.GetFolderFromPathAsync(drive.Name);

                            var thumbnailL = await FolderL.GetScaledImageAsThumbnailAsync(ThumbnailMode.SingleItem, 60, ThumbnailOptions.UseCurrentScale);

                            var clas = new ClassListStroce(FolderL.Path, FolderL.DisplayName, true, FolderL.DisplayType, FolderL.DateCreated.ToString(), Type)
                            {
                                ick = true, ThumbnailMode = thumbnailL
                            };                                                                                                                                                                           // { StorageFolder = FolderL, FlagFolde = true, ThumbnailMode= thumbnailL };
                            if (Type == "Maximum")
                            {
                                clas.Type = "Drive";
                            }
                            else
                            {
                                clas.Type = "DriveMiddle";
                            }
                            try
                            {
                                clas.Spase();
                            }
                            catch (Exception ex)
                            {
                            }

                            ListCol.Add(clas);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }


                StorageFolder Folder = KnownFolders.RemovableDevices;
                try
                {
                    //IReadOnlyList<StorageFolder> folderList = await Folder.GetFoldersAsync();
                    //foreach (StorageFolder FlFolder1 in folderList)
                    {
                        // thumbnail1 = await FlFolder1.GetThumbnailAsync(ThumbnailMode.SingleItem, 100);
                        // ListCol.Add(new ClassListStroce() { StorageFolder = FlFolder1, FlagFolde = true, ThumbnailMode = thumbnail1, Type = Type });
                    }
                }
                catch (Exception)
                {
                }
                Path = String.Empty;
            }
            catch (UnauthorizedAccessException ex)
            {
                var           resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
                MessageDialog messageDialog  = new MessageDialog(resourceLoader.GetString("MessageContentDostup"), resourceLoader.GetString("MessageTiletDostup"));
                await messageDialog.ShowAsync();

                App.Current.Exit();
            }
            catch (Exception ex)
            {
                MessageDialog messageDialog = new MessageDialog(ex.Message);
                await messageDialog.ShowAsync();
            }
        }