TreeNode AddFiles(string[] filePaths, string _namespace) { if (filePaths == null) { return(null); } TreeNode retVal = null; LogDataList log = new LogDataList(); foreach (string path in filePaths) { try { retVal = AddFile(tViewAssets.SelectedNode, path, _namespace); } catch (Exception ex) { log.WriteErrorLog(frmPackageAssetsMessages.Error.UnableAddFileSingle(path), _namespace, ex); } } if (log != null && log.HasErrorsOrWarnings()) { Helper.ShowMessageBox(MessageBoxStrings.General.HAS_ERRORS_WARNINGS, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Warning); frmLogger loggerForm = new frmLogger(_logList: log); loggerForm.StartPosition = FormStartPosition.CenterParent; loggerForm.ShowDialog(); } 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); } }
DialogResult ViewImplicitDir(string path) { RMPackage temppackage = new RMPackage(); temppackage.Name = "Package Manager Probe"; string _namespace = MethodBase.GetCurrentMethod().ToLogFormatFullName(); LogDataList log = null; frmLoading loadingForm = new frmLoading(StringConst.frmLoading.RETRIEVING_ASSETS_DIR + path + "."); bool cancel = false; Thread thread = new Thread(delegate() { try { RMImplicit.RetrievePackFromDir(path, _namespace, false, out log, ref temppackage); } catch (Exception ex) { Helper.ShowMessageBox(MessageBoxStrings.GUI.frmPropPack.UNABLE_RETRIEVE_PACK, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error); Logger.WriteErrorLog(LoggerMessages.GUI.frmPropPack.Error.UnableRetrievePack(path), _namespace, ex, BasicDebugLogger.DebugErrorType.Error); cancel = true; loadingForm.SafeClose(); return; } loadingForm.SafeClose(); }); thread.Start(); loadingForm.ShowDialog(); if (cancel) { return(DialogResult.Cancel); } if (log != null && log.HasErrorsOrWarnings()) { Helper.ShowMessageBox(MessageBoxStrings.General.HAS_ERRORS_WARNINGS, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Warning); frmLogger loggerForm = new frmLogger(_logList: log); loggerForm.StartPosition = FormStartPosition.CenterParent; loggerForm.ShowDialog(); } frmPackageAssets packageAssetsForm = new frmPackageAssets(temppackage, true); return(packageAssetsForm.ShowDialog(this)); }
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; }
void CreateZIPFile(string _namespace, bool implicitAssets) { if (implicitAssets) { if (string.IsNullOrWhiteSpace(txtAssetDir.Text)) { Helper.ShowMessageBox(MessageBoxStrings.GUI.frmPropPack.NO_IMPLICIT_DIR_SEL_SAVE, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!Directory.Exists(txtAssetDir.Text)) { Helper.ShowMessageBox(MessageBoxStrings.GUI.frmPropPack.NO_IMPLICIT_DIR_SEL_SAVE, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { if (CustomAssetPack == null || CustomAssetPack.Collections == null || CustomAssetPack.Collections.Count == 0) { Helper.ShowMessageBox(MessageBoxStrings.GUI.frmPropPack.NO_EXPLICIT_ASSET_SEL_SAVE, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } RMPackage finalPackage = CreatePackageFromUserDetails(true, false); if (finalPackage == null) { return; } saveFileDialog.FileName = string.Empty; saveFileDialog.InitialDirectory = string.Empty; saveFileDialog.Filter = FileDialogFilters.INSTALL_ZIP; if (saveFileDialog.ShowDialog() == DialogResult.Cancel) { return; } Logger.WriteInformationLog(LoggerMessages.GUI.frmPropPack.Info.SAVE_ZIP_INIT + saveFileDialog.FileName + ".", _namespace); RMPackage temppackage = null; Thread thread = null; frmLoading loadingForm = null; bool error = false; if (implicitAssets) { temppackage = new RMPackage(); temppackage.Name = "Package Manager Probe"; LogDataList log = null; loadingForm = new frmLoading(StringConst.frmLoading.RETRIEVING_ASSETS_DIR + txtAssetDir.Text + "."); thread = new Thread(delegate() { try { RMImplicit.RetrievePackFromDir(txtAssetDir.Text, _namespace, false, out log, ref temppackage); } catch (Exception ex) { Helper.ShowMessageBox(MessageBoxStrings.GUI.frmPropPack.UNABLE_RETRIEVE_PACK, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error); Logger.WriteErrorLog(frmPropPackMessagse.Error.UnableRetrievePack(txtAssetDir.Text), _namespace, ex, BasicDebugLogger.DebugErrorType.Error); error = true; loadingForm.SafeClose(); return; } loadingForm.SafeClose(); }); thread.Start(); loadingForm.ShowDialog(); if (error) { return; } if (log != null && log.HasErrorsOrWarnings()) { Helper.ShowMessageBox(MessageBoxStrings.General.HAS_ERRORS_WARNINGS, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Warning); frmLogger loggerForm = new frmLogger(_logList: log); loggerForm.StartPosition = FormStartPosition.CenterParent; loggerForm.ShowDialog(); } } else { temppackage = CustomAssetPack; } RMPackLic license = null; loadingForm = new frmLoading(StringConst.frmLoading.COPYING_ASSETS_TO_TEMP + temppackage + "."); thread = new Thread(delegate() { try { CopyAssetFilesToTemp(_namespace, temppackage, out license); } catch (Exception ex) { Helper.ShowMessageBox(MessageBoxStrings.GUI.frmPropPack.ZIP_FILE_MAKE_ERR_GEN, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error); Logger.WriteErrorLog(frmPropPackMessagse.Error.ZipFileCopyAssetToTempErr(PMFileSystem.PackMan_TempMakeDir), _namespace, ex, BasicDebugLogger.DebugErrorType.Error); error = true; loadingForm.SafeClose(); return; } loadingForm.SafeClose(); }); thread.Start(); loadingForm.ShowDialog(); if (error) { CleanupMakeTemp(_namespace, false); return; } finalPackage.License = license; string xmlPath = PMFileSystem.PackMan_TempMakeDir + "\\" + Vars.INSTALL_FILE_DEFAULT_FILENAME; try { finalPackage.SaveToFile(xmlPath, _namespace, logMessage: new WriteAllTextLogMessages(writeFailed: frmPropPackMessagse.Error.ZipSaveXMLFailed)); } catch { Helper.ShowMessageBox(MessageBoxStrings.GUI.frmPropPack.ZIP_FILE_MAKE_ERR_GEN, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error); CleanupMakeTemp(_namespace, false); return; } loadingForm = new frmLoading(StringConst.frmLoading.CREATE_AN_ARCH_OF_PACK + saveFileDialog.FileName + "."); thread = new Thread(delegate() { try { ArchiveManagement.CreateNewZip(PMFileSystem.PackMan_TempMakeDir, saveFileDialog.FileName, _namespace); } catch (Exception ex) { Helper.ShowMessageBox(MessageBoxStrings.GUI.frmPropPack.ZIP_FILE_MAKE_ERR_GEN, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error); Logger.WriteErrorLog(frmPropPackMessagse.Error.ZIP_MAKE + saveFileDialog.FileName + ".", _namespace, ex, BasicDebugLogger.DebugErrorType.Error); loadingForm.SafeClose(); error = true; return; } loadingForm.SafeClose(); }); thread.Start(); loadingForm.ShowDialog(); if (error) { CleanupMakeTemp(_namespace, false); return; } MadeChanges = false; Helper.ShowMessageBox(MessageBoxStrings.GUI.frmPropPack.ZIP_SUCCESS + saveFileDialog.FileName + ".", MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Information); Logger.WriteInformationLog(LoggerMessages.GUI.frmPropPack.Info.SAVE_ZIP_SUCCESS + saveFileDialog.FileName + ".", _namespace); }