summaryrefslogtreecommitdiff
path: root/protocols/Weather/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2021-05-01 13:30:59 +0300
committerGeorge Hazan <ghazan@miranda.im>2021-05-01 13:30:59 +0300
commitc39c8e1373abf80a88c943d657119081a3d07c89 (patch)
treec2dbdb726e05a9467b3997a2c1d8c4524085b276 /protocols/Weather/src
parenteddff12b3a5b0727ad84d8982f1a39df8e771b10 (diff)
Weather:
- old code removed; - mir_wstrcat replaced with CMStringW calls; - translations fixed
Diffstat (limited to 'protocols/Weather/src')
-rw-r--r--protocols/Weather/src/stdafx.h10
-rw-r--r--protocols/Weather/src/weather.cpp20
-rw-r--r--protocols/Weather/src/weather_contacts.cpp19
-rw-r--r--protocols/Weather/src/weather_data.cpp5
-rw-r--r--protocols/Weather/src/weather_info.cpp106
-rw-r--r--protocols/Weather/src/weather_ini.cpp491
-rw-r--r--protocols/Weather/src/weather_mwin.cpp6
-rw-r--r--protocols/Weather/src/weather_opt.cpp20
-rw-r--r--protocols/Weather/src/weather_popup.cpp24
-rw-r--r--protocols/Weather/src/weather_svcs.cpp2
-rw-r--r--protocols/Weather/src/weather_update.cpp15
-rw-r--r--protocols/Weather/src/weather_userinfo.cpp8
12 files changed, 342 insertions, 384 deletions
diff --git a/protocols/Weather/src/stdafx.h b/protocols/Weather/src/stdafx.h
index 2d558ae68a..d8b0b224c9 100644
--- a/protocols/Weather/src/stdafx.h
+++ b/protocols/Weather/src/stdafx.h
@@ -165,13 +165,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// 505 HTTP Version Not Supported
// defaults constants
-#define VAR_LIST_POPUP TranslateT("%c\tcurrent condition\n%d\tcurrent date\n%e\tdewpoint\n%f\tfeel-like temperature\n%h\ttoday's high\n%i\twind direction\n%l\ttoday's low\n%m\thumidity\n%n\tstation name\n%p\tpressure\n%r\tsunrise time\n%s\tstation ID\n%t\ttemperature\n%u\tupdate time\n%v\tvisibility\n%w\twind speed\n%y\tsun set")
-#define VAR_LIST_OPT TranslateT("%c\tcurrent condition\n%d\tcurrent date\n%e\tdewpoint\n%f\tfeel-like temp\n%h\ttoday's high\n%i\twind direction\n%l\ttoday's low\n%m\thumidity\n%n\tstation name\n%p\tpressure\n%r\tsunrise time\n%s\tstation ID\n%t\ttemperature\n%u\tupdate time\n%v\tvisibility\n%w\twind speed\n%y\tsun set\n----------\n\\n\tnew line")
-#define WEATHER_NO_INFO TranslateT("No information available.\r\nPlease update weather condition first.")
-#define CUSTOM_VARS TranslateT("%[..]\tcustom variables")
-#define VARS_LIST TranslateT("Here is a list of custom variables that are currently available")
-#define NO_FORECAST_URL TranslateT("The URL for complete forecast has not been set. You can set it from the Edit Settings dialog.")
-#define NO_MAP_URL TranslateT("The URL for weather map has not been set. You can set it from the Edit Settings dialog.")
+#define VAR_LIST_OPT TranslateT("%c\tcurrent condition\n%d\tcurrent date\n%e\tdewpoint\n%f\tfeel-like temp\n%h\ttoday's high\n%i\twind direction\n%l\ttoday's low\n%m\thumidity\n%n\tstation name\n%p\tpressure\n%r\tsunrise time\n%s\tstation ID\n%t\ttemperature\n%u\tupdate time\n%v\tvisibility\n%w\twind speed\n%y\tsun set\n----------\n\\n\tnew line")
//============ OPTION STRUCT ============
@@ -454,7 +448,7 @@ const wchar_t* GetDefaultText(int c);
// functions in weather_popup.c
int WeatherPopup(WPARAM wParam, LPARAM lParam);
int WeatherError(WPARAM wParam, LPARAM lParam);
-int WPShowMessage(wchar_t* lpzText, WORD kind);
+int WPShowMessage(const wchar_t* lpzText, WORD kind);
LRESULT CALLBACK PopupWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
diff --git a/protocols/Weather/src/weather.cpp b/protocols/Weather/src/weather.cpp
index 4eafadbad7..243156ef22 100644
--- a/protocols/Weather/src/weather.cpp
+++ b/protocols/Weather/src/weather.cpp
@@ -43,7 +43,7 @@ HANDLE hUpdateMutex;
unsigned status;
unsigned old_status;
-UINT_PTR timerId;
+UINT_PTR timerId = 0;
CMPlugin g_plugin;
@@ -53,7 +53,7 @@ MYOPTIONS opt;
BOOL ThreadRunning;
// variable to determine if module loaded
-BOOL ModuleLoaded;
+BOOL ModuleLoaded = FALSE;
HANDLE hTBButton = nullptr;
@@ -139,24 +139,8 @@ int WeatherInit(WPARAM, LPARAM)
//============ MISC FUNCTIONS ============
-// initialize the global variables at startup
-void InitVar()
-{
- // setup the linklist for weather update list
- UpdateListTail = nullptr;
- UpdateListHead = nullptr;
-
- // other settings
- timerId = 0;
- opt.DefStn = NULL;
- ModuleLoaded = FALSE;
-}
-
int CMPlugin::Load()
{
- // initialize global variables
- InitVar();
-
// load options and set defaults
LoadOptions();
diff --git a/protocols/Weather/src/weather_contacts.cpp b/protocols/Weather/src/weather_contacts.cpp
index 192844e791..0ba7473c49 100644
--- a/protocols/Weather/src/weather_contacts.cpp
+++ b/protocols/Weather/src/weather_contacts.cpp
@@ -61,7 +61,7 @@ INT_PTR LoadForecast(WPARAM wParam, LPARAM)
if (id[0] != 0) {
// check if the complte forecast URL is set. If it is not, display warning and quit
if (db_get_wstatic(wParam, MODULENAME, "InfoURL", loc2, _countof(loc2)) || loc2[0] == 0) {
- MessageBox(nullptr, NO_FORECAST_URL, TranslateT("Weather Protocol"), MB_ICONINFORMATION);
+ MessageBox(nullptr, TranslateT("The URL for complete forecast has not been set. You can set it from the Edit Settings dialog."), TranslateT("Weather Protocol"), MB_ICONINFORMATION);
return 1;
}
// set the url and open the webpage
@@ -79,7 +79,7 @@ INT_PTR WeatherMap(WPARAM wParam, LPARAM)
if (id[0] != 0) {
// check if the weather map URL is set. If it is not, display warning and quit
if (db_get_wstatic(wParam, MODULENAME, "MapURL", loc2, _countof(loc2)) || loc2[0] == 0) {
- MessageBox(nullptr, NO_MAP_URL, TranslateT("Weather Protocol"), MB_ICONINFORMATION);
+ MessageBox(nullptr, TranslateT("The URL for weather map has not been set. You can set it from the Edit Settings dialog."), TranslateT("Weather Protocol"), MB_ICONINFORMATION);
return 1;
}
@@ -106,7 +106,7 @@ typedef struct
static INT_PTR CALLBACK DlgProcChange(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
DBVARIANT dbv;
- wchar_t str[MAX_DATA_LEN], str2[256], city[256], filter[256], *pfilter, *chop;
+ wchar_t str[MAX_DATA_LEN], str2[256], city[256], filter[256], *chop;
char loc[512];
OPENFILENAME ofn; // common dialog box structure
MCONTACT hContact;
@@ -270,18 +270,9 @@ static INT_PTR CALLBACK DlgProcChange(HWND hwndDlg, UINT msg, WPARAM wParam, LPA
ofn.hwndOwner = hwndDlg;
ofn.lpstrFile = str;
ofn.nMaxFile = _countof(str);
+
// set filters
- wcsncpy(filter, TranslateT("Text Files"), _countof(filter) - 1);
- mir_wstrncat(filter, L" (*.txt)", _countof(filter) - mir_wstrlen(filter));
- pfilter = filter + mir_wstrlen(filter) + 1;
- wcsncpy(pfilter, L"*.txt", _countof(filter) - 1);
- pfilter = pfilter + mir_wstrlen(pfilter) + 1;
- wcsncpy(pfilter, TranslateT("All Files"), _countof(filter) - 1);
- mir_wstrncat(pfilter, L" (*.*)", _countof(filter) - mir_wstrlen(filter));
- pfilter = pfilter + mir_wstrlen(pfilter) + 1;
- wcsncpy(pfilter, L"*.*", _countof(filter) - 1);
- pfilter = pfilter + mir_wstrlen(pfilter) + 1;
- *pfilter = '\0';
+ mir_snwprintf(filter, L"%s (*.txt)%c*.txt%c%s (*.*)%c*.*%c%c", TranslateT("Text Files"), 0, 0, TranslateT("All Files"), 0, 0, 0);
ofn.lpstrFilter = filter;
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = nullptr;
diff --git a/protocols/Weather/src/weather_data.cpp b/protocols/Weather/src/weather_data.cpp
index c6d88e4f1f..b4d4393a42 100644
--- a/protocols/Weather/src/weather_data.cpp
+++ b/protocols/Weather/src/weather_data.cpp
@@ -424,11 +424,12 @@ void DBDataManage(MCONTACT hContact, WORD Mode, WPARAM wParam, LPARAM)
if (!mir_strcmp(str, "WeatherInfo") || !mir_strcmp(str, "Ignore") || str[0] == '#')
continue;
+ _A2T strW(str);
HWND hList = GetDlgItem((HWND)wParam, IDC_DATALIST);
- LV_ITEM lvi = { 0 };
+ LV_ITEM lvi = {};
lvi.mask = LVIF_TEXT | LVIF_PARAM;
lvi.lParam = T.indexOf(&str);
- lvi.pszText = TranslateW(_A2T(str));
+ lvi.pszText = TranslateW(strW);
lvi.iItem = ListView_InsertItem(hList, &lvi);
lvi.pszText = wszText;
ListView_SetItemText(hList, lvi.iItem, 1, wszText);
diff --git a/protocols/Weather/src/weather_info.cpp b/protocols/Weather/src/weather_info.cpp
index a2395d9f69..bdc5115195 100644
--- a/protocols/Weather/src/weather_info.cpp
+++ b/protocols/Weather/src/weather_info.cpp
@@ -40,7 +40,7 @@ static void INIInfo(HWND hwndDlg)
ListView_DeleteAllItems(hIniList);
- LVITEM lvi = { 0 };
+ LVITEM lvi = {};
lvi.mask = LVIF_TEXT;
lvi.iItem = 0;
for (WIDATALIST *Item = WIHead; Item != nullptr; Item = Item->next) {
@@ -108,7 +108,7 @@ INT_PTR CALLBACK DlgProcINIPage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM)
TranslateDialogDefault(hwndDlg);
{
HWND hIniList = GetDlgItem(hwndDlg, IDC_INFOLIST);
- LVCOLUMN lvc = { 0 };
+ LVCOLUMN lvc = {};
lvc.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
lvc.fmt = LVCFMT_LEFT;
@@ -141,64 +141,45 @@ INT_PTR CALLBACK DlgProcINIPage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM)
// get the info of individual ini file
// pszSvc = the internal name of the service to get the data
+
+static wchar_t* GetVersionNum(int iVersion)
+{
+ switch (iVersion) {
+ case 1: return L"1.0";
+ case 2: return L"1.1";
+ case 3: return L"1.1a";
+ case 4: return L"1.2";
+ case 5: return L"1.3";
+ case 6: return L"1.4";
+ case 7: return L"1.5";
+ }
+ return L"";
+}
+
void GetINIInfo(wchar_t *pszSvc)
{
- wchar_t str2[2048];
+ CMStringW str;
WIDATA *sData = GetWIData(pszSvc);
// if the service does not exist among the loaded INI's
if (sData == nullptr) {
- mir_snwprintf(str2, TranslateT("The corresponding INI file for \"%s\" is not found."), pszSvc);
- MessageBox(nullptr, str2, TranslateT("Weather INI information"), MB_OK | MB_ICONINFORMATION);
+ str.Format(TranslateT("The corresponding INI file for \"%s\" is not found."), pszSvc);
}
// if exist, get the information
else {
- mir_snwprintf(str2, TranslateT("Weather INI information for \"%s\":"), pszSvc);
- mir_wstrncat(str2, L"\n\n", _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, TranslateT("Name:"), _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, L"\t\t", _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, sData->DisplayName, _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, L"\n", _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, TranslateT("Internal Name:"), _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, L"\t", _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, sData->InternalName, _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, L"\n", _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, TranslateT("Author:"), _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, L"\t\t", _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, sData->Author, _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, L"\n", _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, TranslateT("Version:"), _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, L"\t\t", _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, sData->Version, _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, L"\n", _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, TranslateT("INI Version:"), _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, L"\t", _countof(str2) - mir_wstrlen(str2));
- switch (sData->InternalVer) {
- case 1: mir_wstrncat(str2, L"1.0", _countof(str2) - mir_wstrlen(str2)); break;
- case 2: mir_wstrncat(str2, L"1.1", _countof(str2) - mir_wstrlen(str2)); break;
- case 3: mir_wstrncat(str2, L"1.1a", _countof(str2) - mir_wstrlen(str2)); break;
- case 4: mir_wstrncat(str2, L"1.2", _countof(str2) - mir_wstrlen(str2)); break;
- case 5: mir_wstrncat(str2, L"1.3", _countof(str2) - mir_wstrlen(str2)); break;
- case 6: mir_wstrncat(str2, L"1.4", _countof(str2) - mir_wstrlen(str2)); break;
- case 7: mir_wstrncat(str2, L"1.5", _countof(str2) - mir_wstrlen(str2)); break;
- }
- mir_wstrncat(str2, L"\n", _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, TranslateT("File Name:"), _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, L"\t", _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, sData->ShortFileName, _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, L"\n", _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, TranslateT("Item Count:"), _countof(str2) - mir_wstrlen(str2));
- mir_snwprintf(str2, L"%s\t%i\n", str2, sData->UpdateDataCount);
- mir_wstrncat(str2, TranslateT("Memory Used:"), _countof(str2) - mir_wstrlen(str2));
- mir_snwprintf(str2, L"%s\t%i ", str2, sData->MemUsed);
- mir_wstrncat(str2, TranslateT("bytes"), _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, L"\n\n", _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, TranslateT("Description:"), _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, L"\n", _countof(str2) - mir_wstrlen(str2));
- mir_wstrncat(str2, sData->Description, _countof(str2) - mir_wstrlen(str2));
-
- // display the message box and quit
- MessageBox(nullptr, str2, TranslateT("Weather INI information"), MB_OK | MB_ICONINFORMATION);
+ str.AppendFormat(TranslateT("Weather INI information for \"%s\":"), pszSvc);
+ str += L"\n\n";
+ str.AppendFormat(L"%s\t%s\n", TranslateT("Name:"), sData->DisplayName);
+ str.AppendFormat(L"%s\t%s\n", TranslateT("Internal Name:"), sData->InternalName);
+ str.AppendFormat(L"%s\t%s\n", TranslateT("Author:"), sData->Author);
+ str.AppendFormat(L"%s\t%s\n", TranslateT("Version:"), sData->Version);
+ str.AppendFormat(L"%s\t%s\n", TranslateT("INI Version:"), GetVersionNum(sData->InternalVer));
+ str.AppendFormat(L"%s\t%s\n", TranslateT("File Name:"), sData->ShortFileName);
+ str.AppendFormat(L"%s\t%i\n", TranslateT("Item Count:"), sData->UpdateDataCount);
+ str.AppendFormat(L"%s\t%i %s\n\n", TranslateT("Memory Used:"), (int)sData->MemUsed, TranslateT("bytes"));
+ str.AppendFormat(L"%s\n%s", TranslateT("Description:"), sData->Description);
}
+
+ MessageBox(nullptr, str, TranslateT("Weather INI information"), MB_OK | MB_ICONINFORMATION);
}
//============ DISPLAY A LIST FOR CUSTOM VARIABLES ============
@@ -207,34 +188,33 @@ void GetINIInfo(wchar_t *pszSvc)
// can be found when click on "More" in text option dialog
void MoreVarList(void)
{
- wchar_t str[10240], tempstr[1024];
-
// heading
- wcsncpy(str, VARS_LIST, _countof(str) - 1);
- mir_wstrncat(str, L"\n\n", _countof(str) - mir_wstrlen(str));
+ CMStringW str(TranslateT("Here is a list of custom variables that are currently available"));
+ str += L"\n\n";
+
// loop through all weather services to find custom variables
+ bool bFirst = true;
for (WIDATALIST *Item = WIHead; Item != nullptr; Item = Item->next) {
// loop through all update items in a service
for (WIDATAITEMLIST *WItem = Item->Data.UpdateData; WItem != nullptr; WItem = WItem->Next) {
// the custom variable is defined as "%[<variable name>]"
// ignore the "hi" item and hidden items
if (mir_wstrcmp(WItem->Item.Name, L"Ignore") && WItem->Item.Name[0] != '#') {
+ wchar_t tempstr[1024];
mir_snwprintf(tempstr, L"%c[%s]", '%', WItem->Item.Name);
- wchar_t *find = wcsstr(str, tempstr);
+ auto *find = wcsstr(str, tempstr);
// if the custom variable does not exist in the list, add it to the list
if (find == nullptr) {
- mir_wstrncat(str, tempstr, _countof(str) - mir_wstrlen(str));
- mir_wstrncat(str, L", ", _countof(str) - mir_wstrlen(str));
+ if (bFirst)
+ bFirst = false;
+ else
+ str += L", ";
+ str += tempstr;
}
}
}
}
- // remove the last comma in the list
- wchar_t* find = wcsrchr(str, ',');
- if (find != nullptr)
- *find = '\0';
// display the list in a message box
MessageBox(nullptr, str, TranslateT("More Variables"), MB_OK | MB_ICONINFORMATION | MB_TOPMOST);
}
-
diff --git a/protocols/Weather/src/weather_ini.cpp b/protocols/Weather/src/weather_ini.cpp
index 81a2831736..0948e4c8a3 100644
--- a/protocols/Weather/src/weather_ini.cpp
+++ b/protocols/Weather/src/weather_ini.cpp
@@ -178,14 +178,14 @@ static INT_PTR CALLBACK DlgProcSetup(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR
case IDC_STEP2:
{
- wchar_t szPath[1024];
- GetModuleFileName(GetModuleHandle(nullptr), szPath, _countof(szPath));
- wchar_t *chop = wcsrchr(szPath, '\\');
- if (chop) {
- *chop = '\0';
- mir_wstrncat(szPath, L"\\Plugins\\weather\\", _countof(szPath) - mir_wstrlen(szPath));
- if (_wmkdir(szPath) == 0)
- ShellExecute((HWND)lParam, L"open", szPath, L"", L"", SW_SHOW);
+ CMStringW wszPath('\x00', MAX_PATH);
+ GetModuleFileName(GetModuleHandle(nullptr), wszPath.GetBuffer(), MAX_PATH);
+ int idx = wszPath.Find('\\');
+ if (idx != -1) {
+ wszPath.Truncate(idx);
+ wszPath += L"\\Plugins\\weather\\";
+ if (_wmkdir(wszPath) == 0)
+ ShellExecute((HWND)lParam, L"open", wszPath, L"", L"", SW_SHOW);
}
break;
}
@@ -223,25 +223,24 @@ static INT_PTR CALLBACK DlgProcSetup(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR
// pszFile = the file name + path for the ini file to be loaded
// pszShortFile = the file name of the ini file, but not including the path
// Data = the struct to load the ini content to, and return to previous function
-static void LoadStationData(wchar_t *pszFile, wchar_t *pszShortFile, WIDATA *Data)
+
+static const char *statusStr[10] =
+{
+ "LIGHTNING",
+ "FOG",
+ "SNOW SHOWER",
+ "SNOW",
+ "RAIN SHOWER",
+ "RAIN",
+ "PARTLY CLOUDY",
+ "CLOUDY",
+ "SUNNY",
+ "N/A"
+};
+
+static void LoadStationData(const wchar_t *pszFile, wchar_t *pszShortFile, WIDATA *Data)
{
WIDATAITEM DataItem;
- char *Group, *Temp;
- char *ValName, *Value;
-
- static const char *statusStr[10] =
- {
- "LIGHTNING",
- "FOG",
- "SNOW SHOWER",
- "SNOW",
- "RAIN SHOWER",
- "RAIN",
- "PARTLY CLOUDY",
- "CLOUDY",
- "SUNNY",
- "N/A"
- };
// clean up old stuff
memset(Data, 0, sizeof(*Data));
@@ -249,231 +248,232 @@ static void LoadStationData(wchar_t *pszFile, wchar_t *pszShortFile, WIDATA *Dat
// open the ini file
FILE *pfile = _wfsopen(pszFile, L"rt", _SH_DENYWR);
- if (pfile != nullptr) {
- char Line[4096];
- fgets(Line, _countof(Line), pfile);
+ if (pfile == nullptr)
+ return;
+
+ char Line[4096];
+ fgets(Line, _countof(Line), pfile);
+ TrimString(Line);
+
+ // make sure it is a valid weather protocol ini file
+ if (!mir_strcmp(Line, "[Weather 0.3.x Update Data]"))
+ Data->InternalVer = 1;
+ else if (!mir_strcmp(Line, "[Weather 0.3.x Update Data 1.1]"))
+ Data->InternalVer = 2;
+ else if (!mir_strcmp(Line, "[Weather 0.3.x Update Data 1.1a]"))
+ Data->InternalVer = 3;
+ else if (!mir_strcmp(Line, "[Weather 0.3.x Update Data 1.2]"))
+ Data->InternalVer = 4;
+ else if (!mir_strcmp(Line, "[Weather 0.3.x Update Data 1.3]"))
+ Data->InternalVer = 5;
+ else if (!mir_strcmp(Line, "[Weather 0.3.x Update Data 1.4]"))
+ Data->InternalVer = 6;
+ else if (!mir_strcmp(Line, "[Weather 0.3.x Update Data 1.5]"))
+ Data->InternalVer = 7;
+ else {
+ wchar_t str[4096];
+ mir_snwprintf(str, TranslateT("Invalid ini format for: %s"), pszFile);
+ MessageBox(nullptr, str, TranslateT("Weather Protocol"), MB_OK | MB_ICONERROR);
+ fclose(pfile);
+ return;
+ }
+
+ // initialize all data fields
+ char *Group = "";
+
+ Data->DisplayName = L"";
+ Data->InternalName = L"";
+ Data->Description = L"";
+ Data->Author = L"";
+ Data->Version = L"";
+ Data->DefaultURL = "";
+ Data->DefaultMap = L"";
+ Data->UpdateURL = "";
+ Data->UpdateURL2 = "";
+ Data->UpdateURL3 = "";
+ Data->UpdateURL4 = "";
+ Data->Cookie = "";
+ Data->UserAgent = "";
+ Data->IDSearch.SearchURL = "";
+ Data->IDSearch.NotFoundStr = L"";
+ Data->NameSearch.SearchURL = "";
+ Data->NameSearch.NotFoundStr = L"";
+ Data->NameSearch.SingleStr = L"";
+ Data->NameSearch.Single.First = L"";
+ Data->NameSearch.Multiple.First = L"";
+ Data->IDSearch.Available = FALSE;
+ Data->NameSearch.Single.Available = FALSE;
+ Data->NameSearch.Multiple.Available = FALSE;
+ wSetData(&Data->FileName, pszFile);
+ wSetData(&Data->ShortFileName, pszShortFile);
+
+ ResetDataItem(&Data->IDSearch.Name, L"ID Search - Station Name");
+ ResetDataItem(&Data->NameSearch.Single.Name, L"Name Search Single Result - Station Name");
+ ResetDataItem(&Data->NameSearch.Single.ID, L"Name Search Single Result - Station ID");
+ ResetDataItem(&Data->NameSearch.Multiple.Name, L"Name Search Multiple Result - Station Name");
+ ResetDataItem(&Data->NameSearch.Multiple.ID, L"Name Search Multiple Result - Station ID");
+
+ DataItem.Name = L"";
+ DataItem.Start = L"";
+ DataItem.End = L"";
+ DataItem.Unit = L"";
+ DataItem.Url = "";
+ DataItem.Break = L"";
+ DataItem.Type = 0;
+
+ // initialize the linked list for update items
+ Data->UpdateDataCount = 0;
+ Data->MemUsed = sizeof(WIDATA) + sizeof(WIDATALIST) + (mir_wstrlen(pszShortFile) + mir_wstrlen(pszFile) + 20)*sizeof(wchar_t);
+ Data->UpdateData = nullptr;
+ Data->UpdateDataTail = nullptr;
+
+ // initialize the icon assignment list
+ for (int i = 0; i < 10; i++)
+ WICondListInit(&Data->CondList[i]);
+
+ while (!feof(pfile)) {
+ // determine current tag
+ if (fgets(Line, _countof(Line), pfile) == nullptr)
+ break;
+
TrimString(Line);
- // make sure it is a valid weather protocol ini file
- if (!mir_strcmp(Line, "[Weather 0.3.x Update Data]"))
- Data->InternalVer = 1;
- else if (!mir_strcmp(Line, "[Weather 0.3.x Update Data 1.1]"))
- Data->InternalVer = 2;
- else if (!mir_strcmp(Line, "[Weather 0.3.x Update Data 1.1a]"))
- Data->InternalVer = 3;
- else if (!mir_strcmp(Line, "[Weather 0.3.x Update Data 1.2]"))
- Data->InternalVer = 4;
- else if (!mir_strcmp(Line, "[Weather 0.3.x Update Data 1.3]"))
- Data->InternalVer = 5;
- else if (!mir_strcmp(Line, "[Weather 0.3.x Update Data 1.4]"))
- Data->InternalVer = 6;
- else if (!mir_strcmp(Line, "[Weather 0.3.x Update Data 1.5]"))
- Data->InternalVer = 7;
- else {
- wchar_t str[4096];
- mir_snwprintf(str, TranslateT("Invalid ini format for: %s"), pszFile);
- MessageBox(nullptr, str, TranslateT("Weather Protocol"), MB_OK | MB_ICONERROR);
- fclose(pfile);
- return;
+ // if the line is a group header/footer
+ if (Line[0] == '[') {
+ char *chop = strchr(Line + 1, ']');
+ if (chop == nullptr)
+ continue;
+
+ if (Line[1] != '/') { // if it is not a footer (for old ini)
+ // save the group name
+ char *Temp = (char *)mir_alloc(mir_strlen(Line) + 10);
+ strncpy(Temp, Line + 1, chop - Line - 1);
+ Temp[chop - Line - 1] = 0;
+ wfree(&Group);
+ wSetData(&Group, Temp);
+
+ // see if it is a update item, if it is, add a new item to the linked list
+ if (_stricmp(Group, "HEADER") && _stricmp(Group, "DEFAULT") && _stricmp(Group, "ID SEARCH") &&
+ _stricmp(Group, "NAME SEARCH") && _stricmp(Group, "ICONS")) {
+ wSetData(&DataItem.Name, Temp);
+ DataItem.Type = WID_NORMAL;
+ WIItemListAdd(&DataItem, Data);
+ Data->UpdateDataCount++;
+ }
+ mir_free(Temp);
+ }
+ else {
+ wfree(&Group);
+ wSetData(&Group, "");
+ }
}
- // initialize all data fields
- Group = "";
-
- Data->DisplayName = L"";
- Data->InternalName = L"";
- Data->Description = L"";
- Data->Author = L"";
- Data->Version = L"";
- Data->DefaultURL = "";
- Data->DefaultMap = L"";
- Data->UpdateURL = "";
- Data->UpdateURL2 = "";
- Data->UpdateURL3 = "";
- Data->UpdateURL4 = "";
- Data->Cookie = "";
- Data->UserAgent = "";
- Data->IDSearch.SearchURL = "";
- Data->IDSearch.NotFoundStr = L"";
- Data->NameSearch.SearchURL = "";
- Data->NameSearch.NotFoundStr = L"";
- Data->NameSearch.SingleStr = L"";
- Data->NameSearch.Single.First = L"";
- Data->NameSearch.Multiple.First = L"";
- Data->IDSearch.Available = FALSE;
- Data->NameSearch.Single.Available = FALSE;
- Data->NameSearch.Multiple.Available = FALSE;
- wSetData(&Data->FileName, pszFile);
- wSetData(&Data->ShortFileName, pszShortFile);
-
- ResetDataItem(&Data->IDSearch.Name, L"ID Search - Station Name");
- ResetDataItem(&Data->NameSearch.Single.Name, L"Name Search Single Result - Station Name");
- ResetDataItem(&Data->NameSearch.Single.ID, L"Name Search Single Result - Station ID");
- ResetDataItem(&Data->NameSearch.Multiple.Name, L"Name Search Multiple Result - Station Name");
- ResetDataItem(&Data->NameSearch.Multiple.ID, L"Name Search Multiple Result - Station ID");
-
- DataItem.Name = L"";
- DataItem.Start = L"";
- DataItem.End = L"";
- DataItem.Unit = L"";
- DataItem.Url = "";
- DataItem.Break = L"";
- DataItem.Type = 0;
-
- Temp = "";
-
- // initialize the linked list for update items
- Data->UpdateDataCount = 0;
- Data->MemUsed = sizeof(WIDATA) + sizeof(WIDATALIST) + (mir_wstrlen(pszShortFile) + mir_wstrlen(pszFile) + 20)*sizeof(wchar_t);
- Data->UpdateData = nullptr;
- Data->UpdateDataTail = nullptr;
-
- // initialize the icon assignment list
- for (int i = 0; i < 10; i++)
- WICondListInit(&Data->CondList[i]);
-
- while (!feof(pfile)) {
- // determine current tag
-
- if (fgets(Line, _countof(Line), pfile) == nullptr)
- break;
- TrimString(Line);
-
- // if the line is a group header/footer
- if (Line[0] == '[') {
- char *chop = strchr(Line + 1, ']');
- if (chop == nullptr)
- continue;
-
- if (Line[1] != '/') { // if it is not a footer (for old ini)
- // save the group name
- Temp = (char *)mir_alloc(mir_strlen(Line) + 10);
- strncpy(Temp, Line + 1, chop - Line - 1);
- Temp[chop - Line - 1] = 0;
- wfree(&Group);
- wSetData(&Group, Temp);
- // see if it is a update item, if it is, add a new item to the linked list
- // if (_stricmp(Group, "HEADER") && _stricmp(Group, "DEFAULT") && _stricmp(Group, "ID SEARCH") &&
- // strcmpi(Group, "NAME SEARCH"))
- // wSetData(&DataItem.Name, Group);
- if (_stricmp(Group, "HEADER") && _stricmp(Group, "DEFAULT") && _stricmp(Group, "ID SEARCH") &&
- _stricmp(Group, "NAME SEARCH") && _stricmp(Group, "ICONS")) {
- wSetData(&DataItem.Name, Temp);
- DataItem.Type = WID_NORMAL;
- WIItemListAdd(&DataItem, Data);
- Data->UpdateDataCount++;
- }
- mir_free(Temp);
- }
- else {
- wfree(&Group);
- wSetData(&Group, "");
- }
+ // ignore comments and all lines without an '='
+ char *Value = strchr(Line, '=');
+ if (Value == nullptr)
+ continue;
+
+ // get the string before '=' (ValName) and after '=' (Value)
+ char *ValName = (char *)mir_alloc(mir_strlen(Line) + 1);
+ strncpy(ValName, Line, Value - Line);
+ ValName[Value - Line] = 0;
+ Value++;
+ ConvertBackslashes(Value);
+
+ // store the value for each string
+ if (!_stricmp(Group, "HEADER")) {
+ if (!_stricmp(ValName, "NAME")) wSetData(&Data->DisplayName, Value);
+ else if (!_stricmp(ValName, "INTERNAL NAME")) wSetData(&Data->InternalName, Value);
+ else if (!_stricmp(ValName, "DESCRIPTION")) wSetData(&Data->Description, Value);
+ else if (!_stricmp(ValName, "AUTHOR")) wSetData(&Data->Author, Value);
+ else if (!_stricmp(ValName, "VERSION")) wSetData(&Data->Version, Value);
+ }
+ else if (!_stricmp(Group, "DEFAULT")) {
+ if (!_stricmp(ValName, "DEFAULT URL")) wSetData(&Data->DefaultURL, Value);
+ else if (!_stricmp(ValName, "DEFAULT MAP")) wSetData(&Data->DefaultMap, Value);
+ else if (!_stricmp(ValName, "UPDATE URL")) wSetData(&Data->UpdateURL, Value);
+ else if (!_stricmp(ValName, "UPDATE URL2")) wSetData(&Data->UpdateURL2, Value);
+ else if (!_stricmp(ValName, "UPDATE URL3")) wSetData(&Data->UpdateURL3, Value);
+ else if (!_stricmp(ValName, "UPDATE URL4")) wSetData(&Data->UpdateURL4, Value);
+ else if (!_stricmp(ValName, "COOKIE")) wSetData(&Data->Cookie, Value);
+ else if (!_stricmp(ValName, "USERAGENT")) wSetData(&Data->UserAgent, Value);
+ }
+ else if (!_stricmp(Group, "ID SEARCH")) {
+ if (!_stricmp(ValName, "AVAILABLE")) {
+ if (!_stricmp(Value, "TRUE")) Data->IDSearch.Available = TRUE;
+ else Data->IDSearch.Available = FALSE;
}
- // ignore comments and all lines without an '='
- Value = strchr(Line, '=');
- if (Value == nullptr) continue;
-
- // get the string before '=' (ValName) and after '=' (Value)
- ValName = (char *)mir_alloc(mir_strlen(Line) + 1);
- strncpy(ValName, Line, Value - Line);
- ValName[Value - Line] = 0;
- Value++;
- ConvertBackslashes(Value);
- // store the value for each string
- if (!_stricmp(Group, "HEADER")) {
- if (!_stricmp(ValName, "NAME")) wSetData(&Data->DisplayName, Value);
- else if (!_stricmp(ValName, "INTERNAL NAME")) wSetData(&Data->InternalName, Value);
- else if (!_stricmp(ValName, "DESCRIPTION")) wSetData(&Data->Description, Value);
- else if (!_stricmp(ValName, "AUTHOR")) wSetData(&Data->Author, Value);
- else if (!_stricmp(ValName, "VERSION")) wSetData(&Data->Version, Value);
+ else if (!_stricmp(ValName, "SEARCH URL")) wSetData(&Data->IDSearch.SearchURL, Value);
+ else if (!_stricmp(ValName, "NOT FOUND STR")) wSetData(&Data->IDSearch.NotFoundStr, Value);
+ else if (!_stricmp(ValName, "NAME START")) wSetData(&Data->IDSearch.Name.Start, Value);
+ else if (!_stricmp(ValName, "NAME END")) wSetData(&Data->IDSearch.Name.End, Value);
+ }
+ else if (!_stricmp(Group, "NAME SEARCH")) {
+ if (!_stricmp(ValName, "SINGLE RESULT")) {
+ if (!_stricmp(Value, "TRUE")) Data->NameSearch.Single.Available = TRUE;
+ else Data->NameSearch.Single.Available = FALSE;
}
- else if (!_stricmp(Group, "DEFAULT")) {
- if (!_stricmp(ValName, "DEFAULT URL")) wSetData(&Data->DefaultURL, Value);
- else if (!_stricmp(ValName, "DEFAULT MAP")) wSetData(&Data->DefaultMap, Value);
- else if (!_stricmp(ValName, "UPDATE URL")) wSetData(&Data->UpdateURL, Value);
- else if (!_stricmp(ValName, "UPDATE URL2")) wSetData(&Data->UpdateURL2, Value);
- else if (!_stricmp(ValName, "UPDATE URL3")) wSetData(&Data->UpdateURL3, Value);
- else if (!_stricmp(ValName, "UPDATE URL4")) wSetData(&Data->UpdateURL4, Value);
- else if (!_stricmp(ValName, "COOKIE")) wSetData(&Data->Cookie, Value);
- else if (!_stricmp(ValName, "USERAGENT")) wSetData(&Data->UserAgent, Value);
+ else if (!_stricmp(ValName, "MULTIPLE RESULT")) {
+ if (!_stricmp(Value, "TRUE")) Data->NameSearch.Multiple.Available = TRUE;
+ else Data->NameSearch.Multiple.Available = FALSE;
}
- else if (!_stricmp(Group, "ID SEARCH")) {
- if (!_stricmp(ValName, "AVAILABLE")) {
- if (!_stricmp(Value, "TRUE")) Data->IDSearch.Available = TRUE;
- else Data->IDSearch.Available = FALSE;
+ else if (!_stricmp(ValName, "SEARCH URL")) wSetData(&Data->NameSearch.SearchURL, Value);
+ else if (!_stricmp(ValName, "NOT FOUND STR")) wSetData(&Data->NameSearch.NotFoundStr, Value);
+ else if (!_stricmp(ValName, "SINGLE RESULT STR")) wSetData(&Data->NameSearch.SingleStr, Value);
+ else if (!_stricmp(ValName, "SINGLE FIRST")) wSetData(&Data->NameSearch.Single.First, Value);
+ else if (!_stricmp(ValName, "SINGLE NAME START"))wSetData(&Data->NameSearch.Single.Name.Start, Value);
+ else if (!_stricmp(ValName, "SINGLE NAME END")) wSetData(&Data->NameSearch.Single.Name.End, Value);
+ else if (!_stricmp(ValName, "SINGLE ID START")) wSetData(&Data->NameSearch.Single.ID.Start, Value);
+ else if (!_stricmp(ValName, "SINGLE ID END")) wSetData(&Data->NameSearch.Single.ID.End, Value);
+ else if (!_stricmp(ValName, "MULT FIRST")) wSetData(&Data->NameSearch.Multiple.First, Value);
+ else if (!_stricmp(ValName, "MULT NAME START")) wSetData(&Data->NameSearch.Multiple.Name.Start, Value);
+ else if (!_stricmp(ValName, "MULT NAME END")) wSetData(&Data->NameSearch.Multiple.Name.End, Value);
+ else if (!_stricmp(ValName, "MULT ID START")) wSetData(&Data->NameSearch.Multiple.ID.Start, Value);
+ else if (!_stricmp(ValName, "MULT ID END")) wSetData(&Data->NameSearch.Multiple.ID.End, Value);
+ }
+ else if (!_stricmp(Group, "ICONS")) {
+ for (int i = 0; i < 10; i++) {
+ if (!_stricmp(ValName, statusStr[i])) {
+ WICondListAdd(Value, &Data->CondList[i]);
+ break;
}
- else if (!_stricmp(ValName, "SEARCH URL")) wSetData(&Data->IDSearch.SearchURL, Value);
- else if (!_stricmp(ValName, "NOT FOUND STR")) wSetData(&Data->IDSearch.NotFoundStr, Value);
- else if (!_stricmp(ValName, "NAME START")) wSetData(&Data->IDSearch.Name.Start, Value);
- else if (!_stricmp(ValName, "NAME END")) wSetData(&Data->IDSearch.Name.End, Value);
}
- else if (!_stricmp(Group, "NAME SEARCH")) {
- if (!_stricmp(ValName, "SINGLE RESULT")) {
- if (!_stricmp(Value, "TRUE")) Data->NameSearch.Single.Available = TRUE;
- else Data->NameSearch.Single.Available = FALSE;
- }
- else if (!_stricmp(ValName, "MULTIPLE RESULT")) {
- if (!_stricmp(Value, "TRUE")) Data->NameSearch.Multiple.Available = TRUE;
- else Data->NameSearch.Multiple.Available = FALSE;
+ }
+ else if (Data->UpdateDataCount != 0) {
+ if (!_stricmp(ValName, "START")) wSetData(&Data->UpdateDataTail->Item.Start, Value);
+ else if (!_stricmp(ValName, "SOURCE")) wSetData(&Data->UpdateDataTail->Item.Start, Value);
+ else if (!_stricmp(ValName, "END")) wSetData(&Data->UpdateDataTail->Item.End, Value);
+ else if (!_stricmp(ValName, "UNIT")) wSetData(&Data->UpdateDataTail->Item.Unit, Value);
+ else if (!_stricmp(ValName, "URL")) wSetData(&Data->UpdateDataTail->Item.Url, Value);
+ else if (!_stricmp(ValName, "HIDDEN")) {
+ if (!_stricmp(Value, "TRUE")) {
+ wchar_t *nm = Data->UpdateDataTail->Item.Name;
+ size_t len = mir_wstrlen(nm) + 1;
+
+ Data->UpdateDataTail->Item.Name = nm = (wchar_t*)mir_realloc(nm, sizeof(wchar_t)*(len + 3));
+ memmove(nm + 1, nm, len*sizeof(wchar_t));
+ *nm = '#';
}
- else if (!_stricmp(ValName, "SEARCH URL")) wSetData(&Data->NameSearch.SearchURL, Value);
- else if (!_stricmp(ValName, "NOT FOUND STR")) wSetData(&Data->NameSearch.NotFoundStr, Value);
- else if (!_stricmp(ValName, "SINGLE RESULT STR")) wSetData(&Data->NameSearch.SingleStr, Value);
- else if (!_stricmp(ValName, "SINGLE FIRST")) wSetData(&Data->NameSearch.Single.First, Value);
- else if (!_stricmp(ValName, "SINGLE NAME START"))wSetData(&Data->NameSearch.Single.Name.Start, Value);
- else if (!_stricmp(ValName, "SINGLE NAME END")) wSetData(&Data->NameSearch.Single.Name.End, Value);
- else if (!_stricmp(ValName, "SINGLE ID START")) wSetData(&Data->NameSearch.Single.ID.Start, Value);
- else if (!_stricmp(ValName, "SINGLE ID END")) wSetData(&Data->NameSearch.Single.ID.End, Value);
- else if (!_stricmp(ValName, "MULT FIRST")) wSetData(&Data->NameSearch.Multiple.First, Value);
- else if (!_stricmp(ValName, "MULT NAME START")) wSetData(&Data->NameSearch.Multiple.Name.Start, Value);
- else if (!_stricmp(ValName, "MULT NAME END")) wSetData(&Data->NameSearch.Multiple.Name.End, Value);
- else if (!_stricmp(ValName, "MULT ID START")) wSetData(&Data->NameSearch.Multiple.ID.Start, Value);
- else if (!_stricmp(ValName, "MULT ID END")) wSetData(&Data->NameSearch.Multiple.ID.End, Value);
}
- else if (!_stricmp(Group, "ICONS")) {
- for (int i = 0; i < 10; i++) {
- if (!_stricmp(ValName, statusStr[i])) {
- WICondListAdd(Value, &Data->CondList[i]);
- break;
- }
- }
+ else if (!_stricmp(ValName, "SET DATA")) {
+ Data->UpdateDataTail->Item.Type = WID_SET;
+ wSetData(&Data->UpdateDataTail->Item.End, Value);
}
- else if (Data->UpdateDataCount != 0) {
- if (!_stricmp(ValName, "START")) wSetData(&Data->UpdateDataTail->Item.Start, Value);
- else if (!_stricmp(ValName, "SOURCE")) wSetData(&Data->UpdateDataTail->Item.Start, Value);
- else if (!_stricmp(ValName, "END")) wSetData(&Data->UpdateDataTail->Item.End, Value);
- else if (!_stricmp(ValName, "UNIT")) wSetData(&Data->UpdateDataTail->Item.Unit, Value);
- else if (!_stricmp(ValName, "URL")) wSetData(&Data->UpdateDataTail->Item.Url, Value);
- else if (!_stricmp(ValName, "HIDDEN")) {
- if (!_stricmp(Value, "TRUE")) {
- wchar_t *nm = Data->UpdateDataTail->Item.Name;
- size_t len = mir_wstrlen(nm) + 1;
-
- Data->UpdateDataTail->Item.Name = nm = (wchar_t*)mir_realloc(nm, sizeof(wchar_t)*(len + 3));
- memmove(nm + 1, nm, len*sizeof(wchar_t));
- *nm = '#';
- }
- }
- else if (!_stricmp(ValName, "SET DATA")) {
- Data->UpdateDataTail->Item.Type = WID_SET;
- wSetData(&Data->UpdateDataTail->Item.End, Value);
- }
- else if (!_stricmp(ValName, "BREAK DATA")) {
- Data->UpdateDataTail->Item.Type = WID_BREAK;
- wSetData(&Data->UpdateDataTail->Item.Break, Value);
- }
+ else if (!_stricmp(ValName, "BREAK DATA")) {
+ Data->UpdateDataTail->Item.Type = WID_BREAK;
+ wSetData(&Data->UpdateDataTail->Item.Break, Value);
}
- // recalculate memory used
- Data->MemUsed += (mir_strlen(Value) + 10);
- wfree(&ValName);
}
- // calcualate memory used for the ini and close the file
- Data->MemUsed += sizeof(WIDATAITEMLIST)*Data->UpdateDataCount;
- Data->Enabled = TRUE; // enable the service
- fclose(pfile);
- wfree(&Group);
+ // recalculate memory used
+ Data->MemUsed += (mir_strlen(Value) + 10);
+ wfree(&ValName);
}
+
+ // calcualate memory used for the ini and close the file
+ Data->MemUsed += sizeof(WIDATAITEMLIST)*Data->UpdateDataCount;
+ Data->Enabled = TRUE; // enable the service
+ fclose(pfile);
+ wfree(&Group);
}
//============ LOADING INI FILES ============
@@ -486,28 +486,23 @@ bool LoadWIData(bool dial)
WIHead = WITail;
// find all *.ini file in the plugin\weather directory
- wchar_t szSearchPath[MAX_PATH], FileName[MAX_PATH];
- GetModuleFileName(GetModuleHandle(nullptr), szSearchPath, _countof(szSearchPath));
- wchar_t *chop = wcsrchr(szSearchPath, '\\');
- if (chop == nullptr)
+ CMStringW wszFileName('\x00', MAX_PATH);
+ GetModuleFileName(GetModuleHandle(nullptr), wszFileName.GetBuffer(), MAX_PATH);
+ int idx = wszFileName.ReverseFind('\\');
+ if (idx == -1)
return false;
- *chop = '\0';
- mir_wstrncat(szSearchPath, L"\\Plugins\\Weather\\*.ini", _countof(szSearchPath) - mir_wstrlen(szSearchPath));
- wcsncpy(FileName, szSearchPath, MAX_PATH - 1);
+ wszFileName.Truncate(idx);
+ wszFileName += L"\\Plugins\\Weather\\";
WIN32_FIND_DATA fd;
- HANDLE hFind = FindFirstFile(szSearchPath, &fd);
-
+ HANDLE hFind = FindFirstFile(wszFileName + L"*.ini", &fd);
// load the content of the ini file into memory
if (hFind != INVALID_HANDLE_VALUE) {
do {
- chop = wcsrchr(FileName, '\\');
- chop[1] = '\0';
- mir_wstrncat(FileName, fd.cFileName, _countof(FileName) - mir_wstrlen(FileName));
if (mir_wstrcmpi(fd.cFileName, L"SAMPLE_INI.INI")) {
WIDATA Data;
- LoadStationData(FileName, fd.cFileName, &Data);
+ LoadStationData(wszFileName + fd.cFileName, fd.cFileName, &Data);
if (Data.Enabled)
WIListAdd(Data);
}
diff --git a/protocols/Weather/src/weather_mwin.cpp b/protocols/Weather/src/weather_mwin.cpp
index c837648c09..27c6664a1e 100644
--- a/protocols/Weather/src/weather_mwin.cpp
+++ b/protocols/Weather/src/weather_mwin.cpp
@@ -68,7 +68,7 @@ static LRESULT CALLBACK wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
case WM_MOUSEMOVE:
{
- TRACKMOUSEEVENT tme = { 0 };
+ TRACKMOUSEEVENT tme = {};
tme.cbSize = sizeof(TRACKMOUSEEVENT);
tme.hwndTrack = hwnd;
tme.dwFlags = TME_QUERY;
@@ -86,7 +86,7 @@ static LRESULT CALLBACK wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
case WM_MOUSEHOVER:
{
POINT pt;
- CLCINFOTIP ti = { 0 };
+ CLCINFOTIP ti = {};
GetCursorPos(&pt);
GetWindowRect(hwnd, &ti.rcItem);
@@ -239,7 +239,7 @@ static void addWindow(MCONTACT hContact)
0, 0, 10, 10, g_clistApi.hwndContactList, nullptr, g_plugin.getInst(), (void*)hContact);
WindowList_Add(hMwinWindowList, hWnd, hContact);
- CLISTFrame Frame = { 0 };
+ CLISTFrame Frame = {};
Frame.szName.w = winname;
Frame.hIcon = g_plugin.getIcon(IDI_ICON);
Frame.cbSize = sizeof(Frame);
diff --git a/protocols/Weather/src/weather_opt.cpp b/protocols/Weather/src/weather_opt.cpp
index 8422c28370..f560ae3e49 100644
--- a/protocols/Weather/src/weather_opt.cpp
+++ b/protocols/Weather/src/weather_opt.cpp
@@ -106,19 +106,23 @@ void LoadOptions(void)
// advanced
opt.DisCondIcon = g_plugin.getByte("DisableConditionIcon", false);
+
// popup options
opt.UsePopup = g_plugin.getByte("UsePopUp", true);
opt.UpdatePopup = g_plugin.getByte("UpdatePopup", true);
opt.AlertPopup = g_plugin.getByte("AlertPopup", true);
opt.PopupOnChange = g_plugin.getByte("PopUpOnChange", true);
opt.ShowWarnings = g_plugin.getByte("ShowWarnings", true);
+
// popup colors
opt.BGColour = g_plugin.getDword("BackgroundColour", GetSysColor(COLOR_BTNFACE));
opt.TextColour = g_plugin.getDword("TextColour", GetSysColor(COLOR_WINDOWTEXT));
opt.UseWinColors = g_plugin.getByte("UseWinColors", false);
+
// popup actions
opt.LeftClickAction = g_plugin.getDword("LeftClickAction", IDM_M2);
opt.RightClickAction = g_plugin.getDword("RightClickAction", IDM_M1);
+
// popup delay
opt.pDelay = g_plugin.getDword("PopupDelay", 0);
@@ -141,6 +145,7 @@ void SaveOptions(void)
g_plugin.setByte("RemoveOld", (BYTE)opt.RemoveOldData);
g_plugin.setByte("MakeItalic", (BYTE)opt.MakeItalic);
g_plugin.setByte("AvatarSize", (BYTE)opt.AvatarSize);
+
// units
g_plugin.setWord("tUnit", opt.tUnit);
g_plugin.setWord("wUnit", opt.wUnit);
@@ -151,29 +156,36 @@ void SaveOptions(void)
g_plugin.setWString("DegreeSign", opt.DegreeSign);
g_plugin.setByte("DoNotAppendUnit", (BYTE)opt.DoNotAppendUnit);
g_plugin.setByte("NoFractions", (BYTE)opt.NoFrac);
+
// advanced
g_plugin.setByte("DisableConditionIcon", (BYTE)opt.DisCondIcon);
+
// popup options
g_plugin.setByte("UsePopUp", (BYTE)opt.UsePopup);
g_plugin.setByte("UpdatePopup", (BYTE)opt.UpdatePopup);
g_plugin.setByte("AlertPopup", (BYTE)opt.AlertPopup);
g_plugin.setByte("PopUpOnChange", (BYTE)opt.PopupOnChange);
g_plugin.setByte("ShowWarnings", (BYTE)opt.ShowWarnings);
+
// popup colors
g_plugin.setDword("BackgroundColour", opt.BGColour);
g_plugin.setDword("TextColour", opt.TextColour);
g_plugin.setByte("UseWinColors", (BYTE)opt.UseWinColors);
+
// popup actions
g_plugin.setDword("LeftClickAction", opt.LeftClickAction);
g_plugin.setDword("RightClickAction", opt.RightClickAction);
+
// popup delay
g_plugin.setDword("PopupDelay", opt.pDelay);
+
// misc stuff
g_plugin.setWString("Default", opt.Default);
}
-//============ MAIN OPTIONS ============
+//============ MAIN OPTIONS ============
// weather options
+
static INT_PTR CALLBACK OptionsProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
{
wchar_t str[512];
@@ -333,7 +345,6 @@ static INT_PTR CALLBACK DlgProcText(HWND hdlg, UINT msg, WPARAM wParam, LPARAM l
RECT rc, pos;
HWND button;
HMENU hMenu, hMenu1;
- wchar_t str[4096];
switch (msg) {
case WM_INITDIALOG:
opt_startup = TRUE;
@@ -343,8 +354,7 @@ static INT_PTR CALLBACK DlgProcText(HWND hdlg, UINT msg, WPARAM wParam, LPARAM l
TranslateDialogDefault(hdlg);
// generate the display text for variable list
- wcsncpy(str, VAR_LIST_OPT, _countof(str) - 1);
- SetDlgItemText(hdlg, IDC_VARLIST, str);
+ SetDlgItemText(hdlg, IDC_VARLIST, VAR_LIST_OPT);
for (auto &it : controls)
SetDlgItemText(hdlg, it.id, GetTextValue(it.c));
@@ -407,7 +417,7 @@ static INT_PTR CALLBACK DlgProcText(HWND hdlg, UINT msg, WPARAM wParam, LPARAM l
{
// show the preview in a message box, using the weather data from the default station
WEATHERINFO winfo = LoadWeatherInfo(opt.DefStn);
- wchar_t buf[2] = { var.c, 0 };
+ wchar_t buf[2] = { var.c, 0 }, str[4096];
GetDisplay(&winfo, buf, str);
MessageBox(nullptr, str, TranslateT("Weather Protocol Text Preview"), MB_OK | MB_TOPMOST);
}
diff --git a/protocols/Weather/src/weather_popup.cpp b/protocols/Weather/src/weather_popup.cpp
index 5f2ca4ac3b..aca5559e6b 100644
--- a/protocols/Weather/src/weather_popup.cpp
+++ b/protocols/Weather/src/weather_popup.cpp
@@ -81,7 +81,7 @@ int WeatherError(WPARAM wParam, LPARAM lParam)
// (threaded)
// lpzText = error text
// kind = display type (see m_popup.h)
-int WPShowMessage(wchar_t* lpzText, WORD kind)
+int WPShowMessage(const wchar_t* lpzText, WORD kind)
{
NotifyEventHooks(hHookWeatherError, (WPARAM)lpzText, (LPARAM)kind);
return 0;
@@ -246,7 +246,6 @@ void ReadPopupOpt(HWND hdlg)
INT_PTR CALLBACK DlgPopupOpts(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
int ID;
- wchar_t str[512];
HMENU hMenu, hMenu1;
RECT pos;
HWND button;
@@ -260,6 +259,8 @@ INT_PTR CALLBACK DlgPopupOpts(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam)
// click actions
hMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_PMENU));
hMenu1 = GetSubMenu(hMenu, 0);
+
+ wchar_t str[512];
GetMenuString(hMenu1, opt.LeftClickAction, str, _countof(str), MF_BYCOMMAND);
SetDlgItemText(hdlg, IDC_LeftClick, TranslateW(str));
GetMenuString(hMenu1, opt.RightClickAction, str, _countof(str), MF_BYCOMMAND);
@@ -285,10 +286,12 @@ INT_PTR CALLBACK DlgPopupOpts(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam)
CheckRadioButton(hdlg, IDC_PD1, IDC_PD3, IDC_PD1);
else
CheckRadioButton(hdlg, IDC_PD1, IDC_PD3, IDC_PD3);
- //Colours. First step is configuring the colours.
+
+ // Colours. First step is configuring the colours.
SendDlgItemMessage(hdlg, IDC_BGCOLOUR, CPM_SETCOLOUR, 0, opt.BGColour);
SendDlgItemMessage(hdlg, IDC_TEXTCOLOUR, CPM_SETCOLOUR, 0, opt.TextColour);
- //Second step is disabling them if we want to use default Windows ones.
+
+ // Second step is disabling them if we want to use default Windows ones.
CheckDlgButton(hdlg, IDC_USEWINCOLORS, opt.UseWinColors ? BST_CHECKED : BST_UNCHECKED);
EnableWindow(GetDlgItem(hdlg, IDC_BGCOLOUR), !opt.UseWinColors);
EnableWindow(GetDlgItem(hdlg, IDC_TEXTCOLOUR), !opt.UseWinColors);
@@ -395,11 +398,14 @@ INT_PTR CALLBACK DlgPopupOpts(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam)
case IDC_VAR3:
// display variable list
- wcsncpy(str, L" \n", _countof(str) - 1); // to make the message box wider
- mir_wstrncat(str, VAR_LIST_POPUP, _countof(str) - mir_wstrlen(str));
- mir_wstrncat(str, L"\n", _countof(str) - mir_wstrlen(str));
- mir_wstrncat(str, CUSTOM_VARS, _countof(str) - mir_wstrlen(str));
- MessageBox(nullptr, str, TranslateT("Variable List"), MB_OK | MB_ICONASTERISK | MB_TOPMOST);
+ {
+ CMStringW wszText;
+ wszText += L" \n"; // to make the message box wider
+ wszText += TranslateT("%c\tcurrent condition\n%d\tcurrent date\n%e\tdewpoint\n%f\tfeel-like temperature\n%h\ttoday's high\n%i\twind direction\n%l\ttoday's low\n%m\thumidity\n%n\tstation name\n%p\tpressure\n%r\tsunrise time\n%s\tstation ID\n%t\ttemperature\n%u\tupdate time\n%v\tvisibility\n%w\twind speed\n%y\tsun set");
+ wszText += L"\n";
+ wszText += TranslateT("%[..]\tcustom variables");
+ MessageBox(nullptr, wszText, TranslateT("Variable List"), MB_OK | MB_ICONASTERISK | MB_TOPMOST);
+ }
break;
case IDC_PREVIEW:
diff --git a/protocols/Weather/src/weather_svcs.cpp b/protocols/Weather/src/weather_svcs.cpp
index 3b53b7ee74..e71a5fa0e0 100644
--- a/protocols/Weather/src/weather_svcs.cpp
+++ b/protocols/Weather/src/weather_svcs.cpp
@@ -156,7 +156,7 @@ INT_PTR WeatherGetAvatarInfo(WPARAM, LPARAM lParam)
void AvatarDownloaded(MCONTACT hContact)
{
- PROTO_AVATAR_INFORMATION ai = { 0 };
+ PROTO_AVATAR_INFORMATION ai = {};
ai.hContact = hContact;
if (WeatherGetAvatarInfo(GAIF_FORCE, (LPARAM)&ai) == GAIR_SUCCESS)
diff --git a/protocols/Weather/src/weather_update.cpp b/protocols/Weather/src/weather_update.cpp
index 7c36bebe99..ae875de91f 100644
--- a/protocols/Weather/src/weather_update.cpp
+++ b/protocols/Weather/src/weather_update.cpp
@@ -26,7 +26,7 @@ menu items).
#include "stdafx.h"
-UPDATELIST *UpdateListHead, *UpdateListTail;
+UPDATELIST *UpdateListHead = nullptr, *UpdateListTail = nullptr;
//============ RETRIEVE NEW WEATHER ============
//
@@ -34,7 +34,7 @@ UPDATELIST *UpdateListHead, *UpdateListTail;
// hContact = current contact
int UpdateWeather(MCONTACT hContact)
{
- wchar_t str[256], str2[MAX_TEXT_SIZE];
+ wchar_t str2[MAX_TEXT_SIZE];
DBVARIANT dbv;
BOOL Ch = FALSE;
@@ -56,13 +56,10 @@ int UpdateWeather(MCONTACT hContact)
// error occurs if the return value is not equals to 0
if (opt.ShowWarnings) {
// show warnings by popup
- mir_snwprintf(str, _countof(str) - 105,
- TranslateT("Unable to retrieve weather information for %s"), dbv.pwszVal);
- mir_wstrncat(str, L"\n", _countof(str) - mir_wstrlen(str));
- wchar_t *tszError = GetError(code);
- mir_wstrncat(str, tszError, _countof(str) - mir_wstrlen(str));
+ CMStringW str(FORMAT, TranslateT("Unable to retrieve weather information for %s"), dbv.pwszVal);
+ str.AppendChar('\n');
+ str.Append(ptrW(GetError(code)));
WPShowMessage(str, SM_WARNING);
- mir_free(tszError);
}
// log to netlib
Netlib_LogfW(hNetlibUser, L"Error! Update cannot continue... Start to free memory");
@@ -104,7 +101,7 @@ int UpdateWeather(MCONTACT hContact)
if (!dbres && dbv.pwszVal[0] != 0) {
if (opt.AlertPopup && !g_plugin.getByte(hContact, "DPopUp") && Ch) {
// display alert popup
- mir_snwprintf(str, L"Alert for %s%c%s", winfo.city, 255, dbv.pwszVal);
+ CMStringW str(FORMAT, L"Alert for %s%c%s", winfo.city, 255, dbv.pwszVal);
WPShowMessage(str, SM_WEATHERALERT);
}
// alert issued, set display to italic
diff --git a/protocols/Weather/src/weather_userinfo.cpp b/protocols/Weather/src/weather_userinfo.cpp
index c30647a4e4..2e8edd67c0 100644
--- a/protocols/Weather/src/weather_userinfo.cpp
+++ b/protocols/Weather/src/weather_userinfo.cpp
@@ -61,7 +61,7 @@ static void LoadBriefInfoText(HWND hwndDlg, MCONTACT hContact)
winfo = LoadWeatherInfo(hContact);
// check if data exist. If not, display error message box
if (!g_plugin.getByte(hContact, "IsUpdated"))
- wcsncpy(str, WEATHER_NO_INFO, _countof(str) - 1);
+ wcsncpy(str, TranslateT("No information available.\r\nPlease update weather condition first."), _countof(str) - 1);
else
// set the display text and show the message box
GetDisplay(&winfo, GetTextValue('B'), str);
@@ -92,9 +92,9 @@ static INT_PTR CALLBACK DlgProcMoreData(HWND hwndDlg, UINT msg, WPARAM wParam, L
// get the list to display
{
- LV_COLUMN lvc = { 0 };
+ LV_COLUMN lvc = {};
HWND hList = GetDlgItem(hwndDlg, IDC_DATALIST);
- RECT aRect = { 0 };
+ RECT aRect = {};
GetClientRect(hList, &aRect);
// managing styles
@@ -174,7 +174,7 @@ static INT_PTR CALLBACK DlgProcMoreData(HWND hwndDlg, UINT msg, WPARAM wParam, L
SetDlgItemText(hwndDlg, IDC_MTEXT, TranslateT("Retrieving new data, please wait..."));
ListView_DeleteAllItems(hList);
- LV_ITEM lvi = { 0 };
+ LV_ITEM lvi = {};
lvi.mask = LVIF_TEXT | LVIF_PARAM;
lvi.lParam = 1;
lvi.pszText = L"";