Exemplo n.º 1
0
void unzip(void *GamePath)
{
	CUnzipper zip;
	UZ_FileInfo info;
	char file_path[MAX_PATH];
	int num_files, i;
	FILE *fp;

	strcpy(file_path, (char *)GamePath);
	strcat(file_path, "\\Uninstall.cfg");

	fp = fopen(file_path, "w");

	if (fp != NULL)
	{
		zip.OpenZip("IA.ehf");
		//zip.SetOutputFolder((char *)GamePath);
		CreateFolder((char *)GamePath);

		num_files = zip.GetFileCount();

		for (i=0; i<num_files; i++)
		{
			zip.GetFileInfo(i, info); 
			zip.UnzipFile(i, (char *)GamePath, TRUE);

			fprintf(fp, "%s\\%s\n", GamePath, info.szFileName);
		}
	
		zip.CloseZip();

		fcloseall();
	}
	else
	{
		KillTimer(hWnd, 1);
		
		MessageBox(hWnd, "Error installing!  Code 2", "Error", MB_ICONEXCLAMATION|MB_OK);

		SetDlgItemText(hWnd, IDC_STATUS, "Error");

		return;
	}

	KillTimer(hWnd, 1);
	SetDlgItemText(hWnd, IDC_STATUS, "Done");

	SetDlgItemText(hWnd, IDC_CONTINUE, "Finish");
	EnableWindow(GetDlgItem(hWnd, IDC_CANCEL), FALSE);
	IsInstalled = TRUE;

	MessageBox(hWnd, "Imperial Alliance Installed!", "Success", MB_OK);

	return;
}
Exemplo n.º 2
0
BOOL CTDLWebUpdater::DoProgressDialog(const CString& sPrevCmdLine)
{
	// sanity checks
	ASSERT(m_nResUpdate == TDLWUR_SUCCESS);

	if (m_nResUpdate != TDLWUR_SUCCESS)
		return FALSE;

	// sanity checks
	ASSERT(m_dlgProgress.GetSafeHwnd() == NULL);

	if (m_dlgProgress.GetSafeHwnd())
		return FALSE;

	if (!m_dlgProgress.Create(AfxGetMainWnd(), (WS_VISIBLE | WS_POPUPWINDOW | WS_CAPTION)))
	{
		m_nResUpdate = TDLWUR_ERR_CREATEPROGRESSDLG;
		return FALSE;
	}

	// download update
	m_dlgProgress.SetProgressStatus(TDLWP_DOWNLOAD);
	
	// clear cache first
	if (!WebMisc::DeleteCacheEntry(m_sDownloadUri))
	{
		if (GetLastError() == ERROR_ACCESS_DENIED)
		{
			m_nResUpdate = TDLWUR_ERR_DELETEFROMCACHE;
			return FALSE;
		}
	}

	if (S_OK != ::URLDownloadToFile(NULL, m_sDownloadUri, m_sDownloadFile, 0, &m_dlgProgress))
	{
		m_nResUpdate = TDLWUR_ERR_DOWNLOADZIP;
		return FALSE;
	}

	// else
	FileMisc::LogText(_T("The update '%s' was successfully downloaded to '%s'."), m_sDownloadUri, m_sDownloadFile);

	if (CheckUpdateCancelled())
		return FALSE;

	// unzip the package
	m_dlgProgress.SetProgressStatus(TDLWP_UNZIP);

	// scope so unzipper releases any file handles
	try
	{
		CUnzipper unzip;
		
		FileMisc::LogText(_T("The unzip component was successfully initialised."));
		
		if (!unzip.OpenZip(m_sDownloadFile))
		{
			m_nResUpdate = TDLWUR_ERR_OPENZIP;
			return FALSE;
		}

		FileMisc::LogText(_T("The zip '%s' was successfully opened."), m_sDownloadFile);
		
		if (CheckUpdateCancelled())
			return FALSE;
		
		// check we can create the folder
		if (!FileMisc::CreateFolder(m_sUnzipFolder))
		{
			m_nResUpdate = TDLWUR_ERR_UNZIPFOLDER;
			return FALSE;
		}
		
		FileMisc::LogText(_T("The unzip folder '%s' was successfully created."), m_sUnzipFolder);
		
		// check we can do the unzip
		if (!unzip.UnzipTo(m_sUnzipFolder))
		{
			m_nResUpdate = TDLWUR_ERR_UNZIP;
			return FALSE;
		}
	}
	catch (...)
	{
		FileMisc::LogText(_T("The unzipping of '%s' threw an exception."), m_sDownloadFile);

		m_nResUpdate = TDLWUR_ERR_UNEXPECTED;
		return FALSE;
	}

	// check we can make contents writable
	if (!FileMisc::ModifyAttributes(m_sUnzipFolder, (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN), 0))
	{
		m_nResUpdate = TDLWUR_ERR_UNZIP;
		return FALSE;
	}
	
	FileMisc::LogText(_T("The update file '%s' was successfully unzipped to '%s'."), m_sDownloadFile, m_sUnzipFolder);
	
	if (CheckUpdateCancelled())
		return FALSE;
	
	// backup existing installation binaries and prefs
	m_dlgProgress.SetProgressStatus(TDLWP_BACKUP);
	
	if (!FileMisc::CopyFolder(m_sAppFolder, m_sBackupFolder, _T("*.exe;*.dll;*.ini"), FMDF_HIDDENREADONLY))
	{
		m_nResUpdate = TDLWUR_ERR_DOBACKUP;
		return FALSE;
	}
	
	FileMisc::LogText(_T("The application folder '%s' was successfully backed-up to '%s'."), m_sAppFolder, m_sBackupFolder);
	
	if (CheckUpdateCancelled())
		return FALSE;
	
	// NOTE: NO CANCELLING FROM HERE ON
	
	// copy over installation folder
	m_dlgProgress.SetProgressStatus(TDLWP_COPY);

	// binaries (overwrite)
	if (!FileMisc::CopyFolder(m_sUnzipFolder, m_sAppFolder, NULL, (FMDF_HIDDENREADONLY | FMDF_OVERWRITE)))
	{
		m_nResUpdate = TDLWUR_ERR_DOUPDATE;
		return FALSE;
	}
	
	// resources (do not overwrite existing)
	CString sSrcResources = (FileMisc::TerminatePath(m_sUnzipFolder) + _T("Resources"));
	CString sDestResources = (FileMisc::TerminatePath(m_sAppFolder) + _T("Resources"));

	if (!FileMisc::CopyFolder(sSrcResources, sDestResources, NULL, (FMDF_SUBFOLDERS | FMDF_HIDDENREADONLY | FMDF_NEWER)))
	{
		m_nResUpdate = TDLWUR_ERR_DOUPDATE;
		return FALSE;
	}
	
	FileMisc::LogText(_T("The contents of the temporary download folder '%s' were successfully copied to the application folder '%s'."), m_sUnzipFolder, m_sAppFolder);
	
	// cleanup
	m_dlgProgress.SetProgressStatus(TDLWP_CLEANUP);
	
	// verify we can start the updated application
	CString sParams(sPrevCmdLine);
	sParams += CEnCommandLineInfo::FormatSwitch(SWITCH_UPGRADED);

	if (FileMisc::Run(NULL, m_sAppPath, sParams) <= 32)
	{
		m_nResUpdate = TDLWUR_ERR_RUNUPDATE;
		return FALSE;
	}
	
	FileMisc::LogText(_T("The updated application '%s' was successfully restarted."), m_sAppPath);
	
	// success
	m_dlgProgress.SetProgressStatus(TDLWP_COMPLETE);

	ASSERT(m_nResUpdate == TDLWUR_SUCCESS);
	return TRUE;
}