Skip to content

Commit

Permalink
Merge branch 'develop2'
Browse files Browse the repository at this point in the history
  • Loading branch information
yar229 committed Dec 14, 2018
2 parents 7a9a665 + b27c38e commit d12c30d
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,4 @@ $RECYCLE.BIN/
# Mac desktop service store files
.DS_Store
/_gsdata_/
/.cr/
2 changes: 1 addition & 1 deletion MailRuCloud/MailRuCloudApi/Base/Repos/WebM1RequestRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public async Task<IEntry> FolderInfo(string path, Link ulink, int offset = 0, in
home: WebDavPath.Parent(path),
ulink: ulink,
filename: ulink == null ? WebDavPath.Name(path) : ulink.OriginalName,
nameReplacement: WebDavPath.Name(path))
nameReplacement: ulink?.IsLinkedToFileSystem ?? true ? WebDavPath.Name(path) : null )
: datares.ToFolder(path, ulink);

return entry;
Expand Down
9 changes: 6 additions & 3 deletions MailRuCloud/MailRuCloudApi/CloudSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ public class CloudSettings

public int ListDepth
{
get { return CacheListingSec > 0 ? _listDepth : 1; }
set { _listDepth = value; }
get => CacheListingSec > 0 ? _listDepth : 1;
set => _listDepth = value;
}
private int _listDepth = 1;
}

public string SpecialCommandPrefix { get; set; } = ">>";
public string AdditionalSpecialCommandPrefix { get; set; } = ">>";
}
}
16 changes: 11 additions & 5 deletions MailRuCloud/MailRuCloudApi/Extensions/DtoImportWeb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,11 @@ public static Folder ToFolder(this FolderInfoResult data, string home = null, Li

public static File ToFile(this FolderInfoResult data, string home = null, Link ulink = null, string filename = null, string nameReplacement = null)
{
if (string.IsNullOrEmpty(filename))
{
return new File(WebDavPath.Combine(data.body.home ?? "", data.body.name), data.body.size);
}
if (ulink == null || ulink.IsLinkedToFileSystem)
if (string.IsNullOrEmpty(filename))
{
return new File(WebDavPath.Combine(data.body.home ?? "", data.body.name), data.body.size);
}

PatchEntryPath(data, home, ulink);

Expand All @@ -273,9 +274,14 @@ public static File ToFile(this FolderInfoResult data, string home = null, Link u
? it.ToFile(nameReplacement)
: it.ToFile())
.ToList();

var cmpname = string.IsNullOrEmpty(nameReplacement)
? filename
: nameReplacement;

var groupedFile = z?
.ToGroupedFiles()
.First(it => it.Name == (string.IsNullOrEmpty(nameReplacement) ? filename : nameReplacement));
.First(it => string.IsNullOrEmpty(cmpname) || it.Name == cmpname);

return groupedFile;
}
Expand Down
9 changes: 6 additions & 3 deletions MailRuCloud/MailRuCloudApi/Links/Link.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ namespace YaR.MailRuCloud.Api.Links
{
public class Link : IEntry
{
private Link()
public Link(string href)
{
Href = href;
IsLinkedToFileSystem = false;
}

public Link(ItemLink rootLink, string fullPath, string href) : this()
public Link(ItemLink rootLink, string fullPath, string href) : this(href)
{
_rootLink = rootLink;
FullPath = fullPath;
Href = href;

IsRoot = WebDavPath.PathEquals(WebDavPath.Parent(FullPath), _rootLink.MapTo);

Expand All @@ -31,6 +32,8 @@ public Link(ItemLink rootLink, string fullPath, string href) : this()
CreationTimeUtc = rootLink.CreationDate ?? DateTime.Now;
}

public bool IsLinkedToFileSystem { get; } = true;

private readonly ItemLink _rootLink;

public string OriginalName { get; set; }
Expand Down
19 changes: 18 additions & 1 deletion MailRuCloud/MailRuCloudApi/MailRuCloud.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Net;
using System.Security.Authentication;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
Expand Down Expand Up @@ -34,7 +35,9 @@ public class MailRuCloud : IDisposable
/// Async tasks cancelation token.
/// </summary>
public readonly CancellationTokenSource CancelToken = new CancellationTokenSource();
private readonly CloudSettings _settings;

public CloudSettings Settings => _settings;
private readonly CloudSettings _settings;

/// <summary>
/// Gets or sets account to connect with cloud.
Expand Down Expand Up @@ -72,6 +75,13 @@ public enum ItemType
Unknown
}

public virtual async Task<IEntry> GetPublicItemAsync(string path, ItemType itemType = ItemType.Unknown)
{
var entry = await Account.RequestRepo.FolderInfo(path, new Link(path));

return entry;
}

///// <summary>
///// Get list of files and folders from account.
///// </summary>
Expand All @@ -81,6 +91,13 @@ public enum ItemType
///// <returns>List of the items.</returns>
public virtual async Task<IEntry> GetItemAsync(string path, ItemType itemType = ItemType.Unknown, bool resolveLinks = true)
{
//TODO: вообще, всё плохо стало, всё запуталось, всё надо переписать
var uriMatch = Regex.Match(path, @"\A/https://cloud\.mail\.\w+/public(?<uri>/\S+/\S+)\Z");
if (uriMatch.Success)
{
return await GetPublicItemAsync(uriMatch.Groups["uri"].Value, itemType);
}

path = WebDavPath.Clean(path);

if (_settings.CacheListingSec > 0)
Expand Down
4 changes: 2 additions & 2 deletions MailRuCloud/MailRuCloudApi/MailRuCloudApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<TargetFrameworks>netcoreapp2.0;net452</TargetFrameworks>
<RootNamespace>YaR.MailRuCloud.Api</RootNamespace>
<AssemblyName>MailRuCloud.Api</AssemblyName>
<AssemblyVersion>1.10.1.15</AssemblyVersion>
<FileVersion>1.10.1.15</FileVersion>
<AssemblyVersion>1.10.1.16</AssemblyVersion>
<FileVersion>1.10.1.16</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
43 changes: 36 additions & 7 deletions MailRuCloud/MailRuCloudApi/SpecialCommands/SpecialCommandFabric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,51 @@ public class SpecialCommandFabric

public SpecialCommand Build(MailRuCloud cloud, string param)
{
if (null == param || !param.Contains("/>>")) return null;
var res = ParceLine(param, cloud.Settings.SpecialCommandPrefix);
if (!res.IsValid && !string.IsNullOrEmpty(cloud.Settings.AdditionalSpecialCommandPrefix))
res = ParceLine(param, cloud.Settings.AdditionalSpecialCommandPrefix);
if (!res.IsValid)
return null;

int pos = param.LastIndexOf("/>>", StringComparison.Ordinal);
string path = WebDavPath.Clean(param.Substring(0, pos + 1));
string data = param.Substring(pos + 3);

var parames = ParseParameters(data);
var parames = ParseParameters(res.Data);
var commandContainer = FindCommandContainer(parames);
if (commandContainer == null) return null;

parames = parames.Skip(commandContainer.Commands.Length).ToList();
var cmd = commandContainer.CreateFunc(cloud, path, parames);
var cmd = commandContainer.CreateFunc(cloud, res.Path, parames);

return cmd;
}

private ParamsData ParceLine(string param, string prefix)
{
if (string.IsNullOrEmpty(prefix)) return ParamsData.Invalid;

string pre = "/" + prefix;
if (null == param || !param.Contains(pre)) return ParamsData.Invalid;

int pos = param.LastIndexOf(pre, StringComparison.Ordinal);
string path = WebDavPath.Clean(param.Substring(0, pos + 1));
string data = param.Substring(pos + pre.Length);

return new ParamsData
{
IsValid = true,
Path = path,
Data = data
};
}

private struct ParamsData
{
public bool IsValid { get; set; }
public string Path { get; set; }
public string Data { get; set; }

public static ParamsData Invalid => new ParamsData {IsValid = false};

}

private SpecialCommandContainer FindCommandContainer(IList<string> parames)
{
var commandContainer = CommandContainers
Expand Down
22 changes: 21 additions & 1 deletion WDMRC.Console/Config.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using System.Xml;

namespace YaR.CloudMailRu.Console
Expand All @@ -24,5 +25,24 @@ public static string TwoFactorAuthHandlerName
return res;
}
}

public static string SpecialCommandPrefix => ">>";

public static string AdditionalSpecialCommandPrefix
{
get
{
try
{
var res = Document.SelectSingleNode("/config/AdditionalSpecialCommandPrefix").InnerText;
return res;
}
catch (Exception)
{
return null;
}

}
}
}
}
3 changes: 2 additions & 1 deletion WDMRC.Console/Payload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public static void Run(CommandLineOptions options)
Protocol = options.Protocol,
UserAgent = options.UserAgent,
CacheListingSec = options.CacheListingSec,
ListDepth = options.CacheListingDepth
ListDepth = options.CacheListingDepth,
AdditionalSpecialCommandPrefix = Config.AdditionalSpecialCommandPrefix
};

var httpListener = new HttpListener();
Expand Down
4 changes: 2 additions & 2 deletions WDMRC.Console/WDMRC.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<Copyright>[email protected]</Copyright>
<Description>WebDAV emulator for Cloud.mail.ru</Description>
<PackageId>WebDAVCloudMailRu</PackageId>
<AssemblyVersion>1.10.1.15</AssemblyVersion>
<FileVersion>1.10.1.14</FileVersion>
<AssemblyVersion>1.10.1.16</AssemblyVersion>
<FileVersion>1.10.1.16</FileVersion>
<AssemblyName>wdmrc</AssemblyName>
<RootNamespace>YaR.CloudMailRu.Console</RootNamespace>
<StartupObject></StartupObject>
Expand Down
3 changes: 2 additions & 1 deletion WDMRC.Console/wdmrc.config
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
</log4net>

<TwoFactorAuthHandlerName serializeAs="String">AuthCodeConsole</TwoFactorAuthHandlerName>


<AdditionalSpecialCommandPrefix serializeAs="String">.,.</AdditionalSpecialCommandPrefix>

</config>

0 comments on commit d12c30d

Please sign in to comment.