예제 #1
0
        // TODO: use more specialized interface to get files
        public static async Task <VersionHash> CreateAsync(IStorageMod mod, CancellationToken cancellationToken)
        {
            var hashes = new Dictionary <string, FileHash>();

            foreach (var file in await mod.GetFileList(cancellationToken))
            {
                var stream = await mod.OpenRead(file, cancellationToken);

                if (stream == null)
                {
                    throw new InvalidOperationException();
                }
                var hash = await Sha1AndPboHash.BuildAsync(stream, Utils.GetExtension(file), cancellationToken);

                hashes.Add(file, hash);
            }

            return(new VersionHash(BuildHash(hashes)));
        }
예제 #2
0
        // TODO: use more specialized interface to get files
        public static async Task <MatchHash> CreateAsync(IStorageMod mod, CancellationToken cancellationToken)
        {
            var modCpp = await mod.OpenRead("/mod.cpp", cancellationToken);

            string?name = null;

            if (modCpp != null)
            {
                using var reader = new StreamReader(modCpp);
                var entries = ModUtil.ParseModCpp(reader.ReadToEnd());
                name = entries.GetValueOrDefault("name");
                if (name != null)
                {
                    name = CleanName(name);
                }
            }

            var pboNames = await mod.GetFileList(cancellationToken);

            var pboNameSet = pboNames.Where(p => AddonsPboRegex.IsMatch(p)).ToHashSet();

            return(new MatchHash(pboNameSet, name));
        }