Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
SynchronizeProjectProcessor.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.IO;
5 using System.Linq;
6 using System.Xml.Linq;
7 using System.Xml.XPath;
8 
9 namespace SiliconStudio.Paradox.ProjectGenerator
10 {
12  {
13  private ProjectType projectType;
14 
16  {
17  this.projectType = projectType;
18  }
19 
20  public void Process(ProjectProcessorContext context)
21  {
22  var doc = context.Document;
23  var ns = context.Document.Root.Name.Namespace;
24 
25  var fullPath = context.Project.FullPath;
26 
27  // Remove .Windows (if any)
28  fullPath = fullPath.Replace(".Windows", string.Empty);
29 
30  // Add current platform instead
31  fullPath = Path.Combine(Path.GetDirectoryName(fullPath), Path.GetFileNameWithoutExtension(fullPath) + "." + projectType + Path.GetExtension(fullPath));
32 
33  if (File.Exists(fullPath))
34  {
35  // Already exists, let's synchronize!
36  context.Modified = true;
37 
38  // First, let's load project
39  var newDoc = XDocument.Load(fullPath);
40 
41  // Let's load ItemGroup items from previous and new items
42  var oldItemGroups = doc.XPathSelectElements("/x:Project/x:ItemGroup", context.NamespaceManager).ToArray();
43  var newItemGroups = newDoc.XPathSelectElements("/x:Project/x:ItemGroup", context.NamespaceManager).ToArray();
44 
45  // Remove non-tagged item from new document
46  foreach (var itemGroup in newItemGroups)
47  {
48  var nonTaggedElements = GetUserElements(itemGroup);
49  foreach (var nonTaggedElement in nonTaggedElements)
50  {
51  nonTaggedElement.Remove();
52  }
53  }
54 
55  // Copy back non-tagged item from old document
56  // Try to insert in second ItemGroup (usually first one is Reference)
57  var insertionItemGroup = newItemGroups.Length >= 2 ? newItemGroups[1] : newItemGroups[0];
58  foreach (var itemGroup in oldItemGroups)
59  {
60  var nonTaggedElements = GetUserElements(itemGroup);
61  foreach (var nonTaggedElement in nonTaggedElements)
62  {
63  insertionItemGroup.Add(new XElement(nonTaggedElement));
64  }
65  }
66 
67  // Clear empty item groups
68  foreach (var itemGroup in newItemGroups.ToArray())
69  {
70  if (!itemGroup.HasElements)
71  itemGroup.Remove();
72  }
73 
74  // Set newly generated document
75  context.Document = newDoc;
76  }
77  }
78 
79  /// <summary>
80  /// Gets the user elements (not tagged with AutoGenerated).
81  /// </summary>
82  /// <param name="itemGroup">The old item group.</param>
83  /// <returns></returns>
84  private static XElement[] GetUserElements(XElement itemGroup)
85  {
86  return itemGroup
87  .Elements()
88  .Where(x => !x.Attributes().Any(y => y.Name == "Label" && y.Value == "Paradox.DoNotSync"))
89  .ToArray();
90  }
91 
92  private static void GenerateInfoFile(string infoFile, string bundleDisplayName, string bundleIdentifier)
93  {
94  var doc = new XDocument(
95  new XDeclaration("1.0", "UTF-8", "yes"),
96  new XDocumentType("plist", "-//Apple//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null),
97  new XElement("plist", new XAttribute("version", "1.0"),
98  new XElement("dict",
99  new XElement("key", "UIDeviceFamily"),
100  new XElement("array",
101  new XElement("integer", "1"), // 1 = app runs on iPhone and iPod Touch
102  new XElement("integer", "2") // 2 = app runs on iPad (3 = app runs on Apple TV)
103  ),
104  new XElement("key", "UISupportedInterfaceOrientations"),
105  new XElement("array",
106  new XElement("string", "UIInterfaceOrientationPortrait"),
107  new XElement("string", "UIInterfaceOrientationLandscapeLeft"),
108  new XElement("string", "UIInterfaceOrientationLandscapeRight")
109  ),
110  new XElement("key", "UISupportedInterfaceOrientations~ipad"),
111  new XElement("array",
112  new XElement("string", "UIInterfaceOrientationPortrait"),
113  new XElement("string", "UIInterfaceOrientationPortraitUpsideDown"),
114  new XElement("string", "UIInterfaceOrientationLandscapeRight"),
115  new XElement("string", "UIInterfaceOrientationLandscapeRight")
116  ),
117  new XElement("key", "MinimumOSVersion"),
118  new XElement("string", "3.2"),
119  new XElement("key", "CFBundleDisplayName"),
120  new XElement("string", bundleDisplayName),
121  new XElement("key", "CFBundleIdentifier"),
122  new XElement("string", bundleIdentifier)
123  )
124  )
125  );
126 
127  using (var fileStream = new StreamWriter(infoFile))
128  {
129  fileStream.Write(doc.ToString());
130  }
131  }
132  }
133 }
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t y
Definition: DirectXTexP.h:191
System.IO.File File