Пример #1
0
        string getFreeSpace()
        {
            StringBuilder sb = new StringBuilder();

            try {
                List <long>   freeBytes   = new List <long>();
                List <long>   usableBytes = new List <long>(); // tatsächlich frei (nutzbar)
                List <long>   totalBytes  = new List <long>();
                List <string> sNames      = new List <string>();
                //freeBytes.Add(context.FilesDir.FreeSpace);
                //totalBytes.Add(context.FilesDir.TotalSpace);
                //sNames.Add("primary");
                foreach (var item in context.GetExternalFilesDirs(null))
                {
                    freeBytes.Add(item.FreeSpace);
                    usableBytes.Add(item.UsableSpace);
                    totalBytes.Add(item.TotalSpace);
                    sNames.Add(item.Path);
                    // StatFs stat=new StatFs(file.getPath());
                    // long availableSizeInBytes=stat.getBlockSize()*stat.getAvailableBlocks();
                }

                for (int i = 0; i < sNames.Count; i++)
                {
                    if (i > 0)
                    {
                        sb.AppendLine("");
                    }
                    sb.AppendLine(getItemString("Volume " + i.ToString() + ":", sNames[i], NAME1POS, CONTENT1POS));
                    sb.AppendLine(getItemString("Bytes gesamt", string.Format("{0} B ({1:N1} kb / {2:N1} MB / {3:N1} GB)",
                                                                              totalBytes[i],
                                                                              totalBytes[i] / 1024.0,
                                                                              totalBytes[i] / (1024.0 * 1024.0),
                                                                              totalBytes[i] / (1024.0 * 1024.0 * 1024.0)), NAME2POS, CONTENT1POS));
                    sb.AppendLine(getItemString("Bytes frei", string.Format("{0} B ({1:N1} kb / {2:N1} MB / {3:N1} GB)",
                                                                            freeBytes[i],
                                                                            freeBytes[i] / 1024.0,
                                                                            freeBytes[i] / (1024.0 * 1024.0),
                                                                            freeBytes[i] / (1024.0 * 1024.0 * 1024.0)), NAME2POS, CONTENT1POS));
                    sb.AppendLine(getItemString("Bytes nutzbar", string.Format("{0} B ({1:N1} kb / {2:N1} MB / {3:N1} GB)",
                                                                               usableBytes[i],
                                                                               usableBytes[i] / 1024.0,
                                                                               usableBytes[i] / (1024.0 * 1024.0),
                                                                               usableBytes[i] / (1024.0 * 1024.0 * 1024.0)), NAME2POS, CONTENT1POS));
                }
            } catch (Exception ex) {
                sb.AppendLine("Exception: " + ex.Message);
            }
            return(sb.ToString());
        }