diff options
author | Tobias Weimer <wishmaster51@googlemail.com> | 2015-02-05 20:41:03 +0000 |
---|---|---|
committer | Tobias Weimer <wishmaster51@googlemail.com> | 2015-02-05 20:41:03 +0000 |
commit | e9b379bc27f64fc5d31fd894c95a1da5a18f1795 (patch) | |
tree | cc530448e2c29f256c45549d27e8fd3ea2adf4ad /plugins/Weather | |
parent | 96d3720a8b42bdd4e2595b57a725930289dc791f (diff) |
Weather: Minor fixes
git-svn-id: http://svn.miranda-ng.org/main/trunk@12012 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Weather')
-rw-r--r-- | plugins/Weather/src/weather_addstn.cpp | 32 | ||||
-rw-r--r-- | plugins/Weather/src/weather_contacts.cpp | 12 | ||||
-rw-r--r-- | plugins/Weather/src/weather_conv.cpp | 2 | ||||
-rw-r--r-- | plugins/Weather/src/weather_ini.cpp | 20 | ||||
-rw-r--r-- | plugins/Weather/src/weather_opt.cpp | 8 | ||||
-rw-r--r-- | plugins/Weather/src/weather_popup.cpp | 4 | ||||
-rw-r--r-- | plugins/Weather/src/weather_svcs.cpp | 4 | ||||
-rw-r--r-- | plugins/Weather/src/weather_update.cpp | 4 |
8 files changed, 52 insertions, 34 deletions
diff --git a/plugins/Weather/src/weather_addstn.cpp b/plugins/Weather/src/weather_addstn.cpp index b97dba6b32..50a01b9afb 100644 --- a/plugins/Weather/src/weather_addstn.cpp +++ b/plugins/Weather/src/weather_addstn.cpp @@ -196,7 +196,7 @@ static INT_PTR CALLBACK WeatherSearchAdvancedDlgProc(HWND hwndDlg, UINT msg, WPA return FALSE;
}
-INT_PTR WeatherCreateAdvancedSearchUI(WPARAM wParam, LPARAM lParam)
+INT_PTR WeatherCreateAdvancedSearchUI(WPARAM, LPARAM lParam)
{
HWND parent = (HWND)lParam;
if (parent)
@@ -206,7 +206,7 @@ INT_PTR WeatherCreateAdvancedSearchUI(WPARAM wParam, LPARAM lParam) }
// service function for name search
-INT_PTR WeatherAdvancedSearch(WPARAM wParam, LPARAM lParam)
+INT_PTR WeatherAdvancedSearch(WPARAM, LPARAM lParam)
{
if (searchId != -1) return 0; //only one search at a time
@@ -235,16 +235,18 @@ int IDSearchProc(TCHAR *sID, const int searchId, WIIDSEARCH *sData, TCHAR *svc, // load the page
mir_snprintf(loc, SIZEOF(loc), sData->SearchURL, sID);
- if (InternetDownloadFile(loc, NULL, NULL, &szData) == 0) {
+ BOOL bFound = (InternetDownloadFile(loc, NULL, NULL, &szData) == 0);
+ if (bFound) {
TCHAR* szInfo = szData;
// not found
if ( _tcsstr(szInfo, sData->NotFoundStr) == NULL)
GetDataValue(&sData->Name, str, &szInfo);
}
+
mir_free(szData);
// Station not found exit
- if (str[0] == 0) return 1;
+ if (bFound) return 1;
}
// give no station name but only ID if the search is unavailable
@@ -331,6 +333,9 @@ int NameSearchProc(TCHAR *name, const int searchId, WINAMESEARCH *sData, TCHAR * GetDataValue(&sData->Single.ID, str, &szInfo);
mir_sntprintf(sID, SIZEOF(sID), _T("%s/%s"), svc, str);
}
+ else
+ str[0] = 0;
+
// if no station ID is obtained, quit the search
if (str[0] == 0) {
mir_free(szData);
@@ -339,7 +344,7 @@ int NameSearchProc(TCHAR *name, const int searchId, WINAMESEARCH *sData, TCHAR * // if can't get the name, use the search string as name
if (Name[0] == 0)
- _tcscpy(Name, name);
+ _tcsncpy(Name, name, SIZEOF(Name));
// set the data and broadcast it
PROTOSEARCHRESULT psr = { sizeof(psr) };
@@ -356,7 +361,7 @@ int NameSearchProc(TCHAR *name, const int searchId, WINAMESEARCH *sData, TCHAR * // for multiple result
else if (sData->Multiple.Available) { // multiple results
// search for the next occurrence of the string
- for (;;) {
+ while (true) {
// if station ID appears first in the downloaded data
if ( !_tcsicmp(sData->Multiple.First, _T("ID"))) {
GetDataValue(&sData->Multiple.ID, str, &szInfo);
@@ -369,11 +374,16 @@ int NameSearchProc(TCHAR *name, const int searchId, WINAMESEARCH *sData, TCHAR * GetDataValue(&sData->Multiple.ID, str, &szInfo);
mir_sntprintf(sID, SIZEOF(sID), _T("%s/%s"), svc, str);
}
+ else
+ break;
+
// if no station ID is obtained, search completed and quit the search
- if (str[0] == 0) break;
+ if (str[0] == 0)
+ break;
+
// if can't get the name, use the search string as name
if (Name[0] == 0)
- _tcscpy(Name, name);
+ _tcsncpy(Name, name, SIZEOF(Name));
PROTOSEARCHRESULT psr = { sizeof(psr) };
psr.flags = PSR_TCHAR;
@@ -383,7 +393,9 @@ int NameSearchProc(TCHAR *name, const int searchId, WINAMESEARCH *sData, TCHAR * psr.email = sID;
psr.id = sID;
ProtoBroadcastAck(WEATHERPROTONAME, NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)searchId, (LPARAM)&psr);
- } } }
+ }
+ }
+ }
mir_free(szData);
return 0;
@@ -415,7 +427,7 @@ int NameSearch(TCHAR *name, const int searchId) // ======================MENU ITEM FUNCTION ============
// add a new weather station via find/add dialog
-int WeatherAdd(WPARAM wParam, LPARAM lParam)
+int WeatherAdd(WPARAM, LPARAM)
{
db_set_s(NULL, "FindAdd", "LastSearched", "Weather");
CallService(MS_FINDADD_FINDADD, 0, 0);
diff --git a/plugins/Weather/src/weather_contacts.cpp b/plugins/Weather/src/weather_contacts.cpp index 1edd2aae99..31ed3ef939 100644 --- a/plugins/Weather/src/weather_contacts.cpp +++ b/plugins/Weather/src/weather_contacts.cpp @@ -294,15 +294,15 @@ INT_PTR CALLBACK DlgProcChange(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa ofn.lpstrFile = str;
ofn.nMaxFile = SIZEOF(str);
// set filters
- _tcscpy(filter, TranslateT("Text Files"));
- _tcscat(filter, _T(" (*.txt)"));
+ _tcsncpy(filter, TranslateT("Text Files"), SIZEOF(filter));
+ _tcsncat(filter, _T(" (*.txt)"), SIZEOF(filter));
pfilter = filter + _tcslen(filter)+1;
- _tcscpy(pfilter, _T("*.txt"));
+ _tcsncpy(pfilter, _T("*.txt"), SIZEOF(filter));
pfilter = pfilter + _tcslen(pfilter)+1;
- _tcscpy(pfilter, TranslateT("All Files"));
- _tcscat(pfilter, _T(" (*.*)"));
+ _tcsncpy(pfilter, TranslateT("All Files"), SIZEOF(filter));
+ _tcsncat(pfilter, _T(" (*.*)"), SIZEOF(filter));
pfilter = pfilter + _tcslen(pfilter)+1;
- _tcscpy(pfilter, _T("*.*"));
+ _tcsncpy(pfilter, _T("*.*"), SIZEOF(filter));
pfilter = pfilter + _tcslen(pfilter)+1;
*pfilter = '\0';
ofn.lpstrFilter = filter;
diff --git a/plugins/Weather/src/weather_conv.cpp b/plugins/Weather/src/weather_conv.cpp index 6697ba2891..a29a666ce7 100644 --- a/plugins/Weather/src/weather_conv.cpp +++ b/plugins/Weather/src/weather_conv.cpp @@ -638,5 +638,5 @@ TCHAR *GetError(int code) str = str2;
break;
}
- return str;
+ return mir_tstrdup(str);
}
diff --git a/plugins/Weather/src/weather_ini.cpp b/plugins/Weather/src/weather_ini.cpp index e11085f272..67c5740000 100644 --- a/plugins/Weather/src/weather_ini.cpp +++ b/plugins/Weather/src/weather_ini.cpp @@ -175,23 +175,24 @@ void DestroyCondList(WICONDLIST *List) // load the weather update data form INI files
bool LoadWIData(bool dial)
{
- TCHAR szSearchPath[MAX_PATH], FileName[MAX_PATH];
- WIN32_FIND_DATA fd;
- WIDATA Data;
-
// make sure that the current service data list is empty
WITail = NULL;
WIHead = WITail;
// find all *.ini file in the plugin\weather directory
+ TCHAR szSearchPath[MAX_PATH], FileName[MAX_PATH];
GetModuleFileName(GetModuleHandle(NULL), szSearchPath, SIZEOF(szSearchPath));
TCHAR *chop = _tcsrchr(szSearchPath, '\\');
+ if (chop == NULL)
+ return false;
*chop = '\0';
_tcsncat(szSearchPath, _T("\\Plugins\\Weather\\*.ini"),SIZEOF(szSearchPath));
_tcsncpy(FileName, szSearchPath, SIZEOF(FileName));
+ WIN32_FIND_DATA fd;
HANDLE hFind = FindFirstFile(szSearchPath, &fd);
+
// load the content of the ini file into memory
if (hFind != INVALID_HANDLE_VALUE) {
do {
@@ -199,6 +200,7 @@ bool LoadWIData(bool dial) chop[1] = '\0';
_tcscat(FileName, fd.cFileName);
if ( _tcsicmp(fd.cFileName, _T("SAMPLE_INI.INI"))) {
+ WIDATA Data;
LoadStationData(FileName, fd.cFileName, &Data);
if (Data.Enabled)
WIListAdd(Data);
@@ -566,10 +568,12 @@ INT_PTR CALLBACK DlgProcSetup(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar TCHAR szPath[1024];
GetModuleFileName(GetModuleHandle(NULL), szPath, SIZEOF(szPath));
TCHAR *chop = _tcsrchr(szPath, '\\');
- *chop = '\0';
- _tcsncat(szPath, _T("\\Plugins\\weather\\"),SIZEOF(szPath));
- _tmkdir(szPath);
- ShellExecute((HWND)lParam, _T("open"), szPath, _T(""), _T(""), SW_SHOW);
+ if (chop) {
+ *chop = '\0';
+ _tcsncat(szPath, _T("\\Plugins\\weather\\"),SIZEOF(szPath));
+ _tmkdir(szPath);
+ ShellExecute((HWND)lParam, _T("open"), szPath, _T(""), _T(""), SW_SHOW);
+ }
break;
}
diff --git a/plugins/Weather/src/weather_opt.cpp b/plugins/Weather/src/weather_opt.cpp index 315c7ccbb5..012b123166 100644 --- a/plugins/Weather/src/weather_opt.cpp +++ b/plugins/Weather/src/weather_opt.cpp @@ -254,7 +254,7 @@ void SaveOptions(void) //============ OPTION INITIALIZATION ============
// register the weather option pages
-int OptInit(WPARAM wParam, LPARAM lParam)
+int OptInit(WPARAM wParam, LPARAM)
{
OPTIONSDIALOGPAGE odp = { sizeof(odp) };
odp.hInstance = hInst;
@@ -519,7 +519,6 @@ INT_PTR CALLBACK DlgProcText(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) case IDC_TM6:
case IDC_TM7:
case IDC_TM8:
- WEATHERINFO winfo;
// display the menu
button = GetDlgItem(hdlg, LOWORD(wParam));
GetWindowRect(button, &pos);
@@ -528,12 +527,13 @@ INT_PTR CALLBACK DlgProcText(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) TranslateMenu(hMenu1);
switch (TrackPopupMenu(hMenu1, TPM_LEFTBUTTON | TPM_RETURNCMD, pos.left, pos.bottom, 0, hdlg, NULL)) {
case ID_MPREVIEW:
+ {
// show the preview in a message box, using the weather data from the default station
- winfo = LoadWeatherInfo(opt.DefStn);
+ WEATHERINFO winfo = LoadWeatherInfo(opt.DefStn);
GetDisplay(&winfo, *var[LOWORD(wParam) - IDC_TM1], str);
MessageBox(NULL, str, TranslateT("Weather Protocol Text Preview"), MB_OK | MB_TOPMOST);
break;
-
+ }
case ID_MRESET:
unsigned varo = LOWORD(wParam) - IDC_TM1;
// remove the old setting from db and free memory
diff --git a/plugins/Weather/src/weather_popup.cpp b/plugins/Weather/src/weather_popup.cpp index 68d349b77c..aff1b8738d 100644 --- a/plugins/Weather/src/weather_popup.cpp +++ b/plugins/Weather/src/weather_popup.cpp @@ -258,9 +258,9 @@ INT_PTR CALLBACK DlgPopupOpts(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) // click actions
hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_PMENU));
hMenu1 = GetSubMenu(hMenu, 0);
- GetMenuString(hMenu1, opt.LeftClickAction, str, sizeof(str), MF_BYCOMMAND);
+ GetMenuString(hMenu1, opt.LeftClickAction, str, SIZEOF(str), MF_BYCOMMAND);
SetDlgItemText(hdlg, IDC_LeftClick, TranslateTS(str));
- GetMenuString(hMenu1, opt.RightClickAction, str, sizeof(str), MF_BYCOMMAND);
+ GetMenuString(hMenu1, opt.RightClickAction, str, SIZEOF(str), MF_BYCOMMAND);
SetDlgItemText(hdlg, IDC_RightClick, TranslateTS(str));
DestroyMenu(hMenu);
diff --git a/plugins/Weather/src/weather_svcs.cpp b/plugins/Weather/src/weather_svcs.cpp index d654aa3b60..b485257601 100644 --- a/plugins/Weather/src/weather_svcs.cpp +++ b/plugins/Weather/src/weather_svcs.cpp @@ -115,7 +115,7 @@ static void __cdecl AckThreadProc(HANDLE param) // nothing to do here because weather proto do not need to retrieve contact info form network
// so just return a 0
-INT_PTR WeatherGetInfo(WPARAM wParam,LPARAM lParam)
+INT_PTR WeatherGetInfo(WPARAM,LPARAM lParam)
{
CCSDATA *ccs = (CCSDATA *) lParam;
mir_forkthread(AckThreadProc, (void*)ccs->hContact);
@@ -133,7 +133,7 @@ INT_PTR WeatherGetAvatarInfo(WPARAM wParam, LPARAM lParam) unsigned i;
PROTO_AVATAR_INFORMATIONT* ai = ( PROTO_AVATAR_INFORMATIONT* )lParam;
- GetModuleFileName(GetModuleHandle(NULL), szSearchPath, sizeof(szSearchPath));
+ GetModuleFileName(GetModuleHandle(NULL), szSearchPath, SIZEOF(szSearchPath));
chop = _tcsrchr(szSearchPath, '\\');
if (chop) *chop = '\0';
diff --git a/plugins/Weather/src/weather_update.cpp b/plugins/Weather/src/weather_update.cpp index b5b0c582ed..612f536b5c 100644 --- a/plugins/Weather/src/weather_update.cpp +++ b/plugins/Weather/src/weather_update.cpp @@ -61,8 +61,10 @@ int UpdateWeather(MCONTACT hContact) mir_sntprintf(str, SIZEOF(str) - 105,
TranslateT("Unable to retrieve weather information for %s"), dbv.ptszVal);
_tcscat(str, _T("\n"));
- _tcscat(str, GetError(code));
+ TCHAR *tszError = GetError(code);
+ _tcscat(str, tszError);
WPShowMessage(str, SM_WARNING);
+ mir_free(tszError);
}
// log to netlib
Netlib_LogfT(hNetlibUser, _T("Error! Update cannot continue... Start to free memory"));
|