Skip to content

Commit a8be253

Browse files
committed
check if on windows
1 parent 66a0f30 commit a8be253

2 files changed

Lines changed: 26 additions & 12 deletions

File tree

build.gradle

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
group = 'dev.codeman'
6-
version = '0.0.4'
6+
version = '0.0.5'
77

88
repositories {
99
mavenCentral()
@@ -19,25 +19,36 @@ java {
1919
}
2020
}
2121

22-
def nativeDir = file("$buildDir/resources/main/native")
23-
def dllFile = file("$nativeDir/SMTC4J.dll")
22+
def nativeDownloadDir = layout.buildDirectory.dir("native-download").get().asFile
23+
def nativeDllFile = nativeDownloadDir.toPath().resolve("SMTC4J.dll").toFile()
24+
def resourcesNativeDir = layout.buildDirectory.dir("resources/main/native").get().asFile
2425

25-
tasks.register('downloadNative') {
26+
tasks.register("downloadNative") {
2627
doLast {
27-
if (dllFile.exists()) return
28-
29-
nativeDir.mkdirs()
28+
if (nativeDllFile.exists()) {
29+
println "Native DLL already exists, skipping download."
30+
return
31+
}
3032

33+
nativeDownloadDir.mkdirs()
3134
def tag = "v$version"
3235
def url = "https://github.com/CodeManDev/SMTC4J/releases/download/${tag}/SMTC4J.dll"
36+
println "Downloading native DLL from $url"
3337

34-
println "Downloading native library from $url"
35-
URI.create(url).toURL().withInputStream { i ->
36-
dllFile.withOutputStream { it << i }
38+
new URL(url).withInputStream { input ->
39+
nativeDllFile.withOutputStream { output ->
40+
output << input
41+
}
3742
}
3843
}
3944
}
4045

41-
processResources {
42-
dependsOn 'downloadNative'
46+
tasks.register("copyNativeIntoResources", Copy) {
47+
dependsOn "downloadNative"
48+
from(nativeDllFile)
49+
into(resourcesNativeDir)
50+
}
51+
52+
tasks.named("processResources") {
53+
dependsOn "copyNativeIntoResources"
4354
}

src/main/java/dev/codeman/smtc4j/SMTC4J.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public class SMTC4J {
2626
public static boolean load() {
2727
if (loaded) return true;
2828

29+
if (!System.getProperty("os.name").toLowerCase().contains("win"))
30+
throw new UnsupportedOperationException("SMTC4J is Windows-only");
31+
2932
String dllPath = "/native/SMTC4J.dll";
3033
try (InputStream in = SMTC4J.class.getResourceAsStream(dllPath)) {
3134
if (in == null) {

0 commit comments

Comments
 (0)