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

📄 main.cpp

📁 不可多得的 windows mobile 软件安装程序生成工具Vc++ 源码。提供cab
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	EndUpdateResource(h, FALSE);
	return true;
}

bool CompressExe(char *pszDir, char *pszFnExeT)
{
	// Write cexe.exe resource to temp file
	
	int cb;
	byte *pb = GetResourcePtr(kidrCExe, &cb);
	char szCEXE[MAX_PATH];
	szCEXE[0] = 0;
	GetTempFn(pszDir, szCEXE);
	if (!WriteToFile(pb, cb, szCEXE)) {
		printf("Error writing to temporary file %s!\n", szCEXE);
		return false;
	}

	// Execute cexe with pszFnExeT as parameter, wait on result

	char szCmdLine[MAX_PATH];
	lstrcpy(szCmdLine, "\"");
	lstrcat(szCmdLine, szCEXE);
	lstrcat(szCmdLine, "\" ");
	lstrcat(szCmdLine, "\"");
	lstrcat(szCmdLine, pszFnExeT);
	lstrcat(szCmdLine, "\"");

	STARTUPINFO snfo;
	GetStartupInfo(&snfo);
	PROCESS_INFORMATION pi;
	if (!CreateProcess(NULL, szCmdLine, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS | DETACHED_PROCESS, NULL, NULL, &snfo, &pi)) {
		DeleteFile(szCEXE);
Error:
		printf(".exe compression failed!\n");
		return false;
	}
	CloseHandle(pi.hThread);
	WaitForSingleObject(pi.hProcess, INFINITE);
	DWORD dwExit;
	GetExitCodeProcess(pi.hProcess, &dwExit);
	CloseHandle(pi.hProcess);

	// Delete temp file CEXE

	DeleteFile(szCEXE);

	if (dwExit != 0)
		goto Error;
	return true;
}

void Usage()
{
	printf("\n");
	printf("EzSetup v1.1, July 2001\n");
	printf("\n");
	printf("Usage:\n");
	printf("\n");
	printf("ezsetup <-l language> <-i inifilename> <-r readme.txt> <-e eula.txt> <-o outputexe>\n");
	printf("\n");
	printf("Creates a compressed, self-contained and self-extracting Win32 gui install\n");
	printf("application that when run on your desktop PC will install a WinCE application\n");
	printf("to a WinCE 2.x and above device. To operate, ezsetup simply needs your .ini\n");
	printf("and .cab files, a readme.txt file and a eula.txt file. (For more info on\n");
	printf(".ini and .cab files, see your WinCE SDK documentation).\n");
	printf("\n");
	printf("<-l language>\n");
	printf("    This is specifies the language text of the install program. Valid arguments\n");
	printf("    are english, german, and french.\n");
	printf("\n");
	printf("<-i inifilename>\n");
	printf("    This parameter specifies the .ini file used as part of CE App Mgr setup.\n");
	printf("    The .cab files specified in this .ini file are expected to be in the same\n");
	printf("    directory as the .ini file, and are read in by ezsetup.\n");
	printf("\n");
	printf("<-r readme.txt>\n");
	printf("    Specify a readme.txt file that will appear as the first dialog in the\n");
	printf("    gui setup program.\n");
	printf("\n");
	printf("<-e eula.txt>\n");
	printf("    Specify an end-user license agreement that will appear as the second\n");
	printf("    dialog in the gui setup program.\n");
	printf("\n");
	printf("<-o outputexe>\n");
	printf("    This parameter specifies the output name of the resulting compressed\n");
	printf("    auto-extracting setup executable.\n");
	printf("\n");
	printf("Example:\n");
	printf("\n");
	printf("ezsetup -l english -i chess.ini -r readme.txt -e eula.txt -o ChessSetup.exe\n");
	printf("\n");
	printf("Note: This tool runs on Windows NT, Windows 2000 and Windows XP or later\n");
	printf("versions only.\n");
	printf("\n");
	printf("The executables it produces will run on any Windows platform including Win95\n");
	printf("and Win98.\n");
	printf("\n");
	printf("EzSetup is free software.\n");
	printf("\n");	
	printf("Tinyware, Inc.\n");
	printf("http://www.eskimo.com/~scottlu\n");
	printf("scottlu@eskimo.com\n");
}

int main(int argc, char *argv[])
{
	// Read in command line arguments

	char szLanguage[256];
	char szFnEzSetup[MAX_PATH];
	char szFnIni[MAX_PATH];
	char szFnReadme[MAX_PATH];
	char szFnEula[MAX_PATH];
	char szFnExe[MAX_PATH];

	char *psz = GetCommandLine();
	if (sscanf(GetCommandLine(), "%s -l %s -i %s -r %s -e %s -o %s", szFnEzSetup, szLanguage, szFnIni, szFnReadme, szFnEula, szFnExe) != 6) {
		Usage();
		return -1;
	}

	// Parse for appropriate language

	UINT idrSetup = (UINT)-1;
	if (stricmp(szLanguage, "english") == 0) {
		idrSetup = kidrSetupEnglish;
	} else if (stricmp(szLanguage, "french") == 0) {
		idrSetup = kidrSetupFrench;
	} else if (stricmp(szLanguage, "german") == 0) {
		idrSetup = kidrSetupGerman;
	}
	if (idrSetup == (UINT)-1) {
		printf("Valid language not specified.\n\n");
		return -1;
	}

	// Read in the .ini file

	PropertySection *pprop = CreatePropertySection(szFnIni);
	if (pprop == NULL) {
IniError:
		printf("Error reading .ini file: %s\n\n", szFnIni);
		return -1;
	}

	// Get the name of the component

	PropertySection *ppropAppMgr = pprop->FindChildSection("CEAppManager");
	if (ppropAppMgr == NULL) {
		printf("Could not find [CEAppManager] section in .ini file!\n");
		goto IniError;
	}
	char *pszComponent = ppropAppMgr->GetString("Component", NULL);
	if (pszComponent == NULL) {
		printf("Could not find Component key in [CEAppManager] section in .ini file!\n");
		goto IniError;
	}

	// Now grab the .cab file names from the component section

	PropertySection *ppropComponent = pprop->FindChildSection(pszComponent);
	if (ppropComponent == NULL) {
		printf("Could not find component [%s] section in .ini file!\n", pszComponent);
		goto IniError;
	}
	char *pszCabs = ppropComponent->GetString("CabFiles", NULL);
	if (pszCabs == NULL) {
		printf("Could not find CabFiles key in [%s] section!\n", pszComponent);
		goto IniError;
	}

	// Good so far. Now break out pszCabs into a list of filenames

	char aszFnCabs[20][MAX_PATH];
	int cCabs = sscanf(pszCabs, "\t%[^,\n],\t%[^,\n],\t%[^,\n],\t%[^,\n],\t%[^,\n],\t%[^,\n],\t%[^,\n],\t%[^,\n],\t%[^,\n],\t%[^,\n],\t%[^,\n],\t%[^,\n],\t%[^,\n],\t%[^,\n],\t%[^,\n],\t%[^,\n],\t%[^,\n],\t%[^,\n],\t%[^,\n],\t%[^,\n]",
			&aszFnCabs[0], &aszFnCabs[1], &aszFnCabs[2], &aszFnCabs[3], &aszFnCabs[4], &aszFnCabs[5],
			&aszFnCabs[6], &aszFnCabs[7], &aszFnCabs[8], &aszFnCabs[9], &aszFnCabs[10], &aszFnCabs[11],
			&aszFnCabs[12], &aszFnCabs[13], &aszFnCabs[14], &aszFnCabs[15], &aszFnCabs[16], &aszFnCabs[17],
			&aszFnCabs[18], &aszFnCabs[19]);
	if (cCabs == 0) {
		printf("Error parsing CabFiles value in [%s] section!\n", pszComponent);
		goto IniError;
	}

	// Check to make sure all files are present

	if (!FilePresent(szFnReadme)) {
		printf("Could not find readme text file %s!\n", szFnReadme);
		return -1;
	}
	if (!FilePresent(szFnEula)) {
		printf("Could not find eula text file %s!\n", szFnEula);
		return -1;
	}
	for (int i = 0; i < cCabs; i++) {
		if (!FilePresent(&aszFnCabs[i][0])) {
			printf("Could not find .cab file %s!\n", &aszFnCabs[i][0]);
			return -1;
		}
	}

	// Now print full paths of files read in

	printf("Reading files...\n");
	char szT[MAX_PATH];
	_fullpath(szT, szFnIni, sizeof(szT));
	printf("%s\n", szT);
	_fullpath(szT, szFnReadme, sizeof(szT));
	printf("%s\n", szT);
	_fullpath(szT, szFnEula, sizeof(szT));
	printf("%s\n", szT);
	for (i = 0; i < cCabs; i++) {
		_fullpath(szT, &aszFnCabs[i][0], sizeof(szT));
		printf("%s\n", szT);
	}
	printf("\n");

	// Ready to get to work. Figure out what directory the result
	// is being written to.

	_fullpath(szT, szFnExe, sizeof(szT));
	char szDrive[_MAX_DRIVE];
	char szDir[MAX_PATH];
	char szName[MAX_PATH];
	char szExt[MAX_PATH];
	_splitpath(szT, szDrive, szDir, szName, szExt);

	char szFnExeT[MAX_PATH];
	if (!WriteNewCESetup(idrSetup, szDir, pszComponent, szFnIni, szFnReadme, szFnEula, cCabs, aszFnCabs, szFnExeT))
		return -1;

	// Now compress this new app

	printf("Compressing file...\n");
	if (!CompressExe(szDir, szFnExeT)) {
		DeleteFile(szFnExeT);
		return -1;
	}

	// We're just about done! Now copy to new filename - done this way so
	// in case we exit inappropriately, the old filename (if it exists)
	// doesn't get written to.

	if (!CopyFile(szFnExeT, szFnExe, FALSE)) {
		printf("Error copying %s to %s!\n", szFnExeT, szFnExe);
		DeleteFile(szFnExeT);
		return -1;
	}
	DeleteFile(szFnExeT);

	// Now print status and exit

	printf("%s successfully written.\n", szFnExe);
	printf("%d bytes.\n", FileSize(szFnExe));
	printf("\n");

	// Delete parent property section

	delete pprop;
	
	return 0;
}

⌨️ 快捷键说明

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