Skip to content

Commit

Permalink
Update to Ver. 5.0.4, Downloader Enhansment
Browse files Browse the repository at this point in the history
  • Loading branch information
若凡 祝 committed Jun 18, 2019
1 parent 245c951 commit ecd7e10
Show file tree
Hide file tree
Showing 11 changed files with 553 additions and 481 deletions.
6 changes: 6 additions & 0 deletions SmartLens/About/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1677,10 +1677,16 @@

>>#####新增浏览器设置中关于默认下载位置调整的选项

>>#####解决了某些情况下历史记录产生多个相同记录的问题

>####其他改进

>>#####解决了各模块转换文件比特长度至通俗大小描述功能在特殊情况下可能出现的问题

>>#####简化了历史记录日期枚举的判断逻辑,将相关枚举变为位域

>>#####解决了SmartLensDownloader中存在的一些小问题,优化了整体结构

*****
*****
>##音乐模块参见
Expand Down
4 changes: 2 additions & 2 deletions SmartLens/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
viewTitleBar.ButtonBackgroundColor = Colors.Transparent;
viewTitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
viewTitleBar.ButtonForegroundColor = (Color)Resources["SystemBaseHighColor"];

OnLaunchOrOnActivate(e, true);
}

protected override void OnActivated(IActivatedEventArgs args)
{
if (args is ToastNotificationActivatedEventArgs e)
{
if (e.Argument == "Transcode" || e.Argument == "Update" || e.Argument == "Email")
if (e.Argument == "Transcode" || e.Argument == "Update" || e.Argument == "Email" || e.Argument == "DownloadNotification")
{
return;
}
Expand Down
176 changes: 136 additions & 40 deletions SmartLens/Class/ClassCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using MimeKit.Tnef;
using Newtonsoft.Json;
using SmartLens.NetEase;
using SmartLensDownloaderProvider;
using System;
using System.Collections.Generic;
using System.ComponentModel;
Expand Down Expand Up @@ -1179,7 +1180,8 @@ private SQLite()
Create Table If Not Exists WiFiRecord (SSID Text Not Null, Password Text Not Null, AutoConnect Text Not Null, Primary Key (SSID,Password,AutoConnect));
Create Table If Not Exists HashTable (FileName Text Not Null, HashValue Text Not Null, Primary Key (FileName,HashValue));
Create Table If Not Exists WebFavourite (Subject Text Not Null, WebSite Text Not Null, Primary Key (WebSite));
Create Table If Not Exists WebHistory (Subject Text Not Null, WebSite Text Not Null, DateTime Text Not Null, Primary Key (Subject, WebSite, DateTime))";
Create Table If Not Exists WebHistory (Subject Text Not Null, WebSite Text Not Null, DateTime Text Not Null, Primary Key (Subject, WebSite, DateTime));
Create Table If Not Exists DownloadHistory (UniqueID Text Not Null, ActualName Text Not Null, Uri Text Not Null, State Text Not Null, Primary Key(UniqueID))";
SqliteCommand CreateTable = new SqliteCommand(Command, OLEDB);
_ = CreateTable.ExecuteNonQuery();
}
Expand Down Expand Up @@ -1253,11 +1255,11 @@ public async Task<List<KeyValuePair<DateTime, WebSiteItem>>> GetWebHistoryListAs
public void DeleteWebHistory(KeyValuePair<DateTime, WebSiteItem> Info)
{
SqliteCommand Command = new SqliteCommand("Delete From WebHistory Where Subject=@Subject And WebSite=@WebSite And DateTime=@DateTime", OLEDB);
Command.Parameters.AddWithValue("@Subject", Info.Value.Subject);
Command.Parameters.AddWithValue("@WebSite", Info.Value.WebSite);
Command.Parameters.AddWithValue("@DateTime", Info.Key.ToBinary().ToString());
_ = Command.Parameters.AddWithValue("@Subject", Info.Value.Subject);
_ = Command.Parameters.AddWithValue("@WebSite", Info.Value.WebSite);
_ = Command.Parameters.AddWithValue("@DateTime", Info.Key.ToBinary().ToString());

Command.ExecuteNonQuery();
_ = Command.ExecuteNonQuery();
}

/// <summary>
Expand All @@ -1267,11 +1269,11 @@ public void DeleteWebHistory(KeyValuePair<DateTime, WebSiteItem> Info)
public void SetWebHistoryList(KeyValuePair<DateTime, WebSiteItem> Info)
{
SqliteCommand Command = new SqliteCommand("Insert Into WebHistory Values (@Subject,@WebSite,@DateTime)", OLEDB);
Command.Parameters.AddWithValue("@Subject", Info.Value.Subject);
Command.Parameters.AddWithValue("@WebSite", Info.Value.WebSite);
Command.Parameters.AddWithValue("@DateTime", Info.Key.ToBinary().ToString());
_ = Command.Parameters.AddWithValue("@Subject", Info.Value.Subject);
_ = Command.Parameters.AddWithValue("@WebSite", Info.Value.WebSite);
_ = Command.Parameters.AddWithValue("@DateTime", Info.Key.ToBinary().ToString());

Command.ExecuteNonQuery();
_ = Command.ExecuteNonQuery();
}

/// <summary>
Expand All @@ -1282,8 +1284,8 @@ public void SetWebHistoryList(KeyValuePair<DateTime, WebSiteItem> Info)
public async Task SetWebFavouriteListAsync(WebSiteItem Info)
{
SqliteCommand Command = new SqliteCommand("Insert Into WebFavourite Values (@Subject,@WebSite)", OLEDB);
Command.Parameters.AddWithValue("@Subject", Info.Subject);
Command.Parameters.AddWithValue("@WebSite", Info.WebSite);
_ = Command.Parameters.AddWithValue("@Subject", Info.Subject);
_ = Command.Parameters.AddWithValue("@WebSite", Info.WebSite);
_ = await Command.ExecuteNonQueryAsync();
}

Expand All @@ -1295,7 +1297,68 @@ public async Task SetWebFavouriteListAsync(WebSiteItem Info)
public async Task DeleteWebFavouriteListAsync(WebSiteItem Info)
{
SqliteCommand Command = new SqliteCommand("Delete From WebFavourite Where WebSite = @WebSite", OLEDB);
Command.Parameters.AddWithValue("@WebSite", Info.WebSite);
_ = Command.Parameters.AddWithValue("@WebSite", Info.WebSite);
_ = await Command.ExecuteNonQueryAsync();
}

/// <summary>
/// 异步获取下载列表记录
/// </summary>
/// <returns>无</returns>
public async Task GetDownloadHistoryAsync()
{
SqliteCommand Command = new SqliteCommand("Select * From DownloadHistory", OLEDB);
SqliteDataReader query = await Command.ExecuteReaderAsync();

for (int i = 0; query.Read(); i++)
{
DownloadState State = (DownloadState)Enum.Parse(typeof(DownloadState), query[3].ToString());
if (State == DownloadState.Downloading || State == DownloadState.Paused)
{
State = DownloadState.Canceled;
}

SmartLensDownloader.DownloadList.Add(SmartLensDownloader.CreateDownloadOperatorFromDatabase(new Uri(query[2].ToString()), query[1].ToString(), State, query[0].ToString())); ;
}
}

/// <summary>
/// 更新下载列表状态
/// </summary>
/// <param name="Task"></param>
/// <returns></returns>
public async Task UpdateDownloadHistoryAsync(DownloadOperator Task)
{
SqliteCommand Command = new SqliteCommand("Update DownloadHistory Set State = @State Where UniqueID = @UniqueID", OLEDB);
_ = Command.Parameters.AddWithValue("@UniqueID", Task.UniqueID);
_ = Command.Parameters.AddWithValue("@State", Enum.GetName(typeof(DownloadState), Task.State));
_ = await Command.ExecuteNonQueryAsync();
}

/// <summary>
/// 异步删除特定下载列表项
/// </summary>
/// <param name="Task">下载列表对象</param>
/// <returns></returns>
public async Task DeleteDownloadHistoryAsync(DownloadOperator Task)
{
SqliteCommand Command = new SqliteCommand("Delete From DownloadHistory Where UniqueID = @UniqueID", OLEDB);
_ = Command.Parameters.AddWithValue("@UniqueID", Task.UniqueID);
_ = await Command.ExecuteNonQueryAsync();
}

/// <summary>
/// 异步插入特定下载列表项
/// </summary>
/// <param name="Task">下载列表项</param>
/// <returns></returns>
public async Task SetDownloadHistoryAsync(DownloadOperator Task)
{
SqliteCommand Command = new SqliteCommand("Insert Into DownloadHistory Values (@UniqueID,@ActualName,@Uri,@State)", OLEDB);
_ = Command.Parameters.AddWithValue("@UniqueID", Task.UniqueID);
_ = Command.Parameters.AddWithValue("@ActualName", Task.ActualFileName);
_ = Command.Parameters.AddWithValue("@Uri", Task.Address.AbsoluteUri);
_ = Command.Parameters.AddWithValue("@State", Enum.GetName(typeof(DownloadState), Task.State));
_ = await Command.ExecuteNonQueryAsync();
}

Expand Down Expand Up @@ -1421,13 +1484,13 @@ public async Task<List<KeyValuePair<string, string>>> GetHeshValueAsync()
public async Task SetMusicDataAsync(string MusicName, string Artist, string Album, string Duration, string ImageURL, long SongID, long MVid)
{
SqliteCommand Command = new SqliteCommand("Insert Into MusicList Values (@MusicName,@Artist,@Album,@Duration,@ImageURL,@SongID,@MVid)", OLEDB);
Command.Parameters.AddWithValue("@MusicName", MusicName);
Command.Parameters.AddWithValue("@Artist", Artist);
Command.Parameters.AddWithValue("@Album", Album);
Command.Parameters.AddWithValue("@Duration", Duration);
Command.Parameters.AddWithValue("@SongID", SongID);
Command.Parameters.AddWithValue("@ImageURL", ImageURL);
Command.Parameters.AddWithValue("@MVid", MVid);
_ = Command.Parameters.AddWithValue("@MusicName", MusicName);
_ = Command.Parameters.AddWithValue("@Artist", Artist);
_ = Command.Parameters.AddWithValue("@Album", Album);
_ = Command.Parameters.AddWithValue("@Duration", Duration);
_ = Command.Parameters.AddWithValue("@SongID", SongID);
_ = Command.Parameters.AddWithValue("@ImageURL", ImageURL);
_ = Command.Parameters.AddWithValue("@MVid", MVid);
_ = await Command.ExecuteNonQueryAsync();
}

Expand All @@ -1439,10 +1502,10 @@ public async Task SetMusicDataAsync(string MusicName, string Artist, string Albu
public async Task DeleteMusicAsync(PlayList list)
{
SqliteCommand Command = new SqliteCommand("Delete From MusicList Where MusicName=@MusicName And Artist=@Artist And Album=@Album And Duration=@Duration", OLEDB);
Command.Parameters.AddWithValue("@MusicName", list.Music);
Command.Parameters.AddWithValue("@Artist", list.Artist);
Command.Parameters.AddWithValue("@Album", list.Album);
Command.Parameters.AddWithValue("@Duration", list.Duration);
_ = Command.Parameters.AddWithValue("@MusicName", list.Music);
_ = Command.Parameters.AddWithValue("@Artist", list.Artist);
_ = Command.Parameters.AddWithValue("@Album", list.Album);
_ = Command.Parameters.AddWithValue("@Duration", list.Duration);
_ = await Command.ExecuteNonQueryAsync();
}

Expand Down Expand Up @@ -1473,8 +1536,8 @@ public async Task<List<WiFiInDataBase>> GetAllWiFiDataAsync()
public async Task UpdateWiFiDataAsync(string SSID, bool AutoConnect)
{
SqliteCommand Command = new SqliteCommand("Update WiFiRecord Set AutoConnect = @AutoConnect Where SSID = @SSID", OLEDB);
Command.Parameters.AddWithValue("@SSID", SSID);
Command.Parameters.AddWithValue("@AutoConnect", AutoConnect ? "True" : "False");
_ = Command.Parameters.AddWithValue("@SSID", SSID);
_ = Command.Parameters.AddWithValue("@AutoConnect", AutoConnect ? "True" : "False");

_ = await Command.ExecuteNonQueryAsync();
}
Expand All @@ -1488,8 +1551,8 @@ public async Task UpdateWiFiDataAsync(string SSID, bool AutoConnect)
public async Task UpdateWiFiDataAsync(string SSID, string Password)
{
SqliteCommand Command = new SqliteCommand("Update WiFiRecord Set Password = @Password Where SSID = @SSID", OLEDB);
Command.Parameters.AddWithValue("@SSID", SSID);
Command.Parameters.AddWithValue("@Password", Password);
_ = Command.Parameters.AddWithValue("@SSID", SSID);
_ = Command.Parameters.AddWithValue("@Password", Password);

_ = await Command.ExecuteNonQueryAsync();
}
Expand All @@ -1504,9 +1567,9 @@ public async Task UpdateWiFiDataAsync(string SSID, string Password)
public async Task SetWiFiDataAsync(string SSID, string Password, bool AutoConnect)
{
SqliteCommand Command = new SqliteCommand("Insert Into WiFiRecord Values (@SSID , @Password , @AutoConnect)", OLEDB);
Command.Parameters.AddWithValue("@SSID", SSID);
Command.Parameters.AddWithValue("@Password", Password);
Command.Parameters.AddWithValue("@AutoConnect", AutoConnect ? "True" : "False");
_ = Command.Parameters.AddWithValue("@SSID", SSID);
_ = Command.Parameters.AddWithValue("@Password", Password);
_ = Command.Parameters.AddWithValue("@AutoConnect", AutoConnect ? "True" : "False");

_ = await Command.ExecuteNonQueryAsync();
}
Expand All @@ -1520,8 +1583,8 @@ public void Dispose()
{
OLEDB.Dispose();
OLEDB = null;
SQL = null;
}
SQL = null;
IsDisposed = true;
}

Expand Down Expand Up @@ -3985,16 +4048,13 @@ public WebSiteItem(string Subject, string WebSite)
/// <summary>
/// 历史记录分类标题种类枚举
/// </summary>
public enum HistoryTreeFlag
[Flags]
public enum HistoryTreeCategoryFlag
{
All = 0,
TodayYesterday = 1,
TodayEarlier = 2,
YesterdayEarlier = 3,
Today = 4,
Yesterday = 5,
Earlier = 6,
None = 7
Today = 1,
Yesterday = 2,
Earlier = 4,
None = 8
}
#endregion

Expand Down Expand Up @@ -4401,4 +4461,40 @@ private List<StorageFile> Except(IEnumerable<StorageFile> list1, IEnumerable<Sto
}
}
#endregion

#region 下载列表模板选择器
public sealed class DownloadTemplateSelector : DataTemplateSelector
{
public DataTemplate DownloadingTemplate { get; set; }
public DataTemplate DownloadErrorTemplate { get; set; }
public DataTemplate DownloadCompleteTemplate { get; set; }
public DataTemplate DownloadCancelTemplate { get; set; }
public DataTemplate DownloadPauseTemplate { get; set; }

protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
{
if (item is DownloadOperator Operator)
{
switch (Operator.State)
{
case DownloadState.AlreadyFinished:
return DownloadCompleteTemplate;
case DownloadState.Canceled:
return DownloadCancelTemplate;
case DownloadState.Downloading:
return DownloadingTemplate;
case DownloadState.Error:
return DownloadErrorTemplate;
case DownloadState.Paused:
return DownloadPauseTemplate;
default: return null;
}
}
else
{
return null;
}
}
}
#endregion
}
2 changes: 1 addition & 1 deletion SmartLens/Package.appxmanifest
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3" xmlns:iot="http://schemas.microsoft.com/appx/manifest/iot/windows10" IgnorableNamespaces="uap mp uap3 iot">
<Identity Name="428cf39b-0a14-4a17-b3db-521ad0abb62e" Publisher="CN=Ruofan" Version="5.0.0.0" />
<Identity Name="428cf39b-0a14-4a17-b3db-521ad0abb62e" Publisher="CN=Ruofan" Version="5.0.4.0" />
<mp:PhoneIdentity PhoneProductId="428cf39b-0a14-4a17-b3db-521ad0abb62e" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties>
<DisplayName>SmartLens</DisplayName>
Expand Down
10 changes: 5 additions & 5 deletions SmartLens/Setting/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private async void OnFirstLoad()
ScreenCaptureSwitch.IsOn = !Enable;
}

if(ApplicationData.Current.LocalSettings.Values["EmailProtectionMode"] is bool EnableEmailProtection)
if (ApplicationData.Current.LocalSettings.Values["EmailProtectionMode"] is bool EnableEmailProtection)
{
EmailProtectionSwitch.IsOn = EnableEmailProtection;
}
Expand Down Expand Up @@ -744,7 +744,7 @@ private async void ResetButton_Click(object sender, RoutedEventArgs e)
await ApplicationData.Current.ClearAsync();
ToastContent content = PopToast.GenerateToastContent();
ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(content.GetXml()));
CoreApplication.Exit();
Application.Current.Exit();
}
}

Expand Down Expand Up @@ -845,10 +845,10 @@ private async void EmailProtectionSwitch_Toggled(object sender, RoutedEventArgs
{
Title = "警告",
Content = " 由于Windows Hello尚未设置,无法启用Windows Hello验证\r\r 请先设置Windows Hello后再试",
PrimaryButtonText="前往",
PrimaryButtonText = "前往",
CloseButtonText = "取消"
};
dialog.PrimaryButtonClick += async(s, t) =>
dialog.PrimaryButtonClick += async (s, t) =>
{
await Launcher.LaunchUriAsync(new Uri("ms-settings:signinoptions"));
};
Expand All @@ -863,7 +863,7 @@ private async void EmailProtectionSwitch_Toggled(object sender, RoutedEventArgs

private void WebDirectionSwitch_Toggled(object sender, RoutedEventArgs e)
{
if(WebDirectionSwitch.IsOn)
if (WebDirectionSwitch.IsOn)
{
ApplicationData.Current.LocalSettings.Values["UseInsideWebBrowser"] = true;
}
Expand Down
Loading

0 comments on commit ecd7e10

Please sign in to comment.