Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
skiko
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liuqiang
skiko
Commits
21526244
Commit
21526244
authored
Jul 29, 2020
by
Alexey Tsvetkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adjust Library after conversion to Kotlin
parent
24f1cecb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
37 deletions
+41
-37
Library.kt
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/Library.kt
+41
-37
No files found.
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/Library.kt
View file @
21526244
package
org.jetbrains.skiko
import
java.io.File
import
java.io.IOException
import
java.net.URISyntaxException
import
java.nio.file.Files
import
java.nio.file.StandardCopyOption
import
java.util.*
// based on https://github.com/JetBrains/skija/blob/bc6e0531021e4ff839c07196e0336d6456ed7520/src/main/java/org/jetbrains/skija/Library.java
object
Library
{
var
_
loaded
=
false
private
var
loaded
=
false
// https://github.com/adamheinrich/native-utils/blob/e6a39489662846a77504634b6fafa4995ede3b1d/src/main/java/cz/adamh/utils/NativeUtils.java
@Synchronized
fun
load
(
resourcePath
:
String
,
name
:
String
)
{
if
(
_loaded
)
return
try
{
var
file
:
File
val
fileName
=
_getPrefix
()
+
name
+
"."
+
_getExtension
()
val
url
=
Library
::
class
.
java
.
getResource
(
resourcePath
+
fileName
)
// System.out.println("Loading " + url);
requireNotNull
(
url
)
{
"Library $fileName is not found in $resourcePath"
}
if
(
url
.
protocol
===
"file"
)
file
=
try
{
// System.out.println("Loading " + url);
File
(
url
.
toURI
())
}
catch
(
e
:
URISyntaxException
)
{
throw
RuntimeException
(
e
)
}
else
url
.
openStream
().
use
{
`is`
->
val
tempDir
=
File
(
System
.
getProperty
(
"java.io.tmpdir"
),
"skija_"
+
System
.
nanoTime
())
tempDir
.
mkdirs
()
tempDir
.
deleteOnExit
()
file
=
File
(
tempDir
,
fileName
)
file
.
deleteOnExit
()
Files
.
copy
(
`is`
,
file
.
toPath
(),
StandardCopyOption
.
REPLACE_EXISTING
)
if
(
loaded
)
return
val
libFileName
=
"$libPrefix$name$libExtension"
val
url
=
Library
::
class
.
java
.
getResource
(
resourcePath
+
libFileName
)
// println("Loading " + url);
val
libFile
=
when
{
url
==
null
->
error
(
"Library $libFileName is not found in $resourcePath"
)
url
.
protocol
==
"file"
->
File
(
url
.
toURI
())
else
->
url
.
openStream
().
use
{
input
->
val
tempRoot
=
File
(
System
.
getProperty
(
"java.io.tmpdir"
))
val
tempDir
=
tempRoot
.
resolve
(
"skija_"
+
System
.
nanoTime
()).
apply
{
mkdirs
()
}
File
(
tempDir
,
libFileName
).
also
{
it
.
deleteOnExit
()
Files
.
copy
(
input
,
it
.
toPath
(),
StandardCopyOption
.
REPLACE_EXISTING
)
}
}
System
.
load
(
file
.
absolutePath
)
_loaded
=
true
}
catch
(
e
:
IOException
)
{
throw
RuntimeException
(
e
)
}
System
.
load
(
libFile
.
absolutePath
)
loaded
=
true
}
fun
_getPrefix
():
String
{
val
os
=
System
.
getProperty
(
"os.name"
)
val
lowerCaseOs
=
os
.
toLowerCase
()
return
if
(
lowerCaseOs
.
contains
(
"windows"
))
""
else
"lib"
private
val
libPrefix
:
String
get
()
=
if
(
currentOS
==
OS
.
Windows
)
""
else
"lib"
private
val
libExtension
:
String
get
()
=
when
(
currentOS
)
{
OS
.
Mac
->
".dylib"
OS
.
Linux
->
".so"
OS
.
Windows
->
".dll"
}
private
val
currentOS
by
lazy
{
val
osName
=
System
.
getProperty
(
"os.name"
)
?:
error
(
"Unknown OS: 'os.name' is null"
)
val
os
=
osName
.
toLowerCase
(
Locale
.
ROOT
)
when
{
os
.
contains
(
"mac"
)
||
os
.
contains
(
"darwin"
)
->
OS
.
Mac
os
.
contains
(
"win"
)
->
OS
.
Windows
os
.
contains
(
"nux"
)
->
OS
.
Linux
else
->
error
(
"Unknown OS: $osName"
)
}
}
fun
_getExtension
():
String
{
val
os
=
System
.
getProperty
(
"os.name"
)
?:
throw
RuntimeException
(
"Unknown operation system"
)
val
lowerCaseOs
=
os
.
toLowerCase
()
if
(
lowerCaseOs
.
contains
(
"mac"
)
||
lowerCaseOs
.
contains
(
"darwin"
))
return
"dylib"
if
(
lowerCaseOs
.
contains
(
"windows"
))
return
"dll"
if
(
lowerCaseOs
.
contains
(
"nux"
))
return
"so"
throw
RuntimeException
(
"Unknown operation system: $os"
)
private
enum
class
OS
{
Linux
,
Mac
,
Windows
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment