private void btnSaveDat_Click(object sender, RoutedEventArgs e) { if (dataFile != null && dataFile.Games.Count > 0) { SaveFileDialog dialog = new SaveFileDialog(); dialog.Filter = "Mame / ES (*.dat/*.xml)|*.dat;*.xml|All files (*.*)|*.*"; if (dialog.ShowDialog() == true) { dataFile.Header.Name = headerName.Text; dataFile.Header.Description = headerDesc.Text; if (!DataFile.Save(dataFile, gamesGrid.Items, dialog.FileName)) { this.ShowMessageAsync("Ho No !", "Something went wrong with this file..."); } } } }
private static DataFile Load(string path, string root) { DataFile dataFile = null; try { XmlSerializer serializer = new XmlSerializer(typeof(DataFile), new XmlRootAttribute { ElementName = root }); StreamReader reader = new StreamReader(path); dataFile = (DataFile)serializer.Deserialize(reader); reader.Close(); } catch { Console.WriteLine("Could not parse file: " + path); } return(dataFile); }
private void btnLoadDat_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Mame / ES (*.dat/*.xml)|*.dat;*.xml|All files (*.*)|*.*"; if (openFileDialog.ShowDialog() == true) { dataFile = DataFile.Load(openFileDialog.FileName); if (dataFile != null) { gamesGrid.ItemsSource = dataFile.Games; loadDat.Visibility = Visibility.Hidden; headerPanel.Visibility = Visibility.Visible; gamesGrid.Visibility = Visibility.Visible; } else { this.ShowMessageAsync("Oups", "Something went wrong with this file..."); loadDat.Visibility = Visibility.Visible; headerPanel.Visibility = Visibility.Hidden; gamesGrid.Visibility = Visibility.Hidden; } } }
public static DataFile Load(string path) { // mame.dat DataFile dataFile = Load(path, "datafile"); if (dataFile == null) { // mame2003-plus.xml Console.WriteLine("trying mame2003 format..."); if ((dataFile = Load(path, "mame")) != null) { dataFile.type = Type.Mame2003; } } if (dataFile == null) { // gamelist.xml Console.WriteLine("trying gamelist.xml format..."); if ((dataFile = Load(path, "gameList")) != null) { dataFile.type = Type.EmulationStation; } } if (dataFile == null) { Console.WriteLine("Could not parse file: " + path); return(null); } if (dataFile.Games.Count <= 0) { Console.WriteLine("Could not parse gamelist: no games found"); return(null); } // is datafile a mame "game" or "machine" nodes if (dataFile.Games[0] is Machine) { dataFile.type = Type.MameMachine; } // parse embedded catver, convert it to dictionnary for faster search string catver = GetEmbeddedResource("catver_0.214.ini"); string[] catverLines = catver.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); Dictionary <string, string> catverDic = catverLines.Select(item => item.Split('=')).ToDictionary(s => s[0], s => s[1]); foreach (Game game in dataFile.Games) { string name = string.IsNullOrEmpty(game.name) ? game.nameES : game.name; if (!catverDic.TryGetValue(name, out string genre) && game.isclone) { catverDic.TryGetValue(game.cloneof, out genre); } if (!string.IsNullOrEmpty(genre)) { game.genre = genre; } } // EmulationStation seems to have no header if (dataFile.Header == null) { dataFile.Header = new Header { Name = "No Name", Description = "No Description" }; } Console.WriteLine("database loaded: type is " + dataFile.type.ToString() + ", games: " + dataFile.Games.Count); return(dataFile); }