/// <summary> /// Load ini config data from ini format string content. /// </summary> /// <param name="content">ini format string content</param> public void LoadFromContent(string content) { _sections.Clear(); unsafe { int sectionCount = 0; IntPtr nativeContent = LibUtil.CreateNativeStr(content); int errDescLen = 0; IntPtr nativeSections = LLBCNative.csllbc_Ini_LoadFromContent(nativeContent, new IntPtr(§ionCount), new IntPtr(&errDescLen)); LibUtil.FreeNativePtr(ref nativeContent, false); if (sectionCount == -1) { byte * nativeErrorDesc = (byte *)nativeSections; string errorDesc = LibUtil.Ptr2Str(nativeErrorDesc, errDescLen); LibUtil.FreeNativePtr(nativeErrorDesc); throw new LLBCException("{0}", errorDesc); } else if (sectionCount == 0) { return; } _LoadAllSections((_NativeIniSection *)nativeSections.ToPointer(), sectionCount); LLBCNative.csllbc_Ini_FreeNativeSections(nativeSections, sectionCount); } }
private unsafe void _LoadAllSections(_NativeIniSection *nativeSections, int sectionCount) { for (int sectionIdx = 0; sectionIdx < sectionCount; ++sectionIdx) { _NativeIniSection nativeSection = *(nativeSections + sectionIdx); string sectionName = LibUtil.Ptr2Str(nativeSection.sectionName, nativeSection.sectionNameLen); Dictionary <string, string> values = new Dictionary <string, string>(nativeSection.count); for (int valueIdx = 0; valueIdx < nativeSection.count; ++valueIdx) { string key = LibUtil.Ptr2Str(nativeSection.keys[valueIdx], nativeSection.keysLen[valueIdx]); string value = LibUtil.Ptr2Str(nativeSection.values[valueIdx], nativeSection.valuesLen[valueIdx]); values.Add(key, value); } _sections.Add(sectionName, new IniSection(sectionName, values)); } }
/// <summary> /// Create exception from llbc core library. /// </summary> /// <returns></returns> public static LLBCException CreateExceptionFromCoreLib(uint errNo = 0) { unsafe { int errStrLen = 0; IntPtr errStr; if (errNo == 0) { errStr = LLBCNative.csllbc_FormatLastError(new IntPtr(&errStrLen)); } else { errStr = LLBCNative.csllbc_StrError(errNo, new IntPtr(&errStrLen)); } if (errStrLen > 0) { return(new LLBCException(LibUtil.Ptr2Str(errStr, errStrLen))); } return(new LLBCException("unknown error")); } }