Skip to content

Commit ecd7e10

Browse files
author
若凡 祝
committed
Update to Ver. 5.0.4, Downloader Enhansment
1 parent 245c951 commit ecd7e10

File tree

11 files changed

+553
-481
lines changed

11 files changed

+553
-481
lines changed

SmartLens/About/ChangeLog.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,10 +1677,16 @@
16771677

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

1680+
>>#####解决了某些情况下历史记录产生多个相同记录的问题
1681+
16801682
>####其他改进
16811683

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

1686+
>>#####简化了历史记录日期枚举的判断逻辑,将相关枚举变为位域
1687+
1688+
>>#####解决了SmartLensDownloader中存在的一些小问题,优化了整体结构
1689+
16841690
*****
16851691
*****
16861692
>##音乐模块参见

SmartLens/App.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
6969
viewTitleBar.ButtonBackgroundColor = Colors.Transparent;
7070
viewTitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
7171
viewTitleBar.ButtonForegroundColor = (Color)Resources["SystemBaseHighColor"];
72-
72+
7373
OnLaunchOrOnActivate(e, true);
7474
}
7575

7676
protected override void OnActivated(IActivatedEventArgs args)
7777
{
7878
if (args is ToastNotificationActivatedEventArgs e)
7979
{
80-
if (e.Argument == "Transcode" || e.Argument == "Update" || e.Argument == "Email")
80+
if (e.Argument == "Transcode" || e.Argument == "Update" || e.Argument == "Email" || e.Argument == "DownloadNotification")
8181
{
8282
return;
8383
}

SmartLens/Class/ClassCollection.cs

Lines changed: 136 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using MimeKit.Tnef;
1212
using Newtonsoft.Json;
1313
using SmartLens.NetEase;
14+
using SmartLensDownloaderProvider;
1415
using System;
1516
using System.Collections.Generic;
1617
using System.ComponentModel;
@@ -1179,7 +1180,8 @@ private SQLite()
11791180
Create Table If Not Exists WiFiRecord (SSID Text Not Null, Password Text Not Null, AutoConnect Text Not Null, Primary Key (SSID,Password,AutoConnect));
11801181
Create Table If Not Exists HashTable (FileName Text Not Null, HashValue Text Not Null, Primary Key (FileName,HashValue));
11811182
Create Table If Not Exists WebFavourite (Subject Text Not Null, WebSite Text Not Null, Primary Key (WebSite));
1182-
Create Table If Not Exists WebHistory (Subject Text Not Null, WebSite Text Not Null, DateTime Text Not Null, Primary Key (Subject, WebSite, DateTime))";
1183+
Create Table If Not Exists WebHistory (Subject Text Not Null, WebSite Text Not Null, DateTime Text Not Null, Primary Key (Subject, WebSite, DateTime));
1184+
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))";
11831185
SqliteCommand CreateTable = new SqliteCommand(Command, OLEDB);
11841186
_ = CreateTable.ExecuteNonQuery();
11851187
}
@@ -1253,11 +1255,11 @@ public async Task<List<KeyValuePair<DateTime, WebSiteItem>>> GetWebHistoryListAs
12531255
public void DeleteWebHistory(KeyValuePair<DateTime, WebSiteItem> Info)
12541256
{
12551257
SqliteCommand Command = new SqliteCommand("Delete From WebHistory Where Subject=@Subject And WebSite=@WebSite And DateTime=@DateTime", OLEDB);
1256-
Command.Parameters.AddWithValue("@Subject", Info.Value.Subject);
1257-
Command.Parameters.AddWithValue("@WebSite", Info.Value.WebSite);
1258-
Command.Parameters.AddWithValue("@DateTime", Info.Key.ToBinary().ToString());
1258+
_ = Command.Parameters.AddWithValue("@Subject", Info.Value.Subject);
1259+
_ = Command.Parameters.AddWithValue("@WebSite", Info.Value.WebSite);
1260+
_ = Command.Parameters.AddWithValue("@DateTime", Info.Key.ToBinary().ToString());
12591261

1260-
Command.ExecuteNonQuery();
1262+
_ = Command.ExecuteNonQuery();
12611263
}
12621264

12631265
/// <summary>
@@ -1267,11 +1269,11 @@ public void DeleteWebHistory(KeyValuePair<DateTime, WebSiteItem> Info)
12671269
public void SetWebHistoryList(KeyValuePair<DateTime, WebSiteItem> Info)
12681270
{
12691271
SqliteCommand Command = new SqliteCommand("Insert Into WebHistory Values (@Subject,@WebSite,@DateTime)", OLEDB);
1270-
Command.Parameters.AddWithValue("@Subject", Info.Value.Subject);
1271-
Command.Parameters.AddWithValue("@WebSite", Info.Value.WebSite);
1272-
Command.Parameters.AddWithValue("@DateTime", Info.Key.ToBinary().ToString());
1272+
_ = Command.Parameters.AddWithValue("@Subject", Info.Value.Subject);
1273+
_ = Command.Parameters.AddWithValue("@WebSite", Info.Value.WebSite);
1274+
_ = Command.Parameters.AddWithValue("@DateTime", Info.Key.ToBinary().ToString());
12731275

1274-
Command.ExecuteNonQuery();
1276+
_ = Command.ExecuteNonQuery();
12751277
}
12761278

12771279
/// <summary>
@@ -1282,8 +1284,8 @@ public void SetWebHistoryList(KeyValuePair<DateTime, WebSiteItem> Info)
12821284
public async Task SetWebFavouriteListAsync(WebSiteItem Info)
12831285
{
12841286
SqliteCommand Command = new SqliteCommand("Insert Into WebFavourite Values (@Subject,@WebSite)", OLEDB);
1285-
Command.Parameters.AddWithValue("@Subject", Info.Subject);
1286-
Command.Parameters.AddWithValue("@WebSite", Info.WebSite);
1287+
_ = Command.Parameters.AddWithValue("@Subject", Info.Subject);
1288+
_ = Command.Parameters.AddWithValue("@WebSite", Info.WebSite);
12871289
_ = await Command.ExecuteNonQueryAsync();
12881290
}
12891291

@@ -1295,7 +1297,68 @@ public async Task SetWebFavouriteListAsync(WebSiteItem Info)
12951297
public async Task DeleteWebFavouriteListAsync(WebSiteItem Info)
12961298
{
12971299
SqliteCommand Command = new SqliteCommand("Delete From WebFavourite Where WebSite = @WebSite", OLEDB);
1298-
Command.Parameters.AddWithValue("@WebSite", Info.WebSite);
1300+
_ = Command.Parameters.AddWithValue("@WebSite", Info.WebSite);
1301+
_ = await Command.ExecuteNonQueryAsync();
1302+
}
1303+
1304+
/// <summary>
1305+
/// 异步获取下载列表记录
1306+
/// </summary>
1307+
/// <returns>无</returns>
1308+
public async Task GetDownloadHistoryAsync()
1309+
{
1310+
SqliteCommand Command = new SqliteCommand("Select * From DownloadHistory", OLEDB);
1311+
SqliteDataReader query = await Command.ExecuteReaderAsync();
1312+
1313+
for (int i = 0; query.Read(); i++)
1314+
{
1315+
DownloadState State = (DownloadState)Enum.Parse(typeof(DownloadState), query[3].ToString());
1316+
if (State == DownloadState.Downloading || State == DownloadState.Paused)
1317+
{
1318+
State = DownloadState.Canceled;
1319+
}
1320+
1321+
SmartLensDownloader.DownloadList.Add(SmartLensDownloader.CreateDownloadOperatorFromDatabase(new Uri(query[2].ToString()), query[1].ToString(), State, query[0].ToString())); ;
1322+
}
1323+
}
1324+
1325+
/// <summary>
1326+
/// 更新下载列表状态
1327+
/// </summary>
1328+
/// <param name="Task"></param>
1329+
/// <returns></returns>
1330+
public async Task UpdateDownloadHistoryAsync(DownloadOperator Task)
1331+
{
1332+
SqliteCommand Command = new SqliteCommand("Update DownloadHistory Set State = @State Where UniqueID = @UniqueID", OLEDB);
1333+
_ = Command.Parameters.AddWithValue("@UniqueID", Task.UniqueID);
1334+
_ = Command.Parameters.AddWithValue("@State", Enum.GetName(typeof(DownloadState), Task.State));
1335+
_ = await Command.ExecuteNonQueryAsync();
1336+
}
1337+
1338+
/// <summary>
1339+
/// 异步删除特定下载列表项
1340+
/// </summary>
1341+
/// <param name="Task">下载列表对象</param>
1342+
/// <returns></returns>
1343+
public async Task DeleteDownloadHistoryAsync(DownloadOperator Task)
1344+
{
1345+
SqliteCommand Command = new SqliteCommand("Delete From DownloadHistory Where UniqueID = @UniqueID", OLEDB);
1346+
_ = Command.Parameters.AddWithValue("@UniqueID", Task.UniqueID);
1347+
_ = await Command.ExecuteNonQueryAsync();
1348+
}
1349+
1350+
/// <summary>
1351+
/// 异步插入特定下载列表项
1352+
/// </summary>
1353+
/// <param name="Task">下载列表项</param>
1354+
/// <returns></returns>
1355+
public async Task SetDownloadHistoryAsync(DownloadOperator Task)
1356+
{
1357+
SqliteCommand Command = new SqliteCommand("Insert Into DownloadHistory Values (@UniqueID,@ActualName,@Uri,@State)", OLEDB);
1358+
_ = Command.Parameters.AddWithValue("@UniqueID", Task.UniqueID);
1359+
_ = Command.Parameters.AddWithValue("@ActualName", Task.ActualFileName);
1360+
_ = Command.Parameters.AddWithValue("@Uri", Task.Address.AbsoluteUri);
1361+
_ = Command.Parameters.AddWithValue("@State", Enum.GetName(typeof(DownloadState), Task.State));
12991362
_ = await Command.ExecuteNonQueryAsync();
13001363
}
13011364

@@ -1421,13 +1484,13 @@ public async Task<List<KeyValuePair<string, string>>> GetHeshValueAsync()
14211484
public async Task SetMusicDataAsync(string MusicName, string Artist, string Album, string Duration, string ImageURL, long SongID, long MVid)
14221485
{
14231486
SqliteCommand Command = new SqliteCommand("Insert Into MusicList Values (@MusicName,@Artist,@Album,@Duration,@ImageURL,@SongID,@MVid)", OLEDB);
1424-
Command.Parameters.AddWithValue("@MusicName", MusicName);
1425-
Command.Parameters.AddWithValue("@Artist", Artist);
1426-
Command.Parameters.AddWithValue("@Album", Album);
1427-
Command.Parameters.AddWithValue("@Duration", Duration);
1428-
Command.Parameters.AddWithValue("@SongID", SongID);
1429-
Command.Parameters.AddWithValue("@ImageURL", ImageURL);
1430-
Command.Parameters.AddWithValue("@MVid", MVid);
1487+
_ = Command.Parameters.AddWithValue("@MusicName", MusicName);
1488+
_ = Command.Parameters.AddWithValue("@Artist", Artist);
1489+
_ = Command.Parameters.AddWithValue("@Album", Album);
1490+
_ = Command.Parameters.AddWithValue("@Duration", Duration);
1491+
_ = Command.Parameters.AddWithValue("@SongID", SongID);
1492+
_ = Command.Parameters.AddWithValue("@ImageURL", ImageURL);
1493+
_ = Command.Parameters.AddWithValue("@MVid", MVid);
14311494
_ = await Command.ExecuteNonQueryAsync();
14321495
}
14331496

@@ -1439,10 +1502,10 @@ public async Task SetMusicDataAsync(string MusicName, string Artist, string Albu
14391502
public async Task DeleteMusicAsync(PlayList list)
14401503
{
14411504
SqliteCommand Command = new SqliteCommand("Delete From MusicList Where MusicName=@MusicName And Artist=@Artist And Album=@Album And Duration=@Duration", OLEDB);
1442-
Command.Parameters.AddWithValue("@MusicName", list.Music);
1443-
Command.Parameters.AddWithValue("@Artist", list.Artist);
1444-
Command.Parameters.AddWithValue("@Album", list.Album);
1445-
Command.Parameters.AddWithValue("@Duration", list.Duration);
1505+
_ = Command.Parameters.AddWithValue("@MusicName", list.Music);
1506+
_ = Command.Parameters.AddWithValue("@Artist", list.Artist);
1507+
_ = Command.Parameters.AddWithValue("@Album", list.Album);
1508+
_ = Command.Parameters.AddWithValue("@Duration", list.Duration);
14461509
_ = await Command.ExecuteNonQueryAsync();
14471510
}
14481511

@@ -1473,8 +1536,8 @@ public async Task<List<WiFiInDataBase>> GetAllWiFiDataAsync()
14731536
public async Task UpdateWiFiDataAsync(string SSID, bool AutoConnect)
14741537
{
14751538
SqliteCommand Command = new SqliteCommand("Update WiFiRecord Set AutoConnect = @AutoConnect Where SSID = @SSID", OLEDB);
1476-
Command.Parameters.AddWithValue("@SSID", SSID);
1477-
Command.Parameters.AddWithValue("@AutoConnect", AutoConnect ? "True" : "False");
1539+
_ = Command.Parameters.AddWithValue("@SSID", SSID);
1540+
_ = Command.Parameters.AddWithValue("@AutoConnect", AutoConnect ? "True" : "False");
14781541

14791542
_ = await Command.ExecuteNonQueryAsync();
14801543
}
@@ -1488,8 +1551,8 @@ public async Task UpdateWiFiDataAsync(string SSID, bool AutoConnect)
14881551
public async Task UpdateWiFiDataAsync(string SSID, string Password)
14891552
{
14901553
SqliteCommand Command = new SqliteCommand("Update WiFiRecord Set Password = @Password Where SSID = @SSID", OLEDB);
1491-
Command.Parameters.AddWithValue("@SSID", SSID);
1492-
Command.Parameters.AddWithValue("@Password", Password);
1554+
_ = Command.Parameters.AddWithValue("@SSID", SSID);
1555+
_ = Command.Parameters.AddWithValue("@Password", Password);
14931556

14941557
_ = await Command.ExecuteNonQueryAsync();
14951558
}
@@ -1504,9 +1567,9 @@ public async Task UpdateWiFiDataAsync(string SSID, string Password)
15041567
public async Task SetWiFiDataAsync(string SSID, string Password, bool AutoConnect)
15051568
{
15061569
SqliteCommand Command = new SqliteCommand("Insert Into WiFiRecord Values (@SSID , @Password , @AutoConnect)", OLEDB);
1507-
Command.Parameters.AddWithValue("@SSID", SSID);
1508-
Command.Parameters.AddWithValue("@Password", Password);
1509-
Command.Parameters.AddWithValue("@AutoConnect", AutoConnect ? "True" : "False");
1570+
_ = Command.Parameters.AddWithValue("@SSID", SSID);
1571+
_ = Command.Parameters.AddWithValue("@Password", Password);
1572+
_ = Command.Parameters.AddWithValue("@AutoConnect", AutoConnect ? "True" : "False");
15101573

15111574
_ = await Command.ExecuteNonQueryAsync();
15121575
}
@@ -1520,8 +1583,8 @@ public void Dispose()
15201583
{
15211584
OLEDB.Dispose();
15221585
OLEDB = null;
1586+
SQL = null;
15231587
}
1524-
SQL = null;
15251588
IsDisposed = true;
15261589
}
15271590

@@ -3985,16 +4048,13 @@ public WebSiteItem(string Subject, string WebSite)
39854048
/// <summary>
39864049
/// 历史记录分类标题种类枚举
39874050
/// </summary>
3988-
public enum HistoryTreeFlag
4051+
[Flags]
4052+
public enum HistoryTreeCategoryFlag
39894053
{
3990-
All = 0,
3991-
TodayYesterday = 1,
3992-
TodayEarlier = 2,
3993-
YesterdayEarlier = 3,
3994-
Today = 4,
3995-
Yesterday = 5,
3996-
Earlier = 6,
3997-
None = 7
4054+
Today = 1,
4055+
Yesterday = 2,
4056+
Earlier = 4,
4057+
None = 8
39984058
}
39994059
#endregion
40004060

@@ -4401,4 +4461,40 @@ private List<StorageFile> Except(IEnumerable<StorageFile> list1, IEnumerable<Sto
44014461
}
44024462
}
44034463
#endregion
4464+
4465+
#region 下载列表模板选择器
4466+
public sealed class DownloadTemplateSelector : DataTemplateSelector
4467+
{
4468+
public DataTemplate DownloadingTemplate { get; set; }
4469+
public DataTemplate DownloadErrorTemplate { get; set; }
4470+
public DataTemplate DownloadCompleteTemplate { get; set; }
4471+
public DataTemplate DownloadCancelTemplate { get; set; }
4472+
public DataTemplate DownloadPauseTemplate { get; set; }
4473+
4474+
protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
4475+
{
4476+
if (item is DownloadOperator Operator)
4477+
{
4478+
switch (Operator.State)
4479+
{
4480+
case DownloadState.AlreadyFinished:
4481+
return DownloadCompleteTemplate;
4482+
case DownloadState.Canceled:
4483+
return DownloadCancelTemplate;
4484+
case DownloadState.Downloading:
4485+
return DownloadingTemplate;
4486+
case DownloadState.Error:
4487+
return DownloadErrorTemplate;
4488+
case DownloadState.Paused:
4489+
return DownloadPauseTemplate;
4490+
default: return null;
4491+
}
4492+
}
4493+
else
4494+
{
4495+
return null;
4496+
}
4497+
}
4498+
}
4499+
#endregion
44044500
}

SmartLens/Package.appxmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<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">
3-
<Identity Name="428cf39b-0a14-4a17-b3db-521ad0abb62e" Publisher="CN=Ruofan" Version="5.0.0.0" />
3+
<Identity Name="428cf39b-0a14-4a17-b3db-521ad0abb62e" Publisher="CN=Ruofan" Version="5.0.4.0" />
44
<mp:PhoneIdentity PhoneProductId="428cf39b-0a14-4a17-b3db-521ad0abb62e" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
55
<Properties>
66
<DisplayName>SmartLens</DisplayName>

SmartLens/Setting/SettingsPage.xaml.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ private async void OnFirstLoad()
170170
ScreenCaptureSwitch.IsOn = !Enable;
171171
}
172172

173-
if(ApplicationData.Current.LocalSettings.Values["EmailProtectionMode"] is bool EnableEmailProtection)
173+
if (ApplicationData.Current.LocalSettings.Values["EmailProtectionMode"] is bool EnableEmailProtection)
174174
{
175175
EmailProtectionSwitch.IsOn = EnableEmailProtection;
176176
}
@@ -744,7 +744,7 @@ private async void ResetButton_Click(object sender, RoutedEventArgs e)
744744
await ApplicationData.Current.ClearAsync();
745745
ToastContent content = PopToast.GenerateToastContent();
746746
ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(content.GetXml()));
747-
CoreApplication.Exit();
747+
Application.Current.Exit();
748748
}
749749
}
750750

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

864864
private void WebDirectionSwitch_Toggled(object sender, RoutedEventArgs e)
865865
{
866-
if(WebDirectionSwitch.IsOn)
866+
if (WebDirectionSwitch.IsOn)
867867
{
868868
ApplicationData.Current.LocalSettings.Values["UseInsideWebBrowser"] = true;
869869
}

0 commit comments

Comments
 (0)