Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 1 addition & 36 deletions Assets/Xbox Live/Editor/XboxLivePostProcessing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,25 @@
//
namespace Assets.Xbox_Live.Editor
{
using System;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;

using Microsoft.Xbox.Services;

using SyntaxTree.VisualStudio.Unity.Bridge;

using UnityEditor;
using UnityEditor.Callbacks;

using UnityEngine;

/// <summary>
/// Handles post processing the generated Visaul Studio projects in order to deal with DevCenter
/// Handles post processing the generated Visual Studio projects in order to deal with DevCenter
/// association and including Xbox Live configuration files.
/// </summary>
[InitializeOnLoad]
public class XboxLivePostProcessing
{
static XboxLivePostProcessing()
{
ProjectFilesGenerator.ProjectFileGeneration += AddXboxServicesConfig;
}

/// <summary>
/// Adds the XboxServices.config file to the generated project file.
/// </summary>
/// <param name="fileName">The name of the file being processed.</param>
/// <param name="fileContent">The content of the file being processed.</param>
/// <returns>The project file with an additional content element included.</returns>
/// <remarks>
/// This only modifies the Unity debug projects and will not have any
/// effect on projects built as part of the Unity UWP build process.
/// </remarks>
private static string AddXboxServicesConfig(string fileName, string fileContent)
{
if (!fileName.EndsWith(".Editor.csproj"))
{
const string configFileElement =
" <Content Include=\"" + XboxLiveAppConfiguration.FileName + "\">\r\n" +
" <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>\r\n" +
" </Content>\r\n";

// Hacky way to do this for now. Should make it a bit more stable.
int lastItemGroup = fileContent.LastIndexOf(" </ItemGroup>", StringComparison.OrdinalIgnoreCase);
fileContent = fileContent.Insert(lastItemGroup, configFileElement);
}

return fileContent;
}

[PostProcessBuild(1)]
public static void OnPostprocessBuild(BuildTarget target, string solutionFolder)
{
Expand Down
48 changes: 48 additions & 0 deletions Assets/Xbox Live/Editor/XboxLivePostProcessingUnityProject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) Microsoft Corporation
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
namespace Assets.Xbox_Live.Editor
{
using System;
using Microsoft.Xbox.Services;
using UnityEditor;

/// <summary>
/// Handles post processing the generated Visual Studio projects in order to deal with DevCenter
/// association and including Xbox Live configuration files.
/// </summary>
public class XboxLivePostProcessingUnityProject : AssetPostprocessor
{
private static string OnGeneratedCSProject(string path, string content)
{
return AddXboxServicesConfig(path, content);
}

/// <summary>
/// Adds the XboxServices.config file to the generated project file.
/// </summary>
/// <param name="fileName">The name of the file being processed.</param>
/// <param name="fileContent">The content of the file being processed.</param>
/// <returns>The project file with an additional content element included.</returns>
/// <remarks>
/// This only modifies the Unity debug projects and will not have any
/// effect on projects built as part of the Unity UWP build process.
/// </remarks>
private static string AddXboxServicesConfig(string fileName, string fileContent)
{
if (!fileName.EndsWith(".Editor.csproj"))
{
const string configFileElement =
" <Content Include=\"" + XboxLiveAppConfiguration.FileName + "\">\r\n" +
" <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>\r\n" +
" </Content>\r\n";

// Hacky way to do this for now. Should make it a bit more stable.
int lastItemGroup = fileContent.LastIndexOf(" </ItemGroup>", StringComparison.OrdinalIgnoreCase);
fileContent = fileContent.Insert(lastItemGroup, configFileElement);
}

return fileContent;
}
}
}
11 changes: 11 additions & 0 deletions Assets/Xbox Live/Editor/XboxLivePostProcessingUnityProject.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.