Beispiel #1
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, "\\", "\\");
        }