Skip to content

Commit 3ea4e9e

Browse files
committed
📦 Set custom extraction path for natives
1 parent 3be7c78 commit 3ea4e9e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

common/src/main/java/com/mrcrayfish/controllable/client/input/sdl2/SDL2ControllerManager.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.google.common.io.ByteStreams;
44
import com.mrcrayfish.controllable.Constants;
55
import com.mrcrayfish.controllable.client.input.ControllerManager;
6+
import com.mrcrayfish.controllable_sdl.jna.SdlNativeLibraryLoader;
7+
import com.mrcrayfish.framework.platform.Services;
68
import com.sun.jna.Memory;
79
import com.mrcrayfish.controllable_sdl.api.joystick.SDL_JoystickID;
810
import com.mrcrayfish.controllable_sdl.api.rwops.SDL_RWops;
@@ -11,6 +13,8 @@
1113
import org.jetbrains.annotations.Nullable;
1214
import java.io.IOException;
1315
import java.io.InputStream;
16+
import java.nio.file.Files;
17+
import java.nio.file.Path;
1418
import java.util.HashMap;
1519
import java.util.Map;
1620

@@ -28,6 +32,32 @@
2832
*/
2933
public class SDL2ControllerManager extends ControllerManager
3034
{
35+
static
36+
{
37+
try
38+
{
39+
Path natives = Services.CONFIG.getGamePath().resolve("controllable_natives");
40+
Path sdl = natives.resolve("SDL");
41+
Files.createDirectories(sdl);
42+
SdlNativeLibraryLoader.setExtractionPath(sdl);
43+
44+
// Add a readme to the natives directory for users
45+
Path readMeFile = natives.resolve("README.txt");
46+
if(!Files.exists(readMeFile))
47+
{
48+
Files.writeString(readMeFile, """
49+
This directory holds the natives for Controllable, which are used to interface
50+
with game controllers and read their inputs. It is safe to delete, just make sure
51+
the game is closed as the natives may be loaded; preventing you from deleting them.
52+
If you are developing a modpack, make sure to exclude this directory.""");
53+
}
54+
}
55+
catch(IOException e)
56+
{
57+
throw new RuntimeException(e);
58+
}
59+
}
60+
3161
@Override
3262
public void init()
3363
{

0 commit comments

Comments
 (0)