This commit is contained in:
Fiedler, Andre 2016-11-21 22:10:19 +01:00
Родитель e0f1c0d7d0 d2c014394f
Коммит d8c0624650
4 изменённых файлов: 58 добавлений и 17 удалений

Просмотреть файл

@ -35,6 +35,7 @@ namespace NextcloudApp.ViewModels
public ICommand CreateDirectoryCommand { get; private set; }
public ICommand UploadFilesCommand { get; private set; }
public ICommand UploadPhotosCommand { get; private set; }
public ICommand DownloadResourceCommand { get; private set; }
public ICommand DeleteResourceCommand { get; private set; }
public ICommand RenameResourceCommand { get; private set; }
public ICommand MoveResourceCommand { get; private set; }
@ -84,6 +85,7 @@ namespace NextcloudApp.ViewModels
CreateDirectoryCommand = new DelegateCommand(CreateDirectory);
UploadFilesCommand = new DelegateCommand(UploadFiles);
UploadPhotosCommand = new DelegateCommand(UploadPhotos);
DownloadResourceCommand = new RelayCommand(DownloadResource);
DeleteResourceCommand = new RelayCommand(DeleteResource);
RenameResourceCommand = new RelayCommand(RenameResource);
MoveResourceCommand = new RelayCommand(MoveResource);
@ -109,6 +111,20 @@ namespace NextcloudApp.ViewModels
base.OnNavigatingFrom(e, viewModelState, suspending);
}
private void DownloadResource(object parameter)
{
var resourceInfo = parameter as ResourceInfo;
if (resourceInfo == null)
{
return;
}
var parameters = new SingleFileDownloadPageParameters
{
ResourceInfo = resourceInfo
};
_navigationService.Navigate(PageTokens.SingleFileDownload.ToString(), parameters.Serialize());
}
private void MoveResource(object parameter)
{
var resourceInfo = parameter as ResourceInfo;

Просмотреть файл

@ -75,6 +75,12 @@ namespace NextcloudApp.ViewModels
return;
}
ResourceInfo = resourceInfo;
if (ResourceInfo.ContentType == "dav/directory")
{
ResourceInfo.Name = ResourceInfo.Name + ".zip";
ResourceInfo.ContentType = "application/zip";
}
var savePicker = new FileSavePicker();
@ -96,7 +102,16 @@ namespace NextcloudApp.ViewModels
try
{
IProgress<HttpProgress> progress = new Progress<HttpProgress>(ProgressHandler);
var buffer = await client.Download(ResourceInfo.Path + "/" + ResourceInfo.Name, _cts, progress);
Windows.Storage.Streams.IBuffer buffer;
switch (ResourceInfo.ContentType)
{
case "application/zip":
buffer = await client.DownloadDirectoryAsZip(ResourceInfo.Path, _cts, progress);
break;
default:
buffer = await client.Download(ResourceInfo.Path + "/" + ResourceInfo.Name, _cts, progress);
break;
}
await FileIO.WriteBufferAsync(localFile, buffer);
}
catch (ResponseError e2)

Просмотреть файл

@ -264,13 +264,13 @@
Command="{Binding DataContext.DeleteResourceCommand, ElementName=Page}"
CommandParameter="{Binding}"
Style="{StaticResource MenuFlyoutIconItemStyle}"/>
<!--
<MenuFlyoutItem
Tag="Download"
x:Uid="Download"
Text="Download"
Command="{Binding DataContext.DownloadCommand, ElementName=Page}"
CommandParameter="{Binding}"/>
-->
Command="{Binding DataContext.DownloadResourceCommand, ElementName=Page}"
CommandParameter="{Binding}"
Style="{StaticResource MenuFlyoutIconItemStyle}"/>
</MenuFlyout>
</FlyoutBase.AttachedFlyout>
</Grid>

Просмотреть файл

@ -300,19 +300,14 @@ namespace NextcloudClient
/// <summary>
/// Downloads a remote directory as zip.
/// </summary>
/// <returns>The directory as zip.</returns>
/// <param name="path">path to the remote directory to download.</param>
public async Task<Stream> DownloadDirectoryAsZip(string path)
/// <param name="path">File remote Path.</param>
/// <param name="cts"></param>
/// <param name="progress"></param>
/// <returns>File contents.</returns>
//public async Task<IBuffer> Download(string path, CancellationTokenSource cts, IProgress<HttpProgress> progress)
public async Task<IBuffer> DownloadDirectoryAsZip(string path, CancellationTokenSource cts, IProgress<HttpProgress> progress)
{
var response = await DoRequest(
"GET",
"/index.php/apps/files/ajax/download.php",
new Dictionary<string, string>
{
{"dir", path}
}
);
return (await response.Content.ReadAsInputStreamAsync()).AsStreamForRead();
return await _dav.DownloadFile(GetDavUriZip(path), cts, progress);
}
#endregion
@ -1568,6 +1563,21 @@ namespace NextcloudClient
return new Uri(_url + "/" + Davpath + Uri.EscapeDataString(path).Replace("%2F", "/"));
}
/// <summary>
/// Gets the DAV request URI.
/// </summary>
/// <returns>The DAV URI.</returns>
/// <param name="path">remote Path.</param>
private Uri GetDavUriZip(string path)
{
string[] pathArry = path.Split('/');
string files = pathArry[pathArry.Length - 2 ];
path = path.Substring(0, path.Length - (files.Length + 1) );
return new Uri(_url + "/index.php/apps/files/ajax/download.php?dir=" +
Uri.EscapeDataString(path) +
"&files=" + Uri.EscapeDataString(files));
}
/// <summary>
/// Gets the remote path for OCS API.
/// </summary>