Skip to content

Commit

Permalink
Download list add left time and state column, Add delete menuItem. Ad…
Browse files Browse the repository at this point in the history
…d Download info save when download state changed. Version 1.5.
  • Loading branch information
gy12346123 committed Dec 8, 2016
1 parent 010bb2c commit 380674b
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 21 deletions.
4 changes: 2 additions & 2 deletions BaiduCloudSupport/API/DataInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public class DownloadListDataItem
public double rate { get; set; }
public DateTime startTime { get; set; }
public bool isSelected { get; set; }
public TimeSpan Left { get; set; }
public MyDownloader.Core.DownloaderState state { get; set; }
public TimeSpan left { get; set; }
public MyDownloader.Core.DownloaderStateChinese state { get; set; }
}
}
11 changes: 6 additions & 5 deletions BaiduCloudSupport/API/PCS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ public static Task DownloadFile(string access_token, ulong fs_id, string remoteF
//MainWindow.totalData.SingleFileBytesReceived = e.BytesReceived;
//MainWindow.totalData.SingleFileProgressPercentage = e.ProgressPercentage;
double percent = Math.Round(Convert.ToDouble(e.BytesReceived) / Convert.ToDouble(e.TotalBytesToReceive) * 100, 1);
MainWindow.DownloadListChangeItems(fs_id, e.TotalBytesToReceive, e.BytesReceived, percent, 0d);
MainWindow.DownloadListChangeItems(fs_id, e.TotalBytesToReceive, e.BytesReceived, percent, 0d, TimeSpan.Zero, DownloaderState.Ended);
};
web.DownloadFileCompleted += (object sender, System.ComponentModel.AsyncCompletedEventArgs e) => {
//MainWindow.totalData.SingleFileProgressPercentage = 100;
Expand Down Expand Up @@ -483,25 +483,26 @@ public static void DownloaderEvent(ref Downloader downloader)
downloader.InfoReceived += (object sender, EventArgs e) =>
{
((Downloader)sender).ReGenerateURL = true;
MainWindow.DownloadListChangeItems(((Downloader)sender).fs_id, ((Downloader)sender).FileSize / 1048576L, 0L, 0d, 0d);
MainWindow.DownloadListChangeItems(((Downloader)sender).fs_id, ((Downloader)sender).FileSize / 1048576L, 0L, 0d, 0d, ((Downloader)sender).Left, ((Downloader)sender).State);
};
// Downloader ending event
downloader.Ending += (object sender, EventArgs e) =>
{
MainWindow.DownloadListChangeItems(((Downloader)sender).fs_id, ((Downloader)sender).FileSize / 1048576L, ((Downloader)sender).Transfered / 1048576L, 100d, 0d);
MainWindow.DownloadListChangeItems(((Downloader)sender).fs_id, ((Downloader)sender).FileSize / 1048576L, ((Downloader)sender).Transfered / 1048576L, 100d, 0d, TimeSpan.FromMilliseconds(0d), ((Downloader)sender).State);
};
// Downloader data received event
downloader.DataReceived += (object sender, DownloaderEventArgs e) => {
if (e.Downloader.Progress - e.Downloader.PreProgress > 1d)
{
MainWindow.DownloadListChangeItems(e.Downloader.fs_id, e.Downloader.FileSize / 1048576L, e.Downloader.Transfered / 1048576L, Math.Round(e.Downloader.Progress, 1), Math.Round(e.Downloader.Rate / 1000d, 1));
MainWindow.DownloadListChangeItems(e.Downloader.fs_id, e.Downloader.FileSize / 1048576L, e.Downloader.Transfered / 1048576L, Math.Round(e.Downloader.Progress, 1), Math.Round(e.Downloader.Rate / 1000d, 1), e.Downloader.Left, e.Downloader.State);
e.Downloader.PreProgress = e.Downloader.Progress;
GetDownloadInfo();
}
};
// Downloader state changed event
downloader.StateChanged += (object sender, EventArgs e) => {
MainWindow.DownloadListChangeItems(((Downloader)sender).fs_id, ((Downloader)sender).FileSize / 1048576L, ((Downloader)sender).Transfered / 1048576L, Math.Round(((Downloader)sender).Progress, 1), Math.Round(((Downloader)sender).Rate / 1000d, 1));
MainWindow.DownloadListChangeItems(((Downloader)sender).fs_id, ((Downloader)sender).FileSize / 1048576L, ((Downloader)sender).Transfered / 1048576L, Math.Round(((Downloader)sender).Progress, 1), Math.Round(((Downloader)sender).Rate / 1000d, 1), ((Downloader)sender).Left, ((Downloader)sender).State);
MainWindow.persistedListExtension.Save(MainWindow.persistedListExtension.SaveFromStateChange);
};
// Downloader segment failed event
downloader.SegmentFailed += async (object sender, SegmentEventArgs e) =>
Expand Down
6 changes: 6 additions & 0 deletions BaiduCloudSupport/Language/Lang.en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,10 @@
<sys:String x:Key="MainWindow_MenuItem_GetURL_ShortUrl_Message">Need change the long download url to short(can use short url with thunder)?</sys:String>
<sys:String x:Key="MainWindow_Button_ClearCookies">Cookie</sys:String>
<sys:String x:Key="MainWindow_Button_ClearCookies_Succeed">Clear cookies succeed.</sys:String>
<sys:String x:Key="DataGrid_DownloadList_Left">Left</sys:String>
<sys:String x:Key="DataGrid_DownloadList_Left_Format">hh\:mm\:ss</sys:String>
<sys:String x:Key="DataGrid_DownloadList_State">State</sys:String>
<sys:String x:Key="DataGrid_DownloadList_MenuItem_Delete">Delete</sys:String>
<sys:String x:Key="MainWindow_MenuItem_DownloadList_Delete_NeedDeleteSource_Title">About source file</sys:String>
<sys:String x:Key="MainWindow_MenuItem_DownloadList_Delete_NeedDeleteSource_Message">Need delete source?</sys:String>
</ResourceDictionary>
6 changes: 6 additions & 0 deletions BaiduCloudSupport/Language/Lang.zh.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,10 @@
<sys:String x:Key="MainWindow_MenuItem_GetURL_ShortUrl_Message">是否需要将获得的长链接转换为短链接(可以将短链接用于迅雷下载)?</sys:String>
<sys:String x:Key="MainWindow_Button_ClearCookies">Cookie</sys:String>
<sys:String x:Key="MainWindow_Button_ClearCookies_Succeed">成功清除Cookies。</sys:String>
<sys:String x:Key="DataGrid_DownloadList_Left">还需用时</sys:String>
<sys:String x:Key="DataGrid_DownloadList_Left_Format">hh\:mm\:ss</sys:String>
<sys:String x:Key="DataGrid_DownloadList_State">状态</sys:String>
<sys:String x:Key="DataGrid_DownloadList_MenuItem_Delete">删除</sys:String>
<sys:String x:Key="MainWindow_MenuItem_DownloadList_Delete_NeedDeleteSource_Title">关于原文件</sys:String>
<sys:String x:Key="MainWindow_MenuItem_DownloadList_Delete_NeedDeleteSource_Message">是否需要同时删除原文件(请慎重)?</sys:String>
</ResourceDictionary>
8 changes: 6 additions & 2 deletions BaiduCloudSupport/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,15 @@
<DataGridTextColumn Header="{StaticResource DataGrid_FileList_Size}" Width="1*" Binding="{Binding size,StringFormat='{StaticResource DataGrid_DownloadList_Size_Format}'}"/>
<DataGridTextColumn Header="{StaticResource DataGrid_DownloadList_received}" Width="1*" Binding="{Binding received,StringFormat='{StaticResource DataGrid_DownloadList_received_Format}'}"/>
<DataGridTextColumn Header="{StaticResource DataGrid_DownloadList_Percentage}" Width="1*" Binding="{Binding percentage,StringFormat='{StaticResource DataGrid_DownloadList_Percentage_Format}'}"/>
<DataGridTextColumn Header="{StaticResource DataGrid_DownloadList_Rate}" Width="2*" Binding="{Binding rate,StringFormat='{StaticResource DataGrid_DownloadList_Rate_Format}'}" />
<DataGridTextColumn Header="{StaticResource DataGrid_DownloadList_StartTime}" Width="3*" Binding="{Binding startTime}"/>
<DataGridTextColumn Header="{StaticResource DataGrid_DownloadList_Rate}" Width="1*" Binding="{Binding rate,StringFormat='{StaticResource DataGrid_DownloadList_Rate_Format}'}" />
<DataGridTextColumn Header="{StaticResource DataGrid_DownloadList_Left}" Width="1*" Binding="{Binding left,StringFormat='{StaticResource DataGrid_DownloadList_Left_Format}'}" />
<DataGridTextColumn Header="{StaticResource DataGrid_DownloadList_State}" Width="1*" Binding="{Binding state}" />
<DataGridTextColumn Header="{StaticResource DataGrid_DownloadList_StartTime}" Width="1*" Binding="{Binding startTime}"/>
</DataGrid.Columns>
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Header="{StaticResource DataGrid_DownloadList_MenuItem_Delete}" Click="MenuItem_DownloadList_Delete_Click" />
<Separator />
<MenuItem Header="{StaticResource DataGrid_DownloadList_MenuItem_Start}" Click="MenuItem_Start_Click" />
<MenuItem Header="{StaticResource DataGrid_DownloadList_MenuItem_Stop}" Click="MenuItem_Stop_Click" />
</ContextMenu>
Expand Down
47 changes: 37 additions & 10 deletions BaiduCloudSupport/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public enum ThemeAccent { Red, Green, Blue, Purple, Orange, Lime, Emerald, Teal,

private System.Windows.Forms.NotifyIcon notifyIcon;

private MyDownloader.Extension.PersistedList.PersistedListExtension persistedListExtension;
public static MyDownloader.Extension.PersistedList.PersistedListExtension persistedListExtension;

public MainWindow()
{
Expand Down Expand Up @@ -824,8 +824,8 @@ private async void AddDownloadTask(FileListDataItem item)
rate = 0d,
startTime = DateTime.Now,
isSelected = false,
state = DownloaderState.NeedToPrepare,
Left = TimeSpan.Zero
state = DownloaderStateChinese.需解析,
left = TimeSpan.FromMilliseconds(0d),
};

if (totalData.DownloadListDataItems != null && totalData.DownloadListDataItems.Count() != 0)
Expand Down Expand Up @@ -926,15 +926,18 @@ public static void DownloadListAddItem(List<DownloadListDataItem> list, Download
rate = file.rate,
startTime = file.startTime,
isSelected = file.isSelected,
Left = file.Left,
left = file.left,
state = file.state
});
}
newList.Add(dataItem);
if (dataItem != null)
{
newList.Add(dataItem);
}
totalData.DownloadListDataItems = newList;
}

public static void DownloadListChangeItems(ulong fs_id, long size, long received, double percentage, double rate)
public static void DownloadListChangeItems(ulong fs_id, long size, long received, double percentage, double rate, TimeSpan left, DownloaderState state)
{
lock (_DownloadListChangeLock)
{
Expand All @@ -952,8 +955,8 @@ public static void DownloadListChangeItems(ulong fs_id, long size, long received
rate = rate,
startTime = file.startTime,
isSelected = file.isSelected,
Left = file.Left,
state = file.state
left = left,
state = Other.Tools.ConvertDownloaderState(state)
});
}else
{
Expand Down Expand Up @@ -982,8 +985,8 @@ private void InitDownloadList()
rate = 0d,
startTime = downloader.CreatedDateTime,
isSelected = false,
Left = downloader.Left,
state = downloader.State
left = downloader.Left,
state = Other.Tools.ConvertDownloaderState(downloader.State)
});
}
var list = DownloadManager.Instance.Downloads.ToArray();
Expand Down Expand Up @@ -1720,5 +1723,29 @@ private async void button_ClearCookies_Click(object sender, RoutedEventArgs e)
await this.ShowMessageAsync(GlobalLanguage.FindText("Message_Fail"), GlobalLanguage.FindText("CommonMessage_Exception"));
}
}

private async void MenuItem_DownloadList_Delete_Click(object sender, RoutedEventArgs e)
{
if (dataGrid_FileDownloadList.SelectedItems.Count == 0)
{
await this.ShowMessageAsync(GlobalLanguage.FindText("CommonTitle_Notice"), GlobalLanguage.FindText("MainWindow_DataGrid_SelectedNull"));
return;
}
var needDeleteSource = await this.ShowMessageAsync(GlobalLanguage.FindText("MainWindow_MenuItem_DownloadList_Delete_NeedDeleteSource_Title"), GlobalLanguage.FindText("MainWindow_MenuItem_DownloadList_Delete_NeedDeleteSource_Message"), MessageDialogStyle.AffirmativeAndNegative);

foreach (DownloadListDataItem file in dataGrid_FileDownloadList.SelectedItems)
{
totalData.DownloadListDataItems.Remove(file);
if (needDeleteSource == MessageDialogResult.Affirmative)
{
string path = System.IO.Path.Combine(Setting.DownloadPath, file.file);
if (File.Exists(path))
{
File.Delete(path);
}
}
}
DownloadListAddItem(totalData.DownloadListDataItems, null);
}
}
}
30 changes: 29 additions & 1 deletion BaiduCloudSupport/Other/Tools.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using MyDownloader.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -154,5 +155,32 @@ public static string GenerateStr(int count)
}
return str;
}

public static DownloaderStateChinese ConvertDownloaderState(DownloaderState state)
{
switch (state)
{
case DownloaderState.NeedToPrepare:
return DownloaderStateChinese.需解析;
case DownloaderState.Preparing:
return DownloaderStateChinese.解析中;
case DownloaderState.WaitingForReconnect:
return DownloaderStateChinese.等待重连;
case DownloaderState.Prepared:
return DownloaderStateChinese.解析完毕;
case DownloaderState.Working:
return DownloaderStateChinese.下载中;
case DownloaderState.Pausing:
return DownloaderStateChinese.暂停中;
case DownloaderState.Paused:
return DownloaderStateChinese.已暂停;
case DownloaderState.Ended:
return DownloaderStateChinese.已结束;
case DownloaderState.EndedWithError:
return DownloaderStateChinese.出错;
default:
throw new Exception();
}
}
}
}
2 changes: 1 addition & 1 deletion BaiduCloudSupport/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.4.*")]
[assembly: AssemblyVersion("1.5.*")]
[assembly: InternalsVisibleTo("BaiduCloudSupport.Tests")]
[assembly: InternalsVisibleTo("BaiduCloudSupport.Explorables")]
//[assembly: AssemblyFileVersion("1.0.*")]
13 changes: 13 additions & 0 deletions MyDownloader.Core/DownloaderState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,17 @@ public enum DownloaderState: byte
Ended,
EndedWithError
}

public enum DownloaderStateChinese: byte
{
需解析 = 0,
解析中,
等待重连,
解析完毕,
下载中,
暂停中,
已暂停,
已结束,
出错
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class SegmentItem
private object SaveFromDispose = new object();
private object SaveFromTimer = new object();
private object SaveFromListChange = new object();
public object SaveFromStateChange = new object();

#region IExtension Members

Expand Down Expand Up @@ -100,6 +101,11 @@ public void Dispose()

#region Methods

public void Save(object state)
{
PersistList(state);
}

private void PersistList(object state)
{
List<DownloadItem> downloadsToSave = new List<DownloadItem>();
Expand Down

0 comments on commit 380674b

Please sign in to comment.