public NewConnectionPlaceholderViewModel() { var thumbnail = ResourceManager.GetContentByteArray("/Resources/Connections/AddConnection.png"); Thumbnail = StfsPackageExtensions.GetBitmapFromByteArray(thumbnail); Name = Resx.NewConnection + Strings.DotDotDot; }
private void WrapTreeIntoViewModels(TreeItem <FileSystemItem> tree, ObservableCollection <TreeItemViewModel> children, TreeItemViewModel parent) { foreach (var treeItem in tree.Children.Values) { var icon = treeItem.Content.Type == ItemType.Directory ? "/Resources/Items/16x16/folder.png" : "/Resources/Items/16x16/file.png"; BitmapImage thumbnail; try { thumbnail = StfsPackageExtensions.GetBitmapFromByteArray(treeItem.Content.Thumbnail ?? ResourceManager.GetContentByteArray(icon)); } catch { thumbnail = StfsPackageExtensions.GetBitmapFromByteArray(ResourceManager.GetContentByteArray(icon)); } var vm = new TreeItemViewModel(parent) { Name = treeItem.Name, Title = treeItem.Content.Title, Content = treeItem.Content, Thumbnail = thumbnail, IsChecked = true, IsDirectory = treeItem.Content.Type == ItemType.Directory }; children.Add(vm); WrapTreeIntoViewModels(treeItem, vm.Children, vm); } }
public UserMessageViewModel(string message, NotifyUserMessageEventArgs e) { Message = message; var png = ResourceManager.GetContentByteArray(string.Format("/Resources/{0}.png", e.Icon)); Icon = StfsPackageExtensions.GetBitmapFromByteArray(png); CommandParameter = new UserMessageCommandParameter(this, e.Command, e.CommandParameter); Flags = e.Flags; }
public GodConversionSettingsViewModel(string targetPath, XisoDetails xiso, IWindowManager windowManager) { _windowManager = windowManager; TargetPath = targetPath; TempPath = targetPath; MediaId = xiso.MediaId; TitleId = xiso.TitleId; Disc = string.Format("{0}/{1}", xiso.DiscNumber, xiso.DiscCount); Name = xiso.Name; Thumbnail = xiso.Thumbnail == null || xiso.Thumbnail.Length == 0 || xiso.Thumbnail[0] == 0 ? null : StfsPackageExtensions.GetBitmapFromByteArray(xiso.Thumbnail); BrowseCommand = new DelegateCommand <string>(ExecuteBrowseCommand); RebuildTypeOptions = Enum.GetValues(typeof(IsoRebuildType)).Cast <IsoRebuildType>().Select(t => new ComboBoxItemViewModel <IsoRebuildType>(t)).ToObservableCollection(); //TODO: temporary turned off RebuildTypeOptions[1].IsSelectable = false; RebuildType = RebuildTypeOptions.First(); SaveRebuiltIsoImage = true; SkipSystemUpdate = true; }
protected override ImageSource Convert(FileSystemItemViewModel viewModel, Type targetType) { if (viewModel == null) { return(null); } var rm = viewModel.ResourceManager; var bytes = viewModel.IsUpDirectory ? null : viewModel.Thumbnail; if (bytes == null) { string icon; switch (viewModel.Type) { case ItemType.Directory: if (viewModel.IsUpDirectory) { icon = "up"; } else if (viewModel.Name == "0000000000000000") { icon = "games_folder"; } else if (viewModel.Model.RecognitionState == RecognitionState.PartiallyRecognized) { icon = "xbox_logo"; } else if (viewModel.IsRefreshing) { icon = "refresh_folder"; } else { icon = "folder"; } break; case ItemType.Link: icon = "reparse_point"; break; case ItemType.File: if (viewModel.IsCompressedFile) { icon = "package"; } else if (viewModel.IsIso) { icon = "iso"; } else if (viewModel.IsXex) { icon = "xex"; } else { ImageSource image = null; var extension = Path.GetExtension(viewModel.Name); if (!string.IsNullOrEmpty(extension)) { var key = ThumbnailSize + extension; if (SystemIconCache.ContainsKey(key)) { image = SystemIconCache[key]; } else { try { var shinfo = new ShellFileInfo(); var path = viewModel.Path; if (!File.Exists(path)) { path = key; //creating a temporary dummy file, i.e. 16.png using (File.Create(path)) {} } var size = ThumbnailSize == 16 ? (uint)1 : 0; IconExtensions.SHGetFileInfo(path, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), 0x100 | size); if (path != viewModel.Path) { File.Delete(path); } if (IntPtr.Zero != shinfo.hIcon) { image = Imaging.CreateBitmapSourceFromHIcon(shinfo.hIcon, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); } } catch { } SystemIconCache.Add(key, image); } if (image != null) { return(image); } } icon = "file"; } break; case ItemType.Drive: switch (viewModel.Model.DriveType) { case DriveType.CDRom: icon = "drive_cd"; break; case DriveType.Network: icon = "drive_network"; break; case DriveType.Removable: icon = "drive_flash"; break; default: icon = "drive"; break; } break; default: throw new NotSupportedException("Invalid item type: " + viewModel.Type); } bytes = rm.GetContentByteArray(string.Format("/Resources/Items/{0}x{0}/{1}.png", ThumbnailSize, icon)); } return(bytes[0] == 0 ? null : StfsPackageExtensions.GetBitmapFromByteArray(bytes)); }