Exemple #1
0
        private void miBackupXMLGame_Click(object sender, EventArgs e)
        {
            ShortGame sGame     = (ShortGame)lvGames.SelectedItems[0].Tag;
            string    gameWPath = Path.Combine(_OutPPath, PlatformName, sGame.FileName.Split('.')[0]);

            var backupGame = _xfGames.ScrapBackupGame(sGame.ID);

            MakeXML.Backup_Game(gameWPath, backupGame, "TBGame");
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        internal bool Run()
        {
            ITrace.WriteLine(prefix: false);

            #region
            // Verifications
            // Todo Verifications with zip and 7z
            //if (Directory.Exists(_GamePath))
            //{


            //}
            #endregion

            /* Déplacé 2020
             * // Creation of System folder and working assign
             * ITrace.WriteLine($"[Run] {Lang.CreationFolder}: '{_SystemName}'");
             * Directory.CreateDirectory(_SystemName);
             * Directory.SetCurrentDirectory(_SystemPath);
             *
             * // Creation of Game folder
             * ITrace.WriteLine($"[Run] {Lang.CreationFolder}: '{_GamePath}'");
             * Directory.CreateDirectory(_GamePath);
             */
            //2020 Directory.SetCurrentDirectory(_GamePath);


            #region Creation of the Infos.xml
            if (Settings.Default.opInfos)
            {
                MakeXML.InfoGame(_GamePath, _ZeGame);
            }
            else
            {
                ITrace.WriteLine("[Run] Make info disabled");
            }
            #endregion

            // Tree root + lvl1
            MakeStructure();



            // Copy Roms
            #region 22/08/2020 new rom management
            vApps = CopyRoms(_zBackGame.ApplicationPath, _Tree.Children[nameof(SubFolder.Roms)].Path);

            //vApps = CopySpecific(_zBackGame.ApplicationPath, _Tree.Children["Roms"].Path, "Roms", x => _zBackGame.ApplicationPath = x);
            #endregion


            // Video, Music, Manual
            vManual = CopySpecific(_zBackGame.ManualPath, _Tree.Children[nameof(SubFolder.Manuals)].Path, "Manual", x => _zBackGame.ManualPath = x);
            vMusic  = CopySpecific(_zBackGame.MusicPath, _Tree.Children[nameof(SubFolder.Musics)].Path, "Music", x => _zBackGame.MusicPath = x);
            vVideo  = CopySpecific(_zBackGame.VideoPath, _Tree.Children[nameof(SubFolder.Videos)].Path, "Video", x => _zBackGame.VideoPath = x);


            // CopySpecificFiles() old way;

            // Copy images
            CopyImages();

            #region Copy CheatCodes
            if (Settings.Default.opCheatCodes && !string.IsNullOrEmpty(Settings.Default.CCodesPath))
            {
                CopyCheatCodes();
            }
            else
            {
                ITrace.WriteLine("[Run] Copy Cheat Codes disabled");
            }
            #endregion

            #region Copy Clones
            if (Settings.Default.opClones)
            {
                CopyClones();
            }
            else
            {
                ITrace.WriteLine($"[Run] Clone copy disabled");
            }
            #endregion

            #region Serialization / backup ameliorated of launchbox datas (with found medias missing)
            if (Settings.Default.opEBGame)
            {
                MakeXML.Backup_Game(_GamePath, _zBackGame, "EBGame");
            }
            else
            {
                ITrace.WriteLine($"[Run] Enhanced Backup Game disabled");
            }

            #endregion

            #region Save Struct
            if (Settings.Default.opTreeV)
            {
                GetStruc();
            }
            else
            {
                ITrace.WriteLine($"[Run] Save Struct disabled");
            }
            #endregion


            #region 2020 Résultats
            // au lieu de mettre à true le bool au moment de la copie,
            //on fait un recheck au cas où l'utilisateur a modifié le contenu)
            //PackMeRes.ShowDialog(vGame, vManual, vMusic, vVideo, vApps);


            PackMeRes2 pmr2 = new PackMeRes2(_Tree.Path)
            {
                GameName = _zBackGame.Title,
                // Destinations

                /*CheatPath = _Tree.Children[nameof(SubFolder.CheatCodes)].Path,
                 * ManualPath = _Tree.Children[nameof(SubFolder.Manuals)].Path,
                 * MusicPath = _Tree.Children[nameof(SubFolder.Musics)].Path,
                 * RomPath = _Tree.Children[nameof(SubFolder.Roms)].Path,
                 * VideoPath = _Tree.Children[nameof(SubFolder.Videos)].Path,*/
                // Sources
                SourceRomPath    = _ZePlatform.FolderPath,
                SourceManuelPath = _ZePlatform.PlatformFolders.FirstOrDefault(x => x.MediaType == "Manual"),
                SourceMusicPath  = _ZePlatform.PlatformFolders.FirstOrDefault(x => x.MediaType == "Music"),
                SourceVideoPath  = _ZePlatform.PlatformFolders.FirstOrDefault(x => x.MediaType == "Video"),
            };

            // Liste des manuels

            //pmr2.Musics = Directory.GetFiles(_Tree.Children["Musics"].Path, "*.*", System.IO.SearchOption.TopDirectoryOnly);

            pmr2.LoadDatas();
            pmr2.ShowDialog();


            //pmr2.AddManual();
            #endregion

            #region 2020 choix du nom
            // Fenêtre pour le choix du nom
            GameName gnWindows = new GameName();
            gnWindows.SuggestedGameName = _ZeGame.ExploitableFileName;
            gnWindows.ShowDialog();

            // Changement de nom du dossier
            ushort i = 0;

            string destFolder = Path.Combine(_SystemPath, gnWindows.ChoosenGameName);

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

                        // Attribution du résultat
                        _GamePath = destFolder;

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

            //string destArchLink = Path.Combine(path, $"{destArchive}");
            //string destArchLink = Path.Combine(path, gnWindows.ChoosenGameName);

            // On verra si on dissocie un jour
            _ZeGame.ExploitableFileName = gnWindows.ChoosenGameName;
            #endregion

            // Archive
            //string destArchive = Path.Combine(_SystemPath, _ZeGame.ExploitableFileName);

            #region Compression
            // Zip
            if (Properties.Settings.Default.opZip)
            {
                //  MessageBox.Show("test "+ destArchive);
                //     Make_Zip(destArchive);
                // ZipCompression.Make_Folder(_GamePath, _SystemPath, destArchive);
                ZipCompression.Make_Folder(_GamePath, _SystemPath, _ZeGame.ExploitableFileName);
            }
            else
            {
                ITrace.WriteLine($"[Run] Zip Compression disabled");
            }
            // 7-Zip
            if (Properties.Settings.Default.op7_Zip)
            {
                //MessageBox.Show("test " + destArchive);

                // SevenZipCompression.Make_Folder(_GamePath, _SystemPath, destArchive);
                SevenZipCompression.Make_Folder(_GamePath, _SystemPath, _ZeGame.ExploitableFileName);
            }
            else
            {
                ITrace.WriteLine($"[Run] 7z Compression disabled");
            }
            #endregion

            // Erase the temp folder
            if (MessageBox.Show($"{Lang.EraseTmpFolder} '{_ZeGame.ExploitableFileName}' ?", Lang.Erase, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                try
                {
                    Directory.SetCurrentDirectory(_WFolder);
                    Directory.Delete(_GamePath, true);
                    Console.WriteLine($"[Run] folder {_GamePath} erased");
                }
                catch (Exception exc)
                {
                    Console.WriteLine($"[Run] Error when Erasing temp folder {_GamePath}\n{exc.Message }");
                }
            }


            // Stop loggers
            if (_IScreen != null)
            {
                _IScreen.KillAfter(10);
            }

            ITrace.RemoveListerners(_Loggers);

            return(true);
        }
Exemple #3
0
        /// <summary>
        /// ...
        /// Créer un fichier xml après collection des données dans le fichier xml de launchbox si activé
        /// </summary>
        /// <param name="xFile">believe... xml file </param>
        /// <param name="GameFile">Game file (exploitable)</param>
        internal int Initialize(string xFile, ShortGame sGame)
        {
            // Verif
            if (string.IsNullOrEmpty(ID))
            {
                throw new Exception("Id property: null");
            }

            if (string.IsNullOrEmpty(_SystemName))
            {
                throw new Exception();
            }

            _WFolder = Properties.Settings.Default.OutPPath;

            // Chemin du dossier temporaire du system
            _SystemPath = Path.Combine(_WFolder, _SystemName);
            _GamePath   = Path.Combine(_SystemPath, $"{sGame.ExploitableFileName}");           // New Working Folder
            string logFile = Path.Combine(_WFolder, $"{_SystemName} - {sGame.ExploitableFileName}.log");


            // Todo peut être déclencher un event sur le stop pour couper net ?
            var folderRes = OPFolders.SVerif(_GamePath, "Initialize", Dcs_Buttons.NoPass | Dcs_Buttons.NoRename, (string message) => ITrace.WriteLine(message, true));

            if (folderRes == EDestDecision.Stop)
            {
                //
                ITrace.WriteLine("[Initialize] GoodBye !");
                if (_IScreen != null)
                {
                    _IScreen.Close();
                }

                ITrace.RemoveListener(_IScreen);

                return(200);
            }

            #region System d'affichage
            string prefix = "PackMe";
            //window
            if (Settings.Default.opLogWindow)
            {
                _IScreen        = new InfoScreen();
                _IScreen.Prefix = prefix;
                _IScreen.Show();
                _Loggers.Add(_IScreen);
            }

            // file
            if (Settings.Default.opLogFile)
            {
                InfoToFile iLog = new InfoToFile(logFile, true);
                iLog.Prefix = prefix;
                _Loggers.Add(iLog);
            }

            // debug
            if (Debugger.IsAttached)
            {
                InfoToConsole iConsole = new InfoToConsole();
                iConsole.Prefix = prefix;
                _Loggers.Add(iConsole);
            }

            ITrace.AddListeners(_Loggers);


            ITrace.WriteLine("===== Report of errors: =====");
            ITrace.WriteLine($"[Initialize] ID:\t'{ID}'");
            ITrace.WriteLine($"[Initialize] {Lang.SystemSelected}: '{_SystemName}'");
            ITrace.WriteLine($"[Initialize] {Lang.GameSelected}: '{sGame.Title}' - Rom: '{sGame.ExploitableFileName}'");


            #endregion

            /*
             * BackgroundWorker bw = new BackgroundWorker();
             * bw.DoWork += new DoWorkEventHandler(BwWork); // PackMe.Initialize(_XmlFPlatform);
             * bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(BWRunWorkerCompleted);
             * bw.RunWorkerAsync();
             */

            // Lecture du fichier platform
            XML_Functions xmlPlatform = new XML_Functions();
            xmlPlatform.ReadFile(Path.Combine(Properties.Settings.Default.LBPath, Properties.Settings.Default.fPlatforms));

            _ZePlatform = xmlPlatform.ScrapPlatform(_SystemName);

            // Reconstruct PlatformFolder Path
            foreach (PlatformFolder plfmFolder in _ZePlatform.PlatformFolders)
            {
                plfmFolder.FolderPath = ReconstructPath(plfmFolder.FolderPath);
            }

            // Lecture du fichier des jeux
            _XFunctions = new XML_Functions();
            _XFunctions.ReadFile(xFile);

            // Get Main infos
            _zBackGame = _XFunctions.ScrapBackupGame(ID);
            _ZeGame    = (GameInfo)_zBackGame;

            #region 2020

            // Creation of System folder and working assign
            ITrace.WriteLine($"[Run] {Lang.CreationFolder}: '{_SystemName}'");
            Directory.CreateDirectory(_SystemName);
            Directory.SetCurrentDirectory(_SystemPath);

            // Creation of Game folder
            ITrace.WriteLine($"[Run] {Lang.CreationFolder}: '{_GamePath}'");
            Directory.CreateDirectory(_GamePath);
            #endregion


            #region Original Backup Game
            if (Settings.Default.opOBGame)
            {
                MakeXML.Backup_Game(_GamePath, _zBackGame, "TBGame");
            }
            else
            {
                ITrace.WriteLine("[Run] Original Backup Game disabled");
            }
            #endregion

            _LBoxDI = new DirectoryInfo(Settings.Default.LBPath);

            // Set active Directory to Root
            Directory.SetCurrentDirectory(_WFolder);

            #region Paths reconstruction

            _zBackGame.ApplicationPath = ReconstructPath(_zBackGame.ApplicationPath);
            _zBackGame.ManualPath      = ReconstructPath(_zBackGame.ManualPath);
            _zBackGame.MusicPath       = ReconstructPath(_zBackGame.MusicPath);
            _zBackGame.VideoPath       = ReconstructPath(_zBackGame.VideoPath);
            #endregion


            return(0);
        }