Пример #1
0
        private static void AssembleContentRecursive(CompileContext context, AddonEntry addon, AddonContent currentContent)
        {
            foreach (AddonContent subContent in currentContent.SubContent)
            {
                AssembleContentRecursive(context, addon, subContent);
            }

            CarbonFile absoluteFile = currentContent.RootDirectory.ToFile(currentContent.File);
            if (!absoluteFile.Exists)
            {
                Diagnostic.Warning("Content File {0} does not exist! ({1})", absoluteFile, currentContent.File);
                return;
            }

            var content = new CompileContent(addon, absoluteFile, absoluteFile.ToRelative<CarbonFile>(context.Source.ToDirectory(addon.Name)));
            using (var stream = absoluteFile.OpenRead())
            {
                byte[] md5 = HashUtils.GetMd5(stream);
                content.Md5 = HashUtils.Md5ToString(md5);
            }

            context.FullContentList.Add(content);
        }
Пример #2
0
        private static bool WriteScriptContentToTarget(CompileContent content, CarbonFile target)
        {
            IList<string> contents = new List<string>();
            using (var stream = content.AbsoluteFile.OpenRead())
            {
                using (var reader = new StreamReader(stream))
                {
                    while (!reader.EndOfStream)
                    {
                        string line = reader.ReadLine();
                        contents.Add(line);
                    }
                }
            }

            for (int i = 0; i < contents.Count; i++)
            {
                string line = contents[i];
                string trimmedLine = line.Trim().TrimStart('\t');
                if (trimmedLine.StartsWith("--"))
                {
                    continue;
                }

                Match match = AddonInitParamRegex.Match(line);
                if (match.Success)
                {
                    string replacementLine = string.Concat(match.Groups[1].Value, $"GetAddonGlobalArgs(\"{content.Addon.Name}\")", match.Groups[3].Value);
                    contents[i] = replacementLine;

                    Diagnostic.Warning("Adjusting lua parameters: {0}, line {1}\n{2}\n{3}", content.AbsoluteFile, i, line, replacementLine);
                }
            }

            target.WriteAsString(string.Join(Environment.NewLine, contents));

            return true;
        }