From ba6360a18854b8a03deb4bc1a3840adb345377af Mon Sep 17 00:00:00 2001
From: T0biasCZe <44525446+T0biasCZe@users.noreply.github.com>
Date: Fri, 18 Oct 2024 01:54:57 +0200
Subject: [PATCH] Revert "Win7"
---
Discord WMP/App.config | 23 ++---
Discord WMP/Discord WMP.csproj | 8 +-
Discord WMP/Form1.Designer.cs | 17 +---
Discord WMP/Form1.cs | 9 +-
Discord WMP/Form1.resx | 3 -
Discord WMP/Properties/Resources.Designer.cs | 2 +-
Discord WMP/Properties/Settings.Designer.cs | 2 +-
Discord WMP/Settings1.Designer.cs | 14 +--
Discord WMP/Settings1.settings | 3 -
Discord WMP/systemMediaControls.cs | 101 ++-----------------
10 files changed, 34 insertions(+), 148 deletions(-)
diff --git a/Discord WMP/App.config b/Discord WMP/App.config
index 5efa3a0..5b8dcdf 100644
--- a/Discord WMP/App.config
+++ b/Discord WMP/App.config
@@ -1,12 +1,12 @@
-
+
-
+
-
+
@@ -43,28 +43,25 @@
False
-
- False
-
-
-
+
+
-
-
+
+
-
-
+
+
-
+
diff --git a/Discord WMP/Discord WMP.csproj b/Discord WMP/Discord WMP.csproj
index c836238..2397bb9 100644
--- a/Discord WMP/Discord WMP.csproj
+++ b/Discord WMP/Discord WMP.csproj
@@ -8,7 +8,7 @@
Exe
Discord_WMP
Discord WMP
- v4.8
+ v4.8.1
512
true
true
@@ -96,6 +96,12 @@
+
+ ..\..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\References\10.0.20348.0\Windows.Foundation.FoundationContract\4.0.0.0\Windows.Foundation.FoundationContract.winmd
+
+
+ ..\..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\References\10.0.20348.0\Windows.Foundation.UniversalApiContract\12.0.0.0\Windows.Foundation.UniversalApiContract.winmd
+
diff --git a/Discord WMP/Form1.Designer.cs b/Discord WMP/Form1.Designer.cs
index 91f9084..e9e213d 100644
--- a/Discord WMP/Form1.Designer.cs
+++ b/Discord WMP/Form1.Designer.cs
@@ -44,7 +44,6 @@ private void InitializeComponent() {
this.label2 = new System.Windows.Forms.Label();
this.linkLabel1 = new System.Windows.Forms.LinkLabel();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
- this.checkBox_mediakeys = new System.Windows.Forms.CheckBox();
this.label7 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.linkLabel2 = new System.Windows.Forms.LinkLabel();
@@ -228,18 +227,6 @@ private void InitializeComponent() {
//
this.toolTip1.ToolTipTitle = "settings";
//
- // checkBox_mediakeys
- //
- this.checkBox_mediakeys.AutoSize = true;
- this.checkBox_mediakeys.Location = new System.Drawing.Point(76, 354);
- this.checkBox_mediakeys.Name = "checkBox_mediakeys";
- this.checkBox_mediakeys.Size = new System.Drawing.Size(101, 17);
- this.checkBox_mediakeys.TabIndex = 27;
- this.checkBox_mediakeys.Text = "Use media keys";
- this.toolTip1.SetToolTip(this.checkBox_mediakeys, "Use media keys");
- this.checkBox_mediakeys.UseVisualStyleBackColor = true;
- this.checkBox_mediakeys.CheckedChanged += new System.EventHandler(this.checkBox_changed);
- //
// label7
//
this.label7.AutoSize = true;
@@ -274,8 +261,7 @@ private void InitializeComponent() {
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White;
- this.ClientSize = new System.Drawing.Size(194, 124);
- this.Controls.Add(this.checkBox_mediakeys);
+ this.ClientSize = new System.Drawing.Size(193, 123);
this.Controls.Add(this.linkLabel2);
this.Controls.Add(this.label8);
this.Controls.Add(this.label7);
@@ -331,7 +317,6 @@ private void InitializeComponent() {
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.LinkLabel linkLabel2;
- public System.Windows.Forms.CheckBox checkBox_mediakeys;
}
}
diff --git a/Discord WMP/Form1.cs b/Discord WMP/Form1.cs
index 308adec..955e9de 100644
--- a/Discord WMP/Form1.cs
+++ b/Discord WMP/Form1.cs
@@ -16,15 +16,15 @@
using System.Windows.Forms;
using DiscordRPC;
using DiscordRPC.Logging;
-/*using Windows.Media;
-using Windows.Media.Playback;*/
+using Windows.Media;
+using Windows.Media.Playback;
using WMPLib;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace Discord_WMP {
public partial class Form1 : Form {
- const string version = "v2.2.2b W7";
+ const string version = "v2.2.2c";
const string date = "28.9.24";
string versionn = $"{Discord_WMP.Properties.Resources.CurrentCommit.Trim()} {version} {date}";
@@ -239,14 +239,12 @@ private void settingsload() {
use_rpc = Settings1.Default.show_discord;
checkBox_userpc.Checked = use_rpc;
checkBox_dontautohide.Checked = Settings1.Default.dont_hide;
- checkBox_mediakeys.Checked = Settings1.Default.media_keys;
Console.WriteLine("loaded settings");
loadingsettings = false;
}
private void Form1_Closing(object sender, FormClosingEventArgs e) {
Console.WriteLine("saved settings");
- systemMediaControls.Unhook();
//save settings
Settings1.Default.Save();
//close the console window
@@ -265,7 +263,6 @@ private void checkBox_changed(object sender, EventArgs e) {
use_rpc = checkBox_userpc.Checked;
Settings1.Default.show_discord = use_rpc;
Settings1.Default.dont_hide = checkBox_dontautohide.Checked;
- Settings1.Default.media_keys = checkBox_mediakeys.Checked;
var handle = GetConsoleWindow();
if(show_console) ShowWindow(handle, SW_SHOW);
diff --git a/Discord WMP/Form1.resx b/Discord WMP/Form1.resx
index 26532f1..f672590 100644
--- a/Discord WMP/Form1.resx
+++ b/Discord WMP/Form1.resx
@@ -214,9 +214,6 @@
221, 17
-
- 221, 17
-
AAABAAMAHR8AAAEACACECAAANgAAAICAAAABABgAKMgAALoIAAAAAAAAAQAYAAixAQDi0AAAKAAAAB0A
diff --git a/Discord WMP/Properties/Resources.Designer.cs b/Discord WMP/Properties/Resources.Designer.cs
index 1e53eaa..1d49bf0 100644
--- a/Discord WMP/Properties/Resources.Designer.cs
+++ b/Discord WMP/Properties/Resources.Designer.cs
@@ -61,7 +61,7 @@ internal Resources() {
}
///
- /// Looks up a localized string similar to 42979d1
+ /// Looks up a localized string similar to 8119c66
///.
///
public static string CurrentCommit {
diff --git a/Discord WMP/Properties/Settings.Designer.cs b/Discord WMP/Properties/Settings.Designer.cs
index dc139ae..d5f3e5b 100644
--- a/Discord WMP/Properties/Settings.Designer.cs
+++ b/Discord WMP/Properties/Settings.Designer.cs
@@ -12,7 +12,7 @@ namespace Discord_WMP.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.10.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.7.0.0")]
public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
diff --git a/Discord WMP/Settings1.Designer.cs b/Discord WMP/Settings1.Designer.cs
index c8f8ebb..fe86028 100644
--- a/Discord WMP/Settings1.Designer.cs
+++ b/Discord WMP/Settings1.Designer.cs
@@ -12,7 +12,7 @@ namespace Discord_WMP {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.10.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.11.0.0")]
public sealed partial class Settings1 : global::System.Configuration.ApplicationSettingsBase {
private static Settings1 defaultInstance = ((Settings1)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings1())));
@@ -154,17 +154,5 @@ public bool dont_hide {
this["dont_hide"] = value;
}
}
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("False")]
- public bool media_keys {
- get {
- return ((bool)(this["media_keys"]));
- }
- set {
- this["media_keys"] = value;
- }
- }
}
}
diff --git a/Discord WMP/Settings1.settings b/Discord WMP/Settings1.settings
index a5c8734..b6d8a04 100644
--- a/Discord WMP/Settings1.settings
+++ b/Discord WMP/Settings1.settings
@@ -35,8 +35,5 @@
False
-
- False
-
\ No newline at end of file
diff --git a/Discord WMP/systemMediaControls.cs b/Discord WMP/systemMediaControls.cs
index 57a067d..9b2ba47 100644
--- a/Discord WMP/systemMediaControls.cs
+++ b/Discord WMP/systemMediaControls.cs
@@ -6,21 +6,20 @@
using System.IO;
using System.Linq;
using System.Net;
-using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
-/*using Windows.Foundation;
+using Windows.Foundation;
using Windows.Media;
using Windows.Media.Playback;
using Windows.Storage;
using Windows.Storage.FileProperties;
-using Windows.Storage.Streams;*/
+using Windows.Storage.Streams;
namespace Discord_WMP {
public static class systemMediaControls {
static RemotedWindowsMediaPlayer rm;
- /*public static void SystemControls_ButtonPressed(SystemMediaTransportControls sender, SystemMediaTransportControlsButtonPressedEventArgs args) {
+ public static void SystemControls_ButtonPressed(SystemMediaTransportControls sender, SystemMediaTransportControlsButtonPressedEventArgs args) {
switch(args.Button) {
case SystemMediaTransportControlsButton.Play:
((WMPLib.IWMPPlayer4)rm.GetOcx()).controls.play();
@@ -38,8 +37,8 @@ public static class systemMediaControls {
((WMPLib.IWMPPlayer4)rm.GetOcx()).controls.previous();
break;
}
- }*/
- //static SystemMediaTransportControls systemControls = BackgroundMediaPlayer.Current.SystemMediaTransportControls;
+ }
+ static SystemMediaTransportControls systemControls = BackgroundMediaPlayer.Current.SystemMediaTransportControls;
public static Form1 form1;
public static Form1.playback_data data;
public static string thumbnail_path;
@@ -47,14 +46,11 @@ public static class systemMediaControls {
public static bool server_running = false;
public static bool _run_server = true;
public static bool registered_events = false;
-
- public static bool useMediaKeys = false;
-
public static void update(Form1.playback_data data_, Form1 form) {
rm = form.rm;
data = data_;
- /*systemControls = BackgroundMediaPlayer.Current.SystemMediaTransportControls;
+ systemControls = BackgroundMediaPlayer.Current.SystemMediaTransportControls;
if(data.play_state == WMPLib.WMPPlayState.wmppsUndefined || data.play_state == WMPLib.WMPPlayState.wmppsStopped) {
systemControls.IsEnabled = false;
@@ -78,7 +74,7 @@ public static void update(Form1.playback_data data_, Form1 form) {
if(!registered_events) {
systemControls.ButtonPressed += SystemControls_ButtonPressed;
registered_events = true;
- }*/
+ }
GetAlbumArt();
if(!server_running) {
@@ -88,7 +84,7 @@ public static void update(Form1.playback_data data_, Form1 form) {
else {
checkRequests();
}
- /*systemControls.DisplayUpdater.Type = MediaPlaybackType.Music;
+ systemControls.DisplayUpdater.Type = MediaPlaybackType.Music;
switch(data.media_type) {
case "audio":
systemControls.DisplayUpdater.Type = MediaPlaybackType.Music;
@@ -132,23 +128,7 @@ public static void update(Form1.playback_data data_, Form1 form) {
systemControls.DisplayUpdater.MusicProperties.AlbumTitle = data.album;
systemControls.DisplayUpdater.Thumbnail = RandomAccessStreamReference.CreateFromUri(new Uri($"http://localhost:{Form1.random_port}"));
//systemControls.DisplayUpdater.Thumbnail = RandomAccessStreamReference.CreateFromUri(new Uri("http://tobikcze.eu/files/822671241697689610.png"));
- systemControls.DisplayUpdater.Update();*/
-
-
- if(form.checkBox_mediakeys.Checked) {
- if(useMediaKeys == false) {
- useMediaKeys = true;
- Console.WriteLine("registering key listener");
- MediaKeys.rm = rm;
- MediaKeys.hookId = MediaKeys.SetHook(MediaKeys.HookCallback);
- }
- }
- else {
- if(useMediaKeys == true) {
- useMediaKeys = false;
- MessageBox.Show("Media keys will be disabled after restarting the application");
- }
- }
+ systemControls.DisplayUpdater.Update();
}
public static void GetAlbumArt() {
thumbnail_path = "noalbumart.png"; // fallback image next to exe
@@ -231,7 +211,7 @@ static void ProcessRequest(HttpListenerContext context) {
}
else if(url == "/info") {
ProcessRequestInfo(context);
- }
+ }
else {
context.Response.StatusCode = (int)HttpStatusCode.NotFound;
}
@@ -274,66 +254,5 @@ static void ProcessRequestImage(HttpListenerContext context) {
}
}
}
-
- public static void Unhook() {
- MediaKeys.UnhookWindowsHookEx(MediaKeys.hookId);
- }
- }
- public class MediaKeys {
- public static RemotedWindowsMediaPlayer rm;
-
-
- public const int WH_KEYBOARD_LL = 13;
- public const int WM_KEYDOWN = 0x0100;
- public static IntPtr hookId = IntPtr.Zero;
- public static IntPtr SetHook(LowLevelKeyboardProc proc) {
- using(Process curProcess = Process.GetCurrentProcess())
- using(ProcessModule curModule = curProcess.MainModule) {
- return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
- }
- }
-
- public delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
-
- public static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) {
- if(nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN) {
- int vkCode = Marshal.ReadInt32(lParam);
- switch(vkCode) {
- case (int)Keys.MediaPlayPause:
- ((WMPLib.IWMPPlayer4)rm.GetOcx()).controls.play();
- break;
- case (int)Keys.MediaStop:
- ((WMPLib.IWMPPlayer4)rm.GetOcx()).controls.stop();
- break;
- case (int)Keys.MediaNextTrack:
- ((WMPLib.IWMPPlayer4)rm.GetOcx()).controls.next();
- break;
- case (int)Keys.MediaPreviousTrack:
- ((WMPLib.IWMPPlayer4)rm.GetOcx()).controls.previous();
- break;
- }
- }
- return CallNextHookEx(hookId, nCode, wParam, lParam);
- }
-
- [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
-
- [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- public static extern bool UnhookWindowsHookEx(IntPtr hhk);
-
- [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
-
- [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- private static extern IntPtr GetModuleHandle(string lpModuleName);
-
- [DllImport("user32.dll")]
- private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);
-
- private const int KEYEVENTF_EXTENDEDKEY = 0x0001;
- private const int KEYEVENTF_KEYUP = 0x0002;
- private const byte VK_NUMLOCK = 0x90;
}
}