Example #1
0
        public void OnPostprocessBuild(UnityEditor.Build.Reporting.BuildReport report)
        {
            if (!MobileBuildReportSettingsManager.settings.LabelBuildsEnabled)
            {
                return;
            }

            if (report.summary.result == BuildResult.Failed || report.summary.result == BuildResult.Cancelled ||
                (report.summary.platform != BuildTarget.Android && report.summary.platform != BuildTarget.iOS))
            {
                return;
            }

            var assetData = new MobileBuildReportBuildInfo(report.summary, report.packedAssets);

            if (!Directory.Exists(MobileBuildReportSettingsManager.settings.CacheLocation))
            {
                Directory.CreateDirectory(MobileBuildReportSettingsManager.settings.CacheLocation);
            }

            using (var stream = new FileStream(Path.Combine(MobileBuildReportSettingsManager.settings.CacheLocation, MobileBuildReportSettingsManager.settings.ReportHash), FileMode.Create))
            {
                var formatter = new BinaryFormatter();
                formatter.Serialize(stream, assetData);
            }

            if (report.summary.platform != BuildTarget.iOS)
            {
                return;
            }

            var hashPath = Path.Combine(report.summary.outputPath, "Data", MobileBuildReportSettingsManager.settings.HashFileName);

            CommonTools.WriteTextFile(MobileBuildReportSettingsManager.settings.ReportHash, hashPath);
        }
        private static void CollectArchiveData(string buildPath, out MobileBuildReport report, MobileBuildReportBuildInfo buildInfo)
        {
            report = new MobileBuildReport(buildInfo)
            {
                TotalSize = new FileInfo(buildPath).Length
            };
            report.PlatformData = s_PlatformUtilities.CollectPlatformData(buildPath);

            var temporaryDir = CommonTools.GetTemporaryDirectory();

            using (var archive = ZipFile.OpenRead(buildPath))
            {
                report.Files = new MobileBuildReportFile[archive.Entries.Count(x => x.Length > 0)];
                var i = 0;
                foreach (var file in archive.Entries)
                {
                    if (file.Length == 0)
                    {
                        continue;
                    }

                    report.Files[i] = new MobileBuildReportFile(file.FullName, file.CompressedLength, file.Length);
                    if (buildInfo.AssetPacks.Any(t => t.ShortPath == file.Name))
                    {
                        file.ExtractToFile(Path.Combine(temporaryDir, file.Name));
                    }
                    i++;
                }
            }
            s_PlatformUtilities.PrepareSharedAssets(temporaryDir);

            report.Assets = new MobileBuildReportAssets[buildInfo.AssetPacks.Length];
            for (var i = 0; i < buildInfo.AssetPacks.Length; i++)
            {
                report.Assets[i] = new MobileBuildReportAssets(buildInfo.AssetPacks[i])
                {
                    Contents = new MobileBuildReportAssetInfo[buildInfo.AssetPacks[i].PackInfos.Length]
                };
                for (var j = 0; j < buildInfo.AssetPacks[i].PackInfos.Length; j++)
                {
                    report.Assets[i].Contents[j] = new MobileBuildReportAssetInfo(buildInfo.AssetPacks[i].PackInfos[j]);
                }

                if ((buildInfo.Options & BuildOptions.CompressWithLz4) == 0 && (buildInfo.Options & BuildOptions.CompressWithLz4HC) == 0)
                {
                    EstimateAssetSize(buildInfo.AssetPacks[i], report.Assets[i], temporaryDir);
                }
            }

            Directory.Delete(temporaryDir, true);
        }