154 void WindowsPlatform::SetCurrentDirectory(TString Value) { 155 _wchdir(Value.data()); 156 } 157 158 TString WindowsPlatform::GetPackageRootDirectory() { 159 TString filename = GetModuleFileName(); 160 return FilePath::ExtractFilePath(filename); 161 } 162 163 TString WindowsPlatform::GetAppDataDirectory() { 164 TString result; 165 TCHAR path[MAX_PATH]; 166 167 if (SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, path) == S_OK) { 168 result = path; 169 } 170 171 return result; 172 } 173 174 #define BUFFER_SIZE 256 175 176 // try to find current Java Home from registry 177 // 178 // HKLM\Software\JavaSoft\Java Runtime Environment\CurrentVersion 179 // HKLM\Software\JavaSoft\Java Runtime Environment\[CurrentVersion]\JavaHome 180 // 181 // note that this has been changed in JDK9 to 182 // 183 // HKLM\Software\JavaSoft\JRE\CurrentVersion 184 // HKLM\Software\JavaSoft\JRE\[CurrentVersion]\JavaHome 185 // 186 // return non-empty string as path if found 187 // return empty string otherwise 188 189 TString GetSystemJREForSubkey(TString javaRuntimeSubkey) { 190 Registry registry(HKEY_LOCAL_MACHINE); 191 TString result; 192 193 if (registry.Open(javaRuntimeSubkey)) { 194 TString version = registry.ReadString(_T("CurrentVersion")); 195 196 if (!version.empty()) { 197 if (registry.Open(javaRuntimeSubkey + TString(_T("\\")) + TString(version))) { 198 TString javaHome = registry.ReadString(_T("JavaHome")); 199 200 if (FilePath::DirectoryExists(javaHome)) { 201 result = javaHome; 202 } 203 } 204 } 205 } 206 207 return result; 208 } 209 210 TString WindowsPlatform::GetSystemJRE() { 211 if (GetAppCDSState() != cdsDisabled) { 212 //TODO throw exception 213 return _T(""); 214 } 215 216 TString result; 217 result = GetSystemJREForSubkey(_T("SOFTWARE\\JavaSoft\\JRE")); 218 if (!result.empty()) { 219 return result; 220 } 221 222 result = GetSystemJREForSubkey(_T("SOFTWARE\\JavaSoft\\Java Runtime Environment")); 223 if (!result.empty()) { 224 return result; 225 } 226 227 return result; 228 } 229 230 void WindowsPlatform::ShowMessage(TString title, TString description) { 231 MessageBox(NULL, description.data(), !title.empty() ? title.data() : description.data(), MB_ICONERROR | MB_OK); 232 } 233 234 void WindowsPlatform::ShowMessage(TString description) { 235 TString appname = GetModuleFileName(); 236 appname = FilePath::ExtractFileName(appname); 237 MessageBox(NULL, description.data(), appname.data(), MB_ICONERROR | MB_OK); 238 } 239 240 MessageResponse WindowsPlatform::ShowResponseMessage(TString title, TString description) { 241 MessageResponse result = mrCancel; 242 243 if (::MessageBox(NULL, description.data(), title.data(), MB_OKCANCEL) == IDOK) { 244 result = mrOK; 245 } 246 247 return result; 248 } 249 250 //MessageResponse WindowsPlatform::ShowResponseMessage(TString description) { 251 // TString appname = GetModuleFileName(); 252 // appname = FilePath::ExtractFileName(appname); 253 // return ShowResponseMessage(appname, description); 254 //} 255 256 TString WindowsPlatform::GetBundledJVMLibraryFileName(TString RuntimePath) { 257 TString result = FilePath::IncludeTrailingSeparater(RuntimePath) + 258 _T("jre\\bin\\jli.dll"); 259 260 if (FilePath::FileExists(result) == false) { 261 result = FilePath::IncludeTrailingSeparater(RuntimePath) + 262 _T("bin\\jli.dll"); 263 } 264 265 return result; 266 } 267 268 TString WindowsPlatform::GetSystemJVMLibraryFileName() { 269 TString result; 270 TString jvmPath = GetSystemJRE(); 271 272 if (jvmPath.empty() == false) { 273 result = GetBundledJVMLibraryFileName(jvmPath); 274 } 275 276 return result; 277 } 278 279 ISectionalPropertyContainer* WindowsPlatform::GetConfigFile(TString FileName) { 280 IniFile *result = new IniFile(); 281 282 if (result->LoadFromFile(FileName) == false) { 283 // New property file format was not found, attempt to load old property file format. 284 Helpers::LoadOldConfigFile(FileName, result); 285 } 286 287 return result; 288 } 289 290 TString WindowsPlatform::GetModuleFileName() { 291 TString result; 292 DynamicBuffer<wchar_t> buffer(MAX_PATH); 293 ::GetModuleFileName(NULL, buffer.GetData(), buffer.GetSize()); 294 295 while (ERROR_INSUFFICIENT_BUFFER == GetLastError()) { 296 buffer.Resize(buffer.GetSize() * 2); 297 ::GetModuleFileName(NULL, buffer.GetData(), buffer.GetSize()); 298 } | 154 void WindowsPlatform::SetCurrentDirectory(TString Value) { 155 _wchdir(Value.data()); 156 } 157 158 TString WindowsPlatform::GetPackageRootDirectory() { 159 TString filename = GetModuleFileName(); 160 return FilePath::ExtractFilePath(filename); 161 } 162 163 TString WindowsPlatform::GetAppDataDirectory() { 164 TString result; 165 TCHAR path[MAX_PATH]; 166 167 if (SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, path) == S_OK) { 168 result = path; 169 } 170 171 return result; 172 } 173 174 void WindowsPlatform::ShowMessage(TString title, TString description) { 175 MessageBox(NULL, description.data(), !title.empty() ? title.data() : description.data(), MB_ICONERROR | MB_OK); 176 } 177 178 void WindowsPlatform::ShowMessage(TString description) { 179 TString appname = GetModuleFileName(); 180 appname = FilePath::ExtractFileName(appname); 181 MessageBox(NULL, description.data(), appname.data(), MB_ICONERROR | MB_OK); 182 } 183 184 MessageResponse WindowsPlatform::ShowResponseMessage(TString title, TString description) { 185 MessageResponse result = mrCancel; 186 187 if (::MessageBox(NULL, description.data(), title.data(), MB_OKCANCEL) == IDOK) { 188 result = mrOK; 189 } 190 191 return result; 192 } 193 194 //MessageResponse WindowsPlatform::ShowResponseMessage(TString description) { 195 // TString appname = GetModuleFileName(); 196 // appname = FilePath::ExtractFileName(appname); 197 // return ShowResponseMessage(appname, description); 198 //} 199 200 TString WindowsPlatform::GetBundledJVMLibraryFileName(TString RuntimePath) { 201 TString result = FilePath::IncludeTrailingSeparater(RuntimePath) + 202 _T("jre\\bin\\jli.dll"); 203 204 if (FilePath::FileExists(result) == false) { 205 result = FilePath::IncludeTrailingSeparater(RuntimePath) + 206 _T("bin\\jli.dll"); 207 } 208 209 return result; 210 } 211 212 ISectionalPropertyContainer* WindowsPlatform::GetConfigFile(TString FileName) { 213 IniFile *result = new IniFile(); 214 215 if (result->LoadFromFile(FileName) == false) { 216 // New property file format was not found, attempt to load old property file format. 217 Helpers::LoadOldConfigFile(FileName, result); 218 } 219 220 return result; 221 } 222 223 TString WindowsPlatform::GetModuleFileName() { 224 TString result; 225 DynamicBuffer<wchar_t> buffer(MAX_PATH); 226 ::GetModuleFileName(NULL, buffer.GetData(), buffer.GetSize()); 227 228 while (ERROR_INSUFFICIENT_BUFFER == GetLastError()) { 229 buffer.Resize(buffer.GetSize() * 2); 230 ::GetModuleFileName(NULL, buffer.GetData(), buffer.GetSize()); 231 } |