Пример #1
0
            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);
            }
        void CopyAssetFilesToTemp(string _namespace, RMPackage rootedFilesPack, out RMPackLic license)
        {
            license = License;
            if (rootedFilesPack == null || rootedFilesPack.Collections == null || rootedFilesPack.Collections.Count == 0)
            {
                throw new NullReferenceException(ExceptionMessages.GUI.frmPropPack.NO_ASSETS_SEL);
            }
            Exception outEx;

            CleanupMakeTemp(_namespace);


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

            try
            {
                PackageUtil.ImplicitCopyAssetFilesTo(rootedFilesPack, PMFileSystem.PackMan_TempMakeDir, _namespace);
            }
            catch (Exception ex)
            {
                Logger.WriteErrorLog(frmPropPackMessagse.Error.COPY_SEL_FAILED + PMFileSystem.PackMan_TempMakeDir + ".", _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                CleanupMakeTemp(_namespace, false);
                throw;
            }

            if (License != null && License.LicenseSource == RMPackLic.Source.File)
            {
                if (string.IsNullOrWhiteSpace(License.Data))
                {
                    try
                    {
                        throw new InvalidPackageLicenseException(ExceptionMessages.RMPackage.LIC_FILE_PATH_NULL, InvalidPackageLicenseException.WhichInvalid.InvalidLicenseFile, rootedFilesPack);
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteErrorLog(frmPropPackMessagse.Error.LICENSE_FILE_NULL, _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                        CleanupMakeTemp(_namespace, false);
                        throw;
                    }
                }
                if (!File.Exists(License.Data))
                {
                    try
                    {
                        throw new InvalidPackageLicenseException(ExceptionMessages.RMPackage.LicFileNotExist(License.Data), InvalidPackageLicenseException.WhichInvalid.InvalidLicenseFile, rootedFilesPack);
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteErrorLog(frmPropPackMessagse.Error.LicenseFileNotExist(License.Data), _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                        CleanupMakeTemp(_namespace, false);
                        throw;
                    }
                }
                string destLicFile     = Vars.LICENSE_FILE_DEF_NAME + Path.GetExtension(License.Data);
                string destLicFilePath = PMFileSystem.PackMan_TempMakeDir + "\\" + destLicFile;
                if (Helper.CopyFileSafely(License.Data, destLicFilePath, true, _namespace, out outEx, new CopyFileLogMessages(copyFileFailed: frmPropPackMessagse.Error.LicenseFileNonCopy)) != CopyFileResult.Success)
                {
                    CleanupMakeTemp(_namespace, false);
                    throw outEx;
                }
                license      = License.Clone();
                license.Data = destLicFile;
            }
        }
Пример #3
0
        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);
        }
            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);
            }