Vulpix, you can remane that key as unsane said.
unsane, I wonder why that key is needed at all? Can't you just loop through all settings until you find one that doesn't exist?
Smth like that:
for (lvi.iItem = 0; ; lvi.iItem++)
{
mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV4, lvi.iItem);
char *szIPv4 = db_get_sa(NULL, MODULE, setting);
if (szIPv4 == NULL) break; // break if setting doesn't exist
mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV6, lvi.iItem);
char *szIPv6 = db_get_sa(NULL, MODULE, setting);
if (szIPv6 == NULL) {
mir_free(szIPv4);
break; // break if setting doesn't exist
}
mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PKEY, lvi.iItem);
char *szKey = db_get_sa(NULL, MODULE, setting);
if (szKey == NULL) {
mir_free(szIPv4);
mir_free(szIPv6);
break; // break if setting doesn't exist
}
lvi.iImage = -1;
lvi.mask = LVIF_TEXT | LVIF_IMAGE;
lvi.iSubItem = 0;
lvi.pszText = szIPv4;
SendMessage(hwndList, LVM_INSERTITEMA, 0, (LPARAM)&lvi);
lvi.iSubItem = 1;
lvi.pszText = szIPv6;
SendMessage(hwndList, LVM_SETITEMA, 0, (LPARAM)&lvi);
mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PORT, lvi.iItem);
int port = db_get_w(NULL, MODULE, setting, 0);
if (port > 0)
{
char portNum[10];
itoa(port, portNum, 10);
lvi.pszText = mir_strdup(portNum);
}
lvi.iSubItem = 2;
SendMessage(hwndList, LVM_SETITEMA, 0, (LPARAM)&lvi);
lvi.iSubItem = 3;
lvi.pszText = szKey;
SendMessage(hwndList, LVM_SETITEMA, 0, (LPARAM)&lvi);
lvi.mask = LVIF_IMAGE;
lvi.iSubItem = 4;
lvi.iImage = 0;
ListView_SetItem(hwndList, &lvi);
lvi.iSubItem = 5;
lvi.iImage = 1;
ListView_SetItem(hwndList, &lvi);
}