UWUVCI-AIO-WPF/UWUVCI AIO WPF/UI/Windows/TitleKeys.xaml.cs

207 lines
6.3 KiB
C#
Raw Normal View History

2020-10-02 06:47:35 +00:00
using System;
2020-05-04 16:20:21 +00:00
using System.Diagnostics;
using System.Reflection;
2020-04-30 15:01:41 +00:00
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace UWUVCI_AIO_WPF.UI.Windows
{
/// <summary>
/// Interaktionslogik für TitleKeys.xaml
/// </summary>
public partial class TitleKeys : Window
{
2020-05-01 18:10:51 +00:00
string url = "";
public TitleKeys(string url)
{
2020-04-30 15:01:41 +00:00
MainViewModel mvm = FindResource("mvm") as MainViewModel;
try
{
2020-10-02 06:47:35 +00:00
if (Owner?.GetType() != typeof(MainWindow))
2020-04-30 15:01:41 +00:00
{
2020-10-02 06:47:35 +00:00
WindowStartupLocation = WindowStartupLocation.CenterScreen;
2020-04-30 15:01:41 +00:00
}
}
catch (Exception)
{
2020-10-02 06:47:35 +00:00
WindowStartupLocation = WindowStartupLocation.CenterScreen;
2020-04-30 15:01:41 +00:00
}
string fullurl = "";
try
{
fullurl = mvm.GetURL(url);
2020-05-01 18:10:51 +00:00
if (fullurl == "" || fullurl == null)
2020-04-30 15:01:41 +00:00
{
throw new Exception();
}
}
catch (Exception)
{
Custom_Message cm = new Custom_Message("Not Implemented", $"The Helppage for {url.ToUpper()} is not implemented yet");
try
{
cm.Owner = mvm.mw;
}
catch (Exception)
{
2020-10-02 06:47:35 +00:00
// left empty on purpose
2020-04-30 15:01:41 +00:00
}
cm.ShowDialog();
2020-10-02 06:47:35 +00:00
Close();
2020-04-30 15:01:41 +00:00
mvm.mw.Show();
}
2020-05-01 18:10:51 +00:00
2020-04-30 15:01:41 +00:00
wb.Source = new Uri(fullurl, UriKind.Absolute);
wb.Refresh(true);
2020-05-01 18:10:51 +00:00
clsWebbrowser_Errors.SuppressscriptErrors(wb, true);
2020-05-01 18:10:51 +00:00
InitializeComponent();
this.url = url;
}
2020-04-28 23:56:28 +00:00
public TitleKeys(string url, string title)
{
InitializeComponent();
2020-05-01 18:10:51 +00:00
wb.Visibility = Visibility.Hidden;
2020-05-04 16:20:21 +00:00
Thread t = new Thread(() => DoStuff(url));
t.SetApartmentState(ApartmentState.STA);
t.Start();
tbTitleBar.Text = title.Replace(" Inject "," ");
}
private void MoveWindow(object sender, MouseButtonEventArgs e)
{
try
{
if (e.ChangedButton == MouseButton.Left)
{
2020-10-02 06:47:35 +00:00
Owner.PointToScreen(new Point(Left, Top));
DragMove();
2020-05-04 16:20:21 +00:00
// this.Owner.PointFromScreen(new Point(this.Left, this.Top));
//(FindResource("mvm") as MainViewModel).mw.PointFromScreen(new Point(this.Left, this.Top));
}
//PointFromScreen(new Point(this.Left, this.Top));
}
catch (Exception)
{
2020-10-02 06:47:35 +00:00
// left empty on purpose
2020-05-04 16:20:21 +00:00
}
}
public void DoStuff(string url)
{
2020-04-30 15:01:41 +00:00
MainViewModel mvm = FindResource("mvm") as MainViewModel;
2020-05-04 16:20:21 +00:00
string fullurl = "";
2020-04-30 15:01:41 +00:00
try
{
fullurl = mvm.GetURL(url);
2020-10-02 06:47:35 +00:00
if (string.IsNullOrEmpty(fullurl))
2020-04-30 15:01:41 +00:00
{
throw new Exception();
}
}
catch (Exception e)
2020-04-30 15:01:41 +00:00
{
Custom_Message cm = new Custom_Message("Not Implemented", $"The Helppage for {url.ToUpper()} is not implemented yet");
try
{
cm.Owner = mvm.mw;
}
catch (Exception)
{
2020-10-02 06:47:35 +00:00
// left empty on purpose
2020-04-30 15:01:41 +00:00
}
cm.Show();
2020-10-02 06:47:35 +00:00
Close();
2020-04-30 15:01:41 +00:00
mvm.mw.Show();
}
2020-05-04 16:20:21 +00:00
2020-10-02 06:47:35 +00:00
Dispatcher.Invoke(() =>
2020-05-04 16:20:21 +00:00
{
wb.Source = new Uri(fullurl, UriKind.Absolute);
clsWebbrowser_Errors.SuppressscriptErrors(wb, true);
});
2020-04-30 15:01:41 +00:00
2020-04-28 23:56:28 +00:00
/*dynamic activeX = this.wb.GetType().InvokeMember("ActiveXInstance",
BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
null, this.wb, new object[] { });
activeX.Silent = true;*/
2020-05-01 18:10:51 +00:00
2020-04-28 23:56:28 +00:00
}
private void Window_Close(object sender, RoutedEventArgs e)
{
2020-10-02 06:47:35 +00:00
Owner.Left =Left;
Owner.Top = Top;
Owner.Show();
Close();
}
private void Window_Minimize(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
2020-05-01 18:10:51 +00:00
private void wb_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
load.Visibility = Visibility.Hidden;
wb.Visibility = Visibility.Visible;
}
2020-05-04 16:20:21 +00:00
private void wb_Navigating(object sender, System.Windows.Navigation.NavigatingCancelEventArgs e)
{
2020-10-02 06:47:35 +00:00
if (!e.Uri.ToString().Contains("flumpster"))
{
e.Cancel = true;
2020-05-04 16:20:21 +00:00
2020-10-02 06:47:35 +00:00
var startInfo = new ProcessStartInfo
{
FileName = e.Uri.ToString()
};
2020-05-04 16:20:21 +00:00
2020-10-02 06:47:35 +00:00
Process.Start(startInfo);
}
2020-05-04 16:20:21 +00:00
// cancel navigation to the clicked link in the webBrowser control
}
2020-05-06 21:53:52 +00:00
private void wind_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
(FindResource("mvm") as MainViewModel).mw.Topmost = true;
}
private void wind_Closed(object sender, EventArgs e)
{
(FindResource("mvm") as MainViewModel).mw.Topmost = false;
}
}
public static class clsWebbrowser_Errors
{
//*set wpf webbrowser Control to silent
//*code source: https://social.msdn.microsoft.com/Forums/vstudio/en-US/4f686de1-8884-4a8d-8ec5-ae4eff8ce6db
public static void SuppressscriptErrors(this WebBrowser webBrowser, bool hide)
{
FieldInfo fiComWebBrowser = typeof(WebBrowser).GetField("_axIWebBrowser2", BindingFlags.Instance | BindingFlags.NonPublic);
if (fiComWebBrowser == null)
return;
object objComWebBrowser = fiComWebBrowser.GetValue(webBrowser);
if (objComWebBrowser == null)
return;
objComWebBrowser.GetType().InvokeMember("Silent", BindingFlags.SetProperty, null, objComWebBrowser, new object[] { hide });
}
}
}