private async void BtnCreate_Click(object sender, RoutedEventArgs e) { if (!File.Exists(ViewModel.Path)) { MessageBox.Show("文件不存在。", Title, MessageBoxButton.OK, MessageBoxImage.Error); return; } var fileName = FileExtension.TryValidateFileName(ViewModel.Name, out var trueName) ? trueName : Path.GetFileNameWithoutExtension(ViewModel.Path); var ext = Path.GetExtension(ViewModel.Path); if (ViewModel.UseShortcut) { IShellLink link = (IShellLink) new ShellLink(); //link.SetDescription(fileName); link.SetPath(ViewModel.Path); System.Runtime.InteropServices.ComTypes.IPersistFile file = (System.Runtime.InteropServices.ComTypes.IPersistFile)link; file.Save(Path.Combine(_baseConsole.RomDirectoryPath, fileName + ".lnk"), false); } else { File.Copy(ViewModel.Path, Path.Combine(_baseConsole.RomDirectoryPath, fileName + ext)); } await _baseConsole.Refresh(); var game = _baseConsole.Games.FirstOrDefault(k => k.NameWithoutExtension == fileName); if (File.Exists(ViewModel.IconPath)) { game?.SetIcon(ViewModel.IconPath); } game?.RaisePropertyChanged(nameof(game.IconPath)); _baseWindow.Close(); }
private async void BtnCreate_Click(object sender, RoutedEventArgs e) { string trueName; try { trueName = FileExtension.ValidateFileName(ViewModel.Name); } catch (Exception ex) { MessageBox.Show(ex.Message, Title, MessageBoxButton.OK, MessageBoxImage.Error); return; } var path = Path.Combine(App.Config.GameDirectory, trueName); Directory.CreateDirectory(path); var console = new ConsoleMachine(path); App.GameListLoader.AddConsoleMachine(console); await console.Refresh(); _baseWindow.Close(); }