modules/fxpackager/src/main/native/library/common/WindowsPlatform.cpp

Print this page

        

*** 177,186 **** --- 177,191 ---- // HKLM\Software\JavaSoft\Java Runtime Environment\CurrentVersion // HKLM\Software\JavaSoft\Java Runtime Environment\[CurrentVersion]\JavaHome // return TRUE if found, and path is set in lpszJavaHome // return FALSE otherwise TString WindowsPlatform::GetSystemJRE() { + if (GetAppCDSState() == cdsOn || GetAppCDSState() == cdsGenCache) { + //TODO throw exception + return _T(""); + } + TString result; Registry registry(HKEY_LOCAL_MACHINE); if (registry.Open(JAVA_RUNTIME_SUBKEY) == true) { TString version = registry.ReadString(_T("CurrentVersion"));
*** 204,233 **** } void WindowsPlatform::ShowMessage(TString description) { TString appname = GetModuleFileName(); appname = FilePath::ExtractFileName(appname); ! MessageBox(NULL, appname.data(), description.data(), MB_ICONERROR | MB_OK); } TString WindowsPlatform::GetBundledJVMLibraryFileName(TString RuntimePath) { ! TString result = FilePath::IncludeTrailingSlash(RuntimePath) + _T("jre\\bin\\client\\jvm.dll"); if (FilePath::FileExists(result) == false) { ! result = FilePath::IncludeTrailingSlash(RuntimePath) + _T("jre\\bin\\server\\jvm.dll"); } if (FilePath::FileExists(result) == false) { ! result = FilePath::IncludeTrailingSlash(RuntimePath) + _T("bin\\client\\jvm.dll"); } if (FilePath::FileExists(result) == false) { ! result = FilePath::IncludeTrailingSlash(RuntimePath) + _T("bin\\server\\jvm.dll"); } return result; } --- 209,254 ---- } void WindowsPlatform::ShowMessage(TString description) { TString appname = GetModuleFileName(); appname = FilePath::ExtractFileName(appname); ! MessageBox(NULL, description.data(), appname.data(), MB_ICONERROR | MB_OK); ! } ! ! MessageResponse WindowsPlatform::ShowResponseMessage(TString title, TString description) { ! MessageResponse result = mrCancel; ! ! if (::MessageBox(NULL, description.data(), title.data(), MB_OKCANCEL) == IDOK) { ! result = mrOK; ! } ! ! return result; } + //MessageResponse WindowsPlatform::ShowResponseMessage(TString description) { + // TString appname = GetModuleFileName(); + // appname = FilePath::ExtractFileName(appname); + // return ShowResponseMessage(appname, description); + //} + TString WindowsPlatform::GetBundledJVMLibraryFileName(TString RuntimePath) { ! TString result = FilePath::IncludeTrailingSeparater(RuntimePath) + _T("jre\\bin\\client\\jvm.dll"); if (FilePath::FileExists(result) == false) { ! result = FilePath::IncludeTrailingSeparater(RuntimePath) + _T("jre\\bin\\server\\jvm.dll"); } if (FilePath::FileExists(result) == false) { ! result = FilePath::IncludeTrailingSeparater(RuntimePath) + _T("bin\\client\\jvm.dll"); } if (FilePath::FileExists(result) == false) { ! result = FilePath::IncludeTrailingSeparater(RuntimePath) + _T("bin\\server\\jvm.dll"); } return result; }
*** 241,252 **** } return result; } ! PropertyContainer* WindowsPlatform::GetConfigFile(TString FileName) { ! return new PropertyFile(FileName); } TString WindowsPlatform::GetModuleFileName() { TString result; DynamicBuffer<wchar_t> buffer(MAX_PATH); --- 262,280 ---- } return result; } ! ISectionalPropertyContainer* WindowsPlatform::GetConfigFile(TString FileName) { ! IniFile *result = new IniFile(); ! ! if (result->LoadFromFile(FileName) == false) { ! // New property file format was not found, attempt to load old property file format. ! Helpers::LoadOldConfigFile(FileName, result); ! } ! ! return result; } TString WindowsPlatform::GetModuleFileName() { TString result; DynamicBuffer<wchar_t> buffer(MAX_PATH);
*** 315,332 **** TString runtimeDir = macros.ExpandMacros(package.GetJVMRuntimeDirectory()); std::vector<TString> filelist = FilterList(Imports, std::wregex(_T("MSVCR.*.DLL"), std::regex_constants::icase)); for (std::vector<TString>::iterator it = filelist.begin(); it != filelist.end(); ++it) { TString filename = *it; ! TString msvcr100FileName = FilePath::IncludeTrailingSlash(runtimeDir) + _T("jre\\bin\\") + filename; if (FilePath::FileExists(msvcr100FileName) == true) { result.push_back(msvcr100FileName); break; } else { ! msvcr100FileName = FilePath::IncludeTrailingSlash(runtimeDir) + _T("bin\\") + filename; if (FilePath::FileExists(msvcr100FileName) == true) { result.push_back(msvcr100FileName); break; } --- 343,360 ---- TString runtimeDir = macros.ExpandMacros(package.GetJVMRuntimeDirectory()); std::vector<TString> filelist = FilterList(Imports, std::wregex(_T("MSVCR.*.DLL"), std::regex_constants::icase)); for (std::vector<TString>::iterator it = filelist.begin(); it != filelist.end(); ++it) { TString filename = *it; ! TString msvcr100FileName = FilePath::IncludeTrailingSeparater(runtimeDir) + _T("jre\\bin\\") + filename; if (FilePath::FileExists(msvcr100FileName) == true) { result.push_back(msvcr100FileName); break; } else { ! msvcr100FileName = FilePath::IncludeTrailingSeparater(runtimeDir) + _T("bin\\") + filename; if (FilePath::FileExists(msvcr100FileName) == true) { result.push_back(msvcr100FileName); break; }
*** 334,343 **** --- 362,375 ---- } return result; } + Process* WindowsPlatform::CreateProcess() { + return new WindowsProcess(); + } + #ifdef DEBUG bool WindowsPlatform::IsNativeDebuggerPresent() { bool result = false; if (IsDebuggerPresent() == TRUE) {
*** 437,463 **** TString registryKey = TString(_T("SOFTWARE\\JavaSoft\\Prefs\\")) + lappid + TString(_T("\\/J/V/M/User/Options")); Registry registry(HKEY_CURRENT_USER); if (registry.Open(registryKey) == true) { std::list<TString> keys = registry.GetKeys(); ! TOrderedMap mapOfKeysAndValues; ! int index = 1; for (std::list<TString>::const_iterator iterator = keys.begin(); iterator != keys.end(); iterator++) { TString key = *iterator; TString value = registry.ReadString(key); key = ConvertJavaEcodedStringToString(key); value = ConvertJavaEcodedStringToString(value); if (key.empty() == false) { ! TValueIndex item; ! item.value = value; ! item.index = index; ! ! mapOfKeysAndValues.insert(TOrderedMap::value_type(key, item)); result = true; - index++; } } FMap = mapOfKeysAndValues; } --- 469,489 ---- TString registryKey = TString(_T("SOFTWARE\\JavaSoft\\Prefs\\")) + lappid + TString(_T("\\/J/V/M/User/Options")); Registry registry(HKEY_CURRENT_USER); if (registry.Open(registryKey) == true) { std::list<TString> keys = registry.GetKeys(); ! OrderedMap<TString, TString> mapOfKeysAndValues; for (std::list<TString>::const_iterator iterator = keys.begin(); iterator != keys.end(); iterator++) { TString key = *iterator; TString value = registry.ReadString(key); key = ConvertJavaEcodedStringToString(key); value = ConvertJavaEcodedStringToString(value); if (key.empty() == false) { ! mapOfKeysAndValues.Append(key, value); result = true; } } FMap = mapOfKeysAndValues; }
*** 628,633 **** --- 654,795 ---- return result; } //-------------------------------------------------------------------------------------------------- + #include <TlHelp32.h> + + WindowsJob::WindowsJob() { + FHandle = NULL; + } + + WindowsJob::~WindowsJob() { + if (FHandle != NULL) { + CloseHandle(FHandle); + } + } + + HANDLE WindowsJob::GetHandle() { + if (FHandle == NULL) { + FHandle = CreateJobObject(NULL, NULL); // GLOBAL + + if (FHandle == NULL) + { + ::MessageBox( 0, _T("Could not create job object"), _T("TEST"), MB_OK); + } + else + { + JOBOBJECT_EXTENDED_LIMIT_INFORMATION jeli = { 0 }; + + // Configure all child processes associated with the job to terminate when the + jeli.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; + if (0 == SetInformationJobObject(FHandle, JobObjectExtendedLimitInformation, &jeli, sizeof(jeli))) + { + ::MessageBox( 0, _T("Could not SetInformationJobObject"), _T("TEST"), MB_OK); + } + } + } + + return FHandle; + } + + // Initialize static member of WindowsProcess + WindowsJob WindowsProcess::FJob; + + WindowsProcess::WindowsProcess() : Process() { + FRunning = false; + } + + WindowsProcess::~WindowsProcess() { + Terminate(); + } + + void WindowsProcess::Cleanup() { + CloseHandle(FProcessInfo.hProcess); + CloseHandle(FProcessInfo.hThread); + } + + bool WindowsProcess::IsRunning() { + bool result = false; + + HANDLE handle = ::CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0); + PROCESSENTRY32 process = { 0 }; + process.dwSize = sizeof(process); + + if (::Process32First(handle, &process)) { + do { + if (process.th32ProcessID == FProcessInfo.dwProcessId) { + result = true; + break; + } + } + while (::Process32Next(handle, &process)); + } + + CloseHandle(handle); + + return result; + } + + bool WindowsProcess::Terminate() { + bool result = false; + + if (IsRunning() == true && FRunning == true) { + FRunning = false; + } + + return result; + } + + bool WindowsProcess::Execute(const TString Application, const std::vector<TString> Arguments, bool AWait) { + bool result = false; + + if (FRunning == false) { + FRunning = true; + + STARTUPINFO startupInfo; + ZeroMemory(&startupInfo, sizeof(startupInfo)); + startupInfo.cb = sizeof(startupInfo); + ZeroMemory(&FProcessInfo, sizeof(FProcessInfo)); + + TString command = Application; + + for (std::vector<TString>::const_iterator iterator = Arguments.begin(); iterator != Arguments.end(); iterator++) { + command += TString(_T(" ")) + *iterator; + } + + if (::CreateProcess(Application.data(), (wchar_t*)command.data(), NULL, + NULL, FALSE, 0, NULL, NULL, &startupInfo, &FProcessInfo) == TRUE) { + TString message = PlatformString::Format(_T("Error: Unable to create process %s"), Application.data()); + throw Exception(message); + } + else { + if (FJob.GetHandle() != NULL) { + if (::AssignProcessToJobObject(FJob.GetHandle(), FProcessInfo.hProcess) == 0) { + // Failed to assign process to job. It doesn't prevent anything from continuing so continue. + } + } + + // Wait until child process exits. + if (AWait == true) { + Wait(); + // Close process and thread handles. + Cleanup(); + } + } + } + + return result; + } + + bool WindowsProcess::Wait() { + bool result = false; + + WaitForSingleObject(FProcessInfo.hProcess, INFINITE); + return result; + } + + TProcessID WindowsProcess::GetProcessID() { + return FProcessInfo.dwProcessId; + } + #endif //WINDOWS