/// <summary>
 /// If valid the current plugin file will be set as active.
 /// </summary>
 protected void ActivatePlugin(string p_strPlugin)
 {
     if (FileInstaller.PluginCheck(p_strPlugin, false))
     {
         if (PluginManager.IsActivatiblePluginFile(p_strPlugin))
         {
             PluginManager.ActivatePlugin(p_strPlugin);
         }
     }
 }
        private static bool InstallFile(WebClient webclient, string executableName, string baseSearchingDirectory, string fileWebsite)
        {
            bool skip = RequestDownload(executableName, baseSearchingDirectory);

            if (!skip)
            {
                FileDownloader downloader   = new FileDownloader();
                string         tempLocation = downloader.DownloadFile(webclient, fileWebsite);
                FileInstaller.Install(tempLocation);
                Directory.Delete(Path.GetDirectoryName(tempLocation), true);
                return(true);
            }
            return(false);
        }
Esempio n. 3
0
        /// <summary>
        /// The method that is called to start the backgound task.
        /// </summary>
        /// <remarks>
        /// This method installs all of the files in the <see cref="IMod"/> being installed.
        /// </remarks>
        /// <param name="p_objArgs">Arguments to for the task execution.</param>
        /// <returns>A return value.</returns>
        protected override object DoWork(object[] p_objArgs)
        {
            char[]        chrDirectorySeperators = new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar };
            bool          booSecondaryInstall    = false;
            List <string> lstFiles = Mod.GetFileList();

            OverallProgressMaximum = lstFiles.Count;

            if (GameMode.RequiresModFileMerge)
            {
                GameMode.ModFileMerge(ActiveMods, Mod, false);
            }

            if (GameMode.HasSecondaryInstallPath)
            {
                booSecondaryInstall = GameMode.CheckSecondaryInstall(Mod);
            }

            foreach (string strFile in lstFiles)
            {
                if (Status == TaskStatus.Cancelling)
                {
                    return(false);
                }
                string strFixedPath = GameMode.GetModFormatAdjustedPath(Mod.Format, strFile, Mod);

                if (!string.IsNullOrEmpty(strFixedPath))
                {
                    if (!(GameMode.RequiresModFileMerge && (Path.GetFileName(strFile) == GameMode.MergedFileName)))
                    {
                        if (!(SkipReadme && Readme.IsValidExtension(Path.GetExtension(strFile).ToLower()) && (Path.GetDirectoryName(strFixedPath) == Path.GetFileName(GameMode.PluginDirectory))))
                        {
                            if (FileInstaller.InstallFileFromMod(strFile, strFixedPath, booSecondaryInstall))
                            {
                                if ((GameMode.UsesPlugins) && (PluginManager.IsActivatiblePluginFile(strFixedPath)))
                                {
                                    PluginManager.ActivatePlugin(strFixedPath);
                                }
                            }
                        }
                    }
                }
                StepOverallProgress();
            }
            return(true);
        }
        /// <summary>
        /// The method that is called to start the backgound task.
        /// </summary>
        /// <remarks>
        /// This method installs all of the files in the <see cref="IMod"/> being installed.
        /// </remarks>
        /// <param name="args">Arguments to for the task execution.</param>
        /// <returns>A return value.</returns>
        protected override object DoWork(object[] args)
        {
            IModLinkInstaller ModLinkInstaller = VirtualModActivator.GetModLinkInstaller();

            char[] chrDirectorySeperators = new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar };
            List <KeyValuePair <string, string> > lstFiles       = (FilesToInstall == null) ? Mod.GetFileList().Select(x => new KeyValuePair <string, string>(x, null)).ToList() : FilesToInstall;
            List <KeyValuePair <string, string> > lstFilesToLink = new List <KeyValuePair <string, string> >();

            OverallProgressMaximum = lstFiles.Count * 2;

            if (GameMode.RequiresSpecialFileInstallation && GameMode.IsSpecialFile(Mod.GetFileList()))
            {
                lstFiles = GameMode.SpecialFileInstall(Mod).Select(x => new KeyValuePair <string, string>(x, null)).ToList();
            }

            if (GameMode.RequiresModFileMerge)
            {
                GameMode.ModFileMerge(ActiveMods, Mod, false);
            }

            foreach (KeyValuePair <string, string> File in lstFiles)
            {
                string strFileTo = File.Value;
                if (string.IsNullOrWhiteSpace(strFileTo))
                {
                    strFileTo = File.Key;
                }


                if (Status == TaskStatus.Cancelling)
                {
                    return(false);
                }
                string strFixedPath = GameMode.GetModFormatAdjustedPath(Mod.Format, strFileTo, Mod, false);
                if (string.IsNullOrEmpty(strFixedPath))
                {
                    continue;
                }

                string strModFilenamePath   = Path.Combine(VirtualModActivator.VirtualPath, Path.GetFileNameWithoutExtension(Mod.Filename), GameMode.GetModFormatAdjustedPath(Mod.Format, strFileTo, true));
                string strModDownloadIDPath = (string.IsNullOrWhiteSpace(Mod.DownloadId) || (Mod.DownloadId.Length <= 1) || Mod.DownloadId.Equals("-1", StringComparison.OrdinalIgnoreCase)) ? string.Empty : Path.Combine(VirtualModActivator.VirtualPath, Mod.DownloadId, GameMode.GetModFormatAdjustedPath(Mod.Format, strFileTo, true));
                string strVirtualPath       = strModFilenamePath;

                if (!string.IsNullOrWhiteSpace(strModDownloadIDPath))
                {
                    strVirtualPath = strModDownloadIDPath;
                }

                string strLinkPath = string.Empty;
                if (VirtualModActivator.MultiHDMode)
                {
                    string strModFilenameLink   = Path.Combine(VirtualModActivator.HDLinkFolder, Path.GetFileNameWithoutExtension(Mod.Filename), GameMode.GetModFormatAdjustedPath(Mod.Format, strFileTo, true));
                    string strModDownloadIDLink = (string.IsNullOrWhiteSpace(Mod.DownloadId) || (Mod.DownloadId.Length <= 1) || Mod.DownloadId.Equals("-1", StringComparison.OrdinalIgnoreCase)) ? string.Empty : Path.Combine(VirtualModActivator.HDLinkFolder, Mod.DownloadId, GameMode.GetModFormatAdjustedPath(Mod.Format, strFileTo, true));
                    strLinkPath = strModFilenameLink;

                    if (!string.IsNullOrWhiteSpace(strModDownloadIDLink))
                    {
                        strLinkPath = strModDownloadIDLink;
                    }
                }

                string strFileType = Path.GetExtension(File.Key);
                if (!strFileType.StartsWith("."))
                {
                    strFileType = "." + strFileType;
                }
                bool booHardLinkFile = (VirtualModActivator.MultiHDMode && (GameMode.HardlinkRequiredFilesType(File.Key) || strFileType.Equals(".exe", StringComparison.InvariantCultureIgnoreCase) || strFileType.Equals(".jar", StringComparison.InvariantCultureIgnoreCase)));

                if (!string.IsNullOrEmpty(strFixedPath))
                {
                    if (!(GameMode.RequiresModFileMerge && (Path.GetFileName(File.Key) == GameMode.MergedFileName)))
                    {
                        if (!(SkipReadme && Readme.IsValidExtension(Path.GetExtension(File.Key).ToLower()) && Path.GetDirectoryName(strFixedPath).Equals(Path.GetFileName(GameMode.PluginDirectory), StringComparison.CurrentCultureIgnoreCase)))
                        {
                            FileInstaller.InstallFileFromMod(File.Key, ((booHardLinkFile) ? strLinkPath : strVirtualPath));
                            lstFilesToLink.Add(new KeyValuePair <string, string>(strFileTo, (booHardLinkFile) ? strLinkPath : strVirtualPath));
                        }
                    }
                }
                StepOverallProgress();
            }

            if ((lstFiles.Count > 0) && (lstFilesToLink.Count <= 0))
            {
                throw new InvalidDataException(string.Format("This mod does not have the correct file structure for a {0} mod that NMM can use. It will not work with NMM.", GameMode.Name));
            }

            foreach (KeyValuePair <string, string> strLink in lstFilesToLink)
            {
                if (!VirtualModActivator.DisableLinkCreation)
                {
                    string strFileLink = ModLinkInstaller.AddFileLink(Mod, strLink.Key, strLink.Value, false);

                    if (!string.IsNullOrEmpty(strFileLink))
                    {
                        ActivatePlugin(strFileLink);
                    }
                }
                StepOverallProgress();
            }

            VirtualModActivator.SaveList();
            return(true);
        }
		/// <summary>
		/// 正在回滚文件
		/// </summary>
		/// <param name="e"></param>
		protected virtual void OnRollbackFile(FileInstaller.InstallFileEventArgs e)
		{

		}
		/// <summary>
		/// 正在删除文件
		/// </summary>
		/// <param name="e"></param>
		protected virtual void OnRemoveFile(FileInstaller.InstallFileEventArgs e)
		{
		}