// erase all current weather information from database // lastver = the last used version number in dword (using PLUGIN_MAKE_VERSION) void EraseAllInfo(DWORD lastver) { char str[255]; int ContactCount = 0; HANDLE hContact, LastContact = NULL; DBVARIANT dbv; // loop through all contacts hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); while(hContact) { // see if the contact is a weather contact if(IsMyContact(hContact)) { // check for upgrade if (lastver < __VERSION_DWORD) UpgradeContact(lastver, hContact); DBWriteContactSettingWord(hContact,WEATHERPROTONAME,"Status",ID_STATUS_OFFLINE); DBWriteContactSettingWord(hContact,WEATHERPROTONAME,"StatusIcon",ID_STATUS_OFFLINE); DBDeleteContactSetting(hContact,"CList","MyHandle"); // clear all data if (DBGetContactSettingString(hContact, WEATHERPROTONAME, "Nick", &dbv)) { DBWriteContactSettingString(hContact, WEATHERPROTONAME, "Nick", Translate("<Enter city name here>")); DBWriteContactSettingString(hContact, WEATHERPROTONAME, "LastLog", "never"); DBWriteContactSettingString(hContact, WEATHERPROTONAME, "LastCondition", "None"); DBWriteContactSettingString(hContact, WEATHERPROTONAME, "LastTemperature", "None"); } else DBFreeVariant(&dbv); /* DBWriteContactSettingString(hContact,WEATHERCONDITION,"Update", NODATA); DBWriteContactSettingString(hContact,WEATHERCONDITION,"Condition", NODATA); DBWriteContactSettingString(hContact,WEATHERCONDITION,"Temperature", NODATA); DBWriteContactSettingString(hContact,WEATHERCONDITION,"High", NODATA); DBWriteContactSettingString(hContact,WEATHERCONDITION,"Low", NODATA); DBWriteContactSettingString(hContact,WEATHERCONDITION,"Humidity", NODATA); DBWriteContactSettingString(hContact,WEATHERCONDITION,"Wind Speed", NODATA); DBWriteContactSettingString(hContact,WEATHERCONDITION,"Wind Direction", NODATA); DBWriteContactSettingString(hContact,WEATHERCONDITION,"Pressure", NODATA); DBWriteContactSettingString(hContact,WEATHERCONDITION,"Visibility", NODATA); DBWriteContactSettingString(hContact,WEATHERCONDITION,"Dewpoint", NODATA); DBWriteContactSettingString(hContact,WEATHERCONDITION,"Feel", NODATA); DBWriteContactSettingString(hContact,WEATHERCONDITION,"Heat Index", NODATA); DBWriteContactSettingString(hContact,WEATHERCONDITION,"Sunrise", NODATA); DBWriteContactSettingString(hContact,WEATHERCONDITION,"Sunset", NODATA); */ DBDataManage(hContact, WDBM_REMOVE, 0, 0); DBWriteContactSettingString(hContact, "UserInfo", "MyNotes", ""); // reset update tag DBWriteContactSettingByte(hContact,WEATHERPROTONAME,"IsUpdated",FALSE); // reset logging settings if (!DBGetContactSettingString(hContact,WEATHERPROTONAME,"Log",&dbv)) { DBWriteContactSettingByte(hContact,WEATHERPROTONAME,"File",(BYTE)(dbv.pszVal[0] != 0)); DBFreeVariant(&dbv); } else DBWriteContactSettingByte(hContact,WEATHERPROTONAME,"File",FALSE); // if no default station find, assign a new one if (opt.Default[0] == 0) { GetStationID(hContact, opt.Default, sizeof(opt.Default)); opt.DefStn = hContact; if (!DBGetContactSettingString(hContact,WEATHERPROTONAME,"Nick",&dbv)) { wsprintf(str, Translate("%s is now the default weather station"), dbv.pszVal); DBFreeVariant(&dbv); MessageBox(NULL, str, Translate("Weather Protocol"), MB_OK|MB_ICONINFORMATION); } } // get the handle of the default station if (opt.DefStn == NULL) { if (!DBGetContactSettingString(hContact,WEATHERPROTONAME,"ID",&dbv)) { if (!strcmp(dbv.pszVal, opt.Default)) opt.DefStn = hContact; DBFreeVariant(&dbv); } } ContactCount++; // increment counter LastContact = hContact; } hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0); } // if weather contact exists, set the status to online so it is ready for update // if (ContactCount != 0) status = ONLINE; // in case where the default station is missing if (opt.DefStn == NULL && ContactCount != 0) { if (!DBGetContactSettingString(LastContact,WEATHERPROTONAME,"ID",&dbv)) { strcpy(opt.Default, dbv.pszVal); DBFreeVariant(&dbv); } opt.DefStn = LastContact; if (!DBGetContactSettingString(LastContact,WEATHERPROTONAME,"Nick",&dbv)) { wsprintf(str, Translate("%s is now the default weather station"), dbv.pszVal); DBFreeVariant(&dbv); MessageBox(NULL, str, Translate("Weather Protocol"), MB_OK|MB_ICONINFORMATION); } } // save option in case of default station changed DBWriteContactSettingString(NULL, WEATHERPROTONAME, "Default", opt.Default); }
// erase all current weather information from database // lastver = the last used version number in dword (using PLUGIN_MAKE_VERSION) void EraseAllInfo() { TCHAR str[255]; int ContactCount = 0; MCONTACT LastContact = NULL; DBVARIANT dbv; // loop through all contacts for (MCONTACT hContact = db_find_first(WEATHERPROTONAME); hContact; hContact = db_find_next(hContact, WEATHERPROTONAME)) { db_set_w(hContact, WEATHERPROTONAME, "Status", ID_STATUS_OFFLINE); db_set_w(hContact, WEATHERPROTONAME, "StatusIcon", ID_STATUS_OFFLINE); db_unset(hContact, "CList", "MyHandle"); // clear all data if (db_get_ts(hContact, WEATHERPROTONAME, "Nick", &dbv)) { db_set_ts(hContact, WEATHERPROTONAME, "Nick", TranslateT("<Enter city name here>")); db_set_s(hContact, WEATHERPROTONAME, "LastLog", "never"); db_set_s(hContact, WEATHERPROTONAME, "LastCondition", "None"); db_set_s(hContact, WEATHERPROTONAME, "LastTemperature", "None"); } else db_free(&dbv); DBDataManage(hContact, WDBM_REMOVE, 0, 0); db_set_s(hContact, "UserInfo", "MyNotes", ""); // reset update tag db_set_b(hContact, WEATHERPROTONAME, "IsUpdated", FALSE); // reset logging settings if (!db_get_ts(hContact, WEATHERPROTONAME, "Log", &dbv)) { db_set_b(hContact, WEATHERPROTONAME, "File", (BYTE)(dbv.ptszVal[0] != 0)); db_free(&dbv); } else db_set_b(hContact, WEATHERPROTONAME, "File", FALSE); // if no default station find, assign a new one if (opt.Default[0] == 0) { GetStationID(hContact, opt.Default, _countof(opt.Default)); opt.DefStn = hContact; if (!db_get_ts(hContact, WEATHERPROTONAME, "Nick", &dbv)) { mir_sntprintf(str, TranslateT("%s is now the default weather station"), dbv.ptszVal); db_free(&dbv); MessageBox(NULL, str, TranslateT("Weather Protocol"), MB_OK | MB_ICONINFORMATION); } } // get the handle of the default station if (opt.DefStn == NULL) { if (!db_get_ts(hContact, WEATHERPROTONAME, "ID", &dbv)) { if (!mir_tstrcmp(dbv.ptszVal, opt.Default)) opt.DefStn = hContact; db_free(&dbv); } } ContactCount++; // increment counter LastContact = hContact; } // if weather contact exists, set the status to online so it is ready for update // if (ContactCount != 0) status = ONLINE; // in case where the default station is missing if (opt.DefStn == NULL && ContactCount != 0) { if (!db_get_ts(LastContact, WEATHERPROTONAME, "ID", &dbv)) { _tcsncpy(opt.Default, dbv.ptszVal, _countof(opt.Default) - 1); db_free(&dbv); } opt.DefStn = LastContact; if (!db_get_ts(LastContact, WEATHERPROTONAME, "Nick", &dbv)) { mir_sntprintf(str, TranslateT("%s is now the default weather station"), dbv.ptszVal); db_free(&dbv); MessageBox(NULL, str, TranslateT("Weather Protocol"), MB_OK | MB_ICONINFORMATION); } } // save option in case of default station changed db_set_ts(NULL, WEATHERPROTONAME, "Default", opt.Default); }