MainPage.xaml.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Documents;
  8. using System.Windows.Input;
  9. using System.Windows.Media;
  10. using System.Windows.Media.Animation;
  11. using System.Windows.Shapes;
  12. using Microsoft.Phone.Controls;
  13. using System.IO.IsolatedStorage;
  14. using System.IO;
  15. using System.Windows.Resources;
  16. namespace SolitaireHTML5
  17. {
  18. public partial class MainPage : PhoneApplicationPage
  19. {
  20. private BrowserMouseHelper moveHelper;
  21. // Constructor
  22. public MainPage()
  23. {
  24. InitializeComponent();
  25. webBrowser.Opacity = 0;
  26. moveHelper = new BrowserMouseHelper(ref webBrowser);
  27. moveHelper.ScrollDisabled = true;
  28. SaveFilesToIsoStore();
  29. webBrowser.Navigate(new Uri("html_content/index.html", UriKind.Relative));
  30. }
  31. private void webBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
  32. {
  33. // Show browser
  34. webBrowser.Opacity = 1;
  35. }
  36. private void SaveFilesToIsoStore()
  37. {
  38. //These files must match what is included in the application package,
  39. //or BinaryStream.Dispose below will throw an exception.
  40. string[] files = {
  41. "html_content/index.html",
  42. "html_content/index2.html",
  43. "html_content/script.js",
  44. "html_content/wp.css",
  45. "html_content/gfx/background.png",
  46. "html_content/gfx/card_background.png",
  47. "html_content/gfx/deck_background.png",
  48. "html_content/gfx/Club_ace.png",
  49. "html_content/gfx/Club_2.png",
  50. "html_content/gfx/Club_3.png",
  51. "html_content/gfx/Club_4.png",
  52. "html_content/gfx/Club_5.png",
  53. "html_content/gfx/Club_6.png",
  54. "html_content/gfx/Club_7.png",
  55. "html_content/gfx/Club_8.png",
  56. "html_content/gfx/Club_9.png",
  57. "html_content/gfx/Club_10.png",
  58. "html_content/gfx/Club_jack.png",
  59. "html_content/gfx/Club_queen.png",
  60. "html_content/gfx/Club_king.png",
  61. "html_content/gfx/Diamond_ace.png",
  62. "html_content/gfx/Diamond_2.png",
  63. "html_content/gfx/Diamond_3.png",
  64. "html_content/gfx/Diamond_4.png",
  65. "html_content/gfx/Diamond_5.png",
  66. "html_content/gfx/Diamond_6.png",
  67. "html_content/gfx/Diamond_7.png",
  68. "html_content/gfx/Diamond_8.png",
  69. "html_content/gfx/Diamond_9.png",
  70. "html_content/gfx/Diamond_10.png",
  71. "html_content/gfx/Diamond_jack.png",
  72. "html_content/gfx/Diamond_queen.png",
  73. "html_content/gfx/Diamond_king.png",
  74. "html_content/gfx/Heart_ace.png",
  75. "html_content/gfx/Heart_2.png",
  76. "html_content/gfx/Heart_3.png",
  77. "html_content/gfx/Heart_4.png",
  78. "html_content/gfx/Heart_5.png",
  79. "html_content/gfx/Heart_6.png",
  80. "html_content/gfx/Heart_7.png",
  81. "html_content/gfx/Heart_8.png",
  82. "html_content/gfx/Heart_9.png",
  83. "html_content/gfx/Heart_10.png",
  84. "html_content/gfx/Heart_jack.png",
  85. "html_content/gfx/Heart_queen.png",
  86. "html_content/gfx/Heart_king.png",
  87. "html_content/gfx/Spade_ace.png",
  88. "html_content/gfx/Spade_2.png",
  89. "html_content/gfx/Spade_3.png",
  90. "html_content/gfx/Spade_4.png",
  91. "html_content/gfx/Spade_5.png",
  92. "html_content/gfx/Spade_6.png",
  93. "html_content/gfx/Spade_7.png",
  94. "html_content/gfx/Spade_8.png",
  95. "html_content/gfx/Spade_9.png",
  96. "html_content/gfx/Spade_10.png",
  97. "html_content/gfx/Spade_jack.png",
  98. "html_content/gfx/Spade_queen.png",
  99. "html_content/gfx/Spade_king.png"
  100. };
  101. IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
  102. //if (false == isoStore.FileExists(files[0]))
  103. //{
  104. foreach (string f in files)
  105. {
  106. StreamResourceInfo sr = Application.GetResourceStream(new Uri(f, UriKind.Relative));
  107. using (BinaryReader br = new BinaryReader(sr.Stream))
  108. {
  109. byte[] data = br.ReadBytes((int)sr.Stream.Length);
  110. SaveToIsoStore(f, data);
  111. }
  112. }
  113. //}
  114. }
  115. private void SaveToIsoStore(string fileName, byte[] data)
  116. {
  117. string strBaseDir = string.Empty;
  118. string delimStr = "/";
  119. char[] delimiter = delimStr.ToCharArray();
  120. string[] dirsPath = fileName.Split(delimiter);
  121. //Get the IsoStore.
  122. IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
  123. //Re-create the directory structure.
  124. for (int i = 0; i < dirsPath.Length - 1; i++)
  125. {
  126. strBaseDir = System.IO.Path.Combine(strBaseDir, dirsPath[i]);
  127. isoStore.CreateDirectory(strBaseDir);
  128. }
  129. //Remove the existing file.
  130. if (isoStore.FileExists(fileName))
  131. {
  132. isoStore.DeleteFile(fileName);
  133. }
  134. //Write the file.
  135. using (BinaryWriter bw = new BinaryWriter(isoStore.CreateFile(fileName)))
  136. {
  137. bw.Write(data);
  138. bw.Close();
  139. }
  140. }
  141. }
  142. }