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