Пример #1
0
        private async Task AddFiles(StorageFolder parentFolder)
        {
            var fileQuery = parentFolder.CreateFileQueryWithOptions(
                new QueryOptions(Windows.Storage.Search.CommonFileQuery.OrderByDate, new string[] { ".jpg", ".png" })
                );

            //Find up to 250 pictures in all sub folders of the parent folder

            var files = await fileQuery.GetFilesAsync(0, 250);

            foreach (var file in files)
            {
                string fileType = file.FileType.ToLowerInvariant();
                switch (fileType)
                {
                case ".jpg":
                case ".png":
                    lock (_allUris)
                    {
                        if (_allUris.Count >= MaxPhotos)
                        {
                            return;
                        }

                        string pathname = file.Path;
                        Uri    uri      = new Uri(pathname, UriKind.Absolute);
                        _allUris.Add(uri);
                    }
                    break;
                }
            }
        }
Пример #2
0
        public static async Task <List <string> > GetAllBookmarkFilesSortedAsync(StorageFolder folder)
        {
            var retval = new List <string>();
            // Kind of a lot of work just to get files that are sorted correctly.
            //var folder = await StorageFolder.GetFolderFromPathAsync(folderPath);
            var listOptions = new QueryOptions(CommonFileQuery.DefaultQuery, new List <string>()
            {
                EXTENSION
            });

            listOptions.SortOrder.Clear();
            var se = new SortEntry()
            {
                PropertyName   = "System.DateModified",
                AscendingOrder = true,
            };

            listOptions.SortOrder.Add(se);
            var queryResult   = folder.CreateFileQueryWithOptions(listOptions);
            var bookmarkfiles = await queryResult.GetFilesAsync();

            foreach (var bookmarkfile in bookmarkfiles)
            {
                retval.Add(bookmarkfile.Name);
            }
            return(retval);
        }
Пример #3
0
        /// <summary>
        /// This is the click handler for the button that represents a user.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        async private void UserButton_Click(object sender, RoutedEventArgs e)
        {
            Button b = sender as Button;

            if (b != null)
            {
                OutputProgressRing.IsActive = true;

                // Get the folder that represents the user's files, which wwe saved as the DataContext.
                StorageFolder folder = (StorageFolder)b.DataContext;

                // This try/catch block is for scenarios where the HomeGroup Known Folder is not available.
                try
                {
                    // Search for all files in that folder.
                    QueryOptions queryOptions = new QueryOptions(CommonFileQuery.OrderBySearchRank, null);
                    queryOptions.UserSearchFilter = "*";
                    StorageFileQueryResult      queryResults = folder.CreateFileQueryWithOptions(queryOptions);
                    IReadOnlyList <StorageFile> files        = await queryResults.GetFilesAsync();

                    string outputString = string.Format("Files shared by {0}: {1}\n", folder.Name, files.Count);
                    foreach (StorageFile file in files)
                    {
                        outputString += file.Name + "\n";
                    }
                    rootPage.NotifyUser(outputString, NotifyType.StatusMessage);
                }
                catch (Exception ex)
                {
                    rootPage.NotifyUser(ex.Message, NotifyType.ErrorMessage);
                }
                OutputProgressRing.IsActive = false;
            }
        }
Пример #4
0
        /// <summary>
        /// 指定フォルダ以下にある画像ファイルのみを抽出して返す
        /// </summary>
        /// <param name="folder"></param>
        /// <returns></returns>
        private async Task <IReadOnlyList <StorageFile> > getImageFilesAsync(StorageFolder folder)
        {
            QueryOptions           queryOptions = new QueryOptions(CommonFileQuery.DefaultQuery, FileKind.GetImageFilterList());
            StorageFileQueryResult queryResult  = folder.CreateFileQueryWithOptions(queryOptions);

            return(await queryResult.GetFilesAsync());
        }
Пример #5
0
        private async void FindGif()
        {
            List <string> fileTypeFilter = new List <string>
            {
                ".gif"
            };

            var queryOptions = new QueryOptions(CommonFileQuery.DefaultQuery, fileTypeFilter)
            {
                ApplicationSearchFilter = "System.FileName:*\"" + Path.GetFileNameWithoutExtension(File.Name) + "\"*"
            };

            StorageFolder folder = await File.GetParentAsync();

            StorageFileQueryResult queryResult = folder.CreateFileQueryWithOptions(queryOptions);

            var files = await queryResult.GetFilesAsync();

            if (files.Count > 0)
            {
                IRandomAccessStream fileStream = await files[0].OpenAsync(FileAccessMode.Read);
                BitmapImage         image      = new BitmapImage();
                image.SetSource(fileStream);
                Gif = image;
            }
        }
Пример #6
0
        private async void LoadVideosFromFolder(StorageFolder selectedFolder)
        {
            if (selectedFolder != null)
            {
                // Clear old files.
                importingList.Clear();

                // Filter to get video files only.
                List <string> fileTypeFilter = new List <string>
                {
                    ".mp4",
                    ".wmv",
                    ".mkv",
                    ".avi"
                };
                QueryOptions                queryOptions = new QueryOptions(CommonFileQuery.OrderByName, fileTypeFilter);
                StorageFileQueryResult      results      = selectedFolder.CreateFileQueryWithOptions(queryOptions);
                IReadOnlyList <StorageFile> fileList     = await results.GetFilesAsync();

                // Populate file list.
                foreach (StorageFile file in fileList)
                {
                    importingList.Add(new VideoFile(file));
                }

                StatusText.Text = "Loaded " + importingList.Count + " files.";
            }

            TextFileNum.Text = importingList.Count + " files";
        }
Пример #7
0
        private async void LoadFolder(StorageFolder selectedFolder)
        {
            if (selectedFolder != null)
            {
                // Clear old files.
                displayedFileList.Clear();

                // Application now has read/write access to all contents in the picked folder (including other sub-folder contents).
                StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", selectedFolder);

                // Filter to get video files only.
                List <string> fileTypeFilter = new List <string>
                {
                    ".mp4",
                    ".wmv",
                    ".mkv",
                    ".avi"
                };
                QueryOptions                queryOptions = new QueryOptions(CommonFileQuery.OrderByName, fileTypeFilter);
                StorageFileQueryResult      results      = selectedFolder.CreateFileQueryWithOptions(queryOptions);
                IReadOnlyList <StorageFile> fileList     = await results.GetFilesAsync();

                // Populate file list.
                foreach (StorageFile file in fileList)
                {
                    displayedFileList.Add(new VideoFile(file));
                }
            }
        }
Пример #8
0
        /// <summary>
        /// returns first match for autoload feature. Go manually if you want a specific one out of several subs with same name
        /// </summary>
        async Task <StorageFile> LocateSubtitlesFile(StorageFolder subtitlesFolder)
        {
            var queryResult = subtitlesFolder.CreateFileQueryWithOptions(new QueryOptions(CommonFileQuery.DefaultQuery, VLCFileExtensions.SubtitleExtensions));
            var matches     = await queryResult.GetFilesAsync();

            return(matches.FirstOrDefault());
        }
Пример #9
0
        private async void Addfolder_Click(object sender, RoutedEventArgs e)
        {
            FolderPicker openPicker = new FolderPicker();

            openPicker.ViewMode = PickerViewMode.Thumbnail;
            openPicker.SuggestedStartLocation = PickerLocationId.MusicLibrary;
            List <string> fileTypeFilter = new List <string>();

            fileTypeFilter.Add(".mp3");
            openPicker.FileTypeFilter.Add(".mp3");
            StorageFolder folder = await openPicker.PickSingleFolderAsync();

            if (folder != null)
            {
                Current.Frame.IsEnabled = false;
                var t = new MessageDialog("请等待...");
                await t.ShowAsync();

                var queryOptions = new QueryOptions(CommonFileQuery.OrderByName, fileTypeFilter);
                var query        = folder.CreateFileQueryWithOptions(queryOptions);
                IReadOnlyList <StorageFile> fileList = await query.GetFilesAsync();

                LocalSongsVM.GetLocalSongsVM().ReadMusicFiles(fileList);

                Current.Frame.IsEnabled = true;

                new MessageDialog("歌曲导入完成。");
            }
        }
Пример #10
0
        public void LoadContent(StorageFolder folder)
        {
            Thumbnails.Clear();
            List <string> fileTypeFilter = new List <string>();

            fileTypeFilter.Add(".jpg");
            fileTypeFilter.Add(".jpeg");
            fileTypeFilter.Add(".png");
            fileTypeFilter.Add(".bmp");
            QueryOptions queryOptions = new QueryOptions(CommonFileQuery.OrderBySearchRank, fileTypeFilter);

            Task.Run(async() =>
            {
                StorageFileQueryResult queryResult = folder.CreateFileQueryWithOptions(queryOptions);
                var files = await queryResult.GetFilesAsync();
                foreach (var file in files)
                {
                    if (IsImageFile(file))
                    {
                        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            Thumbnails.Add(new ImageViewerItem(file));
                        });
                    }
                }
            });
        }
        private async Task Picker_Populate()
        {
            Picker_SelectedFile = null;
            if (currentFolder == null)
            {
                lstFiles.Items.Clear();
                lstFiles.Items.Add(">Documents");
                lstFiles.Items.Add(">Pictures");
                lstFiles.Items.Add(">Music");
                lstFiles.Items.Add(">Videos");
                lstFiles.Items.Add(">RemovableStorage");
            }
            else
            {
                lstFiles.Items.Clear();
                lstFiles.Items.Add(">..");
                var folders = await currentFolder.GetFoldersAsync();

                foreach (var f in folders)
                {
                    lstFiles.Items.Add(">" + f.Name);
                }
                var query = currentFolder.CreateFileQueryWithOptions(queryOptions);
                var files = await query.GetFilesAsync();

                foreach (var f in files)
                {
                    lstFiles.Items.Add(f.Name);
                }
            }
        }
Пример #12
0
        public async Task <IEnumerable <StorageFile> > GetStorageFilesInFolderAsync(StorageFolder folder)
        {
            //Get query options with which we search for files in the specified folder
            var options = DirectoryWalker.GetQueryOptions();

            /*
             * options.FileTypeFilter.Add(".mp3");
             * options.FileTypeFilter.Add(".wav");
             * options.FileTypeFilter.Add(".ogg");
             * options.FileTypeFilter.Add(".flac");
             * options.FileTypeFilter.Add(".m4a");
             * options.FileTypeFilter.Add(".aif");
             * options.FileTypeFilter.Add(".wma");*/

            //this is the query result which we recieve after querying in the folder
            StorageFileQueryResult queryResult = folder.CreateFileQueryWithOptions(options);

            //'count' is for total files got after querying.
            uint count = await queryResult.GetItemCountAsync();

            //the event for files changed
            queryResult.ContentsChanged += QueryResult_ContentsChanged;

            if (count == 0)
            {
                string error = "No songs found!";
                BLogger.Logger.Error("No songs were found!");
                await SharedLogic.NotificationManager.ShowMessageAsync(error);

                return(null);
            }

            return(await queryResult.GetFilesAsync());
        }
Пример #13
0
        async void GetProfilePicAsync()
        {
            string profilePicPlaceholderPath = "ms-appx:///Assets/StoreLogo.scale-400.png";

            ProfilePic = new BitmapImage(new Uri(profilePicPlaceholderPath));

            ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;

            if (localSettings.Values["PerformerImageFolder"] is string token)
            {
                StorageItemAccessList futureAccessList = StorageApplicationPermissions.FutureAccessList;
                StorageFolder         profilePicFolder = await futureAccessList.GetFolderAsync(token);

                List <string> fileTypeFilter = new List <string>
                {
                    ".jpg"
                };

                var queryOptions = new QueryOptions(CommonFileQuery.DefaultQuery, fileTypeFilter)
                {
                    ApplicationSearchFilter = "System.FileName:*\"" + Name + "\"*"
                };

                StorageFileQueryResult queryResult = profilePicFolder.CreateFileQueryWithOptions(queryOptions);

                var files = await queryResult.GetFilesAsync();

                if (files.Count > 0)
                {
                    BitmapImage screen = new BitmapImage();
                    screen.SetSource(await files[0].GetThumbnailAsync(ThumbnailMode.SingleItem));
                    ProfilePic = screen;
                }
            }
        }
Пример #14
0
        /// <summary>
        /// returns first match for autoload feature. Go manually if you want a specific one out of several subs with same name
        /// </summary>
        async Task <StorageFile> LocateSubtitlesFile(StorageFolder subtitlesFolder, string fileNameWithoutExtensions)
        {
            var queryResult = subtitlesFolder.CreateFileQueryWithOptions(new QueryOptions(CommonFileQuery.OrderByName, VLCFileExtensions.SubtitleExtensions));
            var matches     = await queryResult.GetFilesAsync();

            return(matches.FirstOrDefault(file => file.DisplayName.Equals(fileNameWithoutExtensions)));
        }
        async private void LoadMediaFiles()
        {
            try
            {
                StorageFolder mediaServerFolder = mediaServers[dmsSelect.SelectedIndex];
                var           queryOptions      = new QueryOptions();
                queryOptions.FolderDepth      = FolderDepth.Deep;
                queryOptions.UserSearchFilter = "System.Kind:=video";
                var queryFolder = mediaServerFolder.CreateFileQueryWithOptions(queryOptions);
                mediaFiles = await queryFolder.GetFilesAsync(0, 25);

                mediaSelect.Items.Clear();
                if (mediaFiles.Count == 0)
                {
                    rootPage.NotifyUser("No Media Files found ", NotifyType.StatusMessage);
                }
                else
                {
                    foreach (StorageFile file in mediaFiles)
                    {
                        mediaSelect.Items.Add(file.DisplayName);
                    }
                    rootPage.NotifyUser("Media files retrieved", NotifyType.StatusMessage);
                }
            }
            catch (Exception e)
            {
                rootPage.NotifyUser("Error locating media files " + e.Message, NotifyType.ErrorMessage);
            }
        }
Пример #16
0
 public static async Task<IReadOnlyList<StorageFile>> GetFilesInFolder(List<string> fileTypeFilter, StorageFolder folder)
 {
     if (folder == null || fileTypeFilter == null || fileTypeFilter.Count == 0)
     {
         return null;
     }
     else
     {
         try
         {
             QueryOptions queryOptions = new QueryOptions();
             foreach (var item in fileTypeFilter)
             {
                 if (item.IndexOf(".") == 0)
                 {
                     queryOptions.FileTypeFilter.Add(item);
                 }
                 else
                 {
                     continue;
                 }
             }
             StorageFileQueryResult results = folder.CreateFileQueryWithOptions(queryOptions);
             return await results.GetFilesAsync();
         }
         catch (IOException)
         {
             return null;
         }
         catch (UnauthorizedAccessException)
         {
             return null;
         }
     }
 }
Пример #17
0
        /// <summary>
        /// Finds and displays the first image file on the storage.
        /// </summary>
        /// <param name="storage"></param>
        async private Task GetFirstImageFromStorageAsync(StorageFolder storage)
        {
            var storageName = storage.Name;

            // Construct the query for image files
            var queryOptions = new QueryOptions(CommonFileQuery.OrderByName, new List <string> {
                ".jpg", ".png", ".gif"
            });
            var imageFileQuery = storage.CreateFileQueryWithOptions(queryOptions);

            // Run the query for image files
            rootPage.NotifyUser("[Launched by Autoplay] Looking for images on " + storageName + " ...", NotifyType.StatusMessage);
            var imageFiles = await imageFileQuery.GetFilesAsync();

            if (imageFiles.Count > 0)
            {
                var imageFile = imageFiles[0];
                rootPage.NotifyUser("[Launched by Autoplay] Found " + imageFile.Name + " on " + storageName, NotifyType.StatusMessage);
                await DisplayImageAsync(imageFile);
            }
            else
            {
                rootPage.NotifyUser("[Launched by Autoplay] No images were found on " + storageName + ". You can use scenario 2 to transfer an image to it", NotifyType.StatusMessage);
            }
        }
Пример #18
0
 private DelegateCommand InitializeSetImageFolderCommand()
 {
     return(new DelegateCommand(async() =>
     {
         var fp = new FolderPicker();
         fp.FileTypeFilter.Add(".jpg");
         fp.FileTypeFilter.Add(".bmp");
         fp.FileTypeFilter.Add(".png");
         fp.FileTypeFilter.Add(".gif");
         _imageFolder = await fp.PickSingleFolderAsync();
         if (_imageFolder != null)
         {
             _localStorage.WriteStorageFolderPath(_imageFolder.Path);
             var fileQuery = new QueryOptions()
             {
                 FolderDepth = FolderDepth.Deep
             };
             var result = await _imageFolder.CreateFileQueryWithOptions(fileQuery).GetFilesAsync();
             _files = result.ToList();
             _localStorage.WriteStorageFiles(_files);
             ImageCount = _files.Count() - 1;
             OnPropertyChanged(nameof(StorageFolderControlsVisibility));
         }
     }));
 }
Пример #19
0
        private DelegateCommand InitializeResumeLastSessionCommand()
        {
            return(new DelegateCommand(async() =>
            {
                FolderPicker fp = new FolderPicker();
                fp.FileTypeFilter.Add(".jpg");
                fp.FileTypeFilter.Add(".bmp");
                fp.FileTypeFilter.Add(".png");
                fp.FileTypeFilter.Add(".gif");
                _imageFolder = await fp.PickSingleFolderAsync();
                _files = new List <StorageFile>();
                if (_imageFolder != null && _imageFolder.Path == _localStorage.ReadStorageFolderPath())
                {
                    ImageCount = _localStorage.ReadImageCount();
                    CurrentImage = _localStorage.ReadLastImageNumber();

                    var result = await _imageFolder.CreateFileQueryWithOptions(new QueryOptions()
                    {
                        FolderDepth = FolderDepth.Deep
                    }).GetFilesAsync();
                    var files = result.ToList();
                    for (int i = 0; i < ImageCount; i++)
                    {
                        var id = _localStorage.ReadFileId(i);
                        if (id != null)
                        {
                            _files.Add(files.FirstOrDefault(f => f.FolderRelativeId == id));
                        }
                    }
                    ViewImage = await StorageFileToImage(_files[_currentImage]);
                }
                ResumeSessionVisibility = Visibility.Collapsed;
                OnPropertyChanged(nameof(StorageFolderControlsVisibility));
            }));
        }
Пример #20
0
        /// Lifecycle



        public MonitoredFolder(StorageFolder folderToObserve, EventHandler <MonitoredFolderChangedArgs> changedEventHandler)
        {
            _monitoredFolder     = folderToObserve ?? throw new ArgumentNullException(nameof(folderToObserve));
            _changedEventHandler = changedEventHandler ?? throw new ArgumentNullException(nameof(changedEventHandler));

            StartMonitoringFolderForChanges();

            // Hookup user's handler for our changed event
            this.Changed += changedEventHandler;

            // Create cancellation token
            _cancellationToken = _cancellationTokenSource.Token;

            ReportLine($"Monitoring folder '{_monitoredFolder.Name}'");

            // Start producing results
            _ = InitialScan();


            return;


            /// Local Functions


            /// <summary>Sets up monitoring _rootFolder for changes. NOTE: Not used for scans.</summary>
            void StartMonitoringFolderForChanges()
            {
                var options = new QueryOptions();

                _contentChangedMonitor = _monitoredFolder.CreateFileQueryWithOptions(options);
                _contentChangedMonitor.ContentsChanged += OnContentsChanged;
                _ = _contentChangedMonitor.GetItemCountAsync();                 // Starts monitoring for changes
            }
        }
        async private void LoadMediaFiles(StorageFolder mediaServerFolder)
        {
            try
            {
                MediaFolders = await mediaServerFolder.GetFoldersAsync();

                MediaList.Items.Clear();
                if (MediaFolders.Count > 0)
                {
                    MediaList.Items.Clear();
                    foreach (StorageFolder folder in MediaFolders)
                    {
                        MediaList.Items.Add(" + " + folder.DisplayName);
                    }
                    MediaTitle.Text = "Media folders retrieved";
                }
                var queryOptions = new QueryOptions();

                var queryFolder = mediaServerFolder.CreateFileQueryWithOptions(queryOptions);
                MediaFiles = await queryFolder.GetFilesAsync();

                if (MediaFiles.Count > 0)
                {
                    foreach (StorageFile file in MediaFiles)
                    {
                        MediaList.Items.Add(file.DisplayName);
                    }
                    MediaTitle.Text = "Media files retrieved";
                }
            }
            catch (Exception ex)
            {
                MediaTitle.Text = "Error locating media files " + ex.Message;
            }
        }
        public async ValueTask <FolderContainerType> GetFolderContainerType(StorageFolder folder)
        {
            var containerType = _folderContainerTypeRepository.GetContainerType(folder.Path);

            if (containerType != null)
            {
                return(containerType.Value);
            }

            var query = folder.CreateFileQueryWithOptions(new Windows.Storage.Search.QueryOptions(Windows.Storage.Search.CommonFileQuery.DefaultQuery, SupportedFileTypesHelper.GetAllSupportedFileExtensions())
            {
                FolderDepth = Windows.Storage.Search.FolderDepth.Shallow
            });
            var count = await query.GetItemCountAsync();

            if (count == 0)
            {
                _folderContainerTypeRepository.SetContainerType(folder.Path, FolderContainerType.Other);
                return(FolderContainerType.Other);
            }

            var items = await query.GetFilesAsync(0, count);

            containerType = items.All(x => SupportedFileTypesHelper.IsSupportedImageFileExtension(x.FileType))
                ? FolderContainerType.OnlyImages
                : FolderContainerType.Other
            ;
            _folderContainerTypeRepository.SetContainerType(folder.Path, containerType.Value);
            return(containerType.Value);
        }
        private async void BrowseButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var folderPicker = new FolderPicker()
                {
                    CommitButtonText       = "Open",
                    SuggestedStartLocation = PickerLocationId.DocumentsLibrary,
                    ViewMode = PickerViewMode.List
                };
                folderPicker.FileTypeFilter.Add(".shp");

                _folder = await folderPicker.PickSingleFolderAsync();

                if (_folder != null)
                {
                    var qopts = new QueryOptions(CommonFileQuery.OrderByName, new string[] { ".shp" });
                    var query = _folder.CreateFileQueryWithOptions(qopts);
                    var files = await query.GetFilesAsync();

                    FileListCombo.ItemsSource = files;
                    FileListCombo.Visibility  = (files.Any()) ? Visibility.Visible : Visibility.Collapsed;
                }
            }
            catch (Exception ex)
            {
                var _ = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
        }
Пример #24
0
        /// <summary>
        /// Loads songs from a specified folder into the library. <seealso cref="LoadCommand"/>
        /// </summary>
        public async void Load()
        {
            //LibVM.Database.RemoveFolder(LibraryFoldersCollection[0].Path);
            FolderPicker picker = new FolderPicker();

            picker.FileTypeFilter.Add(".mp3");
            picker.FileTypeFilter.Add(".wav");
            picker.FileTypeFilter.Add(".ogg");
            picker.FileTypeFilter.Add(".flac");
            picker.FileTypeFilter.Add(".m4a");
            picker.FileTypeFilter.Add(".aif");
            picker.FileTypeFilter.Add(".wma");
            picker.SuggestedStartLocation = PickerLocationId.MusicLibrary;
            picker.ViewMode         = PickerViewMode.List;
            picker.CommitButtonText = "Import";
            StorageFolder folder = await picker.PickSingleFolderAsync();

            if (folder != null)
            {
                LibraryFoldersCollection.Add(folder);
                StorageApplicationPermissions.FutureAccessList.Add(folder);
                //Get query options with which we search for files in the specified folder
                var options = Common.DirectoryWalker.GetQueryOptions();
                //this is the query result which we recieve after querying in the folder
                StorageFileQueryResult queryResult = folder.CreateFileQueryWithOptions(options);
                //the event for files changed
                queryResult.ContentsChanged += QueryResult_ContentsChanged;
                await AddFolderToLibraryAsync(queryResult);
            }
        }
Пример #25
0
        private async Task GetMusicFilesAsync()
        {
            QueryOptions options = new QueryOptions();

            options.FolderDepth = FolderDepth.Deep;
            options.FileTypeFilter.Add(".mp3");
            options.FileTypeFilter.Add(".m4a");

            // Get the Music library
            StorageFolder musicFolder = KnownFolders.MusicLibrary;
            var           result      = musicFolder.CreateFileQueryWithOptions(options);

            IReadOnlyList <StorageFile> musicFiles = await result.GetFilesAsync();

            foreach (StorageFile file in musicFiles)
            {
                // Only files on the local computer are supported.
                // Files on OneDrive or a network location are excluded.
                if (file.Provider.Id == "computer")
                {
                    Songs.Add(await LoadSong(file));
                }
            }

            ImageGridView.ItemsSource = Songs;
        }
Пример #26
0
        private static async Task <DatabaseVirtualFolder> AddToDatabase(StorageFolder folder, int parentId = -1)
        {
            var dbvf = await DatabaseAccessService.InsertVirtualFolderAsync(folder.Name, parentId);

            var subs = await folder.GetFoldersAsync();

            foreach (var item in subs)
            {
                await AddToDatabase(item, dbvf.Id);
            }

            List <string> fileTypeFilter = new List <string>();

            fileTypeFilter.Add(".jpg");
            fileTypeFilter.Add(".png");
            fileTypeFilter.Add(".bmp");
            fileTypeFilter.Add(".gif");
            var queryOptions = new QueryOptions(CommonFileQuery.OrderByName, fileTypeFilter);

            queryOptions.FolderDepth = FolderDepth.Shallow;
            var files = await folder.CreateFileQueryWithOptions(queryOptions).GetFilesAsync();

            foreach (var file in files)
            {
                await DatabaseAccessService.InsertImageAsync(file.Path, false, dbvf.Id);
            }

            return(dbvf);
        }
Пример #27
0
        public async Task <TagImage> ShowRandomImage(StorageFolder imageFolder, string tag)
        {
            CommonFileQuery query        = CommonFileQuery.DefaultQuery;
            var             queryOptions = new QueryOptions(query, new[] { ".jpg", ".jpeg" })
            {
                FolderDepth = FolderDepth.Deep
            };

            _ = imageFolder.CreateFileQueryWithOptions(queryOptions);

            var images = await imageFolder.GetFilesAsync();

            TagImage image = await GenerateImage(images, tag);

            while (image.Tags.Contains(tag) && taggedImages.Count < images.Count)
            {
                if (taggedImages.Contains(image.GetHashCode()) == false)
                {
                    taggedImages.Add(image.GetHashCode());
                }
                image = await GenerateImage(images, tag);
            }

            return(image);
        }
Пример #28
0
        public static async Task <IReadOnlyList <Picture> > GetPicturesByAlbum(string albumName)
        {
            StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
            var           allPicsList   = new List <Picture>();
            // Set options for file type and sort order.
            List <string> fileTypeFilter = new List <string>();

            fileTypeFilter.Add(".jpg");
            fileTypeFilter.Add(".png");
            QueryOptions queryOptions = new QueryOptions(CommonFileQuery.DefaultQuery, fileTypeFilter);
            // Get the JPG files in the user's Pictures folder
            // and its subfolders and sort them by date.
            StorageFileQueryResult results = storageFolder.CreateFileQueryWithOptions(queryOptions);

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


            foreach (StorageFile file in files.OrderBy(a => a.DateCreated))
            {
                var pic = new Picture()
                {
                    picName   = file.Name,
                    albumName = null,
                    path      = file.Path,
                    dateAdded = file.DateCreated.LocalDateTime
                };
                allPicsList.Add(pic);
            }
            return(allPicsList);
        }
Пример #29
0
        public async Task <IReadOnlyList <StorageFile> > GetFilesAsync(List <string> fileTypes)
        {
            QueryOptions                queryOptions = new QueryOptions(CommonFileQuery.DefaultQuery, fileTypes);
            StorageFileQueryResult      queryResult  = _storage.CreateFileQueryWithOptions(queryOptions);
            IReadOnlyList <StorageFile> files        = await queryResult.GetFilesAsync();

            return(files);
        }
 public async static Task PerformWatcherWorkAsync(StorageFolder folder)
 {
     StorageFileQueryResult modifiedqueryResult = folder.CreateFileQueryWithOptions(Common.DirectoryWalker.GetQueryOptions("datemodified:>" + SettingsVM.TimeOpened));
     var files = await modifiedqueryResult.GetFilesAsync();
     if (await modifiedqueryResult.GetItemCountAsync() > 0)
     {
         await AddStorageFilesToLibrary(modifiedqueryResult);
     }
     //since there were no modifed files returned yet the event was raised, this means that some file was renamed or deleted. To acknowledge that change we need to reload everything in the modified folder
     else
     {
         //this is the query result which we recieve after querying in the folder
         StorageFileQueryResult queryResult = folder.CreateFileQueryWithOptions(Common.DirectoryWalker.GetQueryOptions());
         files = await queryResult.GetFilesAsync();
         RenameAddOrDeleteFiles(files);
     }
 }