Example #1
0
        // TODO: use more specialized interface to get files
        public static async Task <MatchHash> CreateAsync(IRepositoryMod mod, CancellationToken cancellationToken)
        {
            byte[]? modCppData = null;
            try
            {
                modCppData = await mod.GetFile("/mod.cpp", cancellationToken);
            }
            catch (Exception)
            {
                // ignored
            }

            string?name = null;

            if (modCppData != null)
            {
                name = ModUtil.ParseModCpp(Encoding.UTF8.GetString(modCppData)).GetValueOrDefault("name");
                if (name != null)
                {
                    name = CleanName(name);
                }
            }

            var pboNames = await mod.GetFileList(cancellationToken);

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

            return(new MatchHash(pboNameSet, name));
        }
Example #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));
        }