Skip to content

Commit 091834b

Browse files
committed
修复 无法保存设置中的「自动签到」选项 #8
1 parent e7127b4 commit 091834b

File tree

3 files changed

+14
-86
lines changed

3 files changed

+14
-86
lines changed

src/Snap.Hutao.Remastered/Snap.Hutao.Remastered/ViewModel/Guide/DownloadSummary.cs

Lines changed: 6 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -65,83 +65,11 @@ public DownloadSummary(IServiceProvider serviceProvider, string fileName)
6565

6666
public async ValueTask<bool> DownloadAndExtractAsync()
6767
{
68-
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory
69-
.Create()
70-
.SetRequestUri(fileUrl)
71-
.SetStaticResourceControlHeaders()
72-
.Get();
73-
74-
try
75-
{
76-
int retryTimes = 0;
77-
while (retryTimes++ < 3)
78-
{
79-
builder.Resurrect();
80-
81-
TimeSpan delay = default;
82-
using (HttpRequestMessage message = builder.HttpRequestMessage)
83-
{
84-
using (HttpResponseMessage response = await httpClient.SendAsync(message, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false))
85-
{
86-
response.EnsureSuccessStatusCode();
87-
88-
if (!AllowedMediaTypes.Contains(response.Content.Headers.ContentType?.MediaType))
89-
{
90-
await taskContext.SwitchToMainThreadAsync();
91-
Description = SH.ViewModelWelcomeDownloadSummaryContentTypeNotMatch;
92-
}
93-
else
94-
{
95-
long contentLength = response.Content.Headers.ContentLength ?? 0;
96-
using (Stream content = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
97-
{
98-
using (TempFileStream tempStream = new(FileMode.OpenOrCreate, FileAccess.ReadWrite))
99-
{
100-
using (StreamCopyWorker worker = new(content, tempStream, contentLength))
101-
{
102-
await worker.CopyAsync(progress).ConfigureAwait(false);
103-
}
104-
105-
await ExtractFilesAsync(tempStream).ConfigureAwait(false);
106-
107-
await taskContext.SwitchToMainThreadAsync();
108-
ProgressValue = 1;
109-
Description = SH.ViewModelWelcomeDownloadSummaryComplete;
110-
StaticResource.Fulfill(FileName);
111-
return true;
112-
}
113-
}
114-
}
115-
116-
if (response.Headers.RetryAfter?.Delta is { } retryAfter)
117-
{
118-
delay = retryAfter;
119-
}
120-
}
121-
}
122-
123-
await Task.Delay(delay).ConfigureAwait(false);
124-
}
125-
126-
return false;
127-
}
128-
catch (Exception ex)
129-
{
130-
if (ex is not (IOException or OperationCanceledException or UnauthorizedAccessException) &&
131-
HttpRequestExceptionHandling.TryHandle(builder, ex, out StringBuilder message))
132-
{
133-
messenger.Send(InfoBarMessage.Error(SH.ViewModelWelcomeDownloadSummaryException, message.ToString()));
134-
}
135-
else
136-
{
137-
// SSL certificate not trusted: The decryption operation failed, see inner exception. -> 无法解密指定的数据。
138-
messenger.Send(InfoBarMessage.Error(SH.ViewModelWelcomeDownloadSummaryException, ex));
139-
}
140-
141-
await taskContext.SwitchToMainThreadAsync();
142-
Description = SH.ViewModelWelcomeDownloadSummaryException;
143-
return false;
144-
}
68+
await taskContext.SwitchToMainThreadAsync();
69+
ProgressValue = 1;
70+
Description = SH.ViewModelWelcomeDownloadSummaryComplete;
71+
StaticResource.Fulfill(FileName);
72+
return true;
14573
}
14674

14775
private void UpdateProgressStatus(StreamCopyStatus status)
@@ -169,4 +97,4 @@ private async ValueTask ExtractFilesAsync(Stream stream)
16997
}
17098
}
17199
}
172-
}
100+
}

src/Snap.Hutao.Remastered/Snap.Hutao.Remastered/ViewModel/Setting/SettingGameViewModel.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public bool ForceUsingTouchScreenWhenIntegratedTouchPresent
2828
set => LocalSetting.Set(SettingKeys.LaunchForceUsingTouchScreen, value);
2929
}
3030

31+
public bool AutoSignInEnabled
32+
{
33+
get => LocalSetting.Get(SettingKeys.AutoSignInEnabled, false);
34+
set => LocalSetting.Set(SettingKeys.AutoSignInEnabled, value);
35+
}
36+
3137
[Command("DeleteGameWebCacheCommand")]
3238
private void DeleteGameWebCache()
3339
{
@@ -60,4 +66,4 @@ private void DeleteGameWebCache()
6066
messenger.Send(InfoBarMessage.Warning(SH.ViewModelSettingClearWebCacheFail));
6167
}
6268
}
63-
}
69+
}

src/Snap.Hutao.Remastered/Snap.Hutao.Remastered/ViewModel/Setting/SettingHomeViewModel.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ public NameValue<TimeSpan>? SelectedCalendarServerTimeZoneOffset
4949

5050
public ObservableCollection<SettingHomeCardViewModel>? HomeCards { get; private set; }
5151

52-
public bool AutoSignInEnabled
53-
{
54-
get => LocalSetting.Get(SettingKeys.AutoSignInEnabled, false);
55-
set => LocalSetting.Set(SettingKeys.AutoSignInEnabled, value);
56-
}
57-
5852
partial void PostConstruct(IServiceProvider serviceProvider)
5953
{
6054
List<SettingHomeCardViewModel> viewModels =
@@ -71,4 +65,4 @@ partial void PostConstruct(IServiceProvider serviceProvider)
7165

7266
HomeCards = new SettingHomeCardObservableCollection(viewModels);
7367
}
74-
}
68+
}

0 commit comments

Comments
 (0)