Пример #1
0
        /*   /// <summary>
         * ///
         * /// </summary>
         * /// <param name="path"></param>
         * /// <param name="compApps"></param>
         * /// <param name="destLocation"></param>
         * /// <returns></returns>
         * /// <remarks>
         * /// On ne garde pas le tail
         * /// </remarks>
         * private string CopyMain(string path, string destLocation)
         * {
         * string futurLink = Path.Combine(destLocation, Path.GetFileName(path));
         *
         * SimpleCopyManager(path, ref _FileConflictDecision, futurLink);
         *
         * return DxPath.To_Relative(destLocation, futurLink);
         * }*/

        private string CopyMain(string fichier, string destLocation, bool wTail, string mediatype = null)
        {
            if (string.IsNullOrEmpty(fichier))
            {
                return(string.Empty);
            }

            PlatformFolder folder = null;

            if (wTail && !string.IsNullOrEmpty(mediatype))
            {
                // On récupère le dossier concerné par le média
                folder = _ZePlatform.PlatformFolders.First(
                    (x) => x.MediaType.Equals(mediatype, StringComparison.OrdinalIgnoreCase));
            }

            string futurLink, tail;

            futurLink = tail = string.Empty;

            if (folder != null && fichier.Contains(folder.FolderPath))
            {
                tail      = fichier.Replace(folder.FolderPath, string.Empty).TrimStart('\\');
                futurLink = Path.Combine(destLocation, tail);
            }
            else
            {
                futurLink = Path.Combine(destLocation, Path.GetFileName(fichier));
            }

            SimpleCopyManager(fichier, ref _FileConflictDecision, futurLink);

            return(DxPath.To_Relative(destLocation, futurLink));
        }
Пример #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="applicationPath"></param>
 /// <param name="type"></param>
 internal void FormatPath(string applicationPath, string type)
 {
     // Pour l'instant le chemin relatif aura une allure de chemin absolu si les lecteurs sont différents
     if (OldPath.StartsWith('.'))
     {
         HardPath  = Path.GetFullPath(OldPath, Global.LaunchBoxRoot);
         RelatPath = OldPath;
     }
     // Hardlink
     else if (OldPath.Contains(':'))
     {
         HardPath  = OldPath;
         RelatPath = DxPath.To_Relative(Global.LaunchBoxRoot, OldPath);
         // OldRelatPath = Path.GetRelativePath(Global.LaunchBoxPath, OldPath);
     }
     // Cas spécial quand ça commence par un nom de folder (Games ne l'utiliserait pas)
     // Si c'est vide ça le transforme en .\
     else
     {
         /*OldHardPath = OldPath;
          * OldRelatPath = DxPath.ToRelative(Global.LaunchBoxRoot, OldPath);*/
         // Cas de figure ou c'est à la racine de Launchbox
         HardPath = Path.Combine(Global.LaunchBoxRoot, OldPath);
         //OldRelatPath = @$".\{OldPath}";
         RelatPath = DxPath.To_Relative(Global.LaunchBoxRoot, HardPath);
     }
 }
Пример #3
0
        private string AssignDefaultPath(string destPath, DataRep defaultPath)
        {
            if (defaultPath == null)
            {
                return(null);
            }

            return(DxPath.To_Relative(destPath, defaultPath.DestPath));;
        }
Пример #4
0
        /// <summary>
        /// Alteration de tous les chemins sur les MVFolders
        /// </summary>
        private async void AlterPath()
        {
            Debug.WriteLine("[PlatformPaths] AlterPath");
            Debug.Indent();
            //////Game.HNewFolderPath = Path.Combine(_NewRoot, tbGames.Text, Platform);
            //////Game.NewFolderPath = DxPath.ToRelative(AppPath, Game.HNewFolderPath);


            for (int i = 0; i < _AMVFolders.Length; i++)
            {
                var amvF = _AMVFolders[i];

                Debug.WriteLine($"[AlterPath] {amvF.MediaType}");

                // Choix de filtrer que videos / games / manuals / music et ... ?
                string hardPath;
                switch (amvF.MediaType)
                {
                case "Game":
                    hardPath = Path.Combine(_NewRoot, tbGames.Text, Platform);
                    break;

                case "Manual":
                    hardPath = Path.Combine(_NewRoot, tbManual.Text, Platform);
                    break;

                case "Music":
                    hardPath = Path.Combine(_NewRoot, tbMusic.Text, Platform);
                    break;

                case "Video":
                    hardPath = Path.Combine(_NewRoot, tbVideo.Text, Platform);
                    break;

                default:
                    hardPath = Path.Combine(_NewRoot, tbImages.Text, Platform, amvF.MediaType);
                    break;
                }

                string relatPath = DxPath.ToRelative(AppPath, hardPath);

                _AMVFolders[i].NewFolderPath  = relatPath;
                _AMVFolders[i].HNewFolderPath = hardPath;
            }

            Debug.Unindent();

            //
            AnalyseProps(_AMVFolders);
            await GenerateInfoPath(_AMVFolders);

            StyleMainFLP();
            SetMainWindow();
            boxLog.Text += @"Simuation finish ..." + Environment.NewLine;
            boxLog.Text += @"Ready, click on proceed to save this modifications." + Environment.NewLine;
        }
Пример #5
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);
        }
Пример #6
0
        public MigrateLModel(C_Platform backupPlatform, IPlatform currentPlatform)
        {
            CurrentPlatform = currentPlatform;
            ///OldPlatform = oldPlatform;
            VisPlatform = backupPlatform;


            //HeTrace.WriteLine($"Old Platform path '{oldPlatform.app}'");
            HeTrace.WriteLine($"Current Platform path '{CurrentPlatform.Folder}'");


            //VisPlatform = C_Platform.Platform_Maker(oldPlatform, oldPlatform.GetAllPlatformFolders());

            VisPlatform.ApplicationPath.NewRelatPath = currentPlatform.Folder;
            VisPlatform.ApplicationPath.NewHardPath  = Path.GetFullPath(currentPlatform.Folder, Global.LaunchBoxRoot);

            foreach (var elem in VisPlatform)
            {
                foreach (var elem2 in currentPlatform.GetAllPlatformFolders())
                {
                    if (elem2.MediaType.Equals(elem.Type))
                    {
                        elem.NewHardPath  = Path.GetFullPath(elem2.FolderPath, Global.LaunchBoxRoot);
                        elem.NewRelatPath = DxPath.To_RelativeOrNull(Global.LaunchBoxRoot, elem.NewHardPath);
                    }
                }
            }


            /*Platform_Tools.SetFolders(in oldPlatform);
             *
             * Platform_Tools.SetFolders(in currentPlatform);*/
            //oldPlatform.

            //HeTrace.WriteLine($"default boximagepath '{oldPlatform.DefaultBoxImagePath}'");


            // Initialization des dossiers
            // Initialization according to the mode (debug/plugin)

            /*if (Global.DebugMode)
             *  // Utilisation de pseudos dossiers
             *  _PlatformFolders = ((MvPlatform)PlatformObject).GetAllPlatformFolders();
             * else
             *  // Récupération de tous les dossiers + tri
             *  _PlatformFolders = PlatformObject.GetAllPlatformFolders()
             *                          .OrderBy(x => x.MediaType).ToArray();*/

            // Games

            /*            GamesPaths.Source = oldPlatform.Folder;
             *          GamesPaths.Destination = currentPlatform.Folder;
             *          HeTrace.WriteLine(oldPlatform.Folder, 5);
             *          HeTrace.WriteLine(currentPlatform.Folder, 5);
             *
             *          /*  // Images
             *            ImagesPaths.Source = Path.GetDirectoryName(OldPlatform.DefaultBoxImagePath);
             *            ImagesPaths.Destination = Path.GetDirectoryName(CurrentPlatform.DefaultBoxImagePath);*/
            // Manuals

            /*     ManualsPaths.Source = oldPlatform.ManualsFolder;
             *   ManualsPaths.Destination = currentPlatform.ManualsFolder;
             *   // Musics
             *   MusicsPaths.Source = oldPlatform.MusicFolder;
             *   MusicsPaths.Destination = currentPlatform.MusicFolder;
             *   // Videos
             *   VideosPaths.Source = oldPlatform.VideosFolder;
             *   VideosPaths.Destination = currentPlatform.VideosFolder;*/
        }
Пример #7
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;
                }
            }
        }
Пример #8
0
        /// <summary>
        /// Simulate effect on paths
        /// </summary>
        /// <remarks>
        /// On ne modifie pas le chemin pour laisser le soin à l'utilisateur de le modifier manuellement
        /// </remarks>
        internal bool Simulate()
        {
            HeTrace.WriteLine(">>> Simulation");

            // Vérification du chemin
            if (!VerifPath(ChosenFolder, nameof(ChosenFolder)))
            {
                return(false);
            }


            // --- Mettre à jour les chemins
            InitializePaths();

            // --- Lancer la simulation

            #region AlterPath

            HeTrace.WriteLine("Altération des dossiers", 5);

            // foreach (var ecp in ExtPlatformPaths)
            foreach (C_PathsDouble ecp in PlatformPaths)
            {
                HeTrace.WriteLine($"\t[AlterPath] {ecp.Type}", level: 10);

                // Choix de filtrer que videos / games / manuals / music et ... ?
                string hardPath;

                // Games
                if (ecp.Type.Equals("Games", StringComparison.OrdinalIgnoreCase))
                {
                    hardPath = Path.Combine(_chosenFolder, GamesFName, SystemFolderName);
                }
                // Manual
                else if (ecp.Type.Equals("Manual", StringComparison.OrdinalIgnoreCase))
                {
                    hardPath = Path.Combine(_chosenFolder, ManualsFName, SystemFolderName);
                }
                // Music
                else if (ecp.Type.Equals("Music", StringComparison.OrdinalIgnoreCase))
                {
                    hardPath = Path.Combine(_chosenFolder, MusicsFName, SystemFolderName);
                }
                // Video
                else if (ecp.Type.Equals("Video", StringComparison.OrdinalIgnoreCase))
                {
                    hardPath = Path.Combine(_chosenFolder, VideosFName, SystemFolderName);
                }
                // Other type of video
                else if (ecp.Type.Equals("Theme Video", StringComparison.OrdinalIgnoreCase))
                {
                    hardPath = Path.Combine(_chosenFolder, VideosFName, SystemFolderName, "Theme");
                }
                // Images
                else
                {
                    hardPath = Path.Combine(_chosenFolder, ImagesFName, SystemFolderName, ecp.Type);
                }


                //string relatPath = Path.GetRelativePath(Global.LaunchBoxPath, hardPath);
                string relatPath = DxPath.To_Relative(Global.LaunchBoxRoot, hardPath);

                ecp.NewRelatPath = relatPath;
                ecp.NewHardPath  = hardPath;

                HeTrace.WriteLine($"\tCombinaison give: {hardPath}", 10);
                HeTrace.WriteLine($"\tRelat find give: {relatPath}", 10);
                // Analyse props n'a plus d'utilité
                // Generate info path n'a apparemment plus d'utilité.
                // Style FLP change le fond mais pas utile ici
                // SetMainWindow Pour la taille de la fenêtre, pas utile ici non plus
            }

            #endregion AlterPath

            HeTrace.WriteLine(">>> End of Simulation"); // Envnew

            return(true);
        }
Пример #9
0
        /// <summary>
        /// Format paths to seek the main and show him as hard and relative
        /// </summary>
        /// <param name="v"></param>
        internal void FormatMainPaths(string sep)
        {
            HeTrace.WriteLine("Format main paths", 5);
            // On détermine le path en selon l'emplacement de Launchbox
            if (String.IsNullOrEmpty(PlatformObject.Folder))
            {
                CHardLink  = Global.LaunchBoxRoot; // On récupère avec le core car ça correspond pas sinon
                CRelatLink = @".\";
                return;
            }

            // Détermination du chemin réel si c'est un chemin relatif
            string platformPath = null;

            if (PlatformObject.Folder.StartsWith('.') || PlatformObject.Folder.Substring(1, 2) != @":\")
            {
                //platformPath = Path.GetFullPath(PlatformObject.Folder, Global.LaunchBoxPath);
                platformPath = Path.GetFullPath(PlatformObject.Folder, Global.LaunchBoxRoot);
            }
            else
            {
                platformPath = PlatformObject.Folder;
            }

            #region Remplace FillInformation de l'ancienne version

            HeTrace.WriteLine($@"PlatformFolder: '{PlatformObject.Folder}'"); // Envnew
            HeTrace.WriteLine(@"Search main paths");                          // Envnew


            #region Recherche du dossier hard
            HeTrace.Write(@"--- Seek of HardLink: ");

            string[] foldersArr = platformPath.Split(sep);          // Sur windows le getfullpath a ramené le chemin avec des \

            // Ici une erreur peut se produire si on a un chemin de type "G:"
            CHardLink = String.Join(sep, foldersArr, 0, foldersArr.Length - 2);
            HeTrace.EndLine($"'{CHardLink}'"); // Envnew
            #endregion


            #region conversion en dur du lien vers le dossier actuel

            // Vérification que le path est sur le même chemin que l'application
            DriveInfo driveApp    = new DriveInfo(Global.LaunchBoxPath);
            DriveInfo driveFolder = new DriveInfo(platformPath);
            if (driveApp.Name.Equals(driveFolder.Name))
            {
                HeTrace.Write(@"--- Transformation HardLink RelatLink: ");
                CRelatLink = DxPath.To_Relative(Global.LaunchBoxRoot, CHardLink);
                //CRelatLink = Path.GetRelativePath(Global.LaunchBoxPath, CHardLink);
                HeTrace.WriteLine($"'{CRelatLink}'"); // Envnew
            }
            else
            {
                HeTrace.WriteLine(@"--- RelatLink impossible different drives letters "); // Envnew
            }


            //tmp = tmp.Replace($@"\{OldPlatformObject.Name}", "");

            //CRelatLink = tmp;
            //tmp = null;
            #endregion

            #endregion Remplace FillInformation de l'ancienne version
        }