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);
            }
        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);
        }
            public static InstalledPackage InstallLocalPackage(string packagePath, ProjectPackMan openProject, string _namespace, out LogDataList log, bool ignoreClash = false, bool alreadyCopiedToTemp = false, bool procEvents = true, bool skipFileExistenceCheck = false)
            {
                log = new LogDataList();

                if (string.IsNullOrWhiteSpace(packagePath))
                {
                    try
                    {
                        throw new ArgumentNullException(ExceptionMessages.General.PACK_PATH_ARG_NULL);
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteErrorLog(InstallerMessages.Error.PACKAGE_PATH_NULL, _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                        throw;
                    }
                }

                if (openProject == null || string.IsNullOrWhiteSpace(openProject.DirectoryPath))
                {
                    try
                    {
                        throw new ArgumentException(ExceptionMessages.General.OPEN_PROJ_ARG_OR_DIRPATH_NULL);
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteErrorLog(InstallerMessages.Error.NO_OPEN_PROJECT, _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                        throw;
                    }
                }

                Logger.WriteInformationLog(InstallerMessages.Information.PACKAGE_INSTALL_START_L + packagePath + ".", _namespace);
                Exception   outEx;
                LogDataList outLog         = null;
                string      oldPackagePath = packagePath;

                try
                {
                    if (!alreadyCopiedToTemp)
                    {
                        packagePath = InitPackageInstaller(packagePath, false, _namespace, out outLog);
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteErrorLog(InstallerMessages.Error.INIT_ERROR + packagePath + ".", _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                    if (procEvents)
                    {
                        CleanupTempInstallDir(_namespace, false);
                    }
                    throw;
                }
                log.AppendLogs(outLog);

                RMPackage package = null;

                try
                {
                    package = new RMPackage(packagePath, _namespace, out outLog);
                }
                catch (Exception ex)
                {
                    log.AppendLogs(outLog);
                    Logger.WriteErrorLog(InstallerMessages.Error.XML_READ_ERROR + packagePath + ".", _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                    if (procEvents)
                    {
                        CleanupTempInstallDir(_namespace, false);
                    }
                    throw;
                }
                log.AppendLogs(outLog);

                if (!skipFileExistenceCheck)
                {
                    PerformPackageFilesExistenceCheck(package, _namespace, out outLog);
                    if (outLog != null)
                    {
                        log.Logs.AddRange(outLog.Logs);
                    }
                }

                if (!ignoreClash && openProject.InstalledPackages.FindByUID(package.UniqueID) != null)
                {
                    try
                    {
                        throw new PackageAlreadyExistsException(ExceptionMessages.General.PackWIDExists(package.UniqueID));
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteErrorLog(InstallerMessages.Error.PACKAGE_ALREADY_EXISTS, _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                        if (procEvents)
                        {
                            CleanupTempInstallDir(_namespace, false);
                        }
                        throw;
                    }
                }

                if (procEvents && OnPackageInstallBegin != null)
                {
                    OnPackageInstallBegin.Invoke(package, false, oldPackagePath, openProject);
                }

                try
                {
                    PerformInstallLocal(package, openProject.DirectoryPath, _namespace);
                }
                catch (Exception ex)
                {
                    Logger.WriteErrorLog(InstallerMessages.Error.INSTALL_PACK_FAILED, _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                    if (procEvents)
                    {
                        CleanupTempInstallDir(_namespace, false);
                    }
                    throw;
                }

                string packManStorePath = openProject.DirectoryPath + "\\" + Vars.PACKAGE_MANAGER_DIRECTORY;

                if (!Directory.Exists(packManStorePath) && Helper.CreateFolderSafely(packManStorePath, _namespace, out outEx, LoggerMessages.GeneralError.CREATE_REQUIRED_DIR_FAILED_ARG) == CreateFolderResult.UserCancelled)
                {
                    throw outEx;
                }
                InstalledPackage newInstall = null;

                try
                {
                    newInstall = CreateLocalInstalledFile(package, Path.GetDirectoryName(packagePath), packManStorePath, _namespace, out outLog);
                    openProject.InstalledPackages.AddSafely(newInstall);
                }
                catch
                {
                    if (procEvents)
                    {
                        CleanupTempInstallDir(_namespace, false);
                    }
                    throw;
                }
                if (outLog != null)
                {
                    log.Logs.AddRange(outLog.Logs);
                }

                if (!alreadyCopiedToTemp)
                {
                    CleanupTempInstallDir(_namespace, false);
                }

                if (procEvents && OnPackageInstalled != null)
                {
                    OnPackageInstalled.Invoke(package, false, oldPackagePath, openProject);
                }

                Logger.WriteInformationLog(InstallerMessages.Information.PACKAGE_INSTALL_DONE_L, _namespace);
                return(newInstall);
            }
            // ---- 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);
            }
            // -------- Global Packages -------- //
            public static InstalledPackage InstallGlobalPackage(string packagePath, string _namespace, out LogDataList log, bool ignoreClash = false, bool alreadyCopiedToTemp = false, bool procEvents = true, bool skipFileExistenceCheck = false)
            {
                Logger.WriteInformationLog(InstallerMessages.Information.PACKAGE_INSTALL_START_G + packagePath + ".", _namespace);
                log = new LogDataList();
                string      oldPackagePath = packagePath;
                LogDataList outLog         = null;

                try
                {
                    if (!alreadyCopiedToTemp)
                    {
                        packagePath = packagePath = InitPackageInstaller(packagePath, true, _namespace, out outLog);
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteErrorLog(InstallerMessages.Error.INIT_ERROR + packagePath + ".", _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                    if (procEvents)
                    {
                        CleanupTempInstallDir(_namespace, false);
                    }
                    throw;
                }
                log.AppendLogs(outLog);

                RMPackage package = null;

                try
                {
                    package = new RMPackage(packagePath, _namespace, out outLog);
                }
                catch (Exception ex)
                {
                    log.AppendLogs(outLog);
                    Logger.WriteErrorLog(InstallerMessages.Error.XML_READ_ERROR + packagePath + ".", _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                    if (procEvents)
                    {
                        CleanupTempInstallDir(_namespace, false);
                    }
                    throw;
                }
                log.AppendLogs(outLog);

                if (!skipFileExistenceCheck)
                {
                    PerformPackageFilesExistenceCheck(package, _namespace, out outLog);
                    log.AppendLogs(outLog);
                }

                if (!ignoreClash && GlobalPackages.FindByUID(package.UniqueID) != null)
                {
                    try
                    {
                        throw new PackageAlreadyExistsException(ExceptionMessages.General.PackWIDExists(package.UniqueID));
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteErrorLog(InstallerMessages.Error.PACKAGE_ALREADY_EXISTS, _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                        if (procEvents)
                        {
                            CleanupTempInstallDir(_namespace, false);
                        }
                        throw;
                    }
                }

                if (procEvents && OnPackageInstallBegin != null)
                {
                    OnPackageInstallBegin.Invoke(package, true, oldPackagePath, null);
                }

                try
                {
                    PerformInstallGlobal(package, _namespace);
                }
                catch (Exception ex)
                {
                    Logger.WriteErrorLog(InstallerMessages.Error.INSTALL_PACK_FAILED, _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                    if (procEvents)
                    {
                        CleanupTempInstallDir(_namespace, false);
                    }
                    throw;
                }

                InstalledPackage newInstall = null;

                try
                {
                    newInstall = CreateGlobalInstalledFile(package, Path.GetDirectoryName(packagePath), _namespace, out outLog);
                    GlobalPackages.AddSafely(newInstall);
                }
                catch
                {
                    if (procEvents)
                    {
                        CleanupTempInstallDir(_namespace, false);
                    }
                    throw;
                }
                log.AppendLogs(outLog);

                if (!alreadyCopiedToTemp)
                {
                    CleanupTempInstallDir(_namespace, false);
                }

                if (OnPackageInstalled != null)
                {
                    OnPackageInstalled.Invoke(package, true, oldPackagePath, null);
                }
                Logger.WriteInformationLog(InstallerMessages.Information.PACKAGE_INSTALL_DONE_G, _namespace);
                return(newInstall);
            }
            public static InstalledPackage UpdateLocalPackage(string pathToInstaller, ProjectPackMan openProject, bool packageAlreadyCopiedToTemp, string _namespace, out LogDataList log, bool skipInstallFileExistenceCheck = false)
            {
                log = new LogDataList();
                if (openProject == null)
                {
                    try
                    {
                        throw new NullProjectException(ExceptionMessages.General.OPEN_PROJ_ARG_NULL);
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteErrorLog(LoggerMessages.PackageManagement.Updater.Error.NO_OPEN_PROJ, _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                        throw;
                    }
                }
                if (string.IsNullOrWhiteSpace(openProject.DirectoryPath))
                {
                    try
                    {
                        throw new InvalidPathException(ExceptionMessages.General.OPEN_PROJ_DIR_PATH_ARG_NULL, openProject.DirectoryPath);
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteErrorLog(LoggerMessages.PackageManagement.Updater.Error.INVALID_OPEN_PROJ_DIR, _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                        throw;
                    }
                }
                string origPath = pathToInstaller;

                Logger.WriteInformationLog(LoggerMessages.PackageManagement.Updater.Information.UpdatePackageStart(openProject.DirectoryPath, pathToInstaller), _namespace);
                LogDataList outLog = null;

                try
                {
                    if (!packageAlreadyCopiedToTemp)
                    {
                        pathToInstaller = Installer.InitPackageInstaller(pathToInstaller, false, _namespace, out outLog);
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteErrorLog(LoggerMessages.PackageManagement.Updater.Error.UNABLE_EXTRACT_LOCAL + pathToInstaller + ".", _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                    throw;
                }
                log.AppendLogs(outLog);


                RMPackage package = null;

                try
                {
                    package = new RMPackage(pathToInstaller, _namespace, out outLog);
                }
                catch (Exception ex)
                {
                    log.AppendLogs(outLog);
                    Logger.WriteErrorLog(LoggerMessages.PackageManagement.Updater.Error.UNABLE_PARSE_XML_LOCAL + pathToInstaller + ".", _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                    throw;
                }
                log.AppendLogs(outLog);

                if (openProject.InstalledPackages == null)
                {
                    try
                    {
                        throw new PackageNotFoundException(false, ExceptionMessages.General.PROJ_NO_PACKAGES);
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteErrorLog(LoggerMessages.PackageManagement.Updater.Error.OPEN_PROJ_NOT_ABLE_FIND_PACK, _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                        throw;
                    }
                }

                InstalledPackage packageInstalled = openProject.InstalledPackages.FindByUID(package.UniqueID);

                if (packageInstalled == null)
                {
                    try
                    {
                        throw new PackageNotFoundException(false, ExceptionMessages.General.PackWIDNotFound(package.UniqueID));
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteErrorLog(LoggerMessages.PackageManagement.Updater.Error.OPEN_PROJ_NOT_ABLE_FIND_PACK, _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                        throw;
                    }
                }

                if (OnPackageUpdateBegin != null)
                {
                    OnPackageUpdateBegin.Invoke(packageInstalled, package, false, origPath, openProject);
                }


                try
                {
                    Uninstaller.UninstallLocalPackage(openProject, package.UniqueID, _namespace, out outLog, procEvents: false);
                }
                catch (Exception ex)
                {
                    Logger.WriteErrorLog(LoggerMessages.PackageManagement.Updater.Error.FAILED_UNINSTALL, _namespace, ex, BasicDebugLogger.DebugErrorType.CriticalError);
                    throw;
                }
                log.AppendLogs(outLog);


                InstalledPackage newlyInstalledPackage = null;

                try
                {
                    newlyInstalledPackage = Installer.InstallLocalPackage(pathToInstaller, openProject, _namespace, out outLog, true, true, false, skipInstallFileExistenceCheck);
                }
                catch (Exception ex)
                {
                    Logger.WriteErrorLog(LoggerMessages.PackageManagement.Updater.Error.FAILED_INSTALL, _namespace, ex, BasicDebugLogger.DebugErrorType.CriticalError);
                    throw;
                }
                log.AppendLogs(outLog);

                if (OnPackageUpdateDone != null)
                {
                    OnPackageUpdateDone.Invoke(newlyInstalledPackage, newlyInstalledPackage.Package, false, origPath, openProject);
                }

                Logger.WriteInformationLog(LoggerMessages.PackageManagement.Updater.Information.UpdatePackageDone(origPath), _namespace);
                return(newlyInstalledPackage);
            }
            public static InstalledPackage UpdateGlobalPackage(string pathToInstaller, string _namespace, out LogDataList log, bool alreadyCopiedToTemp = false, bool skipInstallFileExistenceCheck = false)
            {
                log = new LogDataList();
                Logger.WriteInformationLog(LoggerMessages.PackageManagement.Updater.Information.UPDATE_PACKAGE_START_G + pathToInstaller + ".", _namespace);
                string      origPath = pathToInstaller;
                LogDataList outLog   = null;

                try
                {
                    if (!alreadyCopiedToTemp)
                    {
                        pathToInstaller = Installer.InitPackageInstaller(pathToInstaller, true, _namespace, out outLog);
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteErrorLog(LoggerMessages.PackageManagement.Updater.Error.UNABLE_EXTRACT_GLOBAL + pathToInstaller + ".", _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                    throw;
                }
                log.AppendLogs(outLog);

                RMPackage package = null;

                try
                {
                    package = new RMPackage(pathToInstaller, _namespace, out outLog);
                }
                catch (Exception ex)
                {
                    log.AppendLogs(outLog);
                    Logger.WriteErrorLog(LoggerMessages.PackageManagement.Updater.Error.XML_INVALID + pathToInstaller + ".", _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                    throw;
                }
                log.AppendLogs(outLog);

                if (GlobalPackages == null)
                {
                    try
                    {
                        throw new NullGlobalPackagesException();
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteErrorLog(LoggerMessages.PackageManagement.Updater.Error.NO_GLOBAL_PACKAGES, _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                        throw;
                    }
                }

                InstalledPackage packageInstalled = GlobalPackages.FindByUID(package.UniqueID);

                if (packageInstalled == null)
                {
                    try
                    {
                        throw new PackageNotFoundException(true);
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteWarningLog(LoggerMessages.PackageManagement.Updater.Warning.PACKAGE_TO_BE_UPDATED_NOT_FOUND, _namespace, ex);
                        throw;
                    }
                }



                if (OnPackageUpdateBegin != null)
                {
                    OnPackageUpdateBegin.Invoke(packageInstalled, package, true, origPath, null);
                }


                try
                {
                    Uninstaller.UninstallGlobalPackage(package.UniqueID, _namespace, out outLog, renumberParts: false, procEvents: false);
                }
                catch (Exception ex)
                {
                    Logger.WriteErrorLog(LoggerMessages.PackageManagement.Updater.Error.FAILED_UNINSTALL, _namespace, ex, BasicDebugLogger.DebugErrorType.CriticalError);
                    throw;
                }
                log.AppendLogs(outLog);

                InstalledPackage newlyInstalledPackage = null;

                try
                {
                    newlyInstalledPackage = Installer.InstallGlobalPackage(pathToInstaller, _namespace, out outLog, true, true, false, skipInstallFileExistenceCheck);
                }
                catch (Exception ex)
                {
                    Logger.WriteErrorLog(LoggerMessages.PackageManagement.Updater.Error.FAILED_INSTALL, _namespace, ex, BasicDebugLogger.DebugErrorType.CriticalError);
                    throw;
                }
                log.AppendLogs(outLog);


                if (OnPackageUpdateDone != null)
                {
                    OnPackageUpdateDone.Invoke(newlyInstalledPackage, newlyInstalledPackage.Package, true, origPath, null);
                }

                Logger.WriteInformationLog(LoggerMessages.PackageManagement.Updater.Information.UPDATE_PACKAGE_DONE_G, _namespace);
                return(newlyInstalledPackage);
            }