Пример #1
0
        void RecursiveAddFilesContent(IDirectoryCache directory, RefDictionary <string, object> filesContent,
                                      HashSet <string> takenNames, string destDir)
        {
            DiskCache.UpdateIfNeeded(directory);
            foreach (var child in directory)
            {
                if (child.IsInvalid)
                {
                    continue;
                }
                var outPathFileName = destDir + "/" + child.Name;
                takenNames.Add(outPathFileName);
                if (child is IDirectoryCache)
                {
                    RecursiveAddFilesContent(child as IDirectoryCache, filesContent, takenNames, outPathFileName);
                    continue;
                }

                if (child is IFileCache)
                {
                    filesContent.GetOrAddValueRef(outPathFileName) =
                        new Lazy <object>(() =>
                    {
                        var res = ((IFileCache)child).ByteContent;
                        ((IFileCache)child).FreeCache();
                        return(res);
                    });
                }
            }
        }
Пример #2
0
 internal FastEnumerator(RefDictionary <TKey, TValue> dictionary)
 {
     _dictionary = dictionary;
     _index      = 0;
     _count      = _dictionary._count;
     _current    = 0;
 }
Пример #3
0
        void RecursiveFillOutputByAdditionalResourcesDirectory(IDirectoryCache directoryCache, string resourcesPath,
                                                               RefDictionary <string, object> filesContent, BuildResult buildResult)
        {
            Owner.DiskCache.UpdateIfNeeded(directoryCache);
            foreach (var child in directoryCache)
            {
                if (child is IDirectoryCache)
                {
                    RecursiveFillOutputByAdditionalResourcesDirectory(child as IDirectoryCache, resourcesPath,
                                                                      filesContent, buildResult);
                    continue;
                }

                if (child.IsInvalid)
                {
                    continue;
                }
                var outPathFileName = PathUtils.Subtract(child.FullPath, resourcesPath);
                buildResult.TakenNames.Add(outPathFileName);
                if (child is IFileCache)
                {
                    filesContent.GetOrAddValueRef(outPathFileName) =
                        new Lazy <object>(() =>
                    {
                        var res = ((IFileCache)child).ByteContent;
                        ((IFileCache)child).FreeCache();
                        return(res);
                    });
                }
            }
        }
Пример #4
0
 public void FillOutputByAssetsFromModules(RefDictionary <string, object> filesContent,
                                           Dictionary <string, TSProject> modules, string nodeModulesDir, BuildResult buildResult)
 {
     foreach (var keyValuePair in modules)
     {
         keyValuePair.Value.FillOutputByAssets(filesContent, buildResult, nodeModulesDir, this);
     }
 }
Пример #5
0
 public void BuildTranslationJs(IToolsDir tools, RefDictionary <string, object> filesContent, string versionDir)
 {
     if (_changed)
     {
         _outputJsCache.Clear();
         foreach (var p in Lang2ValueList)
         {
             var langInit = tools.GetLocaleDef(p.Key);
             if (langInit == null)
             {
                 continue;
             }
             var sw      = new StringWriter();
             var posLoc1 = langInit.IndexOf("bobrilRegisterTranslations(", StringComparison.Ordinal) + "bobrilRegisterTranslations(".Length;
             var posLoc2 = langInit.IndexOf(",", posLoc1, StringComparison.Ordinal);
             langInit = langInit.Substring(0, posLoc1) + "\'" + p.Key + "\'" + langInit.Substring(posLoc2);
             sw.Write(langInit);
             var jw = new JsonTextWriter(sw);
             jw.WriteStartArray();
             for (var i = 0; i < UsedIds.Count; i++)
             {
                 var idx = (int)UsedIds[i];
                 jw.WriteValue(((idx < p.Value.Count) ? p.Value[idx] : null) ?? Id2Key[idx].Message);
             }
             jw.WriteEndArray();
             sw.Write(")");
             _outputJsCache[p.Key.ToLowerInvariant() + ".js"] = sw.ToString();
         }
         // scope
         {
             var sw = new StringWriter();
             sw.Write("bobrilRegisterTranslations(\"\",[],");
             var jw = new JsonTextWriter(sw);
             jw.WriteStartArray();
             for (var i = 0; i < UsedIds.Count; i++)
             {
                 var idx = (int)UsedIds[i];
                 var key = Id2Key[idx];
                 var val = key.Message + "\x9" + (key.WithParams ? "1" : "0") + (key.Hint ?? "");
                 jw.WriteValue(val);
             }
             jw.WriteEndArray();
             sw.Write(")");
             _outputJsCache["l10nkeys.js"] = sw.ToString();
         }
         _changed = false;
     }
     foreach (var i in _outputJsCache)
     {
         var outfn = i.Key;
         if (versionDir != null)
         {
             outfn = versionDir + "/" + outfn;
         }
         filesContent.GetOrAddValueRef(outfn) = i.Value;
     }
 }
Пример #6
0
 public override void Write(object o, HtmlWriter tag, DumpState state, RefDictionary refDict)
 {
     var val =  o.ToString();
     tag.Tag("kbd", t =>
     {
         t.NewLineAfterSTag = false;
         t.WriteString(val);
     });
 }
Пример #7
0
 void InitFileStats(long dontTouchGeneration)
 {
     _fileStats = new RefDictionary <uint, FileStat>();
     foreach (var file in _keyValueDB.FileCollection.FileInfos)
     {
         if (file.Value.SubDBId != 0)
         {
             continue;
         }
         if (!_keyValueDB.ContainsValuesAndDoesNotTouchGeneration(file.Key, dontTouchGeneration))
         {
             continue;
         }
         _fileStats.GetOrAddValueRef(file.Key) = new FileStat((uint)_keyValueDB.FileCollection.GetSize(file.Key));
     }
 }
Пример #8
0
 public void FillOutputByAssets(RefDictionary <string, object> filesContent, BuildResult buildResult,
                                string nodeModulesDir, ProjectOptions projectOptions)
 {
     if (Assets == null)
     {
         return;
     }
     foreach (var asset in Assets)
     {
         var fromModules = asset.Key.StartsWith("node_modules/");
         var fullPath    = fromModules ? nodeModulesDir : Owner.FullPath;
         if (fromModules)
         {
             if (projectOptions.Owner.UsedDependencies == null)
             {
                 projectOptions.Owner.UsedDependencies = new HashSet <string>();
             }
             var pos = 0;
             PathUtils.EnumParts(asset.Key, ref pos, out var name, out var isDir);
             PathUtils.EnumParts(asset.Key, ref pos, out name, out isDir);
             projectOptions.Owner.UsedDependencies.Add(name.ToString());
         }
         var item = DiskCache.TryGetItem(PathUtils.Join(fullPath, asset.Key));
         if (item == null || item.IsInvalid)
         {
             continue;
         }
         if (item is IFileCache)
         {
             buildResult.TakenNames.Add(asset.Value);
             filesContent.GetOrAddValueRef(asset.Value) = new Lazy <object>(() =>
             {
                 var res = ((IFileCache)item).ByteContent;
                 ((IFileCache)item).FreeCache();
                 return(res);
             });
         }
         else
         {
             RecursiveAddFilesContent(item as IDirectoryCache, filesContent, buildResult, asset.Value);
         }
     }
 }
Пример #9
0
        public void FillOutputByAdditionalResourcesDirectory(RefDictionary <string, object> filesContent,
                                                             Dictionary <string, TSProject> buildResultModules, BuildResult buildResult)
        {
            var nodeModulesDir = Owner.Owner.FullPath;

            Owner.FillOutputByAssets(filesContent, buildResult, nodeModulesDir, this);
            FillOutputByAssetsFromModules(filesContent, buildResultModules, nodeModulesDir, buildResult);
            if (AdditionalResourcesDirectory == null)
            {
                return;
            }
            var resourcesPath = PathUtils.Join(Owner.Owner.FullPath, AdditionalResourcesDirectory);
            var item          = Owner.DiskCache.TryGetItem(resourcesPath);

            if (item is IDirectoryCache)
            {
                RecursiveFillOutputByAdditionalResourcesDirectory(item as IDirectoryCache, resourcesPath, filesContent, buildResult);
            }
        }
Пример #10
0
        /// <summary>
        /// Calculates the next <see cref="Entity"/> to play from the <see cref="TurnTimeline"/>.
        /// The next <see cref="Entity"/> to play is the one that have the lowest <see cref="EntityTurnTimelineCalculationData.CurrentTimelinePosition"/>.
        /// When this <see cref="Entity"/> has been found, all <see cref="EntityTurnTimelineCalculationData"/> advances in the timeline by the distance from 0 of the founded <see cref="Entity"/>.<see cref="EntityTurnTimelineCalculationData.CurrentTimelinePosition"/>.
        /// Then the founded <see cref="Entity"/> is pushed back to the timeline.
        /// </summary>
        /// <param name="p_turnTimeline"></param>
        /// <returns></returns>
        public static Entity IncrementTimeline(TurnTimeline p_turnTimeline)
        {
            Entity l_lowerTimelineScore   = null;
            float  l_currentComparedScore = 0.0f;

            RefDictionary <Entity, EntityTurnTimelineCalculationData> l_entityTurnTimelineDataLookup = p_turnTimeline.TimelineOrderingDatas;

            var l_entityTurnTimelineDataLookupEnumerator = l_entityTurnTimelineDataLookup.GetRefEnumerator();

            while (l_entityTurnTimelineDataLookupEnumerator.MoveNext())
            {
                var l_timelineOrderingDataEntry_ref = l_entityTurnTimelineDataLookupEnumerator.GetCurrentRef();
                if (l_lowerTimelineScore == null)
                {
                    l_lowerTimelineScore   = l_timelineOrderingDataEntry_ref.key;
                    l_currentComparedScore = l_timelineOrderingDataEntry_ref.value.CurrentTimelinePosition;
                }
                else if (l_timelineOrderingDataEntry_ref.value.CurrentTimelinePosition < l_currentComparedScore)
                {
                    l_lowerTimelineScore   = l_timelineOrderingDataEntry_ref.key;
                    l_currentComparedScore = l_timelineOrderingDataEntry_ref.value.CurrentTimelinePosition;
                }
            }

            if (l_lowerTimelineScore != null)
            {
                float l_removedTimelineScore = l_currentComparedScore;

                // All entities advances in the timeline
                l_entityTurnTimelineDataLookupEnumerator = l_entityTurnTimelineDataLookup.GetRefEnumerator();
                while (l_entityTurnTimelineDataLookupEnumerator.MoveNext())
                {
                    l_entityTurnTimelineDataLookupEnumerator.GetCurrentRef().value.CurrentTimelinePosition += (-1 * l_removedTimelineScore);
                }

                // The next Entity is pushed back on the Timeline
                l_entityTurnTimelineDataLookup.ValueRef(l_lowerTimelineScore).CurrentTimelinePosition = EntityTurnTimelineCalculationData.calculateReferenceTurnTimelineScore(l_lowerTimelineScore);
            }

            return(l_lowerTimelineScore);
        }
Пример #11
0
 public void FillOutputByAssets(RefDictionary <string, object> filesContent, HashSet <string> takenNames,
                                string nodeModulesDir, ProjectOptions projectOptions)
 {
     if (Assets == null)
     {
         return;
     }
     foreach (var asset in Assets)
     {
         var fromModules = asset.Key.StartsWith("node_modules/");
         var fullPath    = fromModules ? nodeModulesDir : Owner.FullPath;
         if (projectOptions.Owner.UsedDependencies == null)
         {
             projectOptions.Owner.UsedDependencies = new HashSet <string>();
         }
         projectOptions.Owner.UsedDependencies.Add(PathUtils.EnumParts(asset.Key).Skip(1).Select(a => a.name)
                                                   .First());
         var item = DiskCache.TryGetItem(PathUtils.Join(fullPath, asset.Key));
         if (item == null || item.IsInvalid)
         {
             continue;
         }
         if (item is IFileCache)
         {
             takenNames.Add(asset.Value);
             filesContent.GetOrAddValueRef(asset.Value) = new Lazy <object>(() =>
             {
                 var res = ((IFileCache)item).ByteContent;
                 ((IFileCache)item).FreeCache();
                 return(res);
             });
         }
         else
         {
             RecursiveAddFilesContent(item as IDirectoryCache, filesContent, takenNames, asset.Value);
         }
     }
 }
Пример #12
0
        public void Build(string sourceRoot, bool testProj = false, bool allowIncremental = true)
        {
            _versionDirPrefix = "";
            var coverage = _project.CoverageEnabled;

            if (coverage)
            {
                allowIncremental = false;
            }
            if (_mainBuildResult.OutputSubDir != null)
            {
                _versionDirPrefix = _mainBuildResult.OutputSubDir + "/";
            }
            var root             = _mainBuildResult.CommonSourceDirectory;
            var incremental      = _buildResult.Incremental && allowIncremental;
            var start            = DateTime.UtcNow;
            var sourceMapBuilder = new SourceMapBuilder();

            if (_project.Localize)
            {
                if (!incremental)
                {
                    sourceMapBuilder.AddText(
                        $"function g11nPath(s){{return\"./{_mainBuildResult.OutputSubDirPrefix}\"+s.toLowerCase()+\".js\"}};");
                    if (_project.DefaultLanguage != null)
                    {
                        sourceMapBuilder.AddText($"var g11nLoc=\"{_project.DefaultLanguage}\";");
                    }
                }
            }

            if (_project.SpriteGeneration)
            {
                _bundlePng = _project.BundlePngUrl;
                var bundlePngContent = _project.SpriteGenerator.BuildImage(false);
                if (bundlePngContent != null)
                {
                    _bundlePngInfo = new List <float>();
                    foreach (var slice in bundlePngContent)
                    {
                        _mainBuildResult.FilesContent.GetOrAddValueRef(
                            PathUtils.InjectQuality(_bundlePng, slice.Quality)) = slice.Content;
                        _bundlePngInfo.Add(slice.Quality);
                    }
                }
                else
                {
                    _bundlePng = null;
                }
            }

            if (_bundlePng != null && !incremental)
            {
                sourceMapBuilder.AddText(_mainBuildResult.GenerateCodeForBobrilBPath(_bundlePng, _bundlePngInfo));
            }

            if (!incremental)
            {
                sourceMapBuilder.AddText(_tools.LoaderJs);
                sourceMapBuilder.AddText(GetGlobalDefines());
                sourceMapBuilder.AddText(GetModuleMap());
                sourceMapBuilder.AddText(BundlerHelpers.JsHeaders(false));
            }

            var cssLink = "";

            var sortedResultSet = incremental
                ? _buildResult.RecompiledIncrementaly.OrderBy(f => f.Owner.FullPath).ToArray()
                : _buildResult.Path2FileInfo.Values.OrderBy(f => f.Owner.FullPath).ToArray();

            if (!incremental)
            {
                foreach (var source in _buildResult.JavaScriptAssets)
                {
                    sourceMapBuilder.AddSource(source.Output, source.MapLink);
                }
            }

            foreach (var source in sortedResultSet)
            {
                if (source.Type == FileCompilationType.TypeScript ||
                    source.Type == FileCompilationType.EsmJavaScript ||
                    source.Type == FileCompilationType.JavaScript)
                {
                    if (source.Output == null)
                    {
                        continue; // Skip d.ts
                    }
                    sourceMapBuilder.AddText(
                        $"R('{PathUtils.Subtract(PathUtils.WithoutExtension(source.Owner.FullPath), root)}',function(require, module, exports, global){{");
                    var adder          = sourceMapBuilder.CreateSourceAdder(source.Output, source.MapLink);
                    var sourceReplacer = new SourceReplacer();
                    _project.ApplySourceInfo(sourceReplacer, source.SourceInfo, _buildResult);
                    sourceReplacer.Apply(adder);
                    sourceMapBuilder.AddText("\n});");
                }
                else if (source.Type == FileCompilationType.Json)
                {
                    sourceMapBuilder.AddText(
                        $"R('{PathUtils.Subtract(source.Owner.FullPath, root)}',");
                    sourceMapBuilder.AddText(source.Owner.Utf8Content);
                    sourceMapBuilder.AddText(");");
                }
                else if (source.Type == FileCompilationType.ImportedCss)
                {
                    sourceMapBuilder.AddText(
                        $"R('{PathUtils.Subtract(source.Owner.FullPath, root)}',function(){{}});");
                    string cssPath = _buildResult.ToOutputUrl(source);
                    _mainBuildResult.FilesContent.GetOrAddValueRef(cssPath) = source.Output;
                    cssLink += "<link rel=\"stylesheet\" href=\"" + cssPath + "\">";
                }
                else if (source.Type == FileCompilationType.Css)
                {
                    string cssPath = _buildResult.ToOutputUrl(source);
                    _mainBuildResult.FilesContent.GetOrAddValueRef(cssPath) = source.Output;
                    cssLink += "<link rel=\"stylesheet\" href=\"" + cssPath + "\">";
                }
                else if (source.Type == FileCompilationType.Resource)
                {
                    _mainBuildResult.FilesContent.GetOrAddValueRef(_buildResult.ToOutputUrl(source)) =
                        source.Owner.ByteContent;
                }
            }

            if (!testProj && _project.NoHtml)
            {
                sourceMapBuilder.AddText(RequireBobril());
                if (_project.MainFile != null)
                {
                    sourceMapBuilder.AddText(
                        $"R.r('./{PathUtils.WithoutExtension(PathUtils.Subtract(_project.MainFile, root))}');");
                }
            }

            if (_project.Localize)
            {
                _project.TranslationDb.BuildTranslationJs(_tools, _mainBuildResult.FilesContent,
                                                          _mainBuildResult.OutputSubDir);
            }

            if (incremental)
            {
                sourceMapBuilder.AddText("//# sourceMappingURL=bundle2.js.map");
                _sourceMap2       = sourceMapBuilder.Build(root, sourceRoot);
                _sourceMap2String = _sourceMap2.ToString();
                _bundle2Js        = sourceMapBuilder.Content();
                _project.Owner.Logger.Info("JS Bundle length: " + _bundleJs.Length + " SourceMap length: " +
                                           _sourceMapString.Length + " Delta: " + _bundle2Js.Length + " SM:" +
                                           _sourceMap2String.Length + " T:" +
                                           (DateTime.UtcNow - start).TotalMilliseconds.ToString("F0") + "ms");
            }
            else
            {
                sourceMapBuilder.AddText("//# sourceMappingURL=" + PathUtils.GetFile(_buildResult.BundleJsUrl) +
                                         ".map");
                if (coverage)
                {
                    _sourceMap = sourceMapBuilder.Build(".", ".");
                    _bundleJs  = sourceMapBuilder.Content();
                    var toplevel = Parser.Parse(_bundleJs);
                    _sourceMap.ResolveInAst(toplevel);
                    var coverageInst = new CoverageInstrumentation();
                    coverageInst.RealPath            = PathUtils.RealPath;
                    _project.CoverageInstrumentation = coverageInst;
                    toplevel = coverageInst.Instrument(toplevel);
                    coverageInst.AddCountingHelpers(toplevel);
                    coverageInst.CleanUp(new SourceReader(_project.Owner.DiskCache,
                                                          _mainBuildResult.CommonSourceDirectory));
                    if (_project.MainFile != null)
                    {
                        MarkImportant(_project.MainFile, _buildResult, new HashSet <string>(), coverageInst);
                    }
                    sourceMapBuilder = new SourceMapBuilder();
                    toplevel.PrintToBuilder(sourceMapBuilder, new OutputOptions {
                        Beautify = true
                    });
                    sourceMapBuilder.AddText("//# sourceMappingURL=" + PathUtils.GetFile(_buildResult.BundleJsUrl) +
                                             ".map");
                }

                _sourceMap = sourceMapBuilder.Build(root, sourceRoot);
                _bundleJs  = sourceMapBuilder.Content();

                _sourceMapString  = _sourceMap.ToString();
                _sourceMap2       = null;
                _sourceMap2String = null;
                _bundle2Js        = null;
                _cssLink          = cssLink;
                _project.Owner.Logger.Info("JS Bundle length: " + _bundleJs.Length + " SourceMap length: " +
                                           _sourceMapString.Length + " T:" +
                                           (DateTime.UtcNow - start).TotalMilliseconds.ToString("F0") + "ms");
            }

            _mainBuildResult.FilesContent.GetOrAddValueRef(_buildResult.BundleJsUrl)          = _bundleJs;
            _mainBuildResult.FilesContent.GetOrAddValueRef(_buildResult.BundleJsUrl + ".map") = _sourceMapString;
            if (incremental)
            {
                _mainBuildResult.FilesContent.GetOrAddValueRef(_versionDirPrefix + "bundle2.js")     = _bundle2Js;
                _mainBuildResult.FilesContent.GetOrAddValueRef(_versionDirPrefix + "bundle2.js.map") =
                    _sourceMap2String;
                SourceMaps = new Dictionary <string, SourceMap>
                {
                    { PathUtils.GetFile(_buildResult.BundleJsUrl), _sourceMap },
                    { "bundle2.js", _sourceMap2 }
                };
            }
            else
            {
                SourceMaps = new Dictionary <string, SourceMap>
                {
                    { PathUtils.GetFile(_buildResult.BundleJsUrl), _sourceMap }
                };
            }

            if (_project.SubProjects != null)
            {
                var newSubBundlers = new RefDictionary <string, FastBundleBundler>();
                foreach (var(projPath, subProject) in _project.SubProjects.OrderBy(a =>
                                                                                   a.Value?.Variant == "serviceworker"))
                {
                    if (subProject == null)
                    {
                        continue;
                    }
                    if (_subBundlers == null || !_subBundlers.TryGetValue(projPath, out var subBundler))
                    {
                        subBundler = new FastBundleBundler(_tools, _mainBuildResult, subProject,
                                                           _buildResult.SubBuildResults.GetOrFakeValueRef(projPath));
                    }

                    newSubBundlers.GetOrAddValueRef(projPath) = subBundler;
                    subBundler.Build(sourceRoot, false, false);
                }

                _subBundlers = newSubBundlers;
            }
            else
            {
                _subBundlers = null;
            }
        }
Пример #13
0
 public PlayerConnectionManager(ILogger logger, PlayerConnectionConfig playerConnectionConfig)
 {
     this._logger      = logger ?? throw new ArgumentNullException(nameof(logger));
     this._connections = new RefDictionary <PlayerId, PlayerConnection>(playerConnectionConfig.Capacity.InitialConnectionsCapacity);
 }
Пример #14
0
 internal Enumerator(RefDictionary <TKey, TValue> dict)
 {
     _dict    = dict;
     _index   = -1;
     _version = _dict._version;
 }
Пример #15
0
        public void Test()
        {
            var dict = new RefDictionary <int, DataStruct>(capacity: 1);

            Assert.Equal(0, dict.Count);

            dict.Add(0, new DataStruct {
                a = 0
            });
            dict.Add(1, new DataStruct {
                a = 1
            });
            dict.Add(2, new DataStruct {
                a = 2
            });

            Assert.Equal(3, dict.Count);
            Assert.Equal(0, dict[0].a);
            Assert.Equal(1, dict[1].a);
            Assert.Equal(2, dict[2].a);

            // Enumerator
            int count = 0;

            foreach (var item in dict)
            {
                Assert.Equal(count++, item.a);
            }

            dict.Remove(1);

            Assert.Equal(2, dict.Count);
            Assert.False(dict.ContainsKey(1));
            Assert.Throws <KeyNotFoundException>(() => dict[1]);

            dict.Add(11, new DataStruct {
                a = 3
            });

            Assert.Equal(3, dict.Count);

            dict.Remove(11);

            Assert.Equal(2, dict.Count);

            dict.Clear();

            Assert.Equal(0, dict.Count);

            dict.Add(3, new DataStruct {
                a = 3
            });
            dict.Add(4, new DataStruct {
                a = 4
            });

            Assert.Equal(2, dict.Count);
            Assert.Equal(3, dict[3].a);
            Assert.Equal(4, dict[4].a);

            ref var i3 = ref dict[3];
Пример #16
0
        static string LoadUsedFilesFromKvi(IKeyIndex keyIndex, FileCollectionWithFileInfos fcfi, uint fileId)
        {
            try
            {
                var file   = fcfi.GetFile(fileId);
                var reader = new SpanReader(file.GetExclusiveReader());
                FileKeyIndex.SkipHeader(ref reader);
                var keyCount    = keyIndex.KeyValueCount;
                var usedFileIds = new RefDictionary <uint, ulong>();
                if (keyIndex.Compression == KeyIndexCompression.Old)
                {
                    for (var i = 0; i < keyCount; i++)
                    {
                        var keyLength = reader.ReadVInt32();
                        reader.SkipBlock(keyLength);
                        var vFileId = reader.ReadVUInt32();
                        reader.SkipVUInt32();
                        var len = reader.ReadVInt32();
                        if (vFileId > 0)
                        {
                            usedFileIds.GetOrAddValueRef(vFileId) += (ulong)Math.Abs(len);
                        }
                    }
                }
                else
                {
                    if (keyIndex.Compression != KeyIndexCompression.None)
                    {
                        return("");
                    }
                    for (var i = 0; i < keyCount; i++)
                    {
                        reader.SkipVUInt32();
                        var keyLengthWithoutPrefix = (int)reader.ReadVUInt32();
                        reader.SkipBlock(keyLengthWithoutPrefix);
                        var vFileId = reader.ReadVUInt32();
                        reader.SkipVUInt32();
                        var len = reader.ReadVInt32();
                        if (vFileId > 0)
                        {
                            usedFileIds.GetOrAddValueRef(vFileId) += (ulong)Math.Abs(len);
                        }
                    }
                }

                var used = usedFileIds.OrderBy(a => a.Key).ToArray();
                var sb   = new StringBuilder();
                foreach (var keyValuePair in used)
                {
                    sb.Append("    in ");
                    sb.Append(keyValuePair.Key);
                    sb.Append(" used ");
                    sb.Append(keyValuePair.Value);
                    sb.Append('\n');
                }
                return(sb.ToString());
            }
            catch
            {
                // ignore
            }

            return("");
        }
Пример #17
0
 internal Enumerator(RefDictionary <TKey, TValue> dictionary)
 {
     _dictionary = dictionary;
     _index      = 0;
     Current     = default;
 }
Пример #18
0
        public void Build(bool compress, bool mangle, bool beautify, bool _, string?__)
        {
            var cssLink     = "";
            var cssToBundle = new List <SourceFromPair>();

            foreach (var source in _buildResult.Path2FileInfo.Values.OrderBy(f => f.Owner.FullPath).ToArray())
            {
                if (source.Type == FileCompilationType.Css || source.Type == FileCompilationType.ImportedCss)
                {
                    cssToBundle.Add(new SourceFromPair(source.Owner.Utf8Content, source.Owner.FullPath));
                }
                else if (source.Type == FileCompilationType.Resource)
                {
                    _mainBuildResult.FilesContent.GetOrAddValueRef(_buildResult.ToOutputUrl(source)) = source.Owner.ByteContent;
                }
            }

            if (cssToBundle.Count > 0)
            {
                string cssPath      = _mainBuildResult.AllocateName("bundle.css");
                var    cssProcessor = new CssProcessor(_project.Tools);
                var    cssContent   = cssProcessor.ConcatenateAndMinifyCss(cssToBundle, (string url, string from) =>
                {
                    var full         = PathUtils.Join(from, url);
                    var fullJustName = full.Split('?', '#')[0];
                    _buildResult.Path2FileInfo.TryGetValue(fullJustName, out var fileAdditionalInfo);
                    _mainBuildResult.FilesContent.GetOrAddValueRef(_buildResult.ToOutputUrl(fileAdditionalInfo)) =
                        fileAdditionalInfo.Owner.ByteContent;
                    return(PathUtils.GetFile(fileAdditionalInfo.OutputUrl) +
                           full.Substring(fullJustName.Length));
                }).Result;
                var cssImports = "";
                foreach (var match in Regex.Matches(cssContent, "@import .*;"))
                {
                    cssImports += match.ToString();
                    cssContent  = cssContent.Replace(match.ToString(), "");
                }

                _mainBuildResult.FilesContent.GetOrAddValueRef(cssPath) = cssImports + cssContent;
                cssLink += "<link rel=\"stylesheet\" href=\"" + cssPath + "\">";
            }

            if (_project.SpriteGeneration)
            {
                _bundlePng = _project.BundlePngUrl;
                var bundlePngContent = _project.SpriteGenerator.BuildImage(true);
                if (bundlePngContent != null)
                {
                    _bundlePngInfo = new List <float>();
                    foreach (var slice in bundlePngContent)
                    {
                        _mainBuildResult.FilesContent.GetOrAddValueRef(PathUtils.InjectQuality(_bundlePng, slice.Quality)) =
                            slice.Content;
                        _bundlePngInfo.Add(slice.Quality);
                    }
                }
                else
                {
                    _bundlePng = null;
                }
            }

            var bundler = new BundlerImpl(_tools);

            bundler.Callbacks = this;
            if ((_project.ExampleSources?.Count ?? 0) > 0)
            {
                bundler.MainFiles = new[] { _project.ExampleSources[0] };
            }
            else
            {
                bundler.MainFiles = new[] { _project.MainFile };
            }

            _mainJsBundleUrl = _buildResult.BundleJsUrl;
            bundler.Compress = compress;
            bundler.Mangle   = mangle;
            bundler.Beautify = beautify;
            bundler.Defines  = _project.BuildDefines(_mainBuildResult);
            bundler.Bundle();
            if (!_project.NoHtml)
            {
                BuildFastBundlerIndexHtml(cssLink);
                _mainBuildResult.FilesContent.GetOrAddValueRef("index.html") = _indexHtml;
            }

            if (_project.SubProjects != null)
            {
                var newSubBundlers = new RefDictionary <string, BundleBundler>();
                foreach (var(projPath, subProject) in _project.SubProjects.OrderBy(a => a.Value?.Variant == "serviceworker"))
                {
                    if (subProject == null)
                    {
                        continue;
                    }
                    if (_subBundlers == null || !_subBundlers.TryGetValue(projPath, out var subBundler))
                    {
                        subBundler = new BundleBundler(_tools, _mainBuildResult, subProject, _buildResult.SubBuildResults.GetOrFakeValueRef(projPath));
                    }

                    newSubBundlers.GetOrAddValueRef(projPath) = subBundler;
                    subBundler.Build(compress, mangle, beautify, false, null);
                }

                _subBundlers = newSubBundlers;
            }
            else
            {
                _subBundlers = null;
            }
        }
Пример #19
0
 public Enumerator(RefDictionary <uint, T> dict)
 => _dictEnumerator = dict.GetEnumerator();
Пример #20
0
 public IndexEnumerator(RefDictionary <TKey, TValue> owner)
 {
     _owner = owner;
 }