static INT_PTR CALLBACK WarnIniChangeDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) { static warnSettingChangeInfo_t *warnInfo; switch(message) { case WM_INITDIALOG: { char szSettingName[256]; const TCHAR *pszSecurityInfo; warnInfo = (warnSettingChangeInfo_t*)lParam; TranslateDialogDefault(hwndDlg); SetDlgItemText(hwndDlg, IDC_ININAME, warnInfo->szIniPath); mir_strcpy(szSettingName, warnInfo->szSection); mir_strcat(szSettingName, " / "); mir_strcat(szSettingName, warnInfo->szName); SetDlgItemTextA(hwndDlg, IDC_SETTINGNAME, szSettingName); SetDlgItemTextA(hwndDlg, IDC_NEWVALUE, warnInfo->szValue); if (IsInSpaceSeparatedList(warnInfo->szSection, warnInfo->szSafeSections)) pszSecurityInfo = LPGENT("This change is known to be safe."); else if (IsInSpaceSeparatedList(warnInfo->szSection, warnInfo->szUnsafeSections)) pszSecurityInfo = LPGENT("This change is known to be potentially hazardous."); else pszSecurityInfo = LPGENT("This change is not known to be safe."); SetDlgItemText(hwndDlg, IDC_SECURITYINFO, TranslateTS(pszSecurityInfo)); } return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDCANCEL: warnInfo->cancel = 1; // fall through case IDYES: case IDNO: warnInfo->warnNoMore = IsDlgButtonChecked(hwndDlg, IDC_WARNNOMORE); EndDialog(hwndDlg, LOWORD(wParam)); break; } break; } return FALSE; }
static void ProcessIniFile(TCHAR* szIniPath, char *szSafeSections, char *szUnsafeSections, int secur, bool secFN) { FILE *fp = _tfopen(szIniPath, _T("rt")); if ( fp == NULL ) return; bool warnThisSection = false; char szSection[128]; szSection[0] = 0; while(!feof(fp)) { char szLine[2048]; if (fgets(szLine,sizeof(szLine),fp) == NULL) break; int lineLength = lstrlenA(szLine); while (lineLength && (BYTE)(szLine[lineLength-1])<=' ') szLine[--lineLength]='\0'; if (szLine[0]==';' || szLine[0]<=' ') continue; if (szLine[0]=='[') { char *szEnd = strchr(szLine+1,']'); if (szEnd == NULL) continue; if (szLine[1] == '!') szSection[0] = '\0'; else { lstrcpynA(szSection,szLine+1,min(sizeof(szSection),(int)(szEnd-szLine))); switch (secur) { case 0: warnThisSection = false; break; case 1: warnThisSection = !IsInSpaceSeparatedList(szSection, szSafeSections); break; case 2: warnThisSection = IsInSpaceSeparatedList(szSection, szUnsafeSections); break; default: warnThisSection = true; break; } if (secFN) warnThisSection=0; } if (szLine[1] == '?') { DBCONTACTENUMSETTINGS dbces; dbces.pfnEnumProc=SettingsEnumProc; lstrcpynA(szSection,szLine+2,min(sizeof(szSection),(int)(szEnd-szLine-1))); dbces.szModule=szSection; dbces.ofsSettings=0; CallService(MS_DB_CONTACT_ENUMSETTINGS,0,(LPARAM)&dbces); while (setting_items) { SettingsList *next = setting_items->next; DBCONTACTGETSETTING dbcgs; dbcgs.szModule = szSection; dbcgs.szSetting = setting_items->name; CallService(MS_DB_CONTACT_DELETESETTING, 0, (LPARAM)&dbcgs); mir_free(setting_items->name); mir_free(setting_items); setting_items = next; } } continue; } if(szSection[0]=='\0') continue; char *szValue=strchr(szLine,'='); if ( szValue == NULL ) continue; char szName[128]; lstrcpynA(szName,szLine,min(sizeof(szName),(int)(szValue-szLine+1))); szValue++; { warnSettingChangeInfo_t warnInfo; warnInfo.szIniPath=szIniPath; warnInfo.szName=szName; warnInfo.szSafeSections=szSafeSections; warnInfo.szSection=szSection; warnInfo.szUnsafeSections=szUnsafeSections; warnInfo.szValue=szValue; warnInfo.warnNoMore=0; warnInfo.cancel=0; if(warnThisSection && IDNO==DialogBoxParam(hMirandaInst,MAKEINTRESOURCE(IDD_WARNINICHANGE),NULL,WarnIniChangeDlgProc,(LPARAM)&warnInfo)) continue; if(warnInfo.cancel) break; if(warnInfo.warnNoMore) warnThisSection=0; } switch(szValue[0]) { case 'b': case 'B': DBWriteContactSettingByte(NULL,szSection,szName,(BYTE)strtol(szValue+1,NULL,0)); break; case 'w': case 'W': DBWriteContactSettingWord(NULL,szSection,szName,(WORD)strtol(szValue+1,NULL,0)); break; case 'd': case 'D': DBWriteContactSettingDword(NULL,szSection,szName,(DWORD)strtoul(szValue+1,NULL,0)); break; case 'l': case 'L': DBDeleteContactSetting(NULL,szSection,szName); break; case 'e': case 'E': ConvertBackslashes(szValue+1, LangPackGetDefaultCodePage()); case 's': case 'S': DBWriteContactSettingString(NULL,szSection,szName,szValue+1); break; case 'g': case 'G': { char *pstr; for(pstr=szValue+1;*pstr;pstr++){ if(*pstr=='\\'){ switch(pstr[1]){ case 'n': *pstr='\n'; break; case 't': *pstr='\t'; break; case 'r': *pstr='\r'; break; default: *pstr=pstr[1]; break; } MoveMemory(pstr+1,pstr+2,lstrlenA(pstr+2)+1); } } } case 'u': case 'U': DBWriteContactSettingStringUtf(NULL,szSection,szName,szValue+1); break; case 'n': case 'h': case 'N': case 'H': { PBYTE buf; int len; char *pszValue,*pszEnd; DBCONTACTWRITESETTING cws; buf=(PBYTE)mir_alloc(lstrlenA(szValue+1)); for(len=0,pszValue=szValue+1;;len++) { buf[len]=(BYTE)strtol(pszValue,&pszEnd,0x10); if(pszValue==pszEnd) break; pszValue=pszEnd; } cws.szModule=szSection; cws.szSetting=szName; cws.value.type=DBVT_BLOB; cws.value.pbVal=buf; cws.value.cpbVal=len; CallService(MS_DB_CONTACT_WRITESETTING,(WPARAM)(HANDLE)NULL,(LPARAM)&cws); mir_free(buf); } break; default: MessageBox(NULL,TranslateT("Invalid setting type. The first character of every value must be b, w, d, l, s, e, u, g, h or n."),TranslateT("Install Database Settings"),MB_OK); break; } } fclose(fp); }
static void ProcessIniFile(TCHAR* szIniPath, char *szSafeSections, char *szUnsafeSections, int secur, bool secFN) { FILE *fp = _tfopen(szIniPath, _T("rt")); if (fp == NULL) return; bool warnThisSection = false; char szSection[128]; szSection[0] = 0; while (!feof(fp)) { char szLine[2048]; if (fgets(szLine, sizeof(szLine), fp) == NULL) break; LBL_NewLine: size_t lineLength = mir_strlen(szLine); while (lineLength && (BYTE)(szLine[lineLength - 1]) <= ' ') szLine[--lineLength] = '\0'; if (szLine[0] == ';' || szLine[0] <= ' ') continue; if (szLine[0] == '[') { char *szEnd = strchr(szLine + 1, ']'); if (szEnd == NULL) continue; if (szLine[1] == '!') szSection[0] = '\0'; else { mir_strncpy(szSection, szLine + 1, min(sizeof(szSection), (int)(szEnd - szLine))); switch (secur) { case 0: warnThisSection = false; break; case 1: warnThisSection = !IsInSpaceSeparatedList(szSection, szSafeSections); break; case 2: warnThisSection = IsInSpaceSeparatedList(szSection, szUnsafeSections); break; default: warnThisSection = true; break; } if (secFN) warnThisSection = 0; } if (szLine[1] == '?') { DBCONTACTENUMSETTINGS dbces; dbces.pfnEnumProc = SettingsEnumProc; mir_strncpy(szSection, szLine+2, min(sizeof(szSection), (int)(szEnd-szLine-1))); dbces.szModule = szSection; dbces.ofsSettings = 0; CallService(MS_DB_CONTACT_ENUMSETTINGS, 0, (LPARAM)&dbces); while (setting_items) { SettingsList *next = setting_items->next; db_unset(NULL, szSection, setting_items->name); mir_free(setting_items->name); mir_free(setting_items); setting_items = next; } } continue; } if (szSection[0] == '\0') continue; char *szValue = strchr(szLine, '='); if (szValue == NULL) continue; char szName[128]; mir_strncpy(szName, szLine, min(sizeof(szName), (int)(szValue-szLine+1))); szValue++; { warnSettingChangeInfo_t warnInfo; warnInfo.szIniPath = szIniPath; warnInfo.szName = szName; warnInfo.szSafeSections = szSafeSections; warnInfo.szSection = szSection; warnInfo.szUnsafeSections = szUnsafeSections; warnInfo.szValue = szValue; warnInfo.warnNoMore = 0; warnInfo.cancel = 0; if (warnThisSection && IDNO == DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_WARNINICHANGE), NULL, WarnIniChangeDlgProc, (LPARAM)&warnInfo)) continue; if (warnInfo.cancel) break; if (warnInfo.warnNoMore) warnThisSection = 0; } switch (szValue[0]) { case 'b': case 'B': db_set_b(NULL, szSection, szName, (BYTE)strtol(szValue+1, NULL, 0)); break; case 'w': case 'W': db_set_w(NULL, szSection, szName, (WORD)strtol(szValue+1, NULL, 0)); break; case 'd': case 'D': db_set_dw(NULL, szSection, szName, (DWORD)strtoul(szValue+1, NULL, 0)); break; case 'l': case 'L': case '-': if (szValue[1] == '*') { LIST<char> arSettings(1); ESFDParam param = { &arSettings, szName }; DBCONTACTENUMSETTINGS dbep = {}; dbep.pfnEnumProc = EnumSettingsForDeletion; dbep.szModule = szSection; dbep.lParam = (LPARAM)¶m; CallService(MS_DB_CONTACT_ENUMSETTINGS, NULL, LPARAM(&dbep)); while (arSettings.getCount()) { db_unset(NULL, szSection, arSettings[0]); mir_free(arSettings[0]); arSettings.remove(0); } } db_unset(NULL, szSection, szName); break; case 'e': case 'E': ConvertBackslashes(szValue+1, Langpack_GetDefaultCodePage()); case 's': case 'S': db_set_s(NULL, szSection, szName, szValue+1); break; case 'g': case 'G': for (char *pstr = szValue + 1; *pstr; pstr++) { if (*pstr == '\\') { switch (pstr[1]) { case 'n': *pstr = '\n'; break; case 't': *pstr = '\t'; break; case 'r': *pstr = '\r'; break; default: *pstr = pstr[1]; break; } memmove(pstr + 1, pstr + 2, mir_strlen(pstr + 2) + 1); } } case 'u': case 'U': db_set_utf(NULL, szSection, szName, szValue + 1); break; case 'm': case 'M': { CMStringA memo(szValue + 1); memo.Append("\r\n"); while (fgets(szLine, sizeof(szLine), fp) != NULL) { switch (szLine[0]) { case 0: case '\r': case '\n': case ' ': case '\t': break; default: db_set_utf(NULL, szSection, szName, memo); goto LBL_NewLine; } memo.Append(rtrim(szLine + 1)); memo.Append("\r\n"); } db_set_utf(NULL, szSection, szName, memo); } break; case 'n': case 'h': case 'N': case 'H': { int len; char *pszValue, *pszEnd; PBYTE buf = (PBYTE)mir_alloc(mir_strlen(szValue + 1)); for (len = 0, pszValue = szValue + 1;; len++) { buf[len] = (BYTE)strtol(pszValue, &pszEnd, 0x10); if (pszValue == pszEnd) break; pszValue = pszEnd; } db_set_blob(NULL, szSection, szName, buf, len); mir_free(buf); } break; default: TCHAR buf[250]; mir_sntprintf(buf, TranslateT("Invalid setting type for '%s'. The first character of every value must be b, w, d, l, s, e, u, g, h or n."), _A2T(szName)); MessageBox(NULL, buf, TranslateT("Install database settings"), MB_ICONWARNING | MB_OK); break; } } fclose(fp); }