コード例 #1
0
        public static void InjectPlatform()
        {
            HeTrace.WriteLine("Platform injection...");
            string backupFolder  = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Common.BackUp);
            string platformsFile = Path.Combine(Config.HLaunchBoxPath, Config.PlatformsFile);


            string newPFile = IHMStatic.GetAFile(Config.LastTargetPath, LanguageManager.Instance.Lang.S_XmlPlatform, "xml");

            if (string.IsNullOrEmpty(newPFile))
            {
                HeTrace.WriteLine("Platform file is null !");
                return;
            }

            HeTrace.WriteLine($"Platform selected is '{newPFile}'");

            using (XML_Platforms srcPlatform = new XML_Platforms(newPFile))
                using (XML_Platforms lbPlatformes = new XML_Platforms(platformsFile))
                {
                    string machineName = srcPlatform.Root.Element(Tag.Platform).Element(Tag.Name)?.Value;
                    var    samePlats   = from platform in lbPlatformes.Root.Elements(Tag.Platform)
                                         where ((string)platform.Element(Tag.Name).Value).Equals(machineName, StringComparison.OrdinalIgnoreCase)
                                         select platform;

                    bool?write = true;
                    // On demande pour REMPLACER la machine si elle existe déjà
                    if (samePlats.Count() > 0)
                    {
                        write &= IHMStatic.AskDxMBox(
                            "Platform is Already present, replace it ?", "Question", E_DxButtons.Yes | E_DxButtons.No, machineName);
                    }


                    if (write == false)
                    {
                        return;
                    }

                    // Backup du fichier de la plateforme;
                    Tool.BackupFile(platformsFile, backupFolder);

                    // On efface si nécessaire.
                    lbPlatformes.RemoveElemByChild(Tag.Platform, Tag.Name, machineName);
                    lbPlatformes.RemoveElemByChild(Tag.PlatformFolder, Tag.Platform, machineName);

                    lbPlatformes.Save(platformsFile);

                    // Injection de la plateforme
                    lbPlatformes.InjectPlatform(srcPlatform.Root.Element(Tag.Platform));

                    // Injection des dossiers
                    lbPlatformes.InjectPlatFolders(srcPlatform.Root.Elements(Tag.PlatformFolder));

                    // Sauvegarde
                    lbPlatformes.Save(platformsFile);
                }

            HeTrace.WriteLine("Platform injection, done");
        }
コード例 #2
0
ファイル: C_LaunchBox.cs プロジェクト: daerlnaxe/Pack-My-Game
        public void InjectPlatform(string platform, string newPFile)
        {
            string platformsFile = Path.Combine(Config.HLaunchBoxPath, Config.PlatformsFile);

            using (XML_Platforms xPlat = new XML_Platforms(platformsFile))
            {
                // Injection en mode true verbatim
                if (xPlat.InjectPlatformExt(newPFile))
                {
                    HeTrace.WriteLine($"Platform {platform} injected");
                    xPlat.Save(platformsFile);
                }
            }
        }
コード例 #3
0
        private void Exec_ExtractPlatform(object sender, ExecutedRoutedEventArgs e)
        {
            TreeSave ts = new TreeSave()
            {
                Model = new M_SaveFile()
                {
                    StartingFolder = System.IO.Path.Combine(Config.HWorkingFolder, _Model.SelectedPlatform.Name),
                    ShowFiles      = true,
                    Info           = "Save to ...",
                    FileValue      = $"TBPlatform - {_Model.SelectedPlatform.Name}.xml"
                }
            };

            if (ts.ShowDialog() == true)
            {
                XML_Platforms.ExtractPlatform(Path.Combine(Config.HLaunchBoxPath, Config.PlatformsFile), _Model.SelectedPlatform.Name, ts.Model.LinkResult);
            }
        }
コード例 #4
0
        /// <summary>
        /// Sert au traitement de packaging pour un jeu
        /// </summary>
        /// <param name="iD"></param>
        /// <param name="platformName"></param>
        public LaunchBoxCore(string platformName)
        {
            if (string.IsNullOrEmpty(platformName))
            {
                throw new Exception();
            }


            //_PlatformName = platformName;

            #region Initialisation des chemins
            _WFolder = Config.HWorkingFolder;
            // Chemin du dossier temporaire du system
            _SystemPath = Path.Combine(_WFolder, platformName);

            #endregion

            _XMLPlatformFile = Path.Combine(Config.HLaunchBoxPath, Config.PlatformsFolder, $"{platformName}.xml");
            _ZePlatform      = XML_Platforms.GetPlatformPaths(Path.Combine(Config.HLaunchBoxPath, Config.PlatformsFile), platformName);


            #region Messages
            MeDebug mdb = new MeDebug()
            {
                ByPass = true,
            };
            HeTrace.AddMessenger("Debug", mdb);

            // Réorientation via les signaux
            MeEmit mdE = new MeEmit()
            {
                ByPass = true,
            };
            HeTrace.AddMessenger("Signal", mdE);
            mdE.SignalWrite     += (x, y) => SetStatus(x, new StateArg(y, false));
            mdE.SignalWriteLine += (x, y) => SetStatus(x, new StateArg(y, false));

            #endregion

            XML_Games.Signal += (x, y) => SetStatus(x, new StateArg(y, false));
        }
コード例 #5
0
        public object Run(int timeSleep = 10)
        {
            try
            {
                /*
                 *
                 * log.AddCaller(this);
                 * HeTrace.AddLogger("LaunchBox", log);
                 */

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

                // Redirige les signaux
                //RedirectSignals();


                // Récupération des infos de la plateforme
                UpdateStatus?.Invoke(this, "Get infos from platform");

                /*
                 * Normalement on peut virer
                 * XML_Functions xf = new XML_Functions();
                 * xf.ReadFile(Common.PlatformsFile);
                 *
                 * Machine = xf.ScrapPlatform(PlatformName);*/

                Machine = XML_Platforms.GetPlatformPaths(Common.PlatformsFile, PlatformName);

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

                // Backup datas
                MachineXMLFile = Path.Combine(PS.Default.LastLBpath, PS.Default.dPlatforms, $"{PlatformName}.xml");
                BackupPlatformFile(MachineXMLFile);
                UpdateStatus?.Invoke(this, $"Backup of '{MachineXMLFile}'");

                // Initialisation des dossiers cible
                // Memo solution la plus simple, fixant des limites et normalement évolutive
                string root = Path.GetDirectoryName(Path.GetDirectoryName(Machine.FolderPath));
                TGamesP = Path.Combine(Machine.FolderPath);
                UpdateStatus?.Invoke(this, $"Target Game path: {TGamesP}");

                TCheatsCodesP = Path.Combine(root, "Cheat Codes", PlatformName);
                UpdateStatus?.Invoke(this, $"Target Cheats path: {TCheatsCodesP}");

                TImagesP = Path.GetDirectoryName(Machine.PlatformFolders.First((x) => x.MediaType.Contains("Box", StringComparison.OrdinalIgnoreCase)).FolderPath);
                UpdateStatus?.Invoke(this, $"Target Images path: {TImagesP}");

                TManualsP = Machine.PlatformFolders.First((x) => x.MediaType == "Manual").FolderPath;
                UpdateStatus?.Invoke(this, $"Target Manuals  path: {TManualsP}");

                TMusicsP = Machine.PlatformFolders.First((x) => x.MediaType == "Music").FolderPath;
                UpdateStatus?.Invoke(this, $"Target Musics path: {TMusicsP}");

                TVideosP = Machine.PlatformFolders.First((x) => x.MediaType == "Video").FolderPath;
                UpdateStatus?.Invoke(this, $"Target Videos path: {TVideosP}");

                //
                int i = 0;
                //MaximumProgressT?.Invoke(this, Games.Count());
                //MaximumProgress?.Invoke(this, 100);
                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);
                    }

                    // todo 7zip

                    // 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);



                    //05/04/2021                LBGame lbGame = XML_Games.Scrap_GameLB(Path.Combine(tmpPath, "EBGame.xml"), "LaunchBox_Backup", PS.Default.wCustomFields);

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

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

                    // Modification de la platforme du jeu
                    UpdateStatus?.Invoke(this, $"Altération of platform {lbGame.Platform} => {PlatformName}");
                    lbGame.Platform = PlatformName;

                    // Copier
                    Copy_LBManager(lbGame, tmpPath);

                    /*// Platform modification
                     * if (PS.Default.ChangePlatform)
                     *  XMLBackup.Change_Platform(Path.Combine(destPath, "EBGame.xml"), machine);*/


                    // 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);

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

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

                return(true);
            }
            catch (Exception exc)
            {
                HeTrace.WriteLine(exc.Message);
                return(false);
            }
        }
コード例 #6
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);
        }