static RSVersion ___RSCFPVersionCacheGetVersionWithID(___RSCFPVersionIndex idx) { if (idx < 0 || idx >= ___RSCFPVersionCount) return 0; if (likely(___RSCFPVersionListCache[idx])) return ___RSCFPVersionListCache[idx]; RSDictionaryRef _contents = RSDictionaryCreateWithContentOfPath(RSAllocatorDefault, ___RSCoreOperatingSystemVersion); RSVersion productVersion = 0, buildVersion = 0; if (___RSCFPreferenceGetCFVersion(&productVersion, &buildVersion)) { ___RSCFPVersionListCache[___RSCFPVersionSelfBuild] = buildVersion; ___RSCFPVersionListCache[___RSCFPVersionSelf] = productVersion; } ___RSCFPVersionListCache[___RSCFPVersionOSBuild] = RSStringUnsignedLongValue(RSDictionaryGetValue(_contents, RSSTR("ProductBuildVersion"))); ___RSCFPVersionListCache[___RSCFPVersionOSProduct] = RSStringUnsignedLongValue(RSDictionaryGetValue(_contents, RSSTR("ProductVersion"))); ___RSCFPVersionListCache[___RSCFPVersionOSProductUserVisible] = RSStringUnsignedLongValue(RSDictionaryGetValue(_contents, RSSTR("ProductUserVisibleVersion"))); if (_contents) RSRelease(_contents); return ___RSCFPVersionListCache[idx]; }
static BOOL __RSProcessInfoUpdateVersion(RSProcessInfoRef processInfo, RSStringRef key /*__RSProcessInfoOperatingSystemVersion*/) { BOOL result = NO; if (__RSProcessInfoObjectForKey(processInfo, key)) return result = YES; RSMutableArrayRef keys = RSArrayCreateMutable(RSAllocatorSystemDefault, 0); RSMutableArrayRef descriptions = RSArrayCreateMutable(RSAllocatorSystemDefault, 0); RSRetain(key); RSArrayAddObject(keys, __RSProcessInfo_kern_ostype); RSArrayAddObject(descriptions, __RSProcessInfoKernelType); RSArrayAddObject(keys, __RSProcessInfo_kern_osversion); RSArrayAddObject(descriptions, __RSProcessInfoKernelVersion); RSArrayAddObject(keys, __RSProcessInfo_kern_osrelease); RSArrayAddObject(descriptions, __RSProcessInfoKernelRelease); RSArrayAddObject(keys, __RSProcessInfo_kern_uuid); RSArrayAddObject(descriptions, __RSProcessInfoKernelUUID); result = __RSProcessInfoUpdateKeys(processInfo, keys, descriptions, key); RSMutableDictionaryRef dict = (RSMutableDictionaryRef)__RSProcessInfoObjectForKey(processInfo, key); __RSRuntimeSetInstanceSpecial(dict, YES); RS_CONST_STRING_DECL(__RSSystemVersionInfoPlistPath, "/System/Library/CoreServices/SystemVersion.plist"); RSDictionaryRef sysVer = RSDictionaryCreateWithContentOfPath(RSAllocatorSystemDefault, __RSSystemVersionInfoPlistPath); RS_CONST_STRING_DECL(ProductUserVisibleVersion, "ProductUserVisibleVersion"); RSStringRef userVisibleVersion = RSDictionaryGetValue(sysVer, ProductUserVisibleVersion); RSDictionarySetValue(dict, __RSProcessInfoHumenReadableOperatingSystemVersion, userVisibleVersion); RSRelease(sysVer); RSRelease(key); RSRelease(descriptions); RSRelease(keys); return result; }
RSExport RSErrorUserInfoKeyCallBack RSErrorGetCallBackForDomain(RSStringRef domainName) { if (!__RSErrorCallBackTable) __RSErrorInitUserInfoKeyCallBackTable(); RSSpinLockLock(&__RSErrorCallBackTableSpinlock); RSErrorUserInfoKeyCallBack cb = RSDictionaryGetValue(__RSErrorCallBackTable, domainName); RSSpinLockUnlock(&__RSErrorCallBackTableSpinlock); return cb; }
static BOOL ___RSCFPreferenceGetCFVersion(RSVersion* productVersion, RSVersion* buildVersion) { if (likely(___RSCFPVersionListCache[___RSCFPVersionSelfBuild])) return ___RSCFPVersionListCache[___RSCFPVersionSelfBuild]; RSDictionaryRef _contents = RSDictionaryCreateWithContentOfPath(RSAllocatorDefault, RSFileManagerStandardizingPath(___RSCoreFoundationLoadPath)); RSVersion _version1 = 0, _version2 = 0; RSStringRef version = RSDictionaryGetValue(_contents, RSSTR("RSProductVersion")); if (version) { _version1 = RSStringFloatValue(version); ___RSCFPVersionListCache[___RSCFPVersionSelfBuild] = _version1; if (*productVersion) *productVersion = _version1; } version = RSDictionaryGetValue(_contents, RSSTR("RSBundleVersion")); if (version) { _version2 = RSStringFloatValue(version); if (*buildVersion) *buildVersion = _version2; } RSRelease(_contents); return (_version1 || _version2) ? YES : NO; }
static RSStringRef __RSErrorCopyUserInfoKey(RSErrorRef err, RSStringRef key) { RSStringRef result = nil; RSDictionaryRef userInfo = __RSErrorGetUserInfo(err); if (userInfo) result = RSDictionaryGetValue(userInfo, key); // result is not retained by RSDictionaryGetValue. if (nil == result) { RSErrorUserInfoKeyCallBack cb = RSErrorGetCallBackForDomain(RSErrorGetDomain(err)); if (cb) result = (RSStringRef)cb(err, key); return result; } return RSRetain(result); }
static RSTypeRef __RSErrorRSCoreFoundationCallBack(RSErrorRef err, RSStringRef key) { if (!RSEqual(key, RSErrorDescriptionKey) && !RSEqual(key, RSErrorLocalizedFailureReasonKey)) return nil; RSStringRef errStr = nil; struct __RSErrorPrivateFormatTable cFormat = __RSErrorDomainRSCoreFoundationGetCStringWithCode(RSErrorGetCode(err)); if (cFormat.argsCnt) { RSStringRef format = RSStringCreateWithCString(RSAllocatorSystemDefault, cFormat.format, RSStringEncodingUTF8); RSArrayRef objects = RSDictionaryGetValue(__RSErrorGetUserInfo(err), RSErrorTargetKey); RSTypeRef object[3] = {nil}; RSIndex minCnt = 0; if (objects) { minCnt = min(cFormat.argsCnt, RSArrayGetCount(objects)); switch (minCnt) { case 1: object[0] = RSArrayObjectAtIndex(objects, 0); errStr = RSStringCreateWithFormat(RSAllocatorSystemDefault, format, object[0]); break; case 2: object[0] = RSArrayObjectAtIndex(objects, 0); object[1] = RSArrayObjectAtIndex(objects, 1); errStr = RSStringCreateWithFormat(RSAllocatorSystemDefault, format, object[0], object[1]); break; case 3: object[0] = RSArrayObjectAtIndex(objects, 0); object[1] = RSArrayObjectAtIndex(objects, 1); object[2] = RSArrayObjectAtIndex(objects, 2); errStr = RSStringCreateWithFormat(RSAllocatorSystemDefault, format, object[0], object[1], object[2]); break; default: HALTWithError(RSInvalidArgumentException, "the formate is too long to support"); break; } } for (RSIndex idx = 0; idx < minCnt; idx++) { RSRelease(object[idx]); } RSRelease(format); } else { errStr = RSStringCreateWithCString(RSAllocatorSystemDefault, cFormat.format, RSStringEncodingUTF8); } return errStr; }
RSExport RSTypeRef RSDictionaryGetValueForKeys(RSDictionaryRef dictionary, RSArrayRef keys) { if (nil == dictionary || !keys || !RSArrayGetCount(keys)) return nil; RSTypeRef rst = nil; RSClassRef dictClass = RSClassGetWithUTF8String("RSDictionary"); RSUInteger cnt = RSArrayGetCount(keys); RSDictionaryRef tmp = dictionary; for (RSUInteger idx = 0; idx < cnt; idx++) { if (RSInstanceIsMemberOfClass(tmp, dictClass)) { tmp = RSDictionaryGetValue(tmp, RSArrayObjectAtIndex(keys, idx)); } else { return nil; } } return rst = tmp; }
static void __RSProcessInfoClassDeallocate(RSTypeRef rs) { RSProcessInfoRef pi = (RSProcessInfoRef)rs; if (pi->_info) { __RSRuntimeSetInstanceSpecial(RSDictionaryGetValue(pi->_info, __RSProcessInfoEnvironment), NO); __RSRuntimeSetInstanceSpecial(RSDictionaryGetValue(pi->_info, __RSProcessInfoMachine), NO); __RSRuntimeSetInstanceSpecial(RSDictionaryGetValue(pi->_info, __RSProcessInfoOperatingSystemVersion), NO); __RSRuntimeSetInstanceSpecial(RSDictionaryGetValue(pi->_info, __RSProcessInfoKernel), NO); __RSRuntimeSetInstanceSpecial(RSDictionaryGetValue(pi->_info, __RSProcessInfoProcessor), NO); __RSRuntimeSetInstanceSpecial(RSDictionaryGetValue(pi->_info, __RSProcessInfoMemory), NO); __RSRuntimeSetInstanceSpecial(RSDictionaryGetValue(pi->_info, __RSProcessInfoProgramName), NO); __RSRuntimeSetInstanceSpecial(pi->_info, NO); RSRelease(pi->_info); } _RSCloseHandle(pi->_core); }
RSExport void RSDictionarySetValueForKeys(RSMutableDictionaryRef dictionary, RSArrayRef keys, RSTypeRef value) { if (nil == dictionary || nil == keys || !RSArrayGetCount(keys)) return; RSClassRef dictClass = RSClassGetWithUTF8String("RSDictionary"); RSUInteger cnt = RSArrayGetCount(keys); if (cnt < 2) { return RSDictionarySetValue(dictionary, RSArrayObjectAtIndex(keys, 0), value); } cnt --; RSMutableDictionaryRef tmp = dictionary, tmp1 = tmp; for (RSUInteger idx = 0; idx < cnt; idx++) { if (RSInstanceIsMemberOfClass(tmp, dictClass)) { tmp1 = (RSMutableDictionaryRef)RSDictionaryGetValue(tmp, RSArrayObjectAtIndex(keys, idx)); if (!tmp1) { tmp1 = RSDictionaryCreateMutable(RSAllocatorSystemDefault, 0, RSDictionaryRSTypeContext); RSDictionarySetValue(tmp, RSArrayObjectAtIndex(keys, idx), tmp1); RSRelease(tmp1); } tmp = tmp1; } else { return ; } } return RSDictionarySetValue(tmp, RSArrayLastObject(keys), value); }
RSExport RSStringRef RSProcessInfoGetProcessorDescription(RSProcessInfoRef processInfo) { __RSGenericValidInstance(processInfo, _RSProcessInfoTypeID); __RSProcessInfoUpdateProcessor(processInfo, __RSProcessInfoProcessor); return RSDictionaryGetValue(__RSProcessInfoObjectForKey(processInfo, __RSProcessInfoProcessor), __RSProcessInfoProcessorBrand); }
RSExport unsigned long long RSProcessInfoGetProcessorCount(RSProcessInfoRef processInfo) { __RSGenericValidInstance(processInfo, _RSProcessInfoTypeID); __RSProcessInfoUpdateProcessor(processInfo, __RSProcessInfoProcessor); return RSStringUnsignedLongLongValue(RSDictionaryGetValue(__RSProcessInfoObjectForKey(processInfo, __RSProcessInfoProcessor), __RSProcessInfoProcessorCount)); }
RSExport unsigned long long RSProcessInfoGetCache3Size(RSProcessInfoRef processInfo) { __RSGenericValidInstance(processInfo, _RSProcessInfoTypeID); __RSProcessInfoUpdateMemory(processInfo, __RSProcessInfoMemory); return RSStringUnsignedLongLongValue(RSDictionaryGetValue(__RSProcessInfoObjectForKey(processInfo, __RSProcessInfoMemory), __RSProcessInfoMemoryCache3)); }
RSExport RSStringRef RSProcessInfoGetKernelReleaseVersion(RSProcessInfoRef processInfo) { __RSGenericValidInstance(processInfo, _RSProcessInfoTypeID); __RSProcessInfoUpdateVersion(processInfo, __RSProcessInfoOperatingSystemVersion); return RSDictionaryGetValue(__RSProcessInfoObjectForKey(processInfo, __RSProcessInfoOperatingSystemVersion), __RSProcessInfoKernelRelease); }
RSExport RSStringRef RSProcessInfoGetMachineSerinalNumber(RSProcessInfoRef processInfo) { __RSGenericValidInstance(processInfo, _RSProcessInfoTypeID); __RSProcessInfoUpdateMachineType(processInfo, __RSProcessInfoMachine); return RSDictionaryGetValue(__RSProcessInfoObjectForKey(processInfo, __RSProcessInfoMachine), __RSProcessInfoMachineSerinalNumber); }
RSInline RSTypeRef __RSProcessInfoObjectForKey(RSProcessInfoRef processInfo, RSStringRef key) { return RSDictionaryGetValue(processInfo->_info, key); }