/// <summary> /// Recursively copies all files and folders from one location to another. /// </summary> /// <param name="installableFile">The folder to install.</param> /// <returns><c>false</c> if the user cancelled the install; /// <c>true</c> otherwise.</returns> protected bool InstallFolderFromMod(InstallableFile installableFile, string strPrefixPath) { IList <string> lstModFiles = ModArchive.GetFileList(Path.Combine(strPrefixPath, installableFile.Source), true, false); string strFrom = Path.Combine(strPrefixPath, installableFile.Source).Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); if (!strFrom.EndsWith(Path.DirectorySeparatorChar.ToString())) { strFrom += Path.DirectorySeparatorChar; } string strTo = installableFile.Destination.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); if ((strTo.Length > 0) && (!strTo.EndsWith(Path.DirectorySeparatorChar.ToString()))) { strTo += Path.DirectorySeparatorChar; } string strMODFile = null; for (int i = 0; i < lstModFiles.Count; i++) { strMODFile = lstModFiles[i]; int intLength = strMODFile.Length - strFrom.Length; if (intLength <= 0) { throw new Exception("Failed to install \"" + strFrom + "\" as folder"); } string strNewFileName = strMODFile.Substring(strFrom.Length, intLength); if (strTo.Length > 0) { strNewFileName = Path.Combine(strTo, strNewFileName); } InstallFileFromMod(strMODFile, strNewFileName, installableFile.Priority); } return(true); }
/// <summary> /// Installs the given <see cref="InstallableFile"/>, and activates any /// plugins it encompasses as requested. /// </summary> /// <param name="installableFile">The file to install.</param> /// <param name="priorityOffset">Offset for the priority. Used to simulate the NMM behaviour of installing files /// in multiple phases, ignoring the priority between those phases</param> /// <returns><c>false</c> if the user cancelled the install; /// <c>true</c> otherwise.</returns> protected bool InstallFile(InstallableFile installableFile, int priorityOffset) { if (installableFile.IsFolder) { if (!InstallFolderFromMod(installableFile, ModArchive.Prefix)) { return(false); } } else { string strSource = Path.Combine(ModArchive.Prefix, installableFile.Source); int count = ModArchive.GetFileList(strSource, true, false).Count; if (count == 1) { string strDest = installableFile.Destination; InstallFileFromMod(strSource, strDest, installableFile.Priority + priorityOffset); } else { modInstallInstructions.Add(Instruction.InstallError("warning", count == 0 ? "Source doesn't match any files: \"" + strSource + "\"" : "Source matches a directory, was supposed to be a file: \"" + strSource + "\"")); } } 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> /// <returns><c>false</c> if the user cancelled the install; /// <c>true</c> otherwise.</returns> protected bool InstallFile(InstallableFile installableFile) { if (installableFile.IsFolder) { if (!InstallFolderFromMod(installableFile, ModArchive.Prefix)) return false; } else { string strSource = Path.Combine(ModArchive.Prefix, installableFile.Source); string strDest = installableFile.Destination; InstallFileFromMod(strSource, strDest); /// ??? Plugin activation } return true; }
/// <summary> /// Recursively copies all files and folders from one location to another. /// </summary> /// <param name="installableFile">The folder to install.</param> /// <returns><c>false</c> if the user cancelled the install; /// <c>true</c> otherwise.</returns> protected bool InstallFolderFromMod(InstallableFile installableFile, string strPrefixPath) { List<string> lstModFiles = ModArchive.GetFileList(Path.Combine(strPrefixPath, installableFile.Source), true); string strFrom = Path.Combine(strPrefixPath, installableFile.Source).Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); if (!strFrom.EndsWith(Path.DirectorySeparatorChar.ToString())) strFrom += Path.DirectorySeparatorChar; string strTo = installableFile.Destination.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); if ((strTo.Length > 0) && (!strTo.EndsWith(Path.DirectorySeparatorChar.ToString()))) strTo += Path.DirectorySeparatorChar; string strMODFile = null; for (int i = 0; i < lstModFiles.Count; i++) { strMODFile = lstModFiles[i]; string strNewFileName = strMODFile.Substring(strFrom.Length, strMODFile.Length - strFrom.Length); if (strTo.Length > 0) strNewFileName = Path.Combine(strTo, strNewFileName); InstallFileFromMod(strMODFile, strNewFileName); } return true; }