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