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
|
||||
/*.so
|
||||
/*.dylib
|
||||
/natives/
|
||||
|
||||
# Log files
|
||||
*.log
|
||||
|
||||
@ -122,10 +122,14 @@ object UiHandler extends Logging {
|
||||
}
|
||||
}
|
||||
|
||||
var tempDir: String = _
|
||||
var nativeLibrariesDir: String = _
|
||||
|
||||
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 is64bit = arch.startsWith("amd64")
|
||||
@ -146,16 +150,19 @@ object UiHandler extends Logging {
|
||||
throw new Exception("Unsupported OS")
|
||||
|
||||
for (lib <- libs) {
|
||||
val dest = new File(Paths.get(nativeLibrariesDir, lib).toString)
|
||||
if (!dest.exists()) {
|
||||
val source = getClass.getResourceAsStream("/" + lib)
|
||||
val dest = new File(Paths.get(tempDir, lib).toString)
|
||||
if (!dest.getParentFile.exists()) dest.getParentFile.mkdirs()
|
||||
val output = new FileOutputStream(dest)
|
||||
output.getChannel.transferFrom(Channels.newChannel(source), 0, Long.MaxValue)
|
||||
output.flush()
|
||||
output.close()
|
||||
source.close()
|
||||
}
|
||||
}
|
||||
|
||||
System.setProperty("org.lwjgl.librarypath", tempDir)
|
||||
System.setProperty("org.lwjgl.librarypath", nativeLibrariesDir)
|
||||
}
|
||||
|
||||
private def loadIcons(): Unit = {
|
||||
@ -238,7 +245,8 @@ object UiHandler extends Logging {
|
||||
if (!audioDisabled)
|
||||
AL.destroy()
|
||||
|
||||
FileUtils.deleteDirectory(new File(tempDir))
|
||||
if (!SystemUtils.IS_OS_WINDOWS)
|
||||
FileUtils.deleteDirectory(new File(nativeLibrariesDir))
|
||||
}
|
||||
|
||||
private def update(): Unit = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user