/** * Define OS-specific constants. * * This function creates or uses JS object |OS.Constants| to store * all its constants. */ bool DefineOSFileConstants(JSContext *cx, JSObject *global) { MOZ_ASSERT(gInitialized); if (gPaths == NULL) { // If an initialization error was ignored, we may end up with // |gInitialized == true| but |gPaths == NULL|. We cannot // |MOZ_ASSERT| this, as this would kill precompile_cache.js, // so we simply return an error. JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_OPEN, "OSFileConstants", "initialization has failed"); return false; } JSObject *objOS; if (!(objOS = GetOrCreateObjectProperty(cx, global, "OS"))) { return false; } JSObject *objConstants; if (!(objConstants = GetOrCreateObjectProperty(cx, objOS, "Constants"))) { return false; } // Build OS.Constants.libc JSObject *objLibc; if (!(objLibc = GetOrCreateObjectProperty(cx, objConstants, "libc"))) { return false; } if (!dom::DefineConstants(cx, objLibc, gLibcProperties)) { return false; } #if defined(XP_WIN) // Build OS.Constants.Win JSObject *objWin; if (!(objWin = GetOrCreateObjectProperty(cx, objConstants, "Win"))) { return false; } if (!dom::DefineConstants(cx, objWin, gWinProperties)) { return false; } #endif // defined(XP_WIN) // Build OS.Constants.Sys JSObject *objSys; if (!(objSys = GetOrCreateObjectProperty(cx, objConstants, "Sys"))) { return false; } nsCOMPtr<nsIXULRuntime> runtime = do_GetService(XULRUNTIME_SERVICE_CONTRACTID); if (runtime) { nsAutoCString os; DebugOnly<nsresult> rv = runtime->GetOS(os); MOZ_ASSERT(NS_SUCCEEDED(rv)); JSString* strVersion = JS_NewStringCopyZ(cx, os.get()); if (!strVersion) { return false; } JS::Value valVersion = STRING_TO_JSVAL(strVersion); if (!JS_SetProperty(cx, objSys, "Name", &valVersion)) { return false; } } // Build OS.Constants.Path JSObject *objPath; if (!(objPath = GetOrCreateObjectProperty(cx, objConstants, "Path"))) { return false; } // Locate libxul { nsAutoString xulPath(gPaths->libDir); xulPath.Append(PR_GetDirectorySeparator()); #if defined(XP_MACOSX) // Under MacOS X, for some reason, libxul is called simply "XUL" xulPath.Append(NS_LITERAL_STRING("XUL")); #else // On other platforms, libxul is a library "xul" with regular // library prefix/suffix xulPath.Append(NS_LITERAL_STRING(DLL_PREFIX)); xulPath.Append(NS_LITERAL_STRING("xul")); xulPath.Append(NS_LITERAL_STRING(DLL_SUFFIX)); #endif // defined(XP_MACOSX) if (!SetStringProperty(cx, objPath, "libxul", xulPath)) { return false; } } if (!SetStringProperty(cx, objPath, "libDir", gPaths->libDir)) { return false; } if (!SetStringProperty(cx, objPath, "tmpDir", gPaths->tmpDir)) { return false; } // Configure profileDir only if it is available at this stage if (!gPaths->profileDir.IsVoid() && !SetStringProperty(cx, objPath, "profileDir", gPaths->profileDir)) { return false; } // Configure localProfileDir only if it is available at this stage if (!gPaths->localProfileDir.IsVoid() && !SetStringProperty(cx, objPath, "localProfileDir", gPaths->localProfileDir)) { return false; } return true; }
/** * Define OS-specific constants. * * This function creates or uses JS object |OS.Constants| to store * all its constants. */ bool DefineOSFileConstants(JSContext *cx, JS::Handle<JSObject*> global) { MOZ_ASSERT(gInitialized); if (gPaths == nullptr) { // If an initialization error was ignored, we may end up with // |gInitialized == true| but |gPaths == nullptr|. We cannot // |MOZ_ASSERT| this, as this would kill precompile_cache.js, // so we simply return an error. JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_CANT_OPEN, "OSFileConstants", "initialization has failed"); return false; } JS::Rooted<JSObject*> objOS(cx); if (!(objOS = GetOrCreateObjectProperty(cx, global, "OS"))) { return false; } JS::Rooted<JSObject*> objConstants(cx); if (!(objConstants = GetOrCreateObjectProperty(cx, objOS, "Constants"))) { return false; } // Build OS.Constants.libc JS::Rooted<JSObject*> objLibc(cx); if (!(objLibc = GetOrCreateObjectProperty(cx, objConstants, "libc"))) { return false; } if (!dom::DefineConstants(cx, objLibc, gLibcProperties)) { return false; } #if defined(XP_WIN) // Build OS.Constants.Win JS::Rooted<JSObject*> objWin(cx); if (!(objWin = GetOrCreateObjectProperty(cx, objConstants, "Win"))) { return false; } if (!dom::DefineConstants(cx, objWin, gWinProperties)) { return false; } #endif // defined(XP_WIN) // Build OS.Constants.Sys JS::Rooted<JSObject*> objSys(cx); if (!(objSys = GetOrCreateObjectProperty(cx, objConstants, "Sys"))) { return false; } #if defined(MOZ_WIDGET_GONK) JSString* strVersion = JS_NewStringCopyZ(cx, "Gonk"); if (!strVersion){ return false; } JS::Rooted<JS::Value> valVersion(cx, STRING_TO_JSVAL(strVersion)); if (!JS_SetProperty(cx, objSys, "Name", valVersion)) { return false; } #else nsCOMPtr<nsIXULRuntime> runtime = do_GetService(XULRUNTIME_SERVICE_CONTRACTID); if (runtime) { nsAutoCString os; DebugOnly<nsresult> rv = runtime->GetOS(os); MOZ_ASSERT(NS_SUCCEEDED(rv)); JSString* strVersion = JS_NewStringCopyZ(cx, os.get()); if (!strVersion) { return false; } JS::Rooted<JS::Value> valVersion(cx, STRING_TO_JSVAL(strVersion)); if (!JS_SetProperty(cx, objSys, "Name", valVersion)) { return false; } } #endif // defined(MOZ_WIDGET_GONK) #if defined(DEBUG) JS::Rooted<JS::Value> valDebug(cx, JSVAL_TRUE); if (!JS_SetProperty(cx, objSys, "DEBUG", valDebug)) { return false; } #endif dom::ConstantSpec umask_cs[] = { { "umask", UINT_TO_JSVAL(gUserUmask) }, PROP_END }; if (!dom::DefineConstants(cx, objSys, umask_cs)) { return false; } // Build OS.Constants.Path JS::Rooted<JSObject*> objPath(cx); if (!(objPath = GetOrCreateObjectProperty(cx, objConstants, "Path"))) { return false; } // Locate libxul // Note that we don't actually provide the full path, only the name of the // library, which is sufficient to link to the library using js-ctypes. #if defined(XP_MACOSX) // Under MacOS X, for some reason, libxul is called simply "XUL", // and we need to provide the full path. nsAutoString libxul; libxul.Append(gPaths->libDir); libxul.AppendLiteral("/XUL"); #else // On other platforms, libxul is a library "xul" with regular // library prefix/suffix. nsAutoString libxul; libxul.AppendLiteral(DLL_PREFIX); libxul.AppendLiteral("xul"); libxul.AppendLiteral(DLL_SUFFIX); #endif // defined(XP_MACOSX) if (!SetStringProperty(cx, objPath, "libxul", libxul)) { return false; } if (!SetStringProperty(cx, objPath, "libDir", gPaths->libDir)) { return false; } if (!SetStringProperty(cx, objPath, "tmpDir", gPaths->tmpDir)) { return false; } // Configure profileDir only if it is available at this stage if (!gPaths->profileDir.IsVoid() && !SetStringProperty(cx, objPath, "profileDir", gPaths->profileDir)) { return false; } // Configure localProfileDir only if it is available at this stage if (!gPaths->localProfileDir.IsVoid() && !SetStringProperty(cx, objPath, "localProfileDir", gPaths->localProfileDir)) { return false; } if (!SetStringProperty(cx, objPath, "homeDir", gPaths->homeDir)) { return false; } if (!SetStringProperty(cx, objPath, "desktopDir", gPaths->desktopDir)) { return false; } if (!SetStringProperty(cx, objPath, "userApplicationDataDir", gPaths->userApplicationDataDir)) { return false; } #if defined(XP_WIN) if (!SetStringProperty(cx, objPath, "winAppDataDir", gPaths->winAppDataDir)) { return false; } if (!SetStringProperty(cx, objPath, "winStartMenuProgsDir", gPaths->winStartMenuProgsDir)) { return false; } #endif // defined(XP_WIN) #if defined(XP_MACOSX) if (!SetStringProperty(cx, objPath, "macUserLibDir", gPaths->macUserLibDir)) { return false; } if (!SetStringProperty(cx, objPath, "macLocalApplicationsDir", gPaths->macLocalApplicationsDir)) { return false; } if (!SetStringProperty(cx, objPath, "macTrashDir", gPaths->macTrashDir)) { return false; } #endif // defined(XP_MACOSX) // sqlite3 is linked from different places depending on the platform nsAutoString libsqlite3; #if defined(ANDROID) // On Android, we use the system's libsqlite3 libsqlite3.AppendLiteral(DLL_PREFIX); libsqlite3.AppendLiteral("sqlite3"); libsqlite3.AppendLiteral(DLL_SUFFIX); #elif defined(XP_WIN) // On Windows, for some reason, this is part of nss3.dll libsqlite3.AppendLiteral(DLL_PREFIX); libsqlite3.AppendLiteral("nss3"); libsqlite3.AppendLiteral(DLL_SUFFIX); #else // On other platforms, we link sqlite3 into libxul libsqlite3 = libxul; #endif // defined(ANDROID) || defined(XP_WIN) if (!SetStringProperty(cx, objPath, "libsqlite3", libsqlite3)) { return false; } return true; }
///--------------------------------------------------------------------- /// Adds a boolean property to the node, either as an attribute, or as a /// child node with the specified name, and a "Value" attribute. ///--------------------------------------------------------------------- void SetBooleanProperty( XMLNode& node, const std::string& propertyName, bool value, bool defaultValue, bool createChild ) { SetStringProperty( node, propertyName, GetBoolAsString( value ), GetBoolAsString( defaultValue), createChild ); }
///--------------------------------------------------------------------- /// Adds an int property to the node, either as an attribute, or as a /// child node with the specified name, and a "Value" attribute. ///--------------------------------------------------------------------- void SetIntProperty( XMLNode& node, const std::string& propertyName, int value, int defaultValue, bool createChild ) { SetStringProperty( node, propertyName, GetIntAsString( value ), GetIntAsString( defaultValue), createChild ); }
// I'd like to not store the account key, if the msg is in // the same account as it was received in, to save disk space and memory. // This might be problematic when a message gets moved... // And I'm not sure if we should short circuit it here, // or at a higher level where it might be more efficient. NS_IMETHODIMP nsMsgHdr::SetAccountKey(const char *aAccountKey) { return SetStringProperty("account", aAccountKey); }
mitk::PropertyList::Pointer mitk::CustomTagParser::ParseDicomPropertyString(std::string dicomPropertyString) { auto results = mitk::PropertyList::New(); if ("" == dicomPropertyString) { //MITK_ERROR << "Could not parse empty custom dicom string"; return results; } std::map<std::string, std::string> privateParameters; // convert hex to ascii // the Siemens private tag contains the information like this // "43\52\23\34" we jump over each \ and convert the number int len = dicomPropertyString.length(); std::string asciiString; for (int i = 0; i < len; i += 3) { std::string byte = dicomPropertyString.substr(i, 2); auto chr = (char)(int)strtol(byte.c_str(), nullptr, 16); asciiString.push_back(chr); } // extract parameter list std::size_t beginning = asciiString.find("### ASCCONV BEGIN ###") + 21; std::size_t ending = asciiString.find("### ASCCONV END ###"); std::string parameterListString = asciiString.substr(beginning, ending - beginning); boost::replace_all(parameterListString, "\r\n", "\n"); boost::char_separator<char> newlineSeparator("\n"); boost::tokenizer<boost::char_separator<char>> parameters(parameterListString, newlineSeparator); for (const auto ¶meter : parameters) { std::vector<std::string> parts; boost::split(parts, parameter, boost::is_any_of("=")); if (parts.size() == 2) { parts[0].erase(std::remove(parts[0].begin(), parts[0].end(), ' '), parts[0].end()); parts[1].erase(parts[1].begin(), parts[1].begin() + 1); // first character is a space privateParameters[parts[0]] = parts[1]; } } std::string revisionString = ""; try { revisionString = ExtractRevision(privateParameters["tSequenceFileName"]); } catch (const std::exception &e) { MITK_ERROR << "Cannot deduce revision information. Reason: "<< e.what(); return results; } results->SetProperty(m_RevisionPropertyName, mitk::StringProperty::New(revisionString)); std::string jsonString = GetRevisionAppropriateJSONString(revisionString); boost::property_tree::ptree root; std::istringstream jsonStream(jsonString); try { boost::property_tree::read_json(jsonStream, root); } catch (const boost::property_tree::json_parser_error &e) { mitkThrow() << "Could not parse json file. Error was:\n" << e.what(); } for (auto it : root) { if (it.second.empty()) { std::string propertyName = m_CESTPropertyPrefix + it.second.data(); if (m_JSONRevisionPropertyName == propertyName) { results->SetProperty(propertyName, mitk::StringProperty::New(it.first)); } else { results->SetProperty(propertyName, mitk::StringProperty::New(privateParameters[it.first])); } } else { MITK_ERROR << "Currently no support for nested dicom tag descriptors in json file."; } } std::string offset = ""; std::string measurements = ""; results->GetStringProperty("CEST.Offset", offset); results->GetStringProperty("CEST.measurements", measurements); if ("" == measurements) { std::string stringRepetitions = ""; std::string stringAverages = ""; results->GetStringProperty("CEST.repetitions", stringRepetitions); results->GetStringProperty("CEST.averages", stringAverages); std::stringstream measurementStream; try { measurementStream << std::stoi(stringRepetitions) + std::stoi(stringAverages); measurements = measurementStream.str(); MITK_INFO << "Could not find measurements, assuming repetitions + averages. Which is: " << measurements; } catch (const std::invalid_argument &ia) { MITK_ERROR << "Could not find measurements, fallback assumption of repetitions + averages could not be determined either: " << ia.what(); } } std::string preparationType = ""; std::string recoveryMode = ""; std::string spoilingType = ""; results->GetStringProperty(CEST_PROPERTY_NAME_PREPERATIONTYPE().c_str(), preparationType); results->GetStringProperty(CEST_PROPERTY_NAME_RECOVERYMODE().c_str(), recoveryMode); results->GetStringProperty(CEST_PROPERTY_NAME_SPOILINGTYPE().c_str(), spoilingType); if (this->IsT1Sequence(preparationType, recoveryMode, spoilingType, revisionString)) { MITK_INFO << "Parsed as T1 image"; mitk::LocaleSwitch localeSwitch("C"); std::stringstream trecStream; std::string trecPath = m_DicomDataPath + "/TREC.txt"; std::ifstream list(trecPath.c_str()); if (list.good()) { std::string currentTime; while (std::getline(list, currentTime)) { trecStream << currentTime << " "; } } else { MITK_WARN << "Assumed T1, but could not load TREC at " << trecPath; } results->SetStringProperty(CEST_PROPERTY_NAME_TREC().c_str(), trecStream.str().c_str()); } else { MITK_INFO << "Parsed as CEST or WASABI image"; std::string sampling = ""; bool hasSamplingInformation = results->GetStringProperty("CEST.SamplingType", sampling); if (hasSamplingInformation) { std::string offsets = GetOffsetString(sampling, offset, measurements); results->SetStringProperty(m_OffsetsPropertyName.c_str(), offsets.c_str()); } else { MITK_WARN << "Could not determine sampling type."; } } //persist all properties mitk::IPropertyPersistence *persSrv = GetPersistenceService(); if (persSrv) { auto propertyMap = results->GetMap(); for (auto const &prop : *propertyMap) { PropertyPersistenceInfo::Pointer info = PropertyPersistenceInfo::New(); std::string key = prop.first; std::replace(key.begin(), key.end(), '.', '_'); info->SetNameAndKey(prop.first, key); persSrv->AddInfo(info); } } return results; }
void AwtDesktopProperties::GetOtherParameters() { // TODO BEGIN: On NT4, some setttings don't trigger WM_SETTINGCHANGE -- // check whether this has been fixed on Windows 2000 and Windows 98 // ECH 10/6/2000 seems to be fixed on NT4 SP5, but not on 98 SetBooleanProperty(TEXT("win.frame.fullWindowDragsOn"), GetBooleanParameter(SPI_GETDRAGFULLWINDOWS)); SetBooleanProperty(TEXT("win.text.fontSmoothingOn"), GetBooleanParameter(SPI_GETFONTSMOOTHING)); // TODO END if (IS_WINXP) { SetIntegerProperty(TEXT("win.text.fontSmoothingType"), GetIntegerParameter(SPI_GETFONTSMOOTHINGTYPE)); SetIntegerProperty(TEXT("win.text.fontSmoothingContrast"), GetIntegerParameter(SPI_GETFONTSMOOTHINGCONTRAST)); SetIntegerProperty(TEXT("win.text.fontSmoothingOrientation"), GetLCDSubPixelOrder()); } int cxdrag = GetSystemMetrics(SM_CXDRAG); int cydrag = GetSystemMetrics(SM_CYDRAG); SetIntegerProperty(TEXT("win.drag.width"), cxdrag); SetIntegerProperty(TEXT("win.drag.height"), cydrag); SetIntegerProperty(TEXT("DnD.gestureMotionThreshold"), max(cxdrag, cydrag)/2); SetIntegerProperty(TEXT("awt.mouse.numButtons"), AwtToolkit::GetNumberOfButtons()); SetIntegerProperty(TEXT("awt.multiClickInterval"), GetDoubleClickTime()); // BEGIN cross-platform properties // Note that these are cross-platform properties, but are being stuck into // WDesktopProperties. WToolkit.lazilyLoadDesktopProperty() can find them, // but if a Toolkit subclass uses the desktopProperties // member, these properties won't be there. -bchristi, echawkes // This property is called "win.frame.fullWindowDragsOn" above // This is one of the properties that don't trigger WM_SETTINGCHANGE SetBooleanProperty(TEXT("awt.dynamicLayoutSupported"), GetBooleanParameter(SPI_GETDRAGFULLWINDOWS)); SetBooleanProperty(TEXT("awt.wheelMousePresent"), ::GetSystemMetrics(SM_MOUSEWHEELPRESENT)); // END cross-platform properties //DWORD menuShowDelay; //SystemParametersInfo(SPI_GETMENUSHOWDELAY, 0, &menuShowDelay, 0); // SetIntegerProperty(TEXT("win.menu.showDelay"), menuShowDelay); SetBooleanProperty(TEXT("win.frame.captionGradientsOn"), GetBooleanParameter(SPI_GETGRADIENTCAPTIONS)); SetBooleanProperty(TEXT("win.item.hotTrackingOn"), GetBooleanParameter(SPI_GETHOTTRACKING)); SetBooleanProperty(TEXT("win.menu.keyboardCuesOn"), GetBooleanParameter(SPI_GETKEYBOARDCUES)); // High contrast accessibility property HIGHCONTRAST contrast; contrast.cbSize = sizeof(HIGHCONTRAST); if (SystemParametersInfo(SPI_GETHIGHCONTRAST, sizeof(HIGHCONTRAST), &contrast, 0) != 0 && (contrast.dwFlags & HCF_HIGHCONTRASTON) == HCF_HIGHCONTRASTON) { SetBooleanProperty(TEXT("win.highContrast.on"), TRUE); } else { SetBooleanProperty(TEXT("win.highContrast.on"), FALSE); } SHELLFLAGSTATE sfs; ::SHGetSettings(&sfs, SSF_SHOWALLOBJECTS | SSF_SHOWATTRIBCOL); if (sfs.fShowAllObjects) { SetBooleanProperty(TEXT("awt.file.showHiddenFiles"), TRUE); } else { SetBooleanProperty(TEXT("awt.file.showHiddenFiles"), FALSE); } if (sfs.fShowAttribCol) { SetBooleanProperty(TEXT("awt.file.showAttribCol"), TRUE); } else { SetBooleanProperty(TEXT("awt.file.showAttribCol"), FALSE); } LPTSTR value; DWORD valueType; // Shell Icon BPP - only honored on platforms before XP value = getWindowsPropFromReg(TEXT("Control Panel\\Desktop\\WindowMetrics"), TEXT("Shell Icon BPP"), &valueType); if (value != NULL) { if (valueType == REG_SZ) { SetStringProperty(TEXT("win.icon.shellIconBPP"), value); } free(value); } // The following registry settings control the file chooser places bar // under the Windows L&F. These settings are not present by default, but // can be enabled using the TweakUI tool from Microsoft. For more info, // see http://msdn.microsoft.com/msdnmag/issues/1100/Registry/ // NoPlacesBar is a REG_DWORD, with values 0 or 1 value = getWindowsPropFromReg(TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\comdlg32"), TEXT("NoPlacesBar"), &valueType); if (value != NULL) { if (valueType == REG_DWORD) { SetBooleanProperty(TEXT("win.comdlg.noPlacesBar"), (BOOL)((int)*value != 0)); } free(value); } LPTSTR valueName = TEXT("PlaceN"); LPTSTR valueNameBuf = (LPTSTR)safe_Malloc((lstrlen(valueName) + 1) * sizeof(TCHAR)); lstrcpy(valueNameBuf, valueName); LPTSTR propKey = TEXT("win.comdlg.placesBarPlaceN"); LPTSTR propKeyBuf = (LPTSTR)safe_Malloc((lstrlen(propKey) + 1) * sizeof(TCHAR)); lstrcpy(propKeyBuf, propKey); int i = 0; do { valueNameBuf[5] = _T('0' + i++); propKeyBuf[25] = valueNameBuf[5]; LPTSTR key = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\comdlg32\\PlacesBar"); if ((value = getWindowsPropFromReg(key, valueNameBuf, &valueType)) != NULL) { if (valueType == REG_DWORD) { // Value is a CSIDL SetIntegerProperty(propKeyBuf, (int)*value); } else { // Value is a path SetStringProperty(propKeyBuf, value); } free(value); } } while (value != NULL); free(valueNameBuf); free(propKeyBuf); }