Changeset 874 for xmlTools/trunk
- Timestamp:
- May 25, 2013, 11:53:39 PM (12 years ago)
- Location:
- xmlTools/trunk
- Files:
-
- 12 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
xmlTools/trunk/posUpdate.sln
r868 r874 28 28 HideSolutionNode = FALSE 29 29 EndGlobalSection 30 GlobalSection(Performance) = preSolution 31 HasPerformanceSessions = true 32 EndGlobalSection 30 33 GlobalSection(MonoDevelopProperties) = preSolution 31 34 StartupItem = src\demo\CommandLine.Demo.csproj -
xmlTools/trunk/posUpdate/ParametersParser.cs
r867 r874 142 142 } 143 143 144 [Verb ]144 [Verb(Description = "Displays current XmlTools version.")] 145 145 public static void version() 146 146 { 147 Console.WriteLine("xmlTools v" + Program. toolsVersion);147 Console.WriteLine("xmlTools v" + Program.XmlToolsVersion); 148 148 Console.WriteLine("\nWritten by s10k"); 149 } 150 151 [Verb(Description = "Displays extra informations about XmlTools.")] 152 public static void about() 153 { 154 version(); 155 Console.WriteLine(); 156 Console.WriteLine("For extra XmlTools support check it page at: http://wiki.oni2.net/XmlTools"); 157 Console.WriteLine(); 158 Console.WriteLine("This program uses the following free libraries: "); 159 Console.WriteLine("-CLAP: for parameter parsing. (http://adrianaisemberg.github.io/CLAP/)"); 160 Console.WriteLine("-IronJS: for custom javascript code execution. (https://github.com/fholm/IronJS)"); 161 Console.WriteLine(); 162 Console.WriteLine("A big thanks to all the oni.bungie.org community!"); 149 163 } 150 164 -
xmlTools/trunk/posUpdate/Program.cs
r868 r874 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.IO; 3 4 using System.Text; 4 using System.Xml;5 using System.IO;6 using System.Globalization;7 using System.Text.RegularExpressions;8 5 9 6 namespace xmlTools … … 11 8 class Program 12 9 { 13 public static readonly string toolsVersion = "0.8g";10 public const string XmlToolsVersion = "0.9"; // const variable are by default static 14 11 private static appErrors lastError = appErrors.NO_ERROR; 15 12 … … 32 29 PATCH_ELEMENT_NOT_FOUND = 203, 33 30 PATCH_ADDTO_ERROR_PARSING_XML = 204, 34 PATCH_COMMAND_NOT_FOUND = 205 31 PATCH_COMMAND_NOT_FOUND = 205, 32 PATCH_CODE_PROCESS_ERROR=206, 33 PATCH_CODE_NOT_FOUND=207, 34 PATCH_CODE_PARSE_XML_OUTPUT_ERROR=208, 35 35 } 36 36 … … 49 49 public static int Main(string[] args) 50 50 { 51 51 52 try 52 53 { -
xmlTools/trunk/posUpdate/XmlPatch.cs
r868 r874 2 2 using System.Collections.Generic; 3 3 using System.Diagnostics; 4 using System.IO; 4 5 using System.Text; 5 6 using System.Xml; 7 using IronJS; 6 8 7 9 namespace xmlTools … … 15 17 String forceFiles = ""; 16 18 bool globalNoBackups = false; 19 IronJS.Hosting.CSharp.Context jsEngine = null; // initialize only when necessary 17 20 18 21 public XmlPatch(String file, bool noBackups) … … 50 53 while ((line = file.ReadLine()) != "</xml>") 51 54 { 52 xmlToInject += line + "\n"; //get all the xml that will be injected55 xmlToInject += line + System.Environment.NewLine; //get all the xml that will be injected 53 56 } 54 57 if (!addOperation(operation, xmlToInject)) … … 71 74 { 72 75 Program.printAppError(Program.appErrors.PATCH_COMMAND_PROCESS_ERROR, "Error while performing command operation in patch file. Aborting..."); 76 return false; 77 } 78 } 79 else if (line.StartsWith("@CUSTOMCODE ")) 80 { 81 string operation = line; 82 string jsCode = ""; 83 84 file.ReadLine(); //ignore <xml> start header 85 while ((line = file.ReadLine()) != "</code>") 86 { 87 jsCode += line + System.Environment.NewLine; //get all the xml that will be injected 88 } 89 if (!executeCode(operation, jsCode)) 90 { 91 Program.printAppError(Program.appErrors.PATCH_CODE_PROCESS_ERROR, "Error while performing code operation in patch file. Aborting..."); 73 92 return false; 74 93 } … … 91 110 //@ADDTO File "example.xml" ParentElement "Animation" Element "Lookup" 92 111 93 string File = "", ParentElement = "", Element= "";112 string FileParam = "", ParentElementParam = "", ElementParam = ""; 94 113 95 114 //---------------------------------------------------Parse Operation command (start) … … 98 117 if (String.IsNullOrEmpty(forceFiles)) 99 118 { 100 File = getPatchParameter(operation, "File");119 FileParam = getPatchParameter(operation, "File"); 101 120 } 102 121 else 103 122 { 104 File = forceFiles;105 } 106 107 ParentElement = getPatchParameter(operation, "ParentElement"); //Get the ParentElement108 109 Element = getPatchParameter(operation, "Element"); //Get the Element123 FileParam = forceFiles; 124 } 125 126 ParentElementParam = getPatchParameter(operation, "ParentElement"); //Get the ParentElement 127 128 ElementParam = getPatchParameter(operation, "Element"); //Get the Element 110 129 } 111 130 catch (Exception e) … … 115 134 } 116 135 117 if (String.IsNullOrEmpty(Element ))136 if (String.IsNullOrEmpty(ElementParam)) 118 137 { 119 138 return false; … … 122 141 //---------------------------------------------------Parse Operation command (end) 123 142 List<String> filesToProcess = new List<String>(); 124 if (String.IsNullOrEmpty(File ))143 if (String.IsNullOrEmpty(FileParam)) 125 144 { 126 145 filesToProcess = Util.getAllXmlFiles(); //no file specified, use all xml files found in same folder 127 146 } 128 else if (Util.containsWildcard(File ))129 { 130 filesToProcess = Util.getXmlFilesWildcard(File );147 else if (Util.containsWildcard(FileParam)) 148 { 149 filesToProcess = Util.getXmlFilesWildcard(FileParam); 131 150 } 132 151 else 133 152 { 134 filesToProcess.Add(File );153 filesToProcess.Add(FileParam); 135 154 } 136 155 … … 147 166 148 167 List<XmlNode> myElements = new List<XmlNode>(); 149 Util.getAllSpecificElements(xdoc.DocumentElement, ref myElements, Element , ParentElement); //Returns all after "Oni" element168 Util.getAllSpecificElements(xdoc.DocumentElement, ref myElements, ElementParam, ParentElementParam); //Returns all after "Oni" element 150 169 151 170 if (myElements.Count == 0) … … 183 202 //@REMOVE File "example.xml" ParentElement "Particles" Element "Particle" 184 203 185 string File = "", ParentElement = "", Element= "";204 string FileParam = "", ParentElementParam = "", ElementParam = ""; 186 205 187 206 //---------------------------------------------------Parse Operation command (start) … … 190 209 if (String.IsNullOrEmpty(forceFiles)) 191 210 { 192 File = getPatchParameter(operation, "File");211 FileParam = getPatchParameter(operation, "File"); 193 212 } 194 213 else 195 214 { 196 File = forceFiles;197 } 198 199 ParentElement = getPatchParameter(operation, "ParentElement"); //Get the ParentElement200 201 Element = getPatchParameter(operation, "Element"); //Get the Element215 FileParam = forceFiles; 216 } 217 218 ParentElementParam = getPatchParameter(operation, "ParentElement"); //Get the ParentElement 219 220 ElementParam = getPatchParameter(operation, "Element"); //Get the Element 202 221 } 203 222 catch (Exception e) … … 207 226 } 208 227 209 if (String.IsNullOrEmpty(Element ))228 if (String.IsNullOrEmpty(ElementParam)) 210 229 { 211 230 return false; … … 215 234 216 235 List<String> filesToProcess = new List<String>(); 217 if (String.IsNullOrEmpty(File ))236 if (String.IsNullOrEmpty(FileParam)) 218 237 { 219 238 filesToProcess = Util.getAllXmlFiles(); //no file specified, use all xml files found in same folder 220 239 } 221 else if (Util.containsWildcard(File ))222 { 223 filesToProcess = Util.getXmlFilesWildcard(File );240 else if (Util.containsWildcard(FileParam)) 241 { 242 filesToProcess = Util.getXmlFilesWildcard(FileParam); 224 243 } 225 244 else 226 245 { 227 filesToProcess.Add(File );246 filesToProcess.Add(FileParam); 228 247 } 229 248 … … 242 261 243 262 List<XmlNode> myElements = new List<XmlNode>(); 244 Util.getAllSpecificElements(xdoc.DocumentElement, ref myElements, Element , ParentElement); //Returns all after "Oni" element263 Util.getAllSpecificElements(xdoc.DocumentElement, ref myElements, ElementParam, ParentElementParam); //Returns all after "Oni" element 245 264 246 265 if (myElements.Count == 0) … … 262 281 263 282 /// <summary> 264 /// 283 /// Executes a command for xmlTools 265 284 /// </summary> 266 285 /// <param name="command"></param> … … 285 304 286 305 // Filename already exists? 287 if (Util.ContainsIgnoreCase(command, "filename:"))306 if (Util.ContainsIgnoreCase(command, "filename:")) 288 307 { 289 308 paramType = "filename:"; … … 296 315 else 297 316 { 298 command = command.Insert(command.Length, " -filename:" + this.forceFiles);317 command = command.Insert(command.Length, " -filename:" + this.forceFiles); 299 318 } 300 319 … … 306 325 { 307 326 endIdx = command.IndexOf("\n", startIdx); // or with endline 308 if(endIdx==-1){ // Filename parameters is the last one in the file (file ends with this parameter) 309 endIdx=command.Length-1; 327 if (endIdx == -1) 328 { // Filename parameters is the last one in the file (file ends with this parameter) 329 endIdx = command.Length - 1; 310 330 } 311 331 } … … 316 336 } 317 337 318 if (this.globalNoBackups && !Util.ContainsIgnoreCase(command, "nobackups")) // add noBackup flag if provided as global parameter338 if (this.globalNoBackups && !Util.ContainsIgnoreCase(command, "nobackups")) // add noBackup flag if provided as global parameter 319 339 { 320 340 command = command.Insert(command.Length, " -nobackups"); … … 328 348 return false; 329 349 } 350 351 return true; 352 } 353 354 /// <summary> 355 /// Executes custom Javascript code over the xml file specified. Uses .NET JINT library. 356 /// </summary> 357 /// <param name="command"></param> 358 /// <returns></returns> 359 private bool executeCode(string operation, string jsCode) 360 { 361 string FileParam = ""; 362 363 //---------------------------------------------------Parse Operation command (start) 364 try 365 { 366 if (String.IsNullOrEmpty(forceFiles)) 367 { 368 FileParam = getPatchParameter(operation, "File"); 369 } 370 else 371 { 372 FileParam = forceFiles; 373 } 374 375 } 376 catch (Exception e) 377 { 378 Program.printAppError(Program.appErrors.PATCH_CODE_PROCESS_ERROR, "Error parsing codeOperation in Patch file.\n" + e.ToString()); 379 return false; 380 } 381 382 //---------------------------------------------------Parse Operation command (end) 383 List<String> filesToProcess = new List<String>(); 384 if (String.IsNullOrEmpty(FileParam)) 385 { 386 filesToProcess = Util.getAllXmlFiles(); //no file specified, use all xml files found in same folder 387 } 388 else if (Util.containsWildcard(FileParam)) 389 { 390 filesToProcess = Util.getXmlFilesWildcard(FileParam); 391 } 392 else 393 { 394 filesToProcess.Add(FileParam); 395 } 396 397 //---------------------------------------------------JS Code Proccess (start) 398 foreach (String currXMLFile in filesToProcess) 399 { 400 if (!this.globalNoBackups && !Util.ContainsIgnoreCase(operation, "NoBackups")) // only skip backup if specified via global parameter or in patch file 401 { 402 Util.backupFile(currXMLFile); 403 } 404 405 string xmlFileContent = File.ReadAllText(currXMLFile); 406 407 // Initialize Jint Engine 408 if (jsEngine == null) 409 { 410 jsEngine = new IronJS.Hosting.CSharp.Context(); 411 412 // Load XML libraries 413 jsEngine.Execute(xmlTools.Properties.Resources.tinyxmlsax); 414 jsEngine.Execute(xmlTools.Properties.Resources.tinyxmlw3cdom); 415 } 416 417 // Construct code to execute 418 StringBuilder sourceCode = new StringBuilder(); 419 420 // give user the xml we needs to edit... 421 sourceCode.Append("var $xmlData='").Append(xmlFileContent.Replace(System.Environment.NewLine, " \\" + System.Environment.NewLine)).Append("';").AppendLine(); // replace is for multine string in javascript (http://stackoverflow.com/questions/805107/creating-multiline-strings-in-javascript) 422 // append the user js code... 423 sourceCode.Append(jsCode).AppendLine(); 424 // return to .NET the new xml data 425 sourceCode.Append("$xmlData;"); 426 427 try 428 { 429 xmlFileContent = jsEngine.Execute(sourceCode.ToString()).ToString(); 430 } 431 catch (Exception e) 432 { 433 Program.printAppError(Program.appErrors.PATCH_CODE_PROCESS_ERROR, "Error parsing code in customCodeOperation in Patch file.\n" + e.ToString()); 434 return false; 435 } 436 437 // Let's see if the returned result is valid xml... 438 try 439 { 440 XmlDocument xmlDoc = new XmlDocument(); 441 442 xmlDoc.LoadXml(xmlFileContent); 443 444 xmlDoc.Save(currXMLFile); //saving the new xml with this method will auto ident it. 445 446 } 447 catch (Exception e) 448 { 449 Program.printAppError(Program.appErrors.PATCH_CODE_PARSE_XML_OUTPUT_ERROR, "Error parsing result xml to customCodeOperation in Patch file.\n" + e.ToString()); 450 return false; 451 } 452 } 453 //---------------------------------------------------JS Code Proccess (end) 330 454 331 455 return true; -
xmlTools/trunk/posUpdate/bin/Release/merge.bat
r710 r874 1 ilmerge /log:log.txt /out:xmlTools.exe posUpdate.exe CLAP.dll 1 ilmerge /log:log.txt /out:xmlTools.exe posUpdate.exe CLAP.dll IronJS.dll FSharp.Core.dll Microsoft.Scripting.Core.dll 2 2 pause -
xmlTools/trunk/posUpdate/xmlTools.csproj
r710 r874 11 11 <RootNamespace>xmlTools</RootNamespace> 12 12 <AssemblyName>posUpdate</AssemblyName> 13 <TargetFrameworkVersion>v 2.0</TargetFrameworkVersion>13 <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> 14 14 <TargetFrameworkProfile> 15 15 </TargetFrameworkProfile> 16 16 <FileAlignment>512</FileAlignment> 17 <IsWebBootstrapper>false</IsWebBootstrapper> 17 18 <PublishUrl>publish\</PublishUrl> 18 19 <Install>true</Install> … … 27 28 <ApplicationRevision>0</ApplicationRevision> 28 29 <ApplicationVersion>1.0.0.%2a</ApplicationVersion> 29 <IsWebBootstrapper>false</IsWebBootstrapper>30 30 <UseApplicationTrust>false</UseApplicationTrust> 31 31 <BootstrapperEnabled>true</BootstrapperEnabled> … … 54 54 <HintPath>..\..\..\Libraries\net20\CLAP.dll</HintPath> 55 55 </Reference> 56 <Reference Include="FSharp.Core, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> 57 <SpecificVersion>False</SpecificVersion> 58 <HintPath>bin\Debug\FSharp.Core.dll</HintPath> 59 </Reference> 60 <Reference Include="IronJS, Version=0.2.0.0, Culture=neutral, processorArchitecture=x86"> 61 <SpecificVersion>False</SpecificVersion> 62 <HintPath>bin\Debug\IronJS.dll</HintPath> 63 </Reference> 64 <Reference Include="Microsoft.Scripting.Core, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> 65 <SpecificVersion>False</SpecificVersion> 66 <HintPath>bin\Debug\Microsoft.Scripting.Core.dll</HintPath> 67 </Reference> 68 <Reference Include="Microsoft.Scripting.ExtensionAttribute"> 69 <HintPath>..\..\..\..\..\..\..\dev_libs\IronJS\Microsoft.Scripting.ExtensionAttribute.dll</HintPath> 70 </Reference> 56 71 <Reference Include="System" /> 57 72 <Reference Include="System.Data" /> … … 60 75 <ItemGroup> 61 76 <Compile Include="ParametersParser.cs" /> 77 <Compile Include="Properties\Resources.Designer.cs"> 78 <AutoGen>True</AutoGen> 79 <DesignTime>True</DesignTime> 80 <DependentUpon>Resources.resx</DependentUpon> 81 </Compile> 62 82 <Compile Include="Util.cs" /> 63 83 <Compile Include="XmlPatch.cs" /> … … 84 104 </BootstrapperPackage> 85 105 </ItemGroup> 106 <ItemGroup> 107 <EmbeddedResource Include="Properties\Resources.resx"> 108 <Generator>ResXFileCodeGenerator</Generator> 109 <LastGenOutput>Resources.Designer.cs</LastGenOutput> 110 </EmbeddedResource> 111 </ItemGroup> 112 <ItemGroup> 113 <None Include="Resources\TextFile1.txt" /> 114 </ItemGroup> 115 <ItemGroup> 116 <None Include="Resources\xmlsax.txt" /> 117 </ItemGroup> 118 <ItemGroup> 119 <None Include="Resources\xmlsax.js.txt" /> 120 </ItemGroup> 121 <ItemGroup> 122 <WCFMetadata Include="Service References\" /> 123 </ItemGroup> 86 124 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 87 125 <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Note:
See TracChangeset
for help on using the changeset viewer.