|
7 | 7 | import com.mrcrayfish.controllable.client.input.Controller; |
8 | 8 | import com.mrcrayfish.controllable.client.input.DeviceInfo; |
9 | 9 | import com.mrcrayfish.controllable.client.input.MultiController; |
| 10 | +import com.mrcrayfish.controllable.util.Utils; |
10 | 11 | import com.mrcrayfish.controllable_sdl.api.gamecontroller.SdlGamecontroller; |
| 12 | +import com.mrcrayfish.controllable_sdl.jna.SdlNativeLibraryLoader; |
11 | 13 | import com.sun.jna.Memory; |
12 | 14 | import com.mrcrayfish.controllable_sdl.api.joystick.SDL_JoystickID; |
13 | 15 | import com.mrcrayfish.controllable_sdl.api.rwops.SDL_RWops; |
|
16 | 18 | import org.jetbrains.annotations.Nullable; |
17 | 19 | import java.io.IOException; |
18 | 20 | import java.io.InputStream; |
| 21 | +import java.nio.file.Files; |
| 22 | +import java.nio.file.Path; |
19 | 23 | import java.util.ArrayList; |
20 | 24 | import java.util.HashMap; |
21 | 25 | import java.util.Iterator; |
|
41 | 45 | */ |
42 | 46 | public class SDL2ControllerManager extends AdaptiveControllerManager |
43 | 47 | { |
| 48 | + static |
| 49 | + { |
| 50 | + try |
| 51 | + { |
| 52 | + Path natives = Utils.getGamePath().resolve("controllable_natives"); |
| 53 | + Path sdl = natives.resolve("SDL"); |
| 54 | + Files.createDirectories(sdl); |
| 55 | + SdlNativeLibraryLoader.setExtractionPath(sdl); |
| 56 | + |
| 57 | + // Add a readme to the natives directory for users |
| 58 | + Path readMeFile = natives.resolve("README.txt"); |
| 59 | + if(!Files.exists(readMeFile)) |
| 60 | + { |
| 61 | + Files.writeString(readMeFile, """ |
| 62 | + This directory holds the natives for Controllable, which are used to interface |
| 63 | + with game controllers and read their inputs. It is safe to delete, just make sure |
| 64 | + the game is closed as the natives may be loaded; preventing you from deleting them. |
| 65 | + If you are developing a modpack, make sure to exclude this directory."""); |
| 66 | + } |
| 67 | + } |
| 68 | + catch(IOException e) |
| 69 | + { |
| 70 | + throw new RuntimeException(e); |
| 71 | + } |
| 72 | + } |
| 73 | + |
44 | 74 | @Override |
45 | 75 | public void init() |
46 | 76 | { |
|
0 commit comments