Пример #1
0
        public bool FileExists(FileUri uri)
        {
            switch (uri.Location)
            {
            case StorageLocation.Bundle:

                try
                {
                    using (var stream = new StreamReader(uri.AbsolutePath))
                    {
                        if (stream == null)
                        {
                            return(false);
                        }

                        return(true);
                    }
                }
                catch
                {
                    return(false);
                }

            case StorageLocation.Internal:
                return(File.Exists(uri.AbsolutePath));

            case StorageLocation.External:
                return(File.Exists(uri.AbsolutePath));

            default:
                return(false);
            }
        }
Пример #2
0
        public void MoveFile(FileUri sourceUri, FileUri destinationUri)
        {
            if (destinationUri.Location == StorageLocation.Bundle)
            {
                throw new InvalidOperationException("Unable to copy file inside the bundle.");
            }

            _fileSystemPlatform.MoveFile(sourceUri, destinationUri);
        }
Пример #3
0
        public void DeleteFile(FileUri uri)
        {
            if (uri.Location == StorageLocation.Bundle)
            {
                throw new InvalidOperationException("Unable to delete file inside the bundle.");
            }

            _fileSystemPlatform.DeleteFile(uri);
        }
Пример #4
0
        public ulong GetFileSize(FileUri uri)
        {
            if (!FileExists(uri))
            {
                return(0);
            }

            FileInfo fi = new FileInfo(uri.AbsolutePath);

            return((ulong)fi.Length);
        }
Пример #5
0
        public static NSUrl ToNSUrl(this FileUri uri)
        {
            switch (uri.Location)
            {
            case StorageLocation.Bundle:
            case StorageLocation.Internal:
            case StorageLocation.External:
                return(NSUrl.FromFilename(uri.AbsolutePath));

            default:
                throw new InvalidOperationException("Invalid FileUri type");
            }
        }
Пример #6
0
        public static Android.Net.Uri ToUri(this FileUri uri)
        {
            switch (uri.Location)
            {
            case StorageLocation.Bundle:
                return(Android.Net.Uri.Parse(uri.AbsolutePath.Replace("bundle://", "file:///android_asset/")));

            case StorageLocation.Internal:
                return(Android.Net.Uri.FromFile(new Java.IO.File(uri.AbsolutePath)));

            case StorageLocation.External:
                return(Android.Net.Uri.FromFile(new Java.IO.File(uri.AbsolutePath)));

            default:
                throw new InvalidOperationException("Invalid FileUri type");
            }
        }
Пример #7
0
        public UniversalFileInfo GetFileInfo(FileUri uri)
        {
            if (!FileExists(uri))
            {
                throw new InvalidOperationException("File doesn't exists.");
            }

            FileInfo fi = new FileInfo(uri.AbsolutePath);

            return(new UniversalFileInfo
            {
                CreationTime = fi.CreationTime,
                LastAccessTime = fi.LastAccessTime,
                LastWriteTime = fi.LastWriteTime,
                Length = (ulong)fi.Length
            });
        }
Пример #8
0
        public Stream OpenFile(FileUri uri, UniversalFileMode mode, UniversalFileAccess access, UniversalFileShare share)
        {
            switch (uri.Location)
            {
            case StorageLocation.Bundle:
                return(Application.Context.Assets.Open(uri.RelativePath));

            case StorageLocation.Internal:
                return(File.Open(uri.AbsolutePath, (FileMode)mode, (FileAccess)access, (FileShare)share));

            case StorageLocation.External:
                return(File.Open(uri.AbsolutePath, (FileMode)mode, (FileAccess)access, (FileShare)share));

            default:
                return(null);
            }
        }
Пример #9
0
 public void MoveFile(FileUri sourceUri, FileUri destinationUri)
 {
     File.Move(sourceUri.AbsolutePath, destinationUri.AbsolutePath);
 }
Пример #10
0
 public Stream OpenFile(FileUri uri, UniversalFileMode mode, UniversalFileAccess access, UniversalFileShare share)
 {
     return(File.Open(uri.AbsolutePath, (FileMode)mode, (FileAccess)access, (FileShare)share));
 }
Пример #11
0
 public bool FileExists(FileUri uri)
 {
     return(File.Exists(uri.AbsolutePath));
 }
Пример #12
0
 public UniversalFileInfo GetFileInfo(FileUri uri)
 {
     return(_fileSystemPlatform.GetFileInfo(uri));
 }
Пример #13
0
 public void CopyFile(FileUri sourceUri, FileUri destinationUri, bool overwrite)
 {
     File.Copy(sourceUri.AbsolutePath, destinationUri.AbsolutePath, overwrite);
 }
Пример #14
0
 public void DeleteFile(FileUri uri)
 {
     File.Delete(uri.AbsolutePath);
 }
Пример #15
0
 public bool FileExists(FileUri uri)
 {
     return(_fileSystemPlatform.FileExists(uri));
 }
Пример #16
0
 public ulong GetFileSize(FileUri uri)
 {
     return(_fileSystemPlatform.GetFileSize(uri));
 }
Пример #17
0
 public Stream OpenFile(FileUri uri)
 {
     return(OpenFile(uri, UniversalFileMode.Open, UniversalFileAccess.Read));
 }
Пример #18
0
 public Stream OpenFile(FileUri uri, UniversalFileMode mode, UniversalFileAccess access)
 {
     return(OpenFile(uri, mode, access, UniversalFileShare.None));
 }
Пример #19
0
 public Stream OpenFile(FileUri uri, UniversalFileMode mode, UniversalFileAccess access, UniversalFileShare share)
 {
     return(_fileSystemPlatform.OpenFile(uri, mode, access, share));
 }