Merge pull request #178 from SunboX/check-if-file-exists
Check if file exists, fixes #163
This commit is contained in:
Коммит
ee292df4dd
|
@ -630,4 +630,13 @@ Please try again later.</value>
|
|||
<value>Error while uploading file '{0}' to Nextcloud.</value>
|
||||
<comment>{0} = file name</comment>
|
||||
</data>
|
||||
<data name="DoYouWantToOverwriteIt" xml:space="preserve">
|
||||
<value>Do you want to overwrite it?</value>
|
||||
</data>
|
||||
<data name="FileAlreadyExists" xml:space="preserve">
|
||||
<value>File already exists</value>
|
||||
</data>
|
||||
<data name="Overwrite" xml:space="preserve">
|
||||
<value>Overwrite</value>
|
||||
</data>
|
||||
</root>
|
|
@ -20,6 +20,8 @@ using Prism.Unity.Windows;
|
|||
using Prism.Windows.AppModel;
|
||||
using DecaTec.WebDav;
|
||||
using System.IO;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
|
||||
namespace NextcloudApp.ViewModels
|
||||
{
|
||||
|
@ -171,6 +173,32 @@ namespace NextcloudApp.ViewModels
|
|||
BytesTotal = (long) properties.Size;
|
||||
});
|
||||
|
||||
var filePath = ResourceInfo.Path + localFile.Name;
|
||||
|
||||
var canUploadFile = true;
|
||||
if (await client.Exists(filePath))
|
||||
{
|
||||
var dialog = new ContentDialog
|
||||
{
|
||||
Title = _resourceLoader.GetString("FileAlreadyExists"),
|
||||
Content =_resourceLoader.GetString("DoYouWantToOverwriteIt"),
|
||||
PrimaryButtonText = _resourceLoader.GetString("Overwrite"),
|
||||
SecondaryButtonText = _resourceLoader.GetString("Cancel")
|
||||
};
|
||||
|
||||
var dialogResult = await _dialogService.ShowAsync(dialog);
|
||||
|
||||
if (dialogResult != ContentDialogResult.Primary)
|
||||
{
|
||||
canUploadFile = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!canUploadFile)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// this moves the OpenReadAsync off of the UI thread and works fine...
|
||||
using (
|
||||
var stream = (
|
||||
|
@ -186,7 +214,7 @@ namespace NextcloudApp.ViewModels
|
|||
var targetStream = stream.AsStreamForRead();
|
||||
|
||||
IProgress<WebDavProgress> progress = new Progress<WebDavProgress>(ProgressHandler);
|
||||
await client.Upload(ResourceInfo.Path + localFile.Name, targetStream, localFile.ContentType, progress, _cts.Token);
|
||||
await client.Upload(filePath, targetStream, localFile.ContentType, progress, _cts.Token);
|
||||
}
|
||||
}
|
||||
catch (ResponseError e2)
|
||||
|
|
Загрузка…
Ссылка в новой задаче