示例#1
0
        /// <summary>
        /// On récupère les informations principales, dont les chemins (EBGame, TBGame)
        /// </summary>
        /// <param name="gamePath"></param>
        /// <param name="file"></param>
        /// <returns></returns>
        /// <remarks>
        /// Si les chemins sont vides, on conserve quand même pas de tri
        /// </remarks>
        private GamePaths GetMainsInfo(string gamePath, string file)
        {
            string xmlFile = Path.Combine(gamePath, file);

            GamePaths gpX = null;

            using (XML_Games xelGames = new XML_Games(xmlFile))
            {
                var xelG = xelGames.GetGameNode();

                gpX = GamePaths.CreateBasic(xelG);
                gpX.Complete(xelGames.GetNodes(Tag.AddApp, Tag.GameId, gpX.Id));

                // Essaie de récupération des paths
                foreach (var app in gpX.Applications)
                {
                    app.CurrentPath = SimuRelativePath(gpX.Platform, app.CurrentPath);
                }

                // ---
                gpX.ManualPath     = SimuRelativePath(gpX.Platform, gpX.ManualPath);
                gpX.MusicPath      = SimuRelativePath(gpX.Platform, gpX.MusicPath);
                gpX.VideoPath      = SimuRelativePath(gpX.Platform, gpX.VideoPath);
                gpX.ThemeVideoPath = SimuRelativePath(gpX.Platform, gpX.ThemeVideoPath);
            }

            return(gpX);
        }
示例#2
0
        private void InjectInXMLFile(string gamePath, GameDataCont gdC, string xmlPlatform, string platFormFolder)
        {
            //DataPlus defGame = gdC.Applications.FirstOrDefault(x => x.IsSelected);

            if (gdC.DefaultApp == null)
            {
                throw new Exception("No default game chosen");
            }

            // Lecture du fichier TBGame ou EBGame
            string xmlGame = null;

            if (File.Exists(Path.Combine(gamePath, "TBGame.xml")))
            {
                xmlGame = Path.Combine(gamePath, "TBGame.xml");
            }
            else if (File.Exists(Path.Combine(gamePath, "EBGame.xml")))
            {
                xmlGame = Path.Combine(gamePath, "EBGame.xml");
            }
            else if (File.Exists(Path.Combine(gamePath, "NBGame.xml")))
            {
                xmlGame = Path.Combine(gamePath, "NBGame.xml");
            }

            //
            if (xmlGame == null)
            {
                throw new Exception("No XML file to inject");
            }

            // Vérification pour voir si le jeu est présent
            using (XML_Games xmlSrc = new XML_Games(xmlGame))
                using (XML_Games xmlPlat = new XML_Games(xmlPlatform))
                {
                    bool?remove = false;
                    if (xmlPlat.Exists(GameTag.ID, gdC.DefaultApp.Id))
                    {
                        remove = IHMStatic.AskDxMBox("Game is already present, remove it ? ", "Question", E_DxButtons.No | E_DxButtons.Yes, gdC.DefaultApp.Name);

                        if (remove != true)
                        {
                            return;
                        }

                        // ----------------- On enlève si désiré
                        xmlPlat.Remove_Game(gdC.DefaultApp.Id);
                        xmlPlat.Remove_AddApps(gdC.DefaultApp.Id);
                        xmlPlat.Remove_CustomF(gdC.DefaultApp.Id);
                        xmlPlat.Remove_AlternateN(gdC.DefaultApp.Id);
                    }

                    // ----------------- Traitement du jeu.
                    XElement xelGame = xmlSrc.GetGameNode();

                    // ---  Modifications
                    // Changement de la plateforme
                    if (xelGame.Element(Tag.Platform) != null)
                    {
                        xelGame.Element(Tag.Platform).Value = gdC.Platform;
                    }

                    // App
                    ModifElement(xelGame, Tag.AppPath, gdC.DefaultApp, true);
                    // Manuel
                    ModifElement(xelGame, GameTag.ManPath, gdC.DefaultManual, true);
                    // Musique
                    ModifElement(xelGame, GameTag.MusPath, gdC.DefaultMusic, false);
                    // Video
                    ModifElement(xelGame, GameTag.VidPath, gdC.DefaultVideo, false);
                    // ThemeVideo
                    ModifElement(xelGame, GameTag.ThVidPath, gdC.DefaultThemeVideo, false);

                    // Changement du RootFolder
                    if (xelGame.Element(GameTag.RootFolder) != null)
                    {
                        xelGame.Element(GameTag.RootFolder).Value = platFormFolder;
                    }


                    // --- Récupération des clones + modification
                    var xelClones = xmlSrc.GetNodes(Tag.AddApp);
                    foreach (XElement clone in xelClones)
                    {
                        var file = gdC.Applications.FirstOrDefault(x => x.Id == clone.Element(CloneTag.Id).Value);
                        if (file != null)
                        {
                            ModifElement(clone, Tag.AppPath, file, true);
                        }
                    }

                    xmlPlat.InjectGame(xelGame);
                    xmlPlat.InjectAddApps(xelClones);

                    // ----------------- Custom Fields
                    if (Config.UseCustomFields)
                    {
                        var xelCFields = xmlSrc.GetNodes(Tag.CustField);
                        xmlPlat.InjectCustomF(xelCFields);
                    }

                    // ----------------- Alternate names
                    var xelANs = xmlSrc.GetNodes(Tag.AltName);
                    xmlPlat.InjectAltName(xelANs);

                    xmlPlat.Root.Save(xmlPlatform);
                }

            /*
             *      elem.Value = DxPath.To_RelativeOrNull(Default.LastLBpath, defGame.DestPath);
             * }
             *
             *
             * // Modification du fichier xml pour l'injection
             */
            void ModifElement <T>(in XElement xelObj, string tag, T elem, bool first) where T : IDataRep
            {
                var target = xelObj.Element(tag);
                var value  = elem == null ? string.Empty : DxPath.To_Relative(Config.HLaunchBoxPath, elem.DestPath);

                // Pour lever le .\
                value = value.StartsWith(@".\") ? value.Substring(2) : value;

                // Vérification
                if (target == null && first)
                {
                    xelObj.AddFirst(new XElement(tag, value));
                }
                else if (target == null && !first)
                {
                    xelObj.Add(new XElement(tag, value));
                }
                else
                {
                    target.Value = value;
                }
            }
        }
示例#3
0
        public object Run(Platform machine)
        {
            try
            {
                // Lecture du fichier xml de la plateforme (verbatim)
                UpdateStatus?.Invoke(this, "Get infos from platform");


                //var srcPlatform = XML_Platforms.Read(_SelectedPlatformXML);
                //string platformName = XML_Platforms.GetByTag(srcPlatform.Element("Platform"), "Name") as string;

                // L'objet n'est utilisé que pour avoir des données, il ne sert pas pour l'écriture


                if (machine.PlatformFolders.Count < 1)
                {
                    UpdateStatus?.Invoke(this, "Error: this machine has no path");
                    return(false);
                }

                // Travail sur le fichier des plateformes
                string platformsFile = Path.Combine(PS.Default.LastLBpath, PS.Default.fPlatforms);
                WorkOnPlatformFile(platformsFile, machine.Name);

                // Backup datas
                string xmlPlateforme = Path.Combine(PS.Default.LastLBpath, PS.Default.dPlatforms, $"{machine.Name}.xml");
                if (File.Exists(xmlPlateforme))
                {
                    BackupPlatformFile(xmlPlateforme);
                    UpdateStatus?.Invoke(this, $"Backup of '{xmlPlateforme}'");
                }


                // --- Initialisation des dossiers cible
                string root = Path.GetDirectoryName(Path.GetDirectoryName(machine.FolderPath));
                InitTargetPaths(machine, root);


                int done = 0;
                int i    = 0;
                foreach (Cont.FileObj game in Games)
                {
                    UpdateProgressT?.Invoke(this, i);

                    UpdateStatus?.Invoke(this, $"Work on: {game.Nom}");

                    string gameName = Path.GetFileNameWithoutExtension(game.Nom);
                    string tmpPath  = Path.Combine(Config.Folder, Path.GetFileNameWithoutExtension(game.Nom));

                    // Décompression
                    if (Path.GetExtension(game.Path).Equals(".zip", StringComparison.OrdinalIgnoreCase))
                    {
                        ZipDecompression.UnCompressArchive(game.Path, tmpPath, CancelToken);
                    }

                    if (CancelToken.IsCancellationRequested)
                    {
                        UpdateStatus?.Invoke(this, "Stopped by user");
                        return(false);
                    }


                    // Chargement des données du jeu
                    string   xmlFile      = Path.Combine(tmpPath, "TBGame.xml");
                    XElement verbatimGame = XML_Games.GetGameNode(xmlFile);

                    BasicGame baseGame = XML_Games.Scrap_BasicGame <BasicGame>(verbatimGame);
#if DEBUG
                    baseGame.Platform = "Sega Genesis";
#endif

                    /*
                     * string gameTitle = XML_Games.GetByTag(verbatimGame, "Title");
                     * UpdateStatus?.Invoke(this, $"Game Title: {gameTitle}");
                     *
                     * string platformGame = XML_Games.GetByTag(verbatimGame, "Platform");
                     * UpdateStatus?.Invoke(this, $"Game for {platformGame}");
                     *
                     * string gameID = XML_Games.GetByTag(verbatimGame, "ID");
                     * UpdateStatus?.Invoke(this, $"GameId: {gameID}");*/



                    // Test pour vérifier si ce sont les mêmes plateformes
                    if (!machine.Name.Equals(baseGame.Platform))
                    {
                        UpdateStatus?.Invoke(this, $"Aborded, wrong plateforme '{game.Nom}'");
                        i++;
                        UpdateProgressT?.Invoke(this, i);
                        continue;
                    }

                    // Copies
                    //Copy_Images(Path.Combine(tmpPath, PS.Default.Images), TImagesP);


                    // Copie et modifie
                    ManageFiles(verbatimGame, tmpPath, Cst.ManualP);

                    //Copy_TBManager(tmpPath);

                    WorkOnGamesFile(xmlPlateforme, verbatimGame, xmlFile, baseGame);


                    // Effacer le dossier temporaire
                    Delete(tmpPath);

                    //i++;
                    UpdateProgress?.Invoke(this, 100);
                    UpdateStatus?.Invoke(this, "Game Finished");

                    done++;
                }

                UpdateStatus?.Invoke(this, $"Number of games processed: {done}/{Games.Count()}");

                return(true);
            }
            catch (Exception exc)
            {
                return(false);
            }
        }