WCHAR * getTestJVMFileName(WCHAR * testJVMFile) { WCHAR * filePtr = testJVMFile; WCHAR * testJavaClass = NULL; if(filePtr!=NULL) { WCHAR * dotClass = NULL; while(searchW(filePtr, L"\\")!=NULL) { filePtr = searchW(filePtr, L"\\"); filePtr++; } dotClass = searchW(filePtr, L".class"); if(dotClass!=NULL) { testJavaClass = appendStringNW(NULL, 0, filePtr, getLengthW(filePtr) - getLengthW(dotClass)); } } return testJavaClass; }
//returns : ERROR_OK, ERROR_INTEGRITY, ERROR_FREE_SPACE void extractFileToDir(LauncherProperties * props, WCHAR ** resultFile) { WCHAR * fileName = NULL; int64t * fileLength = NULL; DWORD crc = 0; writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, "Extracting file ...", 1); readStringWithDebugW( props, & fileName, "file name"); fileLength = newint64_t(0, 0); readBigNumberWithDebug( props, fileLength, "file length "); readNumberWithDebug( props, &crc, "CRC32"); if(!isOK(props)) return; if(fileName!=NULL) { DWORD i=0; WCHAR * dir; resolveString(props, &fileName); for(i=0;i<getLengthW(fileName);i++) { if(fileName[i]==L'/') { fileName[i]=L'\\'; } } dir = getParentDirectory(fileName); writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, " ... extract to directory = ", 0); writeMessageW(props, OUTPUT_LEVEL_DEBUG, 0, dir, 1); checkFreeSpace(props, dir, fileLength); FREE(dir); if(isOK(props)) { writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, " ... starting data extraction", 1); writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, " ... output file is ", 0); writeMessageW(props, OUTPUT_LEVEL_DEBUG, 0, fileName, 1); extractDataToFile(props, fileName, fileLength, crc); writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, " ... extraction finished", 1); *resultFile = fileName; } else { writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, " ... data extraction canceled", 1); } } else { writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, "Error! File name can`t be null. Seems to be integrity error!", 1); *resultFile = NULL; props -> status = ERROR_INTEGRITY; } FREE(fileLength); return; }
void unpackJars(LauncherProperties * props, WCHAR * jvmDir, WCHAR * startDir, WCHAR * unpack200exe) { DWORD attrs; DWORD dwError; DWORD count = 0 ; if(!isOK(props)) return; attrs = GetFileAttributesW(startDir); if(attrs==INVALID_FILE_ATTRIBUTES) { writeErrorA(props, OUTPUT_LEVEL_DEBUG, 1, "Error! Can`t get attributes of the file : ", startDir, GetLastError()); return; } if(attrs & FILE_ATTRIBUTE_DIRECTORY) { // is directory WIN32_FIND_DATAW FindFileData; HANDLE hFind = INVALID_HANDLE_VALUE; WCHAR * DirSpec = appendStringW(appendStringW(NULL, startDir), L"\\*" ); // Find the first file in the directory. hFind = FindFirstFileW(DirSpec, &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { writeErrorA(props, OUTPUT_LEVEL_DEBUG, 1, "Error! Can`t file with pattern ", DirSpec, GetLastError()); } else { // List all the other files in the directory. writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, "... listing directory ", 0); writeMessageW(props, OUTPUT_LEVEL_DEBUG, 0, startDir, 1); while (FindNextFileW(hFind, &FindFileData) != 0 && isOK(props)) { if(lstrcmpW(FindFileData.cFileName, L".")!=0 && lstrcmpW(FindFileData.cFileName, L"..")!=0) { WCHAR * child = NULL; child = appendStringW(appendStringW(appendStringW(NULL, startDir), FILE_SEP), FindFileData.cFileName); if(isDirectory(child)) { writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, "... directory : ", 0); writeMessageW(props, OUTPUT_LEVEL_DEBUG, 0, child, 1); unpackJars(props, jvmDir, child, unpack200exe); } else if(searchW(FindFileData.cFileName, JAR_PACK_GZ_SUFFIX)!=NULL) { WCHAR * jarName = appendStringW(appendStringW( appendStringW(NULL, startDir), FILE_SEP), appendStringNW(NULL, 0, FindFileData.cFileName, getLengthW(FindFileData.cFileName) - getLengthW(PACK_GZ_SUFFIX))); WCHAR * unpackCommand = NULL; writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, "... packed jar : ", 0); writeMessageW(props, OUTPUT_LEVEL_DEBUG, 0, child, 1); writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, "... jar name : ", 0); writeMessageW(props, OUTPUT_LEVEL_DEBUG, 0, jarName, 1); appendCommandLineArgument(&unpackCommand, unpack200exe); appendCommandLineArgument(&unpackCommand, child); appendCommandLineArgument(&unpackCommand, jarName); executeCommand(props, unpackCommand, NULL, UNPACK200_EXTRACTION_TIMEOUT, props->stdoutHandle, props->stderrHandle, NORMAL_PRIORITY_CLASS); FREE(unpackCommand); if(!isOK(props)) { if(props->status==ERROR_PROCESS_TIMEOUT) { writeMessageA(props, OUTPUT_LEVEL_DEBUG, 1, "... could not unpack file : timeout", 1); } else { writeMessageA(props, OUTPUT_LEVEL_DEBUG, 1, "... an error occured unpacking the file", 1); } props->exitCode = props->status; } FREE(jarName); } FREE(child); } } dwError = GetLastError(); FindClose(hFind); if (dwError != ERROR_NO_MORE_FILES) { writeErrorA(props, OUTPUT_LEVEL_DEBUG, 1, "Error! Can`t find file with pattern : ", DirSpec, dwError); } } FREE(DirSpec); } }