/// <summary> /// Convert a list of game objects that are favorites into an xml /// </summary> /// <param name="systemName"></param> /// <param name="saveToGenre"></param> /// <param name="hsPath"></param> public void FavoriteToXml(string systemName, bool saveToGenre, string hsPath) { Favorites f = new Favorites(systemName, hsPath); List<DatabaseGame> g = new List<DatabaseGame>(); g = (List<DatabaseGame>)f.getCurrentGameList(); if (g.Count == 0) { MessageBox.Show("Try saving the xml first to get updated enabled tags."); } SerializeToXML(g, systemName, "Favorites", hsPath); if (saveToGenre) { List<string> genreList = AddFavoritesToGenre(HSPath + "\\Databases\\" + systemName + "\\Genre.xml"); DatabaseMenu m = new DatabaseMenu(); List<DatabaseMenu> mss = new List<DatabaseMenu>(); //Create the main Genre.xml string lastGenre = string.Empty; foreach (var itemGenre in genreList) { if (itemGenre != string.Empty) { if (lastGenre != itemGenre) mss.Add(new DatabaseMenu(itemGenre)); lastGenre = itemGenre; } } m.SerializeGenreItems(mss, hsPath + @"\Databases\" + systemName + "\\Genre.xml"); } }
public override void bw_DoWork(object sender, DoWorkEventArgs e) { string lastRom = string.Empty; List<object> menuandgames = (List<object>)e.Argument; List<DatabaseGame> m_System = (List < DatabaseGame >) menuandgames.ElementAt(0); List<DatabaseMenu> mm = (List<DatabaseMenu>)menuandgames.ElementAt(1); m_System.Sort((x, y) => String.Compare(x.RomName, y.RomName)); string tempSymlinkFile = string.Empty; string FileToLink = string.Empty; int i = 0; DatabaseMenu m = new DatabaseMenu(); try { var a = AppDomain.CurrentDomain.BaseDirectory; List<DatabaseGame> removeGameList = new List<DatabaseGame>(); foreach (var item in m_System) { //bool exists = m_System.Exists(x => x.RomName == item.RomName); string name = item.RomName; char s = name[0]; char t; if (lastRom != string.Empty) { t = lastRom[0]; if (char.ToLower(s) == char.ToLower(t)) { m_System.ElementAt(i).Index = string.Empty; m_System.ElementAt(i).Image = string.Empty; } else { m_System.ElementAt(i).Index = "true"; m_System.ElementAt(i).Image = char.ToLower(s).ToString(); } } else { m_System.ElementAt(i).Index = "true"; m_System.ElementAt(i).Image = char.ToLower(s).ToString(); } // Remove the rom if it existed if (name == lastRom) { removeGameList.Add(item); } else { //+++++++++++++++++++++++ // Symbolic link creation //+++++++++++++++++++++++ if (CreateSymlinks) { // Assign variables then Check wheels tempSymlinkFile = HSPath + "\\Media\\" + multiSystemName + @"\Images\Wheel\"; SymLink.CreateDirectory(tempSymlinkFile); tempSymlinkFile = System.IO.Path.Combine(a, tempSymlinkFile + item.RomName + ".png"); FileToLink = HSPath + "\\Media\\" + item.System + "\\Images\\Wheel\\" + item.RomName + ".png"; SymLink.CheckThenCreate(FileToLink, tempSymlinkFile); // Checkin videos and creating links tempSymlinkFile = HSPath + "\\Media\\" + multiSystemName + @"\Video\"; SymLink.CreateDirectory(tempSymlinkFile); tempSymlinkFile = System.IO.Path.Combine(a, tempSymlinkFile + item.RomName + ".mp4"); FileToLink = HSPath + "\\Media\\" + item.System + "\\Video\\" + item.RomName + ".mp4"; SymLink.CheckThenCreate(FileToLink, tempSymlinkFile); // Checkin videos and creating links tempSymlinkFile = HSPath + "\\Media\\" + multiSystemName + @"\Themes\"; SymLink.CreateDirectory(tempSymlinkFile); tempSymlinkFile = System.IO.Path.Combine(a, tempSymlinkFile + item.RomName + ".zip"); FileToLink = HSPath + "\\Media\\" + item.System + "\\Themes\\" + item.RomName + ".zip"; //If include default theme // If a theme doesn't exist copy over the default theme for this system name and rename to the romname if (defaultTheme) { if (!File.Exists(FileToLink)) FileToLink = HSPath + "\\Media\\" + item.System + "\\Themes\\" + "default.zip"; } SymLink.CheckThenCreate(FileToLink, tempSymlinkFile); for (int ii = 1; ii < 5; ii++) { // Checking artwork folders and creating links tempSymlinkFile = HSPath + "\\Media\\" + multiSystemName + @"\Images\Artwork" + ii + "\\"; SymLink.CreateDirectory(tempSymlinkFile); tempSymlinkFile = System.IO.Path.Combine(a, tempSymlinkFile + item.RomName + ".png"); FileToLink = HSPath + "\\Media\\" + item.System + "\\Images\\Artwork" + ii + "\\" + item.RomName + ".png"; SymLink.CheckThenCreate(FileToLink, tempSymlinkFile); } } //+++++++++++++++++++++++ // End Symbolic link creation //+++++++++++++++++++++++ } lastRom = name; i++; } foreach (var item in removeGameList) { m_System.Remove(item); } // Create Hyperspin settings if (File.Exists(SettingsFile)) { //Directory.CreateDirectory(@"Exports\Hyperspin\Settings\" + multiSystemName); File.Copy(SettingsFile, HSPath + @"\Settings\" + multiSystemName + ".ini", true); } Database.SerializeToXML(m_System, multiSystemName, multiSystemName, HSPath); try { // Stop this loop adding the system to the main menu if you already have it bool flag = false; foreach (var itemName in mm) { if (itemName.name == multiSystemName) { flag = true; } } // Add system because it doesn't exist if (!flag) mm.Add(new DatabaseMenu(multiSystemName, 1)); string Xml = HSPath + @"\Databases\" + multiSystemName + "\\" + multiSystemName + ".xml"; //Create rom mapping for RocketLaunch if (CreateRomMap) { //var koof = System.IO.Path.GetDirectoryName(RLPath); string gamesiniPath = RLPath + "\\Settings\\" + multiSystemName; if (!Directory.Exists(gamesiniPath)) Directory.CreateDirectory(gamesiniPath); RomMapper.CreateGamesIni(Xml, gamesiniPath); } //===================================== // GENRE GENERATING //===================================== // if (CreateGenres) { List<string> genreList = new List<string>(); foreach (DatabaseGame itemGenre in m_System) { itemGenre.Genre = itemGenre.Genre.Replace("/", "-"); bool exists = genreList.Exists(element => element == itemGenre.Genre); if (!exists) { genreList.Add(itemGenre.Genre); // System.Windows.MessageBox.Show(item.Genre); } } genreList.Sort(); List<DatabaseMenu> mss = new List<DatabaseMenu>(); //Create the main Genre.xml foreach (var itemGenre in genreList) { if (itemGenre != string.Empty) { mss.Add(new DatabaseMenu(itemGenre,1)); } } m.SerializeGenreItems(mss, HSPath + @"\Databases\" + multiSystemName + "\\Genre.xml"); // loop through the genremenu list foreach (DatabaseMenu menuItem in mss) { List<DatabaseGame> gg = new List<DatabaseGame>(); foreach (DatabaseGame items in m_System) { if (items.Genre == menuItem.name) gg.Add(new DatabaseGame(items)); } SerializeToGenreXML(gg, multiSystemName, menuItem.name); } } } catch (Exception) { } //BuildMainMenuItems(); } catch (Exception) { } finally { //mm.RemoveAt(0); m.SerializeMainMenuItems(CurrentMenu, mm, HSPath + "\\Databases\\Main Menu"); // mm.Insert(0, new DatabaseMenu("Main Menu")); } }
/// <summary> /// Create an xml from all the games tagged with IsFavorite /// </summary> /// <param name="gamelist"></param> public static void ConvertGameFavoritesToXml(List<DatabaseGame> gamelist, string systemName, bool saveToGenre) { FavesOutList.Clear(); foreach (DatabaseGame game in gamelist) { if (game.IsFavorite) FavesOutList.Add(game); } //Serialize xml SerializeToXML(FavesOutList, systemName, "Favorites", hsPath); if (saveToGenre) { List<string> genreList = AddFavoritesToGenre(hsPath + "\\Databases\\" + systemName + "\\Genre.xml"); DatabaseMenu dbMenu = new DatabaseMenu(); List<DatabaseMenu> genreMenuList = new List<DatabaseMenu>(); //Create the main Genre.xml string lastGenre = string.Empty; foreach (var itemGenre in genreList) { if (itemGenre != string.Empty) { if (lastGenre != itemGenre) genreMenuList.Add(new DatabaseMenu(itemGenre,1)); lastGenre = itemGenre; } } dbMenu.SerializeGenreItems(genreMenuList, hsPath + @"\Databases\" + systemName + "\\Genre.xml"); } }