f637c18e22
- Closed captions fixes - Merged to YoutubeExplode instead of MyToolkit for video sources - Video playback fixes - Internal links support - Subscription button fixed - Comments threads fixes and improvements (highlighting author's and user's names) - General bug fixes
73 lines
2.5 KiB
C#
73 lines
2.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using Windows.Storage;
|
|
using FoxTube.Classes;
|
|
using Newtonsoft.Json;
|
|
using Windows.UI.Popups;
|
|
|
|
namespace FoxTube.Controls
|
|
{
|
|
public class DownloadAgent
|
|
{
|
|
public List<DownloadItem> items = new List<DownloadItem>();
|
|
StorageFolder roaming = ApplicationData.Current.RoamingFolder;
|
|
|
|
public DownloadAgent()
|
|
{
|
|
Initialize();
|
|
Windows.UI.Core.Preview.SystemNavigationManagerPreview.GetForCurrentView().CloseRequested += (s, a) => QuitPrompt();
|
|
}
|
|
|
|
public async void Initialize()
|
|
{
|
|
try
|
|
{
|
|
List<DownloadItemContainer> containers = JsonConvert.DeserializeObject<List<DownloadItemContainer>>(await FileIO.ReadTextAsync(await roaming.GetFileAsync("data.json")));
|
|
|
|
foreach (DownloadItemContainer i in containers)
|
|
try { items.Add(new DownloadItem(i)); }
|
|
catch (FileNotFoundException) { }
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
public void Add(string url)
|
|
{
|
|
items.Add(new DownloadItem(url));
|
|
}
|
|
|
|
private void Item_DownloadCanceled(object sender, params object[] e)
|
|
{
|
|
items.Remove(sender as DownloadItem);
|
|
}
|
|
|
|
public async void QuitPrompt()
|
|
{
|
|
if(items.Find(x => x.InProgress) != null)
|
|
{
|
|
MessageDialog dialog = new MessageDialog("You have some unfinished downloads. Quitting now will erase all downloaded data. Are you sure to continue?", "Some downloads are still pending");
|
|
|
|
dialog.Commands.Add(new UICommand("Yes", async (command) =>
|
|
{
|
|
foreach (DownloadItem i in items.FindAll(x => x.InProgress))
|
|
i.Cancel();
|
|
items.RemoveAll(x => x.InProgress);
|
|
|
|
List<DownloadItemContainer> containers = new List<DownloadItemContainer>();
|
|
foreach (DownloadItem i in items)
|
|
containers.Add(i.Container);
|
|
|
|
await FileIO.WriteTextAsync(
|
|
await roaming.CreateFileAsync("data.json", CreationCollisionOption.ReplaceExisting),
|
|
JsonConvert.SerializeObject(containers));
|
|
}));
|
|
dialog.Commands.Add(new UICommand("No"));
|
|
|
|
dialog.DefaultCommandIndex = 1;
|
|
await dialog.ShowAsync();
|
|
}
|
|
}
|
|
}
|
|
}
|