Skip to content

Commit 178b606

Browse files
committed
fix: Improve webdav stability
* Add config test * Handle failures
1 parent b611da5 commit 178b606

8 files changed

Lines changed: 79 additions & 21 deletions

File tree

VNGod/App.xaml.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,22 @@ private static void HandleRestart(Exception? e)
3535
{
3636
SentrySdk.CaptureException(e!);
3737
if (e != null)
38-
MessageBox.Show("An unexpected error occurred:\n" + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
38+
{
39+
if (
40+
MessageBox.Show("遇到了未经处理的异常,已自动发送错误报告,要重启吗?", "Error", MessageBoxButton.OKCancel, MessageBoxImage.Error) == MessageBoxResult.OK)
41+
{
42+
Process.Start("VNGod.exe");
43+
}
44+
}
3945
else
40-
MessageBox.Show("An unexpected error occurred.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
41-
Process.Start("VNGod.exe");
46+
{
47+
if (
48+
MessageBox.Show("遇到了未经处理的异常,已自动发送错误报告,要重启吗?", "Error", MessageBoxButton.OKCancel, MessageBoxImage.Error) == MessageBoxResult.OK)
49+
{
50+
Process.Start("VNGod.exe");
51+
}
52+
53+
}
4254
Environment.Exit(1);
4355
}
4456

VNGod/Network/WebDAVClient.cs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,42 @@ public static bool IsInitialized
3636
/// <returns></returns>
3737
public async static Task<bool> InitializeClient()
3838
{
39-
if (string.IsNullOrEmpty(Settings.Default.WebDAVUrl) || string.IsNullOrEmpty(Settings.Default.WebDAVUsername) || string.IsNullOrEmpty(Settings.Default.WebDAVPassword))
39+
if (string.IsNullOrEmpty(Settings.Default.WebDAVUrl)||
40+
Settings.Default.WebDAVUrl=="/" // Auto addition, avoid this
41+
|| string.IsNullOrEmpty(Settings.Default.WebDAVUsername) || string.IsNullOrEmpty(Settings.Default.WebDAVPassword))
4042
{
4143
// Clear old client
4244
client = null;
4345
return false;
4446
}
45-
var clientParams = new WebDavClientParams
46-
{
47-
BaseAddress = new Uri(Settings.Default.WebDAVUrl),
48-
Credentials = new NetworkCredential(Settings.Default.WebDAVUsername, Settings.Default.WebDAVPassword)
49-
};
50-
var testClient = new WebDavClient(clientParams);
51-
for (int i = 1; i <= 4; i++)
47+
try
5248
{
53-
if (await TestConnectionAsync(testClient))
49+
var clientParams = new WebDavClientParams
5450
{
55-
client = testClient;
56-
return true;
51+
BaseAddress = new Uri(Settings.Default.WebDAVUrl),
52+
Credentials = new NetworkCredential(Settings.Default.WebDAVUsername, Settings.Default.WebDAVPassword)
53+
};
54+
var testClient = new WebDavClient(clientParams);
55+
for (int i = 1; i <= 4; i++)
56+
{
57+
if (await TestConnectionAsync(testClient))
58+
{
59+
client = testClient;
60+
return true;
61+
}
5762
}
63+
64+
}
65+
catch (Exception ex)
66+
{
67+
Logger.Error($"Exception during WebDAV client initialization: {ex.Message}", ex);
68+
}
69+
finally
70+
{
71+
client = null;
5872
}
59-
client = null;
6073
return false;
74+
6175
}
6276
private async static Task<string?> GetBaseUriAsync(string requestUri)
6377
{

VNGod/Resource/Strings/Strings.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VNGod/Resource/Strings/Strings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,4 +349,7 @@
349349
<data name="DeleteLocalWarning" xml:space="preserve">
350350
<value>Are you sure you want to delete the selected local game? This action cannot be undone.</value>
351351
</data>
352+
<data name="WebDAVNotEnabledWarn" xml:space="preserve">
353+
<value>WebDAV not enabled.</value>
354+
</data>
352355
</root>

VNGod/Resource/Strings/Strings.zh-CN.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,4 +331,7 @@
331331
<data name="DeleteLocalWarning" xml:space="preserve">
332332
<value>确定要删除选定的本地游戏吗?这个操作无法撤销。</value>
333333
</data>
334+
<data name="WebDAVNotEnabledWarn" xml:space="preserve">
335+
<value>没有启用 WebDAV</value>
336+
</data>
334337
</root>

VNGod/View/GameStorageWindow.xaml.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,16 @@ private async void Window_IsVisibleChanged(object sender, DependencyPropertyChan
9898

9999
private async Task RefreshRemoteData()
100100
{
101-
remoteGameList.ItemsSource = await WebDAVHelper.GetRemoteGamesAsync();
101+
if (WebDAVHelper.IsInitialized)
102+
remoteGameList.ItemsSource = await WebDAVHelper.GetRemoteGamesAsync();
103+
else
104+
{
105+
// Completely hide upload and download buttons
106+
Growl.Warning(Strings.WebDAVNotEnabledWarn);
107+
uploadButton.Visibility = Visibility.Collapsed;
108+
downloadButton.Visibility = Visibility.Collapsed;
109+
deleteRemoteButton.Visibility = Visibility.Collapsed;
110+
}
102111
}
103112

104113
private async void DeleteRemoteButton_Click(object sender, RoutedEventArgs e)

VNGod/View/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
xmlns:strings="clr-namespace:VNGod.Resource.Strings"
1010
xmlns:hc="https://handyorg.github.io/handycontrol"
1111
mc:Ignorable="d"
12-
Title="VNGod" Height="600" Width="800"
12+
Title="VNGod" Height="650" Width="900"
1313
IsVisibleChanged="Window_IsVisibleChanged"
1414
Closing="Window_Closing">
1515
<Window.Resources>

VNGod/View/MainWindow.xaml.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public MainWindow()
3636
private void InitializeGameRepo(string repoPath)
3737
{
3838
Resources["gameRepo"] = FileHelper.InitializeRepo(repoPath);
39+
IconHelper.GetIcons(GetRepo());
3940
EnableGlobalButtons(true);
4041
}
4142
private Repo GetRepo()
@@ -128,7 +129,12 @@ private async Task SyncGameSaveAsync()
128129
{
129130
if (string.IsNullOrEmpty(GetCurrentGame().SavePath))
130131
{
131-
Growl.Warning(Strings.NoSavePath);
132+
Growl.Error(Strings.NoSavePath);
133+
return;
134+
}
135+
if (!WebDAVHelper.IsInitialized)
136+
{
137+
Growl.Error(Strings.WebDAVNotEnabledWarn);
132138
return;
133139
}
134140
syncButton.IsEnabled = false;
@@ -144,6 +150,7 @@ private void RescanButton_Click(object sender, RoutedEventArgs e)
144150
{
145151
EnableGlobalButtons(false);
146152
FileHelper.ScanGames(GetRepo());
153+
IconHelper.GetIcons(GetRepo());
147154
EnableGlobalButtons(true);
148155
}
149156

@@ -184,7 +191,7 @@ private async void RefreshInfoButton_Click(object sender, RoutedEventArgs e)
184191
private void OpenGameFolderButton_Click(object sender, RoutedEventArgs e)
185192
{
186193
Process.Start("explorer.exe", gameList.SelectedItem is Game game ?
187-
System.IO.Path.Combine(GetRepo().LocalPath, game.DirectoryName) :
194+
Path.Combine(GetRepo().LocalPath, game.DirectoryName) :
188195
throw new Exception("No game selected."));
189196
}
190197

@@ -254,12 +261,13 @@ private void VndbButton_Click(object sender, RoutedEventArgs e)
254261
}
255262
}
256263

257-
private void SettingsButton_Click(object sender, RoutedEventArgs e)
264+
private async void SettingsButton_Click(object sender, RoutedEventArgs e)
258265
{
259266
SettingsWindow settingsWindow = new();
260267
settingsWindow.ShowDialog();
261268
// Reinitialize WebDAV client with new settings
262-
Task.Run(WebDAVHelper.InitializeClient);
269+
if (!await WebDAVHelper.InitializeClient())
270+
Growl.Warning(Strings.WebDAVInitFailed);
263271
}
264272

265273
private async void SyncButton_Click(object sender, RoutedEventArgs e)

0 commit comments

Comments
 (0)