Ejemplo n.º 1
0
wchar_t* Utils::toAbsolute(wchar_t* relative) {
	const wchar_t* bdir = getBaseDir();
	long len = wcslen(bdir);
	long tlen = len + wcslen(relative);
	wchar_t* result = new wchar_t[tlen + 1];
	if(result){
		wcscpy(result,bdir);
		wcscpy(result + len,relative);
	}
	return result;
}
Ejemplo n.º 2
0
wchar_t* Utils::toAbsolute(wchar_t* relative)
{
    const wchar_t* bdir = getBaseDir();
    long len = (int)wcslen(bdir);
    long tlen = len + (int)wcslen(relative);
    wchar_t* result = (wchar_t*)mir_alloc(sizeof(wchar_t)*(tlen + 1));
    if(result) {
        wcscpy(result, bdir);
        wcscpy(result + len, relative);
    }
    return result;
}
Ejemplo n.º 3
0
int main(int argc, char *argv[]) {
	const char *filename = getFilename(argv[0]);

	std::string target, compilerCommand;
	splitCompilerName(filename, &target, &compilerCommand);

	std::string compilerBaseDir = getBaseDir(compilerCommand);
	if (compilerBaseDir.size() && compilerBaseDir[compilerBaseDir.size() - 1] != '/') {
		compilerBaseDir += '/';
	}
	compilerCommand = compilerBaseDir + "bin/" + compilerCommand;

	// Determine SDK and deployment settings.
	const char *sdkPath   = getenvd("IOS_SDK", IOS_SDK_DEFAULT);
	const char *iOSMinVer = getenvd("IPHONEOS_DEPLOYMENT_TARGET", IOS_MIN_VER_DEFAULT);
	unsetenv("IPHONEOS_DEPLOYMENT_TARGET");

	std::string iOSMinVerParam = "-miphoneos-version-min=";
	iOSMinVerParam += iOSMinVer;

	// Set default archtitecture based on minimum iOS version.
	int major = -1, minor = -1;
	if (sscanf(iOSMinVer, "%d.%d", &major, &minor) != 2) {
		abort();
	}

	// armv6 devices only support up to iOS 4.2.1. If we deploy for such an
	// old version, we default that architecture.
	const char *arch;
	if (major <= 4) {
		arch = "armv6";
	} else {
		arch = "armv7";
	}

	// Make sure all program binaries created are automatically signed.
	std::string codesign = target + "-codesign_allocate";
	setenv("CODESIGN_ALLOCATE", codesign.c_str(), 1);
	setenv("IOS_FAKE_CODE_SIGN", "1", 1);

	// Setup environment for proper execution.
	std::string newLdLibraryPath = compilerBaseDir;
	newLdLibraryPath += "lib";

	char *ldLibraryPath = getenv(LIBRARY_PATH);
	if (ldLibraryPath && *ldLibraryPath) {
		newLdLibraryPath += ':';
		newLdLibraryPath += ldLibraryPath;
	}
	setenv(LIBRARY_PATH, newLdLibraryPath.c_str(), 1);

	// Setup command line arguments for compiler.
	char **params = (char **)malloc(sizeof(char *) * (argc + 9));

	bool hasArch = false;
	bool hasIPhoneOSVersionMin = false;
	for (int i = 1; i < argc; ++i) {
		if (hasPrefix(argv[i], "-arch")) {
			hasArch = true;
			break;
		} else if (hasPrefix(argv[i], "-miphoneos-version-min")) {
			hasIPhoneOSVersionMin = true;
			break;
		}
	}

	int param = 0;
#define ADD_PARAM(x) params[param++] = strdup((x))
	ADD_PARAM(compilerCommand.c_str());
	ADD_PARAM("-target");
	ADD_PARAM(target.c_str());

	if (!hasArch) {
		ADD_PARAM("-arch");
		ADD_PARAM(arch);
	}

	ADD_PARAM("-isysroot");
	ADD_PARAM(sdkPath);

	if (!hasIPhoneOSVersionMin) {
		ADD_PARAM(iOSMinVerParam.c_str());
	}

	ADD_PARAM("-mlinker-version=" LINKER_VERSION);
#undef ADD_PARAM

	for (int i = 1; i < argc; ++i) {
		params[param++] = argv[i];
	}

	params[param] = 0;

	execvp(compilerCommand.c_str(), params);

	abort();
}
Ejemplo n.º 4
0
/*!\brief	Gets all the file names of every .png image found in the given directory. Outputs a series of power 2 sized textures which contain all
 *			the individual images as one sheet (or several depending on how many images you have and what your max sized square is). It also outputs
 *			a single textfile which lists which texture pack contains which images. They are listed using their file names minus the png extension.
 *			If a series of images are found, they are listed as an animation with a single reference name. So if you have cat_1.png cat_2.png cat_3.png
 *			you will get animation 'cat' with 3 frames.
 */
int main(int argc, const char *argv[], const char **envp ){
	char const *refstrSourceDir = DEFAULT_SOURCE;
	char const *refstrOutputFile = DEFAULT_OUTPUT;
	char const *refstrJavapak = NULL;
	char const *refstrManClass = NULL;
	unsigned int maxSquare = 1024;
	eOutputFormat format = eFormatDefault;
	char ignoreOutputFiles[256];	memset(ignoreOutputFiles, 0, sizeof(ignoreOutputFiles));
	short usePadding=FALSE;
	bool enforcePow2=FALSE;

	printf("---Texture Cram---\n");

	/** parse command arguments */
	while(argc > 0){
		if(argc > 1 && strncmp(argv[argc-2], SWITCH_DIR, 2)==0 ){
			refstrSourceDir = argv[argc-1];
			printf("Source directory is %s\n", refstrSourceDir);
			--argc;

		}else if(argc > 1 && strncmp(argv[argc-2], SWITCH_OUTPUT, 2)==0 ){
			refstrOutputFile = argv[argc-1];
			printf("Output path is %s\n", refstrOutputFile);
			--argc;

		}else if(argc > 1 && strncmp(argv[argc-2], SWITCH_MAXSQUARE, 2)==0 ){
			maxSquare = atoi(argv[argc-1]);
			--argc;

		}else if(argc > 1 && strncmp(argv[argc-2], SWITCH_MAN_FORMAT, 2)==0 ){
			if( strncmp(argv[argc-1], MAN_FORMAT_C, strlen(MAN_FORMAT_C) ) == 0 ){
				format = eFormatC;
				printf("Manifest is C\n");
			}else if( strncmp(argv[argc-1], MAN_FORMAT_JAVA, strlen(MAN_FORMAT_JAVA) ) == 0 ){
				format = eFormatJava;
				printf("Manifest is java\n");
			}else{
				printf("Manifest is default\n");
			}
			//- todo others
			--argc;

		}else if(argc > 1 && strncmp(argv[argc-2], SWITCH_JAVAPAK, 5)==0 ){
			refstrJavapak = argv[argc-1];
			printf("Java pack is: %s\n", refstrJavapak);
			--argc;

		}else if(argc > 1 && strncmp(argv[argc-2], SWITCH_CLASS, 5)==0 ){
			refstrManClass = argv[argc-1];
			printf("parent class is: %s\n", refstrManClass);
			--argc;

		}else if(argc > 1 && strncmp(argv[argc-2], SWITCH_PAD, 4)==0 ){
			usePadding=TRUE;
			printf("Padding used\n");
			--argc;
			
		}else if(strncmp(argv[argc-1], SWITCH_NEARPOW2, 2)==0){
			enforcePow2 = TRUE;
		}

		--argc;
	}

	printf("The max size is %i\n", maxSquare);
		
	char *strBaseOut=NULL;
	getBaseDir(&strBaseOut, refstrOutputFile);

	char *strBaseName=NULL;
	getOutputNameFromFullPath(&strBaseName, refstrOutputFile);

	char **subDirs = calloc(2, sizeof(char*));
	size_t numDirs = 1;

	copyString(&subDirs[0], refstrSourceDir);
	subDirs[1] = NULL;

	char buffCurOut[256];

	size_t iDir;
	for(iDir=0; iDir < numDirs; ++iDir){
		sTex **dynarrTextures = NULL;
		sSheetList sheets;	memset(&sheets, 0, sizeof(sheets));
		sFileList files;	memset(&files, 0, sizeof(files));
		sStillList stills;	memset(&stills, 0, sizeof(stills));
		sSeqList seqs;		memset(&seqs, 0, sizeof(seqs));
		sFontList fonts;	memset(&fonts, 0, sizeof(fonts));
		sManifest theMan;	memset(&theMan, 0, sizeof(theMan));

		if(getFiles(subDirs[iDir], &files, ignoreOutputFiles, SEARCH_PATTERN) != NOPROB)
			continue;

		if(strBaseName == NULL)
			getOutputNameFromFullPath(&strBaseName, subDirs[iDir]);

		snprintf(ignoreOutputFiles, 256, "%s*", strBaseName);
		if(strBaseOut != NULL)
			snprintf(buffCurOut, 256, "%s%s", strBaseOut, strBaseName);
		else
			strncpy(buffCurOut, strBaseName, 256);

		if(files.num > 0){
			if(genTextures(subDirs[iDir], &files, &dynarrTextures) != NOPROB)
				goto LOOP_PROB;	
		}

		if(dynarrTextures != NULL){	/** we only need to sort sequences and stills */
			if(sortTextures(dynarrTextures, &seqs, &stills) != NOPROB)
				goto LOOP_PROB;
		}

		{	/** fonts */
			sTex **dynarrFntTexs =NULL;
			sFontInfo **dynarrFntIfo = genFontInfos(subDirs[iDir], ignoreOutputFiles);
			if(dynarrFntIfo != NULL && genTexFromFonts(dynarrFntIfo, &dynarrFntTexs, &fonts) != NOPROB)
				goto LOOP_PROB;

			unsigned int startIdx;
			if(dynarrTextures == NULL){
				startIdx = 0;
			}else{
				for(startIdx=0; dynarrTextures[startIdx] != NULL; ++startIdx)
					;
			}

			appendTexArr(&dynarrTextures, dynarrFntTexs);
			genFontFromInfo((const sFontInfo **)dynarrFntIfo, &fonts, startIdx);
			cleanupFontInfos(&dynarrFntIfo);
		}

		if(dynarrTextures == NULL){
			DBUG_WARN("No textures found");
			goto LOOP_PROB;
		}

		if(arrangeTextures(dynarrTextures, &seqs, &stills, &fonts, &sheets, maxSquare) != NOPROB)
			goto LOOP_PROB;
	
		if(genMan(
			strBaseName,
			&seqs,
			&stills,
			&fonts,
			&sheets,
			(const sTex **)dynarrTextures,
			&theMan
		) != NOPROB)
			goto LOOP_PROB;

		switch(format){
			case eFormatDefault:
				if(writeManifestInTxt(buffCurOut, &theMan, (const sTex **)dynarrTextures) != NOPROB)
					goto LOOP_PROB;	
				break;

			case eFormatC:
				if(writeManifestInC(buffCurOut, &theMan, (const sTex **)dynarrTextures) != NOPROB)
					goto LOOP_PROB;	
				break;

			case eFormatJava:
				if(writeManifestInJava(buffCurOut, refstrJavapak, refstrManClass, &theMan, (const sTex **)dynarrTextures)!=NOPROB)
					goto LOOP_PROB;	
				break;

			default:
				break;
		}

		if(writeSheets(strBaseOut, strBaseName, dynarrTextures, &sheets) != NOPROB)
			goto LOOP_PROB;

		{
			char **moreDirs = NULL;
			getDirs(subDirs[iDir], &moreDirs);

			if(moreDirs != NULL){
				size_t iMore;
				for(iMore = 0; moreDirs[iMore] != NULL; ++iMore){
					++numDirs;
					subDirs = realloc(subDirs, (numDirs + 1) * sizeof(char*));
					snprintf(buffCurOut, 245, "%s/%s", subDirs[iDir], moreDirs[iMore]);
					SAFE_DELETE(moreDirs[iMore]);
					copyString(&subDirs[ numDirs - 1], buffCurOut);
					subDirs[numDirs] = NULL;
				}
			}

			SAFE_DELETE(moreDirs);
		}

	LOOP_PROB:
		cleanupFileList(&files);
		cleanupTextures(&dynarrTextures);
		cleanupSheetList(&sheets);
		cleanupStillList(&stills);
		cleanupSeqList(&seqs);
		cleanupManifest(&theMan);

		SAFE_DELETE(subDirs[iDir]);
		SAFE_DELETE(strBaseName);
	}

	SAFE_DELETE(strBaseName);
	SAFE_DELETE(strBaseOut);
	SAFE_DELETE(subDirs);

	LOG("Finished!\n");
	return 0;
}
Ejemplo n.º 5
0
BOOL CSnapshotManager::generateDumpFile(PEXCEPTION_POINTERS pException, LPCTSTR prefix)
{
	BOOL bSuccess = FALSE;
	::EnterCriticalSection(&m_dmpSection);
	{
		HANDLE hDumpFile = INVALID_HANDLE_VALUE;
		do 
		{
			//查找dbghelp模块
			HMODULE	hDbgHelp = ::GetModuleHandle(_T("dbghelp.dll"));
			if (hDbgHelp == NULL)
			{
				hDbgHelp = ::LoadLibrary(_T("dbghelp.dll"));
				if (hDbgHelp == NULL)
				{
					errorLogE(_T("load module DbgHelp.dll failed."));
					break;
				}
			}

			//查找函数地址
			FnMiniDumpWriteDump	pfnMiniDumpWriteDump = (FnMiniDumpWriteDump) ::GetProcAddress(hDbgHelp, "MiniDumpWriteDump");
			if (pfnMiniDumpWriteDump == NULL)
			{
				errorLogE(_T("Get MiniDumpWriteDump function failed."));
				break;
			}

			//获取当前本地时间
			SYSTEMTIME now;
			::GetLocalTime(&now);

			//创建dmpdir目录
			tstring dmpdir = getBaseDir();
			dmpdir += DMP_PATH;
			if (! ::CreateDirectory(dmpdir.c_str(), NULL) && GetLastError() != ERROR_ALREADY_EXISTS)
			{
				errorLogE(_T("createdir %s failed."), dmpdir);
				break;
			}

			//生成dmp文件名称
			TCHAR filepath[MAX_PATH] = {0};
			_stprintf_s(filepath,  MAX_PATH, _T("%s\\%s-%04d%02d%02d%02d%02d%02d-%03d.dmp"),
				dmpdir.c_str(), prefix,
				now.wYear, now.wMonth, now.wDay,
				now.wHour, now.wMinute, now.wSecond, now.wMilliseconds);

			//设置异常信息
			MINIDUMP_EXCEPTION_INFORMATION dumpinfo;
			dumpinfo.ThreadId = ::GetCurrentThreadId();
			dumpinfo.ExceptionPointers = pException;
			dumpinfo.ClientPointers = 0;

			//创建dmp文件
			hDumpFile = ::CreateFile(filepath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
			if (hDumpFile == INVALID_HANDLE_VALUE)
			{
				errorLogE(_T("create dumpfile failed."));
				break;
			}

			BOOL bWrited = pfnMiniDumpWriteDump(
				::GetCurrentProcess(),
				::GetCurrentProcessId(),
				hDumpFile,
				MiniDumpNormal,
				(pException) ? &dumpinfo : NULL, 
				NULL, 
				NULL
				);
			if (! bWrited)
			{
				errorLogE(_T("pfnMiniDumpWriteDump failed %s. \r\n"), GetErrorMessage());
				break;
			}

			infoLog(_T("minidump filepath is %s"), filepath);
			bSuccess = TRUE;
		} while (FALSE);

		if (hDumpFile != INVALID_HANDLE_VALUE) ::CloseHandle(hDumpFile);
	}
	::LeaveCriticalSection(&m_dmpSection);

	if (m_fnCallback) m_fnCallback(pException);

	return bSuccess;
}