public static void CopyPackageInstallInfo(string dirPath, string _namespace, out LogDataList log) { log = new LogDataList(); log.WriteInformationLog(NewProjectMessages.Info.CopyInstallInfoInit(dirPath), _namespace); Exception exOut; if (!Directory.Exists(dirPath)) { return; } string packageXMLFile = dirPath + "\\" + Vars.INSTALL_FILE_DEFAULT_FILENAME; if (!File.Exists(packageXMLFile)) { try { throw new FileNotFoundException(packageXMLFile + ExceptionMessages.General.COULD_NOT_BE_FOUND); } catch (Exception ex) { Logger.WriteErrorLog(NewProjectMessages.Error.XML_FILE_NOT_FOUND + packageXMLFile + ".", _namespace, ex, BasicDebugLogger.DebugErrorType.Error); throw; } } LogDataList outLog = null; RMPackage package = null; try { package = new RMPackage(packageXMLFile, _namespace, out outLog); } catch (Exception ex) { log.AppendLogs(outLog); throw new InvalidInstalledPackageFile(ExceptionMessages.PackageManagement.InstalledPackage.INVALID_XML + packageXMLFile + ".", packageXMLFile, ex); } log.AppendLogs(outLog); if (package.ContentsSummary == RMCollectionType.Generator)//If package only contains generator parts then we don't copy it. { return; } if (package.ContentsSummary.HasFlag(RMCollectionType.Generator)) { PackageUtil.RemoveGeneratorFilesAndCollection(package, dirPath, _namespace); package.SaveToFile(packageXMLFile, _namespace, logMessage: new WriteAllTextLogMessages(writeFailed: LoggerMessages.PackageManagement.NewProject.Error.XMLFileSaveFailed)); try { Helper.DeleteEmptySubDir(dirPath, _namespace); } catch (Exception ex) { log.WriteWarningLog(NewProjectMessages.Warning.DELETE_SUB_DIR + PMFileSystem.PackMan_TempMakeDir + ".", _namespace, ex); } } string newDataNewDir = PMFileSystem.MV_NewDataMan_Dir + "\\" + package.UniqueIDInMD5; if (Directory.Exists(newDataNewDir) && Helper.DeleteFolderSafely(newDataNewDir, _namespace, out exOut, LoggerMessages.GeneralError.REQUIRED_DIR_EXISTS_DEL_FAILED_ARG) == DeleteFolderResult.UserCancelled) { throw exOut; } if (Helper.CreateFolderSafely(newDataNewDir, _namespace, out exOut, new CreateFolderLogMessages(createFailed: NewProjectMessages.Error.ErrorMakeDir)) == CreateFolderResult.UserCancelled) { throw exOut; } string destArch = newDataNewDir + "\\" + Vars.INSTALLED_ARCH_FILENAME; ArchiveManagement.CreateNewZip(dirPath, destArch, _namespace); if (package.License.LicenseSource == RMPackLic.Source.File) { if (RMPackLic.IsAValidLicenseSourceFile(package.License.Data, package.XMLDirectory)) { string licSourcePath = package.XMLDirectory + "\\" + package.License.Data; string fileName = null; try { fileName = Path.GetFileName(licSourcePath); } catch (Exception ex) { package.License = null; log.WriteWarningLog(NewProjectMessages.Warning.LIC_COPY_FAILED_GEN, _namespace, ex); goto skipLic; } string destPath = newDataNewDir + "\\" + fileName; if (Helper.CopyFileSafely(licSourcePath, destPath, true, _namespace, out exOut, new CopyFileLogMessages(copyFileFailed: NewProjectMessages.Warning.LicCopyFailed, logGroup: log)) != CopyFileResult.Success) { package.License = null; goto skipLic; } package.License.Data = fileName; } else { package.License = null; log.WriteWarningLog(NewProjectMessages.Warning.LIC_COPY_FAILED_GEN, _namespace); } } skipLic: string newPackageXMLFile = newDataNewDir + "\\" + Vars.INSTALLED_XML_FILENAME; //package.Installed = true; //package.SetInstalledPropertyAll(RMPackObject.InstallStatus.Installed); package.SaveToFile(newPackageXMLFile, _namespace, RMPackage.SaveToFileMode.ExplicitAssetInfo, logMessage: new WriteAllTextLogMessages(writeFailed: LoggerMessages.PackageManagement.NewProject.Error.XMLFileSaveFailed)); log.WriteInformationLog(NewProjectMessages.Info.CopyInstallInfoDone(dirPath), _namespace); }
public static string InitPackageInstaller(string packagePath, bool globalPackageInstall, string _namespace, out LogDataList log, bool performChecksumMatching = false) { log = null; Logger.WriteInformationLog(LoggerMessages.PackageManagement.InitPackageInstaller.Info.INIT_START, _namespace); Exception outEx; if (Helper.DeleteFolderSafely(PMFileSystem.PackMan_TempInstall, _namespace, out outEx, LoggerMessages.GeneralError.UNABLE_DELETE_TEMP_DIR_ARG) == DeleteFolderResult.UserCancelled) // Null arg { throw outEx; } if (Helper.CreateFolderSafely(PMFileSystem.PackMan_TempInstall, _namespace, out outEx, LoggerMessages.GeneralError.UNABLE_CREATE_TEMP_DIR_ARG) == CreateFolderResult.UserCancelled) // Null arg { throw outEx; } string origPackPath = packagePath; if (!File.Exists(packagePath)) { try { throw new InstallFileNotFoundException(ExceptionMessages.PackageManagement.Installer.INSTALLER_FILE_NOT_FOUND + packagePath + ".", packagePath); } catch (Exception ex) { Logger.WriteErrorLog(LoggerMessages.PackageManagement.InitPackageInstaller.Error.MissInstallFile(packagePath), _namespace, ex, BasicDebugLogger.DebugErrorType.Error); throw; } } if (Path.GetExtension(packagePath).ToLower() == "." + RMPConstants.MiscFileExtensions.ZIP) { try { ArchiveManagement.ExtractZip(packagePath, PMFileSystem.PackMan_TempInstall, _namespace, performChecksumMatching); } catch (Exception ex) { Logger.WriteErrorLog(LoggerMessages.PackageManagement.InitPackageInstaller.Error.ExtractZipFailed(packagePath, PMFileSystem.PackMan_TempInstall), _namespace, ex, BasicDebugLogger.DebugErrorType.Error); throw; } packagePath = PMFileSystem.PackMan_TempInstall + "\\" + Vars.INSTALL_FILE_DEFAULT_FILENAME; if (!globalPackageInstall) { RMPackage packageParsed = null; try { packageParsed = new RMPackage(packagePath, _namespace, out log); } catch (Exception ex) { Logger.WriteErrorLog(InstallerMessages.Error.FAIL_PACKAGE_PARSE + origPackPath + ".", _namespace, ex, BasicDebugLogger.DebugErrorType.Error); throw; } if (packageParsed.Collections == null || packageParsed.Collections.Count == 0 || packageParsed.ContentsSummary == RMCollectionType.Generator) { try { throw new EmptyPackageException(); } catch (Exception ex) { Logger.WriteErrorLog(InstallerMessages.Error.EMPTY_PACKAGE, _namespace, ex, BasicDebugLogger.DebugErrorType.Error); throw; } } if (packageParsed.ContentsSummary.HasFlag(RMCollectionType.Generator)) { PackageUtil.RemoveGeneratorFilesAndCollection(packageParsed, PMFileSystem.PackMan_TempInstall, _namespace); packageParsed.SaveToFile(packagePath, _namespace, logMessage: new WriteAllTextLogMessages(writeFailed: InstallerMessages.Error.SaveCopyXMLFailed)); } } } else { string packageDir = Path.GetDirectoryName(packagePath); RMPackage packageParsed = null; try { packageParsed = new RMPackage(packagePath, _namespace, out log, null, false, !globalPackageInstall); } catch (Exception ex) { Logger.WriteErrorLog(InstallerMessages.Error.FAIL_PACKAGE_PARSE + origPackPath + ".", _namespace, ex, BasicDebugLogger.DebugErrorType.Error); throw; } try { PackageUtil.ExplicitCopyAssetsAndLicFileTo(packageParsed, packageDir, PMFileSystem.PackMan_TempInstall, _namespace); } catch (Exception ex) { Logger.WriteErrorLog(LoggerMessages.PackageManagement.InitPackageInstaller.Error.CopyPackageFilesFailed(packageDir, PMFileSystem.PackMan_TempInstall), _namespace, ex, BasicDebugLogger.DebugErrorType.Error); throw; } if (packageParsed.Collections == null || packageParsed.Collections.Count == 0) { try { throw new EmptyPackageException(); } catch (Exception ex) { Logger.WriteErrorLog(InstallerMessages.Error.EMPTY_PACKAGE, _namespace, ex, BasicDebugLogger.DebugErrorType.Error); throw; } } packagePath = PMFileSystem.PackMan_TempInstall + "\\" + Vars.INSTALL_FILE_DEFAULT_FILENAME; packageParsed.SaveToFile(packagePath, _namespace, logMessage: new WriteAllTextLogMessages(writeFailed: InstallerMessages.Error.SaveCopyXMLFailed)); } Logger.WriteInformationLog(LoggerMessages.PackageManagement.InitPackageInstaller.Info.INIT_DONE, _namespace); return(packagePath); }