fix: window restore was broken

This commit is contained in:
Frank Skare
2019-10-29 14:34:51 +01:00
parent 9bbde49a5c
commit 05027cd458
10 changed files with 89 additions and 78 deletions

View File

@@ -1,3 +1,7 @@
###
- fix: window restore was broken
### 5.4.2.1 Beta ### 5.4.2.1 Beta
- pressing shift key suppresses auto-load-folder - pressing shift key suppresses auto-load-folder

View File

@@ -1,21 +1,24 @@
MIT License MIT License
Copyright (c) 2017-2019 Frank Skare (stax76) Copyright 2002-2017 Frank Skare (stax76)
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person
a copy of this software and ssociated documentation files (the "Software"), obtaining a copy of this software and ssociated documentation
to deal in the Software without restriction, including without limitation files (the "Software"), to deal in the Software without restriction,
the rights to use, copy, modify, merge, publish, distribute, sublicense, including without limitation the rights to use, copy, modify, merge,
and/or sell copies of the Software, and to permit persons to whom the publish, distribute, sublicense, and/or sell copies of the Software,
Software is furnished to do so, subject to the following conditions: and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included The above copyright notice and this permission notice shall be
in all copies or substantial portions of the Software. included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -20,7 +20,10 @@ namespace mpvnet
public static bool IsDarkTheme { public static bool IsDarkTheme {
get { get {
object value = Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "AppsUseLightTheme", 1); object value = Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "AppsUseLightTheme", 1);
if (value is null) value = 1;
if (value is null)
value = 1;
return (int)value == 0; return (int)value == 0;
} }
} }
@@ -62,43 +65,52 @@ namespace mpvnet
{ {
Types = types; Types = types;
RegHelp.SetObject($"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\{ExeFilename}", null, ExePath); RegHelp.SetObject(@"HKCU\Software\Microsoft\Windows\CurrentVersion\App Paths\" + ExeFilename, null, ExePath);
RegHelp.SetObject($"HKCR\\Applications\\{ExeFilename}", "FriendlyAppName", "mpv.net media player"); RegHelp.SetObject(@"HKCR\Applications\" + ExeFilename, "FriendlyAppName", "mpv.net media player");
RegHelp.SetObject($"HKCR\\Applications\\{ExeFilename}\\shell\\open\\command", null, $"\"{ExePath}\" \"%1\""); RegHelp.SetObject($@"HKCR\Applications\{ExeFilename}\shell\open\command", null, $"\"{ExePath}\" \"%1\"");
RegHelp.SetObject(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities", "ApplicationDescription", "mpv.net media player"); RegHelp.SetObject(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities", "ApplicationDescription", "mpv.net media player");
RegHelp.SetObject(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities", "ApplicationName", "mpv.net"); RegHelp.SetObject(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities", "ApplicationName", "mpv.net");
RegHelp.SetObject($"HKCR\\SystemFileAssociations\\video\\OpenWithList\\{ExeFilename}", null, ""); RegHelp.SetObject(@"HKCR\SystemFileAssociations\video\OpenWithList\" + ExeFilename, null, "");
RegHelp.SetObject($"HKCR\\SystemFileAssociations\\audio\\OpenWithList\\{ExeFilename}", null, ""); RegHelp.SetObject(@"HKCR\SystemFileAssociations\audio\OpenWithList\" + ExeFilename, null, "");
RegHelp.SetObject(@"HKLM\SOFTWARE\RegisteredApplications", "mpv.net", @"SOFTWARE\Clients\Media\mpv.net\Capabilities"); RegHelp.SetObject(@"HKLM\SOFTWARE\RegisteredApplications", "mpv.net", @"SOFTWARE\Clients\Media\mpv.net\Capabilities");
foreach (string ext in Types) foreach (string ext in Types)
{ {
RegHelp.SetObject($"HKCR\\Applications\\{ExeFilename}\\SupportedTypes", "." + ext, ""); RegHelp.SetObject($@"HKCR\Applications\{ExeFilename}\SupportedTypes", "." + ext, "");
RegHelp.SetObject($"HKCR\\" + "." + ext, null, ExeFilenameNoExt + "." + ext); RegHelp.SetObject($@"HKCR\" + "." + ext, null, ExeFilenameNoExt + "." + ext);
RegHelp.SetObject($"HKCR\\" + "." + ext + "\\OpenWithProgIDs", ExeFilenameNoExt + "." + ext, ""); RegHelp.SetObject($@"HKCR\" + "." + ext + @"\OpenWithProgIDs", ExeFilenameNoExt + "." + ext, "");
if (App.VideoTypes.Contains(ext)) RegHelp.SetObject($"HKCR\\" + "." + ext, "PerceivedType", "video");
if (App.AudioTypes.Contains(ext)) RegHelp.SetObject($"HKCR\\" + "." + ext, "PerceivedType", "audio"); if (App.VideoTypes.Contains(ext))
if (App.ImageTypes.Contains(ext)) RegHelp.SetObject($"HKCR\\" + "." + ext, "PerceivedType", "image"); RegHelp.SetObject(@"HKCR\" + "." + ext, "PerceivedType", "video");
RegHelp.SetObject($"HKCR\\" + ExeFilenameNoExt + "." + ext + "\\shell\\open", null, "Play with " + Application.ProductName);
RegHelp.SetObject($"HKCR\\" + ExeFilenameNoExt + "." + ext + "\\shell\\open\\command", null, $"\"{ExePath}\" \"%1\""); if (App.AudioTypes.Contains(ext))
RegHelp.SetObject(@"HKCR\" + "." + ext, "PerceivedType", "audio");
if (App.ImageTypes.Contains(ext))
RegHelp.SetObject(@"HKCR\" + "." + ext, "PerceivedType", "image");
RegHelp.SetObject($@"HKCR\" + ExeFilenameNoExt + "." + ext + @"\shell\open", null, "Play with " + Application.ProductName);
RegHelp.SetObject($@"HKCR\" + ExeFilenameNoExt + "." + ext + @"\shell\open\command", null, $"\"{ExePath}\" \"%1\"");
RegHelp.SetObject(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities\FileAssociations", "." + ext, ExeFilenameNoExt + "." + ext); RegHelp.SetObject(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities\FileAssociations", "." + ext, ExeFilenameNoExt + "." + ext);
} }
} }
public static void Unregister() public static void Unregister()
{ {
RegHelp.RemoveKey($"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\{ExeFilename}"); RegHelp.RemoveKey($@"HKCU\Software\Microsoft\Windows\CurrentVersion\App Paths\" + ExeFilename);
RegHelp.RemoveKey($"HKCR\\Applications\\{ExeFilename}"); RegHelp.RemoveKey($@"HKCR\Applications\" + ExeFilename);
RegHelp.RemoveKey($"HKLM\\SOFTWARE\\Clients\\Media\\mpv.net"); RegHelp.RemoveKey($@"HKLM\SOFTWARE\Clients\Media\mpv.net");
RegHelp.RemoveKey($"HKCR\\SystemFileAssociations\\video\\OpenWithList\\{ExeFilename}"); RegHelp.RemoveKey($@"HKCR\SystemFileAssociations\video\OpenWithList\" + ExeFilename);
RegHelp.RemoveKey($"HKCR\\SystemFileAssociations\\audio\\OpenWithList\\{ExeFilename}"); RegHelp.RemoveKey($@"HKCR\SystemFileAssociations\audio\OpenWithList\" + ExeFilename);
RegHelp.RemoveValue(@"HKLM\SOFTWARE\RegisteredApplications", "mpv.net"); RegHelp.RemoveValue(@"HKLM\SOFTWARE\RegisteredApplications", "mpv.net");
foreach (string id in Registry.ClassesRoot.GetSubKeyNames()) foreach (string id in Registry.ClassesRoot.GetSubKeyNames())
{ {
if (id.StartsWith(ExeFilenameNoExt + ".")) Registry.ClassesRoot.DeleteSubKeyTree(id); if (id.StartsWith(ExeFilenameNoExt + "."))
RegHelp.RemoveValue($"HKCR\\Software\\Classes\\" + id + "\\OpenWithProgIDs", ExeFilenameNoExt + id); Registry.ClassesRoot.DeleteSubKeyTree(id);
RegHelp.RemoveValue($"HKLM\\Software\\Classes\\" + id + "\\OpenWithProgIDs", ExeFilenameNoExt + id);
RegHelp.RemoveValue($@"HKCR\Software\Classes\{id}\OpenWithProgIDs", ExeFilenameNoExt + id);
RegHelp.RemoveValue($@"HKLM\Software\Classes\{id}\OpenWithProgIDs", ExeFilenameNoExt + id);
} }
} }
} }
@@ -107,46 +119,43 @@ namespace mpvnet
{ {
public static void SetObject(string path, string name, object value) public static void SetObject(string path, string name, object value)
{ {
using (RegistryKey rk = GetRootKey(path).CreateSubKey(path.Substring(5), RegistryKeyPermissionCheck.ReadWriteSubTree)) using (RegistryKey regKey = GetRootKey(path).CreateSubKey(path.Substring(5), RegistryKeyPermissionCheck.ReadWriteSubTree))
rk.SetValue(name, value); regKey.SetValue(name, value);
} }
public static string GetString(string path, string name, string defaultValue = "") public static string GetString(string path, string name, string defaultValue = "")
{ {
object val = GetObject(path, name, defaultValue); object value = GetObject(path, name, defaultValue);
if (val == null || !(val is string)) return ""; return !(value is string) ? defaultValue : value.ToString();
return val.ToString();
} }
public static int GetInt(string path, string name, int defaultValue = 0) public static int GetInt(string path, string name, int defaultValue = 0)
{ {
object val = GetObject(path, name, defaultValue); object value = GetObject(path, name, defaultValue);
if (val == null || !(val is int)) return 0; return !(value is int) ? defaultValue : (int)value;
return (int)val;
} }
public static object GetObject(string path, string name, object defaultValue = null) public static object GetObject(string path, string name, object defaultValue = null)
{ {
using (RegistryKey rk = GetRootKey(path).OpenSubKey(path.Substring(5))) using (RegistryKey regKey = GetRootKey(path).OpenSubKey(path.Substring(5)))
if (rk != null) return regKey == null ? null : regKey.GetValue(name, defaultValue);
return rk.GetValue(name, defaultValue);
else
return null;
} }
public static void RemoveKey(string path) public static void RemoveKey(string path)
{ {
try { try
{
GetRootKey(path).DeleteSubKeyTree(path.Substring(5), false); GetRootKey(path).DeleteSubKeyTree(path.Substring(5), false);
} catch { } } catch { }
} }
public static void RemoveValue(string path, string name) public static void RemoveValue(string path, string name)
{ {
try { try
using (RegistryKey rk = GetRootKey(path).OpenSubKey(path.Substring(5), true)) {
if (!(rk is null)) using (RegistryKey regKey = GetRootKey(path).OpenSubKey(path.Substring(5), true))
rk.DeleteValue(name, false); if (regKey != null)
regKey.DeleteValue(name, false);
} catch {} } catch {}
} }

View File

@@ -56,9 +56,6 @@ public class MediaInfo : IDisposable
~MediaInfo() { Dispose(); } ~MediaInfo() { Dispose(); }
[DllImport("kernel32.dll")]
public static extern IntPtr LoadLibrary(string path);
[DllImport("MediaInfo.dll")] [DllImport("MediaInfo.dll")]
static extern IntPtr MediaInfo_New(); static extern IntPtr MediaInfo_New();

View File

@@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Frank Skare (stax76)")] [assembly: AssemblyCompany("Frank Skare (stax76)")]
[assembly: AssemblyProduct("mpv.net")] [assembly: AssemblyProduct("mpv.net")]
[assembly: AssemblyCopyright("Copyright © 2017-2019 Frank Skare (stax76)")] [assembly: AssemblyCopyright("Copyright 2017-2019 Frank Skare (stax76)")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("5.4.2.1")] [assembly: AssemblyVersion("5.4.2.2")]
[assembly: AssemblyFileVersion("5.4.2.1")] [assembly: AssemblyFileVersion("5.4.2.2")]

View File

@@ -1,5 +1,4 @@
using System; using System;
using System.Globalization;
using System.Windows; using System.Windows;
using System.Windows.Media; using System.Windows.Media;

View File

@@ -97,7 +97,10 @@ namespace mpvnet
} }
if (App.Maximized) if (App.Maximized)
{
SetFormPosAndSize(1, true);
WindowState = FormWindowState.Maximized; WindowState = FormWindowState.Maximized;
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -247,15 +250,18 @@ namespace mpvnet
bool WasInitialSizeSet; bool WasInitialSizeSet;
void SetFormPosAndSize(double scale = 1) void SetFormPosAndSize(double scale = 1, bool force = false)
{ {
if (WindowState == FormWindowState.Maximized) if (!force)
return;
if (mp.Fullscreen)
{ {
CycleFullscreen(true); if (WindowState == FormWindowState.Maximized)
return; return;
if (mp.Fullscreen)
{
CycleFullscreen(true);
return;
}
} }
Screen screen = Screen.FromControl(this); Screen screen = Screen.FromControl(this);
@@ -481,13 +487,6 @@ namespace mpvnet
var r2 = Marshal.PtrToStructure<Native.RECT>(m.LParam); var r2 = Marshal.PtrToStructure<Native.RECT>(m.LParam);
Native.SetWindowPos(Handle, IntPtr.Zero, r2.Left, r2.Top, r2.Width, r2.Height, 0); Native.SetWindowPos(Handle, IntPtr.Zero, r2.Left, r2.Top, r2.Width, r2.Height, 0);
break; break;
case 0x112: // WM_SYSCOMMAND
if (m.WParam.ToInt32() == 0xf120) // SC_RESTORE
{
CycleFullscreen(true);
CycleFullscreen(false);
}
break;
case 0x0214: // WM_SIZING case 0x0214: // WM_SIZING
var rc = Marshal.PtrToStructure<Native.RECT>(m.LParam); var rc = Marshal.PtrToStructure<Native.RECT>(m.LParam);
var r = rc; var r = rc;

View File

@@ -116,7 +116,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="Misc\App.cs" /> <Compile Include="Misc\App.cs" />
<Compile Include="Misc\Extension.cs" /> <Compile Include="Misc\Extension.cs" />
<Page Include="Controls\SearchTextBoxUserControl.xaml"> <Page Include="WPF\SearchTextBoxUserControl.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Page> </Page>
@@ -140,7 +140,7 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Compile Include="Controls\SearchTextBoxUserControl.xaml.cs"> <Compile Include="WPF\SearchTextBoxUserControl.xaml.cs">
<DependentUpon>SearchTextBoxUserControl.xaml</DependentUpon> <DependentUpon>SearchTextBoxUserControl.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="DynamicGUI\DynamicGUI.cs" /> <Compile Include="DynamicGUI\DynamicGUI.cs" />