From 42ecdeca853a425c8cec344a57826b9375153ca0 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 22 Mar 2019 18:31:39 +0300 Subject: N&R: useless utility functions removed --- plugins/NotesAndReminders/src/reminders.cpp | 185 ++++++++++++---------------- 1 file changed, 77 insertions(+), 108 deletions(-) (limited to 'plugins/NotesAndReminders/src/reminders.cpp') diff --git a/plugins/NotesAndReminders/src/reminders.cpp b/plugins/NotesAndReminders/src/reminders.cpp index 35420ac104..7802d455a3 100644 --- a/plugins/NotesAndReminders/src/reminders.cpp +++ b/plugins/NotesAndReminders/src/reminders.cpp @@ -174,117 +174,88 @@ void JustSaveReminders(void) } } -void LoadReminders(void) +static bool LoadReminder(char *Value) { - BOOL GenerateUids = FALSE; + char *DelPos = strchr(Value, 0x1B); + if (DelPos) + *DelPos = 0; - arReminders.destroy(); - int RemindersCount = g_plugin.getDword("RemindersData", 0); + // uid:when + char *TVal = strchr(Value + 1, ':'); + if (!TVal || (DelPos && TVal > DelPos)) + return false; + *TVal++ = 0; + + REMINDERDATA *TempRem = new REMINDERDATA(); + TempRem->uid = strtoul(Value + 1, nullptr, 10); + TempRem->When.QuadPart = _strtoui64(TVal, nullptr, 16) * FILETIME_TICKS_PER_SEC; + + // optional \033 separated params + while (DelPos) { + TVal = DelPos + 1; + // find param end and make sure it's null-terminated (if end of data then it's already null-terminated) + DelPos = strchr(TVal, 0x1B); + if (DelPos) + *DelPos = 0; + + // tag: + char *sep = strchr(TVal, ':'); + if (!sep || (DelPos && sep > DelPos)) + break; - for (int i = 0; i < RemindersCount; i++) { - WORD Size = 65535; - char *Value = nullptr; + UINT tag = strtoul(TVal, nullptr, 10); + TVal = sep + 1; - char ValueName[32]; - mir_snprintf(ValueName, "RemindersData%d", i); - ReadSettingBlob(0, MODULENAME, ValueName, &Size, (void**)&Value); + switch (tag) { + case DATATAG_TEXT: + TempRem->szText = TVal; + break; - // was the blob found - if (!Size || !Value) - continue; + case DATATAG_SNDREPEAT: + TempRem->RepeatSound = strtoul(TVal, nullptr, 10); + break; - REMINDERDATA *TempRem = new REMINDERDATA(); - char *DelPos = strchr(Value, 0x1B); - - // ensure that read data is null-terminated - Value[(UINT)Size - 1] = 0; - - if (Value[0] == 'X') { - // new eXtended/fleXible data format - if (DelPos) - *DelPos = 0; - - // uid:when - char *TVal = strchr(Value + 1, ':'); - if (!TVal || (DelPos && TVal > DelPos)) - continue; - - *TVal++ = 0; - TempRem->uid = strtoul(Value + 1, nullptr, 10); - TempRem->When.QuadPart = _strtoui64(TVal, nullptr, 16) * FILETIME_TICKS_PER_SEC; - - // optional \033 separated params - while (DelPos) { - TVal = DelPos + 1; - // find param end and make sure it's null-terminated (if end of data then it's already null-terminated) - DelPos = strchr(TVal, 0x1B); - if (DelPos) - *DelPos = 0; - - // tag: - char *sep = strchr(TVal, ':'); - if (!sep || (DelPos && sep > DelPos)) - break; - - UINT tag = strtoul(TVal, nullptr, 10); - TVal = sep + 1; - - switch (tag) { - case DATATAG_TEXT: - TempRem->szText = TVal; - break; - - case DATATAG_SNDREPEAT: - TempRem->RepeatSound = strtoul(TVal, nullptr, 10); - break; - - case DATATAG_SNDSEL: - TempRem->SoundSel = strtol(TVal, nullptr, 10); - if (TempRem->SoundSel > 2) TempRem->SoundSel = 2; - break; - - case DATATAG_REPEAT: - TempRem->bRepeat = strtol(TVal, nullptr, 10) != 0; - break; - } - } + case DATATAG_SNDSEL: + TempRem->SoundSel = strtol(TVal, nullptr, 10); + if (TempRem->SoundSel > 2) TempRem->SoundSel = 2; + break; - if (TempRem->SoundSel < 0) - TempRem->RepeatSound = 0; + case DATATAG_REPEAT: + TempRem->bRepeat = strtol(TVal, nullptr, 10) != 0; + break; } - else { - // old format (for DB backward compatibility) - if (!DelPos) - continue; + } - DelPos[0] = 0; - // convert time_t to (local) FILETIME + if (TempRem->SoundSel < 0) + TempRem->RepeatSound = 0; - time_t tt = (time_t)strtoul(Value, nullptr, 10); - struct tm *stm = localtime(&tt); + // queue uid generation if invalid uid is present + arReminders.insert(TempRem); + return TempRem->uid == 0; +} - SYSTEMTIME tm; - tm.wDayOfWeek = 0; - tm.wSecond = 0; - tm.wMilliseconds = 0; - tm.wHour = stm->tm_hour; - tm.wMinute = stm->tm_min; - tm.wSecond = stm->tm_sec; - tm.wYear = stm->tm_year + 1900; - tm.wMonth = stm->tm_mon + 1; - tm.wDay = stm->tm_mday; - SystemTimeToFileTime(&tm, (FILETIME*)&TempRem->When); - - TempRem->szText = DelPos + 1; - } +void LoadReminders(void) +{ + bool GenerateUids = false; - // queue uid generation if invalid uid is present - if (!TempRem->uid) - GenerateUids = true; + arReminders.destroy(); + int RemindersCount = g_plugin.getDword("RemindersData", 0); - arReminders.insert(TempRem); + for (int i = 0; i < RemindersCount; i++) { + char ValueName[32]; + mir_snprintf(ValueName, "RemindersData%d", i); + + DBVARIANT dbv = { DBVT_BLOB }; + if (db_get(0, MODULENAME, ValueName, &dbv)) + continue; - FreeSettingBlob(Size, Value); + // was the blob found + if (!dbv.cpbVal || !dbv.pbVal) + continue; + + if (dbv.pbVal[0] == 'X') + GenerateUids |= LoadReminder((char*)dbv.pbVal); + db_free(&dbv); } // generate UIDs if there are any items with an invalid UID @@ -488,17 +459,15 @@ bool CheckRemindersAndStart(void) bResult = true; } else { - char *S2 = strchr(g_RemindSMS, '@'); - char *S1 = (char*)malloc(S2 - g_RemindSMS); - - strncpy(S1, g_RemindSMS, S2 - g_RemindSMS); - S1[S2 - g_RemindSMS] = 0x0; - S2++; - Send(S1, S2, pReminder->szText, NULL); - SAFE_FREE((void**)&S1); - DeleteReminder(pReminder); - JustSaveReminders(); - NOTIFY_LIST(); + char *p = strchr(g_RemindSMS, '@'); + if (p) { + Send(g_RemindSMS, p+1, pReminder->szText, NULL); + *p = '@'; + + DeleteReminder(pReminder); + JustSaveReminders(); + NOTIFY_LIST(); + } } } } -- cgit v1.2.3