Skip to content

Commit

Permalink
Add Mac and Linux auto-setup
Browse files Browse the repository at this point in the history
  • Loading branch information
RuiNtD committed Nov 21, 2018
1 parent 5fe4fa1 commit c4103a9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 27 deletions.
24 changes: 0 additions & 24 deletions SVRichPresence/Mac and Linux Install Instructions.txt

This file was deleted.

35 changes: 35 additions & 0 deletions SVRichPresence/RichPresenceMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using StardewValley;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace SVRichPresence {
Expand Down Expand Up @@ -35,6 +36,7 @@ public override void Entry(IModHelper helper) {
Monitor.Log("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", LogLevel.Alert);
}
#endif
SetupLibs();
api = new RichPresenceAPI(this);
DiscordRpc.EventHandlers handlers = new DiscordRpc.EventHandlers();
DiscordRpc.Initialize(applicationId, ref handlers, false, "413150");
Expand Down Expand Up @@ -170,6 +172,39 @@ public override void Entry(IModHelper helper) {

public override object GetApi() => api;

private void SetupLibs() {
if (Constants.TargetPlatform == GamePlatform.Windows)
return;
const string macLib = "libdiscord-rpc.dylib";
const string nixLib = "libdiscord-rpc.so";
string libPath = Constants.TargetPlatform == GamePlatform.Mac ? macLib : nixLib;
string modPath = Path.Combine(Helper.DirectoryPath, libPath);
string sdvPath = Path.Combine(Constants.ExecutionPath, libPath);
try {
Boolean attempt = false;
if (!File.Exists(sdvPath)) {
Monitor.Log("Attempting RPC library install");
attempt = true;
} else if (File.GetLastWriteTime(modPath) > File.GetLastWriteTime(sdvPath)) {
Monitor.Log("Attempting RPC library update");
attempt = true;
}
if (attempt) {
File.Copy(modPath, sdvPath, true);
File.SetLastWriteTime(sdvPath, File.GetLastWriteTime(modPath)); // just making sure
Monitor.Log("DiscordRP library updated. Please restart game.", LogLevel.Alert);
SaveEvents.AfterLoad += (object sender, EventArgs e) => {
Game1.addHUDMessage(new HUDMessage("DiscordRP library updated. Please restart game.", HUDMessage.newQuest_type));
};
}
} catch (IOException e) {
Monitor.Log("Failed to update Discord RPC library.", LogLevel.Warn);
Monitor.Log(e.ToString(), LogLevel.Trace);
if (!File.Exists(sdvPath))
Monitor.Log("I shall crash now. x_x", LogLevel.Error);
}
}

private void HandleButton(object sender, EventArgsInput e) {
if (e.Button != config.ReloadConfigButton)
return;
Expand Down
3 changes: 0 additions & 3 deletions SVRichPresence/SVRichPresence.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@
<Content Include="libdiscord-rpc.so">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Mac and Linux Install Instructions.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="manifest.json" />
<None Include="packages.config" />
</ItemGroup>
Expand Down

0 comments on commit c4103a9

Please sign in to comment.