public ProjectPackMan(string ProjectDirectoryPath, string _namespace, out LogDataList log) { log = new LogDataList(); if (!Directory.Exists(ProjectDirectoryPath)) { throw new DirectoryNotFoundException(ExceptionMessages.General.DirNotFound(ProjectDirectoryPath)); } DirectoryPath = ProjectDirectoryPath; string packManStorePath = ProjectDirectoryPath + "\\" + Vars.PACKAGE_MANAGER_DIRECTORY; if (!Directory.Exists(packManStorePath)) { return; } string[] directories = Directory.GetDirectories(packManStorePath); if (directories == null || directories.Length == 0) { return; } foreach (string directory in directories) { try { LogDataList outLog; InstalledPackages.AddSafely(new InstalledPackage(directory, _namespace, out outLog)); log.AppendLogs(outLog); } catch (Exception ex) { log.WriteWarningLog(LoggerMessages.PackageManagement.ProjectPackMan.Warning.InvalidPackage(directory), _namespace, ex); } } }
static InstalledPackage CreateLocalInstalledFile(RMPackage package, string sourceFolder, string packManStorePath, string _namespace, out LogDataList log) { log = new LogDataList(); string newInstalledDir = packManStorePath + "\\" + package.UniqueIDInMD5; LogDataList outLog = null; try { CreateInstalledFile(package, sourceFolder, newInstalledDir, _namespace, out outLog); } catch (Exception ex) { Logger.WriteErrorLog(InstallerMessages.Error.UNABLE_CREATE_INSTALLED_FILES, _namespace, ex, BasicDebugLogger.DebugErrorType.Error); throw; } log.AppendLogs(outLog); InstalledPackage retVal = null; try { retVal = new InstalledPackage(newInstalledDir, _namespace, out outLog); } catch (Exception ex) { log.WriteWarningLog(InstallerMessages.Warning.UNABLE_LOAD_PACK, _namespace, ex); } log.AppendLogs(outLog); return(retVal); }
static InstalledPackage CreateGlobalInstalledFile(RMPackage package, string sourceFolder, string _namespace, out LogDataList log) { log = new LogDataList(); string newInstalledDir = PMFileSystem.PackMan_ManDir + "\\" + package.UniqueIDInMD5; LogDataList outLog = null; try { CreateInstalledFile(package, sourceFolder, newInstalledDir, _namespace, out outLog); } catch (Exception ex) { Logger.WriteErrorLog(InstallerMessages.Error.UNABLE_CREATE_INSTALLED_FILES, _namespace, ex, BasicDebugLogger.DebugErrorType.Error); throw; } log.AppendLogs(outLog); InstalledPackage retVal = null; try { retVal = new InstalledPackage(newInstalledDir, _namespace, out outLog); } catch (Exception ex) { log.WriteWarningLog(InstallerMessages.Warning.UNABLE_LOAD_PACK, _namespace, ex); } if (outLog != null) { log.Logs.AddRange(outLog.Logs); } try { NewProject.CopyPackageInstallInfo(sourceFolder, _namespace, out outLog); } catch (Exception ex) { log.WriteWarningLog(InstallerMessages.Warning.UNABLE_COPY_NEWDATA_DIR, _namespace, ex); } if (outLog != null) { log.Logs.AddRange(outLog.Logs); } return(retVal); }
public static void InitializePackageManagement(this frmMain form) { string _namespace = MethodBase.GetCurrentMethod().ToLogFormatFullName(); string[] directories = null; try { directories = Directory.GetDirectories(PMFileSystem.PackMan_ManDir); } catch (Exception ex) { Helper.ShowMessageBox(MessageBoxStrings.PackageManagement.INIT_GLOBAL_GET_DIRS_ERROR, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error); Logger.WriteErrorLog(LoggerMessages.PackageManagement.GLOBAL_DIR_ERROR + PMFileSystem.PackMan_ManDir + ".", _namespace, ex, BasicDebugLogger.DebugErrorType.Error); return; } if (directories == null || directories.Length == 0) { return; } LogDataList log = new LogDataList(); foreach (string directory in directories) { LogDataList outLog = null; try { GlobalPackages.AddSafely(new InstalledPackage(directory, _namespace, out outLog)); } catch (Exception ex) { log.WriteWarningLog(LoggerMessages.PackageManagement.InstalledPackage.Error.ErrorTryLoad(directory), _namespace, ex); if (ex is InvalidInstalledPackageFile castedEx) { log.WriteErrorLog(castedEx.Message, _namespace, castedEx.InnerException); } else { log.WriteErrorLog(ex.Message, _namespace, ex); } } log.AppendLogs(outLog); } if (log.HasErrorsOrWarnings()) { Helper.ShowMessageBox(MessageBoxStrings.PackageManagement.INIT_ERROR_WARNS_FOUND, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { Logger.WriteInformationLog(LoggerMessages.PackageManagement.INIT_GLOBAL_DIR + PMFileSystem.PackMan_ManDir + ".", _namespace); } }
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 void MakeInstalledPackageFileForDefPackage(string XmlPath, string _namespace, out LogDataList log, string rootDirectory = null, bool ignoreClash = false) { log = new LogDataList(); log.WriteInformationLog(MakeInstalledPackagesMessages.Info.CreateInstalledPack(XmlPath, rootDirectory), _namespace); LogDataList outLog = null; RMPackage newPack = null; Exception exResult; try { newPack = new RMPackage(XmlPath, _namespace, out outLog, rootDirectory); } catch (Exception ex) { log.AppendLogs(outLog); Logger.WriteErrorLog(MakeInstalledPackagesMessages.Error.InvalidXML(XmlPath, rootDirectory), _namespace, ex, BasicDebugLogger.DebugErrorType.Error); throw; } log.AppendLogs(outLog); string origDir = newPack.XMLDirectory; InstalledPackage installedPackage = GlobalPackages.FindByUID(newPack.UniqueID); string newPackDir = PMFileSystem.PackMan_ManDir + "\\" + newPack.UniqueIDInMD5; if (installedPackage != null) { if (ignoreClash) { Logger.WriteWarningLog(MakeInstalledPackagesMessages.Warning.InstalledPackExistsExit(newPack.Name), _namespace, null); return; } else { log.WriteWarningLog(MakeInstalledPackagesMessages.Warning.InstalledPackExistsReplace(newPack.Name), _namespace); if (Helper.DeleteFolderSafely(newPackDir, _namespace, out exResult, new DeleteFolderLogMessages(deleteFailed: MakeInstalledPackagesMessages.Error.UnableToDeleteExistingFolder)) == DeleteFolderResult.UserCancelled) { throw exResult; } } } string tempPackDir = PMFileSystem.PackMan_TempDir + "\\" + newPack.UniqueIDInMD5; if (Helper.DeleteFolderSafely(tempPackDir, _namespace, out exResult, LoggerMessages.GeneralError.UNABLE_DELETE_TEMP_DIR_ARG) == DeleteFolderResult.UserCancelled) { throw exResult; } if (Helper.CreateFolderSafely(newPackDir, _namespace, out exResult, new CreateFolderLogMessages(createFailed: MakeInstalledPackagesMessages.Error.UnableCreateRootDir)) == CreateFolderResult.UserCancelled) { throw exResult; } if (Helper.CreateFolderSafely(tempPackDir, _namespace, out exResult, LoggerMessages.GeneralError.UNABLE_CREATE_TEMP_DIR_ARG) == CreateFolderResult.UserCancelled) { throw exResult; } string backupXMLInstallerPath = tempPackDir + "\\" + Vars.INSTALL_FILE_DEFAULT_FILENAME; makeInstPackageAnon onErrorBackup = delegate() { if (Helper.ShowMessageBox(MessageBoxStrings.PackageManagement.FailedMakeInstallPackageArch(newPack.Name), MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { return(true); } Logger.WriteErrorLog(MakeInstalledPackagesMessages.Error.UserRequiredOnFailedBackUpNo(newPack.Name), _namespace, null, BasicDebugLogger.DebugErrorType.Error); Helper.DeleteFolderSafely(tempPackDir, _namespace, out exResult, LoggerMessages.GeneralError.UNABLE_DELETE_TEMP_DIR_ARG); Helper.DeleteFolderSafely(newPackDir, _namespace, out exResult, LoggerMessages.GeneralError.UNABLE_DELETE_UNUSED_DIR_ARG); return(false); }; string rootPathOfFiles; if (rootDirectory == null) { rootPathOfFiles = newPack.XMLDirectory; } else { rootPathOfFiles = rootDirectory; } PackageUtil.ExplicitCopyAssetsAndLicFileTo(newPack, rootPathOfFiles, tempPackDir, _namespace); try { newPack.SaveToFile(backupXMLInstallerPath, _namespace, RMPackage.SaveToFileMode.ImplicitAssetInfo, logMessage: new WriteAllTextLogMessages(writeFailed: MakeInstalledPackagesMessages.Error.UnableCreateInstXML, logGroup: log)); } catch { if (onErrorBackup()) { goto onerrorContinue; } throw; } string archDest = newPackDir + "\\" + Vars.INSTALLED_ARCH_FILENAME; try { ArchiveManagement.CreateNewZip(tempPackDir, archDest, _namespace); } catch (Exception ex) { log.WriteWarningLog(MakeInstalledPackagesMessages.Error.UnableMakeBackup(newPack.Name, tempPackDir, archDest), _namespace, ex); if (onErrorBackup()) { goto onerrorContinue; } throw; } onerrorContinue: //newPack.Installed = true; //newPack.SetInstalledPropertyAll(RMPackObject.InstallStatus.Installed); if (newPack.License != null && newPack.License.LicenseSource == RMPackLic.Source.File && RMPackLic.IsAValidLicenseSourceFile(newPack.License.Data, origDir)) { string licSourcePath = origDir + "\\" + newPack.License.Data; string fileName = Path.GetFileName(licSourcePath); string destPath = newPackDir + "\\" + fileName; CopyFileResult copyRes = Helper.CopyFileSafely(licSourcePath, destPath, true, _namespace, out exResult, new CopyFileLogMessages(copyFileFailed: MakeInstalledPackagesMessages.Error.UnableCopyLicenseFile)); if (copyRes == CopyFileResult.UserCancelled || copyRes == CopyFileResult.SourceFileNotFound) { Helper.DeleteFolderSafely(tempPackDir, _namespace, out exResult, LoggerMessages.GeneralError.UNABLE_DELETE_TEMP_DIR_ARG); Helper.DeleteFolderSafely(newPackDir, _namespace, out exResult, LoggerMessages.GeneralError.UNABLE_DELETE_UNUSED_DIR_ARG); throw exResult; } newPack.License.Data = fileName; } string installedXMLDest = newPackDir + "\\" + Vars.INSTALLED_XML_FILENAME; newPack.Implicit = false; try { newPack.SaveToFile(installedXMLDest, _namespace, RMPackage.SaveToFileMode.ExplicitAssetInfo, logMessage: new WriteAllTextLogMessages(writeFailed: MakeInstalledPackagesMessages.Error.UnableMakeMainXML)); } catch { Helper.DeleteFolderSafely(tempPackDir, _namespace, out exResult, LoggerMessages.GeneralError.UNABLE_DELETE_TEMP_DIR_ARG); Helper.DeleteFolderSafely(newPackDir, _namespace, out exResult, LoggerMessages.GeneralError.UNABLE_DELETE_UNUSED_DIR_ARG); throw; } try { GlobalPackages.AddSafely(new InstalledPackage(newPackDir, _namespace, out outLog)); } catch (Exception ex) { log.WriteWarningLog(LoggerMessages.PackageManagement.InstalledPackage.Error.ErrorTryLoad(newPackDir), _namespace, ex); if (ex is InvalidInstalledPackageFile castedEx) { log.WriteErrorLog(castedEx.Message, _namespace, castedEx.InnerException); } else { log.WriteErrorLog(ex.Message, _namespace, ex); } } log.AppendLogs(outLog); try { NewProject.CopyPackageInstallInfo(tempPackDir, _namespace, out outLog); } catch (Exception ex) { log.WriteWarningLog(MakeInstalledPackagesMessages.Warning.UnableCopyNewProj(newPack.Name, newPackDir), _namespace, ex); } log.AppendLogs(outLog); Helper.DeleteFolderSafely(tempPackDir, _namespace, out exResult, LoggerMessages.GeneralError.UNABLE_DELETE_TEMP_DIR_ARG); log.WriteInformationLog(MakeInstalledPackagesMessages.Info.SUCCESS_CREATE + newPack.Name + ".", _namespace); }
void ProcessCustomAssetsCommonPath(string _namespace) { if (CustomAssetPack == null || CustomAssetPack.Collections == null || CustomAssetPack.Collections.Count == 0) { btnSaveXML.Enabled = true; FormattedCustomAssetPack = null; return; } FormattedCustomAssetPack = (RMPackage)CustomAssetPack.Clone(); if (License != null) { FormattedCustomAssetPack.License = License.Clone(); } List <RMPackFile> retrievedFiles = null; string commonPath = null; frmLoading loadingForm = new frmLoading(StringConst.frmLoading.FORMAT_PACK_META); Thread thread = new Thread(delegate() { commonPath = FormattedCustomAssetPack.TrimPrefixCommonPathOfFiles(out retrievedFiles, true); loadingForm.SafeClose(); }); thread.Start(); loadingForm.ShowDialog(); if (retrievedFiles == null || retrievedFiles.Count == 0 || ((FormattedCustomAssetPack.License == null || FormattedCustomAssetPack.License.LicenseSource != RMPackLic.Source.File) && retrievedFiles.Count == 1)) { btnSaveXML.Enabled = true; if (retrievedFiles != null && retrievedFiles.Count == 1) { CustomAssetsCommonPath = Path.GetDirectoryName(retrievedFiles[0].Path); } return; // User did not select any assets or has selected 1 asset but the license source is not a file. } if (string.IsNullOrWhiteSpace(commonPath)) { Helper.ShowMessageBox(MessageBoxStrings.GUI.frmPropPack.NO_COMMON_PATH, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Warning); CustomAssetsCommonPath = null; btnSaveXML.Enabled = false; return; } bool allPathRelative = true; LogDataList warningLog = new LogDataList(); if (FormattedCustomAssetPack.License != null && FormattedCustomAssetPack.License.LicenseSource == RMPackLic.Source.File && !FormattedCustomAssetPack.License.NonRootedLicenseFile) { warningLog.WriteWarningLog(frmPropPackMessagse.Warning.NonCommonPathFile(License.Data, commonPath, true), _namespace); allPathRelative = false; } foreach (RMPackFile file in retrievedFiles) { if (!file.NonRootedPath) { warningLog.WriteWarningLog(frmPropPackMessagse.Warning.NonCommonPathFile(file.Path, commonPath), _namespace); allPathRelative = false; } } CustomAssetsCommonPath = commonPath; if (allPathRelative) { btnSaveXML.Enabled = true; return; } if (warningLog != null && warningLog.HasErrorsOrWarnings()) { Helper.ShowMessageBox(MessageBoxStrings.General.HAS_ERRORS_WARNINGS, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Warning); frmLogger loggerForm = new frmLogger(_logList: warningLog); loggerForm.StartPosition = FormStartPosition.CenterParent; loggerForm.ShowDialog(); } btnSaveXML.Enabled = false; }
// ---- Helper Methods ---- // static void CreateInstalledFile(RMPackage package, string sourceFolder, string newInstalledDir, string _namespace, out LogDataList log) { log = new LogDataList(); log.WriteInformationLog(InstallerMessages.Information.CREATE_INSTALLED_FILE_START, _namespace); Exception outEx; if (Helper.CreateFolderSafely(newInstalledDir, _namespace, out outEx, LoggerMessages.GeneralError.CREATE_REQUIRED_DIR_FAILED_ARG) == CreateFolderResult.UserCancelled) { throw outEx; } try { Helper.DeleteEmptySubDir(sourceFolder, _namespace); } catch (Exception ex) { log.WriteWarningLog(InstallerMessages.Warning.DELETE_SUB_DIR + sourceFolder + ".", _namespace, ex); } string destArch = newInstalledDir + "\\" + Vars.INSTALLED_ARCH_FILENAME; try { ArchiveManagement.CreateNewZip(sourceFolder, destArch, _namespace); } catch (Exception ex) { log.WriteWarningLog(InstallerMessages.Warning.UnableMakeZip(destArch), _namespace, ex); } if (package.License == null) { log.WriteWarningLog(InstallerMessages.Warning.LIC_SOURCE_NULL, _namespace); } else { 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(InstallerMessages.Warning.INVALID_FILE_NAME_LIC, _namespace, ex); goto skipLic; } string destPath = newInstalledDir + "\\" + fileName; if (Helper.CopyFileSafely(licSourcePath, destPath, true, _namespace, out outEx, new CopyFileLogMessages(copyFileFailed: InstallerMessages.Warning.UnableCopyLicFile, logGroup: log)) != CopyFileResult.Success) { package.License = null; goto skipLic; } package.License.Data = fileName; } else { package.License = null; log.WriteWarningLog(InstallerMessages.Warning.INVALID_LIC, _namespace); } } } skipLic: string saveToXMLPath = newInstalledDir + "\\" + Vars.INSTALLED_XML_FILENAME; package.Implicit = false; package.SaveToFile(saveToXMLPath, _namespace, RMPackage.SaveToFileMode.ExplicitAssetInfo, logMessage: new WriteAllTextLogMessages(writeFailed: InstallerMessages.Error.UnableSaveInstalledXml)); log.WriteInformationLog(InstallerMessages.Information.CREATE_INSTALLED_FILE_DONE, _namespace); }