Skip to content

Commit

Permalink
Forced directory path for DFAssist.WinToast
Browse files Browse the repository at this point in the history
- for some reason the relative path was not working
  • Loading branch information
easly1989 committed Nov 7, 2019
1 parent d6c49d4 commit a5305fb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
22 changes: 14 additions & 8 deletions DFAssist.Core/Toast/WinToastWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Runtime.InteropServices;
using System;
using System.IO;
using System.Runtime.InteropServices;

namespace DFAssist.Core.Toast
{
Expand Down Expand Up @@ -60,10 +62,15 @@ public enum AudioSystemFile

public static class WinToastWrapper
{
private const string DllFilePath = "DFAssist.WinToast.dll";

[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool SetDllDirectory(string lpPathName);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void ToastEventCallback(int messageCode);

[DllImport("libs/DFAssist.WinToast.dll", EntryPoint = "CreateToast_Text01", ExactSpelling = true)]
[DllImport(DllFilePath, EntryPoint = "CreateToast_Text01", ExactSpelling = true)]
public static extern void CreateToast(
[MarshalAs(UnmanagedType.LPWStr)]string appName,
[MarshalAs(UnmanagedType.LPWStr)]string appUserModelId,
Expand All @@ -74,7 +81,7 @@ public static extern void CreateToast(
[MarshalAs(UnmanagedType.I4)]AudioSystemFile audioFile = AudioSystemFile.DefaultSound,
[MarshalAs(UnmanagedType.I4)]AudioOption audioOption = AudioOption.Default);

[DllImport("libs/DFAssist.WinToast.dll", EntryPoint = "CreateToast_Text02", ExactSpelling = true)]
[DllImport(DllFilePath, EntryPoint = "CreateToast_Text02", ExactSpelling = true)]
public static extern void CreateToast(
[MarshalAs(UnmanagedType.LPWStr)]string appName,
[MarshalAs(UnmanagedType.LPWStr)]string appUserModelId,
Expand All @@ -87,7 +94,7 @@ public static extern void CreateToast(
[MarshalAs(UnmanagedType.I4)]AudioSystemFile audioFile = AudioSystemFile.DefaultSound,
[MarshalAs(UnmanagedType.I4)]AudioOption audioOption = AudioOption.Default);

[DllImport("libs/DFAssist.WinToast.dll", EntryPoint = "CreateToast_Text03", ExactSpelling = true)]
[DllImport(DllFilePath, EntryPoint = "CreateToast_Text03", ExactSpelling = true)]
public static extern void CreateToast(
[MarshalAs(UnmanagedType.LPWStr)]string appName,
[MarshalAs(UnmanagedType.LPWStr)]string appUserModelId,
Expand All @@ -100,7 +107,7 @@ public static extern void CreateToast(
[MarshalAs(UnmanagedType.I4)]AudioSystemFile audioFile = AudioSystemFile.DefaultSound,
[MarshalAs(UnmanagedType.I4)]AudioOption audioOption = AudioOption.Default);

[DllImport("libs/DFAssist.WinToast.dll", EntryPoint = "CreateToast_ImageAndText01", ExactSpelling = true)]
[DllImport(DllFilePath, EntryPoint = "CreateToast_ImageAndText01", ExactSpelling = true)]
public static extern void CreateToast(
[MarshalAs(UnmanagedType.LPWStr)]string appName,
[MarshalAs(UnmanagedType.LPWStr)]string appUserModelId,
Expand All @@ -112,7 +119,7 @@ public static extern void CreateToast(
[MarshalAs(UnmanagedType.I4)]AudioSystemFile audioFile = AudioSystemFile.DefaultSound,
[MarshalAs(UnmanagedType.I4)]AudioOption audioOption = AudioOption.Default);

[DllImport("libs/DFAssist.WinToast.dll", EntryPoint = "CreateToast_ImageAndText02", ExactSpelling = true)]
[DllImport(DllFilePath, EntryPoint = "CreateToast_ImageAndText02", ExactSpelling = true)]
public static extern void CreateToast(
[MarshalAs(UnmanagedType.LPWStr)]string appName,
[MarshalAs(UnmanagedType.LPWStr)]string appUserModelId,
Expand All @@ -126,7 +133,7 @@ public static extern void CreateToast(
[MarshalAs(UnmanagedType.I4)]AudioSystemFile audioFile = AudioSystemFile.DefaultSound,
[MarshalAs(UnmanagedType.I4)]AudioOption audioOption = AudioOption.Default);

[DllImport("libs/DFAssist.WinToast.dll", EntryPoint = "CreateToast_ImageAndText03", ExactSpelling = true)]
[DllImport(DllFilePath, EntryPoint = "CreateToast_ImageAndText03", ExactSpelling = true)]
public static extern void CreateToast(
[MarshalAs(UnmanagedType.LPWStr)]string appName,
[MarshalAs(UnmanagedType.LPWStr)]string appUserModelId,
Expand All @@ -139,6 +146,5 @@ public static extern void CreateToast(
[MarshalAs(UnmanagedType.I4)]Duration duration = Duration.System,
[MarshalAs(UnmanagedType.I4)]AudioSystemFile audioFile = AudioSystemFile.DefaultSound,
[MarshalAs(UnmanagedType.I4)]AudioOption audioOption = AudioOption.Default);

}
}
12 changes: 12 additions & 0 deletions DFAssist/Helpers/ToastHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Drawing;
using System.IO;
using System.Reflection;
using Advanced_Combat_Tracker;
using DFAssist.Core.Toast;
using Splat;
Expand All @@ -12,6 +14,16 @@ public class ToastHelper : BaseNotificationHelper<ToastHelper>

public ToastHelper()
{
// we need to force the dll folder for the DFAssist.WinToast c++ library
// should be necessary just once;
// we can also avoid any check, because at this point all the libraries should be already loaded
// and all the check should have been done in the AssemblyResolver
// ReSharper disable AssignNullToNotNullAttribute
var lpPathName = Path.Combine(Path.GetDirectoryName(Locator.Current.GetService<ActPluginData>().pluginFile.ToString()), "libs");
if(WinToastWrapper.SetDllDirectory(lpPathName))
Logger.Write($"UI: Toast library path: {lpPathName}", LogLevel.Debug);
// ReSharper restore AssignNullToNotNullAttribute

_toastEventCallback = delegate (int code)
{
if(code == 0)
Expand Down
4 changes: 2 additions & 2 deletions SharedAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
// to distinguish one build from another. AssemblyFileVersion is specified
// in AssemblyVersionInfo.cs so that it can be easily incremented by the
// automated build process.
[assembly: AssemblyVersion("2.1.6")]
[assembly: AssemblyVersion("2.1.7")]

// By default, the "Product version" shown in the file properties window is
// the same as the value specified for AssemblyFileVersionAttribute.
// Set AssemblyInformationalVersionAttribute to be the same as
// AssemblyVersionAttribute so that the "Product version" in the file
// properties window matches the version displayed in the GAC shell extension.
[assembly: AssemblyInformationalVersion("2.1.6")] // a.k.a. "Product version"
[assembly: AssemblyInformationalVersion("2.1.7")] // a.k.a. "Product version"

0 comments on commit a5305fb

Please sign in to comment.