📄 jnlp2msi.cpp
字号:
lpszUpdVersionInfo[milestoneInfo - versionInfo - 1] = '\0'; } strncpy(lpszFullVersionInfo, versionInfo + 1, endInfo - versionInfo - 1); lpszFullVersionInfo[endInfo - versionInfo - 1] = '\0'; const char* updateInfo = strstr(lpszUpdVersionInfo, "_"); if (updateInfo == NULL) { strcpy(lpszVersionInfo, lpszUpdVersionInfo); } else { strncpy(lpszVersionInfo, lpszUpdVersionInfo, updateInfo-lpszUpdVersionInfo); lpszVersionInfo[updateInfo - lpszUpdVersionInfo] = '\0'; } // If Java Version >= 1.5.0 if (0 > strncmp(lpszVersionInfo, "1.5.0", strlen("1.5.0"))) ret = false; } CloseHandle(hread[0]); CloseHandle(hread[1]); CloseHandle(hread[2]); CloseHandle(hwrite[0]); CloseHandle(hwrite[1]); CloseHandle(hwrite[2]); CloseHandle(pi.hThread); CloseHandle(pi.hProcess); return ret;}///////////////////////////////////////////////////////////////////////////////** * Check whether we've got the correct Java version */int checkJavaVersion(void){ char* pJavaExe = NULL; // If there is java.exe in system32\ or system\, check it if (NULL != (pJavaExe = getenv("windir"))) if (isJavaVersionOK(pJavaExe, "system")) return JAVA_EXE_IN_SYSTEM; else if (isJavaVersionOK(pJavaExe, "system32")) return JAVA_EXE_IN_SYSTEM32; // If there is java.exe in JAVA_HOME, check it if ( (NULL != (pJavaExe = getenv("JAVA_HOME"))) && isJavaVersionOK(pJavaExe, "bin") ) return JAVA_EXE_IN_JAVA_HOME; return 0;}///////////////////////////////////////////////////////////////////////////////** * Launch java to create the destination msi */int launchJava(int iLevel){ char JavaPath[BUFFER_SIZE] = {0}; char* pJavaPath = NULL; switch(iLevel) { case JAVA_EXE_IN_SYSTEM: if (NULL == (pJavaPath = getenv("windir"))) return -1; strncpy(JavaPath, pJavaPath, sizeof(JavaPath)-1); strcat(JavaPath, "\\system\\java.exe"); break; case JAVA_EXE_IN_SYSTEM32: if (NULL == (pJavaPath = getenv("windir"))) return -1; strncpy(JavaPath, pJavaPath, sizeof(JavaPath)-1); strcat(JavaPath, "\\system32\\java.exe"); break; case JAVA_EXE_IN_JAVA_HOME: if (NULL == (pJavaPath = getenv("JAVA_HOME"))) return -1; strncpy(JavaPath, pJavaPath, sizeof(JavaPath)-1); strcat(JavaPath, "\\bin\\java.exe"); break; default: return -1; } // fork a process to launch the java program STARTUPINFO stinfo = {0}; //info of the window stinfo.cb = sizeof(STARTUPINFO); PROCESS_INFORMATION procinfo; //info of the process char CREATEPROCESS[BUFFER_SIZE]; if (mssdkpathSetByUser) { sprintf(CREATEPROCESS, "%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s", JavaPath, optValues[ResourceDir], optValues[PackageName], optValues[OutputDir], optValues[Version], optValues[Release], optValues[LicenseDir], optValues[BannerJpgFile], optValues[PanelJpgFile], optValues[MSSDKPath], optValues[EnableShortcut], optValues[EnableAssociation], optValues[EnableSystemCache], ClassName, JnlpFile); } else if (mssdkpathSetByEnv) { sprintf(CREATEPROCESS, "%s %s %s %s %s %s %s %s %s %s%s%s %s %s %s %s %s", JavaPath, optValues[ResourceDir], optValues[PackageName], optValues[OutputDir], optValues[Version], optValues[Release], optValues[LicenseDir], optValues[BannerJpgFile], optValues[PanelJpgFile], "-DMSSDKDir=\"", mssdkEnvVar, "\"", optValues[EnableShortcut], optValues[EnableAssociation], optValues[EnableSystemCache], ClassName, JnlpFile); } if (echoJavaCmd) { printf("%s\n", CREATEPROCESS); } if(!CreateProcess(NULL, CREATEPROCESS, NULL, NULL, FALSE, NULL, NULL, NULL, &stinfo, &procinfo)) { return -1; } // wait for the end of the process WaitForSingleObject(procinfo.hProcess, INFINITE); CloseHandle(procinfo.hProcess); CloseHandle(procinfo.hThread); return 0;}void printUsage(){ fprintf(stdout, "jnlp2msi: JDIC packaging tool to package a Java Webstart application into\n" " Windows MSI file.(The output will be in executable bootstrapper\n" " format.)\n" "\n" "Note: This tool requires J2SE 1.5.0+, Microsoft Windows SDK Update Package.\n" "\n" "Usage: jnlp2msi [-options] <Jnlp File Path>\n" "\n" "Where <Jnlp File Path>\n" " is the path of the Jnlp file to be packaged.\n" "\n" "Options include:\n" " -msd <value> | -mssdkdir <value>\n" " set the directory where the Windows MS SDK update package\n" " gets installed. If this option is not specified, an environment\n" " variable MSSDKDir must be set to indicate the directory\n" " information. If both this option and MSSDKDir environment variable\n" " are set, the value of MSSDKDir environment variable will be ignored.\n" " -rd <value> | -resourcedir <value>\n" " set the directory of the JNLP resource files, the default value\n" " is the parent directory of the given JNLP file.\n" " -ld <value> | -licensedir <value>\n" " set the directory of the license files.\n" " -pn <value> | -packagename <value>\n" " set the name of the generated MSI package file, the default\n" " value is the jnlp file name without any extension.\n" " -od <value> | -outputdir <value>\n" " set the directory of the generated MSI file, the default value\n" " is the current directory.\n" " -v <value> | -version <value>\n" " set the version number of the generated MSI package, the default\n" " value is 1.0.\n" " -r <value> | -release <value>\n" " set the release number of the generated MSI package, the default\n" " value is 1.0.\n" " -bjf <value> | -bannerjpgfile <value>\n" " set the path of the jpeg file that will be used as the banner\n" " part of the MSI installation GUI. If not set, a jpeg\n" " picture contained in the jar file will be used.\n" " -pjf <value> | -paneljpgfile <value>\n" " set the path of the jpeg file that will be used as the panel\n" " part of the MSI installation GUI. If not set, a jpeg picture\n" " contained in the jar file will be used.\n" " -es | -enableshortcut\n" " create shortcut on the desktop and Start menu after the generated\n" " MSI gets installed.\n" " -ea | -enableassociation\n" " allow the JNLP application to associate itself with the file\n" " extension or mime-type specified by the the assoication tag in\n" " the jnlp file.\n" " -esc | -enablesystemcache\n" " install the JNLP application into the system cache of Java\n" " Webstart. By default, the application will be installed into\n" " the user cache.\n" " in order to install into the system cache, you need to configure\n" " the sytem cache accordingly. Please refer to Java Webstart documents.\n" " -sv | showversion\n" " print the current version info of jnlp2msi.\n" " -? | -help\n" " print this help message.\n" "\n" "Sample: jnlp2msi -msd \"C:\\Program Files\\Microsoft SDK\" d:\\draw.jnlp\n" " (if the MSSDKDir environment variable is not set.)\n" " or\n" " jnlp2msi d:\\draw.jnlp\n" " (if the MSSDKDir environment variable is set.)\n" "\n" );}void printVersion(){ fprintf(stdout, "jnlp2msi version %s build %s.\n" "Visit us at http://jdic.dev.java.net\n", MY_FULL_VERSION, MY_RELEASE_NO );}///////////////////////////////////////////////////////////////////////////////** * Program entry point. */int main(int argc, char* argv[]){ if (argc == 1) { printUsage(); return 1; } initOpts(); //Check if the MSSDKDir environment variable has been set char * temsdkVar = getenv("MSSDKDir"); if (temsdkVar != NULL) { mssdkpathSetByEnv = true; formatPathStr(temsdkVar, mssdkEnvVar); } int iLeft = 1; while (iLeft < argc) { int i = 0; for (; i < OPTS_COUNT; i++) { if (optprocess(sOpts[i], lOpts[i], optNames[i], optValues[i], argv, iLeft)) { if (echoVersion || echoHelp) { if (echoVersion) { printVersion(); } if (echoHelp) { printUsage(); } return 1; } break; } } if (i < OPTS_COUNT) { //one option gets handled in this loop continue; } else { //no option gets handled in this loop strncpy(JnlpFile, argv[iLeft++], sizeof(JnlpFile)-1); break; } } if ((!mssdkpathSetByUser) && (!mssdkpathSetByEnv)) { printUsage(); return -1; } if (JnlpFile[0] == 0) { printUsage(); return -1; } // Check whether the version of JDK is 1.5.0+ int iJavaPlace; if(0 == (iJavaPlace = checkJavaVersion())) { printf("This software runs only on JDK 1.5.0+, \n"); printf("Please install JDK 1.5.0+ into your system\n"); return -1; } if (0 != launchJava(iJavaPlace)) { printf("Create Java process failed!"); } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -