コード例 #1
0
        public static void RefreshModulesInfo(List<AssetInfo> infos, BuildArtifactsInfo artifactsInfo)
        {
            if (artifactsInfo.managedModules.Count <= 0)
                return;

            var modulesSuspects = infos.Where(x => x.path.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
                                    .ToLookup(x => ReliablePath.GetFileName(x.path));

            // add modules
            foreach (var kv in artifactsInfo.managedModules)
            {
                var existingEntries = modulesSuspects[kv.Key].ToList();
                if (existingEntries.Any())
                {
                    foreach (var entry in existingEntries)
                    {
                        entry.size += kv.Value.uncompressed;
                        UpdateCompressedSize(entry, kv.Value.compressed);
                    }
                }
                else
                {
                    var entry = new AssetInfo()
                    {
                        path = kv.Key,
                        size = kv.Value.uncompressed,
                    };
                    UpdateCompressedSize(entry, kv.Value.compressed);
                    infos.Add(entry);
                }
            }
        }
コード例 #2
0
        private static BuildArtifactsInfo CreateFromFileSystem(string totalSizeDir, string dataDirectory, string streamingAssetsName)
        {
            var modulesDirectory         = ReliablePath.Combine(dataDirectory, "Managed");
            var streamingAssetsDirectory = ReliablePath.Combine(dataDirectory, streamingAssetsName);

            Dictionary <string, SizePair> modules = new Dictionary <string, SizePair>();
            long runtimeSize = 0;

            if (Directory.Exists(modulesDirectory))
            {
                // dlls are included as assets, so don't count them as runtime size
                modules = Directory.GetFiles(modulesDirectory, "*.dll", SearchOption.TopDirectoryOnly)
                          .ToDictionary(x => ReliablePath.GetFileName(x), x => (SizePair)GetFileSizeNoThrow(x));

                runtimeSize = GetDirectorySizeNoThrow(modulesDirectory) - Enumerable.Sum(modules, x => x.Value.uncompressed);
            }

            var unityResources = s_unityResourcesNames
                                 .Select(x => new { Relative = x, Actual = ReliablePath.Combine(dataDirectory, x) })
                                 .Where(x => !Directory.Exists(x.Actual))
                                 .Select(x => new { x.Relative, File = new FileInfo(x.Actual) })
                                 .Where(x => x.File.Exists)
                                 .ToDictionary(x => x.Relative, x => (SizePair)x.File.Length);

            return(new BuildArtifactsInfo()
            {
                totalSize = GetDirectorySizeNoThrow(totalSizeDir),
                streamingAssetsSize = GetDirectorySizeNoThrow(streamingAssetsDirectory),
                runtimeSize = runtimeSize,
                managedModules = modules,
                unityResources = unityResources,
                sceneSizes = CalculateScenesSizes(x =>
                {
                    var fileInfo = new FileInfo(ReliablePath.Combine(dataDirectory, x));
                    if (!fileInfo.Exists)
                    {
                        return null;
                    }
                    return fileInfo.Length;
                })
            });
        }
コード例 #3
0
        private static BuildArtifactsInfo CreateForAndroid(string buildPath, bool hasObb)
        {
            Dictionary <string, SizePair> partialResults = new Dictionary <string, SizePair>();
            Dictionary <string, SizePair> managedModules = new Dictionary <string, SizePair>();
            Dictionary <string, SizePair> otherAssets    = new Dictionary <string, SizePair>();

            const string DataDirectory = "assets/bin/Data/";

            long compressedSize      = 0;
            long uncompressedSize    = 0;
            long streamingAssetsSize = 0;

            SizePair runtimeSize    = new SizePair();
            var      unityResources = new Dictionary <string, SizePair>();

            //var sources = Enumerable.Repeat(new { Source = "Apk", Files = GetFilesFromZipArchive(buildPath) }, 1);

            var sources = new List <KeyValuePair <string, string> >();

            sources.Add(new KeyValuePair <string, string>("Apk", buildPath));

            if (hasObb)
            {
                var obbPath = DropExtension(buildPath) + ".main.obb";
                sources.Add(new KeyValuePair <string, string>("Obb", obbPath));
            }

            foreach (var source in sources)
            {
                var path = source.Value;

                compressedSize += GetFileSizeNoThrow(path);

                //files = files.Concat(GetFilesFromZipArchive(obbPath));
                var files = GetFilesFromZipArchive(path);
                foreach (var entry in files)
                {
                    uncompressedSize += entry.size.uncompressed;

                    if (entry.path.StartsWith(DataDirectory))
                    {
                        var fileName = entry.path.Substring(DataDirectory.Length);
                        if (fileName.StartsWith("level") || fileName.StartsWith("mainData"))
                        {
                            partialResults.Add(fileName, entry.size);
                        }
                        else if (fileName.StartsWith("Managed/"))
                        {
                            // dlls are included as assets, so don't count them as a part of runtime
                            if (fileName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
                            {
                                var actualFileName = ReliablePath.GetFileName(fileName);
                                managedModules.Add(actualFileName, entry.size);
                            }
                            else
                            {
                                runtimeSize.compressed   += entry.size.compressed;
                                runtimeSize.uncompressed += entry.size.uncompressed;
                            }
                        }
                        else if (s_unityResourcesNames.Contains(fileName))
                        {
                            unityResources.Add(fileName, entry.size);
                        }
                        else
                        {
                            // is it a guid?
                            var justFileName = Path.GetFileNameWithoutExtension(fileName);
                            if (justFileName.Length == 32 && justFileName.All(x => char.IsDigit(x) || x >= 'a' && x <= 'f' || x >= 'A' && x <= 'F'))
                            {
                                SizePair existingEntry;
                                if (otherAssets.TryGetValue(justFileName, out existingEntry))
                                {
                                    otherAssets[justFileName] = new SizePair(existingEntry.compressed + entry.size.compressed, existingEntry.uncompressed + entry.size.uncompressed);
                                }
                                else
                                {
                                    otherAssets.Add(justFileName, entry.size);
                                }
                            }
                        }
                    }
                    else if (entry.path.StartsWith("assets/"))
                    {
                        streamingAssetsSize += entry.size.uncompressed;
                    }
                    else if (entry.path.StartsWith("lib/"))
                    {
                        runtimeSize.compressed   += entry.size.compressed;
                        runtimeSize.uncompressed += entry.size.uncompressed;
                    }
                }
            }

            var scenes = CalculateScenesSizes(x =>
            {
                SizePair result;
                if (partialResults.TryGetValue(x, out result))
                {
                    return(result);
                }
                return(null);
            });

            return(new BuildArtifactsInfo()
            {
                managedModules = managedModules,
                sceneSizes = scenes,
                streamingAssetsSize = streamingAssetsSize,
                totalSize = new SizePair(compressedSize, uncompressedSize),
                runtimeSize = runtimeSize,
                unityResources = unityResources,
                otherAssets = otherAssets,
            });
        }