HRESULT OpenPropSeqStorage (DWORD dwMode, IStorage **ppStorage) { WStorage StgRoot; WStorage Stg; if (!DEX_GetProjectStorage(*StgRoot.ppv())) return E_UNEXPECTED; HRESULT hr = OpenStorage (g_cbPropertySequences, dwMode, StgRoot, Stg.ppi()); if (FAILED(hr)) { if (!(STGM_WRITE & dwMode) && !(STGM_READWRITE & dwMode)) return hr; RETURN_FAILED_HRESULT(StgRoot -> CreateStorage (g_cbPropertySequences, STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_TRANSACTED | STGM_CREATE, 0L, 0L, Stg.ppi())); RETURN_FAILED_HRESULT(Stg -> SetClass (CLSID_PropertyActionSequence)); } *ppStorage = Stg.detach(); return S_OK; }
int ObserverPlugin::QueryArchives(const TCHAR* lpFileName, Array<ArchiveQueryResult*>& result) { StorageGeneralInfo info; HANDLE hArchive = OpenStorage(lpFileName, &info); if ( hArchive ) { CloseStorage(hArchive); ArchiveQueryResult* pResult = new ArchiveQueryResult; pResult->uidFormat = m_pFormatInfo->uid; pResult->uidPlugin = m_uid; result.add(pResult); return 1; } return 0; }
bool SettingsXML::OpenKey(const wchar_t *regPath, uint access, BOOL abSilent /*= FALSE*/) { // That may occures if Basic settings and "Export" button was pressed _ASSERTE(!gpConEmu->IsResetBasicSettings() || ((access & KEY_WRITE)!=KEY_WRITE)); bool lbRc = false; HRESULT hr = S_OK; wchar_t szErr[512]; szErr[0] = 0; wchar_t szName[MAX_PATH]; const wchar_t* psz = NULL; IXMLDOMNode* pKey = NULL; IXMLDOMNode* pChild = NULL; bool bAllowCreate = (access & KEY_WRITE) == KEY_WRITE; CloseKey(); // на всякий if (!regPath || !*regPath) { return false; } if (!OpenStorage(access, szErr)) { goto wrap; } SAFETRY { _ASSERTE(mp_File != NULL); hr = mp_File->QueryInterface(IID_IXMLDOMNode, (void **)&pKey); if (FAILED(hr)) { _wsprintf(szErr, SKIPLEN(countof(szErr)) L"XML: Root node not found!\nErrCode=0x%08X", (DWORD)hr); goto wrap; } mi_Level = 0; while (*regPath) { // Получить следующий токен psz = wcschr(regPath, L'\\'); if (!psz) psz = regPath + _tcslen(regPath); lstrcpyn(szName, regPath, psz-regPath+1); // Найти в структуре XML pChild = FindItem(pKey, L"key", szName, bAllowCreate); pKey->Release(); pKey = pChild; pChild = NULL; mi_Level++; if (!pKey) { if (bAllowCreate) { _wsprintf(szErr, SKIPLEN(countof(szErr)) L"XML: Can't create key <%s>!", szName); } else { //_wsprintf(szErr, SKIPLEN(countof(szErr)) L"XML: key <%s> not found!", szName); szErr[0] = 0; // ошибку не показывать - настройки по умолчанию } goto wrap; } if (*psz == L'\\') { regPath = psz + 1; } else { break; } } // Нашли, запомнили mp_Key = pKey; pKey = NULL; #if 0 if (mp_Key) { SYSTEMTIME st; wchar_t szTime[32]; GetLocalTime(&st); _wsprintf(szTime, SKIPLEN(countof(szTime)) L"%04i-%02i-%02i %02i:%02i:%02i", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond); SetAttr(mp_Key, L"modified", szTime); SetAttr(mp_Key, L"build", gpConEmu->ms_ConEmuBuild); } #endif lbRc = true; } SAFECATCH { lstrcpy(szErr, L"Exception in SettingsXML::OpenKey"); lbRc = false; } wrap: SafeRelease(pChild); SafeRelease(pKey); if (!lbRc && szErr[0] && !abSilent) { MBoxA(szErr); } return lbRc; }