예제 #1
0
        public GameDataCont InjectGame(string gamePath)
        {
            HeTrace.WriteLine("Dpg Step");

            string dpgFile = Path.Combine(gamePath, "DPGame.json");

            // Check if DPG file exists
            if (!File.Exists(dpgFile))
            {
                DPGMakerCore dpgMaker = new DPGMakerCore();
                dpgMaker.MakeDPG_Folder(gamePath);
            }

            GamePaths gpX = GamePaths.ReadFromJson(dpgFile);

            HeTrace.WriteLine($"Platform Step for '{gpX.Platform}'");
            string platformsFile = Path.Combine(Config.HLaunchBoxPath, Config.PlatformsFile);

            bool CheckIfInjectionNeeded = !XML_Custom.TestPresence(platformsFile, Tag.Platform, Tag.Name, gpX.Platform);

            if (CheckIfInjectionNeeded)
            {
                HeTrace.WriteLine($"Backup of platforms file");
                // Backup du fichier de la plateforme;
                BackupFile(platformsFile, _BackupFolder);

                string newPFile = IHMStatic.GetAFile(Config.LastTargetPath, $"Platform '{gpX.Platform}' doesn't exist. Select the xml file to inject for this platform", "xml");
                if (string.IsNullOrEmpty(newPFile))
                {
                    throw new Exception("File for injection is not filled");
                }

                // Vérification que c'est la bonne plateforme
                if (!XML_Custom.TestPresence(newPFile, Tag.Platform, Tag.Name, gpX.Platform))
                {
                    throw new Exception("File doesn't contain the good platform");
                }

                HeTrace.WriteLine($"Injecting {gpX.Platform} in platforms file for {gpX.Platform}");
                InjectPlatform(gpX.Platform, newPFile);
            }

            ContPlatFolders zePlatform = XML_Platforms.GetPlatformPaths(platformsFile, gpX.Platform);

            HeTrace.WriteLine("Preparing files");
            // Préparation des fichiers
            GameDataCont gdC = PrepareGDC(gamePath, gpX);

            // Manipulation des fichiers
            AssignTargets(gdC, gamePath, zePlatform);

            // --- Lecture de la plateforme
            string machineXMLFile = Path.Combine(Config.HLaunchBoxPath, Config.PlatformsFolder, $"{gpX.Platform}.xml");

            if (!File.Exists(machineXMLFile))
            {
                XML_Games.NewPlatform(machineXMLFile);
            }

            // Backup platform file
            BackupFile(machineXMLFile, _BackupFolder);
            HeTrace.WriteLine($"Backup of '{machineXMLFile}'");

            InjectInXMLFile(gamePath, gdC, machineXMLFile, zePlatform.FolderPath);

            HeTrace.WriteLine($"Game injected: {gdC.Title}");

            return(gdC);
        }
예제 #2
0
        public object Run(int timeSleep = 10)
        {
            bool backupDone = false;

            /*// Tracing
             * MeSimpleLog log = new MeSimpleLog(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Common.Logs, $"{DateTime.Now.ToFileTime()}.log"))
             * {
             *  LogLevel = 1,
             *  FuncPrefix = EPrefix.Horodating,
             * };
             * log.AddCaller(this);
             * HeTrace.AddLogger("LaunchBox", log);*/


            // UpdateStatus += (x, y) => HeTrace.WriteLine(y, this);

            // Redirige les signaux
            //RedirectSignals();



            //
            int i = 0;

            foreach (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.WorkingFolder, Path.GetFileNameWithoutExtension(game.Nom));

                // Décompresser
                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, "EBGame.xml");
                LBGame lbGame  = XML_Games.Scrap_LBGame(xmlFile);
                List <AdditionalApplication> clones = XML_Games.ListAddApps(xmlFile);

                UpdateStatus?.Invoke(this, $"Game info xml loaded: {lbGame.Title}");

                // Vérification de la présence du fichier xml de la plateforme
                string machineXMLFile = Path.Combine(PS.Default.LastLBpath, PS.Default.dPlatforms, $"{lbGame.Platform}.xml");
                if (!File.Exists(machineXMLFile))
                {
                    UpdateStatus?.Invoke(this, $"Creation of xml file: '{machineXMLFile}'");
                    XML_Games.NewPlatform(machineXMLFile);
                }

                // Backup datas
                if (!backupDone)
                {
                    BackupPlatformFile(machineXMLFile);
                    UpdateStatus?.Invoke(this, $"Backup of '{machineXMLFile}'");
                    backupDone = true;
                }


                // Initialisation des dossiers

                TGamesP = Path.GetDirectoryName(lbGame.ApplicationPath);
                UpdateStatus?.Invoke(this, $"Target Game path: {TGamesP}");

                /*TCheatsCodesP = Path.Combine(root, "Cheat Codes", lbGame.Platform);
                 * UpdateStatus?.Invoke($"Target Cheats path: {TCheatsCodesP}");
                 *
                 * TImagesP = Path.Combine(root, "Images", lbGame.Platform);
                 * UpdateStatus?.Invoke($"Target Images path: {TImagesP}");*/

                TManualsP = Path.GetDirectoryName(lbGame.ManualPath);
                UpdateStatus?.Invoke(this, $"Target Manuals  path: {TManualsP}");

                TMusicsP = Path.GetDirectoryName(lbGame.MusicPath);
                UpdateStatus?.Invoke(this, $"Target Musics path: {TMusicsP}");

                TVideosP = Path.GetDirectoryName(lbGame.VideoPath);
                UpdateStatus?.Invoke(this, $"Target Videos path: {TVideosP}");

                // Modification des chemins dans le jeu
                Modify_Paths(lbGame);

                // Copy des jeux
                Copy_Manager(lbGame, tmpPath);

                // Retrait du jeu si présence
                bool?replace = false;
                if (XML_Custom.TestPresence(machineXMLFile, "Game", nameof(lbGame.Id).ToUpper(), lbGame.Id))
                {
                    replace = AskDxMBox("Game is Already present", "Question", E_DxButtons.Yes | E_DxButtons.No, lbGame.Title);
                }

                if (replace == true)
                {
                    XML_Games.Remove_Game(lbGame.Id, machineXMLFile);
                }

                // Injection
                XML_Games.InjectGame(lbGame, machineXMLFile);
                XML_Games.InjectAddApps(clones, machineXMLFile);
                if (PS.Default.wCustomFields)
                {
                    //var r = XML_Games.ListCustomFields(xmlFile, "CustomField");
                    XML_Games.Trans_CustomF(xmlFile, machineXMLFile);
                }

                UpdateStatus?.Invoke(this, $"Injection in xml Launchbox's files");
                //XMLBackup.Copy_EBGame(gameName, Path.Combine(tmpPath, "EBGame.xml"), MachineXMLFile);

                // Effacer le dossier temporaire
                Delete(tmpPath);

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

            UpdateStatus?.Invoke(this, "Task Finished");
            HeTrace.RemoveLogger("LaunchBoxEB");
            UpdateProgressT?.Invoke(this, 100);

            return(true);
        }