Exemplo n.º 1
0
static void DoAutoExec(void)
{
	TCHAR szUse[7], szIniPath[MAX_PATH], szFindPath[MAX_PATH];
	TCHAR *str2;
	TCHAR buf[2048], szSecurity[11], szOverrideSecurityFilename[MAX_PATH], szOnCreateFilename[MAX_PATH];
	char *szSafeSections, *szUnsafeSections;
	int secur;

	GetPrivateProfileString(_T("AutoExec"),_T("Use"),_T("prompt"),szUse,SIZEOF(szUse),mirandabootini);
	if(!lstrcmpi(szUse,_T("no"))) return;
	GetPrivateProfileString(_T("AutoExec"),_T("Safe"),_T("CLC Icons CLUI CList SkinSounds"),buf,SIZEOF(buf),mirandabootini);
	szSafeSections = mir_t2a(buf);
	GetPrivateProfileString(_T("AutoExec"),_T("Unsafe"),_T("ICQ MSN"),buf,SIZEOF(buf),mirandabootini);
	szUnsafeSections = mir_t2a(buf);
	GetPrivateProfileString(_T("AutoExec"),_T("Warn"),_T("notsafe"),szSecurity,SIZEOF(szSecurity),mirandabootini);
	if (!lstrcmpi(szSecurity,_T("none"))) secur = 0;
	else if (!lstrcmpi(szSecurity,_T("notsafe"))) secur = 1;
	else if (!lstrcmpi(szSecurity,_T("onlyunsafe"))) secur = 2;

	GetPrivateProfileString(_T("AutoExec"),_T("OverrideSecurityFilename"),_T(""),szOverrideSecurityFilename,SIZEOF(szOverrideSecurityFilename),mirandabootini);
	GetPrivateProfileString(_T("AutoExec"),_T("OnCreateFilename"),_T(""),szOnCreateFilename,SIZEOF(szOnCreateFilename),mirandabootini);
	GetPrivateProfileString(_T("AutoExec"),_T("Glob"),_T("autoexec_*.ini"),szFindPath,SIZEOF(szFindPath),mirandabootini);
    
	if (dbCreated && szOnCreateFilename[0]) {
		str2 = Utils_ReplaceVarsT(szOnCreateFilename);
		pathToAbsoluteT(str2, szIniPath, NULL);
		mir_free(str2);

		ProcessIniFile(szIniPath, szSafeSections, szUnsafeSections, 0, 1);
	}

	str2 = Utils_ReplaceVarsT(szFindPath);
	pathToAbsoluteT(str2, szFindPath, NULL);
	mir_free(str2);

	WIN32_FIND_DATA fd;
	HANDLE hFind = FindFirstFile(szFindPath, &fd);
	if (hFind == INVALID_HANDLE_VALUE) {
		mir_free(szSafeSections);
		mir_free(szUnsafeSections);
		return;
	}

	str2 = _tcsrchr(szFindPath, '\\');
	if (str2 == NULL) szFindPath[0] = 0;
	else str2[1] = 0;

	do {
		bool secFN = lstrcmpi(fd.cFileName,szOverrideSecurityFilename) == 0;

		mir_sntprintf(szIniPath, SIZEOF(szIniPath), _T("%s%s"), szFindPath, fd.cFileName);
		if(!lstrcmpi(szUse,_T("prompt")) && !secFN) {
			int result=DialogBoxParam(hMirandaInst,MAKEINTRESOURCE(IDD_INSTALLINI),NULL,InstallIniDlgProc,(LPARAM)szIniPath);
			if(result==IDC_NOTOALL) break;
			if(result==IDCANCEL) continue;
		}

		ProcessIniFile(szIniPath, szSafeSections, szUnsafeSections, secur, secFN);

		if(secFN)
			DeleteFile(szIniPath);
		else {
			TCHAR szOnCompletion[8];
			GetPrivateProfileString(_T("AutoExec"),_T("OnCompletion"),_T("recycle"),szOnCompletion,SIZEOF(szOnCompletion),mirandabootini);
			if(!lstrcmpi(szOnCompletion,_T("delete")))
				DeleteFile(szIniPath);
			else if(!lstrcmpi(szOnCompletion,_T("recycle"))) {
				SHFILEOPSTRUCT shfo={0};
				shfo.wFunc=FO_DELETE;
				shfo.pFrom=szIniPath;
				szIniPath[lstrlen(szIniPath)+1]=0;
				shfo.fFlags=FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT | FOF_ALLOWUNDO;
				SHFileOperation(&shfo);
			}
			else if(!lstrcmpi(szOnCompletion,_T("rename"))) {
				TCHAR szRenamePrefix[MAX_PATH];
				TCHAR szNewPath[MAX_PATH];
				GetPrivateProfileString(_T("AutoExec"),_T("RenamePrefix"),_T("done_"),szRenamePrefix,SIZEOF(szRenamePrefix),mirandabootini);
				lstrcpy(szNewPath,szFindPath);
				lstrcat(szNewPath,szRenamePrefix);
				lstrcat(szNewPath,fd.cFileName);
				MoveFile(szIniPath,szNewPath);
			}
			else if(!lstrcmpi(szOnCompletion,_T("ask")))
				DialogBoxParam(hMirandaInst,MAKEINTRESOURCE(IDD_INIIMPORTDONE),NULL,IniImportDoneDlgProc,(LPARAM)szIniPath);
		}
	} while (FindNextFile(hFind, &fd));
	FindClose(hFind);
	mir_free(szSafeSections);
	mir_free(szUnsafeSections);
}
Exemplo n.º 2
0
/**
 * And the main program (what else?)
 * @param argc Number of command-line arguments including the program name itself.
 * @param argv Vector of the command-line arguments.
 */
int CDECL main(int argc, char *argv[])
{
	const char *output_file = NULL;
	const char *before_file = NULL;
	const char *after_file = NULL;

	GetOptData mgo(argc - 1, argv + 1, _opts);
	for (;;) {
		int i = mgo.GetOpt();
		if (i == -1) break;

		switch (i) {
			case 'v':
				puts("$Revision$");
				return 0;

			case 'h':
				puts("settingsgen - $Revision$\n"
						"Usage: settingsgen [options] ini-file...\n"
						"with options:\n"
						"   -v, --version           Print version information and exit\n"
						"   -h, -?, --help          Print this help message and exit\n"
						"   -b FILE, --before FILE  Copy FILE before all settings\n"
						"   -a FILE, --after FILE   Copy FILE after all settings\n"
						"   -o FILE, --output FILE  Write output to FILE\n");
				return 0;

			case 'o':
				output_file = mgo.opt;
				break;

			case 'a':
				after_file = mgo.opt;
				break;

			case 'b':
				before_file = mgo.opt;
				break;

			case -2:
				fprintf(stderr, "Invalid arguments\n");
				return 1;
		}
	}

	_stored_output.Clear();

	for (int i = 0; i < mgo.numleft; i++) ProcessIniFile(mgo.argv[i]);

	/* Write output. */
	if (output_file == NULL) {
		CopyFile(before_file, stdout);
		_stored_output.Write(stdout);
		CopyFile(after_file, stdout);
	} else {
		static const char * const tmp_output = "tmp2.xxx";

		FILE *fp = fopen(tmp_output, "w");
		if (fp == NULL) {
			fprintf(stderr, "settingsgen: Warning: Cannot open file %s\n", tmp_output);
			return 1;
		}
		CopyFile(before_file, fp);
		_stored_output.Write(fp);
		CopyFile(after_file, fp);
		fclose(fp);

		if (CompareFiles(tmp_output, output_file)) {
			/* Files are equal. tmp2.xxx is not needed. */
			unlink(tmp_output);
		} else {
			/* Rename tmp2.xxx to output file. */
#if defined(WIN32) || defined(WIN64)
			unlink(output_file);
#endif
			if (rename(tmp_output, output_file) == -1) error("rename() failed");
		}
	}
	return 0;
}