copy toc去插件安装是什么意思安装程序

安装包设计-------安装(QT)---------知识总结
时间: 17:57:28
&&&& 阅读:86
&&&& 评论:
&&&& 收藏:0
标签:&&&&&&&&&&&&&&&&&&&&&&&&&&&1、判断文件是否存在
QFile file(path);
file.exists();
2、复制文件
bool copy(const QString &fileName, const QString &newName);
3、建立快捷方式
/*& GetShorCutPath && 该函数得到计算机特定位置的路径 && nFolder 表示位置标示,可取 &&
CSIDL_BITBUCKET&&&&&&&&&&&&&&&&&&& 回收站 &&
CSIDL_CONTROLS&&&&&&&&&&&&&&&&&&& 控制面板 &&
CSIDL_DESKTOP&&&&&&&&&&&&&&&&&&&&& Windows桌面 &&
CSIDL_DESKTOPDIRECTORY&& desktop的目录; &&
CSIDL_DRIVES&&&&&&&&&&&&&&&&&&&&&&&&&&& 我的电脑 &&
CSIDL_FONTS&&&&&&&&&&&&&&&&&&&&&&&&&&&& 字体目录 &&
CSIDL_NETHOOD&&&&&&&&&&&&&&&&&&&&&& 网上邻居 &&
CSIDL_NETWORK&&&&&&&&&&&&&&&&&&&&&& 网上邻居virtual folder &&
CSIDL_PERSONAL&&&&&&&&&&&&&&&&&&&&& 我的文档 &&
CSIDL_PRINTERS&&&&&&&&&&&&&&&&&&&&&&& 打印机
CSIDL_PROGRAMS&&&&&&&&&&&&&&&&&&& 程序组 &&
CSIDL_RECENT&&&&&&&&&&&&&&&&&&&&&&&&& 最近打开文档 &&
CSIDL_SENDTO&&&&&&&&&&&&&&&&&&&&&&&&& 发送到菜单项
CSIDL_STARTMENU&&&&&&&&&&&&&&&&&&& 快启菜单
CSIDL_STARTUP&&&&&&&&&&&&&&&&&&&&&&&& 启动目录
CSIDL_TEMPLATES&&&&&&&&&&&&&&&&&&&& 临时文档
shortcutName += ".lnk";
QString temppath = "";
GetShorCutPath(temppath,CSIDL_STARTMENU);
temppath += "/"+shortcutN
QFile::link(appPath,temppath);
void GetShorCutPath(QString &path,int nFolder)
LPITEMIDLIST
LPMALLOC pShellM
char szDir[<span style="color: #0]="";
char szDir2[<span style="color: #0]="";
if(SUCCEEDED(SHGetMalloc(&pShellMalloc)))
if(SUCCEEDED(SHGetSpecialFolderLocation(NULL,nFolder,&pidl)))
SHGetPathFromIDList(pidl,(LPWSTR)szDir);
pShellMalloc-&Free(pidl);
pShellMalloc-&Release();
//类型转换
char temp = szDir[<span style="color: #];
int start = <span style="color: #;
int start2 = <span style="color: #;
while(temp !=‘\0‘)
szDir2[start++] =
start2 += <span style="color: #;
temp = szDir[start2];
if (temp == ‘\\‘)
temp = ‘/‘;
szDir2[start] = ‘\0‘;
path = QString(szDir2);
4、开机启动程序
void MainWindow::autoStart(IniFile &inifile,const QString &appPath)
QString appN
appName = appPath.right(appPath.length()-appPath.lastIndexOf("/")-<span style="color: #);
inifile.readIni("AUTOSTART",flag);
if(flag == "true")
QSettings *reg = new QSettings("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Run",
QSettings::NativeFormat);
reg-&setValue(appName,appPath);
5、运行程序
&&&&&QProcess *process = new QP&&&&& //这个不加析构,不退出&&&&&process-&start(appPath);
6、删除目录及其下所有文件
void deleteDir(const QString &d)
QDir dir(d);
foreach (QFileInfo inf, dir.entryInfoList(QDir::Dirs|QDir::Files)) {
if(inf.isFile())
dir.remove(inf.absoluteFilePath());
else if(inf.isDir() &&
inf.fileName() != "." &&
inf.fileName() != "..")
deleteDir(inf.absolutePath()+"/"+inf.fileName());
dir.rmdir(dir.absolutePath());
/*************************************************************************************
SEFileInfo.cpp
James Spibey
04/08/1999
Implementation of the CSEFileInfo class
You are free to use, distribute or modify this code
as long as this header is not removed or modified.
*************************************************************************************/
#include "SEFileInfo.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
/*******************************************************************************
* Function: CSEFileInfo::CSEFileInfo
* Description:
Default Constructor
* Parameters:
*******************************************************************************/
CSEFileInfo::CSEFileInfo()
/*******************************************************************************
* Function: CSEFileInfo::~CSEFileInfo
* Description:
Destructor
* Parameters:
*******************************************************************************/
CSEFileInfo::~CSEFileInfo()
/*******************************************************************************
* Function: CSEFileInfo::Reset
* Description:
Reset the class data members
* Parameters:
*******************************************************************************/
void CSEFileInfo::Reset()
m_nSize = <span style="color: #;
m_strPathname = "";
m_strFilename = "";
/*************************************************************************************
SelfExtracter.cpp
James Spibey
04/08/1999
Implementation of the CSelfExtracter class
You are free to use, distribute or modify this code
as long as this header is not removed or modified.
*************************************************************************************/
#include "Windows.h"
#include "SelfExtractor.h"
#include "QDebug"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#include "QFileDialog"
#include "QMessageBox"
#include "QDir"
#include "IniFile.h"
/*******************************************************************************
* Function: CSelfExtractor::CSelfExtractor
* Description:
Default Constructor
* Parameters:
*******************************************************************************/
CSelfExtractor::CSelfExtractor()
m_nFiles = <span style="color: #;
m_nTOCSize = <span style="color: #;
/*******************************************************************************
* Function: CSelfExtractor::~CSelfExtractor
* Description:
Destructor
* Parameters:
*******************************************************************************/
CSelfExtractor::~CSelfExtractor()
/*******************************************************************************
* Function: CSelfExtractor::ExtractAll
* Description:
Extract the current archive to the specified directory
* Parameters:
QString Dir: Destination Directory
funcPtr pFn:
Pointer to a user defined callback function
User defined data to pass to the callback function
int: Error Code
INPUT_FILE_ERROR
- Failed to open the input file
OUTPUT_FILE_ERROR
- Failed to create an output file
*******************************************************************************/
int CSelfExtractor::ExtractAll(QString Dir, funcPtr pFn /*= NULL*/, void * userData /*= NULL*/)
//如果用到这个,需要对getthisfilename做更改,如extract函数
//Make sure the directory name has a trailing backslash
EnsureTrailingBackSlash(Dir);
QFile Thisfile(GetThisFileName());
//Archive (Usually itself)
//qDebug()&&GetThisFileName();
//Read the Table of Contents
int res = ReadTOC(GetThisFileName());
if(res != SUCCESS)
//Open the archive
if(!Thisfile.open(QIODevice::ReadOnly))
return INPUT_FILE_ERROR;
//Get the files out in reverse order so we can work out the offsets
//Subtract 1 from the filecount as we are zero-based
for(int i = (m_nFiles - <span style="color: #); i &= <span style="color: # ; i--)
ExtractOne(&Thisfile, i, Dir);
//Do the callback
if(pFn != NULL)
pFn(static_cast&void*&(&m_InfoArray[i]), userData);
//Close the archive
Thisfile.close();
return SUCCESS;
/*******************************************************************************
* Function: CSelfExtractor::Extract
* Description:
Extract a single file from the current archive to the specified directory
* Parameters:
int index:
index in array of file
QString Dir:
Destination Directory
int: Error Code
INPUT_FILE_ERROR
- Failed to open the input file
OUTPUT_FILE_ERROR
- Failed to create an output file
*******************************************************************************/
int CSelfExtractor::Extract(int index, QString Dir,QString &appName)
//Make sure the directory name has a trailing backslash
EnsureTrailingBackSlash(Dir);
QFile Thisfile(appName);//Archive (Usually itself) //GetThisFileName()
//Read the Table of Contents
int res = ReadTOC(appName);
//GetThisFileName()
if(res != SUCCESS)
//Open the archive
if(!Thisfile.open(QIODevice::ReadOnly))
return INPUT_FILE_ERROR;
ExtractOne(&Thisfile, index, Dir);
//Close the archive
Thisfile.close();
return SUCCESS;
/*******************************************************************************
* Function: CSelfExtractor::ExtractOne
* Description:
Actual Data Extraction. Seeks to required offset in archive
and writes new file
* Parameters:
QFile* file:
Pointer to the archive
int index:
Index of file in array
QString Dir:
Destination Dir
int: Error Code
*******************************************************************************/
int CSelfExtractor::ExtractOne(QFile* file, int index, QString Dir)
char buffer[<span style="color: #00];
//Buffer to read and write with
QFile NewFile(Dir + m_InfoArray[index].GetFilename());
//Extracted File
//Get the file size (in bytes)
int FileSize = m_InfoArray[index].GetFileSize();
//Create the new file
if(!NewFile.open(QIODevice::WriteOnly))
return OUTPUT_FILE_ERROR;
//Seek to the correct Offset
file-&seek(m_InfoArray[index].GetFileOffset());
//Loop the data out from the archive
DWORD dwWritten = <span style="color: #;
DWORD dwRead = <span style="color: #;
int AmountToRead = <span style="color: #;
while(TRUE)
//Read out 1000 bytes at a time or the remainder if
//there is less than 1000 left. Exit if there is none left
AmountToRead = FileSize - dwW
if(AmountToRead & <span style="color: #00)
AmountToRead = <span style="color: #00;
else if(AmountToRead == <span style="color: #)
dwRead = file-&read(buffer, AmountToRead);
NewFile.write(buffer, dwRead);
dwWritten += dwR
//Close the output file
NewFile.close();
return SUCCESS;
/*******************************************************************************
* Function: CSelfExtractor::ReadTOC
* Description:
Read the archive‘s Table of Contents
* Parameters:
QString Filename: Filename of the archive (full path)
int: Error Code
*******************************************************************************/
int CSelfExtractor::ReadTOC(QString Filename)
QFile Thisfile(Filename);
//Archive file
char buffer[<span style="color: #00];
//Buffer to read and write with
//Clear the CSEFileInfo class array
//Open the archive
if(!Thisfile.open(QIODevice::ReadOnly))
return NO_SOURCE;
//Read in the signature
int filelen = Thisfile.size();
Thisfile.seek(filelen- static_cast&int&(strlen(SIGNATURE)));
Thisfile.read(buffer, strlen(SIGNATURE));
//Check that it matches
if(strncmp(buffer, SIGNATURE, strlen(SIGNATURE)) != <span style="color: #)
return INVALID_SIG;
//Read Number of files
int LastOffset = strlen(SIGNATURE) + static_cast&int&(sizeof(int));
Thisfile.seek(filelen-LastOffset);
Thisfile.read((char*)&m_nFiles, sizeof(int));
//If there are no files in the archive, there is nothing to extract
if(m_nFiles == <span style="color: #)
return NOTHING_TO_DO;
//Read the TOC in. The array is filled in reverse to ensure that it
//corresponds to the data segment
for(int i = (m_nFiles - <span style="color: #); i &= <span style="color: # ; i--)
= <span style="color: #;
int nOffset = <span style="color: #;
= <span style="color: #;
LastOffset += sizeof(int);
//Get Length of Pathname
Thisfile.seek(filelen-LastOffset);
Thisfile.read((char*)&len, sizeof(int));
LastOffset +=
//Get Path Name
Thisfile.seek(filelen-LastOffset);
Thisfile.read(buffer, len);
LastOffset += sizeof(int);
//Get File Size
Thisfile.seek(filelen-LastOffset);
Thisfile.read((char*)&nSize, sizeof(int));
LastOffset += sizeof(int);
//Get File Offset
Thisfile.seek(filelen-LastOffset);
Thisfile.read((char*)&nOffset, sizeof(int));
//Set the data in the array
m_InfoArray[i].SetSize(nSize);
QString Temp(buffer);
m_InfoArray[i].SetFilename(Temp.left(len));
m_InfoArray[i].SetOffset(nOffset);
//Record the total size of the TOC for use
//when extracting the data segment
m_nTOCSize = LastO
//Close the archive
Thisfile.close();
return SUCCESS;
/*******************************************************************************
* Function: CSelfExtractor::Reset
* Description:
Reset the CSEFileInfo Array
* Parameters:
*******************************************************************************/
void CSelfExtractor::Reset()
for(int i = <span style="color: #; i & MAX_FILES; i++)
m_InfoArray[i].Reset();
= <span style="color: #;
m_nTOCSize
= <span style="color: #;
/*******************************************************************************
* Function: CSelfExtractor::EnsureTrailingBackSlash
* Description:
Ensure that the string has a trailing backslash
* Parameters:
QString &string: Pathname
QString: Pathname
*******************************************************************************/
QString CSelfExtractor::EnsureTrailingBackSlash(QString &string)
int len = string.length();
if(!DIR.exists(string))
DIR.mkdir(string);
if(string[len - <span style="color: #] != ‘\\‘)
string += "/";
return string;
/*******************************************************************************
* Function: CSelfExtractor::GetThisFileName
* Description:
Get this executable‘s file path
* Parameters:
QString: Full Path for this executable
*******************************************************************************/
QString CSelfExtractor::GetThisFileName()
QString appN
IniFile iniFile("C:/DymindTemp/TempPath/qt.ini");
iniFile.readIni("AppTitle",appName);
path=dir.currentPath();
path +="/";
path += appName+".exe";
//改成install
//path += "INSTALL.exe" ;
showtext = "apppath =" ;
showtext +=
#include "zipimplement.h"
#include &direct.h&
#include &vector&
#include &xstring&
#include "QFileInfo"
#include &QDir&
#include &QByteArray&
#include "QFileInfoList"
#include &QFile&
#include "QDebug"
#include "QMessageBox"
CZipImplement::CZipImplement(void)
m_progress.total = <span style="color: #;
m_progress.current = <span style="color: #;
CZipImplement::~CZipImplement(void)
//解压文件到目录---------------------------------------------------------------------
BOOL CZipImplement::Zip_UnPackFiles(QString &mZipFileFullPath, QString& mUnPackPath,funcPtr function,void *userData)
//首先判断参数是否为空,为空则返回 false-------------------------------
if ((mUnPackPath == "") || (mZipFileFullPath == ""))
return FALSE ;
//判断文件时否是文件类型,如果不是返回 false-----------------------------
QFileInfo fileinfo(mZipFileFullPath);
if(!fileinfo.isFile())
return FALSE;
//如果解压缩的路径不存在 试图创建它,只能有一级目录没有创建-------------
QString tZipFilePath = mUnPackP
FolderExist(tZipFilePath);
tZipFilePath += "/";
//打开ZIP文件----------------------------------------------------------
QByteArray ba = mZipFileFullPath.toLocal8Bit();
//Qstring 转换成char *
filechar = ba.data();
zFile=unzOpen(filechar);
if(zFile == <span style="color: #)
return FALSE;
unz_global_
unz_file_info
if (unzGetGlobalInfo(zFile, &gi ) == UNZ_OK )
m_progress.total = gi.number_
for ( unsigned int i = <span style="color: #; i & gi.number_ ++i )
m_progress.current =
char file[<span style="color: #6]
= { <span style="color: # };
char ext[<span style="color: #6]
= { <span style="color: # };
char com[<span style="color: #24]
= { <span style="color: # };
if ( unzGetCurrentFileInfo( zFile, &FileInfo, file, sizeof(file), ext, <span style="color: #6, com, <span style="color: #24 ) != UNZ_OK )
return FALSE;
if( !( FileInfo.external_fa & FILE_ATTRIBUTE_DIRECTORY ) ) //文件,否则为目录
unzOpenCurrentFile(zFile);
char data[<span style="color: #24] = { <span style="color: # };
QString path = tZipFilePath +
FolderExist(path);
QFile File(path);
File.open( QIODevice::WriteOnly);
while(true)
size= unzReadCurrentFile(zFile,data,sizeof(data));
if(size &= <span style="color: #)
File.write(data, size);
File.close();
unzCloseCurrentFile(zFile);
if( i & gi.number_entry - <span style="color: # && unzGoToNextFile( zFile ) != UNZ_OK )
return FALSE;
unzClose(zFile);
if(function !=NULL)
function(static_cast&void*&(&m_progress),userData);
return FALSE;
return TRUE;
void CZipImplement::FolderExist(QString& strPath)
//判定最后一级目录是否存在,如果不存在则创建目录
QDir *dir = new QD
int index = <span style="color: #;
//首先判断是否为文件路径
if(strPath.contains("."))
index = strPath.lastIndexOf("/");
index = strPath.length();
QString str = strPath.left(index);
if(!dir-&exists(str))
dir-&mkdir(str);
dir = NULL;
#pragma once
#include "zip.h"
#include "unzip.h"
#include &QString&
struct ProGress
typedef void (*funcPtr)(void *,void*);
class CZipImplement
CZipImplement(void);
~CZipImplement(void);
unzFile zF
//Zip文件句柄
//***************************************************
//函数功能:解压zip文件到目录下
//参数定义:mZipFileFullPath ---zip文件绝对路径,mUnPackPath--- 输出文件目录
//***************************************************
BOOL Zip_UnPackFiles(QString &mZipFileFullPath, QString& mUnPackPath,funcPtr function = NULL,void *userData = NULL);
//***************************************************
//函数功能:判断目录是否存在,如不存在创建目录
//参数定义:strPath-----目录路径
//***************************************************
void FolderExist(QString& strPath);
ProGress m_
/*************************************************************************************
SelfExtracter.h
James Spibey
Specification of the CSelfExtracter class
This code was based on suggestions from :-
Levente Farkas, Roger Allen, G黱ter (surname unknown)
You are free to use, distribute or modify this code
as long as this header is not removed or modified.
Self Extractor (SFX) File Format
---------------------------------
Starting from the end of the archive and working backwards :-
Header Info
Signature - Identifier for SFX archive
Number of files in archive
Table of Contents
Contains one record in the following format for each file
Length of filename
Length of File
Offset in archive to data
Data Segment
Each file is written (uncompressed) here in the order of the TOC
After this is the extractor executable.
*************************************************************************************/
#if !defined(AFX_SELFEXTRACTOR_H__849C04B2__A8BC_C0__INCLUDED_)
#define AFX_SELFEXTRACTOR_H__849C04B2__A8BC_C0__INCLUDED_
#if _MSC_VER &= 1000
#pragma once
#endif // _MSC_VER &= 1000
#include "QFile"
#include "SEFileInfo.h"
#include "QDir"
#include "QString"
#define NO_SOURCE
#define INVALID_SIG
#define SUCCESS
#define COPY_FAILED
#define NOTHING_TO_DO
#define OUTPUT_FILE_ERROR
#define INPUT_FILE_ERROR
#define RESOURCE_ERROR
#define MAX_FILES
#define SIGNATURE
"!LYME_SFX!"
typedef void (* funcPtr)(void *, void*);
class CSelfExtractor
CSelfExtractor();
virtual ~CSelfExtractor();
//Creation
//Extraction
int Extract(int index, QString Dir,QString &appName);
int ExtractAll(QString dir, funcPtr function = NULL, void * userData = NULL);//
int ReadTOC(QString Filename);
//Data retrieval
inline int GetFileSize(int index){return m_InfoArray[index].GetFileSize();}
inline int GetFileCount(){return m_nF}
CSEFileInfo GetItem(int item){return m_InfoArray[item];}
void Reset();
protected:
QString GetThisFileName();//
QString EnsureTrailingBackSlash(QString &string);
int CreateArchive(QFile* fp, funcPtr function, void* userData);
ExtractOne(QFile* fp, int index, QString Dir);
m_strWorkingD
CSEFileInfo
m_InfoArray[MAX_FILES];
//Array of file information
//No of files in archive
//Size of Table of contents
#endif // !defined(AFX_SELFEXTRACTOR_H__849C04B2__A8BC_C0__INCLUDED_)
/*************************************************************************************
SEFileInfo.h
James Spibey
04/08/1999
Specification of the CSEFileInfo class
You are free to use, distribute or modify this code
as long as this header is not removed or modified.
This class holds data regarding each file in an archive
*************************************************************************************/
#if !defined(AFX_SEFILEINFO_H__5C3D775E_497B_11D3_A8BC_C0__INCLUDED_)
#define AFX_SEFILEINFO_H__5C3D775E_497B_11D3_A8BC_C0__INCLUDED_
#if _MSC_VER &= 1000
#pragma once
#endif // _MSC_VER &= 1000
#include "QString"
#include "QFile"
class CSEFileInfo
CSEFileInfo();
~CSEFileInfo();
SetFilename(QString file){m_strFilename =}
SetSize(int size){m_nSize =}
SetOffset(int offset){m_nOffset =}
GetPathname(){return m_strP}
GetFilename(){return m_strF}
GetFileSize(){return m_nS}
GetFileOffset(){return m_nO}
void Reset();
protected:
//Name of file
//Path to file to add
//Size of file
//Start Offset
#endif // !defined(AFX_SEFILEINFO_H__5C3D775E_497B_11D3_A8BC_C0__INCLUDED_)
& CZipI& BOOL flag = zipimp.Zip_UnPackFiles(SourcePath,installPath,AddCallBack,(void*)this);
void QMyWidgetSeven::AddCallBack(void * CallbackdData,void * userData)
ProGress *pData = static_cast&ProGress *&(CallbackdData);
QMyWidgetSeven *pdlg = static_cast&QMyWidgetSeven*&(userData);
int num = (pData-&current+<span style="color: #)*<span style="color: #00/(pData-&total);
pdlg-&progressBar-&setValue(num);
&标签:&&&&&&&&&&&&&&&&&&&&&&&&&&&原文:/kabe/p/6368051.html
教程昨日排行
&&国之画&&&& &&&&&&
&& &&&&&&&&&&&&&&
鲁ICP备号-4
打开技术之扣,分享程序人生!}

我要回帖

更多关于 copy是什么意思 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信