private UITableViewCell CreateCacheCell(int index)
        {
            string text = null;

            if (0 == index)
            {
                text = string.Format(
                    "Rendered Cache: {0} / {1}",
                    NSByteCountFormatter.Format(TIPGlobalConfiguration.SharedInstance.TotalBytesForAllRenderedCaches, NSByteCountFormatterCountStyle.Binary),
                    NSByteCountFormatter.Format(TIPGlobalConfiguration.SharedInstance.MaxBytesForAllRenderedCaches, NSByteCountFormatterCountStyle.Binary));
            }
            else if (1 == index)
            {
                text = string.Format(
                    "Memory Cache: {0} / {1}",
                    NSByteCountFormatter.Format(TIPGlobalConfiguration.SharedInstance.TotalBytesForAllMemoryCaches, NSByteCountFormatterCountStyle.Binary),
                    NSByteCountFormatter.Format(TIPGlobalConfiguration.SharedInstance.MaxBytesForAllMemoryCaches, NSByteCountFormatterCountStyle.Binary));
            }
            else
            {
                text = string.Format(
                    "Disk Cache: {0} / {1}",
                    NSByteCountFormatter.Format(TIPGlobalConfiguration.SharedInstance.TotalBytesForAllDiskCaches, NSByteCountFormatterCountStyle.Binary),
                    NSByteCountFormatter.Format(TIPGlobalConfiguration.SharedInstance.MaxBytesForAllDiskCaches, NSByteCountFormatterCountStyle.Binary));
            }
            return(CreateChevronTextCell(text));
        }
        public NSMutableArray GetMountedVolumes()
        {
            NSMutableArray volumeList = new NSMutableArray();
            NSArray volKeys = NSArray.FromNSObjects(
                NSUrl.VolumeLocalizedNameKey,
                NSUrl.VolumeTotalCapacityKey,
                NSUrl.VolumeAvailableCapacityKey,
                NSUrl.VolumeIsBrowsableKey,
                NSUrl.VolumeURLKey,
                NSUrl.VolumeUUIDStringKey
            );

            NSFileManager fileManager = new NSFileManager();
            NSUrl[] volumeUrls = fileManager.GetMountedVolumes(volKeys, NSVolumeEnumerationOptions.None);
            NSByteCountFormatter byteFormatter = new NSByteCountFormatter();
            byteFormatter.CountStyle = NSByteCountFormatterCountStyle.File;

            foreach(NSUrl volumeUrl in volumeUrls) {
                NSError volUrlError;
                NSObject volName;
                NSObject volIdentifer;
                NSObject volBrowsable;
                NSObject volBytesAvailable;
                NSObject volBytesTotal;

                volumeUrl.TryGetResource(NSUrl.VolumeLocalizedNameKey, out volName, out volUrlError);
                volumeUrl.TryGetResource(NSUrl.VolumeURLKey, out volIdentifer, out volUrlError);
                volumeUrl.TryGetResource(NSUrl.VolumeIsBrowsableKey, out volBrowsable, out volUrlError);
                volumeUrl.TryGetResource(NSUrl.VolumeAvailableCapacityKey, out volBytesAvailable, out volUrlError);
                volumeUrl.TryGetResource(NSUrl.VolumeTotalCapacityKey, out volBytesTotal, out volUrlError);

                NSNumber volBytesAvailableNum = (NSNumber)volBytesAvailable;
                NSNumber volBytesTotalNum = (NSNumber)volBytesTotal;

                byteFormatter.IncludesUnit = false;
                byteFormatter.IncludesCount = true;

                var volBytesAvailableCount = byteFormatter.Format(volBytesAvailableNum.LongValue);
                var volBytesTotalCount = byteFormatter.Format(volBytesTotalNum.LongValue);

                byteFormatter.IncludesUnit = true;
                byteFormatter.IncludesCount = false;
                var volBytesAvailableUnit = byteFormatter.Format(volBytesAvailableNum.LongValue);
                var volBytesTotalUnit = byteFormatter.Format(volBytesTotalNum.LongValue);

                NSNumber browsable = (NSNumber)volBrowsable;
                if (browsable.BoolValue) {
                    volumeList.Add(new NSDictionary(
                        "name", volName,
                        "id", volIdentifer,
                        "bytesAvailableCount", volBytesAvailableCount,
                        "bytesAvailableUnit", volBytesAvailableUnit,
                        "bytesTotalCount", volBytesTotalCount,
                        "bytesTotalUnit", volBytesTotalUnit
                    ));
                }
            }

            return volumeList;
        }
        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            var cell = TableView.DequeueReusableCell("EntryCell");

            if (cell == null)
            {
                cell = new UITableViewCell(UITableViewCellStyle.Subtitle, "EntryCell");
                cell.TextLabel.Lines         = 1;
                cell.TextLabel.LineBreakMode = UILineBreakMode.HeadTruncation;
                cell.DetailTextLabel.Lines   = 3;
            }

            var entry = results[indexPath.Row];

            cell.ImageView.Image       = entry.Image;
            cell.ImageView.ContentMode = UIViewContentMode.ScaleAspectFit;

            var percent = (entry.Progress < 1f) ? $"({entry.Progress * 100}%) " : string.Empty;

            cell.TextLabel.Text       = entry.Identifier;
            cell.DetailTextLabel.Text =
                $"{entry.Dimensions.Width}x{entry.Dimensions.Height}\n" +
                $"{percent}{NSByteCountFormatter.Format((long)entry.BytesUsed, NSByteCountFormatterCountStyle.Binary)}";

            return(cell);
        }
        private static UPMInboxFile ModelInboxFileFromInboxFile(UPInboxFile inboxFile)
        {
            UPMInboxFile upmInboxFile = new UPMInboxFile(StringIdentifier.IdentifierWithStringId(inboxFile.Path))
            {
                Path = inboxFile.Path,
                URL  = inboxFile.URL
            };

#if PORTING
            upmInboxFile.Name = inboxFile.Path.LastPathComponent();
            Exception    attributesErr;
            NSDictionary fileAttributes = NSFileManager.DefaultManager().AttributesOfItemAtPathError(inboxFile.Path, attributesErr);
            if (attributesErr)
            {
                DDLogError("UPInBoxPageModelController error no fileAttributes: %@", fileAttributes);
            }

            NSNumber fileSizeNumber = fileAttributes.ObjectForKey(NSFileSize);
            upmInboxFile.Size          = fileSizeNumber.LongLongValue();
            upmInboxFile.FormattedSize = NSByteCountFormatter.StringFromByteCountCountStyle(upmInboxFile.Size, NSByteCountFormatterCountStyleFile);
            upmInboxFile.Date          = fileAttributes.ObjectForKey(NSFileCreationDate);
            // Cant use TimeZone here. Called before Login and server independent.
            upmInboxFile.FormattedDate = UPInBoxPageModelController.UpDateFormatter().StringFromDate(upmInboxFile.Date);
            UIDocumentInteractionController interactionController = UIDocumentInteractionController.InteractionControllerWithURL(inboxFile.URL);
            ArrayList icons = interactionController.Icons;
            //upmInboxFile.Icon = icons.LastObject();  // Adding largest Icon available
#endif
            upmInboxFile.MimeTye = UPInboxFileManager.MimeTypeForPath(upmInboxFile.Path);
            upmInboxFile.Color   = UPInBoxPageModelController.ColorForMimeType(upmInboxFile.MimeTye);
            return(upmInboxFile);
        }
Beispiel #5
0
        public string GetFileDescription(string file)
        {
            if (string.IsNullOrEmpty(file))
            {
                return(null);
            }
            long fileSize = 0;
            var  asset    = PHAsset.FetchAssets(new[] { new NSUrl(file) }, null).LastObject as PHAsset;

            if (asset != null)
            {
                var options = new PHImageRequestOptions {
                    Synchronous = true
                };
                PHImageManager.DefaultManager.RequestImageData(asset, options, (data, dataUti, orientation, info) => {
                    fileSize = Convert.ToInt64(data.Length);
                });
            }
            return(NSByteCountFormatter.Format(fileSize, NSByteCountFormatterCountStyle.Binary));
        }
Beispiel #6
0
        public override NSView GetViewForItem(NSTableView tableView, NSTableColumn tableColumn, nint row)
        {
            NSTextField textField = (NSTextField)tableView.MakeView("TextField", null);

            if (textField == null)
            {
                textField = new NSTextField
                {
                    BackgroundColor = NSColor.Clear,
                    Bordered        = false,
                    Editable        = false,
                };
            }

            Title title = dataSource.Titles[(int)row];

            switch (tableColumn.Identifier)
            {
            case "TitleID":
                textField.StringValue = title.titleID ?? "";
                break;

            case "TitleName":
                textField.StringValue = title.titleName ?? "";
                break;

            case "DisplayVersion":
                textField.StringValue = title.displayVersion ?? "";
                break;

            case "Version":
                textField.StringValue = title.versionString ?? "";
                break;

            case "LatestVersion":
                textField.StringValue = title.latestVersionString ?? "";
                break;

            case "Firmware":
                textField.StringValue = title.firmware ?? "";
                break;

            case "MasterKey":
                textField.StringValue = title.masterkeyString ?? "";
                break;

            case "FileName":
                textField.StringValue = title.filename ?? "";
                break;

            case "FileSize":
                textField.StringValue = NSByteCountFormatter.Format(title.filesize, NSByteCountFormatterCountStyle.File) ?? "";
                break;

            case "Type":
                textField.StringValue = title.typeString ?? "";
                break;

            case "Distribution":
                textField.StringValue = title.distribution.ToString() ?? "";
                break;

            case "Structure":
                textField.StringValue = title.structureString ?? "";
                break;

            case "Signature":
                textField.StringValue = title.signatureString ?? "";
                break;

            case "Permission":
                textField.StringValue = title.permissionString ?? "";
                break;

            case "Error":
                textField.StringValue = title.error ?? "";
                break;
            }

            if (title.signature != true)
            {
                textField.BackgroundColor = NSColor.Gray.ColorWithAlphaComponent((nfloat)0.1);
            }

            if (title.permission == Title.Permission.Dangerous)
            {
                textField.TextColor = NSColor.Red;
            }
            else if (title.permission == Title.Permission.Unsafe)
            {
                textField.TextColor = NSColor.Purple;
            }

            textField.Cell.LineBreakMode = NSLineBreakMode.CharWrapping;

            return(textField);
        }
Beispiel #7
0
        public void Export(NSMenuItem menuItem)
        {
            NSSavePanel savePanel = NSSavePanel.SavePanel;

            savePanel.AllowedFileTypes = new string[] { "txt" };
            savePanel.Title            = "Export Titles";

            Process.log?.WriteLine("\nExport Titles");

            savePanel.BeginSheet(Window, (nint result) =>
            {
                if (result == (int)NSModalResponse.OK)
                {
                    using (var writer = new StreamWriter(savePanel.Url.Path))
                    {
                        Window.BeginSheet(sheet, ProgressComplete);
                        userCancelled = false;

                        writer.WriteLine("{0} {1}", NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleName").ToString(), NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleShortVersionString").ToString());
                        writer.WriteLine("--------------------------------------------------------------\n");

                        writer.WriteLine("Export titles starts at {0}\n", String.Format("{0:F}", DateTime.Now));

                        uint index = 0, count = (uint)titles.Count;

                        foreach (var title in titles)
                        {
                            if (userCancelled)
                            {
                                userCancelled = false;
                                break;
                            }

                            message.StringValue  = title.titleName ?? "";
                            progress.DoubleValue = 100f * index++ / count;

                            writer.WriteLine("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}|{11}|{12}|{13}|{14}",
                                             title.titleID,
                                             title.titleName,
                                             title.displayVersion,
                                             title.versionString,
                                             title.latestVersionString,
                                             title.firmware,
                                             title.masterkeyString,
                                             title.filename,
                                             NSByteCountFormatter.Format(title.filesize, NSByteCountFormatterCountStyle.File),
                                             title.typeString,
                                             title.distribution,
                                             title.structureString,
                                             title.signatureString,
                                             title.permissionString,
                                             title.error);
                        }

                        writer.WriteLine("\n{0} of {1} titles exported", index, titles.Count);

                        Process.log?.WriteLine("\n{0} of {1} titles exported", index, titles.Count);

                        Window.EndSheet(sheet);
                    }
                }
            });
        }