Skip to content

Commit 66a8ad4

Browse files
committed
Allow loading mappings from local path
1 parent bb3661b commit 66a8ad4

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/main/java/com/studiohartman/jamepad/ControllerManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.badlogic.gdx.utils.SharedLibraryLoader;
44

55
import java.io.ByteArrayOutputStream;
6+
import java.io.File;
7+
import java.io.FileInputStream;
68
import java.io.IOException;
79
import java.io.InputStream;
810
import java.nio.file.Files;
@@ -283,6 +285,7 @@ public boolean update() {
283285
public void addMappingsFromFile(String path) throws IOException, IllegalStateException {
284286
InputStream source = getClass().getResourceAsStream(path);
285287
if(source==null) source = ClassLoader.getSystemResourceAsStream(path);
288+
if(source==null && new File(path).exists()) source = new FileInputStream(path);
286289
if(source==null) throw new IOException("Cannot open resource from classpath "+path);
287290

288291
if(configuration.loadDatabaseInMemory) {
@@ -294,6 +297,7 @@ public void addMappingsFromFile(String path) throws IOException, IllegalStateExc
294297
while((read = source.read(data, 0, data.length)) != -1) {
295298
buffer.write(data, 0, read);
296299
}
300+
source.close();
297301

298302
byte[] b = buffer.toByteArray();
299303
if(!nativeAddMappingsFromBuffer(b, b.length)) {

0 commit comments

Comments
 (0)