Ejemplo n.º 1
0
        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 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);
        }
        public static void RenumberParts(string parentFolderPath, string _namespace, out LogDataList log, bool relinkGlobalPackages = false)
        {
            log = new LogDataList();
            log.WriteInformationLog(LoggerMessages.GeneratorPartsManager.RenumberParts.Info.RENUMBER_START + parentFolderPath + ".", _namespace);
            Exception outEx;

            if (!Directory.Exists(parentFolderPath))
            {
                return;
            }


            if (Helper.DeleteFolderSafely(PMFileSystem.PackMan_TempRenumberDir, _namespace, out outEx, LoggerMessages.GeneralError.UNABLE_DELETE_TEMP_DIR_ARG) == DeleteFolderResult.UserCancelled)
            {
                throw outEx;
            }

            if (Helper.CreateFolderSafely(PMFileSystem.PackMan_TempRenumberDir, _namespace, out outEx, LoggerMessages.GeneralError.UNABLE_CREATE_TEMP_DIR_ARG) == CreateFolderResult.UserCancelled)
            {
                throw outEx;
            }

            RMPackage tempGenPack = new RMPackage();

            tempGenPack.Name = "Generator Parts Renumber Class";
            LogDataList outLog;

            RMImplicit.RetrievePackFromDir(parentFolderPath, _namespace, true, out outLog, ref tempGenPack);
            log.AppendLogs(outLog);

            if (tempGenPack.Collections == null || tempGenPack.Collections.Count == 0)
            {
                return;
            }

            List <ComparedPath> comparedPaths = null;

            foreach (RMCollection collection in tempGenPack.Collections)
            {
                if (collection is RMGeneratorCollection)
                {
                    RMGeneratorCollection genCollection = collection as RMGeneratorCollection;
                    try
                    {
                        if (genCollection.Parts != null)
                        {
                            comparedPaths = PerformRenumber(genCollection, parentFolderPath, _namespace);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteErrorLog(LoggerMessages.GeneratorPartsManager.RenumberParts.Error.RENUMBER_ABORT_GENERAL, _namespace, ex, BasicDebugLogger.DebugErrorType.CriticalError);
                        throw;
                    }
                }
            }



            if (comparedPaths != null && comparedPaths.Count > 0)
            {
                foreach (ComparedPath comparedPath in comparedPaths)
                {
                    string completeTempPath  = PMFileSystem.PackMan_TempRenumberDir + "\\" + comparedPath.New;
                    string completeFinalPath = parentFolderPath + "\\" + comparedPath.New;

                    MoveFileResult moveResult = Helper.MoveFileSafely(completeTempPath, completeFinalPath, true, _namespace, out outEx,
                                                                      new MoveFileLogMessages(sourceFileNotFound: LoggerMessages.GeneratorPartsManager.RenumberParts.Error.UnableMoveFinalSrcNotFound
                                                                                              , moveFileFailed: LoggerMessages.GeneratorPartsManager.RenumberParts.Error.UnableMoveFinal));
                    if (moveResult == MoveFileResult.UserCancelled || moveResult == MoveFileResult.SourceFileNotFound)
                    {
                        throw outEx;
                    }

                    if (relinkGlobalPackages && PackageManagement.GlobalPackages != null)
                    {
                        foreach (InstalledPackage package in PackageManagement.GlobalPackages)
                        {
                            if (package.Package != null)
                            {
                                RMGenFile foundFile = package.Package.FindGenFileWithPath(comparedPath.Old);
                                if (foundFile != null)
                                {
                                    foundFile.Path      = comparedPath.New;
                                    package.ChangesMade = true;
                                    goto continuehere;
                                }
                            }
                        }
                    }
                    continuehere :;
                }
                if (relinkGlobalPackages && PackageManagement.GlobalPackages != null)
                {
                    foreach (InstalledPackage package in PackageManagement.GlobalPackages)
                    {
                        if (package.ChangesMade && package.Package != null)
                        {
                            package.Package.SaveToFile(package.XMLPath, _namespace, logMessage : new WriteAllTextLogMessages(writeFailed : LoggerMessages.GeneratorPartsManager.RenumberParts.Error.FailedSaveXML));
                            package.ChangesMade = false;
                        }
                    }
                }
            }

            Helper.DeleteFolderSafely(PMFileSystem.PackMan_TempRenumberDir, _namespace, out outEx, LoggerMessages.GeneralError.UNABLE_DELETE_TEMP_DIR_ARG);
            log.WriteInformationLog(LoggerMessages.GeneratorPartsManager.RenumberParts.Info.RENUMBER_END + parentFolderPath + ".", _namespace);
        }