wasStitchNET – Diff between revs 1 and 2

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 1 Rev 2
1 /////////////////////////////////////////////////////////////////////////// 1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (C) Wizardry and Steamworks 2017 - License: GNU GPLv3 // 2 // Copyright (C) Wizardry and Steamworks 2017 - License: GNU GPLv3 //
3 // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // 3 // Please see: http://www.gnu.org/licenses/gpl.html for legal details, //
4 // rights of fair usage, the disclaimer and warranty conditions. // 4 // rights of fair usage, the disclaimer and warranty conditions. //
5 /////////////////////////////////////////////////////////////////////////// 5 ///////////////////////////////////////////////////////////////////////////
6   6  
7 using System; 7 using System;
8 using System.Collections.Generic; 8 using System.Collections.Generic;
-   9 using System.IO;
9 using System.Linq; 10 using System.Linq;
10 using System.Net; 11 using System.Net;
-   12 using System.Security.Cryptography;
11 using System.Threading.Tasks; 13 using System.Threading.Tasks;
12 using wasDAVClient; 14 using wasDAVClient;
13 using wasSharp; 15 using wasSharp;
14 using wasSharp.Linq; 16 using wasSharp.Linq;
15 using wasSharp.Web.Utilities; 17 using wasSharp.Web.Utilities;
-   18 using wasSharpNET.Cryptography;
16   19  
17 namespace wasStitchNET.Repository 20 namespace wasStitchNET.Repository
18 { 21 {
19 public class Tools 22 public class Tools
20 { 23 {
21 /// <summary> 24 /// <summary>
22 /// Lists the release files for a given release version. 25 /// Lists the release files for a given release version.
23 /// </summary> 26 /// </summary>
24 /// <param name="server">the Stitch server to use</param> 27 /// <param name="server">the Stitch server to use</param>
25 /// <param name="release">the release to list files for</param> 28 /// <param name="release">the release to list files for</param>
26 /// <param name="timeout">the timeout connecting to the Stitch repository</param> 29 /// <param name="timeout">the timeout connecting to the Stitch repository</param>
27 /// <returns>a list of Corrade files contained in the repository</returns> 30 /// <returns>a list of Corrade files contained in the repository</returns>
28 public static async Task<IEnumerable<string>> GetReleaseFiles(string server, Version release, int timeout) 31 public static async Task<IEnumerable<string>> GetReleaseFiles(string server, Version release, int timeout)
29 { 32 {
30 using (var client = new Client(new NetworkCredential()) 33 using (var client = new Client(new NetworkCredential())
31 { 34 {
32 Timeout = timeout, 35 Timeout = timeout,
33 UserAgent = STITCH_CONSTANTS.USER_AGENT.Product.Name, 36 UserAgent = STITCH_CONSTANTS.USER_AGENT.Product.Name,
34 UserAgentVersion = STITCH_CONSTANTS.USER_AGENT.Product.Version, 37 UserAgentVersion = STITCH_CONSTANTS.USER_AGENT.Product.Version,
35 Server = server, 38 Server = server,
36 BasePath = string.Join(@"/", STITCH_CONSTANTS.UPDATE_PATH, 39 BasePath = string.Join(@"/", STITCH_CONSTANTS.UPDATE_PATH,
37 STITCH_CONSTANTS.PROGRESSIVE_PATH) 40 STITCH_CONSTANTS.PROGRESSIVE_PATH)
38 }) 41 })
39 { 42 {
40 return (await client 43 return (await client
41 .List( 44 .List(
42 string.Join( 45 string.Join(
43 Constants.DIRECTORY_SEPARATOR, 46 Constants.DIRECTORY_SEPARATOR,
44 $"{release.Major}.{release.Minor}", 47 $"{release.Major}.{release.Minor}",
45 STITCH_CONSTANTS.UPDATE_DATA_PATH), 48 STITCH_CONSTANTS.UPDATE_DATA_PATH),
46 Constants.DavDepth.ALL) 49 Constants.DavDepth.ALL)
47 ) 50 )
48 .Select(o => string.Join(Constants.DIRECTORY_SEPARATOR, 51 .Select(o => string.Join(Constants.DIRECTORY_SEPARATOR,
49 o.Href.PathSplit(Constants.DIRECTORY_SEPARATOR.First()) 52 o.Href.PathSplit(Constants.DIRECTORY_SEPARATOR.First())
50 .Select(part => 53 .Select(part =>
51 WebExtensions.URLUnescapeDataString( 54 WebExtensions.URLUnescapeDataString(
52 part.Trim(Constants.DIRECTORY_SEPARATOR.First()) 55 part.Trim(Constants.DIRECTORY_SEPARATOR.First())
53 ) 56 )
54 ) 57 )
55 .Where(part => !string.IsNullOrEmpty(part)) 58 .Where(part => !string.IsNullOrEmpty(part))
56 .SequenceExceptAny(new[] { 59 .SequenceExceptAny(new[] {
57 STITCH_CONSTANTS.UPDATE_PATH, 60 STITCH_CONSTANTS.UPDATE_PATH,
58 STITCH_CONSTANTS.PROGRESSIVE_PATH, 61 STITCH_CONSTANTS.PROGRESSIVE_PATH,
59 $"{release.Major}.{release.Minor}", 62 $"{release.Major}.{release.Minor}",
60 STITCH_CONSTANTS.UPDATE_DATA_PATH 63 STITCH_CONSTANTS.UPDATE_DATA_PATH
61 }) 64 })
62 ) 65 )
63 ); 66 );
64 } 67 }
-   68 }
-   69  
-   70 /// <summary>
-   71 /// Lists the release files for a given release version.
-   72 /// </summary>
-   73 /// <param name="server">the Stitch server to use</param>
-   74 /// <param name="release">the release to list files for</param>
-   75 /// <param name="timeout">the timeout connecting to the Stitch repository</param>
-   76 /// <returns>a list of Corrade files contained in the repository</returns>
-   77 public static async Task<IEnumerable<KeyValuePair<string, string>>> GetReleaseFileHashes(string server, Version release, int timeout)
-   78 {
-   79 using (var client = new Client(new NetworkCredential())
-   80 {
-   81 Timeout = timeout,
-   82 UserAgent = STITCH_CONSTANTS.USER_AGENT.Product.Name,
-   83 UserAgentVersion = STITCH_CONSTANTS.USER_AGENT.Product.Version,
-   84 Server = server,
-   85 BasePath = string.Join(@"/", STITCH_CONSTANTS.UPDATE_PATH,
-   86 STITCH_CONSTANTS.PROGRESSIVE_PATH)
-   87 })
-   88 {
-   89 Console.WriteLine($"{release.Major}.{release.Minor}");
-   90 return (await client
-   91 .List(
-   92 string.Join(
-   93 Constants.DIRECTORY_SEPARATOR,
-   94 $"{release.Major}.{release.Minor}",
-   95 STITCH_CONSTANTS.UPDATE_DATA_PATH),
-   96 Constants.DavDepth.ALL)
-   97 )
-   98 .Select(async o =>
-   99 {
-   100 using (var memoryStream = new MemoryStream())
-   101 {
-   102 using (var stream = client.Download(o.Href).Result)
-   103 {
-   104 await stream.CopyToAsync(memoryStream);
-   105 }
-   106 return new KeyValuePair<string, string>(
-   107 string.Join(Constants.DIRECTORY_SEPARATOR,
-   108 o.Href.PathSplit(Constants.DIRECTORY_SEPARATOR.First())
-   109 .Select(part =>
-   110 WebExtensions.URLUnescapeDataString(
-   111 part.Trim(Constants.DIRECTORY_SEPARATOR.First())
-   112 )
-   113 )
-   114 .Where(part => !string.IsNullOrEmpty(part))
-   115 .SequenceExceptAny(new[] {
-   116 STITCH_CONSTANTS.UPDATE_PATH,
-   117 STITCH_CONSTANTS.PROGRESSIVE_PATH,
-   118 $"{release.Major}.{release.Minor}",
-   119 STITCH_CONSTANTS.UPDATE_DATA_PATH
-   120 })
-   121 ), System.Security.Cryptography.SHA1.Create().ToHex(memoryStream));
-   122 }
-   123 }
-   124 ).Select(o => o.Result).OfType<KeyValuePair<string, string>>();
-   125 }
65 } 126 }
66 } 127 }
67 } 128 }
68   129