static List<BuildReportTool.SizePart> ParseAssetSizesFromEditorLog(string editorLogPath, string[] prefabsUsedInScenes)
{
List<BuildReportTool.SizePart> assetSizes = new List<BuildReportTool.SizePart>();
Dictionary<string, bool> prefabsInBuildDict = new Dictionary<string, bool>();
const string ASSET_SIZES_KEY = "Used Assets, sorted by uncompressed size:";
foreach (string line in DldUtil.BigFileReader.ReadFile(_lastEditorLogPath, ASSET_SIZES_KEY))
{
if (string.IsNullOrEmpty(line) || line == "\n" || line == "\r\n")
{
break;
}
if (line.IndexOf(ASSET_SIZES_KEY) != -1)
{
continue;
}
Match match = Regex.Match(line, @"^ [0-9].*[a-z0-9) ]$", RegexOptions.IgnoreCase);
if (match.Success)
{
// it's an asset entry. parse it
//string b = match.Groups[0].Value;
string gotName = "???";
string gotSize = "?";
string gotPercent = "?";
match = Regex.Match(line, @"Assets/.+", RegexOptions.IgnoreCase);
if (match.Success)
{
gotName = match.Groups[0].Value;
gotName = gotName.Trim();
//Debug.Log(" name? " + gotName);
}
else
{
match = Regex.Match(line, @"Built-in.+:.+", RegexOptions.IgnoreCase);
if (match.Success)
{
gotName = match.Groups[0].Value;
gotName = gotName.Trim();
//Debug.Log(" built-in?: " + gotName);
}
}
match = Regex.Match(line, @"[0-9.]+ (kb|mb|b|gb)", RegexOptions.IgnoreCase);
if (match.Success)
{
gotSize = match.Groups[0].Value.ToUpper();
//Debug.Log(" size? " + gotSize);
}
else
{
Debug.Log("didn't find size for :" + line);
}
match = Regex.Match(line, @"[0-9.]+%", RegexOptions.IgnoreCase);
if (match.Success)
{
gotPercent = match.Groups[0].Value;
gotPercent = gotPercent.Substring(0, gotPercent.Length-1);
//Debug.Log(" percent? " + gotPercent);
}
else
{
Debug.Log("didn't find percent for :" + line);
}
//Debug.Log("got: " + gotName + " size: " + gotSize);
BuildReportTool.SizePart inPart = new BuildReportTool.SizePart();
inPart.Name = System.Security.SecurityElement.Escape(gotName);
inPart.Size = gotSize;
inPart.SizeBytes = -1;
inPart.DerivedSize = BuildReportTool.Util.GetApproxSizeFromString(gotSize);
inPart.Percentage = Double.Parse(gotPercent);
assetSizes.Add(inPart);
if (gotName.EndsWith(".prefab"))
{
prefabsInBuildDict.Add(gotName, false);
}
}
else
{
break;
}
}
// include prefabs that are instantiated in scenes (they are not by default)
//Debug.Log("addInfo.PrefabsUsedInScenes: " + addInfo.PrefabsUsedInScenes.Length);
foreach (string p in prefabsUsedInScenes)
{
if (p.IndexOf("/Resources/") != -1) continue; // prefabs in resources folder are already included in the editor log build info
if (prefabsInBuildDict.ContainsKey(p)) continue; // if already in assetSizes, continue
BuildReportTool.SizePart inPart = new BuildReportTool.SizePart();
inPart.Name = p;
inPart.Size = "N/A";
inPart.Percentage = -1;
//Debug.Log(" prefab added in used assets: " + p);
assetSizes.Add(inPart);
}
return assetSizes;
}