public static bool ExtractPackage(DTE dte, string toolPath, string unmanagedZipPath, string managedZipPath, Project project,
                                          CrmDevExSolutionPackage crmDevExSolutionPackage, DirectoryInfo extractedFolder, string commandArgs)
        {
            string solutionProjectFolder = GetProjectSolutionFolder(project, crmDevExSolutionPackage.ProjectFolder);

            dte.ExecuteCommand($"shell {toolPath}", commandArgs);

            //Need this. Extend to allow bigger solutions to unpack
            //TODO: Better way?
            System.Threading.Thread.Sleep(10000);

            bool solutionFileDelete    = RemoveDeletedItems(extractedFolder.FullName, project.ProjectItems, crmDevExSolutionPackage.ProjectFolder);
            bool solutionFileAddChange = ProcessDownloadedSolution(extractedFolder, Path.GetDirectoryName(project.FullName), project.ProjectItems);

            Directory.Delete(extractedFolder.FullName, true);

            if (!crmDevExSolutionPackage.SaveSolutions)
            {
                return(true);
            }

            //Solution change or file not present
            bool solutionChange = solutionFileDelete || solutionFileAddChange;
            bool solutionStored = StoreSolutionFile(unmanagedZipPath, project, solutionProjectFolder, solutionChange);

            if (crmDevExSolutionPackage.DownloadManaged && !string.IsNullOrEmpty(managedZipPath))
            {
                solutionStored = StoreSolutionFile(managedZipPath, project, solutionProjectFolder, solutionChange);
            }

            return(solutionStored);
        }
        public static void AddOrUpdateMapping(string solutionPath, Project project, CrmDevExSolutionPackage solutionPackage, Guid organizationId)
        {
            CrmDexExConfig crmDexExConfig = CoreMapping.GetConfigFile(solutionPath, project.UniqueName, organizationId);
            CrmDevExConfigOrgMap crmDevExConfigOrgMap = CoreMapping.GetOrgMap(ref crmDexExConfig, organizationId, project.UniqueName);

            crmDevExConfigOrgMap.SolutionPackage = solutionPackage;

            ConfigFile.UpdateConfigFile(solutionPath, crmDexExConfig);
        }
        public static string GetExtractCommandArgs(string unmanagedZipPath, string managedZipPath, Project project, DirectoryInfo extractedFolder,
                                                   CrmDevExSolutionPackage crmDevExSolutionPackage)
        {
            string projectPath = CrmDeveloperExtensions2.Core.Vs.ProjectWorker.GetProjectPath(project);

            if (string.IsNullOrEmpty(projectPath))
            {
                return(null);
            }

            string commandArgs = CreateExtractCommandArgs(unmanagedZipPath, extractedFolder, projectPath,
                                                          crmDevExSolutionPackage.EnableSolutionPackagerLog, crmDevExSolutionPackage.DownloadManaged);

            return(commandArgs);
        }
        public static bool CreatePackage(DTE dte, string toolPath, string solutionName, Project project,
                                         CrmDevExSolutionPackage crmDevExSolutionPackage, string fullPath, string commandArgs)
        {
            dte.ExecuteCommand($"shell {toolPath}", commandArgs);

            //Need this. Extend to allow bigger solutions to unpack
            //TODO: Better way?
            System.Threading.Thread.Sleep(5000);

            if (!crmDevExSolutionPackage.SaveSolutions)
            {
                return(true);
            }

            project.ProjectItems.AddFromFile(fullPath);

            if (crmDevExSolutionPackage.CreateManaged)
            {
                project.ProjectItems.AddFromFile(fullPath.Replace(".zip", "_managed.zip"));
            }

            return(true);
        }
        public static string GetPackageCommandArgs(Project project, string filename, string solutionProjectFolder, string fullPath, CrmDevExSolutionPackage crmDevExSolutionPackage)
        {
            string projectPath = CrmDeveloperExtensions2.Core.Vs.ProjectWorker.GetProjectPath(project);

            if (string.IsNullOrEmpty(projectPath))
            {
                return(null);
            }

            if (!CrmDeveloperExtensions2.Core.FileSystem.ConfirmOverwrite(
                    new[] { fullPath, fullPath.Replace(".zip", "_managed.zip") }, true))
            {
                return(null);
            }

            string commandArgs = CreatePackCommandArgs(projectPath, solutionProjectFolder, filename,
                                                       crmDevExSolutionPackage.EnableSolutionPackagerLog, crmDevExSolutionPackage.CreateManaged);

            return(commandArgs);
        }
        public static bool CreatePackage(DTE dte, string solutionName, Version version, Project project, CrmDevExSolutionPackage crmDevExSolutionPackage)
        {
            string toolPath = CreateToolPath(dte);

            if (string.IsNullOrEmpty(toolPath))
            {
                return(false);
            }

            string projectPath = CrmDeveloperExtensions2.Core.Vs.ProjectWorker.GetProjectPath(project);

            if (string.IsNullOrEmpty(projectPath))
            {
                return(false);
            }

            string filename = FileHandler.FormatSolutionVersionString(solutionName, version, false);

            string solutionProjectFolder = GetProjectSolutionFolder(project, crmDevExSolutionPackage.ProjectFolder);

            string fullPath = Path.Combine(solutionProjectFolder, filename);

            if (!CrmDeveloperExtensions2.Core.FileSystem.ConfirmOverwrite(
                    new[] { fullPath, fullPath.Replace(".zip", "_managed.zip") }, true))
            {
                return(true);
            }

            string commandArgs = CreatePackCommandArgs(projectPath, solutionProjectFolder, filename,
                                                       crmDevExSolutionPackage.EnableSolutionPackagerLog, crmDevExSolutionPackage.CreateManaged);

            dte.ExecuteCommand($"shell {toolPath}", commandArgs);

            //Need this. Extend to allow bigger solutions to unpack
            //TODO: Better way?
            System.Threading.Thread.Sleep(5000);

            if (!crmDevExSolutionPackage.SaveSolutions)
            {
                return(true);
            }

            project.ProjectItems.AddFromFile(fullPath);

            if (crmDevExSolutionPackage.CreateManaged)
            {
                project.ProjectItems.AddFromFile(fullPath.Replace(".zip", "_managed.zip"));
            }

            return(true);
        }