public void Execute(object parameter) { // Select image string imagePath = SelectImageFile(); if (String.IsNullOrEmpty(imagePath) || !File.Exists(imagePath)) { return; } // Get selected item. var modTuple = _manageModsViewModel.SelectedModTuple; string modDirectory = Path.GetDirectoryName(modTuple.ModConfigPath); // Set icon name and save. string iconFileName = Path.GetFileName(imagePath); if (modDirectory != null) { string iconPath = Path.Combine(modDirectory, iconFileName); // Copy image and set config file path. File.Copy(imagePath, iconPath, true); modTuple.ModConfig.ModIcon = iconFileName; // No need to write file on disk, file will be updated by binding. ImageSource source = Imaging.BitmapFromUri(new Uri(iconPath, UriKind.Absolute)); _manageModsViewModel.Icon = source; modTuple.Image = _manageModsViewModel.GetImageForModConfig(new PathGenericTuple <ModConfig>(modTuple.ModConfigPath, (ModConfig)modTuple.ModConfig)); } }
public void Execute(object parameter) { // Select image string imagePath = SelectImageFile(); if (String.IsNullOrEmpty(imagePath) || !File.Exists(imagePath)) { return; } // Get current selected application and its paths. ApplicationConfig config = _addAppViewModel.Application.Config; // Get application entry in set of all applications. var appIconPathTuple = _addAppViewModel.MainPageViewModel.Applications.First(x => x.Config.Equals(config)); string applicationDirectory = Path.GetDirectoryName(appIconPathTuple.ConfigPath); string applicationIconFileName = Path.GetFileName(imagePath); if (applicationDirectory != null) { string applicationIconPath = Path.Combine(applicationDirectory, applicationIconFileName); // Copy image and set config file path. File.Copy(imagePath, applicationIconPath, true); config.AppIcon = applicationIconFileName; // No need to write file on disk, file will be updated by binding. ImageSource source = Imaging.BitmapFromUri(new Uri(applicationIconPath, UriKind.Absolute)); appIconPathTuple.Image = source; } }
private void UpdateIcon(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == nameof(SelectedMod)) { if (SelectedMod?.Generic != null) { Icon = Imaging.BitmapFromUri(new Uri(SelectedMod.Generic.Image)); } } }
public void Execute(object parameter) { var applicationTuple = _addAppViewModel.MainPageViewModel.Applications.FirstOrDefault(x => x.Config.Equals(_lastConfig)); var loaderConfig = IoC.Get <LoaderConfig>(); var shell = (IShellLink) new ShellLink(); shell.SetDescription($"Launch {applicationTuple?.Config.AppName} via Reloaded II"); shell.SetPath($"\"{loaderConfig.LauncherPath}\""); shell.SetArguments($"{Constants.ParameterLaunch} \"{_lastConfig.AppLocation}\""); shell.SetWorkingDirectory(Path.GetDirectoryName(loaderConfig.LauncherPath)); if (applicationTuple != null) { var hasIcon = ApplicationConfig.TryGetApplicationIcon(applicationTuple.ConfigPath, applicationTuple.Config, out var logoPath); if (hasIcon) { // Make path for icon. string newPath = Path.ChangeExtension(logoPath, ".ico"); // Convert to ICO and save. var bitmapImage = Imaging.BitmapFromUri(new Uri(logoPath, UriKind.Absolute)); var bitmap = Imaging.BitmapImageToBitmap(bitmapImage); var resizedBitmap = Imaging.ResizeImage(bitmap, Constants.IcoMaxWidth, Constants.IcoMaxHeight); using (var newIcon = Icon.FromHandle(resizedBitmap.GetHicon())) using (Stream newIconStream = new FileStream(newPath, FileMode.Create)) { newIcon.Save(newIconStream); } shell.SetIconLocation(newPath, 0); } else { shell.SetIconLocation(_lastConfig.AppLocation, 0); } } // Save the shortcut. var file = (IPersistFile)shell; var link = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), $"{applicationTuple?.Config.AppName} via Reloaded II.lnk"); file.Save(link, false); var messageBox = new MessageBox(_xamlShortcutCreatedTitle.Get(), $"{_xamlShortcutCreatedMessage.Get()} {link}"); messageBox.WindowStartupLocation = WindowStartupLocation.CenterScreen; messageBox.ShowDialog(); }
private void ListView_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { if (ViewModel.SelectedModTuple != null) { ViewModel.Icon = Imaging.BitmapFromUri(new Uri(ViewModel.SelectedModTuple.Image)); } // Tell viewmodel to swap ModId compatibility chart. ImageModPathTuple oldModTuple = null; ImageModPathTuple newModTuple = null; if (e.RemovedItems.Count > 0) { oldModTuple = e.RemovedItems[0] as ImageModPathTuple; } if (e.AddedItems.Count > 0) { newModTuple = e.AddedItems[0] as ImageModPathTuple; } ViewModel.SwapMods(oldModTuple, newModTuple); e.Handled = true; }
/// <summary> /// Obtains an image to represent a given mod, either a custom one or the default placeholder. /// </summary> public ImageSource GetImageForModConfig(PathTuple <ModConfig> modConfig) { var uri = modConfig.Config.TryGetIconPath(modConfig.Path, out string iconPath) ? new Uri(iconPath, UriKind.RelativeOrAbsolute) : WpfConstants.PlaceholderImagePath; return(Imaging.BitmapFromUri(uri)); }