Beispiel #1
0
// do lastchecked(file(X)) returns amount of chars to add to str pointer
int lastChecked(CMStringA &szNewStr, const char *str)
{
	char *szPattern = "lastchecked(file(";
	size_t cbPattern = mir_strlen(szPattern);

	if (!strncmp(str, szPattern, cbPattern)) {
		int file;
		char tszFileName[MAX_PATH], temp[MAX_PATH], szSetting[20];
		sscanf(&str[cbPattern], "%d", &file);
		mir_snprintf(szSetting, "fn%d", file);

		char *szVar = db_get_sa(NULL, MODNAME, szSetting);
		if (szVar == NULL)
			return 0;

		if (!strncmp("http://", szVar, 7) || !strncmp("https://", szVar, 8))
			mir_snprintf(tszFileName, _countof(tszFileName), "%s\\plugins\\fn%d.html", getMimDir(temp), file);
		else
			mir_strncpy(tszFileName, szVar, _countof(tszFileName));
		mir_free(szVar);

		HANDLE hFile = CreateFileA(tszFileName, 0, FILE_SHARE_READ, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
		if (hFile == INVALID_HANDLE_VALUE)
			return 0;

		if (GetLastWriteTime(hFile, tszFileName)) {
			CloseHandle(hFile);
			szNewStr.Append(tszFileName);
			mir_snprintf(tszFileName, _countof(tszFileName), "%s%d))", szPattern, file);
			return (int)mir_strlen(tszFileName);
		}
		CloseHandle(hFile);
	}
	return 0;
}
Beispiel #2
0
int readFileIntoArray(int fileNumber, char *FileContents[])
{
	char dbSetting[20], temp[MAX_STRING_LENGTH];
	mir_snprintf(dbSetting, _countof(dbSetting), "fn%d", fileNumber);

	char *szVar = db_get_sa(NULL, MODNAME, dbSetting);
	if (szVar == NULL)
		return 0;

	char tszFileName[MAX_PATH];
	if (!strncmp("http://", szVar, 7) || !strncmp("https://", szVar, 7))
		mir_snprintf(tszFileName, _countof(tszFileName), "%s\\plugins\\fn%d.html", getMimDir(temp), fileNumber);
	else
		mir_strncpy(tszFileName, szVar, _countof(tszFileName));
	mir_free(szVar);

	FILE* file = fopen(tszFileName, "r");
	if (file == NULL)
		return 0;

	// read the file into the FileContents array
	// free this array before stringReplacer() returns
	int i;
	for (i = 0; fgets(temp, MAX_STRING_LENGTH - 1, file); i++) {
		if (temp[mir_strlen(temp) - 1] == '\n')
			temp[mir_strlen(temp) - 1] = '\0';
		else temp[mir_strlen(temp)] = '\0';

		FileContents[i] = (char*)malloc(mir_strlen(temp) + 1);
		if (FileContents[i] == NULL) break;
		mir_strcpy(FileContents[i], temp);
	}
	fclose(file);
	return i;
}
Beispiel #3
0
void timerFunc(void*)
{
	char text[512], fn[16], szFileName[MAX_PATH], temp[MAX_PATH];

	int timerCount = db_get_w(NULL, MODNAME, "timerCount", 1) + 1;

	if (LCStatus == ID_STATUS_OFFLINE) {
		killTimer();
		return;
	}
	db_set_w(NULL, MODNAME, "timerCount", (WORD)timerCount);

	/* update the web pages*/
	for (int i = 0;; i++) {
		mir_snprintf(fn, "fn%d", i);
		if (!db_get_static(NULL, MODNAME, fn, text, _countof(text)))
			break;

		if (!strncmp("http://", text, mir_strlen("http://")) || !strncmp("https://", text, mir_strlen("https://"))) {
			mir_snprintf(fn, "fn%d_timer", i);
			int timer = db_get_w(NULL, MODNAME, fn, 60);
			if (timer && !(timerCount % timer)) {
				if (!InternetDownloadFile(text)) {
					mir_snprintf(szFileName, "%s\\plugins\\fn%d.html", getMimDir(temp), i);
					savehtml(szFileName);
				}
			}
		}
	}

	/* update all the contacts */
	for (MCONTACT hContact = db_find_first(MODNAME); hContact; hContact = db_find_next(hContact, MODNAME)) {
		int timer = db_get_w(hContact, MODNAME, "Timer", 15);
		if (timer && !(timerCount % timer))
			if (db_get_static(hContact, MODNAME, "Name", text, _countof(text)))
				replaceAllStrings(hContact);
	}
}