long reg_query_winscp_value_ex(HKEY Key, const char * ValueName, unsigned long * /*Reserved*/, unsigned long * Type, uint8_t * Data, unsigned long * DataSize) { long R; DebugAssert(GetConfiguration() != nullptr); THierarchicalStorage * Storage = reinterpret_cast<THierarchicalStorage *>(Key); AnsiString Value; if (Storage == nullptr) { if (UnicodeString(ValueName) == L"RandSeedFile") { Value = AnsiString(GetConfiguration()->GetRandomSeedFileName()); R = ERROR_SUCCESS; } else { DebugFail(); R = ERROR_READ_FAULT; } } else { if (Storage->ValueExists(ValueName)) { Value = AnsiString(Storage->ReadStringRaw(ValueName, L"")); R = ERROR_SUCCESS; } else { R = ERROR_READ_FAULT; } } if (R == ERROR_SUCCESS) { DebugAssert(Type != nullptr); *Type = REG_SZ; char * DataStr = reinterpret_cast<char *>(Data); int sz = static_cast<int>(*DataSize); if (sz > 0) { strncpy(DataStr, Value.c_str(), sz); DataStr[sz - 1] = '\0'; } *DataSize = static_cast<uint32_t>(strlen(DataStr)); } return R; }
//--------------------------------------------------------------------------- long reg_query_winscp_value_ex(HKEY Key, const char * ValueName, unsigned long * /*Reserved*/, unsigned long * Type, unsigned char * Data, unsigned long * DataSize) { long R; assert(Configuration != NULL); THierarchicalStorage * Storage = reinterpret_cast<THierarchicalStorage *>(Key); AnsiString Value; if (Storage == NULL) { if (UnicodeString(ValueName) == L"RandSeedFile") { Value = Configuration->RandomSeedFileName; R = ERROR_SUCCESS; } else { FAIL; R = ERROR_READ_FAULT; } } else { if (Storage->ValueExists(ValueName)) { Value = Storage->ReadStringRaw(ValueName, L""); R = ERROR_SUCCESS; } else { R = ERROR_READ_FAULT; } } if (R == ERROR_SUCCESS) { assert(Type != NULL); *Type = REG_SZ; char * DataStr = reinterpret_cast<char *>(Data); strncpy(DataStr, Value.c_str(), *DataSize); DataStr[*DataSize - 1] = '\0'; *DataSize = strlen(DataStr); } return R; }