PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/WebsitePanel/Trunk/Sources/WebsitePanel.Providers.Statistics.SmarterStats/SmarterStats5.cs

https://github.com/ShaneMcC/websitepanel
C# | 114 lines | 61 code | 15 blank | 38 comment | 17 complexity | 1d1ef664023caeb49b052c2fba400184 MD5 | raw file
  1. // Copyright (c) 2010, SMB SAAS Systems Inc.
  2. // All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without modification,
  5. // are permitted provided that the following conditions are met:
  6. //
  7. // - Redistributions of source code must retain the above copyright notice, this
  8. // list of conditions and the following disclaimer.
  9. //
  10. // - Redistributions in binary form must reproduce the above copyright notice,
  11. // this list of conditions and the following disclaimer in the documentation
  12. // and/or other materials provided with the distribution.
  13. //
  14. // - Neither the name of the SMB SAAS Systems Inc. nor the names of its
  15. // contributors may be used to endorse or promote products derived from this
  16. // software without specific prior written permission.
  17. //
  18. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  22. // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  25. // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. using System;
  29. using System.Collections.Generic;
  30. using System.Text;
  31. using Microsoft.Win32;
  32. namespace WebsitePanel.Providers.Statistics
  33. {
  34. class SmarterStats5 : SmarterStats
  35. {
  36. public override bool IsInstalled()
  37. {
  38. string productName = null, productVersion = null;
  39. // Check x86 platform
  40. RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
  41. if (key != null)
  42. {
  43. var names = key.GetSubKeyNames();
  44. foreach (string s in names)
  45. {
  46. RegistryKey subkey = key.OpenSubKey(s);
  47. //
  48. if (subkey == null)
  49. continue;
  50. //
  51. productName = subkey.GetValue("DisplayName") as String;
  52. //
  53. if (String.IsNullOrEmpty(productName))
  54. continue;
  55. if (productName.Equals("SmarterStats")
  56. || productName.Equals("SmarterStats Service"))
  57. {
  58. productVersion = subkey.GetValue("DisplayVersion") as String;
  59. goto Version_Match;
  60. }
  61. }
  62. }
  63. // Check x64 platform
  64. key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall");
  65. if (key != null)
  66. {
  67. var names = key.GetSubKeyNames();
  68. foreach (string s in names)
  69. {
  70. RegistryKey subkey = key.OpenSubKey(s);
  71. //
  72. if (subkey == null)
  73. continue;
  74. //
  75. productName = subkey.GetValue("DisplayName") as String;
  76. //
  77. if (String.IsNullOrEmpty(productName))
  78. continue;
  79. if (productName.Equals("SmarterStats")
  80. || productName.Equals("SmarterStats Service"))
  81. {
  82. productVersion = subkey.GetValue("DisplayVersion") as String;
  83. goto Version_Match;
  84. }
  85. }
  86. }
  87. Version_Match:
  88. //
  89. if (String.IsNullOrEmpty(productVersion))
  90. return false;
  91. // Match SmarterStats either 5.x or 6.x version
  92. if (productVersion.StartsWith("5.")
  93. || productVersion.StartsWith("6."))
  94. return true;
  95. //
  96. return false;
  97. }
  98. }
  99. }