void CInstall_ProgressDlg::CreateShortCut(CString cslinkPath, CString csExePath, CString csIconPath)
{
HRESULT hres;
hres = ::CoInitialize(NULL);
if(S_OK == hres)
{
//delete old link
CFileFind cfind;
if(cfind.FindFile(cslinkPath)){
CFile::Remove(cslinkPath);
}
IShelllink * pShelllink ;
hres = ::CoCreateInstance( CLSID_Shelllink, NULL,CLSCTX_INPROC_SERVER, IID_IShelllink,(void **)&pShelllink);
if( SUCCEEDED( hres))
{
pShelllink -> SetPath(csExePath);
if(PathFileExists(csIconPath))
pShelllink -> SetIconLocation(csIconPath, 0);
pShelllink -> SetHotkey( MAKEWORd( 'R', HOTKEYF_SHIFT | HOTKEYF_CONTROL));
CString csWorkingDir;
csWorkingDir = csExePath.Left(2);
csWorkingDir.Append(FILE_SEPARATOR);
TRACE_CS(csWorkingDir);
pShelllink -> SetWorkingDirectory(csWorkingDir);
IPersistFile *pPersistFile;
hres = pShelllink -> QueryInterface( IID_IPersistFile, (void **)&pPersistFile) ;
if( SUCCEEDED(hres))
{
hres = pPersistFile -> Save(cslinkPath, TRUE);
pPersistFile -> Release();
}
pShelllink -> Release();
}
::CoUninitialize();
}
}
void CInstall_ProgressDlg::CreateStartMenu()
{
TCHAR chStartupFolder[MAX_PATH];
SHGetSpecialFolderPath(this->GetSafeHwnd(), chStartupFolder,CSIDL_PROGRAMS,FALSE);
CString csStartupFolder = chStartupFolder;
csStartupFolder.Append(FILE_SEPARATOR);
csStartupFolder.Append(FOLDER_APP_NAME);
if(!PathFileExists(csStartupFolder)){
g_InstallHelper.CreateInstallFolder(csStartupFolder);
}
CString csInstallPath;
csInstallPath = g_InstallInfo.chInstallPath;
CString csEXEFilePath;
csEXEFilePath = csInstallPath;
csEXEFilePath.Append(FILE_SEPARATOR);
csEXEFilePath.Append(FILE_APP_NAME);
CString csUnExeFilePath;
csUnExeFilePath = csInstallPath;
csUnExeFilePath.Append(FILE_SEPARATOR);
csUnExeFilePath.Append(FILE_UNINSTALL_NAME);
CString cslinkFileName = csStartupFolder;
cslinkFileName.Append(FILE_SEPARATOR);
cslinkFileName.Append(link_NAME);
cslinkFileName.Append(link_EXT);
CString csUnlinkFileName = csStartupFolder;
csUnlinkFileName.Append(FILE_SEPARATOR);
csUnlinkFileName.Append(link_UNINSTALL_NAME);
csUnlinkFileName.Append(link_EXT);
//get icon path
CString csExeIconPath;
csExeIconPath = csInstallPath;
csExeIconPath.Append(FILE_SEPARATOR);
csExeIconPath.Append(ICON_APP_EXE_NAME);
CString csUnExeIconPath;
csUnExeIconPath = csInstallPath;
csUnExeIconPath.Append(FILE_SEPARATOR);
csUnExeIconPath.Append(ICON_UNINSTALL_EXE_NAME);
TRACE_CS(cslinkFileName);
TRACE_CS(csEXEFilePath);
TRACE_CS(csExeIconPath);
TRACE_CS(csUnlinkFileName);
TRACE_CS(csUnExeFilePath);
TRACE_CS(csUnExeIconPath);
CreateShortCut(cslinkFileName, csEXEFilePath, csExeIconPath);
CreateShortCut(csUnlinkFileName, csUnExeFilePath, csUnExeIconPath);
}