Skip to content

Commit

Permalink
Merge branch 'develop2'
Browse files Browse the repository at this point in the history
  • Loading branch information
yar229 committed Apr 4, 2022
2 parents eb23115 + c7abee6 commit b464860
Show file tree
Hide file tree
Showing 124 changed files with 764 additions and 522 deletions.
2 changes: 1 addition & 1 deletion Hasher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Hasher
{
static class Program
{
static void Main(string[] args)
private static void Main(string[] args)
{
var cmdArguments = Parser.Default.ParseArguments<CommandLineOptions>(args);

Expand Down
6 changes: 3 additions & 3 deletions MailRuCloud/MailRuCloudApi/Base/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public virtual File New(string newfullPath)
{
CreationTimeUtc = CreationTimeUtc,
LastAccessTimeUtc = LastAccessTimeUtc,
LastWriteTimeUtc = LastWriteTimeUtc,
LastWriteTimeUtc = LastWriteTimeUtc
};
file.PublicLinks.AddRange(PublicLinks);

Expand Down Expand Up @@ -132,10 +132,10 @@ public IEnumerable<PublicLinkInfo> GetPublicLinks(Cloud cloud)
/// <summary>
/// List of phisical files contains data
/// </summary>
public virtual List<File> Parts => new List<File> {this};
public virtual List<File> Parts => new() {this};
public virtual IList<File> Files => new List<File> { this };

private static readonly DateTime MinFileDate = new DateTime(1900, 1, 1);
private static readonly DateTime MinFileDate = new(1900, 1, 1);
public virtual DateTime CreationTimeUtc { get; set; } = MinFileDate;
public virtual DateTime LastWriteTimeUtc { get; set; } = MinFileDate;
public virtual DateTime LastAccessTimeUtc { get; set; } = MinFileDate;
Expand Down
6 changes: 4 additions & 2 deletions MailRuCloud/MailRuCloudApi/Base/FileSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ public bool Equals(FileSize other)

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (obj.GetType() != GetType()) return false;
if (ReferenceEquals(null, obj))
return false;
if (obj.GetType() != GetType())
return false;
return Equals((FileSize)obj);
}

Expand Down
2 changes: 1 addition & 1 deletion MailRuCloud/MailRuCloudApi/Base/FilenameServiceInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static int HexToInt(char h)
};
}

static bool IsDigit(char c) => c >= '0' && c <= '9';
static bool IsDigit(char c) => c is >= '0' and <= '9';


var res = new FilenameServiceInfo { CleanName = filename, SplitInfo = new FileSplitInfo { IsHeader = true } };
Expand Down
4 changes: 2 additions & 2 deletions MailRuCloud/MailRuCloudApi/Base/Folder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public IEnumerable<IEntry> Entries
}
}

public List<File> Files { get; set; } = new List<File>();
public List<File> Files { get; set; } = new();

public List<Folder> Folders { get; set; } = new List<Folder>();
public List<Folder> Folders { get; set; } = new();


/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions MailRuCloud/MailRuCloudApi/Base/Repos/IRequestRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class RemotePath
private RemotePath()
{}

public static RemotePath Get(string path) => new RemotePath{Path = path};
public static RemotePath Get(Link link) => new RemotePath{Link = link};
public static RemotePath Get(string path) => new() {Path = path};
public static RemotePath Get(Link link) => new() {Link = link};

public static async Task<RemotePath> Get(string path, LinkManager lm)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public static File ToFile(this FolderInfoResult data, string publicBaseUrl, stri
? filename
: nameReplacement;

if (string.IsNullOrEmpty(cmpname) && data.Body.Weblink != "/" && ulink != null && !ulink.IsLinkedToFileSystem)
if (string.IsNullOrEmpty(cmpname) && data.Body.Weblink != "/" && ulink is { IsLinkedToFileSystem: false })
{
cmpname = WebDavPath.Name(ulink.PublicLinks.First().Uri.OriginalString);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public IFileHash Hash
{
AppendFinalBuffer();

_sha1.TransformFinalBlock(new byte[0], 0, 0);
_sha1.TransformFinalBlock(Array.Empty<byte>(), 0, 0);
_hash = _sha1.Hash;
}
_isClosed = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MobileRequestRepo : MailRuBaseRepo, IRequestRepo
{
private static readonly log4net.ILog Logger = log4net.LogManager.GetLogger(typeof(MobileRequestRepo));

public override HttpCommonSettings HttpSettings { get; } = new HttpCommonSettings
public override HttpCommonSettings HttpSettings { get; } = new()
{
ClientId = "cloud-win",
UserAgent = "CloudDiskOWindows 17.12.0009 beta WzBbt1Ygbm"
Expand All @@ -34,13 +34,13 @@ public MobileRequestRepo(IWebProxy proxy, IAuth auth, int listDepth)

Authent = auth;

_metaServer = new Cached<ServerRequestResult>(old =>
_metaServer = new Cached<ServerRequestResult>(_ =>
{
Logger.Debug("MetaServer expired, refreshing.");
var server = new MobMetaServerRequest(HttpSettings).MakeRequestAsync().Result;
return server;
},
value => TimeSpan.FromSeconds(MetaServerExpiresSec));
_ => TimeSpan.FromSeconds(MetaServerExpiresSec));

//_downloadServer = new Cached<ServerRequestResult>(old =>
// {
Expand All @@ -59,7 +59,7 @@ public MobileRequestRepo(IWebProxy proxy, IAuth auth, int listDepth)

//private readonly Cached<ServerRequestResult> _downloadServer;
private readonly int _listDepth;
private const int DownloadServerExpiresSec = 20 * 60;
//private const int DownloadServerExpiresSec = 20 * 60;



Expand Down Expand Up @@ -96,11 +96,11 @@ public Stream GetDownloadStream(File file, long? start = null, long? end = null)
//}


public void BanShardInfo(ShardInfo banShard)
{
//TODO: implement
Logger.Warn($"{nameof(MobileRequestRepo)}.{nameof(BanShardInfo)} not implemented");
}
//public void BanShardInfo(ShardInfo banShard)
//{
// //TODO: implement
// Logger.Warn($"{nameof(MobileRequestRepo)}.{nameof(BanShardInfo)} not implemented");
//}

public override Task<ShardInfo> GetShardInfo(ShardType shardType)
{
Expand Down Expand Up @@ -145,21 +145,27 @@ public async Task<IEntry> FolderInfo(RemotePath path, int offset = 0, int limit
var f = new Folder(fsFolder.Size == null ? 0 : (long)fsFolder.Size.Value, fsFolder.FullPath);
foreach (var fsi in fsFolder.Items)
{
if (fsi is FsFile fsfi)
switch (fsi)
{
var fi = new File(fsfi.FullPath, (long)fsfi.Size, new FileHashMrc(fsfi.Sha1))
case FsFile fsfi:
{
CreationTimeUtc = fsfi.ModifDate,
LastWriteTimeUtc = fsfi.ModifDate
};
f.Files.Add(fi);
}
else if (fsi is FsFolder fsfo)
{
var fo = new Folder(fsfo.Size == null ? 0 : (long) fsfo.Size.Value, fsfo.FullPath);
f.Folders.Add(fo);
var fi = new File(fsfi.FullPath, (long)fsfi.Size, new FileHashMrc(fsfi.Sha1))
{
CreationTimeUtc = fsfi.ModifDate,
LastWriteTimeUtc = fsfi.ModifDate
};
f.Files.Add(fi);
break;
}
case FsFolder fsfo:
{
var fo = new Folder(fsfo.Size == null ? 0 : (long) fsfo.Size.Value, fsfo.FullPath);
f.Folders.Add(fo);
break;
}
default:
throw new Exception($"Unknown item type {fsi.GetType()}");
}
else throw new Exception($"Unknown item type {fsi.GetType()}");
}
return f;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Specialized;
using YaR.Clouds.Base.Repos.MailRuCloud.Mobile.Requests.Types;
using YaR.Clouds.Base.Requests;

Expand Down Expand Up @@ -27,7 +28,7 @@ protected override byte[] CreateHttpContent()
}
}

protected override RequestResponse<Result> DeserializeMessage(ResponseBodyStream data)
protected override RequestResponse<Result> DeserializeMessage(NameValueCollection responseHeaders, ResponseBodyStream data)
{
var opres = (OpResult)(int)data.OperationResult;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Specialized;
using System.Net;
using YaR.Clouds.Base.Repos.MailRuCloud.Mobile.Requests.Types;
using YaR.Clouds.Base.Requests;
Expand Down Expand Up @@ -60,14 +61,14 @@ protected override byte[] CreateHttpContent()

stream.WritePu32((int)Options);

stream.WriteWithLength(new byte[0]);
stream.WriteWithLength(Array.Empty<byte>());

var body = stream.GetBytes();
return body;
}
}

protected override RequestResponse<Result> DeserializeMessage(ResponseBodyStream data)
protected override RequestResponse<Result> DeserializeMessage(NameValueCollection responseHeaders, ResponseBodyStream data)
{
switch (data.OperationResult)
{
Expand Down Expand Up @@ -200,7 +201,7 @@ private FsItem GetItem(ResponseBodyStream data, FsFolder folder)
data.ReadULong(); // dunno

ulong? GetFolderSize() => (Options & Option.FolderSize) != 0
? (ulong?) data.ReadULong()
? data.ReadULong()
: null;
void ProcessDelete()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Specialized;
using System.Linq;
using YaR.Clouds.Base.Repos.MailRuCloud.Mobile.Requests.Types;
using YaR.Clouds.Base.Requests;
Expand Down Expand Up @@ -61,7 +62,7 @@ protected override byte[] CreateHttpContent()

private static readonly OpResult[] SuccessCodes = { OpResult.Ok, OpResult.NotModified, OpResult.Dunno04, OpResult.Dunno09};

protected override RequestResponse<Result> DeserializeMessage(ResponseBodyStream data)
protected override RequestResponse<Result> DeserializeMessage(NameValueCollection responseHeaders, ResponseBodyStream data)
{
var opres = (OpResult)(int)data.OperationResult;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Specialized;
using YaR.Clouds.Base.Repos.MailRuCloud.Mobile.Requests.Types;
using YaR.Clouds.Base.Requests;

Expand Down Expand Up @@ -35,7 +36,7 @@ protected override byte[] CreateHttpContent()
}
}

protected override RequestResponse<Result> DeserializeMessage(ResponseBodyStream data)
protected override RequestResponse<Result> DeserializeMessage(NameValueCollection responseHeaders, ResponseBodyStream data)
{
var opres = (OpResult) (int) data.OperationResult;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Specialized;
using YaR.Clouds.Base.Requests;
using YaR.Clouds.Base.Requests.Types;

Expand All @@ -10,7 +11,7 @@ protected ServerRequest(HttpCommonSettings settings) : base(settings, null)
{
}

protected override RequestResponse<ServerRequestResult> DeserializeMessage(string data)
protected override RequestResponse<ServerRequestResult> DeserializeMessage(NameValueCollection responseHeaders, string data)
{
var datas = data.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
var msg = new RequestResponse<ServerRequestResult>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using YaR.Clouds.Base.Repos.MailRuCloud.Mobile.Requests.Types;
using YaR.Clouds.Base.Requests;

Expand All @@ -22,7 +23,7 @@ protected override byte[] CreateHttpContent()
}
}

protected override RequestResponse<Result> DeserializeMessage(ResponseBodyStream data)
protected override RequestResponse<Result> DeserializeMessage(NameValueCollection responseHeaders, ResponseBodyStream data)
{
switch (data.OperationResult)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,6 @@ public short ReadShort()
return (short)(ReadInt() & 255);
}

public int ReadInt()
{
int b = _stream.ReadByte();

//Debug.Write($"{b:X} ");

if (b == -1)
throw new Exception("End of stream");
return b;
}

public OperationResult OperationResult { get; }

public int ReadIntSpl()
Expand All @@ -44,17 +33,31 @@ public int ReadIntSpl()

public byte[] ReadNBytes(long count)
{
//Debug.Write($"{nameof(ReadNBytes)}({count}) = ");
byte[] bytes = new byte[count];
for (int i = 0; i < count; i++)
{
bytes[i] = (byte)ReadInt();
}
//Debug.WriteLine("");
int total = (int)count;
byte[] bytes = new byte[total];

int bytesRead = 0;
int read;
while ((read = _stream.Read(bytes, bytesRead, total - bytesRead)) > 0)
bytesRead += read;

if (bytesRead < total)
throw new Exception($"End of stream {nameof(ReadNBytes)}");

return bytes;
}

public int ReadInt()
{
int b = _stream.ReadByte();

//Debug.Write($"{b:X} ");

if (b == -1)
throw new Exception("End of stream");
return b;
}

public ulong ReadULong()
{
//Debug.Write($"{nameof(ReadULong)}() = ");
Expand All @@ -66,7 +69,7 @@ public ulong ReadULong()
{
val = ReadInt();
int high = val & 127;
int rem = 7 - (i / 8);
int rem = 7 - i / 8;
int div = i % 8;
bytes[rem] = (byte) (bytes[rem] | ((high << div) & 255));
high >>= 8 - div;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected override string RelationalUri
{
get
{
var uri = $"{ConstSettings.CloudDomain}/api/v2/dispatcher?api=2&email=anonym&x-email=anonym";
const string uri = $"{ConstSettings.CloudDomain}/api/v2/dispatcher?api=2&email=anonym&x-email=anonym";
return uri;
}
}
Expand Down
Loading

0 comments on commit b464860

Please sign in to comment.