Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Sep 7, 2024
1 parent beddc71 commit bb90671
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions v2rayN/ServiceLib/Handler/WebDavHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public sealed class WebDavHandler
private Config? _config;
private WebDavClient? _client;
private string? _lastDescription;
private string _webDir = "mywebdir";
private string _webDir = Global.AppName + "_backup";
private string _webFileName = "backup.zip";
private string _logTitle = "WebDav--";

Expand Down Expand Up @@ -51,17 +51,12 @@ private async Task<bool> GetClient()
return await Task.FromResult(true);
}

private async Task<bool> CheckProp()
private async Task<bool> TryCreateDir()
{
if (_client is null) return false;
try
{
var result = await _client.Propfind(_webDir);
if (result.IsSuccessful)
{
return true;
}
var result2 = await _client.Mkcol(_webDir); // create a directory
var result2 = await _client.Mkcol(_webDir);
if (result2.IsSuccessful)
{
return true;
Expand Down Expand Up @@ -93,12 +88,20 @@ public async Task<bool> CheckConnection()
{
return false;
}
if (await CheckProp() == false)
await TryCreateDir();

var testName = "readme_test";
var myContent = new StringContent(testName);
var result = await _client.PutFile($"{_webDir}/{testName}", myContent);
if (result.IsSuccessful)
{
await _client.Delete($"{_webDir}/{testName}");
return true;
}
else
{
return false;
}

return true;
}

public async Task<bool> PutFile(string fileName)
Expand All @@ -107,10 +110,7 @@ public async Task<bool> PutFile(string fileName)
{
return false;
}
if (await CheckProp() == false)
{
return false;
}
await TryCreateDir();

try
{
Expand All @@ -136,10 +136,8 @@ public async Task<bool> GetRawFile(string fileName)
{
return false;
}
if (await CheckProp() == false)
{
return false;
}
await TryCreateDir();

try
{
var response = await _client.GetRawFile($"{_webDir}/{_webFileName}");
Expand Down

0 comments on commit bb90671

Please sign in to comment.