Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit

Permalink
8250611: Cannot display splash screen on Windows
Browse files Browse the repository at this point in the history
Reviewed-by: asemenyuk, almatvee, prr
  • Loading branch information
Andy Herrick committed Aug 17, 2020
1 parent 178c45c commit e20fe4a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ Jvm& Jvm::initFromConfigFile(const CfgFile& cfgFile) {
if (splash != appOptions.end()) {
const tstring splashPath = CfgFile::asString(*splash);
if (FileUtils::isFileExists(splashPath)) {
addArgument(_T("-splash"));
addArgument(splashPath);
addArgument(_T("-splash:") + splashPath);
} else {
LOG_WARNING(tstrings::any()
<< "Splash property ignored. File \""
Expand Down Expand Up @@ -138,6 +137,18 @@ Jvm& Jvm::initFromConfigFile(const CfgFile& cfgFile) {
}


bool Jvm::isWithSplash() const {
tstring_array::const_iterator it = args.begin();
const tstring_array::const_iterator end = args.end();
for (; it != end; ++it) {
if (tstrings::startsWith(*it, _T("-splash:"))) {
return true;
}
}
return false;
}


namespace {
void convertArgs(const std::vector<std::string>& args, std::vector<char*>& argv) {
argv.reserve(args.size() + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class Jvm {
return jvmPath;
}

bool isWithSplash() const;

void launch();

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,47 @@ std::unique_ptr<Dll> loadDllWithAddDllDirectory(const tstring& dllFullPath) {
return std::unique_ptr<Dll>(new Dll(dllFullPath));
}


class DllWrapper {
public:
DllWrapper(const tstring& dllName) {
try {
// Try load DLL.
dll = std::unique_ptr<Dll>(new Dll(dllName));
LOG_TRACE(tstrings::any() << "Load [" << dllName << "]: OK");
}
catch (const std::exception&) {
// JVM DLL load failed, though it exists in file system.
try {
// Try adjust the DLL search paths with AddDllDirectory() WINAPI CALL
dll = loadDllWithAddDllDirectory(dllName);
}
catch (const std::exception&) {
// AddDllDirectory() didn't work. Try altering PATH environment
// variable as the last resort.
dll = loadDllWithAlteredPATH(dllName);
}
}
}

private:
DllWrapper(const DllWrapper&);
DllWrapper& operator=(const DllWrapper&);

private:
std::unique_ptr<Dll> dll;
};


tstring getJvmLibPath(const Jvm& jvm) {
FileUtils::mkpath path;

path << FileUtils::dirname(jvm.getPath()) << _T("server") << _T("jvm.dll");

return path;
}


void launchApp() {
// [RT-31061] otherwise UI can be left in back of other windows.
::AllowSetForegroundWindow(ASFW_ANY);
Expand All @@ -115,20 +156,14 @@ void launchApp() {
<< _T("runtime"))
.createJvmLauncher());

std::unique_ptr<Dll> jvmDll;
try {
// Try load JVM DLL.
jvmDll = std::unique_ptr<Dll>(new Dll(jvm->getPath()));
} catch (const std::exception&) {
// JVM DLL load failed, though it exists in file system.
try {
// Try adjust the DLL search paths with AddDllDirectory() WINAPI CALL
jvmDll = loadDllWithAddDllDirectory(jvm->getPath());
} catch (const std::exception&) {
// AddDllDirectory() didn't work. Try altering PATH environment
// variable as the last resort.
jvmDll = loadDllWithAlteredPATH(jvm->getPath());
}
const DllWrapper jliDll(jvm->getPath());
std::unique_ptr<DllWrapper> splashDll;
if (jvm->isWithSplash()) {
const DllWrapper jvmDll(getJvmLibPath(*jvm));
splashDll = std::unique_ptr<DllWrapper>(new DllWrapper(
FileUtils::mkpath()
<< FileUtils::dirname(jvm->getPath())
<< _T("splashscreen.dll")));
}

jvm->launch();
Expand Down

0 comments on commit e20fe4a

Please sign in to comment.