CString CLogActions::GetLogFileName(const char* szLogName)
{
	CString sLogPath=getFileFullName(objSettings.sMessageLogDirectory,TRUE);
	if(!objSettings.SaveMesNotesByDefForUser || strcmp(szLogName,DEFAULT_GENERALLOG)==0){
		// Если нужен общий лог или поюзерного лога нет совсем...
		return sLogPath+DEFAULT_GENERALLOG;
	}
	// Удаляем неверные символы
	CString sGoodLogName=szLogName;
	MakeSafeFileName(sGoodLogName);
	return sLogPath+sGoodLogName+DEFAULT_PERSONLOG;
}
Esempio n. 2
0
// Download thread
void ViDownloadThread(THREAD *thread, void *param)
{
	VI_INSTALL_DLG *d;
	VI_SETTING_ARCH *a;
	HWND hWnd;
	UINT num_files = 2;
	VI_DOWNLOAD_FILE files[2];
	VI_DOWNLOAD_FILE *f;
	UINT i;
	// Validate arguments
	if (thread == NULL || param == NULL)
	{
		return;
	}

	d = (VI_INSTALL_DLG *)param;
	hWnd = d->hWnd;

	Zero(files, sizeof(files));

	a = ViGetSuitableArchForCpu();

	// File body
	f = &files[0];
	StrCpy(f->SrcPath, sizeof(f->SrcPath), a->Path);

	// Configuration file
	if (IsEmptyStr(setting.SettingPath) == false)
	{
		f = &files[1];
		StrCpy(f->SrcPath, sizeof(f->SrcPath), setting.SettingPath);
	}
	else
	{
		// No configuration file
		num_files = 1;
	}

	for (i = 0;i < num_files;i++)
	{
		bool b = true;

		if (i == 0 && setting.DownloadNotRequired)
		{
			b = false;
		}

		if (b)
		{
			wchar_t tmp[MAX_SIZE];
			IO *dest = NULL;
			VI_FILE *down;
			UINT ret;
			UINT totalsize;
			UINT currentsize;
			wchar_t filename_w[MAX_PATH];

			f = &files[i];
			GetFileNameFromFilePath(f->FileName, sizeof(f->FileName), f->SrcPath);
			MakeSafeFileName(f->FileName, sizeof(f->FileName), f->FileName);

			StrToUni(filename_w, sizeof(filename_w), f->FileName);
			ConbinePathW(f->DestPathW, sizeof(f->DestPathW), MsGetMyTempDirW(), filename_w);

			ViInstallDlgSetPos(hWnd, 0);
			UniFormat(tmp, sizeof(tmp), _U(IDS_DOWNLOADSTART+skip), f->FileName);
			ViInstallDlgSetText(d, hWnd, S_STATUS, tmp);

			down = ViOpenFile(f->SrcPath);
			if (down == NULL)
			{
				MsgBoxEx(hWnd, MB_ICONSTOP, _U(IDS_DOWNLOAD_ERROR+skip), f->FileName);

				ViInstallDlgCancel(hWnd);
				return;
			}

			dest = FileCreateW(f->DestPathW);
			if (dest == NULL)
			{
				MsgBoxEx(hWnd, MB_ICONSTOP, _U(IDS_TEMP_ERROR+skip), f->DestPathW);

				ViCloseFile(down);
				ViInstallDlgCancel(hWnd);
				return;
			}

			totalsize = ViGetFileSize(down);
			currentsize = 0;

			UniFormat(tmp, sizeof(tmp), _U(IDS_DOWNLOADING3+skip), f->FileName);
			ViInstallDlgSetText(d, hWnd, S_STATUS, tmp);

			while (true)
			{
				UINT pos = 0;

				if (d->Halt)
				{
					// User cancel
					FileClose(dest);
					ViCloseFile(down);
					return;
				}

				UniFormat(tmp, sizeof(tmp), _U(IDS_DOWNLOADING3+skip), f->FileName);

				ViInstallDlgSetText(d, hWnd, IDS_DOWNLOADING3+skip, tmp);
				ret = ViReadFile(down, d->Buf, d->BufSize);

				if (ret == INFINITE)
				{
					// Communication error
					MsgBoxEx(hWnd, MB_ICONSTOP, _U(IDS_DOWNLOAD_ERROR+skip), f->FileName);

					FileClose(dest);
					ViCloseFile(down);
					ViInstallDlgCancel(hWnd);

					return;
				}

				// Draw progress
				currentsize += ret;

				if (totalsize != 0)
				{
					UniFormat(tmp, sizeof(tmp), _U(IDS_DOWNLOADING+skip),
						((float)totalsize) / 1024.0f / 1024.0f,
						((float)currentsize) / 1024.0f / 1024.0f);

					pos = (UINT)(((float)currentsize) * 100.0f / ((float)totalsize));
				}
				else
				{
					UniFormat(tmp, sizeof(tmp), _U(IDS_DOWNLOADING2+skip),
						((float)currentsize) / 1024.0f / 1024.0f);
					pos = (UINT)(((float)currentsize) * 100.0f / (1024.0f * 1024.0f * 10.0f));
				}

				ViInstallDlgSetText(d, hWnd, S_SIZEINFO, tmp);
				ViInstallDlgSetPos(hWnd, pos);

				if (ret == 0)
				{
					// Download Complete
					break;
				}
				else
				{
					FileWrite(dest, d->Buf, ret);
				}
			}

			ViCloseFile(down);
			FileClose(dest);
		}
	}

	UniStrCpy(setting.DownloadedInstallerPathW, sizeof(setting.DownloadedInstallerPathW),
		files[0].DestPathW);

	if (num_files >= 2)
	{
		UniStrCpy(setting.DownloadedSettingPathW, sizeof(setting.DownloadedSettingPathW),
			files[1].DestPathW);
	}

	PostMessageA(hWnd, WM_VI_DOWNLOAD_FINISHED, 0, 0);
}
BOOL CNetRssProtocol::SendNet_StatusExch(const char* szRec,const char* szProtocol)
{
	if(CString(szProtocol)=="sms"){
		return 1;
	}
	if(objSettings.lRSSLocUser){
		if(isScreenSaverActiveOrCLocked()){
			return -1;
		}
	}
	CString szRecipient=GetCompNameNoProtocol(szRec);
	int iPerson=objSettings.AddrBook.FindPersonByIP(szRecipient,TRUE);
	if(iPerson!=-1){
		if(objSettings.AddrBook.aPersons[iPerson]->IsGroup()){
			// Групповой-заблокирован
			return -1;
		};
	}
	CWebWorld url;
	CString sRSS=url.GetWebPage(szRecipient);
	if(sRSS==""){
		// Не доступен
		return -1;
	}
	#ifdef _DEBUG
	CString sFile=CString("lastblog")+szRecipient+".xml";//http://davydov.blogspot.com/atom.xml
	MakeSafeFileName(sFile);
	SaveFile(CString("c://")+sFile,sRSS);
	#endif
	int iStatus=1;
	XDoc* feedDoc=parseXML(sRSS);
	XNode* feed=0;
	if(feedDoc){
		feed=feedDoc->GetRoot();
		if(!feed){
			delete feedDoc;
			return -1;
		}
		CString sLnewsBuildDate=aLoadedRss[szRecipient];
		int iMaxNews=objSettings.dwProtocolRSSMAxNews;
		if(sLnewsBuildDate==""){
			iMaxNews=5;
		}
		CString sLnewsBuildDateToSet="";
		BOOL bAtom=0;
		CString sGlobalTitle;
		if(feed->GetChild("channel",1)==GetEmptyNode() && feed->GetChild("title",1)!=GetEmptyNode()){
			// Atom!!!
			bAtom=1;
			sGlobalTitle=feed->GetChild("title",1)->value;
		}else{
			sGlobalTitle=feed->GetChild("channel",1)->GetChild("title",1)->value;
		}
		CString sFrom="";
		if(iPerson!=-1){
			sFrom=objSettings.AddrBook.aPersons[iPerson]->GetTitle();
		}else{
			sFrom=sGlobalTitle+"/rss";
		}
		CXMLNodes feedItems;
		if(bAtom){
			feed->FindByTagName("entry",FALSE,feedItems);
		}else{
			feed->GetChild("channel",1)->FindByTagName("item",FALSE,feedItems);
		}
		int iCount=0;
		int iLenCount=feedItems.GetSize();
		if(iLenCount==0){
			// Может rdf???
			feed->FindByTagName("item",FALSE,feedItems);
			iLenCount=feedItems.GetSize();
		}
		CString sSummary;
		while(iCount<iLenCount && iCount<iMaxNews){
			XNode* item=feedItems[iCount];
			CString sPubDate;
			if(bAtom){
				sPubDate=item->GetChild("issued",1)->value;
			}else{
				sPubDate=item->GetChild("pubDate",1)->value;
				if(sPubDate==""){
					//rdf???
					sPubDate=item->GetChild("dc:date",1)->value;
				}
			}
			//sPubDate=UnescapeString(sPubDate);
			StripTags(sPubDate);
			DeEntitize(sPubDate);

			CString sTitle;
			sTitle=item->GetChild("title",1)->value;
			//sTitle=UnescapeString(sTitle);
			StripTags(sTitle);
			DeEntitize(sTitle);
			if(sTitle==""){
				sTitle=sGlobalTitle;
			}
			
			CString sAuthor;
			if(bAtom){
				LPXNode pAut;
				pAut=item->GetChild("author",1);
				if(pAut->iBeginPos!=-1 && pAut->iEndPos!=-1){
					sAuthor=sRSS.Mid(pAut->iBeginPos,pAut->iEndPos-pAut->iBeginPos);
				}
			}else{
				sAuthor=item->GetChild("author",1)->value;
				if(sAuthor==""){
					//rdf???
					sAuthor=item->GetChild("dc:creator",1)->value;
				}
			}
			//sAuthor=UnescapeString(sAuthor);
			StripTags(sAuthor);
			DeEntitize(sAuthor);
			if(sAuthor!=""){
				sTitle+=" (";
				sTitle+=sAuthor;
				sTitle+=")";
			}
			
			LPXNode pDesk;
			if(bAtom){
				pDesk=item->GetChild("content",1);
			}else{
				pDesk=item->GetChild("description",1);
			}
			CString sDesk;
			if(pDesk->iBeginPos!=-1 && pDesk->iEndPos!=-1){
				sDesk=sRSS.Mid(pDesk->iBeginPos,pDesk->iEndPos-pDesk->iBeginPos);
			}
			/*
			if(sDesk.Find("%20")!=-1){
				sDesk=UnescapeString(sDesk);
			}
			*/
			CString sDeskL=sDesk;
			sDeskL.MakeLower();
			if(sDeskL.Find(";div")!=-1 || sDeskL.Find(";span")!=-1){
				// Для извращенных...
				DeEntitize(sDesk);
				StripTags(sDesk);
			}else{
				// Это по правильному
				StripTags(sDesk);
				DeEntitize(sDesk);
			}
			sDesk.TrimLeft();
			sDesk.TrimRight();

			CString sLink;
			if(bAtom){
				CXMLNodes feedLinks;
				item->FindByTagName("link",FALSE,feedLinks);
				for(int j=0;j<feedLinks.GetSize();j++){
					XNode* itemLnk=feedLinks[j];
					sLink=itemLnk->GetAttr("href")->value;
					CString sType=itemLnk->GetAttr("type")->value;
					sType.MakeLower();
					if(sType.Find("text")!=-1){
						break;// Наша линка!
					}
				}
			}else{
				sLink=item->GetChild("link",1)->value;
			}
			sLink=UnescapeString(sLink);
			StripTags(sLink);
			DeEntitize(sLink);
			sLink.TrimLeft();
			sLink.TrimRight();
			
			{
				CSmartLock SL(&csRssFeeds,TRUE);
				CString sRnewsBuildDate=sLink+"\t"+sPubDate+" "+sTitle+" "+sDesk;
				if(sLnewsBuildDate==sRnewsBuildDate){
					if(iCount==0){
						iStatus=1;
					}
					break;
				}
				if(sLnewsBuildDateToSet==""){// Запомнили самую первую новость
					sLnewsBuildDateToSet=sRnewsBuildDate;
				}
				/*
				#ifdef _DEBUG
				else{
					sDesk+="\nOld id-text:"+sLnewsBuildDate;
					sDesk+="\nNew id-text:"+sRnewsBuildDate;
				}
				#endif
				*/
			}

			if(sPubDate!=""){
				COleDateTime dt;
				dt.ParseDateTime(sPubDate);
				if(dt.GetStatus()==COleDateTimeSpan::valid){
					sTitle=dt.Format("%x %X. ")+sTitle;
				}
			}
			CString sNews=sTitle;
			sNews+="\n";
			if(sDesk!=""){
				sNews+="\n";
				sNews+=sDesk;
			}
			if(sLink!=""){
				sNews+="\n\n";
				sNews+=_l("Read more")+": ";
				sNews+=sLink;
			}
			CDataXMLSaver::Xml2Str(sNews);
			if(objSettings.lRSSSummar){
				sSummary+="\n";
				sSummary+="\n";
				sSummary+=sTitle;
				sSummary+="\n";
				sSummary+=_l("Read more")+": ";
				sSummary+=sLink;
			}else{
				CString sAttach="";
				if(objSettings.dwProtocolRSSOType){
					sAttach+=Format("["DEF_OPENTYPE"%i]",objSettings.dwProtocolRSSOType);
				}
				OpenMessage(sFrom,"",sNews,"",sAttach,sGlobalTitle);
			}
			iCount++;
		}
		if(sSummary!=""){
			CString sAttach="";
			if(objSettings.dwProtocolRSSOType){
				sAttach+=Format("["DEF_OPENTYPE"%i]",objSettings.dwProtocolRSSOType);
			}
			sSummary.TrimLeft();
			OpenMessage(sFrom,"",sSummary,"",sAttach,sGlobalTitle);
		}
		if(feedDoc){
			delete feedDoc;
		}
		if(sLnewsBuildDateToSet!=""){
			aLoadedRss.SetAt(szRecipient,sLnewsBuildDateToSet);
		}
	}
	if(iPerson!=-1){
		objSettings.AddrBook.aPersons[iPerson]->iOnlineStatus=iStatus;
		RefreshUserStatusIcon(iPerson);
	}
	return 0;
}
Esempio n. 4
0
int	WINAPI WKInitRecording(HWND hParent)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	if(!pInter){
		AfxMessageBox("Container not found!!!");
		return 0;
	}
	if(hMacroRecControlWindow!=0){
		AfxMessageBox(_pl("To record new macro, You have to stop\nrecording previous macro"));
		return 0;
	}
	static long lMacroCounter=1;
	plgOptions.sLastMacroName="";
	COleDateTime dt=COleDateTime::GetCurrentTime();
	plgOptions.sLastMacroName.Format("%s (%02lu.%02lu.%04lu)",GetRandomName(),dt.GetDay(),dt.GetMonth(),dt.GetYear());
	lMacroCounter++;
	char szPrefFolder[MAX_PATH]="";
	pInter->GetPreferencesFolder(szPrefFolder,sizeof(szPrefFolder));
	CString sTargetFile=szPrefFolder;
	sTargetFile+="RecorderMacro\\";
	if(int(GetFileAttributes(sTargetFile))==-1){
		::CreateDirectory(sTargetFile,NULL);
	}
	plgOptions.sLastMacroContent="";
	DWORD dwStart=GetTickCount();
	ATOM at=GlobalAddAtom("WK_RECORDING");
	DWORD dwRes=DialogBox(WKGetPluginContainer()->GetPluginDllInstance(),MAKEINTRESOURCE(IDD_OPTIONS),hParent,OptionsDialogProc);
	if(!WKUtils::isWKUpAndRunning()){
		return 0;
	}
	GlobalDeleteAtom(at);
	if(dwRes!=0){
		// Пользователь отказался...
		return 0;
	}
	if(pInter){
		pInter->PushMyOptions(0);
	}
	if(plgOptions.sLastMacroContent==""){
		return 0;
	}
	CString sMacroFileNm=plgOptions.sLastMacroName;
	MakeSafeFileName(sMacroFileNm);
	sTargetFile+=sMacroFileNm;
	sTargetFile+=".wkm";
	// Добавлять иконку на время записи макроса
	// Префикс макроса...
	CString sMacroTemplate=	"// Language: %s\r\n"\
							"// Title: %s\r\n"\
							"// Description: Recorded macro\r\n"\
							"// ParamType: String\r\n"\
							"// Hint: wait_for_key_release;\r\n\r\n"\
							"%s"\
							"%s"\
							"\r\n"\
							"// <wkMain>: Action\r\n"\
							"function wkMain()\r\n"\
							"{// wkMain description: Replay keystrokes\r\n"\
							"%s"\
							"};\r\n"\
							"// </wkMain>: End of Action\r\n"\
							"\r\n";
	CString sDopFunc=		(plgOptions.lMFormat==0 || plgOptions.lMFormat==1 || plgOptions.lMFormat==3)?"":"// System object that will be used to replay recorded keystrokes\r\nvar WshShell = new ActiveXObject('WScript.Shell');\r\n";
	sDopFunc+=				"// Playback Speed ratio ('1' means as recorded)\r\n";
	sDopFunc+=				"var iMacroSpeed = 1.0;";
	sDopFunc+=				"\r\n";
	CString sWaitFunc=		(plgOptions.lMFormat==0 || plgOptions.lMFormat==1 || plgOptions.lMFormat==3)?"":"function Wait(time)\r\n"\
							"{\r\n"\
							"	var d = new Date();\r\n"\
							"	var timeCounter = 0;\r\n"\
							"	while((new Date()).getSeconds()-d.getSeconds()<(time*iMacroSpeed)){\r\n"\
							"		timeCounter++;\r\n"\
							"	};\r\n"\
							"}\r\n";
	plgOptions.sLastMacroContent=Format(sMacroTemplate,(plgOptions.lMFormat==0 || plgOptions.lMFormat==1 || plgOptions.lMFormat==3)?"JScript":"JScript",plgOptions.sLastMacroName,sDopFunc,(plgOptions.bRecPauses?sWaitFunc:""),plgOptions.sLastMacroContent);
	DWORD dwStop=GetTickCount();
	CString sTime;
	sTime.Format("%.2f",double(dwStop-dwStart)/1000);
	int iRes=::MessageBox(NULL,_pl("Macro recorded")+"!\n"+_pl("Duration")+": "+sTime+_pl("sec")+". "+_pl("Continue")+"?",_pl("Macro successfully recorded")+"!",IDOK);
	if(iRes==IDOK){
		SaveFile(sTargetFile,plgOptions.sLastMacroContent);
		if(plgOptions.bAP_Add2WK && pInter){
			pInter->AddQrunFromFile(sTargetFile);
		}
		if(plgOptions.bAP_OpenInEd && pInter){
			int iRes=(int)::ShellExecute(NULL,"open","notepad.exe",CString("\"")+sTargetFile+CString("\""),NULL,SW_SHOWNORMAL);
		}
	}
	return 1;
}