Skip to content

Commit

Permalink
Fixed script errors, searching for updates at program start
Browse files Browse the repository at this point in the history
  • Loading branch information
newcat committed Aug 17, 2016
1 parent 6524c2f commit b25fada
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 24 deletions.
1 change: 0 additions & 1 deletion pollPlugin/PollSetup.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public partial class PollSetup : Window, IPlugin

private IPluginHost host;
private ObservableCollection<string> pollOptions = new ObservableCollection<string>();
private ResultsWindow rw;

public PollSetup()
{
Expand Down
18 changes: 17 additions & 1 deletion tvdc/AuthenticationWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Windows;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;

namespace tvdc
{
Expand All @@ -13,6 +15,7 @@ public partial class AuthenticationWindow : Window
public AuthenticationWindow()
{
InitializeComponent();
HideScriptErrors(wb, true);
}

private void Window_Loaded(object sender, RoutedEventArgs e)
Expand All @@ -30,5 +33,18 @@ private void wb_Navigating(object sender, System.Windows.Navigation.NavigatingCa
Close();
}
}

private void HideScriptErrors(WebBrowser webBrowser, bool hide)
{
var fiComWebBrowser = typeof(WebBrowser).GetField("_axIWebBrowser2", BindingFlags.Instance | BindingFlags.NonPublic);
if (fiComWebBrowser == null) return;
var objComWebBrowser = fiComWebBrowser.GetValue(webBrowser);
if (objComWebBrowser == null)
{
webBrowser.Loaded += (o, s) => HideScriptErrors(webBrowser, hide); //In case we are to early
return;
}
objComWebBrowser.GetType().InvokeMember("Silent", BindingFlags.SetProperty, null, objComWebBrowser, new object[] { hide });
}
}
}
4 changes: 4 additions & 0 deletions tvdc/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ private async void init()

initialized = true;

UpdateWindow uw = new UpdateWindow(true);
await uw.searchForUpdates();


}

private async void FollowerTimer_Elapsed(object sender, ElapsedEventArgs e)
Expand Down
6 changes: 3 additions & 3 deletions tvdc/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: nUpdateVersion("1.2.0.0")]
[assembly: AssemblyVersion("1.2.1.0")]
[assembly: AssemblyFileVersion("1.2.1.0")]
[assembly: nUpdateVersion("1.2.1.0")]
7 changes: 4 additions & 3 deletions tvdc/Settings.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ private void btnClearCache_Click(object sender, RoutedEventArgs e)
MessageBox.Show(this, "Cache cleared.", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
}

private void btnCheckUpdate_Click(object sender, RoutedEventArgs e)
private async void btnCheckUpdate_Click(object sender, RoutedEventArgs e)
{
UpdateWindow uw = new UpdateWindow();
uw.ShowDialog();
UpdateWindow uw = new UpdateWindow(false);
await uw.ShowModal(new System.Windows.Interop.WindowInteropHelper(this).Handle);
Activate();
}

}
Expand Down
2 changes: 1 addition & 1 deletion tvdc/updateWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:tvdc"
mc:Ignorable="d" Background="{StaticResource WindowBackgroundBrush}"
Title="TVD Update" Height="300" Width="460" ResizeMode="NoResize" ContentRendered="Content_Rendered" ShowInTaskbar="False" WindowStartupLocation="CenterOwner" Topmost="True">
Title="TVD Update" Height="300" Width="460" ResizeMode="NoResize" ShowInTaskbar="False" WindowStartupLocation="CenterOwner" Topmost="True">
<Window.Resources>
<SolidColorBrush x:Key="TextBox.Static.Border" Color="#FFABAdB3"/>
<SolidColorBrush x:Key="TextBox.MouseOver.Border" Color="#FF7EB4EA"/>
Expand Down
78 changes: 63 additions & 15 deletions tvdc/updateWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
using System.Globalization;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Windows.Threading;
using System.Windows.Interop;

namespace tvdc
{
Expand All @@ -22,47 +26,91 @@ public partial class UpdateWindow : Window, IDisposable
private bool isSearching = false;
private bool isDownloading = false;
private bool readyToInstall = false;
private bool silent = false;

public UpdateWindow()
public UpdateWindow(bool silent)
{
InitializeComponent();
this.silent = silent;
}

private async void Content_Rendered(object sender, EventArgs e)
[DllImport("user32")]
internal static extern bool EnableWindow(IntPtr hwnd, bool bEnable);

public async Task ShowModal(IntPtr ownerHwnd)
{
EnableWindow(ownerHwnd, false);

DispatcherFrame frame = new DispatcherFrame();

Closed += delegate
{
EnableWindow(ownerHwnd, true);
frame.Continue = false;
};

Show();
await searchForUpdates();
Dispatcher.PushFrame(frame);
}

public async Task searchForUpdates()
{

bool updatesFound = false;
isSearching = true;

try
{
updatesFound = await manager.SearchForUpdatesAsync();
} catch (Exception ex)
}
catch (Exception ex)
{
if (ex is OperationCanceledException)
if (ex is OperationCanceledException && !silent)
{
Close();
MessageBox.Show(this, "Failed to search for updates:\n" + ex.Message, "TVD Updater",
MessageBoxButton.OK, MessageBoxImage.Warning);
manager.Dispose();
Close();
return;
}
else if (!(ex is SizeCalculationException))
throw;
} finally
{
if (silent)
{
return;
}
else
{
throw;
}
}
}
finally
{
isSearching = false;
pb.IsIndeterminate = true;
pb.IsIndeterminate = false;
}

if (!updatesFound)
{
Hide();
MessageBox.Show(this, "No updates found.", "TVD Updater", MessageBoxButton.OK, MessageBoxImage.Information);
manager.Dispose();
Close();
return;
if (silent)
{
manager.Dispose();
return;
}
else
{
Close();
MessageBox.Show(this, "No updates found.", "TVD Updater", MessageBoxButton.OK, MessageBoxImage.Information);
manager.Dispose();
return;
}
}

if (silent)
Show();

btnInstall.IsEnabled = true;
lblStatus.Content = "Update(s) found.";

Expand Down Expand Up @@ -136,20 +184,20 @@ private void Manager_PackagesDownloadProgressChanged(object sender, UpdateDownlo

private void Manager_PackagesDownloadFailed(object sender, FailedEventArgs e)
{
Close();
MessageBox.Show(this, "Failed to download updates:\n" + e.Exception.Message, "TVD Updater",
MessageBoxButton.OK, MessageBoxImage.Error);
manager.Dispose();
Close();
return;
}

private void Manager_PackagesDownloadFinished(object sender, EventArgs e)
{
if (!manager.ValidatePackages())
{
Close();
MessageBox.Show(this, "Invalid package found! Please try again.", "TVD Updater",
MessageBoxButton.OK, MessageBoxImage.Error);
Close();
return;
}

Expand Down

0 comments on commit b25fada

Please sign in to comment.