Archived
1
0
This repository has been archived on 2026-04-22. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
FoxTube/FoxTube/Pages/Downloads.xaml.cs
T
2018-07-12 10:57:33 +03:00

71 lines
2.3 KiB
C#

using FoxTube.Controls;
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.Storage;
using Windows.Storage.Pickers;
using Windows.System;
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;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
#pragma warning disable CS0252 // Possible unintended reference comparison; left hand side needs cast
namespace FoxTube.Pages
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class Downloads : Page
{
ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
DownloadAgent agent = Methods.MainPage.Agent;
public Downloads()
{
this.InitializeComponent();
path.Text = settings.Values["defaultDownload"] as string;
agent.ListChanged += UpdateList;
foreach (DownloadItem item in agent.Items)
stack.Children.Add(item);
}
private void UpdateList(object sender, ObjectEventArgs e)
{
if (e.Parameters[0] == "remove")
stack.Children.Remove(sender as DownloadItem);
else if (e.Parameters[0] == "add")
stack.Children.Add(sender as DownloadItem);
}
private async void changePath_Click(object sender, RoutedEventArgs e)
{
FolderPicker picker = new FolderPicker()
{
SuggestedStartLocation = PickerLocationId.Desktop,
ViewMode = PickerViewMode.Thumbnail
};
StorageFolder p = await picker.PickSingleFolderAsync();
if (p != null)
settings.Values["defaultDownload"] = p.Path;
path.Text = settings.Values["defaultDownload"] as string;
}
private async void openFolder_Click(object sender, RoutedEventArgs e)
{
await Launcher.LaunchUriAsync(new Uri(settings.Values["defaultDownload"] as string));
}
}
}