Esempio n. 1
0
        public ulong GetAvailableDiskSpace(FolderUri uri)
        {
            try
            {
                Java.Lang.Process proc =
                    Java.Lang.Runtime.GetRuntime().Exec(String.Format("df {0}", uri.AbsolutePath));

                proc.WaitFor();

                var    resi = proc.InputStream;
                var    rdr  = new StreamReader(resi);
                string str  = rdr.ReadToEnd();

                string[] lines = str.Split('\n');
                if (lines.Length < 2)
                {
                    throw new InvalidOperationException("Unable to get size from shell.");
                }

                string[] entries = lines[1]
                                   .Split(' ')
                                   .Where(e => !String.IsNullOrWhiteSpace(e))
                                   .ToArray();

                string entry = entries[3];

                ulong  value = (ulong)Int32.Parse(entry.Substring(0, entry.Length - 1));
                string unit  = entry.Substring(entry.Length - 1, 1);

                switch (unit)
                {
                // Value is in bytes
                case "B":
                    return(value);

                // Value is in Kbytes
                case "K":
                    return(value * 1024);

                // Value is in Mbytes
                case "M":
                    return(value * 1024 * 1024);

                // Value is in Gbytes
                case "G":
                    return(value * 1024 * 1024 * 1024);

                default:
                    throw new InvalidOperationException("Unknown size unit.");
                }
            }
            catch (Exception ex)
            {
                StatFs stats = new StatFs(uri.AbsolutePath);
                return((ulong)(stats.AvailableBlocks * stats.BlockSize));
            }
        }
Esempio n. 2
0
        public void DeleteFolder(FolderUri uri)
        {
            if (uri.Location == StorageLocation.Bundle)
            {
                throw new InvalidOperationException("Unable to delete folder inside the bundle.");
            }

            _fileSystemPlatform.DeleteFolder(uri);
        }
Esempio n. 3
0
        public ulong GetAvailableDiskSpace(FolderUri uri)
        {
            ulong totalFreeSpace = 0;

            // Use below as suggested by Miguel de Icaza :)
            NSFileSystemAttributes values = NSFileManager.DefaultManager.GetFileSystemAttributes(uri.AbsolutePath);

            totalFreeSpace = values.FreeSize;

            return(totalFreeSpace);
        }
Esempio n. 4
0
        public FileUri[] GetFolderFiles(FolderUri uri, string searchPattern, bool recursive)
        {
            string[] filePaths = _fileSystemPlatform.GetFolderFiles(uri, searchPattern, recursive);
            if (filePaths == null)
            {
                return(null);
            }

            List <FileUri> fileUris = filePaths
                                      .Select(x => CreateFileUri(Path.Combine(uri.Uri, x.Replace(uri.AbsolutePath + "/", String.Empty))))
                                      .ToList();

            return(fileUris.ToArray());
        }
Esempio n. 5
0
 public bool FolderExists(FolderUri uri)
 {
     return(Directory.Exists(uri.AbsolutePath));
 }
Esempio n. 6
0
 public void DeleteFolder(FolderUri uri)
 {
     Directory.Delete(uri.AbsolutePath, true);
 }
Esempio n. 7
0
 public void CreateFolder(FolderUri uri)
 {
     Directory.CreateDirectory(uri.AbsolutePath);
 }
Esempio n. 8
0
 public string[] GetFolderFiles(FolderUri uri, string searchPattern, bool recursive)
 {
     return
         (Directory.GetFiles(uri.AbsolutePath, searchPattern, recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly));
 }
Esempio n. 9
0
 public bool FolderExists(FolderUri uri)
 {
     return(_fileSystemPlatform.FolderExists(uri));
 }
Esempio n. 10
0
 public ulong GetAvailableDiskSpace(FolderUri uri)
 {
     return(_fileSystemPlatform.GetAvailableDiskSpace(uri));
 }