src/Cedar/SW.c
// Create a Shortcut file (Delete the old one)

Create a Shortcut file (Delete the old one)
Create a Shortcut file ( Delete the old one )
void SwInstallShortcuts(SW* sw, WIZARD_PAGE* wp, SW_COMPONENT* c, SW_TASK* t)
{
	UINT i;
	wchar_t tmp[MAX_SIZE];
	wchar_t setuplog[MAX_PATH];
	LIST* o;
	SW_LOGFILE* oldlog;
	if (sw == NULL || wp == NULL || c == NULL || t == NULL)
	{
		return;
	}
	CombinePathW(setuplog, sizeof(setuplog), sw->InstallDir, L"setuplog.dat");
	oldlog = SwLoadLogFile(sw, setuplog);
	if (oldlog != NULL)
	{
		SwPerformPrint(wp, _UU("SW_PERFORM_MSG_DELETE_OLD_LINKS"));
		SwDeleteShortcuts(oldlog);
		SwFreeLogFile(oldlog);
	}
	o = NewListFast(NULL);
	for (i = 0;i < LIST_NUM(sw->LogFile->LogList);i++)
	{
		SW_LOG* g = LIST_DATA(sw->LogFile->LogList, i);
		if (g->Type == SW_LOG_TYPE_LNK || g->Type == SW_LOG_TYPE_LNK_DIR)
		{
			Add(o, g);
		}
	}
	for (i = 0;i < LIST_NUM(o);i++)
	{
		SW_LOG* g = LIST_DATA(o, i);
		Delete(sw->LogFile->LogList, g);
		Free(g);
	}
	ReleaseList(o);
	for (i = 0;i < LIST_NUM(t->LinkTasks);i++)
	{
		SW_TASK_LINK* lt = LIST_DATA(t->LinkTasks, i);
		wchar_t lnk_fullpath[MAX_SIZE];
		wchar_t lnk_dirname[MAX_SIZE];
		wchar_t target_fullpath[MAX_SIZE];
		wchar_t target_dirname[MAX_SIZE];
		wchar_t icon_fullpath[MAX_SIZE];
	L_RETRY_LINK:
		SwPerformPrint(wp, _UU("SW_PERFORM_MSG_CREATE_LINKS"));
		CombinePathW(lnk_fullpath, sizeof(lnk_fullpath), lt->DestDir, lt->DestName);
		UniStrCat(lnk_fullpath, sizeof(lnk_fullpath), L".lnk");
		GetDirNameFromFilePathW(lnk_dirname, sizeof(lnk_dirname), lnk_fullpath);
		CombinePathW(target_fullpath, sizeof(target_fullpath), lt->TargetDir, lt->TargetExe);
		CombinePathW(icon_fullpath, sizeof(icon_fullpath), lt->TargetDir, lt->IconExe);
		GetDirNameFromFilePathW(target_dirname, sizeof(target_dirname), target_fullpath);
		MakeDirExW(lnk_dirname);
		if (lt->NoDeleteDir == false)
		{
			SwAddLog(sw, sw->LogFile, SW_LOG_TYPE_LNK_DIR, lnk_dirname);
		}
		if (CreateLink(lnk_fullpath, target_fullpath, target_dirname, lt->TargetArg,
			lt->DestDescription, icon_fullpath, lt->IconIndex) == false)
		{
			UINT msgret;
			UniFormat(tmp, sizeof(tmp), _UU("SW_PERFORM_MSG_CRAETE_LINK_ERROR"), lnk_fullpath);
			msgret = SwPerformMsgBox(wp, MB_ICONEXCLAMATION | MB_YESNO, tmp);
			if (msgret == IDYES)
			{
				goto L_RETRY_LINK;
			}
		}
		else
		{
			SwAddLog(sw, sw->LogFile, SW_LOG_TYPE_LNK, lnk_fullpath);
		}
	}
}
void SwInstallShortcuts ( SW * sw , WIZARD_PAGE * wp , SW_COMPONENT * c , SW_TASK * t ) { UINT i ; wchar_t tmp [ MAX_SIZE ] ; wchar_t setuplog [ MAX_PATH ] ; LIST * o ; SW_LOGFILE * oldlog ; if ( sw == NULL || wp == NULL || c == NULL || t == NULL ) { return ; } CombinePathW ( setuplog , sizeof ( setuplog ) , sw -> InstallDir , L" " ) ; oldlog = SwLoadLogFile ( sw , setuplog ) ; if ( oldlog != NULL ) { SwPerformPrint ( wp , _UU ( " " ) ) ; SwDeleteShortcuts ( oldlog ) ; SwFreeLogFile ( oldlog ) ; } o = NewListFast ( NULL ) ; for ( i = 0 ; i < LIST_NUM ( sw -> LogFile -> LogList ) ; i ++ ) { SW_LOG * g = LIST_DATA ( sw -> LogFile -> LogList , i ) ; if ( g -> Type == SW_LOG_TYPE_LNK || g -> Type == SW_LOG_TYPE_LNK_DIR ) { Add ( o , g ) ; } } for ( i = 0 ; i < LIST_NUM ( o ) ; i ++ ) { SW_LOG * g = LIST_DATA ( o , i ) ; Delete ( sw -> LogFile -> LogList , g ) ; Free ( g ) ; } ReleaseList ( o ) ; for ( i = 0 ; i < LIST_NUM ( t -> LinkTasks ) ; i ++ ) { SW_TASK_LINK * lt = LIST_DATA ( t -> LinkTasks , i ) ; wchar_t lnk_fullpath [ MAX_SIZE ] ; wchar_t lnk_dirname [ MAX_SIZE ] ; wchar_t target_fullpath [ MAX_SIZE ] ; wchar_t target_dirname [ MAX_SIZE ] ; wchar_t icon_fullpath [ MAX_SIZE ] ; L_RETRY_LINK : SwPerformPrint ( wp , _UU ( " " ) ) ; CombinePathW ( lnk_fullpath , sizeof ( lnk_fullpath ) , lt -> DestDir , lt -> DestName ) ; UniStrCat ( lnk_fullpath , sizeof ( lnk_fullpath ) , L" " ) ; GetDirNameFromFilePathW ( lnk_dirname , sizeof ( lnk_dirname ) , lnk_fullpath ) ; CombinePathW ( target_fullpath , sizeof ( target_fullpath ) , lt -> TargetDir , lt -> TargetExe ) ; CombinePathW ( icon_fullpath , sizeof ( icon_fullpath ) , lt -> TargetDir , lt -> IconExe ) ; GetDirNameFromFilePathW ( target_dirname , sizeof ( target_dirname ) , target_fullpath ) ; MakeDirExW ( lnk_dirname ) ; if ( lt -> NoDeleteDir == false ) { SwAddLog ( sw , sw -> LogFile , SW_LOG_TYPE_LNK_DIR , lnk_dirname ) ; } if ( CreateLink ( lnk_fullpath , target_fullpath , target_dirname , lt -> TargetArg , lt -> DestDescription , icon_fullpath , lt -> IconIndex ) == false ) { UINT msgret ; UniFormat ( tmp , sizeof ( tmp ) , _UU ( " " ) , lnk_fullpath ) ; msgret = SwPerformMsgBox ( wp , MB_ICONEXCLAMATION | MB_YESNO , tmp ) ; if ( msgret == IDYES ) { goto L_RETRY_LINK ; } } else { SwAddLog ( sw , sw -> LogFile , SW_LOG_TYPE_LNK , lnk_fullpath ) ; } } }
Create a Shortcut file (Delete the old one)
Create a Shortcut file ( Delete the old one )
// Validate arguments
 // If there is an old setup log, read it
 // Remove only the shortcut setup log from the current log
 // Generate the full path of the LNK file
 // Get the directory name to be saved the LNK file
 // Generate the full path to the link destination
 // Create the full path of the icon
 // Get the directory name of the full path to the link destination
 // Create a directory
 // Create the LNK file
 // Show the error message if it fails
 // Retry
