public static bool InstallPackage(string file, string packageType, bool writeFeedback) { DnnInstallLogger.InstallLogInfo(Localization.Localization.GetString("LogStart", Localization.Localization.GlobalResourceFile) + "InstallPackage:" + file); bool success = Null.NullBoolean; if (writeFeedback) { HtmlUtils.WriteFeedback(HttpContext.Current.Response, 2, "Installing Package File " + Path.GetFileNameWithoutExtension(file) + ": "); } bool deleteTempFolder = true; if (packageType == "Skin" || packageType == "Container") { deleteTempFolder = Null.NullBoolean; } var installer = new Installer.Installer(new FileStream(file, FileMode.Open, FileAccess.Read), Globals.ApplicationMapPath, true, deleteTempFolder); //Check if manifest is valid if (installer.IsValid) { installer.InstallerInfo.RepairInstall = true; success = installer.Install(); } else { if (installer.InstallerInfo.ManifestFile == null) { //Missing manifest if (packageType == "Skin" || packageType == "Container") { //Legacy Skin/Container string tempInstallFolder = installer.TempInstallFolder; string manifestFile = Path.Combine(tempInstallFolder, Path.GetFileNameWithoutExtension(file) + ".dnn"); var manifestWriter = new StreamWriter(manifestFile); manifestWriter.Write(LegacyUtil.CreateSkinManifest(file, packageType, tempInstallFolder)); manifestWriter.Close(); installer = new Installer.Installer(tempInstallFolder, manifestFile, HttpContext.Current.Request.MapPath("."), true); //Set the Repair flag to true for Batch Install installer.InstallerInfo.RepairInstall = true; success = installer.Install(); } else if (Globals.Status != Globals.UpgradeStatus.None) { var message = string.Format(Localization.Localization.GetString("InstallPackageError", Localization.Localization.ExceptionsResourceFile), file, "Manifest file missing"); DnnInstallLogger.InstallLogError(message); } } else { //log the failure log when installer is invalid and not caught by mainfest file missing. foreach (var log in installer.InstallerInfo.Log.Logs .Where(l => l.Type == LogType.Failure)) { Logger.Error(log.Description); DnnInstallLogger.InstallLogError(log.Description); } success = false; } } if (writeFeedback) { HtmlUtils.WriteSuccessError(HttpContext.Current.Response, success); } if (success) { // delete file try { File.SetAttributes(file, FileAttributes.Normal); File.Delete(file); } catch (Exception exc) { Logger.Error(exc); } } return success; }
public static bool InstallPackage(string strFile, string packageType, bool writeFeedback) { bool blnSuccess = Null.NullBoolean; if (writeFeedback) { HtmlUtils.WriteFeedback(HttpContext.Current.Response, 2, "Installing Package File " + Path.GetFileNameWithoutExtension(strFile) + ": "); } bool deleteTempFolder = true; if (packageType == "Skin" || packageType == "Container") { deleteTempFolder = Null.NullBoolean; } Installer.Installer objInstaller = new Installer.Installer(new FileStream(strFile, FileMode.Open, FileAccess.Read), Common.Globals.ApplicationMapPath, true, deleteTempFolder); //Check if manifest is valid if (objInstaller.IsValid) { objInstaller.InstallerInfo.RepairInstall = true; blnSuccess = objInstaller.Install(); } else { if (objInstaller.InstallerInfo.ManifestFile == null) { //Missing manifest if (packageType == "Skin" || packageType == "Container") { //Legacy Skin/Container string TempInstallFolder = objInstaller.TempInstallFolder; string ManifestFile = Path.Combine(TempInstallFolder, Path.GetFileNameWithoutExtension(strFile) + ".dnn"); StreamWriter manifestWriter = new StreamWriter(ManifestFile); manifestWriter.Write(LegacyUtil.CreateSkinManifest(strFile, packageType, TempInstallFolder)); manifestWriter.Close(); objInstaller = new Installer.Installer(TempInstallFolder, ManifestFile, HttpContext.Current.Request.MapPath("."), true); //Set the Repair flag to true for Batch Install objInstaller.InstallerInfo.RepairInstall = true; blnSuccess = objInstaller.Install(); } } else { blnSuccess = false; } } if (writeFeedback) { HtmlUtils.WriteSuccessError(HttpContext.Current.Response, blnSuccess); } if (blnSuccess) { // delete file try { File.SetAttributes(strFile, FileAttributes.Normal); File.Delete(strFile); } catch { } // error removing the file } return blnSuccess; }