Skip to content

Commit

Permalink
2023 First Commit
Browse files Browse the repository at this point in the history
2023 First Commit
1.Finish task and publish 0.8.0.0 version
2.Completed console application
  • Loading branch information
Gaoyifei1011 committed Jan 1, 2023
1 parent 3f4bb8a commit 93cc15f
Show file tree
Hide file tree
Showing 19 changed files with 349 additions and 87 deletions.
7 changes: 3 additions & 4 deletions Description/README_EN-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ Note: The app can't bypass the Microsoft Store's billing channels, and if the ap
| ---------------------------------------------------------| -------------------------------------------------------------------------------------------------------------------|
| Main page functionality | Completed |
| History (records used links) | Completed |
| Download the file from the generated link | Completed (in beta) |
| Download the file from the generated link | Completed |
| Deploy the app offline after the download is complete | Completed |
| Access the web version of the docking download interface | Completed |
| Console applications (quickly download and deploy) | Planning (Expected 0.8.0 preview implementation) |
| Console applications (quickly download) | Completed |
| Program performance optimization | Planning (Expected to be implemented in version 1.0.0) |

> * At present, the application is in the development stage, some functions have not yet been implemented, and only basic functions are currently provided. In addition, I am a beginner in C#, and I am more time-constrained, I can only use my spare time to develop, the development progress is relatively slow, please understand.
> * The download function is in the testing stage, there may be instability during use, if there is an abnormality during use, please use a browser to download.
> * I am a beginner in C#, and I am more time-constrained, I can only use my spare time to develop, the development progress is relatively slow, please understand.
------

Expand Down
7 changes: 3 additions & 4 deletions Description/README_ZH-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@
| --------------------------------| --------------------------------------------------|
| 主页面功能 | 已完成 |
| 历史记录(记录使用过的链接) | 已完成 |
| 通过生成的链接下载文件 | 已完成(处于测试阶段) |
| 通过生成的链接下载文件 | 已完成 |
| 下载完成后离线部署应用 | 已完成 |
| 访问网页版对接下载接口 | 已完成 |
| 控制台应用程序(快速下载并部署)| 计划中(预计0.8.0预览版本实现) |
| 控制台应用程序(快速下载) | 已完成 |
| 程序性能优化 | 计划中(预计1.0.0正式版本实现) |

> * 目前该应用处于开发阶段,有部分功能尚未实现,目前仅提供基础的功能。此外我是c#的初学者,且本人时间较为紧张,只能利用自己的闲余时间开发,开发进度较为缓慢,请谅解。
> * 下载功能处于测试阶段,在使用过程中可能存在不稳定现象,如果在使用过程中出现异常,请使用浏览器下载。
> * 我是c#的初学者,且本人时间较为紧张,只能利用自己的闲余时间开发,开发进度较为缓慢,请谅解。
------

Expand Down
6 changes: 3 additions & 3 deletions GetStoreApp/GetStoreApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<DesktopCompatible>true</DesktopCompatible>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
<FileAlignment>512</FileAlignment>
<FileVersion>0.7.3.0</FileVersion>
<FileVersion>0.8.0.0</FileVersion>
<GenerateTestArtifacts>True</GenerateTestArtifacts>
<IncludeSymbols>False</IncludeSymbols>
<ImplicitUsings>disable</ImplicitUsings>
Expand All @@ -22,7 +22,7 @@
<Platforms>x86;x64;ARM64</Platforms>
<PublishProfile>Properties\PublishProfiles\win10-$(Platform).pubxml</PublishProfile>
<PublishProtocol>FileSystem</PublishProtocol>
<PublishReadyToRun>False</PublishReadyToRun>
<PublishReadyToRun>True</PublishReadyToRun>
<PublishSingleFile>false</PublishSingleFile>
<PublishTrimmed>true</PublishTrimmed>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
Expand All @@ -33,7 +33,7 @@
<TargetFramework>net7.0-windows10.0.22621.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<TrimMode>partial</TrimMode>
<Version>0.7.3.0</Version>
<Version>0.8.0.0</Version>
<UseWinUI>true</UseWinUI>
<WindowsAppSDKSelfContained>false</WindowsAppSDKSelfContained>
<WindowsPackageType>MSIX</WindowsPackageType>
Expand Down
6 changes: 6 additions & 0 deletions GetStoreApp/Helpers/Controls/Download/Aria2ProcessHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public static void KillProcessAndChildren(int processID)
}
}

/// <summary>
/// 获取所有的子进程ID
/// </summary>
public static List<int> GetChildProcessIds(int parentProcessId)
{
List<int> myChildrenProcessList = new List<int>();
Expand All @@ -108,6 +111,9 @@ public static List<int> GetChildProcessIds(int parentProcessId)
return myChildrenProcessList;
}

/// <summary>
/// 获取父进程ID
/// </summary>
public static int GetParentProcessId(int processId)
{
int ParentID = 0;
Expand Down
9 changes: 2 additions & 7 deletions GetStoreApp/Helpers/Root/InfoHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Windows.ApplicationModel;
using Windows.System;
using Windows.System.Profile;
Expand All @@ -20,7 +19,7 @@ public static class InfoHelper
/// <summary>
/// 初始化系统版本信息
/// </summary>
public static async Task InitializeSystemVersionAsync()
public static void InitializeSystemVersion()
{
ulong VersionInfo = ulong.Parse(SystemVersion);

Expand All @@ -33,14 +32,12 @@ public static async Task InitializeSystemVersionAsync()
SystemVersionDict.Add(nameof(MinorVersion), MinorVersion);
SystemVersionDict.Add(nameof(BuildNumber), BuildNumber);
SystemVersionDict.Add(nameof(BuildRevision), BuildRevision);

await Task.CompletedTask;
}

/// <summary>
/// 初始化应用版本信息
/// </summary>
public static async Task InitializeAppVersionAsync()
public static void InitializeAppVersion()
{
ushort MajorVersion = Package.Current.Id.Version.Major;
ushort MinorVersion = Package.Current.Id.Version.Minor;
Expand All @@ -51,8 +48,6 @@ public static async Task InitializeAppVersionAsync()
AppVersionDict.Add(nameof(MinorVersion), MinorVersion);
AppVersionDict.Add(nameof(BuildVersion), BuildVersion);
AppVersionDict.Add(nameof(RevisionVersion), RevisionVersion);

await Task.CompletedTask;
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions GetStoreApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ public static async Task InitializeProgramResourcesAsync()

await RegionService.InitializeRegionAsync();
await LinkFilterService.InitializeLinkFilterValueAsnyc();
await DownloadOptionsService.InitializeAsync();

await InfoHelper.InitializeAppVersionAsync();
await InfoHelper.InitializeSystemVersionAsync();
InfoHelper.InitializeAppVersion();
InfoHelper.InitializeSystemVersion();

if (IsDesktopProgram)
{
Expand All @@ -104,7 +105,6 @@ public static async Task InitializeProgramResourcesAsync()
await ThemeService.InitializeThemeAsync();
await TopMostService.InitializeTopMostValueAsync();

await DownloadOptionsService.InitializeAsync();
await HistoryLiteNumService.InitializeHistoryLiteNumAsync();
await NotificationService.InitializeNotificationAsync();
await UseInstructionService.InitializeUseInsVisValueAsync();
Expand Down
17 changes: 14 additions & 3 deletions GetStoreApp/Services/Root/ConsoleLaunchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ namespace GetStoreApp.Services.Root
/// </summary>
public static class ConsoleLaunchService
{
/// <summary>
/// 换行符
/// </summary>
// 换行符
public static string LineBreaks = "\r\n";

// 行分隔符
public static char RowSplitCharacter = ' ';

// 列分隔符
public static char ColumnSplitCharacter = '-';

public static bool IsAppRunning = true;

/// <summary>
/// 应用启动时使用的参数
/// </summary>
Expand All @@ -38,6 +44,8 @@ public static async Task InitializeConsoleStartupAsync()
InitializeIntroduction();
InitializeRequestContent();
await RequestService.GetLinksAsync();

Console.WriteLine(LineBreaks + ResourceService.GetLocalized("/Console/ApplicationExit"));
}

/// <summary>
Expand Down Expand Up @@ -67,6 +75,9 @@ private static void OnConsoleCancelKeyPress(object sender, ConsoleCancelEventArg
}
if (Result == MessageBoxResult.IDOK)
{
Console.WriteLine(LineBreaks + ResourceService.GetLocalized("/Console/ApplicationExit"));
IsAppRunning = false;
DownloadService.StopDownloadFile();
Environment.Exit(Convert.ToInt32(AppExitCode.Successfully));
}
}
Expand Down
2 changes: 1 addition & 1 deletion GetStoreApp/Services/Root/ResourceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private static void InitializeTraceCleanupList()
}

/// <summary>
/// UI字符串本地化
/// 字符串本地化
/// </summary>
public static string GetLocalized(string resource)
{
Expand Down
159 changes: 159 additions & 0 deletions GetStoreApp/Services/Shell/DownloadService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
using GetStoreApp.Helpers.Controls.Download;
using GetStoreApp.Services.Controls.Settings.Common;
using GetStoreApp.Services.Root;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Windows.System;

namespace GetStoreApp.Services.Shell
{
/// <summary>
/// 下载服务
/// </summary>
public static class DownloadService
{
private static string Aria2FilePath => Path.Combine(AppContext.BaseDirectory, @"Aria2\Aria2c.exe");

private static bool IsFileDownloading;

private static int Aria2ProcessId;

/// <summary>
/// 下载相应的文件
/// </summary>
public static async Task QueryDownloadIndexAsync()
{
while (true)
{
Console.WriteLine(ResourceService.GetLocalized("/Console/DownloadFile"));
List<string> IndexList = Console.ReadLine().Split(',').ToList();
try
{
bool CheckResult = true;
foreach (string indexItem in IndexList)
{
int index = Convert.ToInt32(indexItem);
if (index > ParseService.ResultDataList.Count || index < 1)
{
CheckResult = false;
break;
}
}

if (CheckResult)
{
for (int index = 0; index < IndexList.Count; index++)
{
string IndexItem = IndexList[index];
if (ConsoleLaunchService.IsAppRunning)
{
Console.WriteLine(ResourceService.GetLocalized("/Console/DownloadingInformation"), index + 1, IndexList.Count);
await DownloadFileAsync(ParseService.ResultDataList[Convert.ToInt32(IndexItem) - 1].FileLink);
}
}
Console.WriteLine(ResourceService.GetLocalized("/Console/DownloadCompleted"));
string InputString = Console.ReadLine();
if (InputString == "Y" || InputString == "y")
{
continue;
}
else
{
Console.WriteLine(ResourceService.GetLocalized("/Console/OpenFolder"));
await OpenDownloadFolderAsync();
break;
}
}
else
{
Console.WriteLine(ResourceService.GetLocalized("/Console/SerialNumberOutRange"));
string InputString = Console.ReadLine();
if (InputString == "Y" || InputString == "y")
{
continue;
}
else
{
break;
}
}
}
catch (Exception)
{
Console.WriteLine(ResourceService.GetLocalized("/Console/SerialNumberError"));
string InputString = Console.ReadLine();
if (InputString == "Y" || InputString == "y")
{
continue;
}
else
{
break;
}
}
}
}

/// <summary>
/// 下载文件
/// </summary>
private static async Task DownloadFileAsync(string fileLink)
{
ProcessStartInfo Aria2Info = new ProcessStartInfo()
{
FileName = Aria2FilePath,

RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,

WindowStyle = ProcessWindowStyle.Hidden,
Arguments = string.Format("--file-allocation=none -d \"{0}\" {1}", DownloadOptionsService.DownloadFolder.Path, fileLink)
};

StreamReader streamReader;

Process Aria2Process = new Process();
Aria2Process.StartInfo = Aria2Info;
Aria2Process.Start();
IsFileDownloading = true;
Aria2ProcessId = Aria2Process.Id;
streamReader = Aria2Process.StandardOutput;
while (!streamReader.EndOfStream)
{
char[] bs = new char[16];
streamReader.Read(bs, 0, 16);
foreach (char o in bs)
{
Console.Write(o);
}
}
await Aria2Process.WaitForExitAsync();
Aria2Process.Close();
}

/// <summary>
/// 打开下载完成后保存的目录
/// </summary>
private static async Task OpenDownloadFolderAsync()
{
await Launcher.LaunchFolderAsync(DownloadOptionsService.DownloadFolder);
}

/// <summary>
/// 程序即将退出,停止下载文件
/// </summary>
public static void StopDownloadFile()
{
if (IsFileDownloading)
{
Aria2ProcessHelper.KillProcessAndChildren(Aria2ProcessId);
}
}
}
}
Loading

0 comments on commit 93cc15f

Please sign in to comment.