void ReadInternalAssociations(CObjectVector<CExtInfo> &items) { items.Clear(); NSynchronization::CCriticalSectionLock lock(g_CriticalSection); CKey associationsKey; if (associationsKey.Open(HKEY_CURRENT_USER, kAssociationsPath, KEY_READ) != ERROR_SUCCESS) return; CSysStringVector extNames; associationsKey.EnumKeys(extNames); for(int i = 0; i < extNames.Size(); i++) { const CSysString extName = extNames[i]; CExtInfo extInfo; // extInfo.Enabled = false; extInfo.Ext = GetUnicodeString(extName); CKey key; if (key.Open(associationsKey, extName, KEY_READ) != ERROR_SUCCESS) return; UString pluginsString; key.QueryValue(kExtPlugins, pluginsString); SplitString(pluginsString, extInfo.Plugins); /* if (key.QueryValue(kExtEnabled, extInfo.Enabled) != ERROR_SUCCESS) extInfo.Enabled = false; */ items.Add(extInfo); } }
void ReadExtractionInfo(NExtract::CInfo &info) { info.Paths.Clear(); info.PathMode = NExtract::NPathMode::kCurrentPathnames; info.OverwriteMode = NExtract::NOverwriteMode::kAskBefore; info.ShowPassword = false; NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection); CKey extractionKey; if(extractionKey.Open(HKEY_CURRENT_USER, GetKeyPath(kExtractionKeyName), KEY_READ) != ERROR_SUCCESS) return; { CKey pathHistoryKey; if(pathHistoryKey.Open(extractionKey, kExtractionPathHistoryKeyName, KEY_READ) == ERROR_SUCCESS) { for (;;) { wchar_t numberString[16]; ConvertUInt64ToString(info.Paths.Size(), numberString); UString path; if (pathHistoryKey.QueryValue(numberString, path) != ERROR_SUCCESS) break; info.Paths.Add(path); } } } UInt32 extractModeIndex; if (extractionKey.QueryValue(kExtractionExtractModeValueName, extractModeIndex) == ERROR_SUCCESS) { switch (extractModeIndex) { case NExtract::NPathMode::kFullPathnames: case NExtract::NPathMode::kCurrentPathnames: case NExtract::NPathMode::kNoPathnames: info.PathMode = NExtract::NPathMode::EEnum(extractModeIndex); break; } } UInt32 overwriteModeIndex; if (extractionKey.QueryValue(kExtractionOverwriteModeValueName, overwriteModeIndex) == ERROR_SUCCESS) { switch (overwriteModeIndex) { case NExtract::NOverwriteMode::kAskBefore: case NExtract::NOverwriteMode::kWithoutPrompt: case NExtract::NOverwriteMode::kSkipExisting: case NExtract::NOverwriteMode::kAutoRename: case NExtract::NOverwriteMode::kAutoRenameExisting: info.OverwriteMode = NExtract::NOverwriteMode::EEnum(overwriteModeIndex); break; } } if (extractionKey.QueryValue(kExtractionShowPasswordValueName, info.ShowPassword) != ERROR_SUCCESS) info.ShowPassword = false; }
void CInfo::Load() { ArcPaths.Clear(); Formats.Clear(); Level = 5; ArcType = L"7z"; ShowPassword = false; EncryptHeaders = false; CS_LOCK CKey key; if (OpenMainKey(key, kKeyName) != ERROR_SUCCESS) return; key.GetValue_Strings(kArcHistory, ArcPaths); { CKey optionsKey; if (optionsKey.Open(key, kOptionsKeyName, KEY_READ) == ERROR_SUCCESS) { CSysStringVector formatIDs; optionsKey.EnumKeys(formatIDs); for (int i = 0; i < formatIDs.Size(); i++) { CKey fk; CFormatOptions fo; fo.FormatID = formatIDs[i]; if (fk.Open(optionsKey, fo.FormatID, KEY_READ) == ERROR_SUCCESS) { GetRegString(fk, kOptions, fo.Options); GetRegString(fk, kMethod, fo.Method); GetRegString(fk, kEncryptionMethod, fo.EncryptionMethod); GetRegUInt32(fk, kLevel, fo.Level); GetRegUInt32(fk, kDictionary, fo.Dictionary); GetRegUInt32(fk, kOrder, fo.Order); GetRegUInt32(fk, kBlockSize, fo.BlockLogSize); GetRegUInt32(fk, kNumThreads, fo.NumThreads); Formats.Add(fo); } } } } UString a; if (key.QueryValue(kArchiver, a) == ERROR_SUCCESS) ArcType = a; key.GetValue_IfOk(kLevel, Level); key.GetValue_IfOk(kShowPassword, ShowPassword); key.GetValue_IfOk(kEncryptHeaders, EncryptHeaders); }
void CInfo::Load() { ArcPaths.Clear(); Formats.Clear(); Level = 5; ArcType = L"7z"; ShowPassword = false; EncryptHeaders = false; CS_LOCK CKey key; if (OpenMainKey(key, kKeyName) != ERROR_SUCCESS) return; Key_Get_BoolPair(key, kNtSecur, NtSecurity); Key_Get_BoolPair(key, kAltStreams, AltStreams); Key_Get_BoolPair(key, kHardLinks, HardLinks); Key_Get_BoolPair(key, kSymLinks, SymLinks); key.GetValue_Strings(kArcHistory, ArcPaths); { CKey optionsKey; if (optionsKey.Open(key, kOptionsKeyName, KEY_READ) == ERROR_SUCCESS) { CSysStringVector formatIDs; optionsKey.EnumKeys(formatIDs); FOR_VECTOR (i, formatIDs) { CKey fk; CFormatOptions fo; fo.FormatID = formatIDs[i]; if (fk.Open(optionsKey, fo.FormatID, KEY_READ) == ERROR_SUCCESS) { GetRegString(fk, kOptions, fo.Options); GetRegString(fk, kMethod, fo.Method); GetRegString(fk, kEncryptionMethod, fo.EncryptionMethod); GetRegUInt32(fk, kLevel, fo.Level); GetRegUInt32(fk, kDictionary, fo.Dictionary); GetRegUInt32(fk, kOrder, fo.Order); GetRegUInt32(fk, kBlockSize, fo.BlockLogSize); GetRegUInt32(fk, kNumThreads, fo.NumThreads); Formats.Add(fo); } } }
void ReadRegLang(UString &langFile) { langFile.Empty(); CKey key; if (key.Open(HKEY_CURRENT_USER, kCUBasePath, KEY_READ) == ERROR_SUCCESS) key.QueryValue(kLangValueName, langFile); }
void ReadWorkDirInfo(NWorkDir::CInfo &info) { info.SetDefault(); NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection); CKey optionsKey; if(optionsKey.Open(HKEY_CURRENT_USER, GetKeyPath(kOptionsInfoKeyName), KEY_READ) != ERROR_SUCCESS) return; UInt32 dirType; if (optionsKey.QueryValue(kWorkDirTypeValueName, dirType) != ERROR_SUCCESS) return; switch (dirType) { case NWorkDir::NMode::kSystem: case NWorkDir::NMode::kCurrent: case NWorkDir::NMode::kSpecified: info.Mode = NWorkDir::NMode::EEnum(dirType); } UString sysWorkDir; if (optionsKey.QueryValue(kWorkDirPathValueName, sysWorkDir) != ERROR_SUCCESS) { info.Path.Empty(); if (info.Mode == NWorkDir::NMode::kSpecified) info.Mode = NWorkDir::NMode::kSystem; } info.Path = GetUnicodeString(sysWorkDir); if (optionsKey.QueryValue(kTempRemovableOnlyValueName, info.ForRemovableOnly) != ERROR_SUCCESS) info.SetForRemovableOnlyDefault(); }
void ReadRegEditor(UString &editorPath) { editorPath.Empty(); CKey key; if (key.Open(HKEY_CURRENT_USER, kCU_FMPath, KEY_READ) == ERROR_SUCCESS) key.QueryValue(kEditor, editorPath); }
bool ReadUi32Val(const TCHAR *name, UInt32 &value) { CKey key; if (key.Open(HKEY_CURRENT_USER, kCUBasePath, KEY_READ) != ERROR_SUCCESS) return false; return key.QueryValue(name, value) == ERROR_SUCCESS; }
void CWindowInfo::Read(bool &windowPosDefined, bool &panelInfoDefined) { windowPosDefined = false; panelInfoDefined = false; NSynchronization::CCriticalSectionLock lock(g_CS); CKey key; if (key.Open(HKEY_CURRENT_USER, kCUBasePath, KEY_READ) != ERROR_SUCCESS) return; CByteBuffer buf; if (QueryBuf(key, kPositionValueName, buf, kWindowPositionHeaderSize)) { Get32(buf, rect.left); Get32(buf + 4, rect.top); Get32(buf + 8, rect.right); Get32(buf + 12, rect.bottom); GetBool(buf + 16, maximized); windowPosDefined = true; } if (QueryBuf(key, kPanelsInfoValueName, buf, kPanelsInfoHeaderSize)) { Get32(buf, numPanels); Get32(buf + 4, currentPanel); Get32(buf + 8, splitterPos); panelInfoDefined = true; } return; }
static bool ReadValue(const TCHAR *value, UInt32 &result) { NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection); CKey optionsKey; if(optionsKey.Open(HKEY_CURRENT_USER, GetKeyPath(kOptionsInfoKeyName), KEY_READ) != ERROR_SUCCESS) return false; return (optionsKey.QueryValue(value, result) == ERROR_SUCCESS); }
bool CheckShellExtensionInfo(const CSysString &extension, UString &iconPath, int &iconIndex) { NSynchronization::CCriticalSectionLock lock(g_CriticalSection); if (!CheckShellExtensionInfo2(extension, iconPath, iconIndex)) return false; CKey extProgKey; return (extProgKey.Open(HKEY_CLASSES_ROOT, GetExtProgramKeyName(extension), KEY_READ) == ERROR_SUCCESS); }
static void ReadStringList(LPCTSTR valueName, UStringVector &folders) { folders.Clear(); NSynchronization::CCriticalSectionLock lock(g_CS); CKey key; if (key.Open(HKEY_CURRENT_USER, kCUBasePath, KEY_READ) == ERROR_SUCCESS) key.GetValue_Strings(valueName, folders); }
bool ReadPanelPath(UInt32 panel, UString &path) { NSynchronization::CCriticalSectionLock lock(g_CS); CKey key; if (key.Open(HKEY_CURRENT_USER, kCUBasePath, KEY_READ) != ERROR_SUCCESS) return false; return (key.QueryValue(GetPanelPathName(panel), path) == ERROR_SUCCESS); }
static bool CheckHandlerCommon(const CSysString &keyName, UInt32 wow) { CKey key; if (key.Open(HKEY_CLASSES_ROOT, keyName, KEY_READ | wow) != ERROR_SUCCESS) return false; CSysString value; if (key.QueryValue(NULL, value) != ERROR_SUCCESS) return false; return StringsAreEqualNoCase_Ascii(value, k_Clsid); }
static bool CheckDragDropMenuHandlerCommon(const CSysString &keyName) { NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection); CKey key; if (key.Open(HKEY_CLASSES_ROOT, GetFullDragDropMenuKeyName(keyName), KEY_READ) != ERROR_SUCCESS) return false; CSysString value; if (key.QueryValue(NULL, value) != ERROR_SUCCESS) return false; return (value.CompareNoCase(kExtensionCLSID) == 0); }
static bool ReadOption(const TCHAR *value, bool defaultValue) { CKey key; if (key.Open(HKEY_CURRENT_USER, kCU_FMPath, KEY_READ) == ERROR_SUCCESS) { bool enabled; if (key.QueryValue(value, enabled) == ERROR_SUCCESS) return enabled; } return defaultValue; }
static bool CheckHandlerCommon(const CSysString &keyName) { NSynchronization::CCriticalSectionLock lock(g_CS); CKey key; if (key.Open(HKEY_CLASSES_ROOT, keyName, KEY_READ) != ERROR_SUCCESS) return false; CSysString value; if (key.QueryValue(NULL, value) != ERROR_SUCCESS) return false; return StringsAreEqualNoCase_Ascii(value, kExtensionCLSID); }
static bool ReadOption(const TCHAR *value, bool defaultValue) { NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection); CKey optionsKey; if(optionsKey.Open(HKEY_CURRENT_USER, GetKeyPath(kOptionsInfoKeyName), KEY_READ) != ERROR_SUCCESS) return defaultValue; bool enabled; if (optionsKey.QueryValue(value, enabled) != ERROR_SUCCESS) return defaultValue; return enabled; }
static bool CheckHandlerCommon(const CSysString &keyName) { NSynchronization::CCriticalSectionLock lock(g_CS); CKey key; if (key.Open(HKEY_CLASSES_ROOT, keyName, KEY_READ) != ERROR_SUCCESS) return false; CSysString value; if (key.QueryValue(NULL, value) != ERROR_SUCCESS) return false; value.MakeUpper(); return (value.Compare(kExtensionCLSID) == 0); }
bool ReadInternalAssociation(const wchar_t *ext, CExtInfo &extInfo) { NSynchronization::CCriticalSectionLock lock(g_CriticalSection); CKey key; if (key.Open(HKEY_CURRENT_USER, CSysString(kAssociationsPath TEXT(STRING_PATH_SEPARATOR)) + GetSystemString(ext), KEY_READ) != ERROR_SUCCESS) return false; UString pluginsString; key.QueryValue(kExtPlugins, pluginsString); SplitString(pluginsString, extInfo.Plugins); return true; }
bool CShellExtInfo::ReadFromRegistry(HKEY hkey, const CSysString &ext) { ProgramKey.Empty(); IconPath.Empty(); IconIndex = -1; // NSynchronization::CCriticalSectionLock lock(g_CriticalSection); { CKey extKey; if (extKey.Open(hkey, GetExtKeyPath(hkey, ext), KEY_READ) != ERROR_SUCCESS) return false; if (extKey.QueryValue(NULL, ProgramKey) != ERROR_SUCCESS) return false; } { CKey iconKey; if (iconKey.Open(hkey, GetFullKeyPath(hkey, ProgramKey + CSysString(TEXT(CHAR_PATH_SEPARATOR)) + kDefaultIconKeyName), KEY_READ) == ERROR_SUCCESS) { UString value; if (iconKey.QueryValue(NULL, value) == ERROR_SUCCESS) { int pos = value.ReverseFind(L','); IconPath = value; if (pos >= 0) { const wchar_t *end; Int32 index = ConvertStringToInt32((const wchar_t *)value + pos + 1, &end); if (*end == 0) { // 9.31: if there is no icon index, we use -1. Is it OK? if (pos != (int)value.Len() - 1) IconIndex = (int)index; IconPath.SetFrom(value, pos); } } } } } return true; }
static void RegisterExt(LPCTSTR lpszExt, LPCTSTR lpszProgID, UINT nIDTypeName, LPCTSTR* rglpszSymbols, LPCTSTR* rglpszExtRegister, LPCTSTR* rglpszRegister, int nIcon) { // don't overwrite anything with the extensions CString strWhole; VERIFY(strWhole.LoadString(nIDTypeName)); CString str; AfxExtractSubString(str, strWhole, DOCTYPE_PROGID); rglpszSymbols[1] = lpszProgID; rglpszSymbols[4] = str; rglpszSymbols[6] = lpszExt; TCHAR buf[10]; wsprintf(buf, _T("%d"), nIcon); rglpszSymbols[7] = buf; // check for .ext and progid CKey key; if (!key.Open(HKEY_CLASSES_ROOT, lpszExt)) // .ext doesn't exist RegisterHelper(rglpszExtRegister, rglpszSymbols, TRUE); key.Close(); if (!key.Open(HKEY_CLASSES_ROOT, lpszProgID)) // ProgID doesn't exist (i.e. txtfile) RegisterHelper(rglpszRegister, rglpszSymbols, TRUE); }
static bool CheckShellExtensionInfo2(const CSysString &extension, UString &iconPath, int &iconIndex) { iconIndex = -1; iconPath.Empty(); NSynchronization::CCriticalSectionLock lock(g_CriticalSection); CKey extKey; if (extKey.Open(HKEY_CLASSES_ROOT, GetExtensionKeyName(extension), KEY_READ) != ERROR_SUCCESS) return false; CSysString programNameValue; if (extKey.QueryValue(NULL, programNameValue) != ERROR_SUCCESS) return false; CSysString extProgramKeyName = GetExtProgramKeyName(extension); UString programNameValueU = GetUnicodeString(programNameValue); if (programNameValueU.CompareNoCase(GetUnicodeString(extProgramKeyName)) != 0) return false; CKey iconKey; if (extKey.Open(HKEY_CLASSES_ROOT, extProgramKeyName + CSysString(TEXT(CHAR_PATH_SEPARATOR)) + kDefaultIconKeyName, KEY_READ) != ERROR_SUCCESS) return false; UString value; if (extKey.QueryValue(NULL, value) == ERROR_SUCCESS) { int pos = value.ReverseFind(L','); iconPath = value; if (pos >= 0) { const wchar_t *end; UInt64 index = ConvertStringToUInt64((const wchar_t *)value + pos + 1, &end); if (*end == 0) { iconIndex = (int)index; iconPath = value.Left(pos); } } } return true; }
LONG CKey::RecurseDeleteKey(LPCTSTR subKeyName) throw() { CKey key; LONG res = key.Open(_object, subKeyName, KEY_READ | KEY_WRITE); if (res != ERROR_SUCCESS) return res; FILETIME fileTime; const UInt32 kBufferSize = MAX_PATH + 1; // 256 in ATL DWORD size = kBufferSize; TCHAR buffer[kBufferSize]; while (RegEnumKeyEx(key._object, 0, buffer, &size, NULL, NULL, NULL, &fileTime) == ERROR_SUCCESS) { res = key.RecurseDeleteKey(buffer); if (res != ERROR_SUCCESS) return res; size = kBufferSize; } key.Close(); return DeleteSubKey(subKeyName); }
void CListViewInfo::Read(const UString &id) { Clear(); CByteBuffer buf; UInt32 size; { NSynchronization::CCriticalSectionLock lock(g_CS); CKey key; if (key.Open(HKEY_CURRENT_USER, kCulumnsKeyName, KEY_READ) != ERROR_SUCCESS) return; if (key.QueryValue(GetSystemString(id), buf, size) != ERROR_SUCCESS) return; } if (size < kListViewHeaderSize) return; UInt32 version; Get32(buf, version); if (version != kListViewVersion) return; Get32(buf + 4, SortID); GetBool(buf + 8, Ascending); size -= kListViewHeaderSize; if (size % kColumnInfoSize != 0) return; unsigned numItems = size / kColumnInfoSize; Columns.ClearAndReserve(numItems); for (unsigned i = 0; i < numItems; i++) { CColumnInfo column; const Byte *p = buf + kListViewHeaderSize + i * kColumnInfoSize; Get32(p, column.PropID); GetBool(p + 4, column.IsVisible); Get32(p + 8, column.Width); Columns.AddInReserved(column); } }
static LONG OpenMainKey(CKey &key, LPCTSTR keyName) { return key.Open(HKEY_CURRENT_USER, GetKeyPath(keyName), KEY_READ); }
void ReadCompressionInfo(NCompression::CInfo &info) { info.HistoryArchives.Clear(); // info.Solid = true; // info.MultiThread = IsMultiProcessor(); info.FormatOptionsVector.Clear(); info.Level = 5; info.ArchiveType = L"7z"; // definedStatus.Maximize = false; info.ShowPassword = false; info.EncryptHeaders = false; NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection); CKey compressionKey; if(compressionKey.Open(HKEY_CURRENT_USER, GetKeyPath(kCompressionKeyName), KEY_READ) != ERROR_SUCCESS) return; { CKey historyArchivesKey; if(historyArchivesKey.Open(compressionKey, kCompressionHistoryArchivesKeyName, KEY_READ) == ERROR_SUCCESS) { for (;;) { wchar_t numberString[16]; ConvertUInt64ToString(info.HistoryArchives.Size(), numberString); UString path; if (historyArchivesKey.QueryValue(numberString, path) != ERROR_SUCCESS) break; info.HistoryArchives.Add(path); } } } /* bool solid = false; if (compressionKey.QueryValue(kSolid, solid) == ERROR_SUCCESS) info.Solid = solid; bool multiThread = false; if (compressionKey.QueryValue(kMultiThread, multiThread) == ERROR_SUCCESS) info.MultiThread = multiThread; */ { CKey optionsKey; if(optionsKey.Open(compressionKey, kCompressionOptionsKeyName, KEY_READ) == ERROR_SUCCESS) { CSysStringVector formatIDs; optionsKey.EnumKeys(formatIDs); for(int i = 0; i < formatIDs.Size(); i++) { CKey formatKey; NCompression::CFormatOptions fo; fo.FormatID = formatIDs[i]; if(formatKey.Open(optionsKey, fo.FormatID, KEY_READ) == ERROR_SUCCESS) { GetRegString(formatKey, kCompressionOptions, fo.Options); GetRegString(formatKey, kCompressionMethod, fo.Method); GetRegString(formatKey, kEncryptionMethod, fo.EncryptionMethod); GetRegUInt32(formatKey, kCompressionLevel, fo.Level); GetRegUInt32(formatKey, kCompressionDictionary, fo.Dictionary); GetRegUInt32(formatKey, kCompressionOrder, fo.Order); GetRegUInt32(formatKey, kCompressionBlockSize, fo.BlockLogSize); GetRegUInt32(formatKey, kCompressionNumThreads, fo.NumThreads); info.FormatOptionsVector.Add(fo); } } } } UInt32 level; if (compressionKey.QueryValue(kCompressionLevelValueName, level) == ERROR_SUCCESS) info.Level = level; CSysString archiveType; if (compressionKey.QueryValue(kCompressionLastFormatValueName, archiveType) == ERROR_SUCCESS) info.ArchiveType = GetUnicodeString(archiveType); if (compressionKey.QueryValue(kCompressionShowPasswordValueName, info.ShowPassword) != ERROR_SUCCESS) info.ShowPassword = false; if (compressionKey.QueryValue(kCompressionEncryptHeadersValueName, info.EncryptHeaders) != ERROR_SUCCESS) info.EncryptHeaders = false; /* if (compressionKey.QueryValue(kCompressionLevelValueName, info.Maximize) == ERROR_SUCCESS) definedStatus.Maximize = true; */ }