/// <summary> /// /// </summary> /// <param name="path"></param> /// <returns></returns> string GetRealAssetFileName(string assetPath) { if (string.IsNullOrWhiteSpace(assetPath)) { throw new ArgumentException("Asset path can not be null, empty or whitespace."); } // take characters until dash '|' : assetPath = new string( assetPath.TakeWhile(ch => ch != '|').ToArray()); return(Path.Combine(contentDirectory, ContentUtils.GetHashedFileName(assetPath, ".asset"))); }
/// <summary> /// Generates /// </summary> /// <param name="key">unique key string value</param> /// <param name="ext">Desired extension with leading dot</param> /// <param name="resolve">Whether returned path is resolved relative to current directory</param> /// <returns></returns> public string GetTempFileName(string key, string ext, bool resolve) { var di = Directory.CreateDirectory(Path.Combine(contentFolder, "Temp")); di.Attributes = FileAttributes.Directory | FileAttributes.Hidden; var fileName = ContentUtils.CalculateMD5Hash(key.ToLower(), true); if (resolve) { return(Path.Combine(contentFolder, "Temp", fileName) + ext); } else { return(Path.Combine("Temp", fileName) + ext); } }
/// <summary> /// Builds assets. /// </summary> /// <param name="forced">Force asset to be rebuilt</param> /// <param name="sourceDirectory">Directory to get resources from</param> /// <param name="targetDirectory">Directory to put built assets to</param> /// <param name="message">Output message</param> /// <param name="selection">Can be null. List of assets to build.</param> /// <returns></returns> public bool Build(bool forced, string sourceDirectory, string targetDirectory, out string message, IEnumerable <string> selection) { int succeeded = 0; int failed = 0; Log.Message("---------- Content Build Started ----------"); HashSet <string> selectedNames = null; if (selection != null) { selectedNames = new HashSet <string>(selection.Select(n => ContentUtils.GetHashedFileName(n, ""))); } // // Check hash collisions : // var collisions = GetHashCollisions(); if (collisions.Any()) { Log.Warning("Detected asset hash collisions:"); foreach (var c in collisions) { Log.Warning(" {0}", c); } } else { Log.Message("Hash collisions are not detected."); } // // Start build : // var errors = new StringBuilder("Build failed:\r\n"); // make directories : Directory.CreateDirectory(targetDirectory); // create build context : var buildContext = new BuildContext(sourceDirectory, targetDirectory, this); // build items : for (int i = 0; i < Count; i++) { var asset = this[i]; if (selectedNames != null) { if (!selectedNames.Contains(asset.Hash)) { continue; } } try { if (buildContext.IsOutOfDate(asset, forced)) { Log.Message("...building: {0}", asset.AssetPath); asset.Build(buildContext); } succeeded++; } catch (AggregateException ae) { foreach (var e in ae.InnerExceptions) { Log.Error("{0}: {1}", asset.AssetPath, e.Message); errors.AppendFormat("{0}: {1}", asset.AssetPath, e.Message); errors.AppendFormat("\r\n"); } failed++; } catch (Exception e) { Log.Error("{0}: {1}", asset.AssetPath, e.Message); errors.AppendFormat("{0}: {1}", asset.AssetPath, e.Message); errors.AppendFormat("\r\n"); failed++; } } Log.Message("---------- Build: {0} succeeded, {1} failed ----------", succeeded, failed); if (failed == 0) { message = string.Format("Build: {0} succeeded, {1} failed", succeeded, failed); return(true); } else { message = string.Format("Build: {0} succeeded, {1} failed\r\n", succeeded, failed) + errors.ToString(); return(false); } }