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
Show 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
package
org.jetbrains.skiko
import
java.io.File
import
java.io.File
import
java.io.IOException
import
java.net.URISyntaxException
import
java.nio.file.Files
import
java.nio.file.Files
import
java.nio.file.StandardCopyOption
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
// based on https://github.com/JetBrains/skija/blob/bc6e0531021e4ff839c07196e0336d6456ed7520/src/main/java/org/jetbrains/skija/Library.java
object
Library
{
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
// https://github.com/adamheinrich/native-utils/blob/e6a39489662846a77504634b6fafa4995ede3b1d/src/main/java/cz/adamh/utils/NativeUtils.java
@Synchronized
fun
load
(
resourcePath
:
String
,
name
:
String
)
{
fun
load
(
resourcePath
:
String
,
name
:
String
)
{
if
(
_loaded
)
return
if
(
loaded
)
return
try
{
var
file
:
File
val
libFileName
=
"$libPrefix$name$libExtension"
val
fileName
=
_getPrefix
()
+
name
+
"."
+
_getExtension
()
val
url
=
Library
::
class
.
java
.
getResource
(
resourcePath
+
libFileName
)
val
url
=
Library
::
class
.
java
.
getResource
(
resourcePath
+
fileName
)
// println("Loading " + url);
// System.out.println("Loading " + url);
val
libFile
=
when
{
requireNotNull
(
url
)
{
"Library $fileName is not found in $resourcePath"
}
url
==
null
->
error
(
"Library $libFileName is not found in $resourcePath"
)
if
(
url
.
protocol
===
"file"
)
file
=
try
{
url
.
protocol
==
"file"
->
File
(
url
.
toURI
())
// System.out.println("Loading " + url);
else
->
url
.
openStream
().
use
{
input
->
File
(
url
.
toURI
())
val
tempRoot
=
File
(
System
.
getProperty
(
"java.io.tmpdir"
))
}
catch
(
e
:
URISyntaxException
)
{
val
tempDir
=
tempRoot
.
resolve
(
"skija_"
+
System
.
nanoTime
()).
apply
{
mkdirs
()
}
throw
RuntimeException
(
e
)
File
(
tempDir
,
libFileName
).
also
{
}
else
url
.
openStream
().
use
{
`is`
->
it
.
deleteOnExit
()
val
tempDir
=
File
(
System
.
getProperty
(
"java.io.tmpdir"
),
"skija_"
+
System
.
nanoTime
())
Files
.
copy
(
input
,
it
.
toPath
(),
StandardCopyOption
.
REPLACE_EXISTING
)
tempDir
.
mkdirs
()
}
tempDir
.
deleteOnExit
()
}
file
=
File
(
tempDir
,
fileName
)
}
file
.
deleteOnExit
()
System
.
load
(
libFile
.
absolutePath
)
Files
.
copy
(
`is`
,
file
.
toPath
(),
StandardCopyOption
.
REPLACE_EXISTING
)
loaded
=
true
}
}
System
.
load
(
file
.
absolutePath
)
_loaded
=
true
private
val
libPrefix
:
String
}
catch
(
e
:
IOException
)
{
get
()
=
if
(
currentOS
==
OS
.
Windows
)
""
else
"lib"
throw
RuntimeException
(
e
)
}
private
val
libExtension
:
String
}
get
()
=
when
(
currentOS
)
{
OS
.
Mac
->
".dylib"
fun
_getPrefix
():
String
{
OS
.
Linux
->
".so"
val
os
=
System
.
getProperty
(
"os.name"
)
OS
.
Windows
->
".dll"
val
lowerCaseOs
=
os
.
toLowerCase
()
}
return
if
(
lowerCaseOs
.
contains
(
"windows"
))
""
else
"lib"
}
private
val
currentOS
by
lazy
{
val
osName
=
System
.
getProperty
(
"os.name"
)
?:
error
(
"Unknown OS: 'os.name' is null"
)
fun
_getExtension
():
String
{
val
os
=
osName
.
toLowerCase
(
Locale
.
ROOT
)
val
os
=
System
.
getProperty
(
"os.name"
)
?:
throw
RuntimeException
(
"Unknown operation system"
)
when
{
val
lowerCaseOs
=
os
.
toLowerCase
()
os
.
contains
(
"mac"
)
||
os
.
contains
(
"darwin"
)
->
OS
.
Mac
if
(
lowerCaseOs
.
contains
(
"mac"
)
||
lowerCaseOs
.
contains
(
"darwin"
))
return
"dylib"
os
.
contains
(
"win"
)
->
OS
.
Windows
if
(
lowerCaseOs
.
contains
(
"windows"
))
return
"dll"
os
.
contains
(
"nux"
)
->
OS
.
Linux
if
(
lowerCaseOs
.
contains
(
"nux"
))
return
"so"
else
->
error
(
"Unknown OS: $osName"
)
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