Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using Windows.Storage;
- namespace Movie_Management_Windows_10.Business
- {
- using Views;
- public static class Cache
- {
- private static StorageFile SettingsFile;
- private static StorageFolder VideosFolder;
- private static List<String> LocatedFolders = new List<String>();
- private static AddVideoFolder VideoView;
- public static void Init()
- {
- CreateFolders();
- }
- public static void LoadVideoView(AddVideoFolder videoView)
- {
- VideoView = videoView;
- ReadVideoFolderSettings();
- }
- private static async void CreateFolders()
- {
- StorageFolder localFolder = ApplicationData.Current.LocalFolder;
- VideosFolder = await localFolder.CreateFolderAsync("\Videos\", CreationCollisionOption.OpenIfExists);
- StorageFolder settingsFolder = await localFolder.CreateFolderAsync("Settings\", CreationCollisionOption.OpenIfExists);
- SettingsFile = await settingsFolder.CreateFileAsync("settings.dat", CreationCollisionOption.OpenIfExists);
- }
- private static async void ReadVideoFolderSettings()
- {
- try
- {
- if (SettingsFile != null)
- {
- string fileContent = await FileIO.ReadTextAsync(SettingsFile);
- string[] rows = fileContent.Split('n');
- foreach(string row in rows)
- {
- string trimmedRow = row.Trim();
- LocatedFolders.Add(trimmedRow);
- VideoView.AddToListView(trimmedRow);
- }
- }
- }
- catch (FileNotFoundException)
- {
- //how?
- throw new FileNotFoundException();
- }
- }
- private static bool VideoExists(string path)
- {
- foreach(string row in LocatedFolders)
- {
- if (row == path)
- return true;
- }
- return false;
- }
- public static async void AddVideoFolderToSettings(string path)
- {
- if (!VideoExists(path))
- {
- string settingsData = "";
- foreach(string row in LocatedFolders)
- {
- settingsData += row;
- }
- settingsData += path + "rn";
- LocatedFolders.Add(path + "rn");
- await FileIO.WriteTextAsync(SettingsFile, settingsData);
- }
- }
- }
- }
- public AppShell()
- {
- this.InitializeComponent();
- Cache.Init();
- this.Loaded += (sender, args) =>
- {
- Current = this;
- this.TogglePaneButton.Focus(FocusState.Programmatic);
- };
- this.RootSplitView.RegisterPropertyChangedCallback(
- SplitView.DisplayModeProperty,
- (s, a) =>
- {
- // Ensure that we update the reported size of the TogglePaneButton when the SplitView's
- // DisplayMode changes.
- this.CheckTogglePaneButtonSizeChanged();
- });
- SystemNavigationManager.GetForCurrentView().BackRequested += SystemNavigationManager_BackRequested;
- NavMenuList.ItemsSource = navlist;
- }
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Runtime.InteropServices.WindowsRuntime;
- using Windows.Foundation;
- using Windows.Foundation.Collections;
- using Windows.UI.Xaml;
- using Windows.UI.Xaml.Controls;
- using Windows.UI.Xaml.Controls.Primitives;
- using Windows.UI.Xaml.Data;
- using Windows.UI.Xaml.Input;
- using Windows.UI.Xaml.Media;
- using Windows.UI.Xaml.Navigation;
- using Windows.Storage.Pickers;
- using Windows.Storage;
- using Windows.Storage.AccessCache;
- // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
- namespace Movie_Management_Windows_10.Views
- {
- using Business;
- /// <summary>
- /// An empty page that can be used on its own or navigated to within a Frame.
- /// </summary>
- public sealed partial class AddVideoFolder : Page
- {
- public AddVideoFolder()
- {
- this.InitializeComponent();
- Cache.LoadVideoView(this);
- }
- private void buttonAddVideoFolder_Click(object sender, RoutedEventArgs e)
- {
- AddBrowsedFolder();
- }
- private async void AddBrowsedFolder()
- {
- FolderPicker folderPicker = new FolderPicker();
- folderPicker.SuggestedStartLocation = PickerLocationId.VideosLibrary;
- folderPicker.FileTypeFilter.Add(".mp4");
- folderPicker.FileTypeFilter.Add(".avi");
- folderPicker.FileTypeFilter.Add(".flv");
- StorageFolder folder = await folderPicker.PickSingleFolderAsync();
- if(folder != null)
- {
- StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", folder);
- Cache.AddVideoFolderToSettings(folder.Path);
- }
- else
- {
- }
- }
- public void AddToListView(string Path)
- {
- this.listViewAddedVideoFolders.Items.Add(Path);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement