ReportDocument.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //-----------------------------------------------------------------------------
  2. // ReportDocument.cpp
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. #include "stdafx.h"
  8. #include "ReportDocument.h"
  9. #include "ProfileChecker.h"
  10. using namespace System::Security;
  11. using namespace XnaGraphicsProfileChecker;
  12. // Generates a report listing what graphics profiles are supported by the current hardware.
  13. ReportDocument::ReportDocument()
  14. {
  15. report = gcnew ElementList();
  16. try
  17. {
  18. GraphicsAdapter^ adapter = GraphicsAdapter::DefaultAdapter;
  19. // Output the graphics card name and device identifiers.
  20. report->Add("h1", adapter->Description);
  21. ElementList^ adapterDetails = gcnew ElementList();
  22. adapterDetails->Add("li", String::Format("Vendor ID: {0:X4}", adapter->VendorId));
  23. adapterDetails->Add("li", String::Format("Device ID: {0:X4}", adapter->DeviceId));
  24. adapterDetails->Add("li", String::Format("Subsystem: {0:X8}", adapter->SubSystemId));
  25. adapterDetails->Add("li", String::Format("Revision: {0:X8}", adapter->Revision));
  26. report->Add("ul", adapterDetails);
  27. for each (GraphicsProfile profile in Enum::GetValues(GraphicsProfile::typeid))
  28. {
  29. report->Add("hr", String::Empty);
  30. report->Add("h1", profile);
  31. // Run our profile checking logic.
  32. ProfileChecker^ profileChecker = gcnew ProfileChecker(profile);
  33. // As a sanity check, also ask the XNA Framework whether this profile is supported.
  34. bool xnaResult = adapter->IsProfileSupported(profile);
  35. // Output the results.
  36. if (profileChecker->IsSupported)
  37. {
  38. report->Add("p", xnaResult ? "Supported" : "Yikes! I think this profile should be supported, but XNA says it is not");
  39. }
  40. else
  41. {
  42. report->Add("p", xnaResult ? "Not supported" : "Yikes! I think this profile should not be supported, but XNA says it is");
  43. ElementList^ errorDetails = gcnew ElementList();
  44. for each (String^ error in profileChecker->Errors)
  45. {
  46. errorDetails->Add("li", error);
  47. }
  48. report->Add("ul", errorDetails);
  49. }
  50. }
  51. }
  52. catch (Exception^ exception)
  53. {
  54. report->Add("p", "Yikes! Check failed with this exception:");
  55. report->Add("pre", exception);
  56. }
  57. }
  58. // Formats the report as a text string.
  59. String^ ReportDocument::ToText(ElementList^ elements)
  60. {
  61. String^ result = String::Empty;
  62. for each (Element^ element in elements)
  63. {
  64. ElementList^ nestedList = dynamic_cast<ElementList^>(element->Item2);
  65. if (nestedList)
  66. result += ToText(nestedList);
  67. else
  68. result += element->Item2 + Environment::NewLine;
  69. }
  70. return result;
  71. }
  72. // Formats the report as an HTML document.
  73. String^ ReportDocument::ToHtml(ElementList^ elements)
  74. {
  75. String^ result = String::Empty;
  76. for each (Element^ element in elements)
  77. {
  78. String^ contents;
  79. ElementList^ nestedList = dynamic_cast<ElementList^>(element->Item2);
  80. if (nestedList)
  81. contents = ToHtml(nestedList);
  82. else
  83. contents = SecurityElement::Escape(element->Item2->ToString());
  84. result += String::Format("<{0}>{1}</{0}>\n", element->Item1, contents);
  85. }
  86. return result;
  87. }