Пример #1
0
        /// <summary>
        /// Gets a list of subfolders in this folder
        /// </summary>
        /// <returns>A list of subfolders in the folder</returns>
        public async Task <IList <IFolder> > GetFoldersAsync(CancellationToken cancellationToken)
        {
            await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

            EnsureExists();
            IList <IFolder> ret = Directory.GetDirectories(Path).Select(d => new FileSystemFolder(d, true)).ToList <IFolder>().AsReadOnly();

            return(ret);
        }
Пример #2
0
        /// <summary>
        /// Gets a list of the files in this folder
        /// </summary>
        /// <returns>A list of the files in the folder</returns>
        public async Task <IList <IFile> > GetFilesAsync(CancellationToken cancellationToken)
        {
            await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

            EnsureExists();
            IList <IFile> ret = Directory.GetFiles(Path).Select(f => new FileSystemFile(f)).ToList <IFile>().AsReadOnly();

            return(ret);
        }
Пример #3
0
        /// <summary>
        /// Renames a file without changing its location.
        /// </summary>
        /// <param name="newName">The new leaf name of the file.</param>
        /// <param name="collisionOption">How to deal with collisions with existing files.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// A task which will complete after the file is renamed.
        /// </returns>
        public async Task RenameAsync(string newName, NameCollisionOption collisionOption, CancellationToken cancellationToken)
        {
            Requires.NotNullOrEmpty(newName, "newName");

            await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

            string newPath = PortablePath.Combine(System.IO.Path.GetDirectoryName(_path), newName);

            await MoveAsync(newPath, collisionOption, cancellationToken);
        }
Пример #4
0
        /// <summary>
        /// Deletes this folder and all of its contents
        /// </summary>
        /// <returns>A task which will complete after the folder is deleted</returns>
        public async Task DeleteAsync(CancellationToken cancellationToken)
        {
            if (!_canDelete)
            {
                throw new IOException("Cannot delete root storage folder.");
            }
            await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

            EnsureExists();
            Directory.Delete(Path, true);
        }
        /// <summary>
        /// Gets a file, given its path.  Returns null if the file does not exist.
        /// </summary>
        /// <param name="path">The path to a file, as returned from the <see cref="IFile.Path"/> property.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A file for the given path, or null if it does not exist.</returns>
        public async Task <IFile> GetFileFromPathAsync(string path, CancellationToken cancellationToken)
        {
            Requires.NotNullOrEmpty(path, "path");
            await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

            if (Root.FileExists(path))
            {
                return(new IsoStoreFile(Root, path));
            }
            return(null);
        }
Пример #6
0
        /// <summary>
        /// Deletes the file
        /// </summary>
        /// <returns>A task which will complete after the file is deleted.</returns>
        public async Task DeleteAsync(CancellationToken cancellationToken)
        {
            await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

            if (!File.Exists(Path))
            {
                throw new PCLStorage.Exceptions.FileNotFoundException("File does not exist: " + Path);
            }

            File.Delete(Path);
        }
        /// <summary>
        /// Gets a list of subfolders in this folder
        /// </summary>
        /// <returns>A list of subfolders in the folder</returns>
        public async Task <IList <IFolder> > GetFoldersAsync(CancellationToken cancellationToken)
        {
            await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

            EnsureExists();

            string[]        folderNames = Root.GetDirectoryNames(System.IO.Path.Combine(Path, "*"));
            IList <IFolder> ret         = folderNames.Select(fn => new IsoStoreFolder(fn, this)).Cast <IFolder>().ToList().AsReadOnly();

            return(ret);
        }
Пример #8
0
        /// <summary>
        /// Creates a file in this folder
        /// </summary>
        /// <param name="desiredName">The name of the file to create</param>
        /// <param name="option">Specifies how to behave if the specified file already exists</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The newly created file</returns>
        public async Task <IFile> CreateFileAsync(string desiredName, CreationCollisionOption option, CancellationToken cancellationToken)
        {
            Requires.NotNullOrEmpty(desiredName, "desiredName");

            await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

            EnsureExists();

            string nameToUse = desiredName;
            string newPath   = System.IO.Path.Combine(Path, nameToUse);

            if (File.Exists(newPath))
            {
                if (option == CreationCollisionOption.GenerateUniqueName)
                {
                    string desiredRoot      = System.IO.Path.GetFileNameWithoutExtension(desiredName);
                    string desiredExtension = System.IO.Path.GetExtension(desiredName);
                    for (int num = 2; File.Exists(newPath); num++)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        nameToUse = desiredRoot + " (" + num + ")" + desiredExtension;
                        newPath   = System.IO.Path.Combine(Path, nameToUse);
                    }
                    InternalCreateFile(newPath);
                }
                else if (option == CreationCollisionOption.ReplaceExisting)
                {
                    File.Delete(newPath);
                    InternalCreateFile(newPath);
                }
                else if (option == CreationCollisionOption.FailIfExists)
                {
                    throw new IOException("File already exists: " + newPath);
                }
                else if (option == CreationCollisionOption.OpenIfExists)
                {
                    //	No operation
                }
                else
                {
                    throw new ArgumentException("Unrecognized CreationCollisionOption: " + option);
                }
            }
            else
            {
                //	Create file
                InternalCreateFile(newPath);
            }

            var ret = new FileSystemFile(newPath);

            return(ret);
        }
Пример #9
0
        public async Task SetLastWriteTime(DateTime lastWriteTime, bool utc = false, CancellationToken cancellationToken = new CancellationToken())
        {
            await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

            if (utc)
            {
                File.SetLastWriteTimeUtc(Path, lastWriteTime);
            }
            else
            {
                File.SetLastWriteTime(Path, lastWriteTime);
            }
        }
Пример #10
0
        /// <summary>
        /// Gets a folder, given its path.  Returns null if the folder does not exist.
        /// </summary>
        /// <param name="path">The path to a folder, as returned from the <see cref="IFolder.Path"/> property.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A folder for the specified path, or null if it does not exist.</returns>
        public async Task <IFolder> GetFolderFromPathAsync(string path, CancellationToken cancellationToken)
        {
            Requires.NotNullOrEmpty(path, "path");

            await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

            if (Directory.Exists(path))
            {
                return(new FileSystemFolder(path, true));
            }

            return(null);
        }
        /// <summary>
        /// Creates a subfolder in this folder
        /// </summary>
        /// <param name="desiredName">The name of the folder to create</param>
        /// <param name="option">Specifies how to behave if the specified folder already exists</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The newly created folder</returns>
        public async Task <IFolder> CreateFolderAsync(string desiredName, CreationCollisionOption option, CancellationToken cancellationToken)
        {
            Requires.NotNullOrEmpty(desiredName, "desiredName");

            await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

            EnsureExists();

            string nameToUse = desiredName;
            string newPath   = System.IO.Path.Combine(Path, nameToUse);

            if (Root.DirectoryExists(newPath))
            {
                if (option == CreationCollisionOption.GenerateUniqueName)
                {
                    for (int num = 2; Root.DirectoryExists(newPath); num++)
                    {
                        nameToUse = desiredName + " (" + num + ")";
                        newPath   = System.IO.Path.Combine(Path, nameToUse);
                    }
                    Root.CreateDirectory(newPath);
                }
                else if (option == CreationCollisionOption.ReplaceExisting)
                {
                    IsoStoreFolder folderToDelete = new IsoStoreFolder(nameToUse, this);
                    await folderToDelete.DeleteAsync(cancellationToken).ConfigureAwait(false);

                    Root.CreateDirectory(newPath);
                }
                else if (option == CreationCollisionOption.FailIfExists)
                {
                    throw new IOException("Directory already exists: " + newPath);
                }
                else if (option == CreationCollisionOption.OpenIfExists)
                {
                    //	No operation
                }
                else
                {
                    throw new ArgumentException("Unrecognized CreationCollisionOption: " + option);
                }
            }
            else
            {
                Root.CreateDirectory(newPath);
            }

            var ret = new IsoStoreFolder(nameToUse, this);

            return(ret);
        }
Пример #12
0
        /// <summary>
        /// Gets a file in this folder
        /// </summary>
        /// <param name="name">The name of the file to get</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The requested file, or null if it does not exist</returns>
        public async Task <IFile> GetFileAsync(string name, CancellationToken cancellationToken)
        {
            await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

            string path = System.IO.Path.Combine(Path, name);

            if (!File.Exists(path))
            {
                throw new PCLStorage.Exceptions.FileNotFoundException("File does not exist: " + path);
            }
            var ret = new FileSystemFile(path);

            return(ret);
        }
Пример #13
0
        /// <summary>
        /// Creates a subfolder in this folder
        /// </summary>
        /// <param name="desiredName">The name of the folder to create</param>
        /// <param name="option">Specifies how to behave if the specified folder already exists</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The newly created folder</returns>
        public async Task <IFolder> CreateFolderAsync(string desiredName, CreationCollisionOption option, CancellationToken cancellationToken)
        {
            Requires.NotNullOrEmpty(desiredName, "desiredName");
            await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

            EnsureExists();
            string nameToUse = desiredName;
            string newPath   = System.IO.Path.Combine(Path, nameToUse);

            if (Directory.Exists(newPath))
            {
                if (option == CreationCollisionOption.GenerateUniqueName)
                {
                    for (int num = 2; Directory.Exists(newPath); num++)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        nameToUse = desiredName + " (" + num + ")";
                        newPath   = System.IO.Path.Combine(Path, nameToUse);
                    }
                    Directory.CreateDirectory(newPath);
                }
                else if (option == CreationCollisionOption.ReplaceExisting)
                {
                    Directory.Delete(newPath, true);
                    Directory.CreateDirectory(newPath);
                }
                else if (option == CreationCollisionOption.FailIfExists)
                {
                    throw new IOException("Directory already exists: " + newPath);
                }
                else if (option == CreationCollisionOption.OpenIfExists)
                {
                    //	No operation
                }
                else
                {
                    throw new ArgumentException("Unrecognized CreationCollisionOption: " + option);
                }
            }
            else
            {
                Directory.CreateDirectory(newPath);
            }

            var ret = new FileSystemFolder(newPath, true);

            return(ret);
        }
Пример #14
0
        /// <summary>
        /// Gets a subfolder in this folder
        /// </summary>
        /// <param name="name">The name of the folder to get</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The requested folder, or null if it does not exist</returns>
        public async Task <IFolder> GetFolderAsync(string name, CancellationToken cancellationToken)
        {
            Requires.NotNullOrEmpty(name, "name");

            await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

            string path = System.IO.Path.Combine(Path, name);

            if (!Directory.Exists(path))
            {
                throw new PCLStorage.Exceptions.DirectoryNotFoundException("Directory does not exist: " + path);
            }
            var ret = new FileSystemFolder(path, true);

            return(ret);
        }
Пример #15
0
        /// <summary>
        /// Gets a file, given its path.  Returns null if the file does not exist.
        /// </summary>
        /// <param name="path">The path to a file, as returned from the <see cref="IFile.Path"/> property.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A file for the given path, or null if it does not exist.</returns>
        public async Task <IFile> GetFileFromPathAsync(string path, CancellationToken cancellationToken)
        {
            Requires.NotNullOrEmpty(path, "path");

            if (SwitchOffMainThread)
            {
                await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);
            }

            if (File.Exists(path))
            {
                return(new FileSystemFile(path));
            }

            return(null);
        }
Пример #16
0
        /// <summary>
        /// Copy a file.
        /// </summary>
        /// <param name="newPath">The new full path of the file.</param>
        /// <param name="collisionOption">How to deal with collisions with existing files.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A task which will complete after the file is moved.</returns>
        public async Task CopyAsync(string newPath, NameCollisionOption collisionOption = NameCollisionOption.ReplaceExisting, CancellationToken cancellationToken = default(CancellationToken))
        {
            Requires.NotNullOrEmpty(newPath, "newPath");

            await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

            string newDirectory = System.IO.Path.GetDirectoryName(newPath);
            string newName      = System.IO.Path.GetFileName(newPath);

            for (int counter = 1; ; counter++)
            {
                cancellationToken.ThrowIfCancellationRequested();
                string candidateName = newName;
                if (counter > 1)
                {
                    candidateName = String.Format(
                        CultureInfo.InvariantCulture,
                        "{0} ({1}){2}",
                        System.IO.Path.GetFileNameWithoutExtension(newName),
                        counter,
                        System.IO.Path.GetExtension(newName));
                }

                string candidatePath = PortablePath.Combine(newDirectory, candidateName);

                if (File.Exists(candidatePath))
                {
                    switch (collisionOption)
                    {
                    case NameCollisionOption.FailIfExists:
                        throw new IOException("File already exists.");

                    case NameCollisionOption.GenerateUniqueName:
                        continue;     // try again with a new name.

                    case NameCollisionOption.ReplaceExisting:
                        File.Delete(candidatePath);
                        break;
                    }
                }

                File.Copy(_path, candidatePath);
                _path = candidatePath;
                _name = candidateName;
                return;
            }
        }
        /// <summary>
        /// Gets a file in this folder
        /// </summary>
        /// <param name="name">The name of the file to get</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The requested file, or null if it does not exist</returns>
        public async Task <IFile> GetFileAsync(string name, CancellationToken cancellationToken)
        {
            Requires.NotNullOrEmpty(name, "name");
            await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

            EnsureExists();

            string path = System.IO.Path.Combine(Path, name);

            if (!Root.FileExists(path))
            {
                throw new PCLStorage.Exceptions.FileNotFoundException("File does not exist: " + path);
            }
            var ret = new IsoStoreFile(name, this);

            return(ret);
        }
Пример #18
0
        /// <summary>
        /// Opens the file
        /// </summary>
        /// <param name="fileAccess">Specifies whether the file should be opened in read-only or read/write mode</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A <see cref="Stream"/> which can be used to read from or write to the file</returns>
        public async Task <Stream> OpenAsync(FileAccess fileAccess, CancellationToken cancellationToken)
        {
            await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

            if (fileAccess == FileAccess.Read)
            {
                return(File.OpenRead(Path));
            }
            else if (fileAccess == FileAccess.ReadAndWrite)
            {
                return(File.Open(Path, FileMode.Open, System.IO.FileAccess.ReadWrite));
            }
            else
            {
                throw new ArgumentException("Unrecognized FileAccess value: " + fileAccess);
            }
        }
Пример #19
0
        /// <summary>
        /// Opens the file
        /// </summary>
        /// <param name="fileAccess">Specifies whether the file should be opened in read-only or read/write mode</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A <see cref="Stream"/> which can be used to read from or write to the file</returns>
        public async Task <Stream> OpenAsync(FileAccess fileAccess, CancellationToken cancellationToken)
        {
            await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

            System.IO.FileAccess nativeFileAccess;
            if (fileAccess == FileAccess.Read)
            {
                nativeFileAccess = System.IO.FileAccess.Read;
            }
            else if (fileAccess == FileAccess.ReadAndWrite)
            {
                nativeFileAccess = System.IO.FileAccess.ReadWrite;
            }
            else
            {
                throw new ArgumentException("Unrecognized FileAccess value: " + fileAccess);
            }

            try
            {
                IsolatedStorageFileStream stream = _root.OpenFile(Path, FileMode.Open, nativeFileAccess, FileShare.Read);
                return(stream);
            }
            catch (IsolatedStorageException ex)
            {
                //	Check to see if error is because file does not exist, if so throw a more specific exception
                bool fileDoesntExist = false;
                try
                {
                    if (!_root.FileExists(Path))
                    {
                        fileDoesntExist = true;
                    }
                }
                catch { }
                if (fileDoesntExist)
                {
                    throw new PCLStorage.Exceptions.FileNotFoundException("File does not exist: " + Path, ex);
                }
                else
                {
                    throw;
                }
            }
        }
Пример #20
0
        /// <summary>
        /// Gets a file from the App Bundle.  Returns null if the file does not exist.
        /// </summary>
        /// <param name="path">The path to a file, as returned from the <see cref="IFile.Path"/> property.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A file for the given path, or null if it does not exist.</returns>
        public static async Task <IFile> GetFileFromAppBundleAsync(string path, CancellationToken cancellationToken)
        {
            Requires.NotNullOrEmpty(path, "path");

            await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

            string bundlePath = NSBundle.MainBundle.ResourcePath;

            bundlePath = Path.Combine(bundlePath, path);
            FileSystemFile f = null;

            if (File.Exists(bundlePath))
            {
                f = new FileSystemFile(bundlePath);
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("JK#237b# GetFileFromAppBundleAsync Error file (" + path + ") must be in the Resources folder marked as BundleResource.");
            }
            return(f);
        }
        /// <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");

            await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

            var checkPath = PortablePath.Combine(Path, name);

            if (Root.FileExists(checkPath))
            {
                return(ExistenceCheckResult.FileExists);
            }
            else if (Root.DirectoryExists(checkPath))
            {
                return(ExistenceCheckResult.FolderExists);
            }
            else
            {
                return(ExistenceCheckResult.NotFound);
            }
        }
Пример #22
0
        public async Task <IFileStats> GetFileStats(CancellationToken cancellationToken = new CancellationToken())
        {
            await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

            var localCreationTime   = _root.GetCreationTime(_path);
            var localLastWriteTime  = _root.GetLastWriteTime(_path);
            var localLastAccessTime = _root.GetLastAccessTime(_path);

            var fileStats = new FileSystemFileStats()
            {
                Name              = _name,
                Extension         = System.IO.Path.GetExtension(_name),
                CreationTime      = localCreationTime.DateTime,
                CreationTimeUTC   = localCreationTime.UtcDateTime,
                LastWriteTime     = localLastWriteTime.DateTime,
                LastWriteTimeUTC  = localLastWriteTime.UtcDateTime,
                LastAccessTime    = localLastAccessTime.DateTime,
                LastAccessTimeUTC = localLastAccessTime.UtcDateTime
            };

            return(fileStats);
        }
Пример #23
0
        /// <summary>
        /// Deletes the file
        /// </summary>
        /// <returns>A task which will complete after the file is deleted.</returns>
        public async Task DeleteAsync(CancellationToken cancellationToken)
        {
            await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

            try
            {
#if WINDOWS_PHONE
                //  Windows Phone (at least WP7) doesn't throw an error if you try to delete something that doesn't exist,
                //  so check for this manually for consistent behavior across platforms
                if (!_root.FileExists(Path))
                {
                    throw new PCLStorage.Exceptions.FileNotFoundException("File does not exist: " + Path);
                }
#endif
                _root.DeleteFile(Path);
            }
            catch (IsolatedStorageException ex)
            {
                //	Check to see if error is because file does not exist, if so throw a more specific exception
                bool fileDoesntExist = false;
                try
                {
                    if (!_root.FileExists(Path))
                    {
                        fileDoesntExist = true;
                    }
                }
                catch { }
                if (fileDoesntExist)
                {
                    throw new PCLStorage.Exceptions.FileNotFoundException("File does not exist: " + Path, ex);
                }
                else
                {
                    throw;
                }
            }
        }
        /// <summary>
        /// Deletes this folder and all of its contents
        /// </summary>
        /// <returns>A task which will complete after the folder is deleted</returns>
        public async Task DeleteAsync(CancellationToken cancellationToken)
        {
            await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

            EnsureExists();

            if (string.IsNullOrEmpty(Path))
            {
                throw new IOException("Cannot delete root Isolated Storage folder.");
            }

            foreach (var subfolder in await GetFoldersAsync(cancellationToken).ConfigureAwait(false))
            {
                await subfolder.DeleteAsync(cancellationToken).ConfigureAwait(false);
            }

            foreach (var file in await GetFilesAsync(cancellationToken).ConfigureAwait(false))
            {
                await file.DeleteAsync(cancellationToken).ConfigureAwait(false);
            }

            Root.DeleteDirectory(Path);
        }
        /// <summary>
        /// Gets a file from the App Bundle.  Returns null if the file does not exist.
        /// </summary>
        /// <param name="path">The path to a file, as returned from the <see cref="IFile.Path"/> property.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A file for the given path, or null if it does not exist.</returns>
        public static async Task <IFile> GetFileFromAppBundleAsync(string assetFolderFilePath, CancellationToken cancellationToken)
        {
            Requires.NotNullOrEmpty(assetFolderFilePath, "assetFolderFilePath");
            await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

            //I was not able to access files from the Assets folder like 'file://android_asset/'
            //Now I copy the file into a temp folder first
            //Hopefully somebody knows a better solution for this
            //Stream iStream = null;
            //try
            //{
            //    iStream = Application.Context.Assets.Open(path);
            //}
            //catch (Exception)
            //{
            //    System.Diagnostics.Debug.WriteLine("JK#237# GetFileFromAppBundleAsync Error file (" + path + ") must be in the assets folder marked as AndroidAsset.");
            //}
            //if (iStream == null)
            //{
            //    return null;
            //}
            var tempPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);

            tempPath = System.IO.Path.Combine(tempPath, "appbundlefilestempfolder");
            if (System.IO.Directory.Exists(tempPath) == false)
            {
                System.IO.Directory.CreateDirectory(tempPath);
            }
            var path = System.IO.Path.GetFileName(assetFolderFilePath); //No subfolder inside the tempfolder

            tempPath = System.IO.Path.Combine(tempPath, path);
            //Files from the app package can't change so there is no need to copy them again
            if (System.IO.File.Exists(tempPath) == false)
            {
                try
                {
                    using (var br = new BinaryReader(Application.Context.Assets.Open(assetFolderFilePath)))
                    {
                        using (var bw = new BinaryWriter(new FileStream(tempPath, FileMode.Create)))
                        {
                            byte[] buffer = new byte[2048];
                            int    length = 0;
                            while ((length = br.Read(buffer, 0, buffer.Length)) > 0)
                            {
                                bw.Write(buffer, 0, length);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine("JK#237# GetFileFromAppBundleAsync Error file (" + path + ") must be in the assets folder marked as AndroidAsset. " + e.Message);
                }
                //var oStream = new FileOutputStream(tempPath);
                //byte[] buffer = new byte[2048];
                //int length = 2048;
                //while (iStream.Read(buffer, 0, length) > 0)
                //{
                //    oStream.Write(buffer, 0, length);
                //}
                //oStream.Flush();
                //oStream.Close();
                //iStream.Close();
            }
            if (System.IO.File.Exists(tempPath) == false)
            {
                return(null);
            }
            return(new FileSystemFile(tempPath));
        }
Пример #26
0
        public async Task <IFileStats> GetFileStats(CancellationToken cancellationToken = new CancellationToken())
        {
            await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

            return(FileSystemFileStats.FromPath(Path));
        }