-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
124 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 68 additions & 2 deletions
70
...UnoFileDownloader/UnoFileDownloader/UnoFileDownloader/Business/DownloadFileListManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,78 @@ | ||
using System; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
|
||
using UnoFileDownloader.Utils; | ||
|
||
namespace UnoFileDownloader.Business | ||
{ | ||
internal class DownloadFileListManager | ||
public class DownloadFileListManager | ||
{ | ||
public ObservableCollection<DownloadFileInfo> DownloadFileInfoList { get; } = new ObservableCollection<DownloadFileInfo>(); | ||
|
||
public async Task InitAsync() | ||
{ | ||
var list = await ReadDownloadedFileListAsync(); | ||
if (list != null) | ||
{ | ||
DownloadFileInfoList.AddRange(list); | ||
} | ||
} | ||
|
||
public Task SaveAsync() => WriteDownloadedFileListToFileAsync(DownloadFileInfoList.ToList()); | ||
|
||
public async Task AddDownloadFileAsync(DownloadFileInfo downloadFileInfo) | ||
{ | ||
DownloadFileInfoList.Add(downloadFileInfo); | ||
await SaveAsync(); | ||
} | ||
|
||
/// <summary> | ||
/// 读取本地存储的下载列表 | ||
/// </summary> | ||
/// <returns></returns> | ||
private async Task<List<DownloadFileInfo>?> ReadDownloadedFileListAsync() | ||
{ | ||
var file = GetStorageFilePath(); | ||
|
||
if (!File.Exists(file)) | ||
{ | ||
return null; | ||
} | ||
|
||
var text = await File.ReadAllTextAsync(file); | ||
|
||
var downloadFileInfoList = JsonSerializer.Deserialize<List<DownloadFileInfo>>(text); | ||
return downloadFileInfoList; | ||
} | ||
|
||
/// <summary> | ||
/// 写入下载列表 | ||
/// </summary> | ||
/// <param name="downloadFileInfoList"></param> | ||
/// <returns></returns> | ||
private async Task WriteDownloadedFileListToFileAsync(List<DownloadFileInfo> downloadFileInfoList) | ||
{ | ||
var file = GetStorageFilePath(); | ||
|
||
var text = JsonSerializer.Serialize(downloadFileInfoList); | ||
|
||
await File.WriteAllTextAsync(file, text); | ||
} | ||
|
||
private string GetStorageFilePath() | ||
{ | ||
string folder = AppContext.BaseDirectory; | ||
var file = Path.Join(folder, StorageFile); | ||
|
||
return file; | ||
} | ||
|
||
private const string StorageFile = "DownloadedFileList.json"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 7 additions & 3 deletions
10
src/UnoFileDownloader/UnoFileDownloader/UnoFileDownloader/Presentation/ShellModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
using UnoFileDownloader.Business; | ||
|
||
namespace UnoFileDownloader.Presentation | ||
{ | ||
public class ShellModel | ||
{ | ||
private readonly INavigator _navigator; | ||
private readonly DownloadFileListManager _downloadFileListManager; | ||
|
||
public ShellModel( | ||
INavigator navigator) | ||
public ShellModel(INavigator navigator, DownloadFileListManager downloadFileListManager) | ||
{ | ||
_navigator = navigator; | ||
_downloadFileListManager = downloadFileListManager; | ||
_ = Start(); | ||
} | ||
|
||
public async Task Start() | ||
{ | ||
await _navigator.NavigateViewModelAsync<AboutModel>(this); | ||
await _downloadFileListManager.InitAsync(); | ||
await _navigator.NavigateViewModelAsync<NewTaskModel>(this); | ||
} | ||
} | ||
} |