Compare commits
15 commits
Author | SHA1 | Date | |
---|---|---|---|
|
0772edd354 | ||
|
9c141e9f5c | ||
|
3b8f440bb2 | ||
|
7358be85e3 | ||
|
8ca2ec9b27 | ||
|
c36acc0750 | ||
|
842266f338 | ||
|
6a6a2e7c9a | ||
|
051b0713ee | ||
|
2add4afa24 | ||
|
8aa1296887 | ||
|
fc27243c1e | ||
|
9278a804cf | ||
|
27ed4a00ba | ||
|
698729cec7 |
10 changed files with 188 additions and 4 deletions
|
@ -2,6 +2,7 @@
|
||||||
using Discord.Net;
|
using Discord.Net;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
using DML.AppCore.Classes;
|
using DML.AppCore.Classes;
|
||||||
|
using DML.Application.Classes.RPC;
|
||||||
using DML.Application.Dialogs;
|
using DML.Application.Dialogs;
|
||||||
using DML.Client;
|
using DML.Client;
|
||||||
using LiteDB;
|
using LiteDB;
|
||||||
|
@ -27,11 +28,14 @@ namespace DML.Application.Classes
|
||||||
internal static LiteDatabase Database { get; set; }
|
internal static LiteDatabase Database { get; set; }
|
||||||
internal static Settings Settings { get; set; }
|
internal static Settings Settings { get; set; }
|
||||||
internal static JobScheduler Scheduler { get; } = new JobScheduler();
|
internal static JobScheduler Scheduler { get; } = new JobScheduler();
|
||||||
internal static RavenClient Raven = new RavenClient("https://0de964231669473e9098b9f6cc1d6278:79d9f2eb24034de199b2a37cc058e0f2@sentry.io/257114");
|
internal static RavenClient Raven { get; } = new RavenClient("https://0de964231669473e9098b9f6cc1d6278:79d9f2eb24034de199b2a37cc058e0f2@sentry.io/257114");
|
||||||
|
internal static bool ShuttingDown { get; private set; } = false;
|
||||||
internal static string DataDirectory
|
internal static string DataDirectory
|
||||||
=> Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"Serraniel\Discord Media Loader");
|
=> Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"Serraniel\Discord Media Loader");
|
||||||
|
|
||||||
|
internal static DiscordRpc.RichPresence RpcPresence;
|
||||||
|
internal static DiscordRpc.EventHandlers RpcHandlers = new DiscordRpc.EventHandlers();
|
||||||
|
|
||||||
public static async Task Run(string[] paramStrings)
|
public static async Task Run(string[] paramStrings)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -91,8 +95,12 @@ namespace DML.Application.Classes
|
||||||
logMemory.ArchiveFile = logFile;
|
logMemory.ArchiveFile = logFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var databasePath = Path.Combine(DataDirectory, "config.db");
|
||||||
|
#if DEBUG
|
||||||
|
databasePath = Path.Combine(DataDirectory, "config.debug.db");
|
||||||
|
#endif
|
||||||
Logger.Debug("Loading database...");
|
Logger.Debug("Loading database...");
|
||||||
Database = new LiteDatabase(Path.Combine(DataDirectory, "config.db"));
|
Database = new LiteDatabase(databasePath);
|
||||||
Database.Log.Logging += (message) => Logger.Trace($"LiteDB: {message}");
|
Database.Log.Logging += (message) => Logger.Trace($"LiteDB: {message}");
|
||||||
|
|
||||||
Logger.Debug("Loading settings collection out of database...");
|
Logger.Debug("Loading settings collection out of database...");
|
||||||
|
@ -247,15 +255,44 @@ namespace DML.Application.Classes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Settings.UseRPC)
|
||||||
|
{
|
||||||
|
Logger.Info("Initializing RPC client");
|
||||||
|
Logger.Trace("Registering RPC handlers");
|
||||||
|
RpcHandlers.readyCallback += RpcReadyCallback;
|
||||||
|
RpcHandlers.disconnectedCallback += RpcDisconnectedCallback;
|
||||||
|
RpcHandlers.errorCallback += RpcErrorCallback;
|
||||||
|
RpcPresence.startTimestamp = DiscordRpcHelper.DateTimeToTimestamp(DateTime.UtcNow);
|
||||||
|
|
||||||
|
Logger.Debug("Calling RPC initialize");
|
||||||
|
DiscordRpc.Initialize("430025401851707393", ref RpcHandlers, true, null);
|
||||||
|
|
||||||
|
// Do not await ;)
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
while (!ShuttingDown)
|
||||||
|
{
|
||||||
|
Logger.Trace("Running RPC callbacks");
|
||||||
|
await Task.Delay(5000);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
splash.Close();
|
splash.Close();
|
||||||
|
|
||||||
Logger.Info("Starting scheduler...");
|
Logger.Info("Starting scheduler...");
|
||||||
Scheduler.Start();
|
// Scheduler.Start();
|
||||||
|
|
||||||
System.Windows.Forms.Application.Run(new MainForm());
|
System.Windows.Forms.Application.Run(new MainForm());
|
||||||
|
|
||||||
|
// shutting down
|
||||||
|
ShuttingDown = true;
|
||||||
|
|
||||||
Logger.Info("Stopping scheduler...");
|
Logger.Info("Stopping scheduler...");
|
||||||
Scheduler.Stop();
|
Scheduler.Stop();
|
||||||
|
|
||||||
|
Logger.Info("Shutting down RPC client");
|
||||||
|
DiscordRpc.Shutdown();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -285,5 +322,26 @@ namespace DML.Application.Classes
|
||||||
Logger.Trace($"Trying to find channel in {server} by id: {id}");
|
Logger.Trace($"Trying to find channel in {server} by id: {id}");
|
||||||
return (from c in server.TextChannels where c.Id == id select c).FirstOrDefault();
|
return (from c in server.TextChannels where c.Id == id select c).FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void RpcUpdatePresence()
|
||||||
|
{
|
||||||
|
Logger.Debug("Updating RPC presence");
|
||||||
|
DiscordRpc.UpdatePresence(ref RpcPresence);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RpcReadyCallback()
|
||||||
|
{
|
||||||
|
Logger.Debug("RpcReady");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RpcDisconnectedCallback(int errorCode, string message)
|
||||||
|
{
|
||||||
|
Logger.Warn($"RPC disconnect received: {errorCode} - {message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RpcErrorCallback(int errorCode, string message)
|
||||||
|
{
|
||||||
|
Logger.Error($"RPC error received: {errorCode} - {message}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
|
59
Discord Media Loader.Application/Classes/RPC/DiscordRpc.cs
Normal file
59
Discord Media Loader.Application/Classes/RPC/DiscordRpc.cs
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace DML.Application.Classes.RPC
|
||||||
|
{
|
||||||
|
// https://github.com/discordapp/discord-rpc/blob/master/examples/button-clicker/Assets/DiscordRpc.cs
|
||||||
|
// Give that man a cookie ^.^
|
||||||
|
|
||||||
|
public class DiscordRpc
|
||||||
|
{
|
||||||
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
|
public delegate void ReadyCallback();
|
||||||
|
|
||||||
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
|
public delegate void DisconnectedCallback(int errorCode, string message);
|
||||||
|
|
||||||
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
|
public delegate void ErrorCallback(int errorCode, string message);
|
||||||
|
|
||||||
|
public struct EventHandlers
|
||||||
|
{
|
||||||
|
public ReadyCallback readyCallback;
|
||||||
|
public DisconnectedCallback disconnectedCallback;
|
||||||
|
public ErrorCallback errorCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Values explanation and example: https://discordapp.com/developers/docs/rich-presence/how-to#updating-presence-update-presence-payload-fields
|
||||||
|
[System.Serializable]
|
||||||
|
public struct RichPresence
|
||||||
|
{
|
||||||
|
public string state; /* max 128 bytes */
|
||||||
|
public string details; /* max 128 bytes */
|
||||||
|
public long startTimestamp;
|
||||||
|
public long endTimestamp;
|
||||||
|
public string largeImageKey; /* max 32 bytes */
|
||||||
|
public string largeImageText; /* max 128 bytes */
|
||||||
|
public string smallImageKey; /* max 32 bytes */
|
||||||
|
public string smallImageText; /* max 128 bytes */
|
||||||
|
public string partyId; /* max 128 bytes */
|
||||||
|
public int partySize;
|
||||||
|
public int partyMax;
|
||||||
|
public string matchSecret; /* max 128 bytes */
|
||||||
|
public string joinSecret; /* max 128 bytes */
|
||||||
|
public string spectateSecret; /* max 128 bytes */
|
||||||
|
public bool instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
[DllImport(RpcWrapper.Dll, EntryPoint = "Discord_Initialize", CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern void Initialize(string applicationId, ref EventHandlers handlers, bool autoRegister, string optionalSteamId);
|
||||||
|
|
||||||
|
[DllImport(RpcWrapper.Dll, EntryPoint = "Discord_UpdatePresence", CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern void UpdatePresence(ref RichPresence presence);
|
||||||
|
|
||||||
|
[DllImport(RpcWrapper.Dll, EntryPoint = "Discord_RunCallbacks", CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern void RunCallbacks();
|
||||||
|
|
||||||
|
[DllImport(RpcWrapper.Dll, EntryPoint = "Discord_Shutdown", CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern void Shutdown();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DML.Application.Classes.RPC
|
||||||
|
{
|
||||||
|
public static class DiscordRpcHelper
|
||||||
|
{
|
||||||
|
public static long DateTimeToTimestamp(DateTime dt)
|
||||||
|
{
|
||||||
|
return (dt.Ticks - 621355968000000000) / 10000000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
29
Discord Media Loader.Application/Classes/RPC/RpcWrapper.cs
Normal file
29
Discord Media Loader.Application/Classes/RPC/RpcWrapper.cs
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace DML.Application.Classes.RPC
|
||||||
|
{
|
||||||
|
public class RpcWrapper
|
||||||
|
{
|
||||||
|
public const string Dll = "discord-rpc-win32";
|
||||||
|
|
||||||
|
public RpcWrapper()
|
||||||
|
{
|
||||||
|
if (!File.Exists(Dll + ".dll"))
|
||||||
|
{
|
||||||
|
MessageBox.Show(
|
||||||
|
"Missing " + Dll + ".dll\n\n" +
|
||||||
|
"Grab it from the release on GitHub or from the DiscordRpcDemo/lib/ folder in the repo then put it alongside DiscordRpcDemo.exe.\n\n" +
|
||||||
|
"https://github.com/nostrenz/cshap-discord-rpc-demo"
|
||||||
|
);
|
||||||
|
|
||||||
|
System.Windows.Forms.Application.Exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,6 +16,7 @@ namespace DML.Application.Classes
|
||||||
public bool SkipExistingFiles { get; set; } = true;
|
public bool SkipExistingFiles { get; set; } = true;
|
||||||
public int ThreadLimit { get; set; } = 50;
|
public int ThreadLimit { get; set; } = 50;
|
||||||
public bool ShowStartUpHints { get; set; } = true;
|
public bool ShowStartUpHints { get; set; } = true;
|
||||||
|
public bool UseRPC { get; set; } = false;
|
||||||
|
|
||||||
public void Store()
|
public void Store()
|
||||||
{
|
{
|
||||||
|
|
|
@ -167,6 +167,9 @@
|
||||||
<Compile Include="Classes\Core.cs" />
|
<Compile Include="Classes\Core.cs" />
|
||||||
<Compile Include="Classes\Job.cs" />
|
<Compile Include="Classes\Job.cs" />
|
||||||
<Compile Include="Classes\JobScheduler.cs" />
|
<Compile Include="Classes\JobScheduler.cs" />
|
||||||
|
<Compile Include="Classes\RPC\DiscordRpc.cs" />
|
||||||
|
<Compile Include="Classes\RPC\DiscordRpcHelper.cs" />
|
||||||
|
<Compile Include="Classes\RPC\RpcWrapper.cs" />
|
||||||
<Compile Include="Dialogs\LoginDialog.cs">
|
<Compile Include="Dialogs\LoginDialog.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|
|
@ -10,6 +10,7 @@ using Discord.WebSocket;
|
||||||
using DML.AppCore.Classes;
|
using DML.AppCore.Classes;
|
||||||
using DML.Application.Classes;
|
using DML.Application.Classes;
|
||||||
using DML.Application.Helper;
|
using DML.Application.Helper;
|
||||||
|
using DML.Application.Classes.RPC;
|
||||||
using DML.Client;
|
using DML.Client;
|
||||||
using static DML.Client.DMLClient;
|
using static DML.Client.DMLClient;
|
||||||
using static SweetLib.Utils.Logger.Logger;
|
using static SweetLib.Utils.Logger.Logger;
|
||||||
|
@ -26,6 +27,8 @@ namespace DML.Application
|
||||||
public partial class MainForm : Form
|
public partial class MainForm : Form
|
||||||
{
|
{
|
||||||
private bool IsInitialized { get; set; } = false;
|
private bool IsInitialized { get; set; } = false;
|
||||||
|
private DiscordRpc.RichPresence Presence { get; }
|
||||||
|
|
||||||
public MainForm()
|
public MainForm()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
@ -241,6 +244,18 @@ namespace DML.Application
|
||||||
pgbProgress.Value = progress;
|
pgbProgress.Value = progress;
|
||||||
|
|
||||||
lbProgress.Text = $"Scanned: {scanned} Downloaded: {done} Open: {totalAttachments - done}";
|
lbProgress.Text = $"Scanned: {scanned} Downloaded: {done} Open: {totalAttachments - done}";
|
||||||
|
|
||||||
|
if (Core.Settings.UseRPC)
|
||||||
|
{
|
||||||
|
Core.RpcPresence.details = "Downloading media files";
|
||||||
|
Core.RpcPresence.state = $"{done} / {totalAttachments} ({pgbProgress.Value}%)";
|
||||||
|
Core.RpcPresence.largeImageKey = "main";
|
||||||
|
Core.RpcPresence.largeImageText = "Visit discordmedialoader.net";
|
||||||
|
Core.RpcPresence.smallImageKey = "author";
|
||||||
|
Core.RpcPresence.smallImageText = "Made by Serraniel";
|
||||||
|
|
||||||
|
Core.RpcUpdatePresence();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void aboutToolStripMenuItem_Click(object sender, System.EventArgs e)
|
private void aboutToolStripMenuItem_Click(object sender, System.EventArgs e)
|
||||||
|
|
|
@ -15,6 +15,7 @@ namespace Discord_Media_Loader
|
||||||
|
|
||||||
private async void FrmSplash_Shown(object sender, EventArgs e)
|
private async void FrmSplash_Shown(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
#if !DEBUG
|
||||||
UseWaitCursor = true;
|
UseWaitCursor = true;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -52,6 +53,7 @@ namespace Discord_Media_Loader
|
||||||
{
|
{
|
||||||
UseWaitCursor = false;
|
UseWaitCursor = false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
DialogResult = DialogResult.OK;
|
DialogResult = DialogResult.OK;
|
||||||
}
|
}
|
||||||
|
|
BIN
Discord Media Loader/bin/Debug/discord-rpc-win32.dll
Normal file
BIN
Discord Media Loader/bin/Debug/discord-rpc-win32.dll
Normal file
Binary file not shown.
Loading…
Add table
Reference in a new issue