Compare commits

...

15 commits

Author SHA1 Message Date
Serraniel 0772edd354
Debug database in debug configuration 2019-02-15 17:11:00 +01:00
Serraniel 9c141e9f5c
Merge branch 'master' into develop
# Conflicts:
#	Discord Media Loader.Application/Classes/Core.cs
#	Discord Media Loader.Application/Classes/Job.cs
#	Discord Media Loader.Application/Classes/JobScheduler.cs
#	Discord Media Loader.Application/Classes/Settings.cs
#	Discord Media Loader.Application/MainForm.cs
2019-02-15 16:58:01 +01:00
Serraniel 3b8f440bb2 Merge branch 'feature/RPC-config' into develop
* feature/RPC-config:
  Disable RPC by default
  Did some corrections because of sweetlib
2018-04-23 21:41:45 +02:00
Serraniel 7358be85e3 Disable RPC by default 2018-04-23 21:40:25 +02:00
Serraniel 8ca2ec9b27 Did some corrections because of sweetlib 2018-04-23 21:40:17 +02:00
Serraniel c36acc0750 Merge branch 'feature/RPC' into develop
* feature/RPC:
  Revert "Added discord rpc and demo repository"
  Implemented basic rpc setup
  Implemented rpc handler and added rpc library
  Added helper file
  Added basic RPC wrapper into project
  Disabled update check on debug versions
  Added discord rpc and demo repository
2018-04-01 20:23:48 +02:00
Serraniel 842266f338 Revert "Added discord rpc and demo repository"
This reverts commit 9278a804cf.
2018-04-01 20:20:35 +02:00
Serraniel 6a6a2e7c9a Implemented basic rpc setup 2018-04-01 20:17:31 +02:00
Serraniel 051b0713ee Implemented rpc handler and added rpc library 2018-04-01 20:16:58 +02:00
Serraniel 2add4afa24 Added helper file 2018-04-01 20:16:17 +02:00
Serraniel 8aa1296887 Added basic RPC wrapper into project 2018-04-01 18:48:25 +02:00
Serraniel fc27243c1e Disabled update check on debug versions 2018-04-01 18:48:06 +02:00
Serraniel 9278a804cf Added discord rpc and demo repository 2018-04-01 18:28:39 +02:00
Serraniel 27ed4a00ba Merge branch 'master' into develop
* master:
  Removed unneccasry parts of code
  Build
  Added an option to set online state. Refresh timer added as it was required to display correct information in UI
2018-04-01 18:26:01 +02:00
Serraniel 698729cec7 Merge branch 'support/1.0' into develop
* support/1.0:
  Build
2018-01-22 20:38:45 +01:00
10 changed files with 188 additions and 4 deletions

View file

@ -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}");
}
} }
} }

View file

@ -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;

View 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();
}
}

View file

@ -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;
}
}
}

View 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();
}
}
}
}

View file

@ -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()
{ {

View file

@ -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>

View file

@ -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)

View file

@ -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;
} }

Binary file not shown.