コード例 #1
0
        /// <summary>
        /// Test if a file exists in the application local cache folder.
        /// </summary>
        /// <param name="knownFolderId">The well known folder ID to use</param>
        /// <param name="fileName">Relative name of the file to open. Can contains subfolders.</param>
        /// <returns>True if file exists.</returns>
        public static Task <bool> IsKnownFolderFileExistsAsync(
            KnownFolderId knownFolderId,
            string fileName)
        {
            StorageFolder workingFolder = StorageFileHelper.GetFolderFromKnownFolderId(knownFolderId);

            return(workingFolder.IsFileExistsAsync(fileName));
        }
コード例 #2
0
        /// <summary>
        /// Return a stream to a specified file from the application local cache folder.
        /// </summary>
        /// <param name="knownFolderId">The well known folder ID to use</param>
        /// <param name="fileName">Relative name of the file to open. Can contains subfolders.</param>
        /// <param name="accessMode">File access mode. Default is read.</param>
        /// <returns>File stream</returns>
        public static Task <IRandomAccessStream> GetKnowFoldersFileStreamAsync(
            KnownFolderId knownFolderId,
            string fileName,
            FileAccessMode accessMode = FileAccessMode.Read)
        {
            StorageFolder workingFolder = StorageFileHelper.GetFolderFromKnownFolderId(knownFolderId);

            return(GetFileStreamAsync(fileName, accessMode, workingFolder));
        }
コード例 #3
0
        /// <summary>
        /// Gets an array of bytes from a <see cref="StorageFile"/> located in a well known folder.
        /// </summary>
        /// <param name="knownFolderId">
        /// The well known folder ID to use.
        /// </param>
        /// <param name="fileName">
        /// The relative <see cref="string"/> file path.
        /// </param>
        /// <returns>
        /// Returns the stored <see cref="byte"/> array.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// Exception thrown if the <paramref name="fileName"/> is null or empty.
        /// </exception>
        public static Task <byte[]> ReadBytesFromKnownFoldersFileAsync(
            KnownFolderId knownFolderId,
            string fileName)
        {
            if (string.IsNullOrWhiteSpace(fileName))
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            var folder = GetFolderFromKnownFolderId(knownFolderId);

            return(folder.ReadBytesFromFileAsync(fileName));
        }
コード例 #4
0
        /// <summary>
        /// Gets a string value from a <see cref="StorageFile"/> located in a well known folder.
        /// </summary>
        /// <param name="knownFolderId">
        /// The well known folder ID to use.
        /// </param>
        /// <param name="fileName">
        /// The relative <see cref="string"/> file path.
        /// </param>
        /// <returns>
        /// Returns the stored <see cref="string"/> value.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// Exception thrown if the <paramref name="fileName"/> is null or empty.
        /// </exception>
        public static async Task <string> ReadTextFromKnownFoldersFileAsync(
            KnownFolderId knownFolderId,
            string fileName)
        {
            if (string.IsNullOrWhiteSpace(fileName))
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            var folder = GetFolderFromKnownFolderId(knownFolderId);

            return(await ReadTextFromFileAsync(folder, fileName));
        }
コード例 #5
0
        /// <summary>
        /// Saves an array of bytes to a <see cref="StorageFile"/> to well known folder/>.
        /// </summary>
        /// <param name="knownFolderId">
        /// The well known folder ID to use.
        /// </param>
        /// <param name="bytes">
        /// The <see cref="byte"/> array to save to the file.
        /// </param>
        /// <param name="fileName">
        /// The <see cref="string"/> name for the file.
        /// </param>
        /// <param name="options">
        /// The creation collision options. Default is ReplaceExisting.
        /// </param>
        /// <returns>
        /// Returns the saved <see cref="StorageFile"/> containing the bytes.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// Exception thrown if the file location or file name are null or empty.
        /// </exception>
        public static Task <StorageFile> WriteBytesToKnownFolderFileAsync(
            KnownFolderId knownFolderId,
            byte[] bytes,
            string fileName,
            CreationCollisionOption options = CreationCollisionOption.ReplaceExisting)
        {
            if (string.IsNullOrWhiteSpace(fileName))
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            var folder = GetFolderFromKnownFolderId(knownFolderId);

            return(folder.WriteBytesToFileAsync(bytes, fileName, options));
        }
コード例 #6
0
        async Task libLoad(KnownFolderId library)
        {
            IsReady = false;
            try
            {
                var max = 200;
                var sfs = await IsoStorePoc.LoadFromLibFolder(library);

                MediaInfos.Clear();
                sfs.Take(max).ToList().ForEach(sf => MediaInfos.Add(new MediaInfo(sf)));
                ApplicationView.GetForCurrentView().Title = Info = $@"Ttl {sfs.Count} in {library}, taking first {max}";
            }
            finally
            {
                IsReady = true;
            }
        }
コード例 #7
0
        //        /// <summary>
        //        /// Gets an object that provides access to the content-related properties of the current folder.
        //        /// </summary>
        //        public StorageItemContentProperties Properties { get; }

        //        /// <summary>
        //        /// Gets the StorageProvider object that contains info about the service that stores the current folder.
        //        /// </summary>
        //        public StorageProvider Provider { get; }

        internal StorageFolder(KnownFolderId folderId)
        {
            // currently there is only support for removable devices
            // and internal storage devices
            if (folderId == KnownFolderId.RemovableDevices)
            {
                _name = s_RemovableStorageDevicesName;
            }
            else if (folderId == KnownFolderId.InternalDevices)
            {
                _name = s_InternalStorageDevicesName;
            }
            else
            {
                throw new NotSupportedException();
            }

            _knownFolderId = folderId;
            _path          = "";
        }
コード例 #8
0
ファイル: Func.cs プロジェクト: alexpisquared/MediaPlay
        async Task onLoadLib_Task(KnownFolderId library)
        {
            try
            {
                CanLoadLibs = false;

                if (library == KnownFolderId.AllAppMods)
                {
                    await onLoadLib_Task(KnownFolderId.MusicLibrary);
                    await onLoadLib_Task(KnownFolderId.VideosLibrary);

                    return;
                }

                var max = 1000;
                var sfs = await IsoStorePoc.LoadFromLibFolder(library);

                var ll = sfs.Take(max).OrderBy(r => r.Path).ThenBy(r => r.Name);
                foreach (var sf in ll)
                {
                    await addNewOrFromMru(sf);                    //async ruins the order by: ll.ToList().ForEach(async sf => await add(sf));
                }
                if (SlctMru != null)
                {
                    SlctLib = selectFromList(SlctMru.PathFile, LibLst);
                }

                ApplicationView.GetForCurrentView().Title = $@"{library}: {LibLst.Count} / {sfs.Count} ";
                TbInfo += $@"\r\n{ApplicationView.GetForCurrentView().Title} ";
            }
            catch (Exception ex) { Debug.WriteLine($"$#~>{ex.Message}"); if (Debugger.IsAttached)
                                   {
                                       Debugger.Break();
                                   }
                                   else
                                   {
                                       await popEx(ex, GetType().FullName);
                                   } }
            finally { CanLoadLibs = true; }
        }
コード例 #9
0
        /// <summary>
        /// Returns a <see cref="StorageFolder"/> from a <see cref="KnownFolderId"/>
        /// </summary>
        /// <param name="knownFolderId">Folder Id</param>
        /// <returns><see cref="StorageFolder"/></returns>
        internal static StorageFolder GetFolderFromKnownFolderId(KnownFolderId knownFolderId)
        {
            StorageFolder workingFolder;

            switch (knownFolderId)
            {
            case KnownFolderId.AppCaptures:
                workingFolder = KnownFolders.AppCaptures;
                break;

            case KnownFolderId.CameraRoll:
                workingFolder = KnownFolders.CameraRoll;
                break;

            case KnownFolderId.DocumentsLibrary:
                workingFolder = KnownFolders.DocumentsLibrary;
                break;

            case KnownFolderId.HomeGroup:
                workingFolder = KnownFolders.HomeGroup;
                break;

            case KnownFolderId.MediaServerDevices:
                workingFolder = KnownFolders.MediaServerDevices;
                break;

            case KnownFolderId.MusicLibrary:
                workingFolder = KnownFolders.MusicLibrary;
                break;

            case KnownFolderId.Objects3D:
                workingFolder = KnownFolders.Objects3D;
                break;

            case KnownFolderId.PicturesLibrary:
                workingFolder = KnownFolders.PicturesLibrary;
                break;

            case KnownFolderId.Playlists:
                workingFolder = KnownFolders.Playlists;
                break;

            case KnownFolderId.RecordedCalls:
                workingFolder = KnownFolders.RecordedCalls;
                break;

            case KnownFolderId.RemovableDevices:
                workingFolder = KnownFolders.RemovableDevices;
                break;

            case KnownFolderId.SavedPictures:
                workingFolder = KnownFolders.SavedPictures;
                break;

            case KnownFolderId.VideosLibrary:
                workingFolder = KnownFolders.VideosLibrary;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(knownFolderId), knownFolderId, null);
            }

            return(workingFolder);
        }
コード例 #10
0
ファイル: Func.cs プロジェクト: alexpisquared/MediaPlay
 async void onLoadLib_void(KnownFolderId library)
 {
     await onLoadLib_Task(library);
 }