Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gpX"></param>
        /// <param name="tree"></param>
        /// <remarks>
        /// Altère GPX pour suivre les fichiers
        /// </remarks>
        private void CopyFiles(GameDataCont gpX, Folder tree)
        {
            // Roms + Clones
            gpX.ApplicationPath = CopyMain(gpX.ApplicationPath, tree.Children[Common.Games].Path, false);
            CopyList(gpX.Apps, tree.Children[Common.Games].Path, false);

            // CheatCodes
            CopyList(gpX.CompCheatCodes, tree.Children[Common.CheatCodes].Path, false);

            // Manuals
            gpX.ManualPath = CopyMain(gpX.ManualPath, tree.Children[Common.Manuals].Path, true, "Manual");
            CopyList(gpX.CompManuals, tree.Children[Common.Manuals].Path, true, "Manual");

            // Musics
            gpX.MusicPath = CopyMain(gpX.MusicPath, tree.Children[Common.Musics].Path, true, "Music");
            CopyList(gpX.Musics, tree.Children[Common.Musics].Path, true, "Music");

            // Videos
            gpX.VideoPath      = CopyMain(gpX.VideoPath, tree.Children[Common.Videos].Path, true, "Video");
            gpX.ThemeVideoPath = CopyMain(gpX.ThemeVideoPath, tree.Children[Common.Videos].Path, true, "Video");
            CopyList(gpX.Videos, tree.Children[Common.Videos].Path, true, "Video");

            // Images
            CopyImages(gpX.Images, tree.Children[Common.Images].Path);
        }
Example #2
0
        protected bool CopyFiles(GameDataCont gdC)
        {
            var files = new List <DataTrans>();

            files.AddRange(gdC.Applications);
            files.AddRange(gdC.Manuals);
            files.AddRange(gdC.Musics);
            files.AddRange(gdC.Videos);

            CopyFExt copyObj = new CopyFExt();

            copyObj.AskToUser     += IHMStatic.Ask4_FileConflict2;
            copyObj.UpdateStatus  += (x, y) => HeTrace.WriteLine(y.Message);
            copyObj.UpdateStatusT += (x, y) => HeTrace.WriteLine(y.Message);

            bool resultat = false;

            SafeBoxes.LaunchDouble(copyObj, () => resultat = copyObj.CopyN(files), "Copy files");

            if (!resultat)
            {
                return(false);
            }

            SafeBoxes.LaunchDouble(copyObj, () => resultat = copyObj.CopyN(gdC.Images), "Copy Images files");

            return(resultat);
        }
Example #3
0
        /// <summary>
        /// Récupère tous les fichiers en fonction du LBGame, ainsi que des dossiers de la plateforme
        /// </summary>
        /// <param name="lbGame"></param>
        /// <param name="gpX"></param>
        private void GetFiles(LBGame lbGame, GameDataCont gdC)
        {
            HeTrace.WriteLine($"[GetFiles]", this);

            var possibilities = GetBasicPossibilities(lbGame.Id, lbGame.Title);

            // Jeu principal + Clones
            gdC.SetApplications = GetFilesForGames(lbGame);

            // CheatCodes
            if (!string.IsNullOrEmpty(Config.HCCodesPath))
            {
                gdC.SetSCheatCodes = GetFilesByPredict(possibilities, Path.Combine(Config.HCCodesPath, _ZePlatform.Name), "CheatCodes");
            }

            // Manuels
            gdC.SetDefaultManual = GetFileForSpecifics(lbGame.ManualPath, Common.Config.HLaunchBoxPath);
            gdC.AddSManuals      = GetMoreFiles("Manual", possibilities);

            // Musics
            gdC.SetDefaultMusic = GetFileForSpecifics(lbGame.MusicPath, Common.Config.HLaunchBoxPath);
            gdC.AddSMusics      = GetMoreFiles("Music", possibilities);

            // Videos
            gdC.SetDefaultVideo      = GetFileForSpecifics(lbGame.VideoPath, Common.Config.HLaunchBoxPath);
            gdC.SetDefaultThemeVideo = GetFileForSpecifics(lbGame.ThemeVideoPath, Common.Config.HLaunchBoxPath);
            gdC.AddSVideos           = GetMoreFiles("Video", possibilities);

            //GetMoreFiles(toSearch, gpX.CompVideos, "Video", gpX.VideoPath, gpX.ThemeVideoPath);

            // Images
            gdC.Images = GetImagesFiles(lbGame, possibilities);
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gpX"></param>
        /// <param name="lbGame"></param>
        /// <param name="gamePath"></param>
        /// <remarks>
        /// Modifie le lbgame
        /// </remarks>
        private void Make_EnhanceBackup(GameDataCont gdC, LBGame lbGame, string gamePath)
        {
            lbGame.ApplicationPath = DxPath.To_RelativeOrNull(Common.Config.HLaunchBoxPath, gdC.DefaultApp?.CurrentPath);
            lbGame.ManualPath      = DxPath.To_RelativeOrNull(Common.Config.HLaunchBoxPath, gdC.DefaultManual?.CurrentPath);
            lbGame.MusicPath       = DxPath.To_RelativeOrNull(Common.Config.HLaunchBoxPath, gdC.DefaultMusic?.CurrentPath);
            lbGame.VideoPath       = DxPath.To_RelativeOrNull(Common.Config.HLaunchBoxPath, gdC.DefaultVideo?.CurrentPath);
            lbGame.ThemeVideoPath  = DxPath.To_RelativeOrNull(Common.Config.HLaunchBoxPath, gdC.DefaultThemeVideo?.CurrentPath);

            XML_Games.EnhancedBackup(_XMLPlatformFile, lbGame, gamePath);
        }
Example #5
0
        // ---

        public M_PackMeRes(string root, ContPlatFolders platform, GameDataCont gdC) : base(platform, gdC)
        {
            GameName = gdC.Title;
            _Root    = root;

            _GamesPath   = Path.Combine(_Root, Common.Games);
            _CheatsPath  = Path.Combine(_Root, Common.CheatCodes);
            _ManualsPath = Path.Combine(_Root, Common.Manuals);
            _MusicsPath  = Path.Combine(_Root, Common.Musics);
            _VideosPath  = Path.Combine(_Root, Common.Videos);

            Init();
        }
Example #6
0
        internal bool MakeDPG(string gamePath, ArchiveMode mode, string archiveLink)
        {
            GamePaths gpX = null;

            // Lecture des fichiers
            if (File.Exists(Path.Combine(gamePath, "DPGame.json")))
            {
                HeTrace.WriteLine("DPG Found");
                gpX = GamePaths.ReadFromJson(Path.Combine(gamePath, "DPGame.json"));
            }
            else if (File.Exists(Path.Combine(gamePath, "EBGame.xml")))
            {
                HeTrace.WriteLine("DPG Missing, work with EBGame");
                gpX = GetMainsInfo(gamePath, "EBGame.xml");
            }
            else if (File.Exists(Path.Combine(gamePath, "TBGame.xml")))
            {
                HeTrace.WriteLine("DPG Missing, work with TBGame");
                gpX = GetMainsInfo(gamePath, "TBGame.xml");
            }
            else if (File.Exists(Path.Combine(gamePath, "NBGame.xml")))
            {
                HeTrace.WriteLine("DPG Missing, work with NBGame");
                gpX = GetMainsInfo(gamePath, "NBGame.xml");
            }

            if (gpX == null)
            {
                throw new Exception("Impossible to continue, no data file available");
            }

            GameDataCont gpC = (GameDataCont)gpX;

            GameDataCompletion(gpC, mode, archiveLink);

            if (gpC.Applications.Count <= 0)
            {
                throw new Exception("No game to inject");
            }

            // Affichage
            IHMStatic.ShowDPG(gpC, gpX, gamePath);

            // Sauvegarde
            gpX.WriteToJson(Path.Combine(gamePath, "DPGame.json"));

            HeTrace.WriteLine("DPG Done");

            return(true);
        }
Example #7
0
 internal static void ShowDPG(GameDataCont gpC, GamePaths gpx, string gamePath)
 {
     Application.Current.Dispatcher?.Invoke
     (
         () =>
     {
         W_DPGMaker winDPG = new W_DPGMaker()
         {
             Model = new M_DPGMaker(gpC, gpx, gamePath),
         };
         if (winDPG.ShowDialog() == true)
         {
             // ...
         }
     }
     );
 }
Example #8
0
        private GamePaths MakeGamePaths(LBGame lbGame, GameDataCont gdC, Folder tree)
        {
            GamePaths gpX = GamePaths.CreateBasic(lbGame);

            //  gpX.ApplicationPath = AssignDefaultPath(tree.Children[Common.Games].Path, gdC.DefaultApp);
            gpX.SetApplications = gdC.Applications.Select(x =>
                                                          new DataPlus()
            {
                Id          = x.Id,
                Name        = x.Name,
                CurrentPath = x.Name,
                IsSelected  = x.IsSelected,
            });

            gpX.ManualPath     = AssignDefaultPath(tree.Children[Common.Manuals].Path, gdC.DefaultManual);
            gpX.MusicPath      = AssignDefaultPath(tree.Children[Common.Musics].Path, gdC.DefaultMusic);
            gpX.VideoPath      = AssignDefaultPath(tree.Children[Common.Videos].Path, gdC.DefaultVideo);
            gpX.ThemeVideoPath = AssignDefaultPath(tree.Children[Common.Videos].Path, gdC.DefaultThemeVideo);
            return(gpX);
        }
Example #9
0
        // ---

        private void CopyFiles(GameDataCont gdC, Folder tree)
        {
            HashCopy objCopy = new HashCopy();

            objCopy.AskToUser += PackMe_IHM.Ask4_FileConflict2;

            HeTrace.WriteLine("[CopyFiles] All files except images");
            // Fusion des fichiers sauf les images
            List <DataTrans> Fichiers = new List <DataTrans>();

            Fichiers.AddRange(gdC.Applications);
            Fichiers.AddRange(gdC.CheatCodes);
            Fichiers.AddRange(gdC.Manuals);
            Fichiers.AddRange(gdC.Musics);
            Fichiers.AddRange(gdC.Videos);

            PackMe_IHM.DoubleProgress(objCopy, "Copy",
                                      (test) => test = objCopy.CopySevNVerif(Fichiers),
                                      (test) => test = objCopy.CopySevNVerif(gdC.Images));
            //copyObj.CopySNVerif(Fichiers);
        }
Example #10
0
        /*
         * private void SetSelected(GamePaths gpX, GameDataCont gpC)
         * {
         *  var app = gpC.Apps.FirstOrDefault(x => x.ALinkToThePath.Equals(gpX.ApplicationPath));
         *  if (app != null)
         *      app.IsSelected = true;
         *  var manual = gpC.Apps.FirstOrDefault(x => x.ALinkToThePath.Equals(gpX.ApplicationPath));
         *  var music = gpC.Apps.FirstOrDefault(x => x.ALinkToThePath.Equals(gpX.ApplicationPath));
         *  var video = gpC.Apps.FirstOrDefault(x => x.ALinkToThePath.Equals(gpX.ApplicationPath));
         *  var themevideo = gpC.Apps.FirstOrDefault(x => x.ALinkToThePath.Equals(gpX.ApplicationPath));
         * }*/

        /// <summary>
        /// On rajoute les fichiers présents sur le disque dur
        /// </summary>
        /// <param name="gpC"></param>
        /// <param name="mode"></param>
        /// <param name="archiveName"></param>
        private void GameDataCompletion(GameDataCont gpC, ArchiveMode mode, string archiveName)
        {
            IEnumerable <string> files = null;

            if (mode == ArchiveMode.Zip)
            {
                files = ZipDecompression.StaticGetAllFiles(archiveName);
                files = files.Select(f => f.Replace('/', '\\'));
            }
            else if (mode == ArchiveMode.SevenZip)
            {
                files = SevenZipDecompression.StaticGetAllFiles(archiveName);
            }
            else if (mode == ArchiveMode.Folder)
            {
                files = Directory.GetFiles(archiveName, "*.*", SearchOption.AllDirectories);
                files = files.Select(f => f.Replace($@"{archiveName}\", string.Empty));
            }
            else
            {
                throw new Exception("Not supported");
            }


            // Vérification des fichiers entrés via le GamePaths;
            string tmp;

            //   gpC.SSetApplications = GameDataCompletion(files, Default.Games, "\\", "\\");
            foreach (DataPlus app in gpC.Applications.ToList())
            {
                tmp = $@"{Config.Games}{app.CurrentPath?.Substring(1)}";

                // Récupération du fichier correspondant
                var f = files.FirstOrDefault(x => x.StartsWith(tmp));

                // Si correspondance trouvée
                if (!string.IsNullOrEmpty(f))
                {
                    continue;
                }

                HeTrace.WriteLine($"File not found {app.CurrentPath}");
                f = files.FirstOrDefault(x => Path.GetFileName(x).Equals(Path.GetFileName(app.CurrentPath)));

                // Si remplacement possible
                if (!string.IsNullOrEmpty(f))
                {
                    app.CurrentPath = f.Replace(Config.Games, ".");
                    HeTrace.WriteLine($"Changed by {app.CurrentPath}");
                }
                else
                {
                    HeTrace.WriteLine("Removed");
                    gpC.RemoveApp(app);
                }
            }


            gpC.SetSCheatCodes = GameDataCompletion(files, Config.CheatCodes, "\\", "\\");
            // Manuals
            var tmp2 = $@"{Config.Manuals}{gpC.DefaultManual?.CurrentPath.Substring(1)}";

            if (!files.Contains(tmp2))
            {
                gpC.UnsetDefaultManual();
            }
            gpC.AddSManuals = GameDataCompletion(files, Config.Manuals, "\\", "\\");
            // Musics
            if (!files.Contains($@"{Config.Musics}{gpC.DefaultMusic?.CurrentPath.Substring(1)}"))
            {
                gpC.UnsetDefaultMusic();
            }
            gpC.AddSMusics = GameDataCompletion(files, Config.Musics, "\\", "\\");
            // Videos
            if (!files.Contains($@"{Config.Videos}{gpC.DefaultVideo?.CurrentPath.Substring(1)}"))
            {
                gpC.UnsetDefaultVideo();
            }

            if (!files.Contains($@"{Config.Videos}{gpC.DefaultThemeVideo?.CurrentPath.Substring(1)}"))
            {
                gpC.UnsetDefaultThemeVideo();
            }

            gpC.AddSVideos = GameDataCompletion(files, Config.Videos, "\\", "\\");
        }
Example #11
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;
                }
            }
        }
Example #12
0
        private void AssignTargets(GameDataCont gdC, string root, ContPlatFolders zePlatform)
        {
            string platFolderPath = zePlatform.FolderPath;

            if (string.IsNullOrEmpty(platFolderPath))
            {
                platFolderPath = Path.Combine(Config.HLaunchBoxPath, "Games");
            }
            else
            {
                platFolderPath = Path.GetFullPath(platFolderPath, Config.HLaunchBoxPath);
            }

            string appTarget = string.Empty;

            if (Config.UseGameNameFolder)
            {
                appTarget = Path.Combine(platFolderPath, Tool.WindowsConv_TitleToFileName(gdC.Title));
            }
            else
            {
                appTarget = platFolderPath;
            }

            // Games
            foreach (var app in gdC.Applications)
            {
                app.DestPath = app.CurrentPath.Replace(Path.Combine(root, Config.Games), appTarget);
            }

            AssignTarget(gdC.Manuals, root, Config.Manuals, Tag.MediaTManual, zePlatform);
            AssignTarget(gdC.Musics, root, Config.Musics, Tag.MediaTMusic, zePlatform);
            AssignTarget(gdC.Videos, root, Config.Videos, Tag.MediaTVideo, zePlatform);

            //    string destPath = zePlatform.PlatformFolders.FirstOrDefault((x => x.MediaType.Equals(mediatype))).FolderPath;

            AssignImages(gdC.Images, root, zePlatform);


            void AssignTarget(IEnumerable <DataRep> elems, string root, string subFolder, string mediaType, ContPlatFolders zePlatform)
            {
                var    dFolder    = zePlatform.PlatformFolders.First(x => x.MediaType.Equals(mediaType));
                string destFolder = Path.GetFullPath(dFolder.FolderPath, Config.HLaunchBoxPath);

                string src = Path.Combine(root, subFolder);

                foreach (var e in elems)
                {
                    e.DestPath = e.CurrentPath.Replace(src, destFolder);
                }
            }

            void AssignImages(List <DataRepImg> images, string root, ContPlatFolders zePlatform)
            {
                string prevMedType = string.Empty;
                string toReplace   = string.Empty;
                string target      = string.Empty;

                foreach (DataRepImg image in images)
                {
                    if (!prevMedType.Equals(image.Categorie))
                    {
                        prevMedType = image.Categorie;
                        toReplace   = Path.Combine(root, Config.Images, image.Categorie);

                        PlatformFolder pTarget = zePlatform.PlatformFolders.FirstOrDefault(x => x.MediaType.Equals(image.Categorie));
                        target = Path.GetFullPath(pTarget.FolderPath, Config.HLaunchBoxPath);
                    }

                    image.DestPath = image.CurrentPath.Replace(toReplace, target);
                }
            }
        }
Example #13
0
        private GameDataCont PrepareGDC(string root, GamePaths gpX)
        {
            HeTrace.WriteLine($"[{nameof(PrepareGDC)}]");

            GameDataCont gdc = new GameDataCont(gpX.Title, gpX.Platform);

            string tmp = string.Empty;

            HeTrace.WriteLine($"\tGames: {Config.Games}");
            // Games
            tmp = Path.Combine(root, Config.Games);
            gdc.SetApplications = gpX.Applications.Select(x =>
                                                          new DataPlus()
            {
                Id          = x.Id,
                Name        = x.Name,
                CurrentPath = Path.GetFullPath(x.CurrentPath, tmp),
                IsSelected  = x.IsSelected,
            });

            if (Directory.Exists(tmp))
            {
                gdc.SSetApplications = Directory.GetFiles(tmp, "*.*", SearchOption.AllDirectories);
            }

            /*gdc.SetDefaultApplication = gpX.ApplicationPath == null ? null : Path.GetFullPath(gpX.ApplicationPath, tmp);
             * gdc.SetApplications = Directory.GetFiles(tmp, "*.*", SearchOption.AllDirectories).ToList();*/

            // Manuals
            HeTrace.WriteLine($"\tManuals: {Config.Manuals}");
            tmp = Path.Combine(root, Config.Manuals);
            gdc.SetDefaultManual = string.IsNullOrEmpty(gpX.ManualPath)? null : Path.GetFullPath(gpX.ManualPath, tmp);
            if (Directory.Exists(tmp))
            {
                gdc.AddSManuals = Directory.GetFiles(Path.Combine(tmp), "*.*", SearchOption.AllDirectories).ToList();
            }

            // Musics
            HeTrace.WriteLine($"\tMusics: {Config.Musics}");
            tmp = Path.Combine(root, Config.Musics);
            gdc.SetDefaultMusic = string.IsNullOrEmpty(gpX.MusicPath) ? null : Path.GetFullPath(gpX.MusicPath, tmp);
            if (Directory.Exists(tmp))
            {
                gdc.AddSMusics = Directory.GetFiles(tmp, "*.*", SearchOption.AllDirectories).ToList();
            }

            // Videos
            HeTrace.WriteLine($"\tVideos: {Config.Videos}");
            tmp = Path.Combine(root, Config.Videos);
            gdc.SetDefaultVideo      = string.IsNullOrEmpty(gpX.VideoPath) ? null : Path.GetFullPath(gpX.VideoPath, tmp);
            gdc.SetDefaultThemeVideo = string.IsNullOrEmpty(gpX.ThemeVideoPath) ? null : Path.GetFullPath(gpX.ThemeVideoPath, tmp);
            if (Directory.Exists(tmp))
            {
                gdc.AddSVideos = Directory.GetFiles(tmp, "*.*", SearchOption.AllDirectories);
            }

            // Cheat Codes
            HeTrace.WriteLine($"\tCheatCodes: {Config.CheatCodes}");
            tmp = Path.Combine(root, Config.CheatCodes);
            if (Directory.Exists(tmp))
            {
                gdc.SetSCheatCodes = Directory.GetFiles(tmp, "*.*", SearchOption.AllDirectories).ToList();
            }

            // Images
            HeTrace.WriteLine("\tImages");
            tmp = Path.Combine(root, Config.Images);
            if (Directory.Exists(tmp))
            {
                gdc.Images = PrepareImages(tmp);
            }


            return(gdc);
        }
Example #14
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);
        }
Example #15
0
 /// <summary>
 /// Affiche en safe la fenêtre de résultat
 /// </summary>
 /// <param name="rootFolder"></param>
 /// <param name="platform"></param>
 /// <param name="gdC"></param>
 /// <returns></returns>
 internal static bool?LaunchBoxCore_Recap(string rootFolder, ContPlatFolders platform, GameDataCont gdC)
 {
     return(Application.Current.Dispatcher?.Invoke
            (
                () =>
     {
         W_PackMeRes W_res = new W_PackMeRes()
         {
             Title = $"{LanguageManager.Instance.Lang.Word_Result} - {gdC.Title}",
             Model = new M_PackMeRes(rootFolder, platform, gdC),
         };
         return W_res.ShowDialog();
     }
            ));
 }
Example #16
0
        // ---

        /// <summary>
        /// Travail pour un jeu
        /// </summary>
        /// <param name="shGame"></param>
        public void PackMe(ShortGame shGame)
        {
            TempDecision = MemorizedDecision;

            // Verif
            if (shGame == null || string.IsNullOrEmpty(shGame.Id))
            {
                HeTrace.WriteLine("Game property: null");
                return;
            }


            // Dossiers
            string gamePath = Path.Combine(_SystemPath, $"{shGame.ExploitableFileName}");             // New Working Folder

            //Compress_ZipMode(gamePath, shGame.Title);
            // Compress_7ZipMode(gamePath, shGame.Title);
            // Contrôle de collisions pour les dossiers
            if (Directory.Exists(gamePath))
            {
                HeTrace.WriteLine($"Directory Exists '{gamePath}'", this);
                // Demande à l'utilisateur si aucune précédente
                if (MemorizedDecision == E_Decision.None)
                {
                    Application.Current.Dispatcher?.Invoke(() =>
                                                           TempDecision = MBDecision.ShowDial(null, gamePath, LanguageManager.Instance.Lang.Folder_Ex, E_DxConfB.Trash | E_DxConfB.OverWrite));

                    switch (TempDecision)
                    {
                    /*   // Gestion des stops
                     * case E_Decision.Stop:
                     *     HeTrace.WriteLine("Stopped by user", this);
                     *     HeTrace.RemoveLogger("game");
                     *     return;
                     * case E_Decision.StopAll:
                     *     HeTrace.WriteLine("Stopped by user", this);
                     *     HeTrace.RemoveLogger("game");
                     *     throw new OperationCanceledException("Stopped by user");
                     */
                    case E_Decision.OverWriteAll:
                    case E_Decision.TrashAll:
                        MemorizedDecision = TempDecision;
                        break;
                    }

                    switch (TempDecision)
                    {
                    case E_Decision.Trash:
                    case E_Decision.TrashAll:
                        HeTrace.WriteLine($"Trash existing folder: '{gamePath}'", this);
                        OpFolders.Trash(@gamePath);
                        break;
                    }
                }
            }
            // --- On part du principe que tout peut être overwritté à partir de là.

            // Construction de la structure
            var tree = MakeStructure(gamePath);

            // ---

            #region Original Backup Game - Before all modifications
            if (Config.CreateTBGame)
            {
                XML_Games.TrueBackup(_XMLPlatformFile, shGame.Id, gamePath);
            }
            else
            {
                HeTrace.WriteLine("[Run] Original Backup Game disabled");
            }
            #endregion

            #region Backup without paths
            XML_Games.NPBackup(_XMLPlatformFile, shGame.Id, gamePath);

            #endregion

            // Récupération du jeu
            LBGame lbGame = XML_Games.Scrap_LBGame <LBGame>(_XMLPlatformFile, "ID", shGame.Id);

            // Récupération des clones


            HeTrace.WriteLine("Alarms about not managed field are not important except if it's about a path containing datas");
            HeTrace.WriteLine("EBGames and TBGames don't use a class they copy directly from xml to xml");

            #region Creation of the Infos.xml (on ne récupère que ce que l'on veut)
            if (Config.CreateInfos)
            {
                // --- Get game from Launchbox (on a besoin que jusqu'au game info)
                XML_Custom.Make_InfoGame(gamePath, lbGame);
            }
            else
            {
                HeTrace.WriteLine("[Run] Make info disabled", this);
            }
            #endregion


            // --- Récupération des fichiers
            GameDataCont gdC = new GameDataCont(lbGame.Title, lbGame.Platform);

            GetFiles(lbGame, gdC);

            if (PackMe_IHM.LaunchBoxCore_Prev(gamePath, _ZePlatform, gdC) != true)
            {
                throw new Exception("Stopped by user");
            }

            // --- Prepare files;
            PrepareList(gdC.Applications, tree, Config.KeepGameStruct, "Game");
            PrepareList(gdC.CheatCodes, tree, Config.KeepCheatStruct, "CheatCode");
            PrepareList(gdC.Manuals, tree, Config.KeepManualStruct, "Manual");
            PrepareList(gdC.Musics, tree, Config.KeepMusicStruct, "Music");
            PrepareList(gdC.Videos, tree, true, "Video");
            PrepareImages(gdC.Images, tree.Children[Common.Images].Path);

            // --- Copie des fichiers
            CopyFiles(gdC, tree);

            // --- Récapitulatif permettant de rajouter ou lever des fichiers au pack
            if (PackMe_IHM.LaunchBoxCore_Recap(gamePath, _ZePlatform, gdC) != true)
            {
                throw new Exception("Stopped by user");
            }

            // --- GamePaths ---
            GamePaths gpX = MakeGamePaths(lbGame, gdC, tree);


            #region Serialization / improved backup of Launchbox datas (with found medias missing)

            /* - En théorie on est toujours sur du relative path
             * - On a fait un assign sur les dossiers spécifiques
             * - On va récupérer la structure exacte sans aucune interprétation et modifier ce que l'on veut
             *      - Les Paths
             */
            if (Config.CreateEBGame)
            {
                Make_EnhanceBackup(gdC, lbGame, gamePath);
            }
            else
            {
                HeTrace.WriteLine($"[Run] Enhanced Backup Game disabled", this);
            }

            #endregion

            // --- Création d'un fichier conservant les fichiers par défaut définis par l'utilisateur en vue de réutilisation plus tard

            gpX.WriteToJson(Path.Combine(gamePath, "DPGame.json"));


            // --- On complète l'arborescence
            FoncSchem.MakeListFolder(tree.Children[Common.Manuals]);
            FoncSchem.MakeListFolder(tree.Children[Common.Images]);
            FoncSchem.MakeListFolder(tree.Children[Common.Musics]);
            FoncSchem.MakeListFolder(tree.Children[Common.Videos]);

            #region Save Struct
            if (Config.CreateTreeV)
            {
                FoncSchem.MakeStruct(tree, gamePath);
            }
            else
            {
                HeTrace.WriteLine($"[Run] Save Struct disabled", this);
            }
            #endregion

            #region 2020 choix du nom
            string name = PackMe_IHM.AskName(shGame.ExploitableFileName, _SystemPath);


            // Changement de nom du dossier <= Pour le moment ça ne fait que vérifier s'il peut écrire
            //si un dossier a le même nom ça ne pourra pas le renommer
            ushort i = 0;

            string destFolder = Path.Combine(_SystemPath, name);

            if (!gamePath.Equals(destFolder))
            {
                while (i < 10)
                {
                    try
                    {
                        Directory.Move(gamePath, destFolder);
                        HeTrace.WriteLine("Folder successfully renamed");

                        // Attribution du résultat
                        gamePath = destFolder;

                        // Sortie
                        break;
                    }
                    catch (IOException ioe)
                    {
                        HeTrace.WriteLine($"Try {i}: {ioe}");
                        Thread.Sleep(10);
                        i++;
                    }
                }
            }

            gamePath = destFolder;

            #endregion

            #region Compression
            // Zip
            if (Config.ZipCompression)
            {
                Compress_ZipMode(gamePath);
            }
            else
            {
                HeTrace.WriteLine($"[Run] Zip Compression disabled", this);
            }

            // 7zip
            if (Config.SevZipCompression)
            {
                Compress_7ZipMode(gamePath);
            }
            else
            {
                HeTrace.WriteLine($"[Run] 7Zip Compression disabled", this);
            }
            #endregion

            #region suppression du dossier de travail
            if (SafeBoxes.Dispatch_Mbox(this, "Would you want to ERASE the temp folder", "Erase", E_DxButtons.No | E_DxButtons.Yes, optMessage: shGame.ExploitableFileName) == true)
            {
                // Erase the temp folder
                try
                {
                    Directory.SetCurrentDirectory(_WFolder);
                    Directory.Delete(gamePath, true);
                    HeTrace.WriteLine($"[Run] folder {gamePath} erased", this);
                }
                catch (Exception exc)
                {
                    HeTrace.WriteLine($"[Run] Error when Erasing temp folder {gamePath}\n{exc.Message }", this);
                }
            }
            #endregion

            SetStatus(this, new StateArg($"Finished: {lbGame.Title}", CancelFlag));
        }