Esempio n. 1
0
        private bool Extractfiles(ZipFile archiveZ, IEnumerable <ZipEntry> files, string destFolder)
        {
            archiveZ.ExtractProgress += ArchiveZ_ExtractProgress;
            archiveZ.ZipError        += ArchiveZ_ZipError;

            int max = files.Count();

            UpdateStatus?.Invoke(this, new StateArg("Zip Decompression", CancelFlag));
            UpdateProgress?.Invoke(this, new ProgressArg(0, 100, CancelFlag));
            UpdateProgressT?.Invoke(this, new ProgressArg(0, max, CancelFlag));

            int i = 0;

            foreach (var ze in files)
            {
                UpdateProgressT?.Invoke(this, new ProgressArg(i, 100, CancelFlag));

                if (TokenSource != null && TokenSource.IsCancellationRequested)
                {
                    return(false);
                }

                //UpdateStatus?.Invoke(this, $"\tZipExtraction: {ze.FileName}");
                ze.Extract(destFolder, ExtractExistingFileAction.OverwriteSilently);
                i++;
            }

            UpdateProgressT?.Invoke(this, new ProgressArg(max, max, CancelFlag));
            return(true);
        }
        public object Run(int timeSleep)
        {
            if (timeSleep < 10)
            {
                throw new Exception($"Timesleep trop bas: {timeSleep}");
            }

            try
            {
                // Thread.Sleep(500);
                // Boucle Totale
                for (int i = 0; i < 10; i++)
                {
                    UpdateStatusT?.Invoke(this, new StateArg("New Task", CancelFlag));
                    UpdateProgressT?.Invoke(this, new ProgressArg(0, 100, CancelFlag));

                    for (int j = 0; j < 50; j++)
                    {
                        if (CancelFlag)
                        {
                            return(false);
                        }

                        UpdateProgress?.Invoke(this, new ProgressArg(j * 2, 100, CancelFlag));

                        while (IsPaused)
                        {
                            Thread.Sleep(100);
                        }

                        if (CancelToken.IsCancellationRequested)
                        {
                            return(null);
                        }

                        UpdateStatus?.Invoke(this, new StateArg($"File {i}.{j}", CancelFlag));
                        // db2.CurrentOP = $"{DxTBLang.File} {i}";


                        Thread.Sleep(timeSleep);
                    }

                    UpdateProgress?.Invoke(this, new ProgressArg(100, 100, false));
                }

                UpdateProgressT?.Invoke(this, new ProgressArg(0, 100, false));
                Thread.Sleep(100);
            }
            catch (Exception exc)
            {
                Debug.WriteLine(exc);
            }
            return(null);
        }
Esempio n. 3
0
        public bool ExtractAll(string fileArchive, string destFolder)
        {
            /*if (!Directory.Exists(destFolder))
             *  return false;*/

            if (!File.Exists(fileArchive))
            {
                return(false);
            }

            //string notFinishedF = Path.Combine(destFolder, "notFinished");

            using (SevenZipExtractor sevenZipExtr = new SevenZipExtractor(fileArchive))
            {
                sevenZipExtr.FileExtractionStarted  += SevenZipExtr_FileExtractionStarted;
                sevenZipExtr.FileExtractionFinished += SevenZipExtr_FileExtractionFinished;
                sevenZipExtr.FileExists             += SevenZipExtr_FileExists;;

                uint max        = sevenZipExtr.FilesCount;
                bool cancelflag = false;

                UpdateStatus?.Invoke(this, new StateArg("7Zip Decompression", cancelflag));
                UpdateProgress?.Invoke(this, new ProgressArg(0, 100, cancelflag));

                int i = 0;
                foreach (ArchiveFileInfo archiveFI in sevenZipExtr.ArchiveFileData)
                {
                    UpdateProgressT?.Invoke(this, new ProgressArg(i, max, cancelflag));
                    UpdateStatus?.Invoke(this, new StateArg($"Extracting {archiveFI.FileName}", cancelflag));

                    if (CancelToken.IsCancellationRequested)
                    {
                        return(false);
                    }

                    string fileDestination = Path.Combine(destFolder, archiveFI.FileName);

                    using (FileStream fs = new FileStream(fileDestination, FileMode.Create, FileAccess.Write))
                    {
                        sevenZipExtr.ExtractFile(archiveFI.Index, fs);
                    }

                    i++;
                }

                UpdateProgress?.Invoke(this, new ProgressArg(max, max, CancelFlag));
            }


            return(true);
        }
Esempio n. 4
0
        /*
         * public static bool UnCompressArchive(string fileArchive, string destFolder, CancellationToken token, I_TProgress asker = null)
         * {
         *  ZipDecompression zc = new ZipDecompression();
         *  if (asker != null)
         *  {
         *      zc.UpdateProgress += asker.SetProgress;
         *      zc.UpdateStatus += asker.SetStatus;
         *      zc.MaximumProgress += asker.SetMaximum;
         *
         *  }
         *
         *  return zc.UncompressArchive(fileArchive, destFolder, token);
         *
         * }*/


        public bool ExtractAll(string fileArchive, string destFolder)
        {
            /*if (!Directory.Exists(destFolder))
             *  return false;*/

            if (!File.Exists(fileArchive))
            {
                return(false);
            }

            //string notFinishedF = Path.Combine(destFolder, "notFinished");

            using (ZipFile archiveZ = ZipFile.Read(fileArchive))
            {
                archiveZ.ExtractProgress += ArchiveZ_ExtractProgress;
                archiveZ.ZipError        += ArchiveZ_ZipError;

                UpdateStatus?.Invoke(this, new StateArg("Zip Decompression", CancelFlag));

                int i   = 0;
                int max = archiveZ.Entries.Count();
                foreach (ZipEntry ze in archiveZ.Entries)
                {
                    UpdateProgressT?.Invoke(this, new ProgressArg(i, max, CancelFlag));
                    UpdateStatus?.Invoke(this, new StateArg($"\tZipExtraction: {ze.FileName}", CancelFlag));

                    if (CancelToken.IsCancellationRequested)
                    {
                        return(false);
                    }

                    ze.Extract(destFolder, ExtractExistingFileAction.OverwriteSilently);

                    i++;
                }

                UpdateProgress?.Invoke(this, new ProgressArg(max, max, CancelFlag));
            }


            return(true);
        }
Esempio n. 5
0
        private bool ExtractFiles(SevenZipExtractor sevenZipExtr, IEnumerable <ArchiveFileInfo> files, string destFolder)
        {
            sevenZipExtr.FileExtractionStarted  += SevenZipExtr_FileExtractionStarted;
            sevenZipExtr.FileExtractionFinished += SevenZipExtr_FileExtractionFinished;
            sevenZipExtr.FileExists             += SevenZipExtr_FileExists;;

            int  max        = files.Count();
            bool cancelflag = false;

            UpdateStatus?.Invoke(this, new StateArg("7Zip Decompression", cancelflag));
            UpdateProgress?.Invoke(this, new ProgressArg(0, 100, cancelflag));

            int i = 0;

            foreach (ArchiveFileInfo archiveFI in files)
            {
                UpdateProgressT?.Invoke(this, new ProgressArg(i, max, cancelflag));
                UpdateStatus?.Invoke(this, new StateArg($"Extracting {archiveFI.FileName}", cancelflag));

                if (TokenSource != null && TokenSource.IsCancellationRequested)
                {
                    return(false);
                }

                string fileDestination = Path.Combine(destFolder, archiveFI.FileName);

                using (FileStream fs = new FileStream(fileDestination, FileMode.Create, FileAccess.Write))
                {
                    sevenZipExtr.ExtractFile(archiveFI.Index, fs);
                }

                i++;
                //UpdateStatus?.Invoke(this, $"\tZipExtraction: {archiveFI.FileName}");
            }

            UpdateProgressT?.Invoke(this, new ProgressArg(max, max, cancelflag));
            return(true);
        }
Esempio n. 6
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);
            }
        }
Esempio n. 7
0
        // ---

        /// <summary>
        /// Signal update progress Total
        /// </summary>
        /// <param name="updateProgressT"></param>
        public void SayUpdateProgressT(Double updateProgressT)
        {
            Debug.WriteLine($"{nameof(SayUpdateProgressT)}: {updateProgressT}");
            UpdateProgressT?.Invoke(this, updateProgressT);
        }
Esempio n. 8
0
        public object Run(int timeSleep = 10)
        {
            bool backupDone = false;

            /*// Tracing
             * MeSimpleLog log = new MeSimpleLog(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Common.Logs, $"{DateTime.Now.ToFileTime()}.log"))
             * {
             *  LogLevel = 1,
             *  FuncPrefix = EPrefix.Horodating,
             * };
             * log.AddCaller(this);
             * HeTrace.AddLogger("LaunchBox", log);*/


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

            // Redirige les signaux
            //RedirectSignals();



            //
            int i = 0;

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

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

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

                // Vérification de la présence du fichier xml de la plateforme
                string machineXMLFile = Path.Combine(PS.Default.LastLBpath, PS.Default.dPlatforms, $"{lbGame.Platform}.xml");
                if (!File.Exists(machineXMLFile))
                {
                    UpdateStatus?.Invoke(this, $"Creation of xml file: '{machineXMLFile}'");
                    XML_Games.NewPlatform(machineXMLFile);
                }

                // Backup datas
                if (!backupDone)
                {
                    BackupPlatformFile(machineXMLFile);
                    UpdateStatus?.Invoke(this, $"Backup of '{machineXMLFile}'");
                    backupDone = true;
                }


                // Initialisation des dossiers

                TGamesP = Path.GetDirectoryName(lbGame.ApplicationPath);
                UpdateStatus?.Invoke(this, $"Target Game path: {TGamesP}");

                /*TCheatsCodesP = Path.Combine(root, "Cheat Codes", lbGame.Platform);
                 * UpdateStatus?.Invoke($"Target Cheats path: {TCheatsCodesP}");
                 *
                 * TImagesP = Path.Combine(root, "Images", lbGame.Platform);
                 * UpdateStatus?.Invoke($"Target Images path: {TImagesP}");*/

                TManualsP = Path.GetDirectoryName(lbGame.ManualPath);
                UpdateStatus?.Invoke(this, $"Target Manuals  path: {TManualsP}");

                TMusicsP = Path.GetDirectoryName(lbGame.MusicPath);
                UpdateStatus?.Invoke(this, $"Target Musics path: {TMusicsP}");

                TVideosP = Path.GetDirectoryName(lbGame.VideoPath);
                UpdateStatus?.Invoke(this, $"Target Videos path: {TVideosP}");

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

                // Copy des jeux
                Copy_Manager(lbGame, tmpPath);

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

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

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

            return(true);
        }
Esempio n. 9
0
        public object Run(Platform machine)
        {
            try
            {
                // Lecture du fichier xml de la plateforme (verbatim)
                UpdateStatus?.Invoke(this, "Get infos from platform");


                //var srcPlatform = XML_Platforms.Read(_SelectedPlatformXML);
                //string platformName = XML_Platforms.GetByTag(srcPlatform.Element("Platform"), "Name") as string;

                // L'objet n'est utilisé que pour avoir des données, il ne sert pas pour l'écriture


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

                // Travail sur le fichier des plateformes
                string platformsFile = Path.Combine(PS.Default.LastLBpath, PS.Default.fPlatforms);
                WorkOnPlatformFile(platformsFile, machine.Name);

                // Backup datas
                string xmlPlateforme = Path.Combine(PS.Default.LastLBpath, PS.Default.dPlatforms, $"{machine.Name}.xml");
                if (File.Exists(xmlPlateforme))
                {
                    BackupPlatformFile(xmlPlateforme);
                    UpdateStatus?.Invoke(this, $"Backup of '{xmlPlateforme}'");
                }


                // --- Initialisation des dossiers cible
                string root = Path.GetDirectoryName(Path.GetDirectoryName(machine.FolderPath));
                InitTargetPaths(machine, root);


                int done = 0;
                int i    = 0;
                foreach (Cont.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.Folder, Path.GetFileNameWithoutExtension(game.Nom));

                    // Décompression
                    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);
                    }


                    // Chargement des données du jeu
                    string   xmlFile      = Path.Combine(tmpPath, "TBGame.xml");
                    XElement verbatimGame = XML_Games.GetGameNode(xmlFile);

                    BasicGame baseGame = XML_Games.Scrap_BasicGame <BasicGame>(verbatimGame);
#if DEBUG
                    baseGame.Platform = "Sega Genesis";
#endif

                    /*
                     * string gameTitle = XML_Games.GetByTag(verbatimGame, "Title");
                     * UpdateStatus?.Invoke(this, $"Game Title: {gameTitle}");
                     *
                     * string platformGame = XML_Games.GetByTag(verbatimGame, "Platform");
                     * UpdateStatus?.Invoke(this, $"Game for {platformGame}");
                     *
                     * string gameID = XML_Games.GetByTag(verbatimGame, "ID");
                     * UpdateStatus?.Invoke(this, $"GameId: {gameID}");*/



                    // Test pour vérifier si ce sont les mêmes plateformes
                    if (!machine.Name.Equals(baseGame.Platform))
                    {
                        UpdateStatus?.Invoke(this, $"Aborded, wrong plateforme '{game.Nom}'");
                        i++;
                        UpdateProgressT?.Invoke(this, i);
                        continue;
                    }

                    // Copies
                    //Copy_Images(Path.Combine(tmpPath, PS.Default.Images), TImagesP);


                    // Copie et modifie
                    ManageFiles(verbatimGame, tmpPath, Cst.ManualP);

                    //Copy_TBManager(tmpPath);

                    WorkOnGamesFile(xmlPlateforme, verbatimGame, xmlFile, baseGame);


                    // Effacer le dossier temporaire
                    Delete(tmpPath);

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

                    done++;
                }

                UpdateStatus?.Invoke(this, $"Number of games processed: {done}/{Games.Count()}");

                return(true);
            }
            catch (Exception exc)
            {
                return(false);
            }
        }