⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 updatermakerdlg.cpp

📁 QT写的自动更新程序 自认为不错 请大家参考
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	//		修改xml文件,记录安装信息
	ofile<<_T("Function .onInstSuccess")<<endl;
	
	strLine.Format(_T("	strcpy $UpdateTime \"%s\""),strTime);
		
	ofile<<(LPCSTR)strLine<<endl;
	ofile<<_T("	${xml::CreateNode} '<Pack filename=\"${FileName}.exe\" appendkey=${KeyType} publishtime=$UpdateTime info=${INFOMATION}  name=${PathName} />' $1")<<endl;
	ofile<<_T("	${xml::GetNodeValue} $2")<<endl;
	ofile<<_T("	strcmp $2 \"Pack\" Equal 0")<<endl;
	ofile<<_T("	${xml::InsertEndChild} $1 $2")<<endl;
	ofile<<_T("	Goto +2")<<endl;
	ofile<<_T("Equal:")<<endl;
	ofile<<_T("	${xml::InsertBeforeNode} $1 $2")<<endl;
	ofile<<_T("	${xml::GotoHandle} $XMLHandle $2")<<endl;
	ofile<<_T("	${xml::GetAttribute} \"LastDate\" $1 $2")<<endl;
	ofile<<_T("	strcmp $2 0 exist notexist")<<endl;
	ofile<<_T("notexist:")<<endl;
	ofile<<_T("	${xml::SetAttribute} \"LastDate\" $UpdateTime $2")<<endl;
	ofile<<_T("	Goto SAVEFILE")<<endl;
	ofile<<_T("exist:")<<endl;
	ofile<<_T("	IntCmp $1 $UpdateTime 0 0 SAVEFILE")<<endl;
	ofile<<_T("	${xml::SetAttribute} \"LastDate\" $UpdateTime $2")<<endl;
	ofile<<_T("SAVEFILE:")<<endl;
	ofile<<_T("	${xml::SaveFile} $XMLFile $1")<<endl;
	ofile<<_T("FunctionEnd")<<endl;

	//退出的时候关闭xml文件
	ofile<<_T("Function .onGUIEnd")<<endl;
	ofile<<_T("	${xml::Unload}")<<endl;
	ofile<<_T("FunctionEnd")<<endl;


	//Section "主程序" SEC01
	//////////////////////////////////////////////////////
	//安装部分
	//		暂时一个组件,以后扩展为n个部分,用户可以选择安装
	//////////////////////////////////
	//设置不同就覆盖模式
	ofile<<_T("SetOverwrite ifdiff")<<endl;

	std::list<GroupList>::iterator iterGroup=m_FilesInfo.begin();
	int FileIndex=1,FileCount=0;
	for (;iterGroup!=m_FilesInfo.end();iterGroup++)
	{
		FileCount+=(int)iterGroup->Files.size();
	}
	if (FileCount==0)
	{
		MessageBox("没有文件。");
		return;
	}
	strEdit=_T("");//记录上个文件所要拷贝的路径
	iterGroup=m_FilesInfo.begin();
	for (int i=1;iterGroup!=m_FilesInfo.end();iterGroup++,i++)
	{
		strLine.Format(_T("Section \"%s\" SEC%d%d"),iterGroup->GroupName,i/10,i%10);
		ofile<<(LPCSTR)strLine<<endl;
		std::list<FileInfo>::iterator iterFile=iterGroup->Files.begin();
		for(;iterFile!=iterGroup->Files.end();iterFile++)
		{
			if (iterFile->Directory!=strEdit)
			{
				strLine.Format(_T("SetOutPath \"%s\""),iterFile->Directory);
				ofile<<(LPCSTR)strLine<<endl;
				strEdit=iterFile->Directory;
			}
			strLine.Format(_T("File \"%s\""),iterFile->FileName);
			ofile<<(LPCSTR)strLine<<endl;

			strLine.Format(_T("NsisTestDll::Test \"@%d#%d@\""),FileCount,FileIndex++);
			ofile<<(LPCSTR)strLine<<endl;
		}
	}
	ofile<<_T("SectionEnd")<<endl;
	ofile.close();

	MessageBox("完成");
	ShellExecute(NULL,"OPEN","C:\\Program Files\\NSIS\\makensis.exe","\""+strTempNSI+"\"",
		NULL,   SW_SHOWNORMAL);

	strFileName.Delete(strFileName.GetLength()-4,4);
	strFileName+=_T(".txt");
	ofile.open(strFileName);
	m_Edit_PathName.GetWindowText(strLine);//显示名称
	ofile<<(LPCSTR)strLine<<endl;

	ofile<<(LPCSTR)strTime<<endl;//发布时间

	int bCheck=m_Check_bWizard.GetCheck();
	ofile<<bCheck<<endl;//安装过程中显示界面

	bCheck=m_Check_UpdataSelf.GetCheck();
	ofile<<bCheck<<endl;//安装过程中显示界面

	if(TRUE==IsDlgButtonChecked(IDC_RADIO1))
	{ofile<<0<<endl;}
	else
	{ofile<<1<<endl;}

	//m_Edit_Intro.GetWindowText(strLine);
	ofile<<(LPCSTR)GetIntroStr()/*strLine*/<<endl;
	ofile.close();
}

void CUpdaterMakerDlg::OnBUTTONNext() 
{
	// TODO: Add your control notification handler code here
	GetDlgItem(IDC_STATIC_FileName)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_EDIT_FileName)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_STATIC_PathName)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_EDIT_PathName)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_STATIC_SoftName)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_COMBO_SoftName)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_STATIC_Intro)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_EDIT_Intro)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_BUTTON_Browse)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_BUTTON_Next)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_CHECK_BWizard)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_CHECK_UpdataSelf)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_BUTTON_Load)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_RADIO1)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_RADIO2)->ShowWindow(SW_HIDE);
	
	GetDlgItem(IDC_BUTTON_AddDir)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_BUTTON_Previous)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_BUTTON_Make1)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_BUTTON_AddGroup)->ShowWindow(SW_SHOW);	
	GetDlgItem(IDC_BUTTON_DelGroup)->ShowWindow(SW_SHOW);	
	GetDlgItem(IDC_BUTTON_ModGroup)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_BUTTON_AddFiles)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_BUTTON_DelFiles)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_BUTTON_ModFile)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_LIST_Group)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_LIST_Files)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_BUTTON_Make1)->ShowWindow(SW_SHOW);
}

void CUpdaterMakerDlg::OnBUTTONPrevious() 
{
	// TODO: Add your control notification handler code here
	GetDlgItem(IDC_STATIC_FileName)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_EDIT_FileName)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_STATIC_PathName)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_EDIT_PathName)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_STATIC_SoftName)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_COMBO_SoftName)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_STATIC_Intro)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_EDIT_Intro)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_BUTTON_Browse)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_BUTTON_Next)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_CHECK_BWizard)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_CHECK_UpdataSelf)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_BUTTON_Load)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_RADIO1)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_RADIO2)->ShowWindow(SW_SHOW);

	
	GetDlgItem(IDC_BUTTON_AddDir)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_BUTTON_Previous)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_BUTTON_Make1)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_BUTTON_AddGroup)->ShowWindow(SW_HIDE);	
	GetDlgItem(IDC_BUTTON_DelGroup)->ShowWindow(SW_HIDE);	
	GetDlgItem(IDC_BUTTON_ModGroup)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_BUTTON_AddFiles)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_BUTTON_DelFiles)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_BUTTON_ModFile)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_LIST_Group)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_LIST_Files)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_BUTTON_Make1)->ShowWindow(SW_HIDE);
}

void CUpdaterMakerDlg::OnSelchangeLISTGroup() 
{
	// TODO: Add your control notification handler code here
	int index=m_List_Group.GetCurSel();
	CString str;
	m_List_Group.GetText(index,str);
	if (m_iterFiles->GroupName==str )return;
	m_iterFiles=m_FilesInfo.begin();
	for (;m_iterFiles!=m_FilesInfo.end();m_iterFiles++)
	{
		if (m_iterFiles->GroupName==str)
		{
			UpdataListCtrl();
			return;
		}
	}
}

void CUpdaterMakerDlg::OnBUTTONAddGroup() 
{
	// TODO: Add your control notification handler code here
	CDlgAddGroup dlg;
	if (dlg.DoModal()==IDOK)
	{
		int i;
		if(0<=m_List_Group.FindString(0,dlg.m_Edit_Name))
		{
			MessageBox("此组已经添加过了!");
			return;
		}
		m_List_Group.AddString(dlg.m_Edit_Name);
		//m_List_Group.SetCurSel()
		i=m_List_Group.SelectString(0,dlg.m_Edit_Name);
		GroupList gl;
		gl.GroupName=dlg.m_Edit_Name;
		gl.Files.clear();
		m_FilesInfo.push_back(gl);
		m_List_Files.DeleteAllItems();
		m_iterFiles=m_FilesInfo.end();
		m_iterFiles--;
	}
}
void CUpdaterMakerDlg::UpdataListCtrl()
{
	m_List_Files.DeleteAllItems();
	std::list<FileInfo>::iterator iter=m_iterFiles->Files.begin();
	for (int i=0;iter!=m_iterFiles->Files.end();iter++,i++)
	{
		m_List_Files.InsertItem(i,iter->FileName);
		m_List_Files.SetItemText(i,1,iter->Directory);   
	}
}
void CUpdaterMakerDlg::OnBUTTONDelGroup() 
{
	// TODO: Add your control notification handler code here
	int index=m_List_Group.GetCurSel();
	CString strName;
	m_List_Group.GetText(index,strName);
	std::list<GroupList>::iterator iter=m_FilesInfo.begin();
	for (;iter!=m_FilesInfo.end();iter++)
	{
		if (iter->GroupName==strName)
		{
			iter=m_FilesInfo.erase(iter);
			break;
		}
	}
	m_List_Group.DeleteString(index);
	if (index>=m_List_Group.GetCount())
	{
		index=m_List_Group.GetCount()-1;
	}
	m_List_Group.SetCurSel(index);
	m_List_Group.GetText(index,strName);

	m_iterFiles=m_FilesInfo.begin();
	for (;m_iterFiles!=m_FilesInfo.end();m_iterFiles++)
	{
		if (m_iterFiles->GroupName==strName)
		{
			break;
		}
	}
	UpdataListCtrl();
	
}

void CUpdaterMakerDlg::OnBUTTONModGroup() 
{
	// TODO: Add your control notification handler code here
	CDlgAddGroup dlg;
	if(m_List_Group.GetCurSel()<0)
	{
		MessageBox("请选中一个已存在的组!");
		return;
	}
	m_List_Group.GetText(m_List_Group.GetCurSel(),dlg.m_Edit_Name);
	if (dlg.DoModal()==IDOK)
	{
		int	index=m_List_Group.GetCurSel();
		m_List_Group.InsertString(m_List_Group.GetCurSel(),dlg.m_Edit_Name);
		m_List_Group.DeleteString(m_List_Group.GetCurSel());
		m_List_Group.SetCurSel(index);
	}
}

void CUpdaterMakerDlg::OnBUTTONAddFiles() 
{
	// TODO: Add your control notification handler code here
	CDlgAddFile dlg;
	if (dlg.DoModal()==IDOK)
	{
		int index=m_List_Files.GetItemCount();
		m_List_Files.InsertItem(index,dlg.strFile);
		m_List_Files.SetItemText(index,1,dlg.strDir); 
		FileInfo fi;
		fi.FileName=dlg.strFile;
		fi.Directory=dlg.strDir;
		m_iterFiles->Files.push_back(fi);
	}
}
void CUpdaterMakerDlg::OnBUTTONAddDir() 
{
	// TODO: Add your control notification handler code here
	CDlgAddDir dlg;
	if (dlg.DoModal()==IDOK)
	{
		AddFiles(dlg.strFile,dlg.strDir);
		//UpdataListCtrl();
	}
}

void CUpdaterMakerDlg::OnBUTTONDelFiles() 
{
	// TODO: Add your control notification handler code here
	POSITION pos=m_List_Files.GetFirstSelectedItemPosition();  
	std::vector<int> index;
	int i;
	index.resize(m_List_Files.GetSelectedCount());
	for (i=0;i<(int)index.size();i++)
	{
		index[i]=m_List_Files.GetNextSelectedItem(pos);
	}
	for (i=index.size()-1;i>=0;i--)
	{
		m_List_Files.DeleteItem(index[i]);
	}
	UpdataListFiles();
}

void CUpdaterMakerDlg::OnBUTTONModFile() 
{
	// TODO: Add your control notification handler code here
	if (m_List_Files.GetSelectedCount()!=1)
	{
		MessageBox("请选择一个文件!");
		return;
	}
	POSITION pos=m_List_Files.GetFirstSelectedItemPosition();
	int index=m_List_Files.GetNextSelectedItem(pos);
	
	CDlgAddFile dlg;
	dlg.strFile=m_List_Files.GetItemText(index,0);
	dlg.strDir=m_List_Files.GetItemText(index,1);
	if (dlg.DoModal()==IDOK)
	{
		m_List_Files.SetItemText(index,0,dlg.strFile);
		m_List_Files.SetItemText(index,1,dlg.strDir);
		UpdataListFiles();
	}
}

void CUpdaterMakerDlg::OnBUTTONBrowse() 
{
	// TODO: Add your control notification handler code here
	CFileDialog dlg(FALSE,_T("*.exe|"),NULL,OFN_OVERWRITEPROMPT,_T("EXE Files (*.exe)|*.exe||"));
	dlg.DoModal();
	m_Edit_FileName.SetWindowText(dlg.GetPathName());
}

//从ListCtrl中更新list中的内容
void CUpdaterMakerDlg::UpdataListFiles()
{
	m_iterFiles->Files.clear();
	for (int index=0;index<m_List_Files.GetItemCount();index++)
	{
		FileInfo fi;
		fi.FileName=m_List_Files.GetItemText(index,0);
		fi.Directory=m_List_Files.GetItemText(index,1);
		m_iterFiles->Files.push_back(fi);
	}
}



void CUpdaterMakerDlg::AddFiles(CString FromDir, CString ToDir)
{
	CFileFind finder;
	CString m_strCurrentDirectory=FromDir;
	m_strCurrentDirectory += "\\*.*";
	
	BOOL bWorking = finder.FindFile( m_strCurrentDirectory );
	while( bWorking )
	{
		bWorking = finder.FindNextFile();
		if( finder.IsDots())
		{
			continue;
		}else if (finder.IsDirectory())
		{
			AddFiles(FromDir+"\\"+finder.GetFileName(),ToDir+"\\"+finder.GetFileName());
		}else{
			//FromDir;
			int index=m_List_Files.GetItemCount();
			m_List_Files.InsertItem(index,FromDir+"\\"+finder.GetFileName());
			m_List_Files.SetItemText(index,1,ToDir); 
			FileInfo fi;
			fi.FileName=FromDir+"\\"+finder.GetFileName();
			fi.Directory=ToDir;
			m_iterFiles->Files.push_back(fi);
		}
	}
	finder.Close();
}

void CUpdaterMakerDlg::OnBUTTONLoad() 
{
	// TODO: Add your control notification handler code here
	CFileDialog dlg(TRUE);
	dlg.DoModal();
	CFile file(dlg.GetPathName(),CFile::modeRead|CFile::typeBinary);
	DWORD fileLength=file.GetLength();
	char* fcontent=new char[fileLength];
	file.Read(fcontent,fileLength);
	CString strFile(fcontent,fileLength);
	m_Edit_Intro.SetWindowText(strFile);
}

CString CUpdaterMakerDlg::GetIntroStr()
{
	CString strEdit;
	m_Edit_Intro.GetWindowText(strEdit);

	UINT pos;
	pos=0;
	strEdit+=_T(" ");
	while(pos!=strEdit.GetLength())
	{
		char c=strEdit.GetAt(pos);
		if (c=='\n'||c=='\r')
		{
			strEdit.Delete(pos);
			continue;
		}
		if (c=='\"')
		{
			strEdit.Delete(pos);
			strEdit.Insert(pos,_T("&quot; "));
			pos+=6;
		}
		else if (c=='\'')
		{
			strEdit.Delete(pos);
			strEdit.Insert(pos,_T("&apos; "));
			pos+=6;
		}
		else if (c=='$')
		{
			strEdit.Insert(pos,_T("$"));
			pos++;
		}
		else if (c=='<')
		{
			strEdit.Delete(pos);
			strEdit.Insert(pos,_T("&lt; "));
			pos+=4;
		}
		else if (c=='>')
		{
			strEdit.Delete(pos);
			strEdit.Insert(pos,_T("&gt; "));
			pos+=4;
		}
		pos++;
	}
	return strEdit;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -