void readString(LauncherProperties * props, SizedString * result, DWORD isUnicode) { DWORD * status = & props->status; HANDLE hFileRead = props->handler; SizedString * rest = props->restOfBytes; DWORD bufferSize = props->bufsize; DWORD read=0; char * buf = NULL; if(*status != ERROR_OK ) return; if(readStringFromBuf(rest, result, isUnicode)==ERROR_OK) { return; } //we need to read file for more data to find \0 character... buf = newpChar(bufferSize); while (ReadFile(hFileRead, buf, bufferSize, &read, 0) && read) { addProgressPosition(props, read); rest->bytes = appendStringN(rest->bytes, rest->length, buf, read); rest->length = rest->length + read; if(readStringFromBuf(rest, result, isUnicode)==ERROR_OK) { //if(result->bytes!=NULL) { //we have find \0 character break; } ZERO(buf, sizeof(char) * bufferSize); if(read==0) { // we have nothing to read.. smth wrong *status = ERROR_INTEGRITY; break; } } FREE(buf); return; }
DWORD readStringFromBuf(SizedString *rest, SizedString * result, DWORD isUnicode) { if((rest->length)!=0) { // we have smth in the restBytes that we have read but haven`t yet proceeded DWORD i=0; for(i=0;i<rest->length;i++) { DWORD check = ((rest->bytes)[i]==0); if(isUnicode) { if ( (i/2)*2==i) {// i is even check = check && (i < rest->length-1 && ((rest->bytes)[i+1]==0)); } else { check = 0; } } if( check ) { // we have found null character in the rest bytes result->bytes = appendStringN(NULL, 0, rest->bytes, i); result->length = i; modifyRestBytes(rest, i + 1 + isUnicode); return ERROR_OK; } } //here we have found no \0 character in the rest of bytes... } return ERROR_INPUTOUPUT; }
DWORD getJavaPropertiesFromOutput(LauncherProperties * props, char *str, JavaProperties ** javaProps) { DWORD separators = getLineSeparatorNumber(str); DWORD result = ERROR_INPUTOUPUT; * javaProps = NULL; if(separators == TEST_JAVA_PARAMETERS) { char * start; char * end; char * javaVersion; char * javaVmVersion; char * javaVendor; char * osName; char * osArch; char * string; JavaVersion * vers; start = str; end = searchA(start, "\n"); javaVersion = appendStringN(NULL, 0, start, getLengthA(start) - getLengthA(end)-1); writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, " java.version = ", 0); writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, javaVersion, 1); start = end + 1; end = searchA(start, "\n"); javaVmVersion = appendStringN(NULL, 0, start, getLengthA(start) - getLengthA(end)-1); writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, " java.vm.version = ", 0); writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, javaVmVersion, 1); start = end + 1; end = searchA(start, "\n"); javaVendor = appendStringN(NULL, 0, start, getLengthA(start) - getLengthA(end)-1); writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, " java.vendor = ", 0); writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, javaVendor, 1); start = end + 1; end = searchA(start, "\n"); osName = appendStringN(NULL, 0, start, getLengthA(start) - getLengthA(end)-1); writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, " os.name = ", 0); writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, osName, 1); start = end + 1; end = searchA(start, "\n"); osArch = appendStringN(NULL, 0, start, getLengthA(start) - getLengthA(end)-1); writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, " os.arch = ", 0); writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, osArch, 2); string = javaVersion; if(javaVmVersion!=NULL) { string = searchA(javaVmVersion, javaVersion); if(string==NULL) { string = javaVersion; } } writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, "... getting java version from string : ", 0); writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, string, 1); vers = getJavaVersionFromString(string, & result); if(javaProps != NULL) { writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, "... some java there", 1); * javaProps = (JavaProperties *) LocalAlloc(LPTR, sizeof(JavaProperties)); (*javaProps)->version = vers; (*javaProps)->vendor = javaVendor; (*javaProps)->osName = osName; (*javaProps)->osArch = osArch; (*javaProps)->javaHome = NULL; (*javaProps)->javaExe = NULL; } else { writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, "... no java there", 1); FREE(javaVendor); FREE(osName); FREE(osArch); } FREE(javaVmVersion); FREE(javaVersion); } return result; }