/// <summary> /// Writes the file represented by the given byte array to the given path. /// </summary> /// <remarks> /// This method writes the given data as a file at the given path. If the file /// already exists the user is prompted to overwrite the file. /// </remarks> /// <param name="p_strPath">The path where the file is to be created.</param> /// <param name="p_bteData">The data that is to make up the file.</param> /// <returns><c>true</c> if the file was written; <c>false</c> otherwise.</returns> public bool GenerateDataFile(string p_strPath, byte[] p_bteData) { bool booSuccess = false; string strPath = p_strPath.Trim().Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); string strFileType = Path.GetExtension(strPath); if (!strFileType.StartsWith(".")) { strFileType = "." + strFileType; } bool booHardLinkFile = (VirtualModActivator.MultiHDMode && (GameMode.HardlinkRequiredFilesType(strPath) || strFileType.Equals(".exe", StringComparison.InvariantCultureIgnoreCase) || strFileType.Equals(".jar", StringComparison.InvariantCultureIgnoreCase))); try { new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Assert(); string strVirtualPath = Path.Combine(((booHardLinkFile) ? VirtualModActivator.HDLinkFolder : VirtualModActivator.VirtualPath), Path.GetFileNameWithoutExtension(Mod.Filename), strPath); Installers.FileInstaller.GenerateDataFile(strVirtualPath, p_bteData); ModLinkInstaller.AddFileLink(Mod, strPath, strVirtualPath, true); booSuccess = true; } finally { PermissionSet.RevertAssert(); } return(booSuccess); }
/// <summary> /// Installs the specified file from the mod to the specified location on the file system. /// </summary> /// <param name="p_strFrom">The path of the file in the mod to install.</param> /// <param name="p_strTo">The path on the file system where the file is to be created.</param> /// <returns><c>true</c> if the file was written; <c>false</c> otherwise.</returns> public virtual bool InstallFileFromMod(string p_strFrom, string p_strTo) { bool booSuccess = false; string strFrom = p_strFrom.Trim().Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar).ToLowerInvariant(); string strTo = p_strTo.Trim().Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); string strFileType = Path.GetExtension(strTo); if (!strFileType.StartsWith(".")) { strFileType = "." + strFileType; } bool booHardLinkFile = (VirtualModActivator.MultiHDMode && (GameMode.HardlinkRequiredFilesType(strTo) || strFileType.Equals(".exe", StringComparison.InvariantCultureIgnoreCase) || strFileType.Equals(".jar", StringComparison.InvariantCultureIgnoreCase))); try { new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Assert(); string strVirtualPath = Path.Combine(((booHardLinkFile) ? VirtualModActivator.HDLinkFolder : VirtualModActivator.VirtualPath), Path.GetFileNameWithoutExtension(Mod.Filename), strTo); Installers.FileInstaller.InstallFileFromMod(strFrom, strVirtualPath); string strCheck = ModLinkInstaller.AddFileLink(Mod, strTo, strVirtualPath, true, true); booSuccess = true; if (!String.IsNullOrEmpty(strCheck)) { SaveXMLInstalledFiles(p_strFrom, p_strTo); } } finally { PermissionSet.RevertAssert(); } return(booSuccess); }