Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. using Windows.Storage;
  8.  
  9. namespace Movie_Management_Windows_10.Business
  10. {
  11. using Views;
  12. public static class Cache
  13. {
  14. private static StorageFile SettingsFile;
  15. private static StorageFolder VideosFolder;
  16. private static List<String> LocatedFolders = new List<String>();
  17. private static AddVideoFolder VideoView;
  18.  
  19. public static void Init()
  20. {
  21. CreateFolders();
  22. }
  23.  
  24. public static void LoadVideoView(AddVideoFolder videoView)
  25. {
  26. VideoView = videoView;
  27. ReadVideoFolderSettings();
  28. }
  29.  
  30. private static async void CreateFolders()
  31. {
  32. StorageFolder localFolder = ApplicationData.Current.LocalFolder;
  33. VideosFolder = await localFolder.CreateFolderAsync("\Videos\", CreationCollisionOption.OpenIfExists);
  34. StorageFolder settingsFolder = await localFolder.CreateFolderAsync("Settings\", CreationCollisionOption.OpenIfExists);
  35. SettingsFile = await settingsFolder.CreateFileAsync("settings.dat", CreationCollisionOption.OpenIfExists);
  36. }
  37.  
  38. private static async void ReadVideoFolderSettings()
  39. {
  40. try
  41. {
  42. if (SettingsFile != null)
  43. {
  44. string fileContent = await FileIO.ReadTextAsync(SettingsFile);
  45. string[] rows = fileContent.Split('n');
  46. foreach(string row in rows)
  47. {
  48. string trimmedRow = row.Trim();
  49. LocatedFolders.Add(trimmedRow);
  50. VideoView.AddToListView(trimmedRow);
  51. }
  52. }
  53. }
  54. catch (FileNotFoundException)
  55. {
  56. //how?
  57. throw new FileNotFoundException();
  58. }
  59. }
  60.  
  61. private static bool VideoExists(string path)
  62. {
  63. foreach(string row in LocatedFolders)
  64. {
  65. if (row == path)
  66. return true;
  67. }
  68. return false;
  69. }
  70.  
  71. public static async void AddVideoFolderToSettings(string path)
  72. {
  73. if (!VideoExists(path))
  74. {
  75. string settingsData = "";
  76. foreach(string row in LocatedFolders)
  77. {
  78. settingsData += row;
  79. }
  80. settingsData += path + "rn";
  81. LocatedFolders.Add(path + "rn");
  82. await FileIO.WriteTextAsync(SettingsFile, settingsData);
  83. }
  84. }
  85.  
  86. }
  87. }
  88.  
  89. public AppShell()
  90. {
  91. this.InitializeComponent();
  92. Cache.Init();
  93. this.Loaded += (sender, args) =>
  94. {
  95. Current = this;
  96.  
  97. this.TogglePaneButton.Focus(FocusState.Programmatic);
  98. };
  99.  
  100. this.RootSplitView.RegisterPropertyChangedCallback(
  101. SplitView.DisplayModeProperty,
  102. (s, a) =>
  103. {
  104. // Ensure that we update the reported size of the TogglePaneButton when the SplitView's
  105. // DisplayMode changes.
  106. this.CheckTogglePaneButtonSizeChanged();
  107. });
  108.  
  109. SystemNavigationManager.GetForCurrentView().BackRequested += SystemNavigationManager_BackRequested;
  110.  
  111. NavMenuList.ItemsSource = navlist;
  112. }
  113.  
  114. using System;
  115. using System.Collections.Generic;
  116. using System.IO;
  117. using System.Linq;
  118. using System.Runtime.InteropServices.WindowsRuntime;
  119. using Windows.Foundation;
  120. using Windows.Foundation.Collections;
  121. using Windows.UI.Xaml;
  122. using Windows.UI.Xaml.Controls;
  123. using Windows.UI.Xaml.Controls.Primitives;
  124. using Windows.UI.Xaml.Data;
  125. using Windows.UI.Xaml.Input;
  126. using Windows.UI.Xaml.Media;
  127. using Windows.UI.Xaml.Navigation;
  128. using Windows.Storage.Pickers;
  129. using Windows.Storage;
  130. using Windows.Storage.AccessCache;
  131.  
  132. // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
  133.  
  134. namespace Movie_Management_Windows_10.Views
  135. {
  136. using Business;
  137. /// <summary>
  138. /// An empty page that can be used on its own or navigated to within a Frame.
  139. /// </summary>
  140. public sealed partial class AddVideoFolder : Page
  141. {
  142. public AddVideoFolder()
  143. {
  144. this.InitializeComponent();
  145. Cache.LoadVideoView(this);
  146. }
  147.  
  148. private void buttonAddVideoFolder_Click(object sender, RoutedEventArgs e)
  149. {
  150. AddBrowsedFolder();
  151. }
  152.  
  153. private async void AddBrowsedFolder()
  154. {
  155. FolderPicker folderPicker = new FolderPicker();
  156. folderPicker.SuggestedStartLocation = PickerLocationId.VideosLibrary;
  157. folderPicker.FileTypeFilter.Add(".mp4");
  158. folderPicker.FileTypeFilter.Add(".avi");
  159. folderPicker.FileTypeFilter.Add(".flv");
  160.  
  161.  
  162. StorageFolder folder = await folderPicker.PickSingleFolderAsync();
  163. if(folder != null)
  164. {
  165. StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", folder);
  166. Cache.AddVideoFolderToSettings(folder.Path);
  167. }
  168. else
  169. {
  170.  
  171. }
  172. }
  173.  
  174. public void AddToListView(string Path)
  175. {
  176. this.listViewAddedVideoFolders.Items.Add(Path);
  177. }
  178. }
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement