Skip to content

Commit

Permalink
Add query links mode settings
Browse files Browse the repository at this point in the history
1.Add query links mode settings
2.Update Microsoft.WindowsPackageManager.ComInterop version to 1.7.11132
  • Loading branch information
Gaoyifei1011 committed Apr 26, 2024
1 parent 9e23ec8 commit 3fbfcac
Show file tree
Hide file tree
Showing 40 changed files with 690 additions and 295 deletions.
2 changes: 2 additions & 0 deletions GetStoreApp/Extensions/DataType/Constant/ConfigKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public static class ConfigKey

public const string WebKernelKey = "WebKernel";

public const string QueryLinksModeKey = "QueryLinksMode";

public const string WindowWidthKey = "WindowWidth";

public const string WindowHeightKey = "WindowHeight";
Expand Down
Binary file modified GetStoreApp/GetStoreAppResource.res
Binary file not shown.
30 changes: 15 additions & 15 deletions GetStoreApp/Helpers/Controls/Store/HttpParseHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,31 @@ public static partial class HtmlParseHelper

private static Regex ResultDataListRegex = ResultDataListRegularExpression();

private static string ParseContent = string.Empty;
private static string parseContent = string.Empty;

/// <summary>
/// 初始化HtmlParseService类时添加HtmlReqeustHelper生成的字符串数据
/// </summary>
public static void InitializeParseData(RequestModel HttpRequestData)
public static void InitializeParseData(RequestModel httpRequestData)
{
ParseContent = HttpRequestData.RequestContent;
parseContent = httpRequestData.RequestContent;
}

/// <summary>
/// 解析网页数据中包含的CategoryID信息
/// </summary>
public static string HtmlParseCID()
{
if (!string.IsNullOrEmpty(ParseContent))
if (!string.IsNullOrEmpty(parseContent))
{
MatchCollection CIDCollection = CIDRegex.Matches(ParseContent);
if (CIDCollection.Count > 0)
MatchCollection cidCollection = CIDRegex.Matches(parseContent);
if (cidCollection.Count > 0)
{
GroupCollection CIDGroups = CIDCollection[0].Groups;
GroupCollection cidGroups = cidCollection[0].Groups;

if (CIDGroups.Count > 0)
if (cidGroups.Count > 0)
{
return CIDGroups[1].Value;
return cidGroups[1].Value;
}
}
}
Expand All @@ -55,13 +55,13 @@ public static string HtmlParseCID()
/// </summary>
public static List<QueryLinksModel> HtmlParseLinks()
{
List<QueryLinksModel> ResultDataList = new List<QueryLinksModel>();
List<QueryLinksModel> resultDataList = new List<QueryLinksModel>();

if (!string.IsNullOrEmpty(ParseContent))
if (!string.IsNullOrEmpty(parseContent))
{
MatchCollection ResultDataListCollection = ResultDataListRegex.Matches(ParseContent);
MatchCollection resultDataListCollection = ResultDataListRegex.Matches(parseContent);

foreach (Match matchItem in ResultDataListCollection)
foreach (Match matchItem in resultDataListCollection)
{
GroupCollection ResultDataListGroups = matchItem.Groups;

Expand All @@ -74,11 +74,11 @@ public static List<QueryLinksModel> HtmlParseLinks()
queryLinksData.FileSHA1 = ResultDataListGroups[4].Value;
queryLinksData.FileSize = ResultDataListGroups[5].Value;

ResultDataList.Add(queryLinksData);
resultDataList.Add(queryLinksData);
}
}
}
return ResultDataList;
return resultDataList;
}
}
}
20 changes: 7 additions & 13 deletions GetStoreApp/Helpers/Controls/Store/HttpRequestHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using GetStoreApp.Models.Controls.Store;
using GetStoreApp.Services.Root;
using Microsoft.UI.Xaml.Controls;
using System;
using System.Runtime.InteropServices;
using System.Text;
Expand Down Expand Up @@ -46,7 +47,7 @@ public static string GenerateRequestContent(string type, string url, string ring
/// </summary>
public static async Task<RequestModel> HttpRequestAsync(string content)
{
RequestModel HttpRequestResult = null;
RequestModel httpRequestResult = null;

// 添加超时设置(半分钟后停止获取)
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
Expand Down Expand Up @@ -124,7 +125,7 @@ public static async Task<RequestModel> HttpRequestAsync(string content)
}
finally
{
HttpRequestResult = new RequestModel
httpRequestResult = new RequestModel
{
RequestId = RequestId,
RequestStatusCode = RequestStatusCode,
Expand All @@ -134,32 +135,25 @@ public static async Task<RequestModel> HttpRequestAsync(string content)
cancellationTokenSource.Dispose();
}

return HttpRequestResult;
return httpRequestResult;
}

/// <summary>
/// 检查请求后的状态信息
/// </summary>
public static int CheckRequestState(RequestModel HttpRequestData)
public static InfoBarSeverity CheckRequestState(RequestModel HttpRequestData)
{
// 服务器请求异常,返回状态值3
if (HttpRequestData.RequestId is not 0)
{
return 3;
return InfoBarSeverity.Error;
}

// 服务器请求成功
else
{
// 成功下返回值为成功,否则返回警告
if (HttpRequestData.RequestContent.Contains("The links were successfully received from the Microsoft Store server.", StringComparison.Ordinal))
{
return 1;
}
else
{
return 2;
}
return HttpRequestData.RequestContent.Contains("The links were successfully received from the Microsoft Store server.", StringComparison.OrdinalIgnoreCase) ? InfoBarSeverity.Success : InfoBarSeverity.Warning;
}
}
}
Expand Down
16 changes: 0 additions & 16 deletions GetStoreApp/Helpers/Converters/ValueConverterHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,5 @@ public static Visibility BooleanToVisibilityReverseConvert(bool value)
{
return value is false ? Visibility.Visible : Visibility.Collapsed;
}

/// <summary>
/// 空字符串值与显示值转换
/// </summary>
public static Visibility StringVisibilityConvert(string value)
{
return !string.IsNullOrEmpty(value) ? Visibility.Visible : Visibility.Collapsed;
}

/// <summary>
/// 空字符串值与显示值转换(判断结果相反)
/// </summary>
public static Visibility StringReverseVisibilityConvert(string value)
{
return string.IsNullOrEmpty(value) ? Visibility.Visible : Visibility.Collapsed;
}
}
}
2 changes: 1 addition & 1 deletion GetStoreApp/Models/Controls/Store/HistoryModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class HistoryModel
public string HistoryKey { get; set; }

/// <summary>
/// 查询链接控件:历史记录的应用名称
/// 查询链接控件:历史记录的应用名称或类别ID
/// </summary>
public string HistoryAppName { get; set; }

Expand Down
1 change: 1 addition & 0 deletions GetStoreApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ private static async Task InitializeResourcesAsync(bool isDesktopProgram)
{
ResourceService.LocalizeReosurce();
LinkFilterService.InitializeLinkFilterValue();
QueryLinksModeService.InitializeQueryLinksMode();
await DownloadOptionsService.InitializeAsync();
}

Expand Down
6 changes: 3 additions & 3 deletions GetStoreApp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
[assembly: AssemblyCompany("高怡飞")]
[assembly: AssemblyCopyright("Copyright ©2022-2024 高怡飞, All Rights Reserved.")]
[assembly: AssemblyDescription("获取商店应用")]
[assembly: AssemblyFileVersion("3.9.424.0")]
[assembly: AssemblyInformationalVersion("3.9.424.0")]
[assembly: AssemblyFileVersion("3.9.426.0")]
[assembly: AssemblyInformationalVersion("3.9.426.0")]
[assembly: AssemblyProduct("获取商店应用")]
[assembly: AssemblyTitle("获取商店应用")]
[assembly: AssemblyVersion("3.9.424.0")]
[assembly: AssemblyVersion("3.9.426.0")]

// 设置程序集对 COM 组件的访问权限
[assembly: ComVisible(false)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ await Task.Run(async () =>
}
catch (Exception e)
{
LogService.WriteLog(LoggingLevel.Warning, "InitializeWebKernel download record state failed.", e);
LogService.WriteLog(LoggingLevel.Warning, "Initialize download record state failed.", e);
return;
}
}
Expand Down
78 changes: 78 additions & 0 deletions GetStoreApp/Services/Controls/Settings/QueryLinksModeService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using GetStoreApp.Extensions.DataType.Constant;
using GetStoreApp.Services.Root;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;

namespace GetStoreApp.Services.Controls.Settings
{
/// <summary>
/// 查询链接方式选择设置服务
/// </summary>
public static class QueryLinksModeService
{
private static string queryLinksModeSettingsKey = ConfigKey.QueryLinksModeKey;

private static DictionaryEntry defaultQueryLinksMode;

private static DictionaryEntry _queryLinksMode;

public static DictionaryEntry QueryLinksMode
{
get { return _queryLinksMode; }

private set
{
if (!Equals(_queryLinksMode, value))
{
_queryLinksMode = value;
PropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(QueryLinksMode)));
}
}
}

public static List<DictionaryEntry> QueryLinksModeList { get; private set; }

public static event PropertyChangedEventHandler PropertyChanged;

/// <summary>
/// 应用在初始化前获取设置存储的查询链接方式选择值
/// </summary>
public static void InitializeQueryLinksMode()
{
QueryLinksModeList = ResourceService.QueryLinksModeList;

defaultQueryLinksMode = QueryLinksModeList.Find(item => item.Value.ToString() is "Official");

QueryLinksMode = GetQueryLinksMode();
}

/// <summary>
/// 获取设置存储的查询链接方式选择值,如果设置没有存储,使用默认值
/// </summary>
private static DictionaryEntry GetQueryLinksMode()
{
object queryLinksModeValue = LocalSettingsService.ReadSetting<object>(queryLinksModeSettingsKey);

if (queryLinksModeValue is null)
{
SetQueryLinksMode(defaultQueryLinksMode);
return defaultQueryLinksMode;
}

DictionaryEntry selectedQueryLinksMode = QueryLinksModeList.Find(item => item.Value.Equals(queryLinksModeValue));

return selectedQueryLinksMode.Key is null ? defaultQueryLinksMode : selectedQueryLinksMode;
}

/// <summary>
/// 查询链接方式发生修改时修改设置存储的查询链接方式值
/// </summary>
public static void SetQueryLinksMode(DictionaryEntry queryLinksMode)
{
QueryLinksMode = queryLinksMode;

LocalSettingsService.SaveSetting(queryLinksModeSettingsKey, queryLinksMode.Value);
}
}
}
2 changes: 1 addition & 1 deletion GetStoreApp/Services/Controls/Settings/WebKernelService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private static DictionaryEntry GetWebKernel()
}

/// <summary>
/// 历史记录显示数量发生修改时修改设置存储的微软商店页面历史记录显示数量值
/// 网页浏览器内核发生修改时修改设置存储的网页浏览器内核值
/// </summary>
public static void SetWebKernel(DictionaryEntry webKernel)
{
Expand Down
4 changes: 2 additions & 2 deletions GetStoreApp/Services/Root/ConsoleLaunchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private static void InitializeRequestContent()
try
{
typeIndex = int.Parse(ConsoleHelper.ReadLine());
if (typeIndex < 1 || typeIndex > 4)
if (typeIndex is < 1 or > 4)
{
typeIndex = 1;
}
Expand All @@ -123,7 +123,7 @@ private static void InitializeRequestContent()
try
{
channelIndex = int.Parse(ConsoleHelper.ReadLine());
if (channelIndex < 1 || channelIndex > 4)
if (channelIndex is < 1 or > 4)
{
channelIndex = 4;
}
Expand Down
12 changes: 12 additions & 0 deletions GetStoreApp/Services/Root/ResourceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public static class ResourceService

public static List<DictionaryEntry> WebKernelList { get; } = new List<DictionaryEntry>();

public static List<DictionaryEntry> QueryLinksModeList { get; } = new List<DictionaryEntry>();

public static List<DictionaryEntry> InstallModeList { get; } = new List<DictionaryEntry>();

public static List<DictionaryEntry> ThemeList { get; } = new List<DictionaryEntry>();
Expand Down Expand Up @@ -77,6 +79,7 @@ public static void LocalizeReosurce()
InitializeSearchStoreInfoList();
InitializeBackdropList();
InitializeWebKernelList();
InitializeQueryLinksModeList();
InitializeInstallModeList();
InitializeThemeList();
InitializeTraceCleanupList();
Expand Down Expand Up @@ -229,6 +232,15 @@ private static void InitializeWebKernelList()
WebKernelList.Add(new DictionaryEntry(GetLocalized("Settings/WebKernelWebView2"), "WebView2"));
}

/// <summary>
/// 初始化查询链接方式信息列表
/// </summary>
private static void InitializeQueryLinksModeList()
{
QueryLinksModeList.Add(new DictionaryEntry(GetLocalized("Settings/QueryLinksModeOfficial"), "Official"));
QueryLinksModeList.Add(new DictionaryEntry(GetLocalized("Settings/QueryLinksModeThirdParty"), "ThirdParty"));
}

/// <summary>
/// 初始化安装模式信息列表
/// </summary>
Expand Down
Loading

0 comments on commit 3fbfcac

Please sign in to comment.