/////////////////////////////////////////////////////////////////////////// // Copyright (C) Wizardry and Steamworks 2017 - License: GNU GPLv3 // // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // // rights of fair usage, the disclaimer and warranty conditions. // /////////////////////////////////////////////////////////////////////////// using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Threading.Tasks; using wasDAVClient; using wasDAVClient.Helpers; using wasSharp; using wasSharp.Sets; using wasSharp.Web.Utilities; using wasSharpNET.Cryptography; using SHA1 = System.Security.Cryptography.SHA1; namespace wasStitchNET.Repository { public class Tools { /// /// Lists the release files for a given release version. /// /// the Stitch server to use /// the release to list files for /// the timeout connecting to the Stitch repository /// a list of Corrade files contained in the repository public static async Task> GetReleaseFiles(string server, Version release, int timeout) { try { using (var client = new Client(new NetworkCredential()) { Timeout = timeout, UserAgent = STITCH_CONSTANTS.USER_AGENT.Product.Name, UserAgentVersion = STITCH_CONSTANTS.USER_AGENT.Product.Version, Server = server, BasePath = string.Join(@"/", STITCH_CONSTANTS.UPDATE_PATH, STITCH_CONSTANTS.PROGRESSIVE_PATH) }) { return (await client .List( string.Join( Constants.DIRECTORY_SEPARATOR, $"{release.Major}.{release.Minor}", STITCH_CONSTANTS.UPDATE_DATA_PATH), Constants.DavDepth.ALL) ) .Select(o => string.Join(Constants.DIRECTORY_SEPARATOR, o.Href.PathSplit(Constants.DIRECTORY_SEPARATOR.First()) .Select(part => part.Trim(Constants.DIRECTORY_SEPARATOR.First()).URLUnescapeDataString() ) .Where(part => !string.IsNullOrEmpty(part)) .SequenceExceptAny(new[] { STITCH_CONSTANTS.UPDATE_PATH, STITCH_CONSTANTS.PROGRESSIVE_PATH, $"{release.Major}.{release.Minor}", STITCH_CONSTANTS.UPDATE_DATA_PATH }) ) ); } } catch (wasDAVConflictException ex) { throw new StitchException(ex); } } /// /// Lists the release files for a given release version. /// /// the Stitch server to use /// the release to list files for /// the timeout connecting to the Stitch repository /// a list of Corrade files contained in the repository public static IEnumerable> GetReleaseFileHashes(string server, Version release, int timeout) { try { using (var client = new Client(new NetworkCredential()) { Timeout = timeout, UserAgent = STITCH_CONSTANTS.USER_AGENT.Product.Name, UserAgentVersion = STITCH_CONSTANTS.USER_AGENT.Product.Version, Server = server, BasePath = string.Join(@"/", STITCH_CONSTANTS.UPDATE_PATH, STITCH_CONSTANTS.PROGRESSIVE_PATH) }) { return client .List( string.Join( Constants.DIRECTORY_SEPARATOR, $"{release.Major}.{release.Minor}", STITCH_CONSTANTS.UPDATE_DATA_PATH), Constants.DavDepth.ALL) .Result .AsParallel() .Where(item => !item.IsCollection) .ToDictionary(o => string.Join(Constants.DIRECTORY_SEPARATOR, o.Href.PathSplit(Constants.DIRECTORY_SEPARATOR.First()) .Select(part => part.Trim(Constants.DIRECTORY_SEPARATOR.First()) .URLUnescapeDataString() ) .Where(part => !string.IsNullOrEmpty(part)) .SequenceExceptAny(new[] { STITCH_CONSTANTS.UPDATE_PATH, STITCH_CONSTANTS.PROGRESSIVE_PATH, $"{release.Major}.{release.Minor}", STITCH_CONSTANTS.UPDATE_DATA_PATH })), o => SHA1.Create().ToHex(client.Download(o.Href).Result)); } } catch (wasDAVException ex) { throw new StitchException(ex); } } } }