public void Cook(List <string> bundles) { AssetCache.Instance.Initialize(); CookingRulesMap = CookingRulesBuilder.Build(InputBundle, Target); LogText = ""; var allTimer = StartBenchmark( $"Asset cooking. Asset cache mode: {AssetCache.Instance.Mode}. Active platform: {Target.Platform}" + System.Environment.NewLine + DateTime.Now + System.Environment.NewLine ); PluginLoader.BeforeBundlesCooking(); var requiredCookCode = !The.Workspace.ProjectJson.GetValue <bool>("SkipCodeCooking"); var bundleBackups = new List <string>(); try { UserInterface.Instance.SetupProgressBar(CalculateOperationCount(bundles)); BeginCookBundles?.Invoke(); var assetsGroupedByBundles = GetAssetsGroupedByBundles(InputBundle.EnumerateFileInfos(), bundles); for (int i = 0; i < bundles.Count; i++) { var extraTimer = StartBenchmark(); CookBundle(bundles[i], assetsGroupedByBundles[i], bundleBackups); StopBenchmark(extraTimer, $"{bundles[i]} cooked: "); } var extraBundles = bundles.ToList(); extraBundles.Remove(CookingRulesBuilder.MainBundleName); extraBundles.Reverse(); PluginLoader.AfterBundlesCooked(extraBundles); if (requiredCookCode) { CodeCooker.Cook(Target, CookingRulesMap, bundles.ToList()); } StopBenchmark(allTimer, "All bundles cooked: "); PrintBenchmark(); } catch (System.Exception e) { Console.WriteLine(e.Message); RestoreBackups(bundleBackups); } finally { cookCanceled = false; RemoveBackups(bundleBackups); EndCookBundles?.Invoke(); UserInterface.Instance.StopProgressBar(); } }
public void SyncUpdated(string fileExtension, string bundleAssetExtension, Converter converter, Func <string, string, bool> extraOutOfDateChecker = null) { foreach (var fileInfo in InputBundle.EnumerateFileInfos(null, fileExtension)) { UserInterface.Instance.IncreaseProgressBar(); var srcPath = fileInfo.Path; var dstPath = Path.ChangeExtension(srcPath, bundleAssetExtension); var bundled = OutputBundle.FileExists(dstPath); var srcRules = CookingRulesMap[srcPath]; var needUpdate = !bundled || fileInfo.LastWriteTime != OutputBundle.GetFileLastWriteTime(dstPath); needUpdate = needUpdate || !srcRules.SHA1.SequenceEqual(OutputBundle.GetCookingRulesSHA1(dstPath)); needUpdate = needUpdate || (extraOutOfDateChecker?.Invoke(srcPath, dstPath) ?? false); if (needUpdate) { if (converter != null) { try { if (converter(srcPath, dstPath)) { Console.WriteLine((bundled ? "* " : "+ ") + dstPath); CookingRules rules = null; if (!string.IsNullOrEmpty(dstPath)) { CookingRulesMap.TryGetValue(dstPath, out rules); } PluginLoader.AfterAssetUpdated(OutputBundle, rules, dstPath); } } catch (System.Exception e) { Console.WriteLine( "An exception was caught while processing '{0}': {1}\n", srcPath, e.Message); throw; } } else { Console.WriteLine((bundled ? "* " : "+ ") + dstPath); using (var stream = InputBundle.OpenFile(srcPath)) { OutputBundle.ImportFile(dstPath, stream, 0, fileExtension, InputBundle.GetFileLastWriteTime(srcPath), AssetAttributes.None, CookingRulesMap[srcPath].SHA1); } } } } }
private int CalculateOperationCount(List <string> bundles) { var assetCount = 0; var assetsGroupedByBundles = GetAssetsGroupedByBundles(InputBundle.EnumerateFileInfos(), bundles); for (int i = 0; i < bundles.Count; i++) { var savedInputBundle = InputBundle; AssetBundle.SetCurrent( new CustomSetAssetBundle(InputBundle, assetsGroupedByBundles[i]), resetTexturePool: false); OutputBundle = CreateOutputBundle(bundles[i], bundleBackups: null); try { assetCount += CookStages.Sum(stage => stage.GetOperationCount()); } finally { OutputBundle.Dispose(); OutputBundle = null; AssetBundle.SetCurrent(savedInputBundle, resetTexturePool: false); } } return(assetCount); }
public void Update() { _inputs = new InputBundle(); }
public int GetUpdateOperationCount(string fileExtension) => InputBundle.EnumerateFileInfos(null, fileExtension).Count();
public void ImportTexture(string path, Bitmap texture, ICookingRules rules, DateTime time, byte[] CookingRulesSHA1) { var textureParamsPath = Path.ChangeExtension(path, ".texture"); var textureParams = new TextureParams { WrapMode = rules.WrapMode, MinFilter = rules.MinFilter, MagFilter = rules.MagFilter, }; if (!AreTextureParamsDefault(rules)) { TextureTools.UpscaleTextureIfNeeded(ref texture, rules, false); var isNeedToRewriteTexParams = true; if (OutputBundle.FileExists(textureParamsPath)) { var oldTexParams = InternalPersistence.Instance.ReadObjectFromBundle <TextureParams>(OutputBundle, textureParamsPath); isNeedToRewriteTexParams = !oldTexParams.Equals(textureParams); } if (isNeedToRewriteTexParams) { InternalPersistence.Instance.WriteObjectToBundle(OutputBundle, textureParamsPath, textureParams, Persistence.Format.Binary, ".texture", InputBundle.GetFileLastWriteTime(textureParamsPath), AssetAttributes.None, null); } } else { if (OutputBundle.FileExists(textureParamsPath)) { DeleteFileFromBundle(textureParamsPath); } } if (rules.GenerateOpacityMask) { var maskPath = Path.ChangeExtension(path, ".mask"); OpacityMaskCreator.CreateMask(OutputBundle, texture, maskPath); } var attributes = AssetAttributes.ZippedDeflate; if (!TextureConverterUtils.IsPowerOf2(texture.Width) || !TextureConverterUtils.IsPowerOf2(texture.Height)) { attributes |= AssetAttributes.NonPowerOf2Texture; } switch (Target.Platform) { case TargetPlatform.Android: //case TargetPlatform.iOS: var f = rules.PVRFormat; if (f == PVRFormat.ARGB8 || f == PVRFormat.RGB565 || f == PVRFormat.RGBA4) { TextureConverter.RunPVRTexTool(texture, OutputBundle, path, attributes, rules.MipMaps, rules.HighQualityCompression, rules.PVRFormat, CookingRulesSHA1, time); } else { TextureConverter.RunEtcTool(texture, OutputBundle, path, attributes, rules.MipMaps, rules.HighQualityCompression, CookingRulesSHA1, time); } break; case TargetPlatform.iOS: TextureConverter.RunPVRTexTool(texture, OutputBundle, path, attributes, rules.MipMaps, rules.HighQualityCompression, rules.PVRFormat, CookingRulesSHA1, time); break; case TargetPlatform.Win: case TargetPlatform.Mac: TextureConverter.RunNVCompress(texture, OutputBundle, path, attributes, rules.DDSFormat, rules.MipMaps, CookingRulesSHA1, time); break; default: throw new Lime.Exception(); } }