From ae0525e4ceb7f88b808ff94458a4768c9f3cc264 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 30 Dec 2013 11:58:42 +0000 Subject: code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@7424 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/modules/database/dbini.cpp | 244 ++++++++++++++++++++--------------------- 1 file changed, 121 insertions(+), 123 deletions(-) (limited to 'src/modules/database/dbini.cpp') diff --git a/src/modules/database/dbini.cpp b/src/modules/database/dbini.cpp index d10e98131d..672350084e 100644 --- a/src/modules/database/dbini.cpp +++ b/src/modules/database/dbini.cpp @@ -31,42 +31,43 @@ extern TCHAR mirandabootini[MAX_PATH]; static INT_PTR CALLBACK InstallIniDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) { - switch(message) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - SetDlgItemText(hwndDlg, IDC_ININAME, (TCHAR*)lParam); + switch (message) { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + SetDlgItemText(hwndDlg, IDC_ININAME, (TCHAR*)lParam); + { + TCHAR szSecurity[11]; + const TCHAR *pszSecurityInfo; + + GetPrivateProfileString(_T("AutoExec"), _T("Warn"), _T("notsafe"), szSecurity, SIZEOF(szSecurity), mirandabootini); + if (!lstrcmpi(szSecurity, _T("all"))) + pszSecurityInfo = LPGENT("Security systems to prevent malicious changes are in place and you will be warned before every change that is made."); + else if (!lstrcmpi(szSecurity, _T("onlyunsafe"))) + pszSecurityInfo = LPGENT("Security systems to prevent malicious changes are in place and you will be warned before changes that are known to be unsafe."); + else if (!lstrcmpi(szSecurity, _T("none"))) + pszSecurityInfo = LPGENT("Security systems to prevent malicious changes have been disabled. You will receive no further warnings."); + else pszSecurityInfo = NULL; + if (pszSecurityInfo) SetDlgItemText(hwndDlg, IDC_SECURITYINFO, TranslateTS(pszSecurityInfo)); + } + return TRUE; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDC_VIEWINI: { - TCHAR szSecurity[11]; - const TCHAR *pszSecurityInfo; - - GetPrivateProfileString(_T("AutoExec"), _T("Warn"), _T("notsafe"), szSecurity, SIZEOF(szSecurity), mirandabootini); - if ( !lstrcmpi(szSecurity, _T("all"))) - pszSecurityInfo = LPGENT("Security systems to prevent malicious changes are in place and you will be warned before every change that is made."); - else if ( !lstrcmpi(szSecurity, _T("onlyunsafe"))) - pszSecurityInfo = LPGENT("Security systems to prevent malicious changes are in place and you will be warned before changes that are known to be unsafe."); - else if ( !lstrcmpi(szSecurity, _T("none"))) - pszSecurityInfo = LPGENT("Security systems to prevent malicious changes have been disabled. You will receive no further warnings."); - else pszSecurityInfo = NULL; - if (pszSecurityInfo) SetDlgItemText(hwndDlg, IDC_SECURITYINFO, TranslateTS(pszSecurityInfo)); - } - return TRUE; - - case WM_COMMAND: - switch(LOWORD(wParam)) { - case IDC_VIEWINI: - { - TCHAR szPath[MAX_PATH]; - GetDlgItemText(hwndDlg, IDC_ININAME, szPath, SIZEOF(szPath)); - ShellExecute(hwndDlg, _T("open"), szPath, NULL, NULL, SW_SHOW); - break; - } - case IDOK: - case IDCANCEL: - case IDC_NOTOALL: - EndDialog(hwndDlg, LOWORD(wParam)); - break; + TCHAR szPath[MAX_PATH]; + GetDlgItemText(hwndDlg, IDC_ININAME, szPath, SIZEOF(szPath)); + ShellExecute(hwndDlg, _T("open"), szPath, NULL, NULL, SW_SHOW); } break; + + case IDOK: + case IDCANCEL: + case IDC_NOTOALL: + EndDialog(hwndDlg, LOWORD(wParam)); + break; + } + break; } return FALSE; } @@ -80,11 +81,12 @@ static bool IsInSpaceSeparatedList(const char *szWord, const char *szList) szEnd = strchr(szItem, ' '); if (szEnd == NULL) return !lstrcmpA(szItem, szWord); - if (szEnd - szItem == wordLen) { - if ( !strncmp(szItem, szWord, wordLen)) + + if (szEnd - szItem == wordLen) + if (!strncmp(szItem, szWord, wordLen)) return true; - } - szItem = szEnd+1; + + szItem = szEnd + 1; } } @@ -100,10 +102,10 @@ struct warnSettingChangeInfo_t { static INT_PTR CALLBACK WarnIniChangeDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) { - static struct warnSettingChangeInfo_t *warnInfo; + static warnSettingChangeInfo_t *warnInfo; switch(message) { - case WM_INITDIALOG: + case WM_INITDIALOG: { char szSettingName[256]; const TCHAR *pszSecurityInfo; @@ -122,63 +124,62 @@ static INT_PTR CALLBACK WarnIniChangeDlgProc(HWND hwndDlg, UINT message, WPARAM 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; - case IDYES: - case IDNO: - warnInfo->warnNoMore = IsDlgButtonChecked(hwndDlg, IDC_WARNNOMORE); - EndDialog(hwndDlg, LOWORD(wParam)); - break; - } + return TRUE; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDCANCEL: + warnInfo->cancel = 1; + case IDYES: + case IDNO: + warnInfo->warnNoMore = IsDlgButtonChecked(hwndDlg, IDC_WARNNOMORE); + EndDialog(hwndDlg, LOWORD(wParam)); break; + } + break; } return FALSE; } static INT_PTR CALLBACK IniImportDoneDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) { - switch(message) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - SetDlgItemText(hwndDlg, IDC_ININAME, (TCHAR*)lParam); - SetDlgItemText(hwndDlg, IDC_NEWNAME, (TCHAR*)lParam); - return TRUE; - case WM_COMMAND: - { - TCHAR szIniPath[MAX_PATH]; - GetDlgItemText(hwndDlg, IDC_ININAME, szIniPath, SIZEOF(szIniPath)); - switch(LOWORD(wParam)) { - case IDC_DELETE: - DeleteFile(szIniPath); - case IDC_LEAVE: - EndDialog(hwndDlg, LOWORD(wParam)); - break; - case IDC_RECYCLE: - { - SHFILEOPSTRUCT shfo = {0}; - shfo.wFunc = FO_DELETE; - shfo.pFrom = szIniPath; - szIniPath[lstrlen(szIniPath)+1] = '\0'; - shfo.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT | FOF_ALLOWUNDO; - SHFileOperation(&shfo); - } - EndDialog(hwndDlg, LOWORD(wParam)); - break; - case IDC_MOVE: - { - TCHAR szNewPath[MAX_PATH]; - GetDlgItemText(hwndDlg, IDC_NEWNAME, szNewPath, SIZEOF(szNewPath)); - MoveFile(szIniPath, szNewPath); - } - EndDialog(hwndDlg, LOWORD(wParam)); - break; + TCHAR szIniPath[MAX_PATH]; + + switch (message) { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + SetDlgItemText(hwndDlg, IDC_ININAME, (TCHAR*)lParam); + SetDlgItemText(hwndDlg, IDC_NEWNAME, (TCHAR*)lParam); + return TRUE; + + case WM_COMMAND: + GetDlgItemText(hwndDlg, IDC_ININAME, szIniPath, SIZEOF(szIniPath)); + switch (LOWORD(wParam)) { + case IDC_DELETE: + DeleteFile(szIniPath); + case IDC_LEAVE: + EndDialog(hwndDlg, LOWORD(wParam)); + break; + case IDC_RECYCLE: + { + SHFILEOPSTRUCT shfo = { 0 }; + shfo.wFunc = FO_DELETE; + shfo.pFrom = szIniPath; + szIniPath[lstrlen(szIniPath) + 1] = '\0'; + shfo.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT | FOF_ALLOWUNDO; + SHFileOperation(&shfo); } + EndDialog(hwndDlg, LOWORD(wParam)); + break; + case IDC_MOVE: + TCHAR szNewPath[MAX_PATH]; + GetDlgItemText(hwndDlg, IDC_NEWNAME, szNewPath, SIZEOF(szNewPath)); + MoveFile(szIniPath, szNewPath); + EndDialog(hwndDlg, LOWORD(wParam)); break; } + break; } return FALSE; } @@ -204,13 +205,13 @@ static void ConvertBackslashes(char *str, UINT fileCp) char *pstr; for (pstr = str; *pstr; pstr = CharNextExA(fileCp, pstr, 0)) { if (*pstr == '\\') { - switch(pstr[1]) { + 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, strlen(pstr+2) + 1); + memmove(pstr + 1, pstr + 2, strlen(pstr + 2) + 1); } } } @@ -224,27 +225,27 @@ static void ProcessIniFile(TCHAR* szIniPath, char *szSafeSections, char *szUnsaf bool warnThisSection = false; char szSection[128]; szSection[0] = 0; - while ( !feof(fp)) { + while (!feof(fp)) { char szLine[2048]; if (fgets(szLine, sizeof(szLine), fp) == NULL) break; LBL_NewLine: int lineLength = lstrlenA(szLine); - while (lineLength && (BYTE)(szLine[lineLength-1]) <= ' ') + while (lineLength && (BYTE)(szLine[lineLength - 1]) <= ' ') szLine[--lineLength] = '\0'; if (szLine[0] == ';' || szLine[0] <= ' ') continue; if (szLine[0] == '[') { - char *szEnd = strchr(szLine+1, ']'); + 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))); + lstrcpynA(szSection, szLine + 1, min(sizeof(szSection), (int)(szEnd - szLine))); switch (secur) { case 0: warnThisSection = false; @@ -312,7 +313,7 @@ LBL_NewLine: warnThisSection = 0; } - switch(szValue[0]) { + switch (szValue[0]) { case 'b': case 'B': db_set_b(NULL, szSection, szName, (BYTE)strtol(szValue+1, NULL, 0)); @@ -339,28 +340,25 @@ LBL_NewLine: 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); + 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; } + MoveMemory(pstr + 1, pstr + 2, lstrlenA(pstr + 2) + 1); } } case 'u': case 'U': - db_set_utf(NULL, szSection, szName, szValue+1); + db_set_utf(NULL, szSection, szName, szValue + 1); break; case 'm': case 'M': { - CMStringA memo(szValue+1); + CMStringA memo(szValue + 1); memo.Append("\r\n"); while (fgets(szLine, sizeof(szLine), fp) != NULL) { switch (szLine[0]) { @@ -371,7 +369,7 @@ LBL_NewLine: goto LBL_NewLine; } - memo.Append(rtrim(szLine+1)); + memo.Append(rtrim(szLine + 1)); memo.Append("\r\n"); } db_set_utf(NULL, szSection, szName, memo); @@ -385,8 +383,8 @@ LBL_NewLine: int len; char *pszValue, *pszEnd; - PBYTE buf = (PBYTE)mir_alloc(lstrlenA(szValue+1)); - for (len = 0, pszValue = szValue+1;;len++) { + PBYTE 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; @@ -397,7 +395,7 @@ LBL_NewLine: } break; default: - TCHAR buf[ 250 ]; + TCHAR buf[250]; mir_sntprintf(buf, SIZEOF(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; @@ -414,26 +412,26 @@ static void DoAutoExec(void) int secur; GetPrivateProfileString(_T("AutoExec"), _T("Use"), _T("prompt"), szUse, SIZEOF(szUse), mirandabootini); - if ( !lstrcmpi(szUse, _T("no"))) return; + if (!lstrcmpi(szUse, _T("no"))) return; GetPrivateProfileString(_T("AutoExec"), _T("Safe"), _T("CLC Icons CLUI CList SkinSounds PluginUpdater"), buf, SIZEOF(buf), mirandabootini); szSafeSections = mir_t2a(buf); GetPrivateProfileString(_T("AutoExec"), _T("Unsafe"), _T("AIM Facebook GG ICQ IRC JABBER MRA MSN SKYPE Tlen TWITTER XFire"), buf, SIZEOF(buf), mirandabootini); szUnsafeSections = mir_t2a(buf); GetPrivateProfileString(_T("AutoExec"), _T("Warn"), _T("notsafe"), szSecurity, SIZEOF(szSecurity), mirandabootini); - if ( !lstrcmpi(szSecurity, _T("none"))) secur = 0; - else if ( !lstrcmpi(szSecurity, _T("notsafe"))) secur = 1; - else if ( !lstrcmpi(szSecurity, _T("onlyunsafe"))) secur = 2; + if (!lstrcmpi(szSecurity, _T("none"))) secur = 0; + else if (!lstrcmpi(szSecurity, _T("notsafe"))) secur = 1; + else if (!lstrcmpi(szSecurity, _T("onlyunsafe"))) secur = 2; GetPrivateProfileString(_T("AutoExec"), _T("OverrideSecurityFilename"), _T(""), szOverrideSecurityFilename, SIZEOF(szOverrideSecurityFilename), mirandabootini); GetPrivateProfileString(_T("AutoExec"), _T("OnCreateFilename"), _T(""), szOnCreateFilename, SIZEOF(szOnCreateFilename), mirandabootini); GetPrivateProfileString(_T("AutoExec"), _T("Glob"), _T("autoexec_*.ini"), szFindPath, SIZEOF(szFindPath), mirandabootini); if (g_bDbCreated && szOnCreateFilename[0]) { - PathToAbsoluteT( VARST(szOnCreateFilename), szIniPath); + PathToAbsoluteT(VARST(szOnCreateFilename), szIniPath); ProcessIniFile(szIniPath, szSafeSections, szUnsafeSections, 0, 1); } - PathToAbsoluteT( VARST(szFindPath), szFindPath); + PathToAbsoluteT(VARST(szFindPath), szFindPath); WIN32_FIND_DATA fd; HANDLE hFind = FindFirstFile(szFindPath, &fd); @@ -451,7 +449,7 @@ static void DoAutoExec(void) bool secFN = lstrcmpi(fd.cFileName, szOverrideSecurityFilename) == 0; mir_sntprintf(szIniPath, SIZEOF(szIniPath), _T("%s%s"), szFindPath, fd.cFileName); - if ( !lstrcmpi(szUse, _T("prompt")) && !secFN) { + if (!lstrcmpi(szUse, _T("prompt")) && !secFN) { int result = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_INSTALLINI), NULL, InstallIniDlgProc, (LPARAM)szIniPath); if (result == IDC_NOTOALL) break; if (result == IDCANCEL) continue; @@ -464,17 +462,17 @@ static void DoAutoExec(void) else { TCHAR szOnCompletion[8]; GetPrivateProfileString(_T("AutoExec"), _T("OnCompletion"), _T("recycle"), szOnCompletion, SIZEOF(szOnCompletion), mirandabootini); - if ( !lstrcmpi(szOnCompletion, _T("delete"))) + if (!lstrcmpi(szOnCompletion, _T("delete"))) DeleteFile(szIniPath); - else if ( !lstrcmpi(szOnCompletion, _T("recycle"))) { - SHFILEOPSTRUCT shfo = {0}; + else if (!lstrcmpi(szOnCompletion, _T("recycle"))) { + SHFILEOPSTRUCT shfo = { 0 }; shfo.wFunc = FO_DELETE; shfo.pFrom = szIniPath; - szIniPath[lstrlen(szIniPath)+1] = 0; + szIniPath[lstrlen(szIniPath) + 1] = 0; shfo.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT | FOF_ALLOWUNDO; SHFileOperation(&shfo); } - else if ( !lstrcmpi(szOnCompletion, _T("rename"))) { + else if (!lstrcmpi(szOnCompletion, _T("rename"))) { TCHAR szRenamePrefix[MAX_PATH]; TCHAR szNewPath[MAX_PATH]; GetPrivateProfileString(_T("AutoExec"), _T("RenamePrefix"), _T("done_"), szRenamePrefix, SIZEOF(szRenamePrefix), mirandabootini); @@ -483,7 +481,7 @@ static void DoAutoExec(void) lstrcat(szNewPath, fd.cFileName); MoveFile(szIniPath, szNewPath); } - else if ( !lstrcmpi(szOnCompletion, _T("ask"))) + else if (!lstrcmpi(szOnCompletion, _T("ask"))) DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_INIIMPORTDONE), NULL, IniImportDoneDlgProc, (LPARAM)szIniPath); } } @@ -519,7 +517,7 @@ int InitIni(void) void UninitIni(void) { - if ( !bModuleInitialized) + if (!bModuleInitialized) return; CallService(MS_SYSTEM_REMOVEWAIT, (WPARAM)hIniChangeNotification, 0); -- cgit v1.2.3