wasStitchNET – Diff between revs 3 and 5
?pathlinks?
Rev 3 | Rev 5 | |||
---|---|---|---|---|
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; |
- | ||
10 | using System.Linq; |
9 | using System.Linq; |
|
11 | using System.Net; |
10 | using System.Net; |
|
12 | using System.Security.Cryptography; |
- | ||
13 | using System.Threading.Tasks; |
11 | using System.Threading.Tasks; |
|
14 | using wasDAVClient; |
12 | using wasDAVClient; |
|
15 | using wasSharp; |
13 | using wasSharp; |
|
16 | using wasSharp.Linq; |
14 | using wasSharp.Linq; |
|
17 | using wasSharp.Web.Utilities; |
15 | using wasSharp.Web.Utilities; |
|
18 | using wasSharpNET.Cryptography; |
16 | using wasSharpNET.Cryptography; |
|
19 | |
17 | |
|
20 | namespace wasStitchNET.Repository |
18 | namespace wasStitchNET.Repository |
|
21 | { |
19 | { |
|
22 | public class Tools |
20 | public class Tools |
|
23 | { |
21 | { |
|
24 | /// <summary> |
22 | /// <summary> |
|
25 | /// Lists the release files for a given release version. |
23 | /// Lists the release files for a given release version. |
|
26 | /// </summary> |
24 | /// </summary> |
|
27 | /// <param name="server">the Stitch server to use</param> |
25 | /// <param name="server">the Stitch server to use</param> |
|
28 | /// <param name="release">the release to list files for</param> |
26 | /// <param name="release">the release to list files for</param> |
|
29 | /// <param name="timeout">the timeout connecting to the Stitch repository</param> |
27 | /// <param name="timeout">the timeout connecting to the Stitch repository</param> |
|
30 | /// <returns>a list of Corrade files contained in the repository</returns> |
28 | /// <returns>a list of Corrade files contained in the repository</returns> |
|
31 | public static async Task<IEnumerable<string>> GetReleaseFiles(string server, Version release, int timeout) |
29 | public static async Task<IEnumerable<string>> GetReleaseFiles(string server, Version release, int timeout) |
|
32 | { |
30 | { |
|
33 | using (var client = new Client(new NetworkCredential()) |
31 | using (var client = new Client(new NetworkCredential()) |
|
34 | { |
32 | { |
|
35 | Timeout = timeout, |
33 | Timeout = timeout, |
|
36 | UserAgent = STITCH_CONSTANTS.USER_AGENT.Product.Name, |
34 | UserAgent = STITCH_CONSTANTS.USER_AGENT.Product.Name, |
|
37 | UserAgentVersion = STITCH_CONSTANTS.USER_AGENT.Product.Version, |
35 | UserAgentVersion = STITCH_CONSTANTS.USER_AGENT.Product.Version, |
|
38 | Server = server, |
36 | Server = server, |
|
39 | BasePath = string.Join(@"/", STITCH_CONSTANTS.UPDATE_PATH, |
37 | BasePath = string.Join(@"/", STITCH_CONSTANTS.UPDATE_PATH, |
|
40 | STITCH_CONSTANTS.PROGRESSIVE_PATH) |
38 | STITCH_CONSTANTS.PROGRESSIVE_PATH) |
|
41 | }) |
39 | }) |
|
42 | { |
40 | { |
|
43 | return (await client |
41 | return (await client |
|
44 | .List( |
42 | .List( |
|
45 | string.Join( |
43 | string.Join( |
|
46 | Constants.DIRECTORY_SEPARATOR, |
44 | Constants.DIRECTORY_SEPARATOR, |
|
47 | $"{release.Major}.{release.Minor}", |
45 | $"{release.Major}.{release.Minor}", |
|
48 | STITCH_CONSTANTS.UPDATE_DATA_PATH), |
46 | STITCH_CONSTANTS.UPDATE_DATA_PATH), |
|
49 | Constants.DavDepth.ALL) |
47 | Constants.DavDepth.ALL) |
|
50 | ) |
48 | ) |
|
51 | .Select(o => string.Join(Constants.DIRECTORY_SEPARATOR, |
49 | .Select(o => string.Join(Constants.DIRECTORY_SEPARATOR, |
|
52 | o.Href.PathSplit(Constants.DIRECTORY_SEPARATOR.First()) |
50 | o.Href.PathSplit(Constants.DIRECTORY_SEPARATOR.First()) |
|
53 | .Select(part => |
51 | .Select(part => |
|
54 | WebExtensions.URLUnescapeDataString( |
- | ||
55 | part.Trim(Constants.DIRECTORY_SEPARATOR.First()) |
52 | part.Trim(Constants.DIRECTORY_SEPARATOR.First()).URLUnescapeDataString() |
|
56 | ) |
- | ||
57 | ) |
53 | ) |
|
58 | .Where(part => !string.IsNullOrEmpty(part)) |
54 | .Where(part => !string.IsNullOrEmpty(part)) |
|
59 | .SequenceExceptAny(new[] { |
55 | .SequenceExceptAny(new[] { |
|
60 | STITCH_CONSTANTS.UPDATE_PATH, |
56 | STITCH_CONSTANTS.UPDATE_PATH, |
|
61 | STITCH_CONSTANTS.PROGRESSIVE_PATH, |
57 | STITCH_CONSTANTS.PROGRESSIVE_PATH, |
|
62 | $"{release.Major}.{release.Minor}", |
58 | $"{release.Major}.{release.Minor}", |
|
63 | STITCH_CONSTANTS.UPDATE_DATA_PATH |
59 | STITCH_CONSTANTS.UPDATE_DATA_PATH |
|
64 | }) |
60 | }) |
|
65 | ) |
61 | ) |
|
66 | ); |
62 | ); |
|
67 | } |
63 | } |
|
68 | } |
64 | } |
|
69 | |
65 | |
|
70 | /// <summary> |
66 | /// <summary> |
|
71 | /// Lists the release files for a given release version. |
67 | /// Lists the release files for a given release version. |
|
72 | /// </summary> |
68 | /// </summary> |
|
73 | /// <param name="server">the Stitch server to use</param> |
69 | /// <param name="server">the Stitch server to use</param> |
|
74 | /// <param name="release">the release to list files for</param> |
70 | /// <param name="release">the release to list files for</param> |
|
75 | /// <param name="timeout">the timeout connecting to the Stitch repository</param> |
71 | /// <param name="timeout">the timeout connecting to the Stitch repository</param> |
|
76 | /// <returns>a list of Corrade files contained in the repository</returns> |
72 | /// <returns>a list of Corrade files contained in the repository</returns> |
|
77 | public static IEnumerable<KeyValuePair<string, string>> GetReleaseFileHashes(string server, Version release, int timeout) |
73 | public static IEnumerable<KeyValuePair<string, string>> GetReleaseFileHashes(string server, Version release, int timeout) |
|
78 | { |
74 | { |
|
79 | using (var client = new Client(new NetworkCredential()) |
75 | using (var client = new Client(new NetworkCredential()) |
|
80 | { |
76 | { |
|
81 | Timeout = timeout, |
77 | Timeout = timeout, |
|
82 | UserAgent = STITCH_CONSTANTS.USER_AGENT.Product.Name, |
78 | UserAgent = STITCH_CONSTANTS.USER_AGENT.Product.Name, |
|
83 | UserAgentVersion = STITCH_CONSTANTS.USER_AGENT.Product.Version, |
79 | UserAgentVersion = STITCH_CONSTANTS.USER_AGENT.Product.Version, |
|
84 | Server = server, |
80 | Server = server, |
|
85 | BasePath = string.Join(@"/", STITCH_CONSTANTS.UPDATE_PATH, |
81 | BasePath = string.Join(@"/", STITCH_CONSTANTS.UPDATE_PATH, |
|
86 | STITCH_CONSTANTS.PROGRESSIVE_PATH) |
82 | STITCH_CONSTANTS.PROGRESSIVE_PATH) |
|
87 | }) |
83 | }) |
|
88 | { |
84 | { |
|
89 | return client |
85 | return client |
|
90 | .List( |
86 | .List( |
|
91 | string.Join( |
87 | string.Join( |
|
92 | Constants.DIRECTORY_SEPARATOR, |
88 | Constants.DIRECTORY_SEPARATOR, |
|
93 | $"{release.Major}.{release.Minor}", |
89 | $"{release.Major}.{release.Minor}", |
|
94 | STITCH_CONSTANTS.UPDATE_DATA_PATH), |
90 | STITCH_CONSTANTS.UPDATE_DATA_PATH), |
|
95 | Constants.DavDepth.ALL) |
91 | Constants.DavDepth.ALL) |
|
96 | .Result |
92 | .Result |
|
97 | .AsParallel() |
93 | .AsParallel() |
|
98 | .Where(item => !item.IsCollection) |
94 | .Where(item => !item.IsCollection) |
|
99 | .ToDictionary(o => string.Join(Constants.DIRECTORY_SEPARATOR, |
95 | .ToDictionary(o => string.Join(Constants.DIRECTORY_SEPARATOR, |
|
100 | o.Href.PathSplit(Constants.DIRECTORY_SEPARATOR.First()) |
96 | o.Href.PathSplit(Constants.DIRECTORY_SEPARATOR.First()) |
|
101 | .Select(part => WebExtensions.URLUnescapeDataString( |
- | ||
102 | part.Trim(Constants.DIRECTORY_SEPARATOR.First()) |
97 | .Select(part => part.Trim(Constants.DIRECTORY_SEPARATOR.First()).URLUnescapeDataString() |
|
103 | ) |
- | ||
104 | ) |
98 | ) |
|
105 | .Where(part => !string.IsNullOrEmpty(part)) |
99 | .Where(part => !string.IsNullOrEmpty(part)) |
|
106 | .SequenceExceptAny(new[] { |
100 | .SequenceExceptAny(new[] { |
|
107 | STITCH_CONSTANTS.UPDATE_PATH, |
101 | STITCH_CONSTANTS.UPDATE_PATH, |
|
108 | STITCH_CONSTANTS.PROGRESSIVE_PATH, |
102 | STITCH_CONSTANTS.PROGRESSIVE_PATH, |
|
109 | $"{release.Major}.{release.Minor}", |
103 | $"{release.Major}.{release.Minor}", |
|
110 | STITCH_CONSTANTS.UPDATE_DATA_PATH |
104 | STITCH_CONSTANTS.UPDATE_DATA_PATH |
|
111 | })), o => System.Security.Cryptography.SHA1.Create().ToHex(client.Download(o.Href).Result)); |
105 | })), o => System.Security.Cryptography.SHA1.Create().ToHex(client.Download(o.Href).Result)); |
|
112 | } |
106 | } |
|
113 | } |
107 | } |
|
114 | } |
108 | } |
|
115 | } |
109 | } |
|
116 | |
110 | |