summaryrefslogtreecommitdiff
path: root/protocols/Weather/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2025-01-24 16:58:02 +0300
committerGeorge Hazan <george.hazan@gmail.com>2025-01-24 16:58:02 +0300
commit4c43d12f03c53aa53585efa40daf22580eae9c45 (patch)
tree52471e10ee66a56331bdedbe998c6f86dba579d5 /protocols/Weather/src
parent781beb2c50cea2ce2a3da799d8e4a70fa21d6fab (diff)
Weather: dropped all that trash with ini files structure
Diffstat (limited to 'protocols/Weather/src')
-rw-r--r--protocols/Weather/src/proto.h6
-rw-r--r--protocols/Weather/src/resource.h14
-rw-r--r--protocols/Weather/src/stdafx.h113
-rw-r--r--protocols/Weather/src/weather.cpp9
-rw-r--r--protocols/Weather/src/weather_addstn.cpp199
-rw-r--r--protocols/Weather/src/weather_contacts.cpp92
-rw-r--r--protocols/Weather/src/weather_conv.cpp91
-rw-r--r--protocols/Weather/src/weather_http.cpp117
-rw-r--r--protocols/Weather/src/weather_ini.cpp582
-rw-r--r--protocols/Weather/src/weather_opt.cpp40
-rw-r--r--protocols/Weather/src/weather_update.cpp192
11 files changed, 24 insertions, 1431 deletions
diff --git a/protocols/Weather/src/proto.h b/protocols/Weather/src/proto.h
index d94e1b1850..3a42f47e5d 100644
--- a/protocols/Weather/src/proto.h
+++ b/protocols/Weather/src/proto.h
@@ -150,9 +150,6 @@ class CWeatherProto : public PROTO<CWeatherProto>
void GetStationID(MCONTACT hContact, wchar_t *id, int idlen);
WEATHERINFO LoadWeatherInfo(MCONTACT hContact);
- // http
- int InternetDownloadFile(char *szUrl, char *cookie, char *userAgent, wchar_t **szData);
-
// menu items
void InitMenuItems();
void UpdateMenu(BOOL State);
@@ -188,10 +185,7 @@ class CWeatherProto : public PROTO<CWeatherProto>
bool CheckSearch();
int IDSearch(wchar_t *id, const int searchId);
- int IDSearchProc(wchar_t *sID, const int searchId, struct WIIDSEARCH *sData, wchar_t *svc, wchar_t *svcname);
-
int NameSearch(wchar_t *name, const int searchId);
- int NameSearchProc(wchar_t *name, const int searchId, struct WINAMESEARCH *sData, wchar_t *svc, wchar_t *svcname);
void __cdecl NameSearchThread(void *);
void __cdecl BasicSearchThread(void *);
diff --git a/protocols/Weather/src/resource.h b/protocols/Weather/src/resource.h
index f71cf3f9f5..03253f80ee 100644
--- a/protocols/Weather/src/resource.h
+++ b/protocols/Weather/src/resource.h
@@ -1,6 +1,6 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
-// Used by ..\res\resource.rc
+// Used by W:\miranda-ng\protocols\Weather\res\resource.rc
//
#define IDI_ICON 101
#define IDD_USERINFO 201
@@ -17,7 +17,6 @@
#define IDR_PMENU 213
#define IDD_TEXTOPT 216
#define IDD_BRIEF 217
-#define IDD_SETUP 218
#define IDR_TMENU 219
#define IDR_TMMENU 220
#define IDI_EDIT 222
@@ -54,8 +53,6 @@
#define IDC_HTEXT 2028
#define IDC_DPop 2029
#define IDC_DAutoUpdate 2030
-#define IDC_IURL 2032
-#define IDC_MURL 2033
#define IDC_Overwrite 2035
#define IDC_UPDCONDCHG 2036
#define IDC_REMOVEOLD 2037
@@ -75,12 +72,8 @@
#define IDC_W3 2052
#define IDC_W4 2053
#define IDC_BROWSE 2054
-#define IDC_VIEW1 2055
-#define IDC_RESET1 2056
-#define IDC_VIEW2 2057
#define IDC_V1 2058
#define IDC_V2 2059
-#define IDC_RESET2 2060
#define IDC_GETNAME 2062
#define IDC_P1 2063
#define IDC_P2 2064
@@ -121,14 +114,9 @@
#define IDC_MOREDETAIL 2095
#define IDC_DATALIST 2096
#define IDC_MUPDATE 2097
-#define IDC_MFRAME 2099
#define IDC_MTOGGLE 2101
#define IDC_MWEBPAGE 2102
#define IDC_MTEXT 2103
-#define IDC_STEP1 2107
-#define IDC_STEP2 2108
-#define IDC_STEP3 2109
-#define IDC_STEP4 2110
#define IDC_AVATARSPIN 2124
#define IDC_SEARCHCITY 2125
#define IDC_HEADERBAR 2126
diff --git a/protocols/Weather/src/stdafx.h b/protocols/Weather/src/stdafx.h
index 7e119ab19f..ac1f1bd16f 100644
--- a/protocols/Weather/src/stdafx.h
+++ b/protocols/Weather/src/stdafx.h
@@ -114,9 +114,6 @@ enum EWeatherCondition
#define SM_WEATHERALERT 16
#define WM_UPDATEDATA (WM_USER + 2687)
-// defaults constants
-#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")
-
/////////////////////////////////////////////////////////////////////////////////////////
// DATA FORMAT STRUCT
@@ -135,104 +132,10 @@ struct WIDATAITEM
int Type;
};
-struct WITEMLIST
-{
- WIDATAITEM Item;
- struct WITEMLIST *Next;
-};
-
-typedef struct WITEMLIST WIDATAITEMLIST;
-
-struct WIIDSEARCH
-{
- BOOL Available;
- char *SearchURL;
- wchar_t *NotFoundStr;
- WIDATAITEM Name;
-};
-
-struct WINAMESEARCHTYPE
-{
- BOOL Available;
- wchar_t *First;
- WIDATAITEM Name;
- WIDATAITEM ID;
-};
-
-struct WINAMESEARCH
-{
- char *SearchURL;
- wchar_t *NotFoundStr;
- wchar_t *SingleStr;
- WINAMESEARCHTYPE Single;
- WINAMESEARCHTYPE Multiple;
-};
-
-struct STRLIST
-{
- wchar_t *Item;
- struct STRLIST *Next;
-};
-
-typedef struct STRLIST WICONDITEM;
-
-struct WICONDLIST
-{
- WICONDITEM *Head;
- WICONDITEM *Tail;
-};
-
-struct WIDATA
-{
- wchar_t *FileName;
- wchar_t *ShortFileName;
- BOOL Enabled;
-
- // header
- wchar_t *DisplayName;
- wchar_t *InternalName;
- wchar_t *Description;
- wchar_t *Author;
- wchar_t *Version;
- int InternalVer;
- size_t MemUsed;
-
- // default
- char *DefaultURL;
- wchar_t *DefaultMap;
- char *UpdateURL;
- char *UpdateURL2;
- char *UpdateURL3;
- char *UpdateURL4;
- char *Cookie;
- char *UserAgent;
-
- // items
- int UpdateDataCount;
- WIDATAITEMLIST *UpdateData;
- WIDATAITEMLIST *UpdateDataTail;
- WIIDSEARCH IDSearch;
- WINAMESEARCH NameSearch;
- WICONDLIST CondList[MAX_COND];
-};
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// DATA LIST (LINKED LIST)
-
-struct DATALIST
-{
- WIDATA Data;
- struct DATALIST *next;
-};
-
-typedef struct DATALIST WIDATALIST;
-
/////////////////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
-extern WIDATALIST *WIHead, *WITail;
-
-extern HWND hPopupWindow, hWndSetup;
+extern HWND hPopupWindow;
extern MWindowList hDataWindowList, hWindowList;
@@ -247,7 +150,6 @@ extern bool g_bIsUtf;
void ClearStatusIcons();
-uint16_t GetIcon(const wchar_t* cond, WIDATA *Data);
void CaseConv(wchar_t *str);
void TrimString(char *str);
void TrimString(wchar_t *str);
@@ -256,9 +158,6 @@ char *GetSearchStr(char *dis);
wchar_t *GetDisplay(WEATHERINFO *w, const wchar_t *dis, wchar_t* str);
-void GetSvc(wchar_t *pszID);
-void GetID(wchar_t *pszID);
-
wchar_t *GetError(int code);
/////////////////////////////////////////////////////////////////////////////////////////
@@ -275,16 +174,6 @@ void wfree(wchar_t *&Data);
void DBDataManage(MCONTACT hContact, uint16_t Mode, WPARAM wParam, LPARAM lParam);
/////////////////////////////////////////////////////////////////////////////////////////
-// functions in weather_ini.c
-
-WIDATA* GetWIData(wchar_t *pszServ);
-
-bool IsContainedInCondList(const wchar_t *pszStr, WICONDLIST *List);
-
-void DestroyWIList();
-bool LoadWIData(bool dial);
-
-/////////////////////////////////////////////////////////////////////////////////////////
// functions in weather_info.c
const wchar_t *GetDefaultText(int c);
diff --git a/protocols/Weather/src/weather.cpp b/protocols/Weather/src/weather.cpp
index 7c61a6c075..884362d1a5 100644
--- a/protocols/Weather/src/weather.cpp
+++ b/protocols/Weather/src/weather.cpp
@@ -28,9 +28,6 @@ belong to any other file.
//============ GLOBAL VARIABLES ============
-WIDATALIST *WIHead;
-WIDATALIST *WITail;
-
HWND hPopupWindow;
MWindowList hDataWindowList, hWindowList;
@@ -74,7 +71,6 @@ static int OnPreShutdown(WPARAM, LPARAM)
{
WindowList_Broadcast(hWindowList, WM_CLOSE, 0, 0);
WindowList_Broadcast(hDataWindowList, WM_CLOSE, 0, 0);
- SendMessage(hWndSetup, WM_CLOSE, 0, 0);
return 0;
}
@@ -102,9 +98,6 @@ int CMPlugin::Load()
// load dll with icons
hIconsDll = LoadLibraryW(g_pwszIconsName);
- // load weather update data
- LoadWIData(true);
-
// window lists
hDataWindowList = WindowList_Create();
hWindowList = WindowList_Create();
@@ -130,8 +123,6 @@ int CMPlugin::Unload()
DestroyWindow(hPopupWindow);
- DestroyWIList(); // unload all ini data from memory
-
WindowList_Destroy(hDataWindowList);
WindowList_Destroy(hWindowList);
return 0;
diff --git a/protocols/Weather/src/weather_addstn.cpp b/protocols/Weather/src/weather_addstn.cpp
index 3de0e48984..1dcf9004a9 100644
--- a/protocols/Weather/src/weather_addstn.cpp
+++ b/protocols/Weather/src/weather_addstn.cpp
@@ -68,17 +68,7 @@ MCONTACT CWeatherProto::AddToList(int, PROTOSEARCHRESULT *psr)
// set contact info and settings
wchar_t svc[256];
wcsncpy(svc, psr->email.w, _countof(svc)); svc[_countof(svc) - 1] = 0;
- GetSvc(svc);
- // set settings by obtaining the default for the service
- if (psr->lastName.w[0] != 0) {
- WIDATA *sData = GetWIData(svc);
- setWString(hContact, "MapURL", sData->DefaultMap);
- setString(hContact, "InfoURL", sData->DefaultURL);
- }
- else { // if no valid service is found, create empty strings for MapURL and InfoURL
- setString(hContact, "MapURL", "");
- setString(hContact, "InfoURL", "");
- }
+
// write the other info and settings to the database
setWString(hContact, "ID", psr->email.w);
setWString(hContact, "Nick", psr->nick.w);
@@ -214,198 +204,21 @@ HANDLE CWeatherProto::SearchAdvanced(MWindow hwndOwner)
return (HANDLE)sttSearchId;
}
-/////////////////////////////////////////////////////////////////////////////////////////
-// Seaching station ID from a single weather service
-// sID = search string for the station ID
-// searchId = -1
-// sData = the ID search data for that particular weather service
-// svcname = the name of the weather service that is currently searching (ie. Yahoo Weather)
-
-int CWeatherProto::IDSearchProc(wchar_t *sID, const int searchId, WIIDSEARCH *sData, wchar_t *svc, wchar_t *svcname)
+int CWeatherProto::IDSearch(wchar_t *sID, const int searchId)
{
- wchar_t str[MAX_DATA_LEN], newID[MAX_DATA_LEN];
-
- if (sData->Available) {
- char loc[255];
- wchar_t *szData = nullptr;
-
- // load the page
- mir_snprintf(loc, sData->SearchURL, _T2A(sID).get());
- BOOL bFound = (InternetDownloadFile(loc, nullptr, nullptr, &szData) == 0);
- if (bFound) {
- wchar_t *szInfo = szData;
-
- // not found
- if (wcsstr(szInfo, sData->NotFoundStr) == nullptr)
- GetDataValue(&sData->Name, str, &szInfo);
- }
-
- mir_free(szData);
- // Station not found exit
- if (!bFound)
- return 1;
- }
-
- // give no station name but only ID if the search is unavailable
- else wcsncpy(str, TranslateT("<Enter station name here>"), MAX_DATA_LEN - 1);
- mir_snwprintf(newID, L"%s/%s", svc, sID);
-
- // set the search result and broadcast it
+ // return an empty contact on "#"
PROTOSEARCHRESULT psr = { sizeof(psr) };
psr.flags = PSR_UNICODE;
- psr.nick.w = str;
+ psr.nick.w = TranslateT("<Enter station name here>"); // to be entered
psr.firstName.w = L" ";
- psr.lastName.w = svcname;
- psr.email.w = newID;
+ psr.lastName.w = L"";
+ psr.email.w = TranslateT("<Enter station ID here>"); // to be entered
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)searchId, (LPARAM)&psr);
return 0;
}
-int CWeatherProto::IDSearch(wchar_t *sID, const int searchId)
-{
- // for a normal ID search (ID != #)
- if (mir_wstrcmp(sID, L"#")) {
- WIDATALIST *Item = WIHead;
-
- // search every weather service using the search station ID
- while (Item != nullptr) {
- IDSearchProc(sID, searchId, &Item->Data.IDSearch, Item->Data.InternalName, Item->Data.DisplayName);
- Item = Item->next;
- }
- }
- // if the station ID is #, return a dummy result and quit the funciton
- else {
- // return an empty contact on "#"
- PROTOSEARCHRESULT psr = { sizeof(psr) };
- psr.flags = PSR_UNICODE;
- psr.nick.w = TranslateT("<Enter station name here>"); // to be entered
- psr.firstName.w = L" ";
- psr.lastName.w = L"";
- psr.email.w = TranslateT("<Enter station ID here>"); // to be entered
- ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)searchId, (LPARAM)&psr);
- }
-
- return 0;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// Seaching station name from a single weather service (Threaded)
-// name = the name of the weather station to be searched
-// searchId = -1
-// sData = the name search data for that particular weather service
-// svcname = the name of the weather service that is currently searching (ie. Yahoo Weather)
-
-int CWeatherProto::NameSearchProc(wchar_t *name, const int searchId, WINAMESEARCH *sData, wchar_t *svc, wchar_t *svcname)
-{
- wchar_t Name[MAX_DATA_LEN], str[MAX_DATA_LEN], sID[MAX_DATA_LEN], *szData = nullptr, *search;
-
- // replace spaces with %20
- char loc[256];
- T2Utf szSearchName(name);
- mir_snprintf(loc, sData->SearchURL, mir_urlEncode(szSearchName).c_str());
- if (InternetDownloadFile(loc, nullptr, nullptr, &szData) == 0) {
- wchar_t *szInfo = szData;
- search = wcsstr(szInfo, sData->NotFoundStr); // determine if data is available
- if (search == nullptr) { // if data is found
- // test if it is single result
- if (sData->Single.Available && sData->Multiple.Available)
- search = wcsstr(szInfo, sData->SingleStr);
- // for single result
- if (sData->Single.Available && (search != nullptr || !sData->Multiple.Available)) { // single result
- // if station ID appears first in the downloaded data
- if (!mir_wstrcmpi(sData->Single.First, L"ID")) {
- GetDataValue(&sData->Single.ID, str, &szInfo);
- mir_snwprintf(sID, L"%s/%s", svc, str);
- GetDataValue(&sData->Single.Name, Name, &szInfo);
- }
- // if station name appears first in the downloaded data
- else if (!mir_wstrcmpi(sData->Single.First, L"NAME")) {
- GetDataValue(&sData->Single.Name, Name, &szInfo);
- GetDataValue(&sData->Single.ID, str, &szInfo);
- mir_snwprintf(sID, L"%s/%s", svc, str);
- }
- else
- str[0] = 0;
-
- // if no station ID is obtained, quit the search
- if (str[0] == 0) {
- mir_free(szData);
- return 1;
- }
-
- // if can't get the name, use the search string as name
- if (Name[0] == 0)
- wcsncpy(Name, name, _countof(Name));
-
- // set the data and broadcast it
- PROTOSEARCHRESULT psr = { sizeof(psr) };
- psr.flags = PSR_UNICODE;
- psr.nick.w = Name;
- psr.firstName.w = L" ";
- psr.lastName.w = svcname;
- psr.email.w = sID;
- psr.id.w = sID;
- ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)searchId, (LPARAM)&psr);
- mir_free(szData);
- return 0;
- }
- // for multiple result
- else if (sData->Multiple.Available) { // multiple results
- // search for the next occurrence of the string
- while (true) {
- // if station ID appears first in the downloaded data
- if (!mir_wstrcmpi(sData->Multiple.First, L"ID")) {
- GetDataValue(&sData->Multiple.ID, str, &szInfo);
- mir_snwprintf(sID, L"%s/%s", svc, str);
- GetDataValue(&sData->Multiple.Name, Name, &szInfo);
- }
- // if station name appears first in the downloaded data
- else if (!mir_wstrcmpi(sData->Multiple.First, L"NAME")) {
- GetDataValue(&sData->Multiple.Name, Name, &szInfo);
- GetDataValue(&sData->Multiple.ID, str, &szInfo);
- mir_snwprintf(sID, L"%s/%s", svc, str);
- }
- else
- break;
-
- // if no station ID is obtained, search completed and quit the search
- if (str[0] == 0)
- break;
-
- // if can't get the name, use the search string as name
- if (Name[0] == 0)
- wcsncpy(Name, name, _countof(Name));
-
- PROTOSEARCHRESULT psr = { sizeof(psr) };
- psr.flags = PSR_UNICODE;
- psr.nick.w = Name;
- psr.firstName.w = L"";
- psr.lastName.w = svcname;
- psr.email.w = sID;
- psr.id.w = sID;
- ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)searchId, (LPARAM)&psr);
- }
- }
- }
-
- mir_free(szData);
- return 0;
- }
-
- mir_free(szData);
- return 1;
-}
-
int CWeatherProto::NameSearch(wchar_t *name, const int searchId)
{
- // search every weather service using the search station name
- WIDATALIST *Item = WIHead;
- while (Item != nullptr) {
- if (Item->Data.NameSearch.Single.Available || Item->Data.NameSearch.Multiple.Available)
- NameSearchProc(name, searchId, &Item->Data.NameSearch, Item->Data.InternalName, Item->Data.DisplayName);
- Item = Item->next;
- }
-
return 0;
}
diff --git a/protocols/Weather/src/weather_contacts.cpp b/protocols/Weather/src/weather_contacts.cpp
index 0c9cd20d74..759380eb15 100644
--- a/protocols/Weather/src/weather_contacts.cpp
+++ b/protocols/Weather/src/weather_contacts.cpp
@@ -28,7 +28,6 @@ the contact.
static void OpenUrl(wchar_t *format, wchar_t *id)
{
wchar_t loc[512];
- GetID(id);
mir_snwprintf(loc, format, id);
Utils_OpenUrlW(loc);
}
@@ -109,7 +108,7 @@ class CEditDlg : public CWeatherDlgBase
CCtrlEdit edtID, edtName;
CCtrlButton btnExternal, btnChange;
- CCtrlMButton btnGetName, btnBrowse, btnView1, btnView2, btnReset1, btnReset2;
+ CCtrlMButton btnGetName, btnBrowse;
wchar_t str[MAX_DATA_LEN], str2[256];
@@ -119,10 +118,6 @@ public:
hContact(_1),
edtID(this, IDC_ID),
edtName(this, IDC_NAME),
- btnView1(this, IDC_VIEW1, SKINICON_OTHER_SEARCHALL, LPGEN("View webpage")),
- btnView2(this, IDC_VIEW2, SKINICON_OTHER_SEARCHALL, LPGEN("View webpage")),
- btnReset1(this, IDC_RESET1, SKINICON_OTHER_RENAME, LPGEN("Reset to default")),
- btnReset2(this, IDC_RESET2, SKINICON_OTHER_RENAME, LPGEN("Reset to default")),
btnBrowse(this, IDC_BROWSE, SKINICON_EVENT_FILE, LPGEN("Browse")),
btnGetName(this, IDC_GETNAME, SKINICON_OTHER_RENAME, LPGEN("Get city name from ID")),
btnChange(this, IDC_CHANGE),
@@ -131,10 +126,6 @@ public:
edtID.OnChange = Callback(this, &CEditDlg::onChanged_ID);
edtName.OnChange = Callback(this, &CEditDlg::onChanged_Name);
- btnView1.OnClick = Callback(this, &CEditDlg::onClick_View1);
- btnView2.OnClick = Callback(this, &CEditDlg::onClick_View2);
- btnReset1.OnClick = Callback(this, &CEditDlg::onClick_Reset1);
- btnReset2.OnClick = Callback(this, &CEditDlg::onClick_Reset2);
btnBrowse.OnClick = Callback(this, &CEditDlg::onClick_Browse);
btnChange.OnClick = Callback(this, &CEditDlg::onClick_Change);
btnGetName.OnClick = Callback(this, &CEditDlg::onClick_GetName);
@@ -144,10 +135,6 @@ public:
bool OnInitDialog() override
{
// make all buttons flat
- btnView1.MakeFlat();
- btnView2.MakeFlat();
- btnReset1.MakeFlat();
- btnReset2.MakeFlat();
btnBrowse.MakeFlat();
btnGetName.MakeFlat();
@@ -181,15 +168,6 @@ public:
CheckDlgButton(m_hwnd, IDC_DAutoUpdate, m_proto->getByte(hContact, "DAutoUpdate", FALSE) ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(m_hwnd, IDC_Internal, m_proto->getByte(hContact, "History", 0) ? BST_CHECKED : BST_UNCHECKED);
- if (!m_proto->getWString(hContact, "InfoURL", &dbv)) {
- SetDlgItemText(m_hwnd, IDC_IURL, dbv.pwszVal);
- db_free(&dbv);
- }
- if (!m_proto->getWString(hContact, "MapURL", &dbv)) {
- SetDlgItemText(m_hwnd, IDC_MURL, dbv.pwszVal);
- db_free(&dbv);
- }
-
// display the dialog box and free memory
Utils_RestoreWindowPositionNoMove(m_hwnd, NULL, MODULENAME, "EditSetting_");
ShowWindow(m_hwnd, SW_SHOW);
@@ -229,30 +207,7 @@ public:
// get the weather update data using the string in the ID field
GetDlgItemText(m_hwnd, IDC_ID, str, _countof(str));
- GetSvc(str);
- WIDATA *sData = GetWIData(str);
- GetDlgItemText(m_hwnd, IDC_ID, str, _countof(str));
- GetID(str);
-
- // if ID search is available, do it
- if (sData->IDSearch.Available) {
- // load the page
- char loc[512];
- mir_snprintf(loc, sData->IDSearch.SearchURL, str);
- str[0] = 0;
- wchar_t *pData = nullptr;
- if (m_proto->InternetDownloadFile(loc, nullptr, sData->UserAgent, &pData) == 0) {
- wchar_t *szInfo = pData;
- wchar_t *search = wcsstr(szInfo, sData->IDSearch.NotFoundStr);
-
- // if the page is found (ie. valid ID), get the name of the city
- if (search == nullptr)
- m_proto->GetDataValue(&sData->IDSearch.Name, str, &szInfo);
- }
- // free memory
- mir_free(pData);
- }
-
+
// give no station name but only ID if the search is unavailable
if (str[0] != 0)
SetDlgItemText(m_hwnd, IDC_NAME, str);
@@ -298,44 +253,6 @@ public:
EnableWindow(GetDlgItem(m_hwnd, IDC_CHANGE), ofn.lpstrFile[0] != 0);
}
- void onClick_View1(CCtrlButton *)
- {
- // view the page for more info
- GetDlgItemText(m_hwnd, IDC_IURL, str, _countof(str));
- if (str[0]) {
- GetDlgItemText(m_hwnd, IDC_ID, str2, _countof(str2));
- OpenUrl(str, str2);
- }
- }
-
- void onClick_View2(CCtrlButton *)
- {
- // view the page for weather map
- GetDlgItemText(m_hwnd, IDC_MURL, str, _countof(str));
- if (str[0]) {
- GetDlgItemText(m_hwnd, IDC_ID, str2, _countof(str2));
- OpenUrl(str, str2);
- }
- }
-
- void onClick_Reset1(CCtrlButton *)
- {
- // reset the more info url to service default
- GetDlgItemText(m_hwnd, IDC_ID, str, _countof(str));
- GetSvc(str);
- WIDATA *sData = GetWIData(str);
- SetDlgItemTextA(m_hwnd, IDC_IURL, sData->DefaultURL);
- }
-
- void onClick_Reset2(CCtrlButton *)
- {
- // reset the weathe map url to service default
- GetDlgItemText(m_hwnd, IDC_ID, str, _countof(str));
- GetSvc(str);
- WIDATA *sData = GetWIData(str);
- SetDlgItemText(m_hwnd, IDC_MURL, sData->DefaultMap);
- }
-
void onClick_Change(CCtrlButton *)
{
// temporary disable the protocol while applying the change
@@ -358,11 +275,6 @@ public:
}
else m_proto->delSetting(hContact, "Log");
- GetDlgItemText(m_hwnd, IDC_IURL, str, _countof(str));
- m_proto->setWString(hContact, "InfoURL", str);
-
- GetDlgItemText(m_hwnd, IDC_MURL, str, _countof(str));
- m_proto->setWString(hContact, "MapURL", str);
m_proto->setWord(hContact, "Status", ID_STATUS_OFFLINE);
m_proto->setWord(hContact, "StatusIcon", -1);
m_proto->AvatarDownloaded(hContact);
diff --git a/protocols/Weather/src/weather_conv.cpp b/protocols/Weather/src/weather_conv.cpp
index 9cb2677099..7bcd8e4030 100644
--- a/protocols/Weather/src/weather_conv.cpp
+++ b/protocols/Weather/src/weather_conv.cpp
@@ -318,69 +318,6 @@ void CWeatherProto::GetElev(wchar_t *tempchar, wchar_t *unit, wchar_t *str)
}
/////////////////////////////////////////////////////////////////////////////////////////
-// assign the contact icon (status) from the condition string
-// the description may be different between different sources
-// cond = the string for weather condition
-// return value = status for the icon (ONLINE, OFFLINE, etc)
-
-static const wchar_t *statusStr[MAX_COND] = { L"Lightning", L"Fog", L"Snow", L"Rain", L"Partly Cloudy", L"Cloudy", L"Sunny", L"N/A", L"Rain Shower", L"Snow Shower"};
-static const uint16_t statusValue[MAX_COND] = { LIGHT, FOG, SNOW, RAIN, PCLOUDY, CLOUDY, SUNNY, NA, RSHOWER, SSHOWER };
-
-uint16_t GetIcon(const wchar_t *cond, WIDATA *Data)
-{
- // set the icon using ini
- for (int i = 0; i < _countof(statusValue); i++)
- if (IsContainedInCondList(cond, &Data->CondList[i]))
- return statusValue[i];
-
- // internal detection
- if (wcsstr(cond, L"mainy sunny") || wcsstr(cond, L"mainy clear") || wcsstr(cond, L"partly sunny") || wcsstr(cond, L"partly cloudy") || wcsstr(cond, L"mostly") || wcsstr(cond, L"clouds"))
- return PCLOUDY;
-
- if (wcsstr(cond, L"sunny") || wcsstr(cond, L"clear") || wcsstr(cond, L"fair"))
- return SUNNY;
-
- if (wcsstr(cond, L"thunder") || wcsstr(cond, L"t-storm"))
- return LIGHT;
-
- if (wcsstr(cond, L"cloud") || wcsstr(cond, L"overcast"))
- return CLOUDY;
-
- if (wcsstr(cond, L"fog") || wcsstr(cond, L"mist") || wcsstr(cond, L"smoke") || wcsstr(cond, L"sand") || wcsstr(cond, L"dust") || wcsstr(cond, L"haze"))
- return FOG;
-
- if (wcsstr(cond, L"snow shower"))
- return SSHOWER;
-
- if (wcsstr(cond, L"snow") || wcsstr(cond, L"ice") || wcsstr(cond, L"freezing") || wcsstr(cond, L"wintry"))
- return SNOW;
-
- if (wcsstr(cond, L"rain shower"))
- return RSHOWER;
-
- if (wcsstr(cond, L"drizzle") || wcsstr(cond, L"rain"))
- return RAIN;
-
- // set the icon using langpack
- for (int i = 0; i < _countof(statusStr)-1; i++) {
- wchar_t LangPackStr[64], LangPackStr1[128];
- int j = 0;
- do {
- j++;
- // using the format _T("# Weather <condition name> <counter> #"
- mir_snwprintf(LangPackStr, L"# Weather %s %i #", statusStr[i], j);
- wcsncpy_s(LangPackStr1, TranslateW(LangPackStr), _TRUNCATE);
- CharLowerBuff(LangPackStr1, (uint32_t)mir_wstrlen(LangPackStr1));
- if (wcsstr(cond, LangPackStr1) != nullptr)
- return statusValue[i];
- // loop until the translation string exists (ie, the translated string is differ from original)
- } while (mir_wstrcmp(TranslateW(LangPackStr), LangPackStr));
- }
-
- return NA;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
// this function convert the string to the format with 1 upper case followed by lower case char
void CaseConv(wchar_t *str)
@@ -548,34 +485,6 @@ wchar_t* GetDisplay(WEATHERINFO *w, const wchar_t *dis, wchar_t *str)
}
/////////////////////////////////////////////////////////////////////////////////////////
-// get service data module internal name
-// mod/id <- the mod part
-// pszID = original 2-part id, return the service internal name
-
-void GetSvc(wchar_t *pszID)
-{
- wchar_t *chop = wcschr(pszID, '/');
- if (chop != nullptr)
- *chop = '\0';
- else
- pszID[0] = 0;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// get the id use for update without the service internal name
-// mod/id <- the id part
-// pszID = original 2-part id, return the single part id
-
-void GetID(wchar_t *pszID)
-{
- wchar_t *chop = wcschr(pszID, '/');
- if (chop != nullptr)
- mir_wstrcpy(pszID, chop + 1);
- else
- pszID[0] = 0;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
// Get the text when an error code is specified
// code = the error code obtained when updating weather
// str = the string for the error
diff --git a/protocols/Weather/src/weather_http.cpp b/protocols/Weather/src/weather_http.cpp
deleted file mode 100644
index 91ae9b911c..0000000000
--- a/protocols/Weather/src/weather_http.cpp
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
-Weather Protocol plugin for Miranda IM
-Copyright (c) 2012 Miranda NG team
-Copyright (c) 2005-2011 Boris Krasnovskiy All Rights Reserved
-Copyright (c) 2002-2005 Calvin Che
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; version 2
-of the License.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/*
-This file contain the source related to downloading weather info
-from the web using netlib
-*/
-
-#include "stdafx.h"
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// function to download webpage from the internet
-// szUrl = URL of the webpage to be retrieved
-// return value = 0 for success, 1 or HTTP error code for failure
-// global var used: szData, szInfo = containing the retrieved data
-
-int CWeatherProto::InternetDownloadFile(char *szUrl, char *cookie, char *userAgent, wchar_t **szData)
-{
- if (userAgent == nullptr || userAgent[0] == 0)
- userAgent = NETLIB_USER_AGENT;
-
- // initialize the netlib request
- MHttpRequest nlhr(REQUEST_GET);
- nlhr.flags = NLHRF_DUMPASTEXT | NLHRF_HTTP11 | NLHRF_REDIRECT;
- nlhr.m_szUrl = szUrl;
- nlhr.AddHeader("User-Agent", userAgent);
- nlhr.AddHeader("Cache-Control", "no-cache");
- nlhr.AddHeader("Pragma", "no-cache");
- nlhr.AddHeader("Connection", "close");
- if (mir_strlen(cookie) > 0)
- nlhr.AddHeader("Cookie", cookie);
-
- // download the page
- NLHR_PTR nlhrReply(Netlib_HttpTransaction(m_hNetlibUser, &nlhr));
- if (nlhrReply == nullptr) {
- // if the data does not downloaded successfully (ie. disconnected), then return 1000 as error code
- *szData = (wchar_t*)mir_alloc(512);
- // store the error code in szData
- mir_wstrcpy(*szData, L"NetLib error occurred!!");
- return NLHRF_REDIRECT;
- }
-
- // if the recieved code is 200 OK
- int result;
- if (nlhrReply->resultCode == 200) {
- if (!nlhrReply->body.IsEmpty()) {
- bool bIsUtf = false;
- result = 0;
-
- // allocate memory and save the retrieved data
- auto *pszHdr = nlhrReply->FindHeader("Content-Type");
- // look for Content-Type=utf-8 in header
- if (pszHdr && strstr(_strlwr(pszHdr), "utf-8"))
- bIsUtf = true;
- else {
- char *end = nlhrReply->body.GetBuffer();
- while (end) {
- // look for
- // <meta http-equiv="Content-Type" content="utf-8" />
- char *beg = strstr(end, "<meta");
- if (beg) {
- end = strchr(beg, '>');
- if (end) {
- char tmp = *end;
- *end = 0;
-
- char *method = strstr(beg, "http-equiv=\"");
- if (method && _strnicmp(method + 12, "Content-Type", 12) == 0 && strstr(method, "utf-8")) {
- bIsUtf = true;
- *end = tmp;
- break;
- }
- else *end = tmp;
- }
- }
- else
- break;
- }
- }
-
- wchar_t *retVal = nullptr;
- if (bIsUtf)
- retVal = mir_utf8decodeW(nlhrReply->body);
- if (retVal == nullptr)
- retVal = mir_a2u(nlhrReply->body);
- *szData = retVal;
- }
- else result = DATA_EMPTY;
- }
- // return error code if the recieved code is neither 200 OK nor 302 Moved
- else {
- // store the error code in szData
- CMStringW wszError(FORMAT, L"Error occured! HTTP Error: %i\n", nlhrReply->resultCode);
- *szData = wszError.Detach();
- result = nlhrReply->resultCode;
- }
-
- // make a copy of the retrieved data, then free the memory of the http reply
- return result;
-}
diff --git a/protocols/Weather/src/weather_ini.cpp b/protocols/Weather/src/weather_ini.cpp
deleted file mode 100644
index 0296e0a7d8..0000000000
--- a/protocols/Weather/src/weather_ini.cpp
+++ /dev/null
@@ -1,582 +0,0 @@
-/*
-Weather Protocol plugin for Miranda IM
-Copyright (c) 2012 Miranda NG team
-Copyright (c) 2005-2011 Boris Krasnovskiy All Rights Reserved
-Copyright (c) 2002-2005 Calvin Che
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; version 2
-of the License.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-
-/*
-This file contain the source related to loading the reading the
-weather ini files and store them into memory. Also containing
-code for unloading and getting weather data from the ini settings.
-*/
-
-#include "stdafx.h"
-
-HWND hWndSetup;
-
-//============ DATA LIST (LINKED LIST) ============
-//
-// add an item into weather service data list
-// Data = the service data to be added to the list
-static void WIListAdd(WIDATA Data)
-{
- // create a new datalist item and point to the data
- WIDATALIST *newItem = (WIDATALIST*)mir_alloc(sizeof(WIDATALIST));
- newItem->Data = Data;
- // add to the linked list
- newItem->next = nullptr;
- if (WITail == nullptr) WIHead = newItem;
- else WITail->next = newItem;
- WITail = newItem;
-}
-
-// get the service data (from loaded ini file) by internal name
-// pszServ = internal name for the service
-// return value = the matching WIDATA struct for pszServ, NULL if no match found
-WIDATA* GetWIData(wchar_t *pszServ)
-{
- // loop through the list to find matching internal name
- for (WIDATALIST *Item = WIHead; Item != nullptr; Item = Item->next)
- // if internal name found, return the data
- if (mir_wstrcmp(Item->Data.InternalName, pszServ) == 0)
- return &Item->Data;
-
- // return NULL when no match found
- return nullptr;
-}
-
-//============ DATA ITEM LIST (LINKED LIST) ============
-//
-// add a new update item into the current list
-void WIItemListAdd(WIDATAITEM *DataItem, WIDATA *Data)
-{
- WIDATAITEMLIST *newItem = (WIDATAITEMLIST*)mir_alloc(sizeof(WIDATAITEMLIST));
- newItem->Item = *DataItem;
- newItem->Next = nullptr;
- if (Data->UpdateData == nullptr) Data->UpdateData = newItem;
- else Data->UpdateDataTail->Next = newItem;
- Data->UpdateDataTail = newItem;
-}
-
-// reset the data item by using empty string
-// Item = the item to set
-// name = the string to store in the "name" field
-void ResetDataItem(WIDATAITEM *Item, const wchar_t *name)
-{
- Item->Name = mir_wstrdup(name);
- Item->Start = L"";
- Item->End = L"";
- Item->Unit = L"";
- Item->Url = "";
- Item->Break = L"";
- Item->Type = 0;
-}
-
-// free the data item by using empty string
-// Item = the item to free
-void FreeDataItem(WIDATAITEM *Item)
-{
- wfree(Item->Name);
- wfree(Item->Start);
- wfree(Item->End);
- wfree(Item->Unit);
- wfree(Item->Url);
- wfree(Item->Break);
-}
-
-//============ Condition Icon List ============
-//
-// initiate icon assignmet list
-void WICondListInit(WICONDLIST *List)
-{
- List->Tail = nullptr;
- List->Head = nullptr;
-}
-
-// add a new update item into the current list
-void WICondListAdd(char *str, WICONDLIST *List)
-{
- WICONDITEM *newItem = (WICONDITEM*)mir_alloc(sizeof(WICONDITEM));
- wSetData(newItem->Item, str);
- CharLowerW(newItem->Item);
- newItem->Next = nullptr;
- if (List->Tail == nullptr) List->Head = newItem;
- else List->Tail->Next = newItem;
- List->Tail = newItem;
-}
-
-// check if the condition string matched for the assignment
-bool IsContainedInCondList(const wchar_t *pszStr, WICONDLIST *List)
-{
- // loop through the list to find matching internal name
- for (WICONDITEM *Item = List->Head; Item != nullptr; Item = Item->Next) {
- // if internal name found, return true indicating that the data is found
- if (wcsstr(pszStr, Item->Item))
- return true;
-
- }
- // return false when no match found
- return false;
-}
-
-// free the memory for icon assignment list
-void DestroyCondList(WICONDLIST *List)
-{
- // free the list one by one
- for (WICONDITEM *temp = List->Head; temp != nullptr; temp = List->Head) {
- List->Head = temp->Next;
- wfree(temp->Item); // free the data struct
- mir_free(temp);
- }
- // make sure the entire list is clear
- List->Tail = nullptr;
-}
-
-
-//============ WEATHER INI SETUP DIALOG ============
-//
-static INT_PTR CALLBACK DlgProcSetup(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- switch (msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
-
- // make the buttons flat
- SendDlgItemMessage(hwndDlg, IDC_STEP1, BUTTONSETASFLATBTN, TRUE, 0);
- SendDlgItemMessage(hwndDlg, IDC_STEP2, BUTTONSETASFLATBTN, TRUE, 0);
- SendDlgItemMessage(hwndDlg, IDC_STEP3, BUTTONSETASFLATBTN, TRUE, 0);
- SendDlgItemMessage(hwndDlg, IDC_STEP4, BUTTONSETASFLATBTN, TRUE, 0);
-
- // set icons
- Window_SetIcon_IcoLib(hwndDlg, g_plugin.getIconHandle(IDI_ICON));
-
- WindowList_Add(hWindowList, hwndDlg);
- ShowWindow(hwndDlg, SW_SHOW);
- break;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_STEP1:
- // update current data
- Utils_OpenUrl("https://miranda-ng.org/");
- break;
-
- case IDC_STEP2:
- {
- 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;
- }
-
- case IDC_STEP3:
- if (LoadWIData(false))
- MessageBox(nullptr,
- TranslateT("All update data has been reloaded."),
- TranslateT("Weather Protocol"), MB_OK | MB_ICONINFORMATION);
- break;
-
- case IDC_STEP4:
- db_set_s(0, "FindAdd", "LastSearched", "Weather");
- CallService(MS_FINDADD_FINDADD, 0, 0);
- __fallthrough;
-
- case IDCANCEL:
- // close the info window
- DestroyWindow(hwndDlg);
- break;
- }
- break;
-
- case WM_CLOSE:
- DestroyWindow(hwndDlg);
- break;
-
- case WM_DESTROY:
- Window_FreeIcon_IcoLib(hwndDlg);
- break;
- }
- return FALSE;
-}
-
-// load the station data from a file
-// 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 const char *statusStr[MAX_COND] =
-{
- "LIGHTNING",
- "FOG",
- "SNOW",
- "RAIN",
- "PARTLY CLOUDY",
- "CLOUDY",
- "SUNNY",
- "N/A",
- "RAIN SHOWER",
- "SNOW SHOWER",
-};
-
-static void LoadStationData(const wchar_t *pszFile, wchar_t *pszShortFile, WIDATA *Data)
-{
- WIDATAITEM DataItem;
-
- // clean up old stuff
- memset(Data, 0, sizeof(*Data));
- Data->Enabled = FALSE;
-
- // open the ini file
- FILE *pfile = _wfsopen(pszFile, L"rt", _SH_DENYWR);
- 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 (auto &it : Data->CondList)
- WICondListInit(&it);
-
- g_bIsUtf = false;
-
- 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
- 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, "");
- }
- }
-
- // 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(ValName, "UTF8")) g_bIsUtf = (0 == _stricmp(Value, "true"));
- }
- 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")) Data->IDSearch.Available = (0 == _stricmp(Value, "true"));
- 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")) Data->NameSearch.Single.Available = (0 == _stricmp(Value, "true"));
- else if (!_stricmp(ValName, "MULTIPLE RESULT")) Data->NameSearch.Multiple.Available = (0 == _stricmp(Value, "true"));
- 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 < _countof(statusStr); i++) {
- if (!_stricmp(ValName, statusStr[i])) {
- WICondListAdd(Value, &Data->CondList[i]);
- break;
- }
- }
- }
- 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);
- }
- }
- // 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 ============
-//
-// load the weather update data form INI files
-bool LoadWIData(bool dial)
-{
- // make sure that the current service data list is empty
- WITail = nullptr;
- WIHead = WITail;
-
- // find all *.ini file in the plugin\weather directory
- CMStringW wszFileName('\x00', MAX_PATH);
- GetModuleFileName(GetModuleHandle(nullptr), wszFileName.GetBuffer(), MAX_PATH);
- int idx = wszFileName.ReverseFind('\\');
- if (idx == -1)
- return false;
- wszFileName.Truncate(idx);
- wszFileName += L"\\Plugins\\Weather\\";
-
- WIN32_FIND_DATA fd;
- HANDLE hFind = FindFirstFile(wszFileName + L"*.ini", &fd);
-
- // load the content of the ini file into memory
- if (hFind != INVALID_HANDLE_VALUE) {
- do {
- if (mir_wstrcmpi(fd.cFileName, L"SAMPLE_INI.INI")) {
- WIDATA Data;
- LoadStationData(wszFileName + fd.cFileName, fd.cFileName, &Data);
- if (Data.Enabled)
- WIListAdd(Data);
- }
- // look through the entire "plugins\weather" directory
- } while (FindNextFile(hFind, &fd));
- FindClose(hFind);
- }
-
- if (WIHead == nullptr) {
- // no ini found, display an error message box.
- if (dial)
- hWndSetup = CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_SETUP), nullptr, DlgProcSetup);
- else
- MessageBox(nullptr,
- TranslateT("No update data file is found. Please check your Plugins\\Weather directory."),
- TranslateT("Weather Protocol"), MB_OK | MB_ICONERROR);
- return false;
- }
- return true;
-}
-
-//============ FREE WIDATA ITEM FROM MEMORY ============
-//
-// free the WIDATA struct from memory
-// Data = the struct to be freed
-static void FreeWIData(WIDATA *Data)
-{
- // free update items linked list first
- WIDATAITEMLIST *WItem = Data->UpdateData;
- while (WItem != nullptr) {
- Data->UpdateData = WItem->Next;
- FreeDataItem(&WItem->Item);
- mir_free(WItem);
- WItem = Data->UpdateData;
- }
-
- // free the strings in the rest of the struct
- wfree(Data->DisplayName);
- wfree(Data->InternalName);
- wfree(Data->Description);
- wfree(Data->Author);
- wfree(Data->Version);
- wfree(Data->DefaultURL);
- wfree(Data->DefaultMap);
- wfree(Data->UpdateURL);
- wfree(Data->UpdateURL2);
- wfree(Data->UpdateURL3);
- wfree(Data->UpdateURL4);
- wfree(Data->Cookie);
- wfree(Data->UserAgent);
- wfree(Data->IDSearch.SearchURL);
- wfree(Data->IDSearch.NotFoundStr);
- FreeDataItem(&Data->IDSearch.Name);
- wfree(Data->NameSearch.SearchURL);
- wfree(Data->NameSearch.NotFoundStr);
- wfree(Data->NameSearch.SingleStr);
- wfree(Data->NameSearch.Single.First);
- FreeDataItem(&Data->NameSearch.Single.Name);
- FreeDataItem(&Data->NameSearch.Single.ID);
- wfree(Data->NameSearch.Multiple.First);
- FreeDataItem(&Data->NameSearch.Multiple.Name);
- FreeDataItem(&Data->NameSearch.Multiple.ID);
- wfree(Data->ShortFileName);
- wfree(Data->FileName);
- for (auto &it : Data->CondList)
- DestroyCondList(&it);
-}
-
-// remove all service data from memory
-void DestroyWIList(void)
-{
- // free the list one by one
- while (WIHead != nullptr) {
- WIDATALIST *wi = WIHead;
- WIHead = wi->next;
- FreeWIData(&wi->Data); // free the data struct
- mir_free(wi);
- }
-
- // make sure the entire list is clear
- WITail = nullptr;
-}
diff --git a/protocols/Weather/src/weather_opt.cpp b/protocols/Weather/src/weather_opt.cpp
index ddda55a453..4fa83b1ecc 100644
--- a/protocols/Weather/src/weather_opt.cpp
+++ b/protocols/Weather/src/weather_opt.cpp
@@ -299,6 +299,8 @@ public:
/////////////////////////////////////////////////////////////////////////////////////////
// text option 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")
+
struct
{
wchar_t c;
@@ -319,12 +321,11 @@ static controls[] =
class COptionsTextDlg : public CWeatherDlgBase
{
- CCtrlMButton btnMore, btnReset, tm1, tm2, tm3, tm4, tm5, tm6, tm7, tm8;
+ CCtrlMButton btnReset, tm1, tm2, tm3, tm4, tm5, tm6, tm7, tm8;
public:
COptionsTextDlg(CWeatherProto *ppro) :
CWeatherDlgBase(ppro, IDD_TEXTOPT),
- btnMore(this, IDC_MORE),
btnReset(this, IDC_RESET),
tm1(this, IDC_TM1),
tm2(this, IDC_TM2),
@@ -335,7 +336,6 @@ public:
tm7(this, IDC_TM7),
tm8(this, IDC_TM8)
{
- btnMore.OnClick = Callback(this, &COptionsTextDlg::onClick_More);
btnReset.OnClick = Callback(this, &COptionsTextDlg::onClick_Reset);
tm1.OnClick = tm2.OnClick = tm3.OnClick = tm4.OnClick = tm5.OnClick = tm6.OnClick = tm7.OnClick = tm8.OnClick =
@@ -364,7 +364,6 @@ public:
tm6.MakeFlat();
tm7.MakeFlat();
tm8.MakeFlat();
- btnMore.MakeFlat();
btnReset.MakeFlat();
return true;
}
@@ -386,39 +385,6 @@ public:
return true;
}
- void onClick_More(CCtrlButton *)
- {
- // heading
- 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);
- auto *find = wcsstr(str, tempstr);
- // if the custom variable does not exist in the list, add it to the list
- if (find == nullptr) {
- if (bFirst)
- bFirst = false;
- else
- str += L", ";
- str += tempstr;
- }
- }
- }
- }
-
- // display the list in a message box
- MessageBox(nullptr, str, TranslateT("More Variables"), MB_OK | MB_ICONINFORMATION | MB_TOPMOST);
- }
-
void onClick_TM(CCtrlButton *pButton)
{
// display the menu
diff --git a/protocols/Weather/src/weather_update.cpp b/protocols/Weather/src/weather_update.cpp
index 75f73a2039..7c90f73fcf 100644
--- a/protocols/Weather/src/weather_update.cpp
+++ b/protocols/Weather/src/weather_update.cpp
@@ -381,199 +381,29 @@ int CWeatherProto::GetWeatherData(MCONTACT hContact)
wchar_t id[256];
GetStationID(hContact, id, _countof(id));
- // test ID format
- wchar_t *szInfo = wcschr(id, '/');
- if (szInfo == nullptr)
- return INVALID_ID_FORMAT;
-
- GetID(id);
-
wchar_t Svc[256];
GetStationID(hContact, Svc, _countof(Svc));
- GetSvc(Svc);
// check for invalid station
if (id[0] == 0) return INVALID_ID;
if (Svc[0] == 0) return INVALID_SVC;
- // get the update strings (loaded to memory from ini files)
- WIDATA *Data = GetWIData(Svc);
- if (Data == nullptr)
- return SVC_NOT_FOUND; // the ini for the station cannot be found
-
uint16_t cond = NA;
char loc[256];
- for (int i = 0; i < 4; ++i) {
- // generate update URL
- switch (i) {
- case 0:
- mir_snprintf(loc, Data->UpdateURL, _T2A(id).get());
- break;
-
- case 1:
- mir_snprintf(loc, Data->UpdateURL2, _T2A(id).get());
- break;
-
- case 2:
- mir_snprintf(loc, Data->UpdateURL3, _T2A(id).get());
- break;
-
- case 3:
- mir_snprintf(loc, Data->UpdateURL4, _T2A(id).get());
- break;
-
- default:
- continue;
- }
-
- if (loc[0] == 0)
- continue;
-
- // download the html file from the internet
- wchar_t *szData = nullptr;
- int retval = InternetDownloadFile(loc, Data->Cookie, Data->UserAgent, &szData);
- if (retval != 0) {
- mir_free(szData);
- return retval;
- }
- if (wcsstr(szData, L"Document Not Found") != nullptr) {
- mir_free(szData);
- return DOC_NOT_FOUND;
- }
-
- szInfo = szData;
- WIDATAITEMLIST *Item = Data->UpdateData;
-
- // begin parsing item by item
- while (Item != nullptr) {
- if (Item->Item.Url[0] != 0 && Item->Item.Url[0] != (i + '1')) {
- Item = Item->Next;
- continue;
- }
- wchar_t DataValue[MAX_DATA_LEN];
- switch (Item->Item.Type) {
- case WID_NORMAL:
- // if it is a normal item with start= and end=, then parse through the downloaded string
- // to get a data value.
- GetDataValue(&Item->Item, DataValue, &szInfo);
- if (mir_wstrcmp(Item->Item.Name, L"Condition") && mir_wstrcmpi(Item->Item.Unit, L"Cond"))
- wcsncpy(DataValue, TranslateW(DataValue), MAX_DATA_LEN - 1);
- break;
-
- case WID_SET:
- {
- // for the "Set Data=" operation
- DBVARIANT dbv;
- wchar_t *chop, *str, str2[MAX_DATA_LEN];
- BOOL hasvar = FALSE;
- size_t stl;
-
- // get the set data operation string
- str = Item->Item.End;
- DataValue[0] = 0;
- // go through each part of the operation string seperated by the & operator
- do {
- // the end of the string, last item
- chop = wcsstr(str, L" & ");
- if (chop == nullptr)
- chop = wcschr(str, '\0');
-
- stl = min(sizeof(str2) - 1, (unsigned)(chop - str - 2));
- wcsncpy(str2, str + 1, stl);
- str2[stl] = 0;
-
- switch (str[0]) {
- case '[': // variable, add the value to the result string
- hasvar = TRUE;
- if (!DBGetData(hContact, _T2A(str2), &dbv)) {
- mir_wstrncat(DataValue, TranslateW(dbv.pwszVal), _countof(DataValue) - mir_wstrlen(DataValue));
- DataValue[_countof(DataValue) - 1] = 0;
- db_free(&dbv);
- }
- break;
-
- case'\"': // constant, add it to the result string
- mir_wstrncat(DataValue, TranslateW(str2), _countof(DataValue) - mir_wstrlen(DataValue));
- DataValue[_countof(DataValue) - 1] = 0;
- break;
- }
-
- // remove the front part of the string that is done and continue parsing
- str = chop + 3;
- } while (chop[0] && str[0]);
-
- if (!hasvar) ConvertDataValue(&Item->Item, DataValue);
- break;
- }
- case WID_BREAK:
- {
- // for the "Break Data=" operation
- DBVARIANT dbv;
- if (!DBGetData(hContact, _T2A(Item->Item.Start), &dbv)) {
- wcsncpy(DataValue, dbv.pwszVal, _countof(DataValue));
- DataValue[_countof(DataValue) - 1] = 0;
- db_free(&dbv);
- }
- else {
- DataValue[0] = 0;
- break; // do not continue if the source is invalid
- }
-
- // generate the strings
- wchar_t *end = wcsstr(DataValue, Item->Item.Break);
- if (end == nullptr) {
- DataValue[0] = 0;
- break; // exit if break string is not found
- }
- *end = '\0';
- end += mir_wstrlen(Item->Item.Break);
- while (end[0] == ' ')
- end++; // remove extra space
-
- ConvertDataValue(&Item->Item, DataValue);
-
- // write the 2 strings created from the break operation
- if (Item->Item.End[0])
- db_set_ws(hContact, WEATHERCONDITION, _T2A(Item->Item.End), end);
- break;
- }
- }
-
- // don't store data if it is not available
- if ((DataValue[0] != 0 && mir_wstrcmp(DataValue, NODATA) &&
- mir_wstrcmp(DataValue, TranslateW(NODATA)) && mir_wstrcmp(Item->Item.Name, L"Ignore")) ||
- (!mir_wstrcmp(Item->Item.Name, L"Alert") && i == 0)) {
- // temporary workaround for mToolTip to show feel-like temperature
- if (!mir_wstrcmp(Item->Item.Name, L"Feel"))
- db_set_ws(hContact, WEATHERCONDITION, "Heat Index", DataValue);
- GetStationID(hContact, Svc, _countof(Svc));
- if (!mir_wstrcmp(Svc, opt.Default))
- db_set_ws(0, DEFCURRENTWEATHER, _T2A(Item->Item.Name), DataValue);
- if (!mir_wstrcmp(Item->Item.Name, L"Condition")) {
- wchar_t buf[128], *cbuf;
- mir_snwprintf(buf, L"#%s Weather", DataValue);
- cbuf = TranslateW(buf);
- if (cbuf[0] == '#')
- cbuf = TranslateW(DataValue);
- db_set_ws(hContact, WEATHERCONDITION, _T2A(Item->Item.Name), cbuf);
- CharLowerBuff(DataValue, (uint32_t)mir_wstrlen(DataValue));
- cond = GetIcon(DataValue, Data);
- }
- else if (mir_wstrcmpi(Item->Item.Unit, L"Cond") == 0) {
- wchar_t buf[128], *cbuf;
- mir_snwprintf(buf, L"#%s Weather", DataValue);
- cbuf = TranslateW(buf);
- if (cbuf[0] == '#')
- cbuf = TranslateW(DataValue);
- db_set_ws(hContact, WEATHERCONDITION, _T2A(Item->Item.Name), cbuf);
- }
- else db_set_ws(hContact, WEATHERCONDITION, _T2A(Item->Item.Name), DataValue);
- }
- Item = Item->Next;
- }
+ // download the html file from the internet
+ wchar_t *szData = nullptr;
+ int retval = 1; // InternetDownloadFile(loc, 0, 0, &szData);
+ if (retval != 0) {
mir_free(szData);
+ return retval;
}
+ if (wcsstr(szData, L"Document Not Found") != nullptr) {
+ mir_free(szData);
+ return DOC_NOT_FOUND;
+ }
+
+ mir_free(szData);
// assign condition icon
setWord(hContact, "StatusIcon", cond);