Пример #1
0
            /// <inheritdoc/>
            public override Task <ResultStatus> Execute(IExecuteContext executeContext, BuilderContext builderContext)
            {
                var steps = new List <BuildStep>();

                var urlRoot = originalSourcePath.GetParent();

                var fileStream = new FileStream(originalSourcePath.ToWindowsPath(), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);

                using (var recordedEffectCompile = new EffectLogStore(fileStream))
                {
                    recordedEffectCompile.LoadNewValues();

                    foreach (var entry in recordedEffectCompile.GetValues())
                    {
                        var effectCompileRequest = entry.Key;

                        var compilerParameters = new CompilerParameters();
                        effectCompileRequest.UsedParameters.CopyTo(compilerParameters);
                        compilerParameters.Platform = context.GetGraphicsPlatform();
                        compilerParameters.Profile  = context.GetGameSettingsAsset().DefaultGraphicsProfile;
                        steps.Add(new CommandBuildStep(new EffectCompileCommand(context, urlRoot, effectCompileRequest.EffectName, compilerParameters, package)));
                    }
                }

                Steps = steps;

                return(base.Execute(executeContext, builderContext));
            }
Пример #2
0
 protected override IEnumerable <Message> ExtractMessagesFromFile(UFile file)
 {
     try
     {
         // Read all content
         var reader = new XamlXmlReader(file.ToWindowsPath(), new XamlXmlReaderSettings {
             ProvideLineInfo = true
         });
         return(DoExtractMessagesFromFile(file, reader));
     }
     catch (XamlException ex)
     {
         Console.Error.WriteLine($"{file.ToWindowsPath()}: {ex.Message}");
         return(Enumerable.Empty <Message>());
     }
 }
Пример #3
0
        private async Task UpgradeProject(MSBuildWorkspace workspace, UFile projectPath)
        {
            // Upgrade .csproj file
            // TODO: Use parsed file?
            var fileContents = File.ReadAllText(projectPath);

            // Rename referenced to the package, shaders and effects
            var newFileContents = fileContents.Replace(".pdx", ".xk");

            // Rename variables
            newFileContents = newFileContents.Replace("Paradox", "Xenko");

            // Create fallback for old environment variable
            var index = newFileContents.IndexOf("<SiliconStudioCurrentPackagePath>", StringComparison.InvariantCulture);

            if (index >= 0)
            {
                newFileContents = newFileContents.Insert(index, "<SiliconStudioXenkoDir Condition=\"'$(SiliconStudioXenkoDir)' == ''\">$(SiliconStudioParadoxDir)</SiliconStudioXenkoDir>\n    ");
            }

            // Save file if there were any changes
            if (newFileContents != fileContents)
            {
                File.WriteAllText(projectPath, newFileContents);
            }

            // Upgrade source code
            var project = await workspace.OpenProjectAsync(projectPath.ToWindowsPath());

            var compilation = await project.GetCompilationAsync();

            var tasks = compilation.SyntaxTrees.Select(syntaxTree => Task.Run(() => UpgradeSourceFile(syntaxTree))).ToList();

            await Task.WhenAll(tasks);
        }
Пример #4
0
            void TryCopyResource(UFile resourceFilePath, UFile targetFilePath)
            {
                resourcesSourceToTarget.Add(resourceFilePath, targetFilePath);

                if (resourcesTargetToSource.TryGetValue(targetFilePath, out var otherResourceFilePath))
                {
                    logger.Error($"Could not copy resource file [{targetFilePath.MakeRelative(resourceOutputPath)}] because it exists in multiple locations: [{resourceFilePath.ToWindowsPath()}] and [{otherResourceFilePath.ToWindowsPath()}]");
                }
                else
                {
                    resourcesTargetToSource.Add(targetFilePath, resourceFilePath);

                    try
                    {
                        Directory.CreateDirectory(targetFilePath.GetFullDirectory());
                        File.Copy(resourceFilePath, targetFilePath, true);

                        RegisterItem(targetFilePath);
                    }
                    catch (Exception e)
                    {
                        logger.Error($"Could not copy resource file from [{resourceFilePath.ToWindowsPath()}] to [{targetFilePath.MakeRelative(resourceOutputPath)}]", e);
                    }
                }
            }
Пример #5
0
        private async Task UpgradeProject(MSBuildWorkspace workspace, UFile projectPath)
        {
            // Upgrade .csproj file
            // TODO: Use parsed file?
            var fileContents = File.ReadAllText(projectPath);

            // Rename referenced to the package, shaders and effects
            var newFileContents = fileContents.Replace(".pdx", ".xk");

            // Rename variables
            newFileContents = newFileContents.Replace("Paradox", "Xenko");

            // Save file if there were any changes
            if (newFileContents != fileContents)
            {
                File.WriteAllText(projectPath, newFileContents);
            }

            // Upgrade source code
            var project = await workspace.OpenProjectAsync(projectPath.ToWindowsPath());

            var compilation = await project.GetCompilationAsync();

            var tasks = compilation.SyntaxTrees.Select(syntaxTree => Task.Run(() => UpgradeSourceFile(syntaxTree))).ToList();

            await Task.WhenAll(tasks);
        }
Пример #6
0
        private void Explore()
        {
            var startInfo = new ProcessStartInfo("explorer.exe", $"/select,{fullPath.ToWindowsPath()}")
            {
                UseShellExecute = true
            };
            var explorer = new Process {
                StartInfo = startInfo
            };

            explorer.Start();
        }
Пример #7
0
        /// <summary>
        /// Handles project asset addition (from Visual Studio/HDD external changes to Game Studio).
        /// </summary>
        private static void AddNewProjectAssets(ProjectViewModel projectViewModel, List <AssetViewModel> projectAssets, Project project, List <UFile> projectFiles)
        {
            // Nothing to add?
            if (projectFiles.Count == 0)
            {
                return;
            }

            var scriptAssets = projectAssets.Where(x => x.AssetItem.Asset is IProjectAsset).Select(x => x.AssetItem);

            var documentsToIgnore = (from scriptAsset in scriptAssets
                                     from document in projectFiles
                                     let ufileDoc = new UFile(document)
                                                    where ufileDoc == scriptAsset.FullPath
                                                    select document).ToList();

            //remove what we have already
            var documentsCopy = new List <UFile>(projectFiles);

            foreach (var document in documentsToIgnore)
            {
                documentsCopy.Remove(document);
            }

            //add what we are missing
            if (documentsCopy.Count > 0)
            {
                var newScriptAssets = new List <AssetViewModel>();
                foreach (var document in documentsCopy)
                {
                    var docFile  = new UFile(document);
                    var projFile = new UFile(project.FilePath);

                    var assetName = docFile.MakeRelative(projectViewModel.Package.RootDirectory).GetDirectoryAndFileNameWithoutExtension();

                    var asset     = new ScriptSourceFileAsset();
                    var assetItem = new AssetItem(assetName, asset)
                    {
                        IsDirty       = true, //todo review / this is actually very important in the case of renaming, to propagate the change from VS to Game Studio, if we set it false here, during renaming the renamed asset won't be removed
                        SourceFolder  = projectViewModel.Package.RootDirectory,
                        SourceProject = projFile.ToWindowsPath(),
                    };

                    var directory      = projectViewModel.Package.GetOrCreateProjectDirectory(projectViewModel, assetItem.Location.GetFullDirectory().FullPath, false);
                    var newScriptAsset = projectViewModel.Package.CreateAsset(directory, assetItem, false, null);
                    newScriptAssets.Add(newScriptAsset);
                }

                // We're out of any transaction in this context so we have to manually notify that new assets were created.
                projectViewModel.Session.NotifyAssetPropertiesChanged(newScriptAssets);
            }
        }
Пример #8
0
            /// <inheritdoc/>
            public override Task <ResultStatus> Execute(IExecuteContext executeContext, BuilderContext builderContext)
            {
                var steps = new List <BuildStep>();

                var urlRoot = originalSourcePath.GetParent();

                var fileStream = new FileStream(originalSourcePath.ToWindowsPath(), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);

                using (var recordedEffectCompile = new EffectLogStore(fileStream))
                {
                    recordedEffectCompile.LoadNewValues();

                    foreach (var entry in recordedEffectCompile.GetValues())
                    {
                        steps.Add(EffectCompileCommand.FromRequest(context, package, urlRoot, entry.Key));
                    }
                }

                Steps = steps;

                return(base.Execute(executeContext, builderContext));
            }
Пример #9
0
 void RegisterItem(UFile targetFilePath)
 {
     generatedItems.Add((targetFilePath.ToWindowsPath(), UPath.Combine("xenko", targetFilePath.MakeRelative(outputPath)).ToWindowsPath()));
 }
Пример #10
0
        private async Task <Project> OpenProject(UFile projectPath)
        {
            if (msbuildWorkspace == null)
            {
                // Only load workspace for C# assemblies (default includes VB but not added as a NuGet package)
                //var csharpWorkspaceAssemblies = new[] { Assembly.Load("Microsoft.CodeAnalysis.Workspaces"), Assembly.Load("Microsoft.CodeAnalysis.CSharp.Workspaces"), Assembly.Load("Microsoft.CodeAnalysis.Workspaces.Desktop") };
                var host = await RoslynHost;
                msbuildWorkspace = MSBuildWorkspace.Create(ImmutableDictionary <string, string> .Empty, host.HostServices);
            }

            msbuildWorkspace.CloseSolution();

            // Try up to 10 times (1 second)
            const int retryCount = 10;

            for (var i = retryCount - 1; i >= 0; --i)
            {
                try
                {
                    var project = await msbuildWorkspace.OpenProjectAsync(projectPath.ToWindowsPath());

                    // Change the default CSharp language version to match the supported version for a specific visual studio version or MSBuild version
                    //  this is because roslyn  will always resolve Default to Latest which might not match the
                    //  latest version supported by the build tools installed on the machine
                    var csharpParseOptions = project.ParseOptions as CSharpParseOptions;
                    if (csharpParseOptions != null)
                    {
                        if (csharpParseOptions.SpecifiedLanguageVersion == LanguageVersion.Default || csharpParseOptions.SpecifiedLanguageVersion == LanguageVersion.Latest)
                        {
                            LanguageVersion targetLanguageVersion = csharpParseOptions.SpecifiedLanguageVersion;

                            // Check the visual studio version inside the solution first, which is what visual studio uses to decide which version to open
                            //  this should not be confused with the toolsVersion below, since this is the MSBuild version (they might be different)
                            Version visualStudioVersion = session.CurrentProject?.Package.Session.VisualStudioVersion;
                            if (visualStudioVersion != null)
                            {
                                if (visualStudioVersion.Major <= 14)
                                {
                                    targetLanguageVersion = LanguageVersion.CSharp6;
                                }
                            }
                            else
                            {
                                // Fallback to checking the tools version on the csproj
                                //  this happens when you open an sdpkg instead of a sln file as a project
                                ProjectRootElement xml = ProjectRootElement.Open(projectPath);
                                Version            toolsVersion;
                                if (Version.TryParse(xml.ToolsVersion, out toolsVersion))
                                {
                                    if (toolsVersion.Major <= 14)
                                    {
                                        targetLanguageVersion = LanguageVersion.CSharp6;
                                    }
                                }
                            }
                            project = project.WithParseOptions(csharpParseOptions.WithLanguageVersion(targetLanguageVersion));
                        }
                    }
                    return(project);
                }
                catch (IOException)
                {
                    // FIle might still be locked, let's wait little bit more
                    await Task.Delay(100);

                    if (i == 0)
                    {
                        throw;
                    }
                }
            }

            // Unreachable
            throw new InvalidOperationException();
        }