/// <summary>
 /// A simple constructor that initializes the object with its dependencies.
 /// </summary>
 public VirtualConfigFixTask(List <string> p_lstConfigFilePath, ModManager p_mmgModManager, IVirtualModActivator p_vmaVirtualModActivator, IModProfile p_mprProfile)
 {
     ConfigFilePaths     = p_lstConfigFilePath;
     ModProfile          = p_mprProfile;
     ModManager          = p_mmgModManager;
     VirtualModActivator = p_vmaVirtualModActivator;
 }
Пример #2
0
        private void LoadProfile(IModProfile p_impModProfile)
        {
            //if ((p_impModProfile.ModList == null) || (p_impModProfile.ModFileList == null))
            ViewModel.ProfileManager.LoadProfileFileList(p_impModProfile);

            this.plwProfiles.LoadData(p_impModProfile.ModList, p_impModProfile.ModFileList);
        }
Пример #3
0
 /// <summary>
 /// Updates the profile.
 /// </summary>
 public void UpdateProfile(IModProfile p_impModProfile, byte[] p_bteIniEdits, byte[] p_bteLoadOrder, string[] p_strOptionalFiles)
 {
     UpdateCurrentProfileModCount();
     SaveProfile(p_impModProfile, null, p_bteIniEdits, p_bteLoadOrder, p_strOptionalFiles);
     m_tslProfiles.Remove(CurrentProfile);
     m_tslProfiles.Add(p_impModProfile);
     SaveConfig();
 }
Пример #4
0
 /// <summary>
 /// A simple constructor that initializes the object with its dependencies.
 /// </summary>
 /// <param name="p_ModManager">The current ModManager.</param>
 /// <param name="p_lstMods">The mod list.</param>
 /// <param name="p_intNewValue">The new category id.</param>
 public CheckOnlineProfileIntegrityTask(IModRepository p_mrRepository, IModProfile p_imProfile, IProfileManager p_pmProfileManager, Dictionary <string, string> p_dicMissingMod, string p_strGameModeID)
 {
     ModRepository   = p_mrRepository;
     ModProfile      = p_imProfile;
     MissingModsList = p_dicMissingMod;
     GameModeID      = p_strGameModeID;
     ProfileManager  = p_pmProfileManager;
 }
Пример #5
0
 /// <summary>
 /// Renames the profile.
 /// </summary>
 public void RenameProfile(IModProfile p_impModProfile, string p_strName)
 {
     m_tslProfiles.Remove(p_impModProfile);
     p_impModProfile.Name = p_strName;
     SaveProfile(p_impModProfile, null, null, null, null);
     m_tslProfiles.Add(p_impModProfile);
     SaveConfig();
 }
Пример #6
0
        /// <summary>
        /// Loads the selected profile files from the hd.
        /// </summary>
        public void LoadProfile(IModProfile p_impModProfile, out Dictionary <string, string> p_dicFileStream)
        {
            p_dicFileStream = new Dictionary <string, string>();
            string strLoadOrder = String.Empty;
            string strModList   = String.Empty;

            string strProfilePath = Path.Combine(m_strProfileManagerPath, p_impModProfile.Id);

            if (m_booUsesPlugin)
            {
                if (File.Exists(Path.Combine(strProfilePath, "loadorder.txt")))
                {
                    using (StreamReader srLoadOrder = new StreamReader(Path.Combine(strProfilePath, "loadorder.txt")))
                    {
                        strLoadOrder = srLoadOrder.ReadToEnd();
                        p_dicFileStream.Add("loadorder", strLoadOrder);
                    }
                }
            }

            if (File.Exists(Path.Combine(strProfilePath, "modlist.xml")))
            {
                using (StreamReader srModFiles = new StreamReader(Path.Combine(strProfilePath, "modlist.xml")))
                {
                    strModList = srModFiles.ReadToEnd();
                    p_dicFileStream.Add("modlist", strModList);
                }
            }

            if (File.Exists(Path.Combine(strProfilePath, "IniEdits.xml")))
            {
                using (StreamReader srModFiles = new StreamReader(Path.Combine(strProfilePath, "IniEdits.xml")))
                {
                    string strIniList = srModFiles.ReadToEnd();
                    p_dicFileStream.Add("iniEdits", strIniList);
                }
            }

            string strOptionalFolder = Path.Combine(strProfilePath, "Optional");

            if (Directory.Exists(strOptionalFolder))
            {
                string[] strFiles = Directory.GetFiles(strOptionalFolder);

                if ((strFiles != null) && (strFiles.Length > 0))
                {
                    string strOptionalFiles = String.Empty;
                    foreach (string strFile in strFiles)
                    {
                        strOptionalFiles += (strFile + "#");
                    }

                    p_dicFileStream.Add("optional", strOptionalFiles);
                }
            }

            m_strCurrentProfileId = p_impModProfile.Id;
        }
Пример #7
0
 /// <summary>
 /// A simple constructor that initializes the object with its dependencies.
 /// </summary>
 public WriteProfileTask(IModProfile modProfile, byte[] modList, byte[] iniList, byte[] loadOrder, string[] optionalFiles, string profileManagerPath)
 {
     _modProfile         = modProfile;
     _modList            = modList;
     _iniList            = iniList;
     _loadOrder          = loadOrder;
     _optionalFiles      = optionalFiles;
     _profileManagerPath = profileManagerPath;
 }
Пример #8
0
        /// <summary>
        /// Perform initial setup steps for the profile switch,
        /// installing and disabling mods when required.
        /// </summary>
        public IBackgroundTask ProfileSwitchSetup(ReadOnlyObservableList <IMod> modsToDeactivate, List <IMod> modsToInstall, IProfileManager profileManager,
                                                  IModProfile profileToInstall, IModProfile profileToSwitch, bool p_booFilesOnly, ConfirmActionMethod p_camConfirm, ConfirmItemOverwriteDelegate p_dlgOverwriteConfirmationDelegate)
        {
            ProfileSwitchSetupTask profileSwitchSetup = new ProfileSwitchSetupTask(modsToDeactivate, modsToInstall, profileManager, profileToInstall, profileToSwitch, InstallationLog, InstallerFactory, VirtualModActivator,
                                                                                   GameMode.GameModeEnvironmentInfo.InstallInfoDirectory, p_booFilesOnly, p_camConfirm, p_dlgOverwriteConfirmationDelegate);

            profileSwitchSetup.Update(p_camConfirm);
            return(profileSwitchSetup);
        }
Пример #9
0
 public ProfileSwitchToken(bool isSilent, IModProfile modProfile, List <IVirtualModLink> virtualLinks, List <string> scriptedMismatch, List <IVirtualModInfo> missingMods, Dictionary <string, string> profiles)
 {
     IsSilent             = isSilent;
     Profile              = modProfile;
     VirtualLinks         = virtualLinks;
     MissingMods          = missingMods;
     ScriptedMismatchList = scriptedMismatch;
     ProfileDictionary    = profiles;
 }
Пример #10
0
        /// <summary>
        /// Removes the profile from the profile manager.
        /// </summary>
        /// <param name="p_impModProfile">The profile to remove.</param>
        public void RemoveProfile(IModProfile p_impModProfile)
        {
            if (Directory.Exists(Path.Combine(m_strProfileManagerPath, p_impModProfile.Id)))
            {
                FileUtil.ForceDelete(Path.Combine(m_strProfileManagerPath, p_impModProfile.Id));
            }

            m_tslProfiles.Remove(p_impModProfile);
            SaveConfig();
        }
Пример #11
0
 public void SetCurrentProfile(IModProfile p_impProfile)
 {
     if (p_impProfile != null)
     {
         m_strCurrentProfileId = p_impProfile.Id;
     }
     else
     {
         m_strCurrentProfileId = null;
     }
 }
Пример #12
0
        public void ExportProfile(IModProfile p_impModProfile, string p_strPath)
        {
            string strProfilePath = Path.Combine(m_strProfileManagerPath, p_impModProfile.Id);

            if (File.Exists(p_strPath))
            {
                string strRandomPath = p_strPath + "_" + Path.GetRandomFileName();
                FileUtil.Move(p_strPath, strRandomPath, true);
            }
            ZipFile.CreateFromDirectory(strProfilePath, p_strPath);
        }
Пример #13
0
        public bool LoadProfileFileList(IModProfile p_impModProfile)
        {
            List <IVirtualModLink> lstModLinks;
            List <IVirtualModInfo> lstModList;
            string strPath    = Path.Combine(m_strProfileManagerPath, Path.Combine(p_impModProfile.Id, "modlist.xml"));
            bool   booSuccess = VirtualModActivator.LoadListOnDemand(strPath, out lstModLinks, out lstModList);

            p_impModProfile.UpdateLists(lstModLinks, lstModList);

            return(booSuccess);
        }
Пример #14
0
        private byte[] GetProfileBytes(IModProfile p_impModProfile)
        {
            XElement xelProfile = new XElement("profile",
                                               new XAttribute("profileId", p_impModProfile.Id),
                                               new XAttribute("profileName", p_impModProfile.Name),
                                               new XAttribute("isDefault", p_impModProfile.IsDefault ? "1" : "0"),
                                               new XElement("gameModeId",
                                                            new XText(p_impModProfile.GameModeId)),
                                               new XElement("modCount",
                                                            new XText(p_impModProfile.ModCount.ToString())));

            return(System.Text.Encoding.UTF8.GetBytes(xelProfile.ToString()));
        }
Пример #15
0
        /// <summary>
        /// Setup the ProfileView
        /// </summary>
        /// <param name="p_lvwList">The source list view.</param>
        /// <param name="p_cmgProfileManager">The mod Profile Manager.</param>
        public void Setup(ReadOnlyObservableList <IMod> p_rolManagedMods, IModRepository p_mmrModRepository, IProfileManager p_cmgProfileManager, ISettings p_Settings)
        {
            this.Tag = false;

            this.CellEditActivation = CellEditActivateMode.None;
            this.MultiSelect        = true;
            this.AllowDrop          = true;
            this.UseFiltering       = true;
            this.UseHyperlinks      = true;

            ProfileManager     = p_cmgProfileManager;
            m_mmrModRepository = p_mmrModRepository;
            m_rolManagedMods   = p_rolManagedMods;
            Settings           = p_Settings;

            // Setup menuStrip commands
            SetupContextMenu();

            // Setup Profile validator
            SetupProfileValidator();

            // Setup Profile sorter
            SetupProfileSorter();

            this.CheckBoxes           = false;
            this.UseSubItemCheckBoxes = false;

            this.FormatRow += delegate(object sender, FormatRowEventArgs e)
            {
                IModProfile modProfile = (IModProfile)e.Model;
                var         proProfile = ProfileManager.ModBackedProfiles.Where(x => string.Equals(x.Name, modProfile.Name, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
                if (proProfile == null)
                {
                    e.Item.ForeColor = Color.Gray;
                }
            };

            // Setup AspectGetter (IconListView cell parser)
            SetupColumnParser();

            // Setup the Drag&Drop functionality
            SetupDragAndDrop();

            // Setup ImageGetters
            SetupImageGetters();

            // Set control initialized
            this.Tag = true;

            ResetColumns();
        }
Пример #16
0
        /// <summary>
        /// Runs the managed updaters.
        /// </summary>
        /// <param name="p_ModManager">The Mod Manager.</param>
        /// <param name="p_lstMods">The list of mods to update.</param>
        /// <param name="p_intNewValue">The new category id value.</param>
        /// <param name="p_camConfirm">The delegate to call to confirm an action.</param>
        /// <returns>The background task that will run the updaters.</returns>
        public IBackgroundTask SwitchProfile(IModProfile p_impProfile, ModManager p_ModManager, IList <IVirtualModLink> p_lstNewLinks, IList <IVirtualModLink> p_lstRemoveLinks, bool p_booStartupMigration, ConfirmActionMethod p_camConfirm)
        {
            ProfileActivationTask patProfileSwitch = new ProfileActivationTask(p_ModManager, p_lstNewLinks, p_lstRemoveLinks, p_booStartupMigration);

            if (VirtualModActivator.GameMode.LoadOrderManager != null)
            {
                VirtualModActivator.GameMode.LoadOrderManager.MonitorExternalTask(patProfileSwitch);
            }
            else
            {
                patProfileSwitch.Update(p_camConfirm);
            }
            return(patProfileSwitch);
        }
Пример #17
0
 public void SetDefaultProfile(IModProfile p_impProfile)
 {
     foreach (IModProfile Profile in m_tslProfiles)
     {
         if (Profile == p_impProfile)
         {
             Profile.IsDefault = true;
         }
         else
         {
             Profile.IsDefault = false;
         }
     }
 }
Пример #18
0
        public bool RestoreBackupProfile()
        {
            IModProfile impImported = ImportProfile(Path.Combine(VirtualModActivator.VirtualPath, "Backup_DONOTDELETE.zip"));

            if (impImported != null)
            {
                m_strCurrentProfileId = impImported.Id;
                SetDefaultProfile(impImported);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #19
0
        /// <summary>
        /// Updates the profile file.
        /// </summary>
        public void UpdateProfileLoadOrder(IModProfile p_impModProfile, byte[] p_bteLoadOrder)
        {
            if (p_impModProfile != null)
            {
                string strProfilePath = Path.Combine(m_strProfileManagerPath, p_impModProfile.Id);

                if (!Directory.Exists(strProfilePath))
                {
                    Directory.CreateDirectory(strProfilePath);
                }

                if ((m_booUsesPlugin) && (p_bteLoadOrder != null) && (p_bteLoadOrder.Length > 0))
                {
                    File.WriteAllBytes(Path.Combine(strProfilePath, "loadorder.txt"), p_bteLoadOrder);
                }
            }
        }
Пример #20
0
 /// <summary>
 /// A simple constructor that initializes the object with its dependencies.
 /// </summary>
 public ProfileSwitchSetupTask(ReadOnlyObservableList <IMod> modsToDeactivate, List <IMod> modsToInstall, IProfileManager profileManager, IModProfile profileToInstall,
                               IModProfile profileToSwitch, IInstallLog installLog, ModInstallerFactory modInstallerFactory, VirtualModActivator virtualModActivator, string scriptedLogPath, bool filesOnly,
                               ConfirmActionMethod confirmActionMethod, ConfirmItemOverwriteDelegate overwriteConfirmationDelegate)
 {
     _installLog                    = installLog;
     _modInstallerFactory           = modInstallerFactory;
     _modsToDeactivate              = modsToDeactivate;
     VirtualModActivator            = virtualModActivator;
     _logPath                       = scriptedLogPath;
     _filesOnly                     = filesOnly;
     _profileToInstall              = profileToInstall;
     _profileToSwitch               = profileToSwitch;
     _profileManager                = profileManager;
     _modsToInstall                 = modsToInstall;
     _confirmMethod                 = confirmActionMethod;
     _overwriteConfirmationDelegate = overwriteConfirmationDelegate;
 }
Пример #21
0
        /// <summary>
        /// Updates the programme.
        /// </summary>
        /// <param name="p_booIsAutoCheck">Whether the check is automatic or user requested.</param>
        public void ProfilePluginImport()
        {
            IModProfile impCurrentProfile = ProfileManager.CurrentProfile;

            if (impCurrentProfile != null)
            {
                if ((impCurrentProfile.LoadOrder != null) && (impCurrentProfile.LoadOrder.Count > 0))
                {
                    PluginManagerVM.ImportLoadOrderFromDictionary(impCurrentProfile.LoadOrder);
                }
                else
                {
                    Dictionary <string, string> dicProfile;
                    ProfileManager.LoadProfile(impCurrentProfile, out dicProfile);
                    if ((dicProfile != null) && (dicProfile.Count > 0) && (dicProfile.ContainsKey("loadorder")))
                    {
                        PluginManagerVM.ImportLoadOrderFromString(dicProfile["loadorder"]);
                    }
                }
            }
        }
Пример #22
0
        public string IsScriptedLogPresent(string p_strModFile, IModProfile p_impProfile)
        {
            if (p_impProfile == null)
            {
                return(null);
            }

            string CurrentProfileScriptedLogPath = GetCurrentProfileScriptedLogPath(p_impProfile);

            if (Directory.Exists(CurrentProfileScriptedLogPath))
            {
                string strModLog = Path.GetFileNameWithoutExtension(p_strModFile);
                strModLog += ".xml";
                strModLog  = Path.Combine(CurrentProfileScriptedLogPath, strModLog);

                if (File.Exists(strModLog))
                {
                    return(strModLog);
                }
            }

            return(null);
        }
Пример #23
0
 /// <summary>
 /// A simple constructor that initializes the object with its dependencies.
 /// </summary>
 public CheckOnlineProfileIntegrityTask(IModRepository p_mrRepository, IModProfile p_imProfile, IProfileManager p_pmProfileManager)
 {
     ModRepository  = p_mrRepository;
     ModProfile     = p_imProfile;
     ProfileManager = p_pmProfileManager;
 }
 public IBackgroundTask FixConfigFiles(List<string> p_lstFiles, IModProfile p_mprProfile, ConfirmActionMethod p_camConfirm)
 {
     throw new NotImplementedException();
 }
Пример #25
0
        /// <summary>
        /// The method that is called to start the backgound task.
        /// </summary>
        /// <param name="args">Arguments to for the task execution.</param>
        /// <returns>Always <c>null</c>.</returns>
        protected override object DoWork(object[] args)
        {
            OverallMessage          = "Backuping Nexus Mod Manager...";
            OverallProgress         = 0;
            OverallProgressStepSize = 1;
            ShowItemProgress        = true;
            OverallProgressMaximum  = 7;
            ItemProgressStepSize    = 1;
            FileCounter             = 0;

            OverallMessage = "Creating the directories.";
            StepOverallProgress();

            DriveInfo drive = new DriveInfo(EnvironmentInfo.TemporaryPath);

            drive = new DriveInfo(drive.Name);

            if (drive.AvailableFreeSpace > (TotalFileSize))
            {
                string BackupDirectory = Path.Combine(EnvironmentInfo.TemporaryPath, "NMMBACKUP");
                if (Directory.Exists(BackupDirectory))
                {
                    FileUtil.ForceDelete(BackupDirectory);
                }

                bool PathLimit = CheckPathLimit(BackupDirectory);
                if (PathLimit)
                {
                    string NewBackupDirectory = Path.Combine(Directory.GetDirectoryRoot(BackupDirectory), "NMMTemp");
                    string WarningMessage     = "Warning: NMM won't be able to use the default 'temp' folder for this operation, this will cause some file paths to reach the OS limit of 260 characters and prevent files to be copied." + Environment.NewLine + Environment.NewLine;
                    WarningMessage = WarningMessage + "Just for this backup NMM will use a " + NewBackupDirectory + " folder. This folder will be removed after the backup completes.";

                    MessageBox.Show(WarningMessage, "Create Backup", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    BackupDirectory = NewBackupDirectory;
                }

                string strPathToCreate = BackupDirectory;
                Directory.CreateDirectory(strPathToCreate);
                strPathToCreate = Path.Combine(BackupDirectory, Path.GetFileName(ModManager.GameMode.PluginDirectory));
                Directory.CreateDirectory(strPathToCreate);
                strPathToCreate = Path.Combine(BackupDirectory, "VIRTUAL INSTALL");
                Directory.CreateDirectory(strPathToCreate);
                strPathToCreate = Path.Combine(BackupDirectory, "PROFILE");
                Directory.CreateDirectory(strPathToCreate);

                int    i   = 1;
                string dir = string.Empty;

                OverallProgressMaximum = BackupManager.lstBaseGameFiles.Count();
                if ((BackupManager.checkList.Contains(0)) && (BackupManager.lstBaseGameFiles.Count > 0))
                {
                    i = 1;
                    foreach (BackupInfo bkInfo in BackupManager.lstBaseGameFiles)
                    {
                        if (i < BackupManager.lstBaseGameFiles.Count())
                        {
                            ItemMessage = bkInfo.VirtualModPath;
                            StepItemProgress();
                        }

                        OverallMessage = string.Format("Copying GAME BASE files...{0}/{1}", i++, BackupManager.lstBaseGameFiles.Count());
                        StepOverallProgress();
                        dir = Path.GetDirectoryName(Path.Combine(bkInfo.ModID, bkInfo.VirtualModPath));
                        if (!string.IsNullOrEmpty(dir))
                        {
                            Directory.CreateDirectory(Path.Combine(BackupDirectory, bkInfo.Directory, dir));
                        }

                        try
                        {
                            File.Copy(bkInfo.RealModPath, Path.Combine(BackupDirectory, bkInfo.Directory, bkInfo.VirtualModPath), true);
                        }
                        catch (FileNotFoundException)
                        { }
                    }

                    TotalFiles += BackupManager.lstBaseGameFiles.Count;
                }

                if ((BackupManager.checkList.Contains(1)) && (BackupManager.lstInstalledModFiles.Count > 0))
                {
                    OverallProgressMaximum = BackupManager.lstInstalledModFiles.Count();
                    foreach (BackupInfo bkInfo in BackupManager.lstInstalledModFiles)
                    {
                        OverallMessage = string.Format("Copying MODS INSTALLATION files...{0}/{1}", i++, BackupManager.lstInstalledModFiles.Count());
                        StepOverallProgress();
                        dir = Path.GetDirectoryName(Path.Combine(bkInfo.ModID, bkInfo.VirtualModPath));
                        if (!string.IsNullOrEmpty(dir))
                        {
                            Directory.CreateDirectory(Path.Combine(BackupDirectory, bkInfo.Directory, dir));
                        }

                        try
                        {
                            File.Copy(bkInfo.RealModPath, Path.Combine(BackupDirectory, bkInfo.Directory, bkInfo.ModID, bkInfo.VirtualModPath), true);
                        }
                        catch (FileNotFoundException)
                        { }

                        if (ItemProgress < ItemProgressMaximum)
                        {
                            ItemMessage = bkInfo.RealModPath;
                            StepItemProgress();
                        }
                    }

                    OverallProgressMaximum = BackupManager.lstInstalledNMMLINKFiles.Count();
                    foreach (BackupInfo bkInfo in BackupManager.lstInstalledNMMLINKFiles)
                    {
                        OverallMessage = string.Format("Copying NMMLINK files...{0}/{1}", i++, BackupManager.lstInstalledNMMLINKFiles.Count());
                        StepOverallProgress();
                        dir = Path.GetDirectoryName(Path.Combine("NMMLINK", bkInfo.VirtualModPath));
                        if (!string.IsNullOrEmpty(dir))
                        {
                            Directory.CreateDirectory(Path.Combine(BackupDirectory, dir));
                        }

                        try
                        {
                            File.Copy(bkInfo.RealModPath, Path.Combine(BackupDirectory, bkInfo.Directory, bkInfo.ModID, bkInfo.VirtualModPath), true);
                        }
                        catch (FileNotFoundException)
                        { }

                        if (ItemProgress < ItemProgressMaximum)
                        {
                            ItemMessage = bkInfo.RealModPath;
                            StepItemProgress();
                        }
                    }

                    TotalFiles += BackupManager.lstInstalledModFiles.Count + BackupManager.lstInstalledNMMLINKFiles.Count;
                }

                OverallProgressMaximum = BackupManager.lstLooseFiles.Count();
                if ((BackupManager.checkList.Contains(2)) && (BackupManager.lstLooseFiles.Count > 0))
                {
                    i = 1;
                    foreach (BackupInfo bkInfo in BackupManager.lstLooseFiles)
                    {
                        if (i < BackupManager.lstLooseFiles.Count())
                        {
                            ItemMessage = bkInfo.VirtualModPath;
                            StepItemProgress();
                        }

                        OverallMessage = string.Format("Copying " + Path.GetFileName(ModManager.GameMode.PluginDirectory) + " files...{0}/{1}", i++, BackupManager.lstLooseFiles.Count());
                        StepOverallProgress();
                        dir = Path.GetDirectoryName(Path.Combine(bkInfo.ModID, bkInfo.VirtualModPath));
                        if (!string.IsNullOrEmpty(dir))
                        {
                            Directory.CreateDirectory(Path.Combine(BackupDirectory, bkInfo.Directory, dir));
                        }

                        try
                        {
                            File.Copy(bkInfo.RealModPath, Path.Combine(BackupDirectory, bkInfo.Directory, bkInfo.VirtualModPath), true);
                        }
                        catch (FileNotFoundException)
                        { }
                    }

                    TotalFiles += BackupManager.lstLooseFiles.Count;
                }

                OverallProgressMaximum = BackupManager.lstModArchives.Count();
                if ((BackupManager.checkList.Contains(3)) && (BackupManager.lstModArchives.Count > 0))
                {
                    i = 1;
                    foreach (BackupInfo bkInfo in BackupManager.lstModArchives)
                    {
                        if (i < BackupManager.lstModArchives.Count())
                        {
                            ItemMessage = bkInfo.VirtualModPath;
                            StepItemProgress();
                        }

                        OverallMessage = string.Format("Copying MOD ARCHIVES...{0}/{1}", i++, BackupManager.lstModArchives.Count());
                        StepOverallProgress();
                        dir = Path.GetDirectoryName(Path.Combine(bkInfo.Directory, bkInfo.VirtualModPath));
                        if (!string.IsNullOrEmpty(dir))
                        {
                            Directory.CreateDirectory(Path.Combine(BackupDirectory, dir));
                        }

                        try
                        {
                            File.Copy(bkInfo.RealModPath, Path.Combine(BackupDirectory, bkInfo.Directory, bkInfo.VirtualModPath), true);
                        }
                        catch (FileNotFoundException)
                        { }
                    }

                    TotalFiles += BackupManager.lstModArchives.Count;
                }

                byte[] bteLoadOrder = null;
                if (ModManager.GameMode.UsesPlugins)
                {
                    bteLoadOrder = PluginManagerVM.ExportLoadOrder();
                }

                string[] strOptionalFiles = null;

                if (ModManager.GameMode.RequiresOptionalFilesCheckOnProfileSwitch)
                {
                    if ((PluginManager != null) && ((PluginManager.ActivePlugins != null) && (PluginManager.ActivePlugins.Count > 0)))
                    {
                        strOptionalFiles = ModManager.GameMode.GetOptionalFilesList(PluginManager.ActivePlugins.Select(x => x.Filename).ToArray());
                    }
                }

                IModProfile mprModProfile = AddProfile(null, null, bteLoadOrder, ModManager.GameMode.ModeId, -1, strOptionalFiles, Path.Combine(BackupDirectory, "PROFILE"));

                string gameModeName = PurgeIllegalWindowsCharacters(ModManager.GameMode.Name);

                Directory.CreateDirectory(Path.Combine(BackupDirectory, gameModeName));

                string installLog = Path.Combine(ModManager.GameMode.GameModeEnvironmentInfo.InstallInfoDirectory, "InstallLog.xml");

                if (File.Exists(installLog))
                {
                    File.Copy(installLog, Path.Combine(BackupDirectory, "InstallLog.xml"));
                }

                string startPath = BackupDirectory;
                string zipPath   = Path.Combine(EnvironmentInfo.ApplicationPersonalDataFolderPath, "NMM_BACKUP.zip");

                if (File.Exists(zipPath))
                {
                    File.Delete(zipPath);
                }

                OverallMessage = "Zipping the Archive...";
                StepOverallProgress();

                string strDateTimeStamp = DateTime.Now.ToString(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.SortableDateTimePattern);
                strDateTimeStamp = strDateTimeStamp.Replace(":", "");
                strDateTimeStamp = strDateTimeStamp.Replace("-", "");
                strDateTimeStamp = strDateTimeStamp.Replace("T", "-");

                SevenZipCompressor szcCompressor = new SevenZipCompressor(startPath);
                szcCompressor.CompressionLevel        = SevenZip.CompressionLevel.Normal;
                szcCompressor.ArchiveFormat           = OutArchiveFormat.Zip;
                szcCompressor.FastCompression         = false;
                szcCompressor.CompressionMethod       = CompressionMethod.Default;
                szcCompressor.CompressionMode         = SevenZip.CompressionMode.Create;
                szcCompressor.FileCompressionStarted += new EventHandler <FileNameEventArgs>(compressor_FileCompressionStarted);

                szcCompressor.CompressDirectory(startPath, Path.Combine(SelectedPath, ModManager.GameMode.ModeId + "_NMM_BACKUP_" + strDateTimeStamp + ".zip"));

                OverallMessage = "Deleting the leftovers.";
                StepOverallProgress();
                FileUtil.ForceDelete(BackupDirectory);
            }
            else
            {
                return(string.Format("Not enough space on drive: {0} - ({1}Mb required)", drive.Name, ((TotalFileSize / 1024) / 1024).ToString()));
            }

            return(null);
        }
 /// <summary>
 /// A simple constructor that initializes the object with its dependencies.
 /// </summary>
 /// <param name="p_ModManager">The current ModManager.</param>
 /// <param name="p_lstMods">The mod list.</param>
 /// <param name="p_intNewValue">The new category id.</param>
 public ToggleSharingProfileTask(IModRepository p_mrRepository, ProfileManager p_pmProfileManager, IModProfile p_imProfile)
 {
     ModRepository  = p_mrRepository;
     ProfileManager = p_pmProfileManager;
     ModProfile     = p_imProfile;
 }
 /// <summary>
 /// A simple constructor that initializes the object with its dependencies.
 /// </summary>
 /// <param name="p_ModManager">The current ModManager.</param>
 /// <param name="p_lstMods">The mod list.</param>
 /// <param name="p_intNewValue">The new category id.</param>
 public RenameBackedProfileTask(IModRepository p_mrRepository, IModProfile p_impProfile, string p_strNewName)
 {
     ModRepository = p_mrRepository;
     ModProfile    = p_impProfile;
     NewName       = p_strNewName;
 }
 /// <summary>
 /// A simple constructor that initializes the object with its dependencies.
 /// </summary>
 /// <param name="p_ModManager">The current ModManager.</param>
 /// <param name="p_lstMods">The mod list.</param>
 /// <param name="p_intNewValue">The new category id.</param>
 public RemoveBackedProfileTask(IModRepository p_mrRepository, IModProfile p_impProfile, ProfileManager p_pmProfileManager)
 {
     ModRepository  = p_mrRepository;
     ModProfile     = p_impProfile;
     ProfileManager = p_pmProfileManager;
 }
Пример #29
0
        public List <string> CheckScriptedInstallersIntegrity(IModProfile p_impFrom, IModProfile p_impTo)
        {
            List <string> lstConflicts = new List <string>();
            string        strToPath    = GetCurrentProfileScriptedLogPath(p_impTo);

            if (!Directory.Exists(strToPath))
            {
                return(null);
            }

            if (p_impFrom == null)
            {
                List <string> lstTo = new List <string>();
                lstTo = Directory.GetFiles(strToPath, "*.xml", SearchOption.TopDirectoryOnly).ToList();
                if ((lstTo != null) && (lstTo.Count > 0))
                {
                    lstTo = lstTo.Select(x => Path.GetFileName(x)).ToList();

                    foreach (string File in lstTo)
                    {
                        IVirtualModInfo modMod = VirtualModActivator.VirtualMods.Find(x => Path.GetFileNameWithoutExtension(x.ModFileName).Equals(Path.GetFileNameWithoutExtension(File), StringComparison.CurrentCultureIgnoreCase));
                        if (modMod != null)
                        {
                            lstConflicts.Add(Path.GetFileName(modMod.ModFileName));
                        }
                    }
                }
            }
            else
            {
                string strFromPath = GetCurrentProfileScriptedLogPath(p_impFrom);
                if (!Directory.Exists(strFromPath))
                {
                    return(null);
                }

                List <string> lstFrom      = new List <string>();
                List <string> lstTo        = new List <string>();
                List <string> lstCommon    = new List <string>();
                Int32         intConflicts = 0;

                try
                {
                    lstFrom = Directory.GetFiles(strFromPath, "*.xml", SearchOption.TopDirectoryOnly).ToList();
                    lstTo   = Directory.GetFiles(strToPath, "*.xml", SearchOption.TopDirectoryOnly).ToList();

                    if ((lstFrom != null) && (lstFrom.Count > 0))
                    {
                        lstFrom = lstFrom.Select(x => Path.GetFileName(x)).ToList();
                    }
                    else
                    {
                        return(lstConflicts);
                    }

                    if ((lstTo != null) && (lstTo.Count > 0))
                    {
                        lstTo = lstTo.Select(x => Path.GetFileName(x)).ToList();
                    }
                    else
                    {
                        return(lstConflicts);
                    }

                    lstCommon = lstFrom.Intersect(lstTo, StringComparer.CurrentCultureIgnoreCase).ToList();

                    foreach (string File in lstCommon)
                    {
                        intConflicts = 0;
                        List <KeyValuePair <string, string> > dicFrom = LoadXMLModFilesToInstall(Path.Combine(strFromPath, File));
                        List <KeyValuePair <string, string> > dicTo   = LoadXMLModFilesToInstall(Path.Combine(strToPath, File));

                        intConflicts += dicFrom.Where(x => !dicTo.Contains(x, StringComparer.CurrentCultureIgnoreCase)).Count();
                        if (intConflicts <= 0)
                        {
                            intConflicts += dicTo.Where(x => !dicFrom.Contains(x, StringComparer.CurrentCultureIgnoreCase)).Count();
                        }

                        if (intConflicts > 0)
                        {
                            IVirtualModInfo modMod = VirtualModActivator.VirtualMods.Find(x => Path.GetFileNameWithoutExtension(x.ModFileName).Equals(Path.GetFileNameWithoutExtension(File), StringComparison.CurrentCultureIgnoreCase));
                            if (modMod != null)
                            {
                                lstConflicts.Add(Path.GetFileName(modMod.ModFileName));
                            }
                        }
                    }
                }
                catch
                { }
            }

            return(lstConflicts);
        }
Пример #30
0
        /// <summary>
        /// Updates the profile file.
        /// </summary>
        public void SaveProfile(IModProfile p_impModProfile, byte[] p_bteModList, byte[] p_bteIniList, byte[] p_bteLoadOrder, string[] p_strOptionalFiles)
        {
            if (p_impModProfile != null)
            {
                string strProfilePath = Path.Combine(m_strProfileManagerPath, p_impModProfile.Id);

                if (!Directory.Exists(strProfilePath))
                {
                    Directory.CreateDirectory(strProfilePath);
                }

                if ((m_booUsesPlugin) && (p_bteLoadOrder != null) && (p_bteLoadOrder.Length > 0))
                {
                    File.WriteAllBytes(Path.Combine(strProfilePath, "loadorder.txt"), p_bteLoadOrder);
                }

                if ((p_bteModList != null) && (p_bteModList.Length > 0))
                {
                    File.WriteAllBytes(Path.Combine(strProfilePath, "modlist.xml"), p_bteModList);
                }
                else if (VirtualModActivator.VirtualLinks != null)
                {
                    if (VirtualModActivator.ModCount > 0)
                    {
                        VirtualModActivator.SaveModList(Path.Combine(strProfilePath, "modlist.xml"));
                    }
                    else
                    {
                        FileUtil.ForceDelete(Path.Combine(strProfilePath, "modlist.xml"));
                    }
                }

                if ((p_bteIniList != null) && (p_bteIniList.Length > 0))
                {
                    File.WriteAllBytes(Path.Combine(strProfilePath, "IniEdits.xml"), p_bteIniList);
                }

                File.WriteAllBytes(Path.Combine(strProfilePath, "profile.xml"), GetProfileBytes(p_impModProfile));

                string strOptionalFolder = Path.Combine(strProfilePath, "Optional");

                if (!(p_strOptionalFiles == null))
                {
                    if (Directory.Exists(strOptionalFolder))
                    {
                        string[] strFiles = Directory.GetFiles(strOptionalFolder);

                        foreach (string file in strFiles)
                        {
                            lock (m_objLock)
                                FileUtil.ForceDelete(file);
                        }
                    }

                    if ((p_strOptionalFiles != null) && (p_strOptionalFiles.Length > 0))
                    {
                        lock (m_objLock)
                            if (!Directory.Exists(strOptionalFolder))
                            {
                                Directory.CreateDirectory(strOptionalFolder);
                            }

                        foreach (string strFile in p_strOptionalFiles)
                        {
                            lock (m_objLock)
                                if (File.Exists(strFile))
                                {
                                    File.Copy(strFile, Path.Combine(strOptionalFolder, Path.GetFileName(strFile)), true);
                                }
                        }
                    }
                }
            }
        }
Пример #31
0
 private string GetCurrentProfileScriptedLogPath(IModProfile p_impProfile)
 {
     return(Path.Combine(m_strProfileManagerPath, p_impProfile.Id, "Scripted"));
 }