//------------------------------------------------------------------------- nsresult DataStruct::WriteCache(nsISupports* aData, uint32_t aDataLen) { // Get a new path and file to the temp directory nsCOMPtr<nsIFile> cacheFile ( getter_AddRefs(GetFileSpec(mCacheFileName)) ); if (cacheFile) { // remember the file name if (!mCacheFileName) { nsXPIDLCString fName; cacheFile->GetNativeLeafName(fName); mCacheFileName = nsCRT::strdup(fName); } // write out the contents of the clipboard // to the file //uint32_t bytes; nsCOMPtr<nsIOutputStream> outStr; NS_NewLocalFileOutputStream(getter_AddRefs(outStr), cacheFile); if (!outStr) return NS_ERROR_FAILURE; void* buff = nullptr; nsPrimitiveHelpers::CreateDataFromPrimitive ( mFlavor.get(), aData, &buff, aDataLen ); if ( buff ) { uint32_t ignored; outStr->Write(reinterpret_cast<char*>(buff), aDataLen, &ignored); nsMemory::Free(buff); return NS_OK; } } return NS_ERROR_FAILURE; }
// pop up the Save box for a template, and have it save a copy of the current document. void run_template_saver() { TemplateLooper *looper; BMessage *message; BMessenger *messenger; BFilePanel *panel; // create message to deliver when done message = new BMessage(M_TEMPLATE_SAVE); message->AddInt32("DocID", editor.curev->DocID); // create looper to deliver it to looper = new TemplateLooper(); looper->Run(); messenger = new BMessenger(NULL, looper); // set starting dir to that of template directory entry_ref start_dir; GetTemplateDirectoryRef(&start_dir); // create panel panel = new BFilePanel(B_SAVE_PANEL, messenger, &start_dir, 0, false, message, NULL, true); // set window title BString title; title << "Save as Template: " << GetFileSpec(editor.curev->filename); panel->Window()->SetTitle(title.String()); // and away we go if (TemplatePanel) delete TemplatePanel; TemplatePanel = panel; panel->Show(); }
bool wxExDirWithListView::OnDir(const std::string& dir) { if (wxConfigBase::Get()->ReadBool(_("Add folders"), true)) { wxExListItem(m_ListView, dir, GetFileSpec()).Insert(); } return true; }
//------------------------------------------------------------------------- nsresult DataStruct::ReadCache(nsISupports** aData, uint32_t* aDataLen) { // if we don't have a cache filename we are out of luck if (!mCacheFileName) return NS_ERROR_FAILURE; // get the path and file name nsCOMPtr<nsIFile> cacheFile ( getter_AddRefs(GetFileSpec(mCacheFileName)) ); bool exists; if ( cacheFile && NS_SUCCEEDED(cacheFile->Exists(&exists)) && exists ) { // get the size of the file int64_t fileSize; int64_t max32 = 0xFFFFFFFF; cacheFile->GetFileSize(&fileSize); if (fileSize > max32) return NS_ERROR_OUT_OF_MEMORY; uint32_t size = uint32_t(fileSize); // create new memory for the large clipboard data nsAutoArrayPtr<char> data(new char[size]); if ( !data ) return NS_ERROR_OUT_OF_MEMORY; // now read it all in nsCOMPtr<nsIInputStream> inStr; NS_NewLocalFileInputStream( getter_AddRefs(inStr), cacheFile); if (!cacheFile) return NS_ERROR_FAILURE; nsresult rv = inStr->Read(data, fileSize, aDataLen); // make sure we got all the data ok if (NS_SUCCEEDED(rv) && *aDataLen == size) { nsPrimitiveHelpers::CreatePrimitiveForData ( mFlavor.get(), data, fileSize, aData ); return *aData ? NS_OK : NS_ERROR_FAILURE; } // zero the return params *aData = nullptr; *aDataLen = 0; } return NS_ERROR_FAILURE; }
JSONElement LexerConf::ToJSON() const { JSONElement json = JSONElement::createObject(GetName()); json.addProperty("Name", GetName()); json.addProperty("Theme", GetThemeName()); json.addProperty("Flags", m_flags); json.addProperty("Id", GetLexerId()); json.addProperty("KeyWords0", GetKeyWords(0)); json.addProperty("KeyWords1", GetKeyWords(1)); json.addProperty("KeyWords2", GetKeyWords(2)); json.addProperty("KeyWords3", GetKeyWords(3)); json.addProperty("KeyWords4", GetKeyWords(4)); json.addProperty("Extensions", GetFileSpec()); JSONElement properties = JSONElement::createArray("Properties"); json.append(properties); StyleProperty::Map_t::const_iterator iter = m_properties.begin(); for(; iter != m_properties.end(); ++iter) { properties.arrayAppend(iter->second.ToJSON()); } return json; }
HRESULT ScaDbsRead( __inout SCA_DB** ppsdList, __in SCA_ACTION saAction ) { HRESULT hr = S_OK; UINT er = ERROR_SUCCESS; PMSIHANDLE hView; PMSIHANDLE hRec; PMSIHANDLE hViewFileSpec = NULL; LPWSTR pwzData = NULL; LPWSTR pwzId = NULL; LPWSTR pwzComponent = NULL; SCA_DB* psd = NULL; if (S_OK != WcaTableExists(L"SqlDatabase")) { WcaLog(LOGMSG_VERBOSE, "Skipping ScaCreateDatabase() - SqlDatabase table not present"); ExitFunction1(hr = S_FALSE); } if (S_OK == WcaTableExists(L"SqlFileSpec")) { hr = WcaOpenView(vcsSqlFileSpecQuery, &hViewFileSpec); ExitOnFailure(hr, "failed to open view on SqlFileSpec table"); } // loop through all the sql databases hr = WcaOpenExecuteView(vcsSqlDatabaseQuery, &hView); ExitOnFailure(hr, "Failed to open view on SqlDatabase table"); while (S_OK == (hr = WcaFetchRecord(hView, &hRec))) { BOOL fHasComponent = FALSE; INSTALLSTATE isInstalled = INSTALLSTATE_UNKNOWN; INSTALLSTATE isAction = INSTALLSTATE_UNKNOWN; hr = WcaGetRecordString(hRec, sdqSqlDb, &pwzId); ExitOnFailure(hr, "Failed to get SqlDatabase.SqlDb"); hr = WcaGetRecordString(hRec, sdqComponent, &pwzComponent); ExitOnFailure1(hr, "Failed to get Component for database: '%ls'", psd->wzKey); if (pwzComponent && *pwzComponent) { fHasComponent = TRUE; er = ::MsiGetComponentStateW(WcaGetInstallHandle(), pwzComponent, &isInstalled, &isAction); hr = HRESULT_FROM_WIN32(er); ExitOnFailure1(hr, "Failed to get state for component: %ls", pwzComponent); // If we're doing install but the Component is not being installed or we're doing // uninstall but the Component is not being uninstalled, skip it. if ((WcaIsInstalling(isInstalled, isAction) && SCA_ACTION_INSTALL != saAction) || (WcaIsUninstalling(isInstalled, isAction) && SCA_ACTION_UNINSTALL != saAction)) { continue; } } hr = NewDb(&psd); ExitOnFailure1(hr, "Failed to allocate memory for new database: %D", pwzId); hr = ::StringCchCopyW(psd->wzKey, countof(psd->wzKey), pwzId); ExitOnFailure1(hr, "Failed to copy SqlDatabase.SqlDbL: %ls", pwzId); hr = ::StringCchCopyW(psd->wzComponent, countof(psd->wzComponent), pwzComponent); ExitOnFailure1(hr, "Failed to copy SqlDatabase.Component_: %ls", pwzComponent); psd->fHasComponent = fHasComponent; psd->isInstalled = isInstalled; psd->isAction = isAction; hr = WcaGetRecordFormattedString(hRec, sdqServer, &pwzData); ExitOnFailure1(hr, "Failed to get Server for database: '%ls'", psd->wzKey); hr = ::StringCchCopyW(psd->wzServer, countof(psd->wzServer), pwzData); ExitOnFailure1(hr, "Failed to copy server string to database object:%ls", pwzData); hr = WcaGetRecordFormattedString(hRec, sdqInstance, &pwzData); ExitOnFailure1(hr, "Failed to get Instance for database: '%ls'", psd->wzKey); hr = ::StringCchCopyW(psd->wzInstance, countof(psd->wzInstance), pwzData); ExitOnFailure1(hr, "Failed to copy instance string to database object:%ls", pwzData); hr = WcaGetRecordFormattedString(hRec, sdqDatabase, &pwzData); ExitOnFailure1(hr, "Failed to get Database for database: '%ls'", psd->wzKey); hr = ::StringCchCopyW(psd->wzDatabase, countof(psd->wzDatabase), pwzData); ExitOnFailure1(hr, "Failed to copy database string to database object:%ls", pwzData); hr = WcaGetRecordInteger(hRec, sdqAttributes, &psd->iAttributes); ExitOnFailure(hr, "Failed to get SqlDatabase.Attributes"); hr = WcaGetRecordFormattedString(hRec, sdqUser, &pwzData); ExitOnFailure1(hr, "Failed to get User record for database: '%ls'", psd->wzKey); // if a user was specified if (*pwzData) { psd->fUseIntegratedAuth = FALSE; hr = ScaGetUser(pwzData, &psd->scau); ExitOnFailure1(hr, "Failed to get user information for database: '%ls'", psd->wzKey); } else { psd->fUseIntegratedAuth = TRUE; // integrated authorization doesn't have a User record } hr = WcaGetRecordString(hRec, sdqDbFileSpec, &pwzData); ExitOnFailure1(hr, "Failed to get Database FileSpec for database: '%ls'", psd->wzKey); // if a database filespec was specified if (*pwzData) { hr = GetFileSpec(hViewFileSpec, pwzData, &psd->sfDb); ExitOnFailure1(hr, "failed to get FileSpec for: %ls", pwzData); if (S_OK == hr) { psd->fHasDbSpec = TRUE; } } hr = WcaGetRecordString(hRec, sdqLogFileSpec, &pwzData); ExitOnFailure1(hr, "Failed to get Log FileSpec for database: '%ls'", psd->wzKey); // if a log filespec was specified if (*pwzData) { hr = GetFileSpec(hViewFileSpec, pwzData, &psd->sfLog); ExitOnFailure1(hr, "failed to get FileSpec for: %ls", pwzData); if (S_OK == hr) { psd->fHasLogSpec = TRUE; } } *ppsdList = AddDbToList(*ppsdList, psd); psd = NULL; // set the db NULL so it doesn't accidentally get freed below } if (E_NOMOREITEMS == hr) { hr = S_OK; } ExitOnFailure(hr, "Failure occured while processing SqlDatabase table"); LExit: if (psd) { ScaDbsFreeList(psd); } ReleaseStr(pwzComponent); ReleaseStr(pwzId); ReleaseStr(pwzData); return hr; }
wxXmlNode* LexerConf::ToXml() const { // convert the lexer back xml node wxXmlNode* node = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("Lexer")); // set the lexer name node->AddProperty(wxT("Name"), GetName()); node->AddProperty("Theme", GetThemeName()); node->AddProperty("IsActive", IsActive() ? "Yes" : "No"); node->AddAttribute("UseCustomTextSelFgColour", IsUseCustomTextSelectionFgColour() ? "Yes" : "No"); node->AddProperty(wxT("StylingWithinPreProcessor"), BoolToString(GetStyleWithinPreProcessor())); wxString strId; strId << GetLexerId(); node->AddProperty(wxT("Id"), strId); // set the keywords node wxXmlNode* keyWords0 = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("KeyWords0")); XmlUtils::SetNodeContent(keyWords0, GetKeyWords(0)); node->AddChild(keyWords0); wxXmlNode* keyWords1 = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("KeyWords1")); XmlUtils::SetNodeContent(keyWords1, GetKeyWords(1)); node->AddChild(keyWords1); wxXmlNode* keyWords2 = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("KeyWords2")); XmlUtils::SetNodeContent(keyWords2, GetKeyWords(2)); node->AddChild(keyWords2); wxXmlNode* keyWords3 = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("KeyWords3")); XmlUtils::SetNodeContent(keyWords3, GetKeyWords(3)); node->AddChild(keyWords3); wxXmlNode* keyWords4 = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("KeyWords4")); XmlUtils::SetNodeContent(keyWords4, GetKeyWords(4)); node->AddChild(keyWords4); // set the extensions node wxXmlNode* extesions = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("Extensions")); XmlUtils::SetNodeContent(extesions, GetFileSpec()); node->AddChild(extesions); // set the properties wxXmlNode* properties = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("Properties")); std::map<long, StyleProperty>::const_iterator iter = m_properties.begin(); for(; iter != m_properties.end(); ++iter) { StyleProperty p = iter->second; wxXmlNode* property = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("Property")); strId.Clear(); strId << p.GetId(); property->AddProperty(wxT("Id"), strId); property->AddProperty(wxT("Name"), p.GetName()); property->AddProperty(wxT("Bold"), BoolToString(p.IsBold())); property->AddProperty(wxT("Face"), p.GetFaceName()); property->AddProperty(wxT("Colour"), p.GetFgColour()); property->AddProperty(wxT("BgColour"), p.GetBgColour()); property->AddProperty(wxT("Italic"), BoolToString(p.GetItalic())); property->AddProperty(wxT("Underline"), BoolToString(p.GetUnderlined())); property->AddProperty(wxT("EolFilled"), BoolToString(p.GetEolFilled())); strId.Clear(); strId << p.GetAlpha(); property->AddProperty(wxT("Alpha"), strId); wxString strSize; strSize << p.GetFontSize(); property->AddProperty(wxT("Size"), strSize); properties->AddChild(property); } node->AddChild(properties); return node; }
bool wxExDirWithListView::OnFile(const std::string& file) { wxExListItem(m_ListView, file, GetFileSpec()).Insert(); return true; }