wasStitchNET – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /////////////////////////////////////////////////////////////////////////// |
2 | // Copyright (C) Wizardry and Steamworks 2017 - License: GNU GPLv3 // |
||
3 | // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // |
||
4 | // rights of fair usage, the disclaimer and warranty conditions. // |
||
5 | /////////////////////////////////////////////////////////////////////////// |
||
6 | |||
7 | using System.IO; |
||
8 | using System.Linq; |
||
9 | using System.Threading.Tasks; |
||
10 | using wasDAVClient; |
||
11 | using wasSharpNET.Cryptography; |
||
12 | using SHA1 = System.Security.Cryptography.SHA1; |
||
13 | |||
14 | namespace wasStitchNET |
||
15 | { |
||
16 | public class Hashing |
||
17 | { |
||
18 | public static async Task<string> HashLocalFiles(string path) |
||
19 | { |
||
20 | using (var memoryStream = new MemoryStream()) |
||
21 | { |
||
22 | foreach (var file in Directory |
||
23 | .GetFiles(path, "*.*", SearchOption.AllDirectories) |
||
24 | .OrderBy(o => o.Split(Path.DirectorySeparatorChar).Last())) |
||
25 | { |
||
26 | using (var fileStream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read)) |
||
27 | { |
||
28 | await fileStream.CopyToAsync(memoryStream); |
||
29 | } |
||
30 | } |
||
31 | memoryStream.Position = 0L; |
||
32 | return SHA1.Create().ToHex(memoryStream); |
||
33 | } |
||
34 | } |
||
35 | |||
36 | public static async Task<string> HashRemoteFiles(Client client, string path) |
||
37 | { |
||
38 | using (var memoryStream = new MemoryStream()) |
||
39 | { |
||
40 | foreach (var item in (await client.List(path, Constants.DavDepth.ALL)).OrderBy(o => o.DisplayName).Where(item => !item.IsCollection)) |
||
41 | { |
||
42 | using (var stream = client.Download(item.Href).Result) |
||
43 | { |
||
44 | await stream.CopyToAsync(memoryStream); |
||
45 | } |
||
46 | } |
||
47 | memoryStream.Position = 0L; |
||
48 | return SHA1.Create().ToHex(memoryStream); |
||
49 | } |
||
50 | } |
||
51 | } |
||
52 | } |