/// <summary> /// Recursively copies all files and folders from one location to another. /// </summary> /// <param name="p_ilfFile">The folder to install.</param> /// <returns><c>false</c> if the user cancelled the install; /// <c>true</c> otherwise.</returns> protected bool InstallFolderFromMod(InstallableFile p_ilfFile) { List <string> lstModFiles = Mod.GetFileList(p_ilfFile.Source, true); ItemProgress = 0; ItemProgressMaximum = lstModFiles.Count; String strFrom = p_ilfFile.Source.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar).ToLowerInvariant(); if (!strFrom.EndsWith(Path.DirectorySeparatorChar.ToString())) { strFrom += Path.DirectorySeparatorChar; } String strTo = p_ilfFile.Destination.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); if ((strTo.Length > 0) && (!strTo.EndsWith(Path.DirectorySeparatorChar.ToString()))) { strTo += Path.DirectorySeparatorChar; } String strMODFile = null; for (Int32 i = 0; i < lstModFiles.Count; i++) { if (Status == TaskStatus.Cancelling) { return(false); } strMODFile = lstModFiles[i]; string strNewFileName = strMODFile.Substring(strFrom.Length, strMODFile.Length - strFrom.Length); if (strTo.Length > 0) { strNewFileName = Path.Combine(strTo, strNewFileName); } //Installers.FileInstaller.InstallFileFromMod(strMODFile, GameMode.GetModFormatAdjustedPath(Mod.Format, Path.Combine(strTo, strNewFileName), false)); InstallFileFromMod(strMODFile, strNewFileName); SaveXMLInstalledFiles(strMODFile, strNewFileName); StepItemProgress(); } return(true); }
/// <summary> /// Installs the given <see cref="InstallableFile"/>, and activates any /// plugins it encompasses as requested. /// </summary> /// <param name="p_ilfFile">The file to install.</param> /// <param name="p_booActivate">Whether or not to activate the given file, if it is a plugin.</param> /// <returns><c>false</c> if the user cancelled the install; /// <c>true</c> otherwise.</returns> protected bool InstallFile(InstallableFile p_ilfFile, bool p_booActivate) { string strSource = p_ilfFile.Source; string strDest = p_ilfFile.Destination; ItemMessage = "Installing " + (String.IsNullOrEmpty(strDest) ? strSource : strDest); if (p_ilfFile.IsFolder) { if (!InstallFolderFromMod(p_ilfFile)) { return(false); } //if the destination length is greater than 0, then nothing in // this folder is directly in the Data folder as so cannot be // activated if (strDest.Length == 0) { List <string> lstFiles = Mod.GetFileList(strSource, true); ItemMessage = "Activating " + (String.IsNullOrEmpty(strDest) ? strSource : strDest); ItemProgress = 0; ItemProgressMaximum = lstFiles.Count; string strDirectorySeparatorChar = Path.DirectorySeparatorChar.ToString(); if (!strSource.EndsWith(strDirectorySeparatorChar) && !strSource.EndsWith("/")) { strSource += strDirectorySeparatorChar; } foreach (string strFile in lstFiles) { string strNewFileName = GameMode.GetModFormatAdjustedPath(Mod.Format, strFile.Substring(strSource.Length, strFile.Length - strSource.Length), false); if (Installers.PluginManager != null) { if (Installers.PluginManager.IsActivatiblePluginFile(strNewFileName)) { Installers.PluginManager.SetPluginActivation(strNewFileName, p_booActivate); } } if (Status == TaskStatus.Cancelling) { return(false); } StepItemProgress(); } } } else { ItemProgress = 0; ItemProgressMaximum = 2; //Installers.FileInstaller.InstallFileFromMod(strSource, GameMode.GetModFormatAdjustedPath(Mod.Format, strDest, false)); InstallFileFromMod(strSource, strDest); SaveXMLInstalledFiles(strSource, strDest); StepItemProgress(); string strPluginPath = GameMode.GetModFormatAdjustedPath(Mod.Format, String.IsNullOrEmpty(strDest) ? strSource : strDest, false); if (Installers.PluginManager != null) { if (Installers.PluginManager.IsActivatiblePluginFile(strPluginPath)) { Installers.PluginManager.SetPluginActivation(strPluginPath, p_booActivate); } } StepItemProgress(); } return(true); }