/// <summary> /// "Decrypts" uniform string into FileIdentifier instance exposing its path and hash. /// </summary> /// <param name="cloakedId"></param> /// <returns></returns> public static FileIdentifier Decloak(string cloakedId) { cloakedId = Obfuscator.Decloak(cloakedId); Regex regex = new Regex("(.*)::(.*)"); MatchCollection matches = regex.Matches(cloakedId); if (matches.Count() != 1) { throw new InvalidFileIdentifierException(cloakedId); } return(new FileIdentifier { Path = matches[0].Groups[1].Value, Hash = matches[0].Groups[2].Value }); }
/// <summary> /// Gets a list of all tags from tag index folder. Tags are not read from package manifests. /// </summary> /// <returns></returns> public IEnumerable<string> GetAllTags() { string[] rawTags = Directory.GetDirectories(_settings.TagsPath); List<string> tags = new List<string>(); foreach (string rawTag in rawTags) { try { tags.Add(Obfuscator.Decloak(Path.GetFileName(rawTag))); } catch (FormatException) { // log invalid tag folders, and continue. _logger.LogError($"The tag \"{rawTag}\" is not a valid base64 string. This node in the tags folder should be pruned out."); } } return tags; }
/// <summary> /// Gets a list of all tags, and all packages tagged by each tag. /// </summary> /// <returns></returns> public Dictionary<string, IEnumerable<string>> GetTagsThenPackages() { string[] rawTags = Directory.GetDirectories(_settings.TagsPath); Dictionary<string, IEnumerable<string>> tags = new Dictionary<string, IEnumerable<string>>(); foreach (string rawTag in rawTags) { try { IEnumerable<string> packages = Directory.GetFiles(rawTag).Select(r => Path.GetFileName(r)); tags.Add(Obfuscator.Decloak(Path.GetFileName(rawTag)), packages); } catch (FormatException) { // log invalid tag folders, and continue. _logger.LogError($"The tag \"{rawTag}\" is not a valid base64 string. This node in the tags folder should be pruned out."); } } return tags; }