public static List <Tuple <string, AssetPointer> > GetPointers( Stream indexList, string[] packPaths, out bool compression) { AssetResult r = ParseResult(indexList); List <Tuple <string, AssetPointer> > assetList = new List <Tuple <string, AssetPointer> >(); for (int i = 0; i < r.IndexList.Count; i++) { if (r.IndexList[i].PackageType == AssetPackageType.Unpack) { Console.WriteLine("Skipping File Parsing"); continue; } assetList.Add( new Tuple <string, AssetPointer>( packPaths[GetId(packPaths, r.IndexList[i].PackageId)], r.IndexList[i] ) ); } compression = r.Compression; return(assetList); }
internal IEnumerator DownLoad() { mStatus = AssetStatus.Status_Loading; if (mCurWWW != null) { UnLoad(false); mCurWWW = null; } mCurWWW = new WWW(mAssetUrl); mCurWWW.threadPriority = mThreadPriority; yield return(mCurWWW); OnDonwloaded(); mIsDone = true; if (!string.IsNullOrEmpty(error)) { mResult = AssetResult.Result_Error; } else { mResult = AssetResult.Result_Succeed; } }
public static Dictionary <string, Tuple <int, MemoryStream> > UnpackAssets(Stream indexList, Stream[] packs) { AssetResult r = ParseResult(indexList); Dictionary <string, Tuple <int, MemoryStream> > assetList = new Dictionary <string, Tuple <int, MemoryStream> >(); for (int i = 0; i < r.IndexList.Count; i++) { if (r.IndexList[i].PackageType == AssetPackageType.Memory) { continue; } MemoryStream ms = new MemoryStream(r.IndexList[i].Length); byte[] buf = new byte[packs[r.IndexList[i].PackageId].Length]; packs[r.IndexList[i].PackageId].Position = r.IndexList[i].Offset; packs[r.IndexList[i].PackageId].Read(buf, 0, buf.Length); ms.Write(buf, 0, buf.Length); ms.Position = 0; assetList.Add(r.IndexList[i].Path, new Tuple <int, MemoryStream>(r.IndexList[i].Length, ms)); } for (int i = 0; i < packs.Length; i++) { packs[i].Close(); } indexList.Close(); return(assetList); }
PackAssets( string assetFolder, string outputFolder, AssetPackageInfo info, bool compression = false) // [...]/assets { AssetResult ret = new AssetResult(outputFolder); ret.Compression = compression; Uri assetPath = new Uri(assetFolder); foreach (KeyValuePair <string, AssetFileInfo> assetFileInfo in info.FileInfos) { Console.WriteLine("Checking Folder: " + assetFolder + " with pattern: " + assetFileInfo.Key); string[] files = Directory.GetFiles(assetFolder, assetFileInfo.Key, SearchOption.AllDirectories); AssetPackageType type = assetFileInfo.Value.PackageType; for (int i = 0; i < files.Length; i++) { Uri file = new Uri(files[i]); Uri packPath = assetPath.MakeRelativeUri(file); ret.AddFile(files[i], packPath.ToString(), type); } } return(ret); }
public TagElement(AssetResult result, string value, SerializableHashSet <string> values) { _assetResult = result; _value = value; _values = values; var visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Packages/org.visualpinball.engine.unity/VisualPinball.Unity/VisualPinball.Unity.Editor/AssetBrowser/TagElement.uxml"); var ui = visualTree.CloneTree(); var styleSheet = AssetDatabase.LoadAssetAtPath <StyleSheet>("Packages/org.visualpinball.engine.unity/VisualPinball.Unity/VisualPinball.Unity.Editor/AssetBrowser/TagElement.uss"); ui.styleSheets.Add(styleSheet); Add(ui); _displayElement = ui.Q <VisualElement>("display"); _editElement = ui.Q <VisualElement>("edit"); _nameElement = ui.Q <Label>("attribute-name"); _nameEditElement = ui.Q <SearchSuggest>("attribute-name-edit"); ui.Q <Button>("okButton").RegisterCallback <MouseUpEvent>(_ => CompleteEdit(true, _nameEditElement.Value)); ui.Q <Button>("cancelButton").RegisterCallback <MouseUpEvent>(_ => ToggleEdit()); _displayElement.RegisterCallback <MouseDownEvent>(OnNameClicked); if (!_assetResult.Library.IsLocked) { _nameEditElement.RegisterKeyDownCallback(evt => OnKeyDown(evt, _nameEditElement)); // right-click menu _displayElement.AddManipulator(new ContextualMenuManipulator(AddContextMenu)); } Update(); RegisterCallback <AttachToPanelEvent>(OnAttached); }
private static AssetResult ParseResult(Stream s) { XmlSerializer xs = new XmlSerializer(typeof(AssetResult)); AssetResult ret = (AssetResult)xs.Deserialize(s); s.Close(); return(ret); }
public KeyValueElement(AssetResult result, LibraryKeyValue keyValue, bool isLink) { _assetResult = result; _keyValue = keyValue; var visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Packages/org.visualpinball.engine.unity/VisualPinball.Unity/VisualPinball.Unity.Editor/AssetBrowser/KeyValueElement.uxml"); var ui = visualTree.CloneTree(); var styleSheet = AssetDatabase.LoadAssetAtPath <StyleSheet>("Packages/org.visualpinball.engine.unity/VisualPinball.Unity/VisualPinball.Unity.Editor/AssetBrowser/KeyValueElement.uss"); ui.styleSheets.Add(styleSheet); Add(ui); _displayElement = ui.Q <VisualElement>("display"); _displayLinkElement = ui.Q <VisualElement>("display-link"); _editElement = ui.Q <VisualElement>("edit"); _nameElement = ui.Q <Label>("attribute-name"); _linkElement = ui.Q <Label>("attribute-link"); _valuesElement = ui.Q <VisualElement>("attribute-values"); _nameEditElement = ui.Q <SearchSuggest>("attribute-name-edit"); _valuesEditElement = ui.Q <SearchSuggest>("attribute-value-edit"); ui.Q <Button>("okButton").RegisterCallback <MouseUpEvent>(_ => CompleteEdit(true, _nameEditElement.Value, _valuesEditElement.Value)); ui.Q <Button>("cancelButton").RegisterCallback <MouseUpEvent>(_ => CompleteEdit(false)); _isLink = isLink; DisplayContainer.RemoveFromClassList("hidden"); DisplayContainer.RegisterCallback <MouseDownEvent>(OnNameClicked); if (!_assetResult.Library.IsLocked) { _nameEditElement.RegisterKeyDownCallback(evt => OnKeyDown(evt, _nameEditElement)); _valuesEditElement.RegisterKeyDownCallback(evt => OnKeyDown(evt, _valuesEditElement)); if (!_isLink) { _valuesEditElement.IsMultiValue = true; } // right-click menu DisplayContainer.AddManipulator(new ContextualMenuManipulator(AddContextMenu)); } RegisterCallback <AttachToPanelEvent>(OnAttached); }
public static void PackAssets(string outputFolder, int packSize, string memoryFileExts, string unpackedFileExts, string assetFolder, bool compression) { AssetPacker.MaxsizeKilobytes = packSize; Console.WriteLine("Parsing File info..."); AssetPackageInfo info = CreatePackageInfo(memoryFileExts, unpackedFileExts); Console.WriteLine("Creating Asset Pack(" + assetFolder + ")..."); AssetResult ret = AssetPacker.PackAssets(assetFolder, outputFolder, info, compression); Console.WriteLine("Packaging " + ret.IndexList.Count + " Assets in " + ret.Packs.Count + " Packs."); Console.WriteLine("Saving Asset Pack to " + outputFolder); ret.Save(); Console.WriteLine("Packaging Assets Finished."); }
public void Reset() { m_init = false; m_curWWW = null; m_loaded = false; m_unloadCompress = false; m_unLoaded = false; m_isDone = false; m_assetBundle = null; m_assetUrl = null; m_result = AssetResult.Result_Succeed; m_refCount = 0; m_loadObjects = null; m_mainObject = null; m_threadPriority = ThreadPriority.Normal; m_assetType = AssetType.Asset_AssetBundle; m_bAllowDelete = false; m_params.Clear(); }
public void Reset() { mInit = false; mCurWWW = null; mLoaded = false; mUnloadCompress = false; mUnLoaded = false; mIsDone = false; mAssetBundle = null; mAssetUrl = null; mResult = AssetResult.Result_Succeed; mRefCount = 0; mLoadObjects = null; mMainObject = null; mThreadPriority = ThreadPriority.Normal; mAssetType = AssetType.AssetType_AssetBundle; mAssetSize = 0; mbAllowDelete = false; mParams.Clear(); }
private async Task MinifyAssets(string pageName) { string role = UsersRoles; SettingHelper settingHelper = new SettingHelper(_cache); string fileName = role.Replace(" ", "_") + "_" + pageName; string headerCSS = "css_" + fileName; string headerJS = "jsHeader_" + fileName; string footerJS = "jsFooter_" + fileName; string rootPath = _env.WebRootPath; string cssLink = string.Empty; string jsScriptHeader = string.Empty; string jsScriptFooter = string.Empty; bool optimizeAssets = settingHelper.GetCachedSettingBoolValue(SettingKeys.OptimizeAssets); if (optimizeAssets) { string optimizecssFilePath = ShorternPath(Path.Combine(FolderName.Optimize, headerCSS + cssExtension)); string optimizeJsTopFilePath = ShorternPath(Path.Combine(FolderName.Optimize, headerJS + jsExtension)); string optimizeJsFilePath = ShorternPath(Path.Combine(FolderName.Optimize, footerJS + jsExtension)); BundleController bundleController = new BundleController(); if (File.Exists(Path.Combine(_env.WebRootPath, optimizecssFilePath))) { AssetCollection assetCollection = await bundleController.GetAssetCollection(pageName, role); cssLink = assetCollection.CssLink; jsScriptHeader = assetCollection.JSHeaderLink; jsScriptFooter = assetCollection.JSFooterLink; } else { if (excessMode == ExcessModes.local) { DeleteFile(optimizecssFilePath); DeleteFile(optimizeJsTopFilePath); DeleteFile(optimizeJsFilePath); } if (!Directory.Exists(Path.Combine(rootPath, FolderName.Optimize))) { Directory.CreateDirectory(Path.Combine(rootPath, FolderName.Optimize)); } AssetResult assetResult = await GetFileList(pageName, role); Task <bool> bundlejsTop = BundleAsset(optimizeJsTopFilePath, assetResult.JSHeader, AssetType.Js); Task <bool> bundlejsFooterTop = BundleAsset(optimizeJsFilePath, assetResult.JSFooter, AssetType.Js); Task <bool> bundleCss = BundleAsset(optimizecssFilePath, assetResult.CSS, AssetType.Css); await Task.WhenAll(bundlejsTop, bundlejsFooterTop, bundleCss); jsScriptHeader = assetResult.JsHeaderCDN; jsScriptHeader += string.Format("<script src='{0}'></script>", _hostURL + "/" + optimizeJsTopFilePath.Replace("\\", "/")); jsScriptFooter = assetResult.JsFooterTopCDN; jsScriptFooter += string.Format("<script src='{0}'></script>", _hostURL + "/" + optimizeJsFilePath.Replace("\\", "/")); jsScriptFooter += assetResult.JsFooterBottomCDN; cssLink = assetResult.CssCDN; cssLink += string.Format("<link href='{0}' rel='stylesheet' type='text/css' />", _hostURL + "/" + optimizecssFilePath.Replace("\\", "/")); AssetCollection assetCollection = new AssetCollection() { PageName = pageName, RoleName = role, CssLink = cssLink, JSHeaderLink = jsScriptHeader, JSFooterLink = jsScriptFooter, Name = string.Empty }; await bundleController.SaveAssetCollection(assetCollection); } } else { AssetResult assetCollection = await GetFileList(pageName, role); jsScriptHeader = assetCollection.JsHeaderCDN + CombineLinks(assetCollection.JSHeader, AssetType.Js); jsScriptFooter = assetCollection.JsFooterTopCDN + CombineLinks(assetCollection.JSFooter, AssetType.Js) + assetCollection.JsFooterBottomCDN; cssLink = assetCollection.CssCDN + CombineLinks(assetCollection.CSS, AssetType.Css); } TempData["cssHeader"] = cssLink; TempData["jsHeader"] = jsScriptHeader; TempData["jsFooter"] = jsScriptFooter; }
private async Task <AssetResult> GetFileList(string pageName, string role) { List <string> jsFilePaths = new List <string>(); List <string> cssFilePaths = new List <string>(); List <BundleAsset> objLocatedAssets = new List <BundleAsset>(); //get all the items from the httpContext IDictionary <object, object> items = HttpContext.Items; foreach (KeyValuePair <object, object> item in items) { if (item.Key.ToString().Contains("_jsPlacement")) { AssetLocation assetLocation = (AssetLocation)item.Value; objLocatedAssets.Add(new BundleAsset() { Position = assetLocation.Position, AssetType = AssetType.Js, IsExternal = false, FilePath = assetLocation.FilePath }); } else if (item.Key.ToString().Contains("_cssPlacement")) { AssetLocation assetLocation = (AssetLocation)item.Value; objLocatedAssets.Add(new BundleAsset() { Position = assetLocation.Position, AssetType = AssetType.Css, IsExternal = false, FilePath = assetLocation.FilePath }); } else if (item.Key.ToString().Contains("_js")) { string url = item.Value.ToString(); if (!jsFilePaths.Contains(url)) { jsFilePaths.Add(url); } } else if (item.Key.ToString().Contains("_css")) { string url = item.Value.ToString(); if (!cssFilePaths.Contains(url)) { cssFilePaths.Add(url); } } } List <BundleAsset> objBundleList = (List <BundleAsset>) await AssestsList(pageName, role); objBundleList.AddRange(objLocatedAssets); string cssCDN = string.Empty; string jsHeaderCDN = string.Empty; string jsFooterTopCDN = string.Empty; string jsFooterBottomCDN = string.Empty; List <string> cssTop = new List <string>(); List <string> cssBottom = new List <string>(); List <string> jsHeader = new List <string>(); List <string> jsHeaderBottom = new List <string>(); List <string> jsFooterTop = new List <string>(); List <string> jsFooterBottom = new List <string>(); foreach (BundleAsset bundle in objBundleList) { if (bundle.AssetType == AssetType.Css) { if (bundle.IsExternal) { cssCDN += string.Format("<link href='{0}' rel='stylesheet' type='text/css' />", bundle.FilePath); } else { switch (bundle.Position) { case AssetPosition.HeaderTop: cssTop.Add(bundle.FilePath); break; case AssetPosition.HeaderBottom: cssBottom.Add(bundle.FilePath); break; } } } else { if (bundle.IsExternal) { string link = string.Format("<script src='{0}'></script>", bundle.FilePath); switch (bundle.Position) { case AssetPosition.Header: jsHeaderCDN += link; break; case AssetPosition.FooterTop: jsFooterTopCDN += link; break; case AssetPosition.FooterBottom: jsFooterBottomCDN += link; break; } } else { switch (bundle.Position) { case AssetPosition.Header: jsHeader.Add(bundle.FilePath); break; case AssetPosition.HeaderBottom: jsHeaderBottom.Add(bundle.FilePath); break; case AssetPosition.FooterTop: jsFooterTop.Add(bundle.FilePath); break; case AssetPosition.FooterBottom: jsFooterBottom.Add(bundle.FilePath); break; } } } } cssTop.AddRange(cssFilePaths); cssTop.AddRange(cssBottom); jsHeader.AddRange(jsHeaderBottom); jsFooterTop.AddRange(jsFilePaths); jsFooterTop.AddRange(jsFooterBottom); AssetResult assetCollection = new AssetResult() { CSS = cssTop, JSHeader = jsHeader, JSFooter = jsFooterTop, CssCDN = cssCDN, JsHeaderCDN = jsHeaderCDN, JsFooterTopCDN = jsFooterTopCDN, JsFooterBottomCDN = jsFooterBottomCDN }; return(assetCollection); }
protected AssetResult ListAssets(GridModel model, AssetSearch search) { var response = new AssetResult(); ExecuteReader("r_Asset_List", delegate(SqlCommand sqlCommand) { if (search != null) { if (!string.IsNullOrEmpty(search.Id)) { sqlCommand.Parameters.AddWithValue("@Id", search.Id); } if (search.Status != 0) { sqlCommand.Parameters.AddWithValue("@status", search.Status); } if (!string.IsNullOrEmpty(search.Name)) { sqlCommand.Parameters.AddWithValue("@name", search.Name); } if (!string.IsNullOrEmpty(search.CreateDate)) { sqlCommand.Parameters.AddWithValue("@From", DateTime.Parse(search.CreateDate)); sqlCommand.Parameters.AddWithValue("@To", DateTime.Parse(search.CreateDate).AddHours(23).AddMinutes(59)); } if (!string.IsNullOrEmpty(search.TagId)) { sqlCommand.Parameters.AddWithValue("@TagId", search.TagId); } if (model.iSortCol_0 != 0) { model.iSortCol_0--; } switch (model.SortingDirection) { case SortDirection.Undefiened: sqlCommand.Parameters.AddWithValue("@sortColumn", 4); sqlCommand.Parameters.AddWithValue("@SortDirection", 1); break; case SortDirection.Ascending: sqlCommand.Parameters.AddWithValue("@sortColumn", model.iSortCol_0); sqlCommand.Parameters.AddWithValue("@SortDirection", 0); break; case SortDirection.Descending: sqlCommand.Parameters.AddWithValue("@sortColumn", model.iSortCol_0); sqlCommand.Parameters.AddWithValue("@SortDirection", 1); break; default: break; } } var pageSize = model == null ? 10 : ((model.iDisplayLength == 0) ? 10 : model.iDisplayLength); var PageNumber = model == null ? 1 : ((model.iDisplayStart == 0) ? 1 : model.iDisplayStart) / pageSize + 1; sqlCommand.Parameters.AddWithValue("@pageSize", pageSize); sqlCommand.Parameters.AddWithValue("@PageNumber", PageNumber); }, delegate(SqlDataReader reader) { while (reader.Read()) { response.Assets.Add(new AssetListModel { Id = reader.GetInt32(0), AID = reader.GetString(1), Name = reader.GetString(2), Status = (AssetStatus)reader.GetInt32(3), TagId = reader.IsDBNull(4) ? string.Empty : reader.GetString(4), CreateDate = reader.GetDateTime(5), ImagePath = reader.IsDBNull(6)?string.Empty: reader.GetString(6), Category = reader.GetString(7), Department = reader.IsDBNull(8) ? string.Empty : reader.GetString(8), Type = reader.GetString(9), Cost = reader.GetDecimal(10), PurchaseDate = reader.IsDBNull(11) ? DateTime.MinValue : reader.GetDateTime(11), Location = reader.IsDBNull(12) ? string.Empty : reader.GetString(12) }); } if (reader.NextResult() && reader.Read()) { response.RowsCount = reader.GetInt32(0); } }); return(response); }