Skip to content
This repository has been archived by the owner on Apr 9, 2023. It is now read-only.

Commit

Permalink
Added support and Binary for Linux dispatch.
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Nov 17, 2017
1 parent 4995581 commit df1d190
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions discord-rpc.iml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: net.java.dev.jna:jna:3.2.7" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.5" level="project" />
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.6" level="project" />
</component>
</module>
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>

</dependencies>

<build>
Expand Down
21 changes: 15 additions & 6 deletions src/main/java/net/arikia/dev/drpc/DiscordRPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
import com.sun.jna.Native;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.SystemUtils;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;

/**
* @author Nicolas "Vatuu" Adamoglou
Expand Down Expand Up @@ -82,10 +81,20 @@ public static void DiscordRespond(String userId, DiscordReply reply){

//Load DLL depending on the user's architecture.
private static void loadDLL(){
boolean is64bit = System.getProperty("sun.arch.data.model").equals("64");
String name ="discord-rpc.dll";
String finalPath = is64bit ? "/lib/win64/" + name : "/lib/win32/" + name;
File f = new File(System.getenv("TEMP") + "/discord-rpc.jar/discord-rpc.dll");
String name = System.mapLibraryName("discord-rpc");
String finalPath = "";
String tempPath = "";

if(SystemUtils.IS_OS_WINDOWS){
boolean is64bit = System.getProperty("sun.arch.data.model").equals("64");
finalPath = is64bit ? "/lib/win64/discord-rpc.dll" : "/lib/win32/discord-rpc.dll";
tempPath = System.getenv("TEMP") + "/discord-rpc.jar/discord-rpc.dll";
}else if(SystemUtils.IS_OS_LINUX) {
finalPath = "/lib/lin64/discord-rpc.so";
tempPath = System.getenv("TMPDIR") + "/discord-rpc.jar/discord-rpc.so";
}

File f = new File(tempPath);

try(InputStream in = DiscordRPC.class.getResourceAsStream(finalPath); OutputStream out = FileUtils.openOutputStream(f)){
IOUtils.copy(in, out);
Expand Down
Binary file added src/main/resources/lib/lin64/discord-rpc.so
Binary file not shown.

0 comments on commit df1d190

Please sign in to comment.