public bool CheckCachedResource(string fullPathInResources) { string key = CFileManager.EraseExtension(fullPathInResources).ToLower(); CResource resource = null; return(this.m_cachedResourceMap.TryGetValue(key, out resource)); }
/// <summary>Вычисление выражения.</summary> /// <typeparam name="T">тип результата вычисления выражения</typeparam> /// <param name="x_sTerm">выражение</param> /// <returns>результат вычисления выражения</returns> public T EvaluateTerm <T>(string x_sTerm) { // Компиляция сборки, содержащей класс с единственным методом, возвращающим результат вычисления выражения. CompilerResults c_crAssembly = CodeDomProvider.CreateProvider("c#").CompileAssemblyFromSource( new CompilerParameters(new string[] { "mscorlib.dll" }) { GenerateInMemory = true }, String.Format( n_sTemplate_AssemblyContent, n_sDefault_ClassName, n_sDefault_MethodName, x_sTerm)); // Проверка ошибок при компиляции сборки. if (c_crAssembly.Errors.HasErrors) { #region Формирование сообщения об ошибке компиляции StringBuilder c_sbErrors = new StringBuilder(); foreach (CompilerError c_eError in c_crAssembly.Errors) { c_sbErrors.AppendLine(c_eError.ErrorText); } throw new ArgumentException( String.Format( CResource.LoadString("IDS_ERR_COMPILERERROR"), x_sTerm, c_sbErrors.ToString()), "x_sExpression"); #endregion } // Выполнение метода, возвращающего результат вычисления выражения. return((T)c_crAssembly.CompiledAssembly.GetType(n_sDefault_ClassName).GetMethod(n_sDefault_MethodName).Invoke(null, null)); }
public CResource GetResource(string fullPathInResources, System.Type resourceContentType, enResourceType resourceType, bool needCached = false, bool unloadBelongedAssetBundleAfterLoaded = false) { if (string.IsNullOrEmpty(fullPathInResources)) { return(new CResource(string.Empty, string.Empty, null, resourceType, unloadBelongedAssetBundleAfterLoaded)); } string key = CFileManager.EraseExtension(fullPathInResources).ToLower(); CResource resource = null; if (this.m_cachedResourceMap.TryGetValue(key, out resource)) { if (resource.m_resourceType != resourceType) { resource.m_resourceType = resourceType; } return(resource); } resource = new CResource(key, fullPathInResources, resourceContentType, resourceType, unloadBelongedAssetBundleAfterLoaded); this.LoadResource(resource); if (needCached) { this.m_cachedResourceMap.Add(key, resource); } return(resource); }
/// <summary>Формирование строки с названием месяца.</summary> /// <param name="x_lMonth">индекс месяца. Замечание: месяцы нумеруются начиная с 1.</param> /// <returns>строка с названием месяца.</returns> public static string GetMonth(long x_lMonth) { string[] c_sMonths = new string[] { CResource.LoadString("IDS_VAL_JANUARY"), CResource.LoadString("IDS_VAL_FEBRUARY"), CResource.LoadString("IDS_VAL_MARCH"), CResource.LoadString("IDS_VAL_APRIL"), CResource.LoadString("IDS_VAL_MAY"), CResource.LoadString("IDS_VAL_JUNE"), CResource.LoadString("IDS_VAL_JULY"), CResource.LoadString("IDS_VAL_AUGUST"), CResource.LoadString("IDS_VAL_SEPTEMBER"), CResource.LoadString("IDS_VAL_OCTOBER"), CResource.LoadString("IDS_VAL_NOVEMBER"), CResource.LoadString("IDS_VAL_DECEMBER") }; if ((x_lMonth >= 1) && (x_lMonth <= 12)) { return(c_sMonths[x_lMonth - 1]); } else { throw new ArgumentException( CResource.LoadString(String.Format("IDS_ERR_MONTHOUTOFRANGE", x_lMonth)), "x_lMonth"); } }
/* - Info * Region for creating the finished CResource * from the data held in the buffers that tables 5 and 7 point to. * Table 5 - List of objects that together make a Single CResource object and * all the CObjects the are referenced by it. * Table 7 - List of embedded CR2W files that the main CResource can use * * TODO - Come up with an elegant solution to hold the emebedded files. * Option 1: Parse each as a new CResource and return each one with the main as a list. * Option 2: Parse each as a new CResource and store with the main one. * Option 3: Do not parse but just hold as a byte array until the user needs to change stuff. * Option 4: Export as a new CR2W physical file that can be later parsed. */ //TO BE IMPROVED public CResource CreateResource() { var temp = objects[0]; var type = names[temp.typeID]; Type resType = Type.GetType($"CR2W.Types.W3.{type}"); if (resType == null) { throw new UnknownObjectTypeException($"[UNKOWN TYPE] {type} could not be found"); } if (!resType.IsSubclassOf(typeof(CResource))) { throw new InvalidOperationException($"[UNSUPPORTED TYPE] {type} is not a CResource"); } BaseStream.Seek(temp.offset, SeekOrigin.Begin); CResource resource = (CResource)Activator.CreateInstance(resType); resource.Flags = temp.flags; resource.Template = temp.template; resource.ParseBytes(this, temp.size); return(resource); }
private void InitConfig() { CResource resource = Singleton <CResourceManager> .GetInstance().GetResource("Config/ParticleLimit", typeof(TextAsset), enResourceType.Numeric, false, true); if (resource == null) { return; } CBinaryObject cBinaryObject = resource.m_content as CBinaryObject; if (null == cBinaryObject) { return; } string text = StringHelper.ASCIIBytesToString(cBinaryObject.m_data); string[] array = text.Split(new char[] { '\r', '\n' }); array = Array.FindAll <string>(array, (string x) => !string.IsNullOrEmpty(x)); for (int i = 0; i < array.Length; i++) { string text2 = array[i]; if (!string.IsNullOrEmpty(text2)) { text2 = text2.Trim(); if (text2.Contains("//")) { text2 = text2.Substring(0, text2.IndexOf("//")); } text2 = text2.Trim(); if (!string.IsNullOrEmpty(text2)) { string[] array2 = text2.Split(new char[] { ':' }); if (array2 == null || array2.Length != 2) { return; } int[] array3 = new int[2]; for (int j = 0; j < array2.Length; j++) { array3[j] = Mathf.Abs(int.Parse(array2[j])); } if (array3[0] != 0 && array3[0] != 1) { return; } this.LIMIT_CONFIG[i] = array3[1]; } } } }
/// <summary>Удаление тега из списка.</summary> /// <param name="x_stTag">тег</param> /// <remarks>Перед удалением тег переводится в нижний регистр с удалением начальных и конечных знаков пробела.</remarks> public void DetachTag(string x_sTag) { if (String.IsNullOrEmpty(x_sTag)) { throw new ArgumentException( CResource.LoadString("IDS_ERR_EMPTYTAGAVLUE"), "x_sTag"); } m_hsTags.Remove(x_sTag.ToLower().Trim()); }
public static CActorInfo GetActorInfo(string path, enResourceType resourceType) { CResource resource = Singleton <CResourceManager> .GetInstance().GetResource(path, typeof(CActorInfo), resourceType, false, false); if (resource == null) { return(null); } return(resource.m_content as CActorInfo); }
public static CR2WFile FromCResource(this CR2WFile file, CResource res, bool cooked = false) { // checks to see if the variable from which the chunk is built is properly constructed if (res == null || res.REDName != res.REDType || res.ParentVar != null) { throw new NotImplementedException(); } file.CreateChunk(res); return(file); }
//* -----------------------------------------------------------------------* /// <summary>リソースを読み出し・登録します。</summary> /// <remarks> /// <paramref name="mgrContent"/>に<c>null</c>を指定すると /// 登録のみで実際の読み出しは<c>reload</c>を呼び出したときに行われます。 /// </remarks> /// /// <param name="strAsset">アセット名文字列</param> /// <param name="mgrContent">コンテンツマネージャ</param> public CResource <_T> load(string strAsset, ContentManager mgrContent) { CResource <_T> resource = new CResource <_T>(); resource.asset = strAsset; if (mgrContent != null) { resource.load(true, mgrContent); } resources.AddLast(resource); return(resource); }
public void Test01() { for (; ;) { DDCurtain.DrawCurtain(); DDDraw.DrawSimple(CResource.GetPicture(@"CResource\Picture\Picture0001.png"), 0, 0); DDDraw.DrawSimple(CResource.GetPicture(@"CResource\Picture\Picture0002.png"), 200, 0); DDDraw.DrawSimple(CResource.GetPicture(@"CResource\Picture\Picture0003.png"), 400, 0); DDEngine.EachFrame(); } }
private void InitConfig() { CResource resource = Singleton <CResourceManager> .GetInstance().GetResource("Config/ParticleLimit", typeof(TextAsset), enResourceType.Numeric, false, true); if (resource != null) { CBinaryObject content = resource.m_content as CBinaryObject; if (null != content) { char[] separator = new char[] { '\r', '\n' }; foreach (string str2 in StringHelper.UTF8BytesToString(ref content.m_data).Split(separator)) { if (!string.IsNullOrEmpty(str2)) { str2 = str2.Trim(); if (str2.Contains("//")) { str2 = str2.Substring(0, str2.IndexOf("//")); } str2 = str2.Trim(); if (!string.IsNullOrEmpty(str2)) { char[] chArray2 = new char[] { ':', ',' }; string[] strArray2 = str2.Split(chArray2); if ((strArray2 == null) || (strArray2.Length != 3)) { return; } int[] numArray = new int[3]; for (int i = 0; i < strArray2.Length; i++) { numArray[i] = Mathf.Abs(int.Parse(strArray2[i])); } if ((numArray[0] != 0) && (numArray[0] != 1)) { return; } if (numArray[1] >= numArray[2]) { return; } this.LIMIT_CONFIG[numArray[0]] = new int[] { numArray[1], numArray[2] }; } } } } } }
//* -----------------------------------------------------------------------* /// <summary>リソースを検索します。</summary> /// /// <param name="strAsset">アセット名文字列</param> /// <param name="bCreate">対象リソースまだ読まれていない場合、読み出すかどうか</param> /// <returns>アセット名に対応するリソース。存在しない場合、null</returns> public CResource <_T> search(string strAsset, bool bCreate) { CResource <_T> result = null; foreach (CResource <_T> resource in resources) { if (resource.asset.Equals(strAsset)) { result = resource; break; } } if (result == null && bCreate) { result = load(strAsset); } return(result); }
private CResourcePackerInfo GetResourceBelongedPackerInfo(CResource resource) { if (this.m_resourcePackerInfoSet == null) { return(null); } CResourcePackerInfo resourceBelongedPackerInfo = this.m_resourcePackerInfoSet.GetResourceBelongedPackerInfo(resource.m_key); if (resourceBelongedPackerInfo != null) { string str = string.Empty; if (!resourceBelongedPackerInfo.m_fileExtMap.TryGetValue(resource.m_fullPathInResourcesWithoutExtension.ToLower(), out str)) { Debug.LogError("No Resource " + resource.m_fullPathInResourcesWithoutExtension + " found in ext name map of bundle:" + resourceBelongedPackerInfo.m_pathInIFS); } resource.m_fileFullPathInResources = resource.m_fullPathInResourcesWithoutExtension + "." + str; } return(resourceBelongedPackerInfo); }
/// <summary>Получение доступа к требуемому журналу сообщений.</summary> /// <param name="x_tpJournalType">тип журнала.</param>> /// <returns>требуемый журнал.</returns>> public static CJournal Journal(Type x_tpJournalType) { if (!m_dcJournals.ContainsKey(x_tpJournalType)) { // Создание требуемого журнала сообщений, если он не существует. try { m_dcJournals.Add(x_tpJournalType, (CJournal)Activator.CreateInstance(x_tpJournalType)); } catch { throw new ArgumentException( String.Format( CResource.LoadString("IDS_ERR_INVALIDJOURNALTYPE"), x_tpJournalType.FullName), "x_tpJournalType"); } } return(m_dcJournals[x_tpJournalType]); }
public void LoadDatabin(string name, ResourceLoader.BinLoadCompletedDelegate finishDelegate) { CResource resource = Singleton <CResourceManager> .GetInstance().GetResource(name, typeof(TextAsset), enResourceType.Numeric, false, false); DebugHelper.Assert(resource != null, "Failed Load Resource {0}", new object[] { name }); CBinaryObject cBinaryObject = resource.m_content as CBinaryObject; DebugHelper.Assert(cBinaryObject != null, "Failed Load Databin {0}", new object[] { name }); byte[] data = cBinaryObject.m_data; if (finishDelegate != null) { finishDelegate(ref data); } Singleton <CResourceManager> .GetInstance().RemoveCachedResource(name); }
/// <summary>Создание нового элемента с указанной информацией в атрибутах в указанном узле документа XML.</summary> /// <param name="x_xnElementParent">узел документа XML, в который добавляется новый элемент.</param> /// <param name="x_sElementName">имя нового элемента.</param> /// <param name="x_lElementType">тип нового элемента.</param> /// <param name="x_sElementData">данные нового элемента.</param> public static void AddElement( XmlNode x_xnElementParent, string x_sElementName, ElementTypeEnum x_lElementType, params string[] x_sElementData) { // Создание нового элемента. XmlNode c_xnElement = x_xnElementParent.OwnerDocument.CreateNode("element", x_sElementName, ""); switch (x_lElementType) { case ElementTypeEnum.ATTRIBUTE_ELEMENT: for (int i = 0; i < x_sElementData.Length; i += 2) { // Добавление атрибута к новому элементу и присваивание ему значения. c_xnElement.Attributes.Append(x_xnElementParent.OwnerDocument.CreateAttribute(x_sElementData[i])); c_xnElement.Attributes[x_sElementData[i]].InnerText = x_sElementData[i + 1]; } break; case ElementTypeEnum.NODE_ELEMENT: for (int i = 0; i < x_sElementData.Length; i += 2) { // Добавление дочернего узла к новому элементу и присваивание ему значения. c_xnElement.AppendChild(x_xnElementParent.OwnerDocument.CreateNode(XmlNodeType.Element, x_sElementData[i], "")); c_xnElement.LastChild.InnerText = x_sElementData[i + 1]; } break; default: throw new Exception( String.Format( CResource.LoadString("IDS_ERR_INVALIDELEMENTTYPE"), Enum.Format(typeof(ElementTypeEnum), x_lElementType, "G"))); } // Добавление созданного элемента к родительскому элементу документа XML. x_xnElementParent.AppendChild(c_xnElement); }
//* ────────────-_______________________* //* constructor & destructor ───────────────────────* //* -----------------------------------------------------------------------* /// <summary>コンストラクタ。</summary> /// /// <param name="__font">スプライトフォント リソース</param> public CFont(CResource <SpriteFont> __font) { font = __font; }
//* -----------------------------------------------------------------------* /// <summary>コンストラクタ。</summary> /// /// <param name="__font">フォントリソース</param> /// <param name="__strText">テキスト</param> public CFont(CResource <SpriteFont> __font, string __strText) : this(__font) { text = __strText; }
private void CreateFile(CResource value) { }
//* -----------------------------------------------------------------------* /// <summary>テクスチャを閉じ、キャッシュからも削除します。</summary> /// /// <param name="resource">リソースとアセットのペア オブジェクト</param> public void close(CResource <_T> resource) { resources.Remove(resource); }
public static string GetREDExtensionFromCVariable(CResource cvar) { //if (cvar is CResource) return ""; if (cvar is CCookedExplorations) { return("redexp"); } if (cvar is CBehaviorGraph) { return("w2beh"); } if (cvar is CCharacterEntityTemplate) { return("w2cent"); } if (cvar is CEntityTemplate) { return("w2ent"); } if (cvar is CFoliageResource) { return("flyr"); } if (cvar is CGameWorld) { return("w2w"); } if (cvar is CMaterialGraph) { return("w2mg"); } if (cvar is CMaterialInstance) { return("w2mi"); } if (cvar is CPhysicsDestructionResource) { return("reddest"); // check before mesh } if (cvar is CMesh) { return("w2mesh"); } if (cvar is CRagdoll) { return("w2ragdoll"); } if (cvar is CCutsceneTemplate) { return("w2cutscene"); // check before CSkeletalAnimationSet } if (cvar is CStorySceneDialogset) { return("w2dset"); // check before CSkeletalAnimationSet } if (cvar is CSkeletalAnimationSet) { return("w2anims"); } if (cvar is CExtAnimEventsFile) { return("w2animev"); } if (cvar is CSwarmCellMap) { return("cellmap"); } if (cvar is CSwfResource) { return("redswf"); } //if (cvar is CUmbraScene) return ""; //?? if (cvar is CWayPointsCollectionsSet) { return("redwpset"); } if (cvar is CUmbraTile) { return("w3occlusion"); } if (cvar is CFont) { return("w2fnt"); } if (cvar is CTextureArray) { return("texarray"); } if (cvar is CTerrainTile) { return("w2ter"); } //if (cvar is CSwfTexture) return "redswf"; //?? if (cvar is CBitmapTexture) { return("xbm"); } if (cvar is CCubeTexture) { return("w2cube"); } if (cvar is CGenericGrassMask) { return("grassmask"); } if (cvar is CParticleSystem) { return("w2p"); } if (cvar is CDyngResource) { return("w3dyng"); } if (cvar is CSkeleton) { return("w3fac"); // w3dyng // w3fac } if (cvar is CWayPointsCollection) { return("redwpset"); } //if (cvar is C2dArray) return ""; // unused if (cvar is CApexClothResource) { return("redcloth"); } if (cvar is CApexDestructionResource) { return("redapex"); } // if (cvar is CApexResource) return ""; // unused if (cvar is CAreaMapPinsResource) { return("w2am"); } if (cvar is CBehTree) { return("w2behtree"); } //if (cvar is CCharacterResource) return "";// unused //if (cvar is CCollisionMesh) return "";// unused //if (cvar is CCommonGameResource) return "";// unused if (cvar is CCommunity) { return("w2comm"); } if (cvar is CDLCDefinition) { return("reddlc"); } //if (cvar is CDynamicLayer) return "";// unused if (cvar is CEntityExternalAppearance) { return("w3app"); } if (cvar is CEntityMapPinsResource) { return("w2em"); } if (cvar is CEnvironmentDefinition) { return("env"); } if (cvar is CFormation) { return("formation"); } if (cvar is CFurMeshResource) { return("redfur"); } //if (cvar is CGameResource) return "";// unused if (cvar is CGuiConfigResource) { return("guiconfig"); } if (cvar is CHudResource) { return("hud"); } if (cvar is CJobTree) { return("w2job"); } if (cvar is CJournalInitialEntriesResource) { return("w2je"); } if (cvar is CJournalResource) { return("journal"); } if (cvar is CLayer) { return("w2l"); } if (cvar is CMenuResource) { return("menu"); } //if (cvar is CMeshTypeResource) return "";// unused if (cvar is CMimicFace) { return("w3fac"); } //if (cvar is CMimicFaces) return "";// unused //if (cvar is CModConverter) return "";// unused if (cvar is CMoveSteeringBehavior) { return("w2steer"); } //if (cvar is CNavmesh) return "";// unused if (cvar is CPopupResource) { return("popup"); } if (cvar is CQuest) { return("w2quest"); } if (cvar is CQuestMapPinsResource) { return("w2qm"); } if (cvar is CQuestPhase) { return("w2phase"); } if (cvar is CResourceSimplexTree) { return("w3simplex"); } //if (cvar is CRewardGroup) return "";// unused //if (cvar is CSourceTexture) return "";// unused if (cvar is CSpawnTree) { return("spawntree"); } //if (cvar is CSRTBaseTree) return "";// unused if (cvar is CStoryScene) { return("w2scene"); } if (cvar is CSwitchableFoliageResource) { return("w2sf"); } //if (cvar is CUnknownResource) return "";// unused if (cvar is CVegetationBrush) { return("vbrush"); } if (cvar is CWitcherGameResource) { return("redgame"); } if (cvar is CWizardDefinition) { return("wizdef"); } //if (cvar is CWorld) return "";// unused //if (cvar is CWorldMap) return "";// unused //if (cvar is IGuiResource) return ""; //if (cvar is IMaterial) return ""; //if (cvar is IMaterialDefinition) return ""; //if (cvar is ITexture) return ""; return(""); }