Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Win7" #19

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions Discord WMP/App.config
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="Discord_WMP.Settings1" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
<section name="Discord_WMP.Settings1" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8.1" />
</startup>
<userSettings>
<Discord_WMP.Settings1>
Expand Down Expand Up @@ -43,28 +43,25 @@
<setting name="dont_hide" serializeAs="String">
<value>False</value>
</setting>
<setting name="media_keys" serializeAs="String">
<value>False</value>
</setting>
</Discord_WMP.Settings1>
</userSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0"/>
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2"/>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<System.Windows.Forms.ApplicationConfigurationSection>
<add key="DpiAwareness" value="DpiUnawareGdiScaled"/>
<add key="DpiAwareness" value="DpiUnawareGdiScaled" />
</System.Windows.Forms.ApplicationConfigurationSection>
</configuration>
8 changes: 7 additions & 1 deletion Discord WMP/Discord WMP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OutputType>Exe</OutputType>
<RootNamespace>Discord_WMP</RootNamespace>
<AssemblyName>Discord WMP</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
Expand Down Expand Up @@ -96,6 +96,12 @@
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Windows.Foundation.FoundationContract">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\References\10.0.20348.0\Windows.Foundation.FoundationContract\4.0.0.0\Windows.Foundation.FoundationContract.winmd</HintPath>
</Reference>
<Reference Include="Windows.Foundation.UniversalApiContract">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\References\10.0.20348.0\Windows.Foundation.UniversalApiContract\12.0.0.0\Windows.Foundation.UniversalApiContract.winmd</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AlbumArtAdder.cs">
Expand Down
17 changes: 1 addition & 16 deletions Discord WMP/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions Discord WMP/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}";

Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions Discord WMP/Form1.resx
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,6 @@
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>221, 17</value>
</metadata>
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>221, 17</value>
</metadata>
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAABAAMAHR8AAAEACACECAAANgAAAICAAAABABgAKMgAALoIAAAAAAAAAQAYAAixAQDi0AAAKAAAAB0A
Expand Down
2 changes: 1 addition & 1 deletion Discord WMP/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Discord WMP/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 1 addition & 13 deletions Discord WMP/Settings1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions Discord WMP/Settings1.settings
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,5 @@
<Setting Name="dont_hide" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="media_keys" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
101 changes: 10 additions & 91 deletions Discord WMP/systemMediaControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -38,23 +37,20 @@ 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;

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;
Expand All @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -231,7 +211,7 @@ static void ProcessRequest(HttpListenerContext context) {
}
else if(url == "/info") {
ProcessRequestInfo(context);
}
}
else {
context.Response.StatusCode = (int)HttpStatusCode.NotFound;
}
Expand Down Expand Up @@ -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;
}
}