protected override void ProcessFile(InstallFile file, System.Xml.XPath.XPathNavigator nav) { if (file != null) { Files.Add(file); } }
protected virtual bool InstallFile(InstallFile insFile) { try { if ((this.Package.InstallerInfo.IgnoreWhiteList || Util.IsFileValid(insFile, Package.InstallerInfo.AllowableFiles))) { if (File.Exists(PhysicalBasePath + insFile.FullName)) { Util.BackupFile(insFile, PhysicalBasePath, Log); } Util.CopyFile(insFile, PhysicalBasePath, Log); return true; } else { Log.AddFailure(string.Format(Util.FILE_NotAllowed, insFile.FullName)); return false; } } catch (Exception ex) { Log.AddFailure(Util.EXCEPTION + " - " + ex.Message); return false; } }
protected override bool InstallFile(InstallFile file) { bool bSuccess = true; if (file.Action == "UnRegister") { DeleteFile(file); } else { int returnCode = DataProvider.Instance().RegisterAssembly(this.Package.PackageID, file.Name, file.Version.ToString(3)); switch (returnCode) { case 0: Log.AddInfo(Util.ASSEMBLY_Added + " - " + file.FullName); break; case 1: Log.AddInfo(Util.ASSEMBLY_Updated + " - " + file.FullName); break; case 2: case 3: Log.AddInfo(Util.ASSEMBLY_Registered + " - " + file.FullName); break; } if (returnCode < 2 || (returnCode == 2 && file.InstallerInfo.RepairInstall)) { bSuccess = base.InstallFile(file); } } return bSuccess; }
protected override void RollbackFile(InstallFile installFile) { if (File.Exists(installFile.BackupFileName)) { Util.RestoreFile(installFile, PhysicalBasePath, Log); } }
protected virtual void DeleteFile(InstallFile insFile) { if (DeleteFiles) { Util.DeleteFile(insFile, PhysicalBasePath, Log); } }
private bool ExecuteSql(InstallFile scriptFile, bool useTransaction) { bool bSuccess = true; Log.AddInfo(string.Format(Util.SQL_BeginFile, scriptFile.Name)); string strScript = FileSystemUtils.ReadFile(PhysicalBasePath + scriptFile.FullName); if (strScript.StartsWith("?")) { strScript = strScript.Substring(1); } string strSQLExceptions = Null.NullString; strSQLExceptions = DataProvider.Instance().ExecuteScript(strScript); if (!String.IsNullOrEmpty(strSQLExceptions)) { if (Package.InstallerInfo.IsLegacyMode) { Log.AddWarning(string.Format(Util.SQL_Exceptions, Environment.NewLine, strSQLExceptions)); } else { Log.AddFailure(string.Format(Util.SQL_Exceptions, Environment.NewLine, strSQLExceptions)); bSuccess = false; } } Log.AddInfo(string.Format(Util.SQL_EndFile, scriptFile.Name)); return bSuccess; }
private bool InstallScriptFile(InstallFile scriptFile) { bool bSuccess = InstallFile(scriptFile); if (bSuccess && ProviderConfiguration.DefaultProvider.ToLower() == Path.GetExtension(scriptFile.Name.ToLower()).Substring(1)) { Log.AddInfo(Util.SQL_Executing + scriptFile.Name); bSuccess = ExecuteSql(scriptFile, false); } return bSuccess; }
protected override void DeleteFile(InstallFile file) { if (DataProvider.Instance().UnRegisterAssembly(this.Package.PackageID, file.Name)) { Log.AddInfo(Util.ASSEMBLY_UnRegistered + " - " + file.FullName); base.DeleteFile(file); } else { Log.AddInfo(Util.ASSEMBLY_InUse + " - " + file.FullName); } }
protected bool CleanupFile(InstallFile insFile) { try { if (File.Exists(PhysicalBasePath + insFile.FullName)) { Util.BackupFile(insFile, PhysicalBasePath, Log); } Util.DeleteFile(insFile, PhysicalBasePath, Log); return true; } catch (Exception ex) { ex.ToString(); return false; } }
protected override void UnInstallFile(InstallFile scriptFile) { //Process the file if it is an UnInstall Script var extension = Path.GetExtension(scriptFile.Name.ToLower()); if (extension != null && (UnInstallScripts.ContainsValue(scriptFile))) { string fileExtension = extension.Substring(1); if (scriptFile.Name.ToLower().StartsWith("uninstall.") && IsValidScript(fileExtension)) { //Install Script Log.AddInfo(Util.SQL_Executing + scriptFile.Name); ExecuteSql(scriptFile); } } //Call base method to delete file base.UnInstallFile(scriptFile); }
private bool InstallScriptFile(InstallFile scriptFile) { //Call base InstallFile method to copy file bool bSuccess = InstallFile(scriptFile); //Process the file if it is an Install Script var extension = Path.GetExtension(scriptFile.Name.ToLower()); if (extension != null) { string fileExtension = extension.Substring(1); if (bSuccess && IsValidScript(fileExtension)) { Log.AddInfo(Util.SQL_Executing + scriptFile.Name); bSuccess = ExecuteSql(scriptFile); } } return(bSuccess); }
public JsonResult UpdateFile(string staffCode, string appId, string verCdStr, string verNm, string fileNm) { InstallFileDAO installFileDAO = new InstallFileDAO(); InstallFile installFile = null; try { int verCd = int.Parse(verCdStr); installFile = new InstallFile { appId = appId, verCd = verCd, verNm = verNm, fileNm = fileNm }; } catch (Exception ex) { } return(Json(installFileDAO.UpdateFile(staffCode, installFile))); }
/// ----------------------------------------------------------------------------- /// <summary> /// The InstallFile method installs a single assembly. /// </summary> /// <param name="file">The InstallFile to install.</param> /// <returns></returns> protected override bool InstallFile(InstallFile file) { bool bSuccess = true; if (file.Action == "UnRegister") { this.DeleteFile(file); } else { // Attempt to register assembly this will return False if the assembly exists and true if it does not or is older int returnCode = DataProvider.Instance().RegisterAssembly(this.Package.PackageID, file.Name, file.Version.ToString(3)); switch (returnCode) { case 0: // Assembly Does Not Exist this.Log.AddInfo(Util.ASSEMBLY_Added + " - " + file.FullName); break; case 1: // Older version of Assembly Exists this.Log.AddInfo(Util.ASSEMBLY_Updated + " - " + file.FullName); break; case 2: case 3: // Assembly already Registered this.Log.AddInfo(Util.ASSEMBLY_Registered + " - " + file.FullName); break; } // If assembly not registered, is newer (or is the same version and we are in repair mode) if (returnCode < 2 || (returnCode == 2 && file.InstallerInfo.RepairInstall)) { // Call base class version to copy file to \bin bSuccess = base.InstallFile(file); this.AddOrUpdateBindingRedirect(file); } } return(bSuccess); }
protected override void WriteFileElement(XmlWriter writer, InstallFile file) { Log.AddInfo(string.Format(Util.WRITER_AddFileToManifest, file.Name)); string type = "Install"; string version = Null.NullString; string fileName = Path.GetFileNameWithoutExtension(file.Name); if (fileName.ToLower() == "uninstall") { type = "UnInstall"; version = Package.Version.ToString(3); } else if (fileName.ToLower() == "install") { type = "Install"; version = new Version(0, 0, 0).ToString(3); } else if (fileName.StartsWith("Install")) { type = "Install"; version = fileName.Replace("Install.", ""); } else { type = "Install"; version = fileName; } writer.WriteStartElement(ItemNodeName); writer.WriteAttributeString("type", type); if (!string.IsNullOrEmpty(file.Path)) { writer.WriteElementString("path", file.Path); } writer.WriteElementString("name", file.Name); if (!string.IsNullOrEmpty(file.SourceFileName)) { writer.WriteElementString("sourceFileName", file.SourceFileName); } writer.WriteElementString("version", version); writer.WriteEndElement(); }
protected override void RollbackFile(InstallFile insFile) { ZipInputStream unzip = new ZipInputStream(new FileStream(insFile.InstallerInfo.TempInstallFolder + insFile.FullName, FileMode.Open)); ZipEntry entry = unzip.GetNextEntry(); while (entry != null) { if (!entry.IsDirectory) { if (File.Exists(insFile.BackupPath + entry.Name)) { Util.RestoreFile(new InstallFile(unzip, entry, this.Package.InstallerInfo), PhysicalBasePath, Log); } else { Util.DeleteFile(entry.Name, PhysicalBasePath, Log); } } entry = unzip.GetNextEntry(); } }
/// ----------------------------------------------------------------------------- /// <summary> /// The CleanupFile method cleansup a single file. /// </summary> /// <param name="insFile">The InstallFile to clean up</param> /// ----------------------------------------------------------------------------- protected bool CleanupFile(InstallFile insFile) { try { //Backup File if (File.Exists(PhysicalBasePath + insFile.FullName)) { Util.BackupFile(insFile, PhysicalBasePath, Log); } //Delete file Util.DeleteFile(insFile, PhysicalBasePath, Log); return(true); } catch (Exception exc) { Logger.Error(exc); return(false); } }
/// <summary>If the <paramref name="file"/> is a strong-named assembly, applies the XML merge.</summary> /// <param name="file">The assembly file.</param> /// <param name="xmlMergeFile">The XML merge file name.</param> /// <returns><c>true</c> if the XML Merge was applied successfully, <c>false</c> if the file was not a strong-named assembly or could not be read.</returns> private bool ApplyXmlMerge(InstallFile file, string xmlMergeFile) { var assemblyName = ReadAssemblyName(Path.Combine(this.PhysicalBasePath, file.FullName)); var publicKeyToken = ReadPublicKey(assemblyName); if (string.IsNullOrEmpty(publicKeyToken)) { return(false); } var name = assemblyName.Name; var assemblyVersion = assemblyName.Version; var newVersion = assemblyVersion.ToString(); var xmlMergePath = Path.Combine(Globals.InstallMapPath, "Config", xmlMergeFile); var xmlMergeDoc = GetXmlMergeDoc(xmlMergePath, name, publicKeyToken, OldVersion, newVersion); var xmlMerge = new XmlMerge(xmlMergeDoc, file.Version.ToString(), this.Package.Name); xmlMerge.UpdateConfigs(); return(true); }
/// <summary>If tyhe <paramref name="file"/> is a strong-named assembly, applies the XML merge.</summary> /// <param name="file">The assembly file.</param> /// <param name="xmlMergeFile">The XML merge file name.</param> /// <returns><c>true</c> if the XML Merge was applied successfully, <c>false</c> if the file was not a strong-named assembly.</returns> private bool ApplyXmlMerge(InstallFile file, string xmlMergeFile) { var assemblyName = AssemblyName.GetAssemblyName(Path.Combine(this.PhysicalBasePath, file.FullName)); if (!assemblyName.Flags.HasFlag(AssemblyNameFlags.PublicKey)) { return(false); } var name = assemblyName.Name; var publicKeyToken = PublicKeyTokenRegex.Match(assemblyName.FullName).Groups[1].Value; var oldVersion = "0.0.0.0-" + new Version(assemblyName.Version.Major, short.MaxValue, short.MaxValue, short.MaxValue); var newVersion = assemblyName.Version.ToString(); var xmlMergePath = Path.Combine(Globals.InstallMapPath, "Config", xmlMergeFile); var xmlMergeDoc = GetXmlMergeDoc(xmlMergePath, name, publicKeyToken, oldVersion, newVersion); var xmlMerge = new XmlMerge(xmlMergeDoc, file.Version.ToString(), this.Package.Name); xmlMerge.UpdateConfigs(); return(true); }
private void CreateManifest() { foreach (string fileName in Regex.Split(txtFiles.Text, Environment.NewLine)) { string name = fileName.Trim(); if (!string.IsNullOrEmpty(name)) { var file = new InstallFile(name); _Writer.AddFile(file); } } foreach (string fileName in Regex.Split(txtAssemblies.Text, Environment.NewLine)) { string name = fileName.Trim(); if (!string.IsNullOrEmpty(name)) { var file = new InstallFile(name); _Writer.AddFile(file); } } txtManifest.Text = _Writer.WriteManifest(false); }
public InstallFileJSON UpdateFile(string staffCode, InstallFile installFile) { InstallFileJSON result = new InstallFileJSON(); if (installFile != null) { StringBuilder sbSQL = new StringBuilder(); try { using (NpgDB npgDB = Connection.DBConnect()) { sbSQL.AppendLine("INSERT INTO dinstallfile"); sbSQL.AppendLine("(appid, vercd, vernm, filenm, upopr)"); sbSQL.AppendLine("VALUES ("); sbSQL.AppendLine(":p_appid, :p_vercd, :p_vernm, :p_filenm, :p_upopr"); sbSQL.AppendLine(")"); sbSQL.AppendLine("RETURNING appid, vercd, vernm, filenm, upopr"); npgDB.Command = sbSQL.ToString(); npgDB.SetParams(":p_appid", installFile.appId); npgDB.SetParamsLongString(":p_vercd", installFile.verCd + ""); npgDB.SetParams(":p_vernm", installFile.verNm); npgDB.SetParams(":p_filenm", installFile.fileNm); npgDB.SetParams(":p_upopr", staffCode); using (NpgsqlDataReader rec = npgDB.Query()) { if (rec.Read()) { result.fileContent = new InstallFile(rec); result.success = true; } } } } catch (Exception ex) { } } return(result); }
protected virtual void WriteFileElement(XmlWriter writer, InstallFile file) { Log.AddInfo(string.Format(Util.WRITER_AddFileToManifest, file.Name)); writer.WriteStartElement(ItemNodeName); if (!string.IsNullOrEmpty(file.Path)) { string path = file.Path; if (!string.IsNullOrEmpty(_BasePath)) { if (file.Path.ToLowerInvariant().Contains(_BasePath.ToLowerInvariant())) { path = file.Path.ToLowerInvariant().Replace(_BasePath.ToLowerInvariant() + "\\", ""); } } writer.WriteElementString("path", path); } writer.WriteElementString("name", file.Name); if (!string.IsNullOrEmpty(file.SourceFileName)) { writer.WriteElementString("sourceFileName", file.SourceFileName); } writer.WriteEndElement(); }
/// <summary> /// Saves all open System Files to disk. /// </summary> /// <param name="directory"></param> /// <param name="manifestDirectory">Optional stores the Versions/CDNs in a different location</param> public void Save(string directory, string manifestDirectory = "") { // if this field exists and mismatches the generated file; the client will error // if this field is missing the client will generate the file and variable itself ConfigContainer?.CDNConfig?.GetValues("archive-group")?.Clear(); IndexContainer?.Save(directory, ConfigContainer); RootFile?.Write(directory, this); DownloadFile?.Write(directory, this); DownloadSizeFile?.Write(directory, this); InstallFile?.Write(directory, this); EncodingFile?.Write(directory, this); ConfigContainer?.Save(directory, ManifestContainer); // save the manifests if (string.IsNullOrWhiteSpace(manifestDirectory)) { manifestDirectory = directory; } ManifestContainer?.Save(manifestDirectory); RootFile?.FileLookup?.Close(); }
protected override void UnInstallFile(InstallFile scriptFile) { //Process the file if it is an UnInstall Script var extension = Path.GetExtension(scriptFile.Name.ToLower()); if (extension != null && (UnInstallScripts.ContainsValue(scriptFile) )) { string fileExtension = extension.Substring(1); if (scriptFile.Name.ToLower().StartsWith("uninstall.") && IsValidScript(fileExtension)) { //Install Script Log.AddInfo(Util.SQL_Executing + scriptFile.Name); ExecuteSql(scriptFile); } } //Call base method to delete file base.UnInstallFile(scriptFile); }
private bool InstallScriptFile(InstallFile scriptFile) { //Call base InstallFile method to copy file bool bSuccess = InstallFile(scriptFile); //Process the file if it is an Install Script var extension = Path.GetExtension(scriptFile.Name.ToLower()); if (extension != null) { string fileExtension = extension.Substring(1); if (bSuccess && IsValidScript(fileExtension)) { Log.AddInfo(Util.SQL_Executing + scriptFile.Name); bSuccess = ExecuteSql(scriptFile); } } return bSuccess; }
/// ----------------------------------------------------------------------------- /// <summary> /// The ReadManifestItem method reads a single node /// </summary> /// <param name="nav">The XPathNavigator representing the node</param> /// <param name="checkFileExists">Flag that determines whether a check should be made</param> /// <history> /// [cnurse] 08/07/2007 created /// </history> /// ----------------------------------------------------------------------------- protected virtual InstallFile ReadManifestItem(XPathNavigator nav, bool checkFileExists) { string fileName = Null.NullString; //Get the path XPathNavigator pathNav = nav.SelectSingleNode("path"); if (pathNav == null) { fileName = DefaultPath; } else { fileName = pathNav.Value + "\\"; } //Get the name XPathNavigator nameNav = nav.SelectSingleNode("name"); if (nameNav != null) { fileName += nameNav.Value; } //Get the sourceFileName string sourceFileName = Util.ReadElement(nav, "sourceFileName"); var file = new InstallFile(fileName, sourceFileName, Package.InstallerInfo); if ((!string.IsNullOrEmpty(BasePath)) && (BasePath.ToLowerInvariant().StartsWith("app_code") && file.Type == InstallFileType.Other)) { file.Type = InstallFileType.AppCode; } if (file != null) { //Set the Version string strVersion = XmlUtils.GetNodeValue(nav, "version"); if (!string.IsNullOrEmpty(strVersion)) { file.SetVersion(new Version(strVersion)); } else { file.SetVersion(Package.Version); } //Set the Action string strAction = XmlUtils.GetAttributeValue(nav, "action"); if (!string.IsNullOrEmpty(strAction)) { file.Action = strAction; } if (InstallMode == InstallMode.Install && checkFileExists && file.Action != "UnRegister") { if (File.Exists(file.TempFileName)) { Log.AddInfo(string.Format(Util.FILE_Found, file.Path, file.Name)); } else { Log.AddFailure(Util.FILE_NotFound + " - " + file.TempFileName); } } } return file; }
/// ----------------------------------------------------------------------------- /// <summary> /// The ProcessFile method determines what to do with parsed "file" node /// </summary> /// <param name="file">The file represented by the node</param> /// <param name="nav">The XPathNavigator representing the node</param> /// <history> /// [cnurse] 08/07/2007 created /// </history> /// ----------------------------------------------------------------------------- protected override void ProcessFile(InstallFile file, XPathNavigator nav) { switch (file.Extension) { case "htm": case "html": case "ascx": case "css": if (file.Path.ToLower().IndexOf(Globals.glbAboutPage.ToLower()) < 0) { SkinFiles.Add(PhysicalBasePath + file.FullName); } break; } //Call base method to set up for file processing base.ProcessFile(file, nav); }
/// ----------------------------------------------------------------------------- /// <summary> /// The DeleteFile method deletes a single assembly. /// </summary> /// <param name="file">The InstallFile to delete</param> /// <history> /// [cnurse] 08/01/2007 created /// </history> /// ----------------------------------------------------------------------------- protected override void DeleteFile(InstallFile file) { //Attempt to unregister assembly this will return False if the assembly is used by another package and //cannot be delete andtrue if it is not being used and can be deleted if (DataProvider.Instance().UnRegisterAssembly(Package.PackageID, file.Name)) { Log.AddInfo(Util.ASSEMBLY_UnRegistered + " - " + file.FullName); //Call base class version to deleteFile file from \bin base.DeleteFile(file); } else { Log.AddInfo(Util.ASSEMBLY_InUse + " - " + file.FullName); } }
/// ----------------------------------------------------------------------------- /// <summary> /// The RollbackFile method rolls back the install of a single file. /// </summary> /// <remarks>For new installs this removes the added file. For upgrades it restores the /// backup file created during install</remarks> /// <param name="insFile">The InstallFile to commit</param> /// <history> /// [cnurse] 01/18/2008 created /// </history> /// ----------------------------------------------------------------------------- protected override void RollbackFile(InstallFile insFile) { var unzip = new ZipInputStream(new FileStream(insFile.InstallerInfo.TempInstallFolder + insFile.FullName, FileMode.Open)); ZipEntry entry = unzip.GetNextEntry(); while (entry != null) { if (!entry.IsDirectory) { //Check for Backups if (File.Exists(insFile.BackupPath + entry.Name)) { //Restore File Util.RestoreFile(new InstallFile(unzip, entry, Package.InstallerInfo), PhysicalBasePath, Log); } else { //Delete File Util.DeleteFile(entry.Name, PhysicalBasePath, Log); } } entry = unzip.GetNextEntry(); } }
/// ----------------------------------------------------------------------------- /// <summary> /// The RollbackFile method rolls back the install of a single file. /// </summary> /// <remarks>For new installs this removes the added file. For upgrades it restores the /// backup file created during install</remarks> /// <param name="installFile">The InstallFile to commit</param> /// <history> /// [cnurse] 08/01/2007 created /// </history> /// ----------------------------------------------------------------------------- protected virtual void RollbackFile(InstallFile installFile) { if (File.Exists(installFile.BackupFileName)) { Util.RestoreFile(installFile, PhysicalBasePath, Log); } else { DeleteFile(installFile); } }
public string GetDownloadURL() { return(InstallFile.Replace(@"\", "/")); }
/// ----------------------------------------------------------------------------- /// <summary> /// The InstallFile method installs a single assembly. /// </summary> /// <param name = "insFile">The InstallFile to install.</param> /// <returns></returns> protected override bool InstallFile(InstallFile insFile) { bool retValue = true; try { this.Log.AddInfo(Util.FILES_Expanding); // Create the folder for destination this._Manifest = insFile.Name + ".manifest"; if (!Directory.Exists(this.PhysicalBasePath)) { Directory.CreateDirectory(this.PhysicalBasePath); } using (var unzip = new ZipInputStream(new FileStream(insFile.TempFileName, FileMode.Open))) using (var manifestStream = new FileStream(Path.Combine(this.PhysicalBasePath, this.Manifest), FileMode.Create, FileAccess.Write)) { var settings = new XmlWriterSettings(); settings.ConformanceLevel = ConformanceLevel.Fragment; settings.OmitXmlDeclaration = true; settings.Indent = true; using (var writer = XmlWriter.Create(manifestStream, settings)) { // Start the new Root Element writer.WriteStartElement("dotnetnuke"); writer.WriteAttributeString("type", "ResourceFile"); writer.WriteAttributeString("version", "5.0"); // Start files Element writer.WriteStartElement("files"); ZipEntry entry = unzip.GetNextEntry(); while (entry != null) { entry.CheckZipEntry(); if (!entry.IsDirectory) { string fileName = Path.GetFileName(entry.Name); // Start file Element writer.WriteStartElement("file"); // Write path writer.WriteElementString( "path", entry.Name.Substring(0, entry.Name.IndexOf(fileName))); // Write name writer.WriteElementString("name", fileName); var physicalPath = Path.Combine(this.PhysicalBasePath, entry.Name); if (File.Exists(physicalPath)) { Util.BackupFile( new InstallFile(entry.Name, this.Package.InstallerInfo), this.PhysicalBasePath, this.Log); } Util.WriteStream(unzip, physicalPath); // Close files Element writer.WriteEndElement(); this.Log.AddInfo(string.Format(Util.FILE_Created, entry.Name)); } entry = unzip.GetNextEntry(); } // Close files Element writer.WriteEndElement(); this.Log.AddInfo(Util.FILES_CreatedResources); } } } catch (Exception exc) { Logger.Error(exc); retValue = false; } return(retValue); }
/// ----------------------------------------------------------------------------- /// <summary> /// The DeleteFile method deletes a single assembly. /// </summary> /// <param name="file">The InstallFile to delete</param> /// <history> /// [cnurse] 01/18/2008 created /// </history> /// ----------------------------------------------------------------------------- protected override void DeleteFile(InstallFile file) { }
/// ----------------------------------------------------------------------------- /// <summary> /// The CommitFile method commits a single file. /// </summary> /// <param name="insFile">The InstallFile to commit</param> /// <history> /// [cnurse] 01/18/2008 created /// </history> /// ----------------------------------------------------------------------------- protected override void CommitFile(InstallFile insFile) { }
public void AddResourceFile(InstallFile file) { this._Resources[file.FullName.ToLowerInvariant()] = file; }
/// ----------------------------------------------------------------------------- /// <summary> /// The CleanupFile method cleansup a single file. /// </summary> /// <param name="insFile">The InstallFile to clean up</param> /// <history> /// [cnurse] 09/05/2007 created /// </history> /// ----------------------------------------------------------------------------- protected bool CleanupFile(InstallFile insFile) { try { //Backup File if (File.Exists(PhysicalBasePath + insFile.FullName)) { Util.BackupFile(insFile, PhysicalBasePath, Log); } //Delete file Util.DeleteFile(insFile, PhysicalBasePath, Log); return true; } catch (Exception exc) { Logger.Error(exc); return false; } }
/// ----------------------------------------------------------------------------- /// <summary> /// The InstallFile method installs a single assembly. /// </summary> /// <param name = "insFile">The InstallFile to install</param> /// <history> /// [cnurse] 01/18/2008 created /// [aprasad] 01/26/2011 Removed condition [If String.IsNullOrEmpty(Manifest) Then] prior to setting _Manifest /// Since it was not able to set _Manifest for the second file onwards, same manifest file was being /// created for all the resource files /// </history> /// ----------------------------------------------------------------------------- protected override bool InstallFile(InstallFile insFile) { FileStream fs = null; ZipInputStream unzip = null; XmlWriter writer = null; bool retValue = true; try { Log.AddInfo(Util.FILES_Expanding); unzip = new ZipInputStream(new FileStream(insFile.TempFileName, FileMode.Open)); //Create a writer to create the manifest for the resource file _Manifest = insFile.Name + ".manifest"; if (!Directory.Exists(PhysicalBasePath)) { Directory.CreateDirectory(PhysicalBasePath); } fs = new FileStream(Path.Combine(PhysicalBasePath, Manifest), FileMode.Create, FileAccess.Write); var settings = new XmlWriterSettings(); settings.ConformanceLevel = ConformanceLevel.Fragment; settings.OmitXmlDeclaration = true; settings.Indent = true; writer = XmlWriter.Create(fs, settings); //Start the new Root Element writer.WriteStartElement("dotnetnuke"); writer.WriteAttributeString("type", "ResourceFile"); writer.WriteAttributeString("version", "5.0"); //Start files Element writer.WriteStartElement("files"); ZipEntry entry = unzip.GetNextEntry(); while (entry != null) { if (!entry.IsDirectory) { string fileName = Path.GetFileName(entry.Name); //Start file Element writer.WriteStartElement("file"); //Write path writer.WriteElementString("path", entry.Name.Substring(0, entry.Name.IndexOf(fileName))); //Write name writer.WriteElementString("name", fileName); string physicalPath = Path.Combine(PhysicalBasePath, entry.Name); if (File.Exists(physicalPath)) { Util.BackupFile(new InstallFile(entry.Name, Package.InstallerInfo), PhysicalBasePath, Log); } Util.WriteStream(unzip, physicalPath); //Close files Element writer.WriteEndElement(); Log.AddInfo(string.Format(Util.FILE_Created, entry.Name)); } entry = unzip.GetNextEntry(); } //Close files Element writer.WriteEndElement(); Log.AddInfo(Util.FILES_CreatedResources); } catch (Exception exc) { Instrumentation.DnnLog.Error(exc); retValue = false; } finally { if (writer != null) { //Close XmlWriter writer.Close(); } if (fs != null) { //Close FileStreams fs.Close(); } if (unzip != null) { unzip.Close(); } } return retValue; }
protected override void ProcessFile(InstallFile file, System.Xml.XPath.XPathNavigator nav) { base.ProcessFile(file, nav); }
protected override void UnInstallFile(InstallFile unInstallFile) { _Manifest = unInstallFile.Name + ".manifest"; var doc = new XPathDocument(Path.Combine(PhysicalBasePath, Manifest)); foreach (XPathNavigator fileNavigator in doc.CreateNavigator().Select("dotnetnuke/files/file")) { string path = XmlUtils.GetNodeValue(fileNavigator, "path"); string fileName = XmlUtils.GetNodeValue(fileNavigator, "name"); string filePath = Path.Combine(path, fileName); try { if (DeleteFiles) { Util.DeleteFile(filePath, PhysicalBasePath, Log); } } catch (Exception ex) { Log.AddFailure(ex); } } if (DeleteFiles) { Util.DeleteFile(Manifest, PhysicalBasePath, Log); } }
/// ----------------------------------------------------------------------------- /// <summary> /// The CommitFile method commits a single file. /// </summary> /// <param name="insFile">The InstallFile to commit</param> /// ----------------------------------------------------------------------------- protected virtual void CommitFile(InstallFile insFile) { }
/// ----------------------------------------------------------------------------- /// <summary> /// The InstallFile method installs a single assembly. /// </summary> /// <param name="file">The InstallFile to install</param> /// <history> /// [cnurse] 08/01/2007 created /// </history> /// ----------------------------------------------------------------------------- protected override bool InstallFile(InstallFile file) { bool bSuccess = true; if (file.Action == "UnRegister") { DeleteFile(file); } else { //Attempt to register assembly this will return False if the assembly exists and true if it does not or is older int returnCode = DataProvider.Instance().RegisterAssembly(Package.PackageID, file.Name, file.Version.ToString(3)); switch (returnCode) { case 0: //Assembly Does Not Exist Log.AddInfo(Util.ASSEMBLY_Added + " - " + file.FullName); break; case 1: //Older version of Assembly Exists Log.AddInfo(Util.ASSEMBLY_Updated + " - " + file.FullName); break; case 2: case 3: //Assembly already Registered Log.AddInfo(Util.ASSEMBLY_Registered + " - " + file.FullName); break; } //If assembly not registered, is newer (or is the same version and we are in repair mode) if (returnCode < 2 || (returnCode == 2 && file.InstallerInfo.RepairInstall)) { //Call base class version to copy file to \bin bSuccess = base.InstallFile(file); } } return bSuccess; }
/// ----------------------------------------------------------------------------- /// <summary> /// The ReadManifestItem method reads a single node /// </summary> /// <param name="nav">The XPathNavigator representing the node</param> /// <param name="checkFileExists">Flag that determines whether a check should be made</param> /// ----------------------------------------------------------------------------- protected virtual InstallFile ReadManifestItem(XPathNavigator nav, bool checkFileExists) { string fileName = Null.NullString; //Get the path XPathNavigator pathNav = nav.SelectSingleNode("path"); if (pathNav == null) { fileName = DefaultPath; } else { fileName = pathNav.Value + "\\"; } //Get the name XPathNavigator nameNav = nav.SelectSingleNode("name"); if (nameNav != null) { fileName += nameNav.Value; } //Get the sourceFileName string sourceFileName = Util.ReadElement(nav, "sourceFileName"); var file = new InstallFile(fileName, sourceFileName, Package.InstallerInfo); if ((!string.IsNullOrEmpty(BasePath)) && (BasePath.StartsWith("app_code", StringComparison.InvariantCultureIgnoreCase) && file.Type == InstallFileType.Other)) { file.Type = InstallFileType.AppCode; } if (file != null) { //Set the Version string strVersion = XmlUtils.GetNodeValue(nav, "version"); if (!string.IsNullOrEmpty(strVersion)) { file.SetVersion(new Version(strVersion)); } else { file.SetVersion(Package.Version); } //Set the Action string strAction = XmlUtils.GetAttributeValue(nav, "action"); if (!string.IsNullOrEmpty(strAction)) { file.Action = strAction; } if (InstallMode == InstallMode.Install && checkFileExists && file.Action != "UnRegister") { if (File.Exists(file.TempFileName)) { Log.AddInfo(string.Format(Util.FILE_Found, file.Path, file.Name)); } else { Log.AddFailure(Util.FILE_NotFound + " - " + file.TempFileName); } } } return(file); }
/// ----------------------------------------------------------------------------- /// <summary> /// The UnInstallFile method unInstalls a single file. /// </summary> /// <param name="unInstallFile">The InstallFile to unInstall.</param> /// <history> /// [cnurse] 02/11/2008 created /// </history> /// ----------------------------------------------------------------------------- protected override void UnInstallFile(InstallFile unInstallFile) { //Uninstall file base.UnInstallFile(unInstallFile); if (unInstallFile.Extension == "htm" || unInstallFile.Extension == "html") { //Try to remove "processed file" string fileName = unInstallFile.FullName; fileName = fileName.Replace(Path.GetExtension(fileName), ".ascx"); Util.DeleteFile(fileName, PhysicalBasePath, Log); } }
public void AddResourceFile(InstallFile file) { _Resources[file.FullName.ToLower()] = file; }
/// ----------------------------------------------------------------------------- /// <summary> /// The ProcessFile method determines what to do with parsed "file" node /// </summary> /// <param name="file">The file represented by the node</param> /// <param name="nav">The XPathNavigator representing the node</param> /// <history> /// [cnurse] 08/07/2007 created /// </history> /// ----------------------------------------------------------------------------- protected virtual void ProcessFile(InstallFile file, XPathNavigator nav) { if (file != null && IsCorrectType(file.Type)) { Files.Add(file); //Add to the Package.InstallerInfo.Files[file.FullName.ToLower()] = file; } }
/// <summary> /// 引发 <see cref="InstallFile" /> 事件 /// </summary> protected virtual void OnInstallFile(InstallFileEventArgs e) { InstallFile.Invoke(this, e); }
private bool ExecuteSql(InstallFile scriptFile) { bool bSuccess = true; Log.AddInfo(string.Format(Util.SQL_BeginFile, scriptFile.Name)); //read script file for installation string strScript = FileSystemUtils.ReadFile(PhysicalBasePath + scriptFile.FullName); //This check needs to be included because the unicode Byte Order mark results in an extra character at the start of the file //The extra character - '?' - causes an error with the database. if (strScript.StartsWith("?")) { strScript = strScript.Substring(1); } string strSQLExceptions = DataProvider.Instance().ExecuteScript(strScript); if (!String.IsNullOrEmpty(strSQLExceptions)) { if (Package.InstallerInfo.IsLegacyMode) { Log.AddWarning(string.Format(Util.SQL_Exceptions, Environment.NewLine, strSQLExceptions)); } else { Log.AddFailure(string.Format(Util.SQL_Exceptions, Environment.NewLine, strSQLExceptions)); bSuccess = false; } } Log.AddInfo(string.Format(Util.SQL_EndFile, scriptFile.Name)); return bSuccess; }
/// ----------------------------------------------------------------------------- /// <summary> /// The ProcessFile method determines what to do with parsed "file" node /// </summary> /// <param name="file">The file represented by the node</param> /// <param name="nav">The XPathNavigator representing the node</param> /// <history> /// [cnurse] 08/07/2007 created /// </history> /// ----------------------------------------------------------------------------- protected override void ProcessFile(InstallFile file, XPathNavigator nav) { string type = nav.GetAttribute("type", ""); if (file != null && IsCorrectType(file.Type)) { if (file.Name.ToLower().StartsWith("install.")) { //This is the initial script when installing _installScript = file; } else if (file.Name.ToLower().StartsWith("upgrade.")) { _upgradeScript = file; } else if (type.ToLower() == "install") { //These are the Install/Upgrade scripts InstallScripts[file.Version] = file; } else { //These are the Uninstall scripts UnInstallScripts[file.Version] = file; } } //Call base method to set up for file processing base.ProcessFile(file, nav); }
/// ----------------------------------------------------------------------------- /// <summary> /// The UnInstallFile method unInstalls a single file. /// </summary> /// <param name="unInstallFile">The InstallFile to unInstall.</param> /// ----------------------------------------------------------------------------- protected virtual void UnInstallFile(InstallFile unInstallFile) { DeleteFile(unInstallFile); }
/// ----------------------------------------------------------------------------- /// <summary> /// The UnInstallFile method unInstalls a single file. /// </summary> /// <param name="unInstallFile">The InstallFile to unInstall.</param> /// <history> /// [cnurse] 01/07/2008 created /// </history> /// ----------------------------------------------------------------------------- protected virtual void UnInstallFile(InstallFile unInstallFile) { DeleteFile(unInstallFile); }
/// ----------------------------------------------------------------------------- /// <summary> /// The InstallFile method installs a single assembly. /// </summary> /// <param name = "insFile">The InstallFile to install</param> /// <history> /// [cnurse] 01/18/2008 created /// [aprasad] 01/26/2011 Removed condition [If String.IsNullOrEmpty(Manifest) Then] prior to setting _Manifest /// Since it was not able to set _Manifest for the second file onwards, same manifest file was being /// created for all the resource files /// </history> /// ----------------------------------------------------------------------------- protected override bool InstallFile(InstallFile insFile) { FileStream fs = null; ZipInputStream unzip = null; XmlWriter writer = null; bool retValue = true; try { Log.AddInfo(Util.FILES_Expanding); unzip = new ZipInputStream(new FileStream(insFile.TempFileName, FileMode.Open)); //Create a writer to create the manifest for the resource file _Manifest = insFile.Name + ".manifest"; if (!Directory.Exists(PhysicalBasePath)) { Directory.CreateDirectory(PhysicalBasePath); } fs = new FileStream(Path.Combine(PhysicalBasePath, Manifest), FileMode.Create, FileAccess.Write); var settings = new XmlWriterSettings(); settings.ConformanceLevel = ConformanceLevel.Fragment; settings.OmitXmlDeclaration = true; settings.Indent = true; writer = XmlWriter.Create(fs, settings); //Start the new Root Element writer.WriteStartElement("dotnetnuke"); writer.WriteAttributeString("type", "ResourceFile"); writer.WriteAttributeString("version", "5.0"); //Start files Element writer.WriteStartElement("files"); ZipEntry entry = unzip.GetNextEntry(); while (entry != null) { if (!entry.IsDirectory) { string fileName = Path.GetFileName(entry.Name); //Start file Element writer.WriteStartElement("file"); //Write path writer.WriteElementString("path", entry.Name.Substring(0, entry.Name.IndexOf(fileName))); //Write name writer.WriteElementString("name", fileName); string physicalPath = Path.Combine(PhysicalBasePath, entry.Name); if (File.Exists(physicalPath)) { Util.BackupFile(new InstallFile(entry.Name, Package.InstallerInfo), PhysicalBasePath, Log); } Util.WriteStream(unzip, physicalPath); //Close files Element writer.WriteEndElement(); Log.AddInfo(string.Format(Util.FILE_Created, entry.Name)); } entry = unzip.GetNextEntry(); } //Close files Element writer.WriteEndElement(); Log.AddInfo(Util.FILES_CreatedResources); } catch (Exception exc) { Instrumentation.DnnLog.Error(exc); retValue = false; } finally { if (writer != null) { //Close XmlWriter writer.Close(); } if (fs != null) { //Close FileStreams fs.Close(); } if (unzip != null) { unzip.Close(); } } return(retValue); }
/// ----------------------------------------------------------------------------- /// <summary> /// The ReadManifest method reads the manifest file for the config compoent. /// </summary> /// <history> /// [cnurse] 08/03/2007 created /// </history> /// ----------------------------------------------------------------------------- public override void ReadManifest(XPathNavigator manifestNav) { _FileName = Util.ReadAttribute(manifestNav, "fileName"); _UninstallFileName = Util.ReadAttribute(manifestNav, "unInstallFileName"); if (string.IsNullOrEmpty(_FileName)) { XPathNavigator nav = manifestNav.SelectSingleNode("config"); //Get the name of the target config file to update XPathNavigator nodeNav = nav.SelectSingleNode("configFile"); string targetFileName = nodeNav.Value; if (!string.IsNullOrEmpty(targetFileName)) { _TargetFile = new InstallFile(targetFileName, "", Package.InstallerInfo); } //Get the Install config changes nodeNav = nav.SelectSingleNode("install"); _InstallConfig = nodeNav.InnerXml; //Get the UnInstall config changes nodeNav = nav.SelectSingleNode("uninstall"); _UnInstallConfig = nodeNav.InnerXml; } }