Exemplo n.º 1
0
BOOL CCheckRuleXMLParse::Load(CheckRuleArray &arrCheckRuleList)
{
	BOOL bRet = FALSE;
	// 检查旧版本生成的未加密xml文件是否存在
	CString strOldXmlPath = m_strRuleFilePath;
	strOldXmlPath.Replace(L".bpxml", L"xml");
	if (IsFileExist(strOldXmlPath))
	{
		// 读取老版本生成的未加密xml
		if (CheckVersion(m_strRuleFilePath).CompareNoCase(L"1.0") == 0)
			bRet = Load(m_strRuleFilePath, arrCheckRuleList);
		if (CheckVersion(m_strRuleFilePath).CompareNoCase(L"1.1") == 0)
			bRet = LoadNew(m_strRuleFilePath, arrCheckRuleList);
	}
	else
	{
		if (IsFileExist(m_strRuleFilePath))
		{
			// 先解密再读取
			CString strTempXmlFile;
			GetTempFile(strTempXmlFile, L"xml");
			DecodeFileEx(m_strRuleFilePath, strTempXmlFile);
			if (CheckVersion(strTempXmlFile).CompareNoCase(L"1.0") == 0)
				bRet = Load(strTempXmlFile, arrCheckRuleList);
			if (CheckVersion(strTempXmlFile).CompareNoCase(L"1.1") == 0)
				bRet = LoadNew(strTempXmlFile, arrCheckRuleList);

			// 结束后删除临时xml文件
			SafeDeleteFile(strTempXmlFile);
		}
	}

	return bRet;
}
Exemplo n.º 2
0
static void ApplyDownloads(void *param)
{
	HWND hDlg = (HWND)param;

	//////////////////////////////////////////////////////////////////////////////////////
	// if we need to escalate priviledges, launch a atub

	if (!PrepareEscalation()) {
		PostMessage(hDlg, WM_CLOSE, 0, 0);
		return;
	}

	//////////////////////////////////////////////////////////////////////////////////////
	// ok, let's unpack all zips

	AutoHandle pipe(hPipe);
	HWND hwndList = GetDlgItem(hDlg, IDC_LIST_UPDATES);
	OBJLIST<FILEINFO> &todo = *(OBJLIST<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
	//create needed folders after escalating priviledges. Folders creates when we actually install updates
	TCHAR tszFileTemp[MAX_PATH], tszFileBack[MAX_PATH];

	mir_sntprintf(tszFileBack, _countof(tszFileBack), _T("%s\\Backups"), tszRoot);
	SafeCreateDirectory(tszFileBack);

	mir_sntprintf(tszFileTemp, _countof(tszFileTemp), _T("%s\\Temp"), tszRoot);
	SafeCreateDirectory(tszFileTemp);

	VARST tszMirandaPath(_T("%miranda_path%"));

	HANDLE nlc = NULL;
	for (int i=0; i < todo.getCount(); ++i) {
		ListView_EnsureVisible(hwndList, i, FALSE);
		if (todo[i].bEnabled) {
			// download update
			ListView_SetItemText(hwndList, i, 1, TranslateT("Downloading..."));

			if (DownloadFile(&todo[i].File, nlc)) {
				ListView_SetItemText(hwndList, i, 1, TranslateT("Succeeded."));
				if (unzip(todo[i].File.tszDiskPath, tszMirandaPath, tszFileBack,false))
					SafeDeleteFile(todo[i].File.tszDiskPath);  // remove .zip after successful update
			}
			else
				ListView_SetItemText(hwndList, i, 1, TranslateT("Failed!"));
		}
		else
			ListView_SetItemText(hwndList, i, 1, TranslateT("Skipped."));
	}
	Netlib_CloseHandle(nlc);

	ShowPopup(TranslateT("Plugin Updater"), TranslateT("Download complete"), POPUP_TYPE_INFO);

	int rc = MessageBox(hDlg, TranslateT("Download complete. Do you want to go to plugins option page?"), TranslateT("Plugin Updater"), MB_YESNO | MB_ICONQUESTION);
	if (rc == IDYES)
		CallFunctionAsync(OpenPluginOptions, 0);

	PostMessage(hDlg, WM_CLOSE, 0, 0);
}
Exemplo n.º 3
0
static void ApplyUpdates(void *param)
{
	HWND hDlg = (HWND)param;
	OBJLIST<FILEINFO> &todo = *(OBJLIST<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
	if (todo.getCount() == 0) {
		return;
	}

	// 1) If we need to escalate priviledges, launch a stub
	if (!PrepareEscalation()) {
		PostMessage(hDlg, WM_CLOSE, 0, 0);
		return;
	}

	AutoHandle pipe(hPipe);
	HWND hwndList = GetDlgItem(hDlg, IDC_LIST_UPDATES);
	//create needed folders after escalating priviledges. Folders creates when we actually install updates
	TCHAR tszFileTemp[MAX_PATH], tszFileBack[MAX_PATH];
	mir_sntprintf(tszFileBack, SIZEOF(tszFileBack), _T("%s\\Backups"), tszRoot);
	SafeCreateDirectory(tszFileBack);
	mir_sntprintf(tszFileTemp, SIZEOF(tszFileTemp), _T("%s\\Temp"), tszRoot);
	SafeCreateDirectory(tszFileTemp); 

	// 2) Download all plugins
	HANDLE nlc = NULL;
	for (int i=0; i < todo.getCount(); i++) {
		ListView_EnsureVisible(hwndList, i, FALSE);
		if (!todo[i].bEnabled) {
			SetStringText(hwndList, i, TranslateT("Skipped."));
		}
		else if (todo[i].bDeleteOnly) {
			SetStringText(hwndList, i, TranslateT("Will be deleted!"));
		}
		else {
			// download update
			SetStringText(hwndList, i, TranslateT("Downloading..."));

			FILEURL *pFileUrl = &todo[i].File;
			if (!DownloadFile(pFileUrl, nlc)) {
				SetStringText(hwndList, i, TranslateT("Failed!"));

				// interrupt update as we require all components to be updated
				Netlib_CloseHandle(nlc);
				PostMessage(hDlg, UM_ERROR, 0, 0);
				SkinPlaySound("updatefailed");
				return;
			}
			SetStringText(hwndList, i, TranslateT("Succeeded."));
		}
	}
	Netlib_CloseHandle(nlc);

	// 3) Unpack all zips
	VARST tszMirandaPath(_T("%miranda_path%"));
	for (int i = 0; i < todo.getCount(); i++) {
		FILEINFO& p = todo[i];
		if (p.bEnabled) {
			if (p.bDeleteOnly) { 
				// we need only to backup the old file
				TCHAR *ptszRelPath = p.tszNewName + _tcslen(tszMirandaPath) + 1, tszBackFile[MAX_PATH];
				mir_sntprintf(tszBackFile, SIZEOF(tszBackFile), _T("%s\\%s"), tszFileBack, ptszRelPath);
				BackupFile(p.tszNewName, tszBackFile);
			}
			else {
				// if file name differs, we also need to backup the old file here
				// otherwise it would be replaced by unzip
				if ( _tcsicmp(p.tszOldName, p.tszNewName)) {
					TCHAR tszSrcPath[MAX_PATH], tszBackFile[MAX_PATH];
					mir_sntprintf(tszSrcPath, SIZEOF(tszSrcPath), _T("%s\\%s"), tszMirandaPath, p.tszOldName);
					mir_sntprintf(tszBackFile, SIZEOF(tszBackFile), _T("%s\\%s"), tszFileBack, p.tszOldName);
					BackupFile(tszSrcPath, tszBackFile);
				}

				if ( unzip(p.File.tszDiskPath, tszMirandaPath, tszFileBack,true))
					SafeDeleteFile(p.File.tszDiskPath);  // remove .zip after successful update
			}
		}
	}
	SkinPlaySound("updatecompleted");

#if MIRANDA_VER < 0x0A00
	// 4) Change title of clist
	ptrT title = db_get_tsa(NULL, "CList", "TitleText");
	if (!_tcsicmp(title, _T("Miranda IM")))
		db_set_ts(NULL, "CList", "TitleText", _T("Miranda NG"));
#endif

	opts.bForceRedownload = false;
	db_unset(NULL, MODNAME, DB_SETTING_REDOWNLOAD);

	db_set_b(NULL, MODNAME, DB_SETTING_RESTART_COUNT, 5);

	// 5) Prepare Restart
	int rc = MessageBox(hDlg, TranslateT("Update complete. Press Yes to restart Miranda now or No to postpone a restart until the exit."), TranslateT("Plugin Updater"), MB_YESNO | MB_ICONQUESTION);
	PostMessage(hDlg, WM_CLOSE, 0, 0);
	if (rc == IDYES)
#if MIRANDA_VER >= 0x0A00
		CallServiceSync(MS_SYSTEM_RESTART, db_get_b(NULL, MODNAME, "RestartCurrentProfile", 1) ? 1 : 0, 0);
#else
		CallFunctionAsync(RestartMe, 0);
#endif
}
Exemplo n.º 4
0
static void DlgUpdateSilent(void *lParam)
{
	OBJLIST<FILEINFO> &UpdateFiles = *(OBJLIST<FILEINFO> *)lParam;
	if (UpdateFiles.getCount() == 0) {
		delete &UpdateFiles;
		return;
	}

	// 1) If we need to escalate priviledges, launch a stub
	if (!PrepareEscalation()) {
		delete &UpdateFiles;
		return;
	}

	AutoHandle pipe(hPipe);
	//create needed folders after escalating priviledges. Folders creates when we actually install updates
	TCHAR tszFileTemp[MAX_PATH], tszFileBack[MAX_PATH];

	mir_sntprintf(tszFileBack, SIZEOF(tszFileBack), _T("%s\\Backups"), tszRoot);
	SafeCreateDirectory(tszFileBack);

	mir_sntprintf(tszFileTemp, SIZEOF(tszFileTemp), _T("%s\\Temp"), tszRoot);
	SafeCreateDirectory(tszFileTemp);

	// 2) Download all plugins
	HANDLE nlc = NULL;
	// Count all updates that have been enabled
	int count = 0;
	for (int i = 0; i < UpdateFiles.getCount(); i++) {
		if (UpdateFiles[i].bEnabled && !UpdateFiles[i].bDeleteOnly) {
			// download update
			FILEURL *pFileUrl = &UpdateFiles[i].File;
			if (!DownloadFile(pFileUrl, nlc)) {
				// interrupt update as we require all components to be updated
				Netlib_CloseHandle(nlc);
				SkinPlaySound("updatefailed");
				delete &UpdateFiles;
				return;
			}
			count++;
		}

	}
	Netlib_CloseHandle(nlc);

	// All available updates have been disabled
	if (count == 0) {
		delete &UpdateFiles;
		return;
	}

	// 3) Unpack all zips
	VARST tszMirandaPath(_T("%miranda_path%"));
	for (int i = 0; i < UpdateFiles.getCount(); i++) {
		FILEINFO& p = UpdateFiles[i];
		if (p.bEnabled) {
			if (p.bDeleteOnly) {
				// we need only to backup the old file
				TCHAR *ptszRelPath = p.tszNewName + _tcslen(tszMirandaPath) + 1, tszBackFile[MAX_PATH];
				mir_sntprintf(tszBackFile, SIZEOF(tszBackFile), _T("%s\\%s"), tszFileBack, ptszRelPath);
				BackupFile(p.tszNewName, tszBackFile);
			}
			else {
				// if file name differs, we also need to backup the old file here
				// otherwise it would be replaced by unzip
				if (_tcsicmp(p.tszOldName, p.tszNewName)) {
					TCHAR tszSrcPath[MAX_PATH], tszBackFile[MAX_PATH];
					mir_sntprintf(tszSrcPath, SIZEOF(tszSrcPath), _T("%s\\%s"), tszMirandaPath, p.tszOldName);
					mir_sntprintf(tszBackFile, SIZEOF(tszBackFile), _T("%s\\%s"), tszFileBack, p.tszOldName);
					BackupFile(tszSrcPath, tszBackFile);
				}
				
				// remove .zip after successful update
				if (unzip(p.File.tszDiskPath, tszMirandaPath, tszFileBack, true))
					SafeDeleteFile(p.File.tszDiskPath);
			}
		}
	}
	delete &UpdateFiles;
	SkinPlaySound("updatecompleted");

#if MIRANDA_VER < 0x0A00
	// 4) Change title of clist
	ptrT title = db_get_tsa(NULL, "CList", "TitleText");
	if (!_tcsicmp(title, _T("Miranda IM")))
		db_set_ts(NULL, "CList", "TitleText", _T("Miranda NG"));
#endif

	opts.bForceRedownload = false;
	db_unset(NULL, MODNAME, DB_SETTING_REDOWNLOAD);

	db_set_b(NULL, MODNAME, DB_SETTING_RESTART_COUNT, 5);
	db_set_b(NULL, MODNAME, DB_SETTING_NEED_RESTART, 1);

	// 5) Prepare Restart
	TCHAR tszTitle[100];
	mir_sntprintf(tszTitle, SIZEOF(tszTitle), TranslateT("%d component(s) was updated"), count);		

	if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1)) {
		ShowPopup(tszTitle,TranslateT("You need to restart your Miranda to apply installed updates."),POPUP_TYPE_MSG);
	} else {
		bool notified = false;

		if (ServiceExists(MS_CLIST_SYSTRAY_NOTIFY)) {
			MIRANDASYSTRAYNOTIFY err;
			err.szProto = MODULEA;
			err.cbSize = sizeof(err);
			err.dwInfoFlags = NIIF_INTERN_UNICODE | NIIF_INFO;
			err.tszInfoTitle = tszTitle;
			err.tszInfo = TranslateT("You need to restart your Miranda to apply installed updates.");
			err.uTimeout = 30000;

			notified = !CallService(MS_CLIST_SYSTRAY_NOTIFY, 0, (LPARAM)&err);
		}
			
		if (!notified) {
			// Error, let's try to show MessageBox as last way to inform user about successful update
			TCHAR tszText[200];
			mir_sntprintf(tszText, SIZEOF(tszText), _T("%s\n\n%s"), TranslateT("You need to restart your Miranda to apply installed updates."), TranslateT("Would you like to restart it now?"));

			if (MessageBox(NULL, tszText, tszTitle, MB_ICONINFORMATION | MB_YESNO) == IDYES)
#if MIRANDA_VER >= 0x0A00
				CallServiceSync(MS_SYSTEM_RESTART, db_get_b(NULL, MODNAME, "RestartCurrentProfile", 1) ? 1 : 0, 0);
#else
				CallFunctionAsync(RestartMe, 0);
#endif
		}
	}
}
Exemplo n.º 5
0
static void ApplyDownloads(void *param)
{
	HWND hDlg = (HWND)param;

	//////////////////////////////////////////////////////////////////////////////////////
	// if we need to escalate priviledges, launch a atub

	if (!PrepareEscalation()) {
		DestroyWindow(hDlg);
		return;
	}

	//////////////////////////////////////////////////////////////////////////////////////
	// ok, let's unpack all zips

	AutoHandle pipe(hPipe);
	HWND hwndList = GetDlgItem(hDlg, IDC_LIST_UPDATES);
	OBJLIST<FILEINFO> &todo = *(OBJLIST<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
	TCHAR tszBuff[2048], tszFileTemp[MAX_PATH], tszFileBack[MAX_PATH];

	mir_sntprintf(tszFileBack, SIZEOF(tszFileBack), _T("%s\\Backups"), tszRoot);
	SafeCreateDirectory(tszFileBack);

	mir_sntprintf(tszFileTemp, SIZEOF(tszFileTemp), _T("%s\\Temp"), tszRoot);
	SafeCreateDirectory(tszFileTemp);

	HANDLE nlc = NULL;
	for (int i=0; i < todo.getCount(); ++i) {
		ListView_EnsureVisible(hwndList, i, FALSE);
		if (!todo[i].bEnabled) {
			ListView_SetItemText(hwndList, i, 2, TranslateT("Skipped."));
			continue;
		}

		// download update
		ListView_SetItemText(hwndList, i, 2, TranslateT("Downloading..."));

		FILEURL *pFileUrl = &todo[i].File;
		if (!DownloadFile(pFileUrl->tszDownloadURL, pFileUrl->tszDiskPath, pFileUrl->CRCsum, nlc)) {
			ListView_SetItemText(hwndList, i, 2, TranslateT("Failed!"));
		}
		else
			ListView_SetItemText(hwndList, i, 2, TranslateT("Succeeded."));
	}
	Netlib_CloseHandle(nlc);

	if (todo.getCount() > 0) {
		ShowPopup(0, LPGENT("Plugin Updater"), TranslateT("Download complete"), 2, 0);

		TCHAR *tszMirandaPath = Utils_ReplaceVarsT(_T("%miranda_path%"));

		for (int i = 0; i < todo.getCount(); i++) {
			if (!todo[i].bEnabled)
				continue;

			TCHAR tszBackFile[MAX_PATH];
			FILEINFO& p = todo[i];
			if (p.bDeleteOnly) { // we need only to backup the old file
				TCHAR *ptszRelPath = p.tszNewName + _tcslen(tszMirandaPath) + 1;
				mir_sntprintf(tszBackFile, SIZEOF(tszBackFile), _T("%s\\%s"), tszFileBack, ptszRelPath);
				BackupFile(p.tszNewName, tszBackFile);
				continue;
			}

			// if file name differs, we also need to backup the old file here
			// otherwise it would be replaced by unzip
			if ( _tcsicmp(p.tszOldName, p.tszNewName)) {
				TCHAR tszSrcPath[MAX_PATH];
				mir_sntprintf(tszSrcPath, SIZEOF(tszSrcPath), _T("%s\\%s"), tszMirandaPath, p.tszOldName);
				mir_sntprintf(tszBackFile, SIZEOF(tszBackFile), _T("%s\\%s"), tszFileBack, p.tszOldName);
				BackupFile(tszSrcPath, tszBackFile);
			}

			if ( unzip(p.File.tszDiskPath, tszMirandaPath, tszFileBack,false))
				SafeDeleteFile(p.File.tszDiskPath);  // remove .zip after successful update
		}
	}

	PopupDataText temp;
	temp.Title = TranslateT("Plugin Updater");
	temp.Text = tszBuff;
	lstrcpyn(tszBuff, TranslateT("Download complete. Do you want to go to plugins option page?"), SIZEOF(tszBuff));
	int rc = MessageBox(hDlg, temp.Text, temp.Title, MB_YESNO | MB_ICONQUESTION);
	if (rc == IDYES)
		CallFunctionAsync(OpenPluginOptions, 0);

	CloseWindow(hDlg);
	DestroyWindow(hDlg);
	hwndDialog = NULL;
	return;
}
Exemplo n.º 6
0
BOOL CCheckRuleXMLParse::Save(const CString &strFilePath, const CheckRuleArray &arrCheckRuleList)
{
	// 删除老版本生成的未加密xml
	CString strOldXmlPath = strFilePath;
	strOldXmlPath.Replace(L".bpxml", L"xml");
	if (IsFileExist(strOldXmlPath))
		SafeDeleteFile(strOldXmlPath);

	// 删除新版本生成的加密bpxml
	if (IsFileExist(strFilePath))
		SafeDeleteFile(strFilePath);

	BOOL bResult = TRUE;

	// 初始化
	Init();

	// 创建xml文件
	if (!m_pXMLDocument->CreateDocument(L"CheckRule"))
		bResult = FALSE;

	// 存储数据
	if (bResult)
	{
		IBpXMLNode* pRootNode = m_pXMLDocument->GetRootElement();
		pRootNode->SetAttribute(L"version", L"1.1");
		DestroyXMLNode(pRootNode);
		CString strValue;	
		for (int i=0; i<arrCheckRuleList.GetSize(); i++)
		{
			IBpXMLNode* pRuleNode = m_pXMLDocument->CreateElementNode(L"node");
			IBpXMLNode* pChildNode = NULL;
			if (pRuleNode != NULL)
			{
				strValue.Format(L"%d", arrCheckRuleList[i].nID);
				pRuleNode->SetAttribute(L"id", strValue);
				strValue.Format(L"%d", arrCheckRuleList[i].nRuleType);
				pRuleNode->SetAttribute(L"ruletype", strValue);
				pChildNode = pRuleNode->AppendNewElementChild(L"ruledesc");
				pChildNode->SetText(arrCheckRuleList[i].strRuleDesc);
				DestroyXMLNode(pChildNode);
				pChildNode = pRuleNode->AppendNewElementChild(L"rulename");
				pChildNode->SetText(arrCheckRuleList[i].strRuleName);
				DestroyXMLNode(pChildNode);
				pChildNode = pRuleNode->AppendNewElementChild(L"rulecontent");

				for (int j=0; j<arrCheckRuleList[i].arrRuleContent.GetCount(); j++)
				{
					strValue.Format(L"rc%d", j);
					pChildNode->SetAttribute(strValue, arrCheckRuleList[i].arrRuleContent.GetAt(j));
				}
				DestroyXMLNode(pChildNode);
				pChildNode = pRuleNode->AppendNewElementChild(L"MdlFilter");
				strValue.Format(L"%d", arrCheckRuleList[i].dwMdlFilter);
				pChildNode->SetText(strValue);
				DestroyXMLNode(pChildNode);

				DestroyXMLNode(pRuleNode);
			}
		}
	}

	// 保存为临时xml文件
	CString strTempXMLFile;
	GetTempFile(strTempXMLFile, L"xml");
	m_pXMLDocument->SaveXML(strTempXMLFile);

	// xml文件加密
	bResult = EncodeFileEx(strTempXMLFile, strFilePath);
	SafeDeleteFile(strTempXMLFile);

	// 释放资源
	Uninit();
	return bResult;
}