Exemplo n.º 1
0
        private string GetTypeLibCleanScript(ScriptExportType scriptExportType)
        {
            var builder = new StringBuilder();

            if (scriptExportType == ScriptExportType.Batch)
            {
                foreach (string libId in typeLibIds)
                {
                    builder.AppendLine("regedit /d /s  \"HKEY_CLASSES_ROOT\\TypeLib\\{ " + libId + "}\"");
                }
                foreach (string libId in typeLibIds)
                {
                    builder.AppendLine("rem reg Delete  \"HKEY_CLASSES_ROOT\\TypeLib\\{ " + libId + "}\" /va /f");
                }
                //builder.AppendLine("regedit /d /s  \"HKEY_CLASSES_ROOT\\TypeLib\\{ A0DCD767 - 2262 - 4228 - 9B52 - A0642C9D6A75}\"");
                //builder.AppendLine("regedit /d /s   \"HKEY_CLASSES_ROOT\\TypeLib\\{ C5CE8735 - 5F4D - 4C52 - A999 - 6CBEEC5A2587}\"");
                //builder.AppendLine("rem reg Delete  \"HKEY_CLASSES_ROOT\\TypeLib\\{ A0DCD767 - 2262 - 4228 - 9B52 - A0642C9D6A75}\" /va /f");
                //builder.AppendLine("rem reg Delete  \"HKEY_CLASSES_ROOT\\TypeLib\\{ C5CE8735 - 5F4D - 4C52 - A999 - 6CBEEC5A2587}\" /va /f");
            }
            else
            {
                builder.AppendLine(Encoding.UTF8.GetString(Resources.UnregisterTypeLibs));
            }

            return(builder.ToString());
        }
 private string GenerateSolutionPackerMerge(IEnumerable <ISolutionProjectModel> solutionProjects, IServiceSettings settings,
                                            ScriptExportType scriptExportType)
 {
     if (settings.GetSettingsFromProvider <BuildServiceSettings>().BuildMode == BuildMode.MergedBuild)
     {
         var builder     = new StringBuilder();
         var branchPath  = solutionProjects.First().ParentWorkingFolder.LocalItem;
         var solutionStr = string.Join(";", solutionProjects.Select(model => model.SolutionFileName));
         if (scriptExportType == ScriptExportType.Powershell)
         {
             builder.AppendLine("function MergeSolutions()");
             builder.AppendLine("{");
             builder.AppendLine($"$solutionPacker = \"{GetSolutionPackerExe()}\"");
             builder.AppendLine($"$source = \"{branchPath}\"");
             builder.AppendLine($"$solutions = \"{solutionStr}\"");
             builder.AppendLine("Invoke-Expression \" & '$solutionPacker' - s 'Build.sln' -p '$source' -i '$solutions'\"");
             builder.AppendLine("}");
         }
         else
         {
             builder.AppendLine($"\"{GetSolutionPackerExe()}\" -p \"{branchPath}\" -i \"{solutionStr}\" ");
         }
         return(builder.ToString());
     }
     return(string.Empty);
 }
        //Refer MonoManager, ScriptAssetExporter, ScriptExportManager
        void DoExport(Func <MonoScript, bool> selector = null)
        {
            var managedPath            = Path.Combine(GameDir, "Managed");
            var globalgamemanagersPath = Path.Combine(GameDir, "globalgamemanagers.assets");
            var gameStructure          = GameStructure.Load(new string[]
            {
                globalgamemanagersPath,
                managedPath
            });

            fileCollection = gameStructure.FileCollection;
            if (selector == null)
            {
                selector = (o) => true;
            }
            var assets = fileCollection.FetchAssets().Where(o => o is MonoScript ms && selector(ms)).ToArray();
            ScriptExportManager scriptManager = new ScriptExportManager(ExportPath);
            Dictionary <Object, ScriptExportType> exportTypes = new Dictionary <Object, ScriptExportType>();

            foreach (Object asset in assets)
            {
                MonoScript       script     = (MonoScript)asset;
                ScriptExportType exportType = script.GetExportType(scriptManager);
                exportTypes.Add(asset, exportType);
            }
            foreach (KeyValuePair <Object, ScriptExportType> exportType in exportTypes)
            {
                string path = scriptManager.Export(exportType.Value);
            }
            //scriptManager.ExportRest();
        }
Exemplo n.º 4
0
        public override void Init(IScriptExportManager manager)
        {
            m_template = manager.RetrieveType(Type.ElementType);

            int argumentCount = MonoUtils.GetGenericArgumentCount(Type);

            m_arguments = new ScriptExportType[argumentCount];
            for (int i = Type.GenericArguments.Count - argumentCount, j = 0; i < Type.GenericArguments.Count; i++, j++)
            {
                TypeReference argument = Type.GenericArguments[i];
                m_arguments[j] = manager.RetrieveType(argument);
            }

            if (Type.DeclaringType != null)
            {
                if (Type.DeclaringType.HasGenericParameters)
                {
                    IEnumerable <TypeReference> nestArguments = Type.GenericArguments.Take(Type.GenericArguments.Count - argumentCount);
                    GenericInstanceType         nestInstance  = MonoUtils.CreateGenericInstance(Type.DeclaringType, nestArguments);
                    m_nest = manager.RetrieveType(nestInstance);
                }
                else
                {
                    m_nest = manager.RetrieveType(Type.DeclaringType);
                }
            }
        }
Exemplo n.º 5
0
 private string GetRegsvr32Script(ScriptExportType type, string dllFile)
 {
     if (type == ScriptExportType.Batch)
     {
         return(GetRegsvr32Bat(dllFile));
     }
     return(GetRegsvr32Ps1(dllFile));
 }
 private static string CreateServiceFooter(ScriptExportType scriptType)
 {
     if (scriptType == ScriptExportType.Powershell)
     {
         return("}" + Environment.NewLine);
     }
     return(string.Empty);
 }
 private string GetStaticScriptsStarts(ScriptExportType scriptType)
 {
     if (scriptType == ScriptExportType.Powershell && IsTeamFoundationPowerShellSnapInInstalled)
     {
         return(Encoding.UTF8.GetString(Resources.PluginManager));
     }
     return(string.Empty);
 }
        private static string CreateHeader(ScriptExportType scriptType, IOperationService service, string powerShellParams)
        {
            string operationHead = "rem --------" + service.OperationName.ToUpper() + "--------";

            if (scriptType == ScriptExportType.Powershell)
            {
                operationHead =
                    $"# --------{service.OperationName.ToUpper()}--------{Environment.NewLine}{Environment.NewLine}function {service.GetPowershellFunctionName()}({powerShellParams}){Environment.NewLine}" +
                    "{";
            }
            return(operationHead);
        }
Exemplo n.º 9
0
        public override void Init(IScriptExportManager manager)
        {
            m_owner = manager.RetrieveType(Type.ElementType);

            List <ScriptExportType> arguments = new List <ScriptExportType>();

            foreach (TypeReference argument in Type.GenericArguments)
            {
                ScriptExportType exportParameter = manager.RetrieveType(argument);
                arguments.Add(exportParameter);
            }
            m_arguments = arguments.ToArray();
        }
Exemplo n.º 10
0
        private string GenerateExternalScriptParts(bool generatePreCode, IOperationService currentService, IEnumerable <ISolutionProjectModel> solutions, IServiceSettings settings,
                                                   ScriptExportType scriptExportType)
        {
            var builder = new StringBuilder();

            foreach (var scriptGenerator in CheckoutAndBuild2Package.GetExportedValues <IScriptGenerator>())
            {
                builder.AppendLine(generatePreCode
                    ? scriptGenerator.GeneratePreScriptCode(currentService, solutions, settings, scriptExportType)
                    : scriptGenerator.GeneratePostScriptCode(currentService, solutions, settings, scriptExportType));
            }
            return(builder.ToString());
        }
Exemplo n.º 11
0
 private string GetCallScriptMethodScript(ScriptExportType scriptType, string filePath)
 {
     if (File.Exists(filePath))
     {
         if (scriptType == ScriptExportType.Batch)
         {
             return($"call \"{filePath}\"");
         }
         if (scriptType == ScriptExportType.Powershell)
         {
             return($"Invoke-Expression \"{filePath}\"");
         }
     }
     return(string.Empty);
 }
Exemplo n.º 12
0
        public void Export(IExportContainer container, IEnumerable <Object> assets, string dirPath, Action <IExportContainer, Object, string> callback)
        {
            ScriptExportManager scriptManager = new ScriptExportManager(dirPath);

            foreach (Object asset in assets)
            {
                MonoScript       script     = (MonoScript)asset;
                ScriptExportType exportType = script.CreateExportType(scriptManager);
                string           path       = scriptManager.Export(exportType);
                if (path != null)
                {
                    callback?.Invoke(container, asset, path);
                }
            }
            scriptManager.ExportRest();
        }
Exemplo n.º 13
0
        public void Export(IExportContainer container, IEnumerable <Object> assets, string dirPath, Action <IExportContainer, Object, string> callback)
        {
            ScriptExportManager scriptManager = new ScriptExportManager(dirPath);
            Dictionary <Object, ScriptExportType> exportTypes = new Dictionary <Object, ScriptExportType>();

            foreach (Object asset in assets)
            {
                MonoScript       script     = (MonoScript)asset;
                ScriptExportType exportType = script.GetExportType(scriptManager);
                exportTypes.Add(asset, exportType);
            }
            foreach (KeyValuePair <Object, ScriptExportType> exportType in exportTypes)
            {
                string path = scriptManager.Export(exportType.Value);
                if (path != null)
                {
                    callback?.Invoke(container, exportType.Key, path);
                }
            }
            scriptManager.ExportRest();
        }
Exemplo n.º 14
0
        public string GeneratePreScriptCode(IOperationService service, IEnumerable <ISolutionProjectModel> solutions, IServiceSettings settings,
                                            ScriptExportType scriptExportType)
        {
            if (service.GetOperationType() == KnownOperation.Build)
            {
                var cpSettings = settings.GetSettingsFromProvider <CPSettings>();
                var builder    = new StringBuilder();
                if (cpSettings.DeleteTypeLibs)
                {
                    builder.AppendLine(GetTypeLibCleanScript(scriptExportType));
                }
                var cc = solutions.FirstOrDefault(model => model.ItemPath.Contains(SolutionNames.ControlCenter));
                if (cc != null && cpSettings.RegisterCom)
                {
                    builder.AppendLine(GetRegsvr32Script(scriptExportType, Path.Combine(cc.SolutionFolder, @"Assemblies\LicProtectorEasyGo264.dll")));
                }

                return(builder.ToString());
            }
            return(string.Empty);
        }
        //Refer MonoManager, ScriptAssetExporter, ScriptExportManager
        void DoExport(Func <MonoScript, bool> selector = null)
        {
            var managedPath            = Path.Combine(GameDir, "Managed");
            var globalgamemanagersPath = Path.Combine(GameDir, "globalgamemanagers.assets");
            var gameStructure          = GameStructure.Load(new string[]
            {
                globalgamemanagersPath,
                managedPath
            });

            fileCollection = gameStructure.FileCollection;
            if (selector == null)
            {
                selector = (o) => true;
            }
            var assets = fileCollection.FetchAssets().Where(o => o is MonoScript ms && selector(ms)).ToArray();
            ScriptExportManager scriptManager = new ScriptExportManager(ExportPath);
            Dictionary <Object, ScriptExportType> exportTypes = new Dictionary <Object, ScriptExportType>();

            foreach (Object asset in assets)
            {
                MonoScript script = (MonoScript)asset;
                if (ScriptByName)
                {
                    using (MD5 md5 = MD5.Create())
                    {
                        var data    = md5.ComputeHash(Encoding.UTF8.GetBytes($"{script.AssemblyName}.{script.Namespace}.{script.ClassName}"));
                        var newGuid = new Guid(data);
                        Util.SetGUID(script, newGuid);
                    }
                }
                ScriptExportType exportType = script.GetExportType(scriptManager);
                exportTypes.Add(asset, exportType);
            }
            foreach (KeyValuePair <Object, ScriptExportType> exportType in exportTypes)
            {
                string path = scriptManager.Export(exportType.Value);
            }
            //scriptManager.ExportRest();
        }
Exemplo n.º 16
0
        public Task <string> GenerateExportScriptAsync(WorkingFolderListViewModel listViewModel, ScriptExportType scriptType,
                                                       CancellationToken cancellationToken = default(CancellationToken))
        {
            IServiceSettings settings         = serviceProvider.Get <SettingsService>().GetMainServiceSettings();
            string           powerShellParams = "";//"[string] $source";

            return(Task.Run(() =>
            {
                return Check.TryCatch <string, TaskCanceledException>(() =>
                {
                    var builder = new StringBuilder();
                    var servicesToExport = mainLogic.GetIncludedServices().Where(service => service.AllowScriptExport && service.SupportedScriptExportTypes.Contains(scriptType)).OrderBy(service => service.Order);

                    builder.AppendLineIfNotEmpty(GetCallScriptMethodScript(scriptType, settings.PreBuildScriptPath));
                    builder.AppendLineIfNotEmpty(GenerateSolutionPackerMerge(listViewModel.WorkingFolders.SelectMany(model => model.Projects).Where(model => model.IsIncluded).OrderBy(model => model.BuildPriority), settings, scriptType));
                    List <Task <string> > tasks = servicesToExport.Select(service => Task.Run(() =>
                    {
                        var solutionProjectModels = listViewModel.WorkingFolders.SelectMany(model => model.Projects).Where(service.IsIncluded).OrderBy(model => model.BuildPriority);
                        var innerBuilder = new StringBuilder()
                                           .AppendLine(GenerateExternalScriptParts(true, service, solutionProjectModels, settings, scriptType))
                                           .AppendLine()
                                           .AppendLine(CreateHeader(scriptType, service, powerShellParams)).AppendLine();
                        innerBuilder.AppendLineIfNotEmpty(service.GetScript(solutionProjectModels, settings, scriptType));
                        innerBuilder.AppendLine(CreateServiceFooter(scriptType));
                        innerBuilder.AppendLine(GenerateExternalScriptParts(false, service, solutionProjectModels, settings, scriptType));
                        return innerBuilder.AppendLine().ToString();
                    }, cancellationToken)).ToList();

                    Check.TryCatch <OperationCanceledException>(() => Task.WhenAll(tasks).ContinueWith(t => builder.AppendLine(string.Join(Environment.NewLine, t.Result)), cancellationToken, TaskContinuationOptions.NotOnCanceled, System.Threading.Tasks.TaskScheduler.Current).Wait(cancellationToken));

                    if (scriptType == ScriptExportType.Powershell)
                    {
                        builder.AppendLinesIfNotEmpty(GeneratePowershellMethodCalls(servicesToExport, powerShellParams, settings).ToArray());
                    }

                    builder.AppendLineIfNotEmpty(GetCallScriptMethodScript(scriptType, settings.PostBuildScriptPath));

                    var result = ScriptHelper.PrepareScriptVars(builder.AppendLine(scriptType == ScriptExportType.Batch ? "pause;" : "").ToString(), true, scriptType);
                    return new StringBuilder(GetStaticScriptsStarts(scriptType))
                    .AppendLine(result)
                    .AppendLine(GetStaticScriptsEnds(scriptType))
                    .ToString();
                });
            }, cancellationToken));
        }
Exemplo n.º 17
0
        public string GetScript(IEnumerable <ISolutionProjectModel> solutionProjects, IServiceSettings settings, ScriptExportType exportType)
        {
            if (settings.GetSettingsFromProvider <BuildServiceSettings>().BuildMode == BuildMode.MergedBuild)
            {
                if (exportType == ScriptExportType.Powershell)
                {
                    return($"set-alias NUGET \"{NugetExe(solutionProjects.First(), settings)}\"{Environment.NewLine}Invoke-Expression \" & 'NUGET' restore '{solutionProjects.First().ParentWorkingFolder.LocalItem}\\Build.sln'\"");
                }
                return($"\"{NugetExe(solutionProjects.First(), settings)}\" restore \"{solutionProjects.First().ParentWorkingFolder.LocalItem}\\Build.sln\"");
            }

            return(string.Join(Environment.NewLine, solutionProjects.Select(model => exportType == ScriptExportType.Batch ? GetBatchScript(model, settings) : GetPowershellScript(model, settings))));
        }
Exemplo n.º 18
0
 public string GetScript(IEnumerable <ISolutionProjectModel> solutionProjects, IServiceSettings settings, ScriptExportType exportType)
 {
     return(string.Join(Environment.NewLine, solutionProjects.Select(model => exportType == ScriptExportType.Batch ? GetBatchScript(model, settings) : GetPowershellScript(model, settings))));
 }
Exemplo n.º 19
0
 public string GeneratePostScriptCode(IOperationService service, IEnumerable <ISolutionProjectModel> solutions, IServiceSettings settings,
                                      ScriptExportType scriptExportType)
 {
     return(string.Empty);
 }
Exemplo n.º 20
0
 private bool HasSameField(ScriptExportType type)
 {
     return(false);
 }
Exemplo n.º 21
0
 private string GetStaticScriptsEnds(ScriptExportType scriptType)
 {
     return(string.Empty);
 }
Exemplo n.º 22
0
 public string GetScript(IEnumerable <ISolutionProjectModel> solutionProjects, IServiceSettings settings, ScriptExportType exportType)
 {
     return(exportType == ScriptExportType.Batch ? GetBatchScript(solutionProjects, settings) : GetPowershellScript(solutionProjects, settings));
 }
Exemplo n.º 23
0
 public static string PrepareScriptVars(string script, bool removeDuplicateLines, ScriptExportType scriptType)
 {
     return(scriptType == ScriptExportType.Batch ? PrepareBatchScriptVars(script, removeDuplicateLines) : PreparePowershellScriptVars(script, removeDuplicateLines));
 }