mirror of
https://gitlab.com/cc-ru/ocelot/ocelot-desktop.git
synced 2025-12-20 02:59:19 +01:00
Fix #16: crash when trying to clean native DLLs on Windows
This commit is contained in:
parent
f0dd326086
commit
e4e7aeb39d
1
.gitignore
vendored
1
.gitignore
vendored
@ -38,6 +38,7 @@ cacerts
|
|||||||
/*.dll
|
/*.dll
|
||||||
/*.so
|
/*.so
|
||||||
/*.dylib
|
/*.dylib
|
||||||
|
/natives/
|
||||||
|
|
||||||
# Log files
|
# Log files
|
||||||
*.log
|
*.log
|
||||||
|
|||||||
@ -122,10 +122,14 @@ object UiHandler extends Logging {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var tempDir: String = _
|
var nativeLibrariesDir: String = _
|
||||||
|
|
||||||
private def loadLibraries(): Unit = {
|
private def loadLibraries(): Unit = {
|
||||||
tempDir = Files.createTempDirectory("ocelot-desktop").toString
|
// we cannot remove DLL files on Windows after they were loaded by Ocelot
|
||||||
|
// therefore we will create them in local directory and keep for future
|
||||||
|
nativeLibrariesDir = if (SystemUtils.IS_OS_WINDOWS)
|
||||||
|
Paths.get(SystemUtils.USER_DIR, "natives").toString
|
||||||
|
else Files.createTempDirectory("ocelot-desktop").toString
|
||||||
|
|
||||||
val arch = System.getProperty("os.arch")
|
val arch = System.getProperty("os.arch")
|
||||||
val is64bit = arch.startsWith("amd64")
|
val is64bit = arch.startsWith("amd64")
|
||||||
@ -146,16 +150,19 @@ object UiHandler extends Logging {
|
|||||||
throw new Exception("Unsupported OS")
|
throw new Exception("Unsupported OS")
|
||||||
|
|
||||||
for (lib <- libs) {
|
for (lib <- libs) {
|
||||||
val source = getClass.getResourceAsStream("/" + lib)
|
val dest = new File(Paths.get(nativeLibrariesDir, lib).toString)
|
||||||
val dest = new File(Paths.get(tempDir, lib).toString)
|
if (!dest.exists()) {
|
||||||
val output = new FileOutputStream(dest)
|
val source = getClass.getResourceAsStream("/" + lib)
|
||||||
output.getChannel.transferFrom(Channels.newChannel(source), 0, Long.MaxValue)
|
if (!dest.getParentFile.exists()) dest.getParentFile.mkdirs()
|
||||||
output.flush()
|
val output = new FileOutputStream(dest)
|
||||||
output.close()
|
output.getChannel.transferFrom(Channels.newChannel(source), 0, Long.MaxValue)
|
||||||
source.close()
|
output.flush()
|
||||||
|
output.close()
|
||||||
|
source.close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.setProperty("org.lwjgl.librarypath", tempDir)
|
System.setProperty("org.lwjgl.librarypath", nativeLibrariesDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
private def loadIcons(): Unit = {
|
private def loadIcons(): Unit = {
|
||||||
@ -238,7 +245,8 @@ object UiHandler extends Logging {
|
|||||||
if (!audioDisabled)
|
if (!audioDisabled)
|
||||||
AL.destroy()
|
AL.destroy()
|
||||||
|
|
||||||
FileUtils.deleteDirectory(new File(tempDir))
|
if (!SystemUtils.IS_OS_WINDOWS)
|
||||||
|
FileUtils.deleteDirectory(new File(nativeLibrariesDir))
|
||||||
}
|
}
|
||||||
|
|
||||||
private def update(): Unit = {
|
private def update(): Unit = {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user