Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
yar229 committed Feb 27, 2017
2 parents e4c88c9 + 2e24280 commit 3b81778
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 11 deletions.
4 changes: 4 additions & 0 deletions External/basicauth.reg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WebClient\Parameters]
"BasicAuthLevel"=dword:00000002
Binary file added External/filesizelimit.reg
Binary file not shown.
2 changes: 1 addition & 1 deletion WDMRC.Console/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</mapping>
<mapping>
<level value="WARN"/>
<foreColor value="Red"/>
<foreColor value="Yellow"/>
</mapping>
<mapping>
<level value="INFO"/>
Expand Down
5 changes: 2 additions & 3 deletions WDMRC.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ static void Main(string[] args)
}
finally
{
cancellationTokenSource.Cancel();
httpListener.Stop();
httpListener.Close();
cancellationTokenSource?.Cancel();
httpListener?.Stop();
}
return 0;

Expand Down
6 changes: 6 additions & 0 deletions WDMRC.Console/WDMRC.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
<PropertyGroup>
<AssemblyOriginatorKeyFile>fookey.pfx</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>cloud.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="CommandLine, Version=2.0.275.0, Culture=neutral, PublicKeyToken=de6f01bd326f8c32, processorArchitecture=MSIL">
<HintPath>..\packages\CommandLineParser.2.1.1-beta\lib\net45\CommandLine.dll</HintPath>
Expand Down Expand Up @@ -97,6 +100,9 @@
<Name>WebDavMailRuCloudStore</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="cloud.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Binary file added WDMRC.Console/cloud.ico
Binary file not shown.
14 changes: 14 additions & 0 deletions WebDavMailRuCloudStore/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ public static Task<bool> Move(this MailRuCloud cloud, IStoreItem item, string de
throw new ArgumentException(string.Empty, nameof(item));
}

public static string GetFullPath(this IStoreItem item)
{
if (null == item) return string.Empty;

var storeItem = item as MailruStoreItem;
if (storeItem != null)
return storeItem.FullPath;
var storeCollection = item as MailruStoreCollection;
if (storeCollection != null)
return storeCollection.FullPath;

throw new ArgumentException(string.Empty, nameof(item));
}


public static long ContentLength(this IHttpRequest request)
{
Expand Down
7 changes: 3 additions & 4 deletions WebDavMailRuCloudStore/Mailru/DeleteHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Threading.Tasks;
using System.Threading.Tasks;
using System.Xml.Linq;
using NWebDav.Server;
using NWebDav.Server.Helpers;
Expand Down Expand Up @@ -78,7 +77,7 @@ public async Task<bool> HandleRequestAsync(IHttpContext httpContext, IStore stor
}

// Delete item
var status = await DeleteItemAsync(parentCollection, splitUri.Name, httpContext, splitUri.CollectionUri, errors).ConfigureAwait(false);
var status = await DeleteItemAsync(parentCollection, splitUri.Name, httpContext).ConfigureAwait(false);
if (status == DavStatusCode.Ok && errors.HasItems)
{
// Obtain the status document
Expand All @@ -97,7 +96,7 @@ public async Task<bool> HandleRequestAsync(IHttpContext httpContext, IStore stor
return true;
}

private async Task<DavStatusCode> DeleteItemAsync(IStoreCollection collection, string name, IHttpContext httpContext, Uri baseUri, UriResultCollection errors)
private async Task<DavStatusCode> DeleteItemAsync(IStoreCollection collection, string name, IHttpContext httpContext)
{
// Attempt to delete the item
return await collection.DeleteItemAsync(name, httpContext).ConfigureAwait(false);
Expand Down
13 changes: 12 additions & 1 deletion WebDavMailRuCloudStore/Mailru/StoreBase/MailruStoreCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,18 @@ public async Task<StoreItemResult> MoveItemAsync(string sourceName, IStoreCollec
if (destinationStoreCollection.FullPath == FullPath)
await Cloud.Instance(httpContext).Rename(item, destinationName);
else
await Cloud.Instance(httpContext).Move(item, destinationStoreCollection.FullPath);
{
if (sourceName == destinationName || string.IsNullOrEmpty(destinationName))
{
await Cloud.Instance(httpContext).Move(item, destinationStoreCollection.FullPath);
}
else
{
await Cloud.Instance(httpContext).Rename(item, destinationName);
string path = WebDavPath.Combine(WebDavPath.Parent(item.GetFullPath()), destinationName);
await Cloud.Instance(httpContext).MoveOrCopy(path, destinationStoreCollection.FullPath, true);
}
}

return new StoreItemResult(result, new MailruStoreItem(LockingManager, null, IsWritable));
}
Expand Down
29 changes: 28 additions & 1 deletion WebDavMailRuCloudStore/Mailru/StoreBase/MailruStoreItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Security.Cryptography;
using System.Threading.Tasks;
using MailRuCloudApi;
using NWebDav.Server;
using NWebDav.Server.Helpers;
using NWebDav.Server.Http;
Expand Down Expand Up @@ -156,12 +157,38 @@ public async Task<DavStatusCode> UploadFromStreamAsync(IHttpContext httpContext,
if (!IsWritable)
return DavStatusCode.Conflict;


// dirty hack! HIGH MEMORY CONSUME
// mail.ru needs size of file, but some clients does not send it
// so we'll cache file in memory
// TODO: rewrite
if (httpContext.Request.GetHeaderValue("Transfer-Encoding") == "chunked" && _fileInfo.Size.DefaultValue == 0)
{
SLog.Log(LogLevel.Warning, () => "Client does not send file size, caching in memory!");
var memStream = new MemoryStream();
await inputStream.CopyToAsync(memStream).ConfigureAwait(false);

_fileInfo.Size = new FileSize(memStream.Length);

using (var outputStream = IsWritable
? Cloud.Instance(httpContext).GetFileUploadStream(_fileInfo.FullPath, _fileInfo.Size.DefaultValue)
: null)
{
memStream.Seek(0, SeekOrigin.Begin);
await memStream.CopyToAsync(outputStream).ConfigureAwait(false);
}
return DavStatusCode.Ok;
}




// Copy the stream
try
{
// Copy the information to the destination stream
using (var outputStream = IsWritable
? Cloud.Instance(httpContext).GetFileUploadStream(_fileInfo.FullPath, ".bin", _fileInfo.Size.DefaultValue)
? Cloud.Instance(httpContext).GetFileUploadStream(_fileInfo.FullPath, _fileInfo.Size.DefaultValue)
: null)
{
await inputStream.CopyToAsync(outputStream).ConfigureAwait(false);
Expand Down

0 comments on commit 3b81778

Please sign in to comment.