diff options
author | Michael Vrhel <michael.vrhel@artifex.com> | 2014-05-07 22:13:18 -0700 |
---|---|---|
committer | Michael Vrhel <michael.vrhel@artifex.com> | 2014-09-09 16:39:35 -0700 |
commit | e49f2b58d98071192cc803951da5e06783d55592 (patch) | |
tree | 4ab25129b4cd97269dc1a72c934d4168e86f40b3 /platform/winrt | |
parent | 6b99e7b1295d094323c10401f8b21c81c29554eb (diff) | |
download | mupdf-e49f2b58d98071192cc803951da5e06783d55592.tar.xz |
Add error checking to catch when gs DLL is not found.
Diffstat (limited to 'platform/winrt')
-rw-r--r-- | platform/winrt/gsview/About.xaml | 39 | ||||
-rw-r--r-- | platform/winrt/gsview/About.xaml.cs | 16 | ||||
-rw-r--r-- | platform/winrt/gsview/MainWindow.xaml.cs | 17 | ||||
-rw-r--r-- | platform/winrt/gsview/ghostsharp.cs | 279 | ||||
-rw-r--r-- | platform/winrt/gsview/gsview.csproj | 5 |
5 files changed, 307 insertions, 49 deletions
diff --git a/platform/winrt/gsview/About.xaml b/platform/winrt/gsview/About.xaml index d6776c44..13b3b142 100644 --- a/platform/winrt/gsview/About.xaml +++ b/platform/winrt/gsview/About.xaml @@ -1,9 +1,10 @@ -<Window x:Class="gsview.About" +<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - Title="{Binding RelativeSource={RelativeSource Self}, Mode=OneTime, Path=ProductTitle}" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="gsview.About" + Title="{Binding ProductTitle, Mode=OneTime, RelativeSource={RelativeSource Self}}" x:Uid="idAboutBox" - Style="{DynamicResource AboutDialogStyle}" WindowStartupLocation="CenterOwner"> + Style="{DynamicResource AboutDialogStyle}" WindowStartupLocation="CenterOwner" Height="353" Width="501"> <Window.Resources> <XmlDataProvider x:Key="aboutProvider" XPath="ApplicationInfo" IsAsynchronous="False" IsInitialLoadEnabled="True"> <x:XData> @@ -13,7 +14,7 @@ </x:XData> </XmlDataProvider> <Image x:Key="aboutLogo" Source="resources/banner.png" /> - <Style x:Key="AboutDialogStyle" TargetType="Window"> + <Style x:Key="AboutDialogStyle" TargetType="{x:Type Window}"> <Setter Property="Height" Value="Auto" /> <Setter Property="Width" Value="500" /> <Setter Property="ShowInTaskbar" Value="False" /> @@ -36,7 +37,7 @@ </Setter.Value> </Setter> </Style> - <Style TargetType="Label"> + <Style TargetType="{x:Type Label}"> <Setter Property="Padding" Value="0" /> </Style> <Style x:Key="ParagraphSeparator" TargetType="{x:Type Label}"> @@ -44,7 +45,7 @@ </Style> <Style x:Key="LinkLabelStyle"> <Setter Property="Control.Padding" Value="0" /> - <Setter Property="Control.VerticalAlignment" Value="Center" /> + <Setter Property="FrameworkElement.VerticalAlignment" Value="Center" /> </Style> <Style x:Key="ReadOnlyDescStyle" TargetType="{x:Type TextBox}"> <Setter Property="MinLines" Value="6" /> @@ -64,27 +65,29 @@ <StackPanel x:Uid="clientArea" Style="{StaticResource BackgroundStyle}"> <StaticResource ResourceKey="aboutLogo" /> <StackPanel x:Uid="displayArea" Style="{StaticResource DisplayAreaStyle}" - DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Mode=OneTime}"> + DataContext="{Binding Mode=OneTime, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"> <Label x:Name="productName" x:Uid="productName" - Content="{Binding Mode=OneTime, Path=Product}" /> + Content="{Binding Product, Mode=OneTime}" /> <StackPanel x:Uid="versionArea" Orientation="Horizontal"> <Label x:Name="versionLabel" x:Uid="VersionLabel" Content="Version - " /> - <Label x:Name="version" x:Uid="version" Content="{Binding Mode=OneTime, Path=Version}" /> + <Label x:Name="version" x:Uid="version" Content="{Binding Version, Mode=OneTime}" /> </StackPanel> - <Label x:Name="copyright" x:Uid="copyright" Content="{Binding Mode=OneTime, Path=Copyright}" /> - <Label x:Name="company" x:Uid="company" Content="{Binding Mode=OneTime, Path=Company}" /> + <Label x:Name="copyright" x:Uid="copyright" Content="{Binding Copyright, Mode=OneTime}" /> + <Label x:Name="company" x:Uid="company" Content="{Binding Company, Mode=OneTime}" /> <Label x:Name="reserved" x:Uid="reserved" Content="All Rights Reserved." /> <Label x:Name="info" x:Uid="info" Style="{StaticResource ParagraphSeparator}" - Content="Product details:" /> - <TextBox x:Name="description" x:Uid="description" Text="{Binding Mode=OneTime, Path=Description}" - Style="{StaticResource ReadOnlyDescStyle}" /> + Content="Product details:" /> + <TextBox x:Name="description" x:Uid="description" Text="" + Style="{StaticResource ReadOnlyDescStyle}" Height="140" /> <DockPanel x:Uid="buttonArea"> <Button x:Name="okButton" x:Uid="okButton" Style="{StaticResource OkButtonStyle}" - Content="OK" /> + Content="OK" /> <Label x:Name="productLink" x:Uid="productLink" Style="{StaticResource LinkLabelStyle}" > - <Hyperlink x:Name="hyperlink" x:Uid="hyperlink" NavigateUri="{Binding Mode=OneTime, Path=LinkUri}" Style="{StaticResource LinkLabelStyle}" - Hyperlink.RequestNavigate="hyperlink_RequestNavigate"> - <TextBlock Text="{Binding Mode=OneTime, Path=LinkText}" /> + <Hyperlink x:Name="hyperlink" x:Uid="hyperlink" NavigateUri="{Binding LinkUri, Mode=OneTime}" Style="{StaticResource LinkLabelStyle}" + RequestNavigate="hyperlink_RequestNavigate"> + <InlineUIContainer> + <TextBlock Text="{Binding LinkText, Mode=OneTime}" /> + </InlineUIContainer> </Hyperlink> </Label> </DockPanel> diff --git a/platform/winrt/gsview/About.xaml.cs b/platform/winrt/gsview/About.xaml.cs index 81f888d4..6bd50cbe 100644 --- a/platform/winrt/gsview/About.xaml.cs +++ b/platform/winrt/gsview/About.xaml.cs @@ -5,6 +5,7 @@ using System.Reflection; using System.Windows; using System.Windows.Data; using System.Xml; +using System.ComponentModel; namespace gsview { @@ -19,13 +20,8 @@ namespace gsview protected About() { InitializeComponent(); - InitDescription(); } - private void InitDescription() - { - VariableDescription = CalculatePropertyValue<AssemblyDescriptionAttribute>(propertyNameDescription, xPathDescription); - } /// <summary> /// Constructor that takes a parent for this About dialog. @@ -54,8 +50,8 @@ namespace gsview #region AboutData Provider #region Member data - public String VariableDescription; private XmlDocument xmlDoc = null; + private string variabledescription; private const string propertyNameTitle = "Title"; private const string propertyNameDescription = "Description"; private const string propertyNameProduct = "Product"; @@ -118,7 +114,13 @@ namespace gsview /// </summary> public string Description { - get { return VariableDescription; } + get { return CalculatePropertyValue<AssemblyDescriptionAttribute>(propertyNameDescription, xPathDescription);} + } + + public string VariableDescription + { + get; + set; } /// <summary> diff --git a/platform/winrt/gsview/MainWindow.xaml.cs b/platform/winrt/gsview/MainWindow.xaml.cs index 86bdc575..0700a014 100644 --- a/platform/winrt/gsview/MainWindow.xaml.cs +++ b/platform/winrt/gsview/MainWindow.xaml.cs @@ -258,6 +258,7 @@ namespace gsview m_outputintents = new OutputIntent(); m_outputintents.Activate(); m_ghostscript.gsIOUpdateMain += new ghostsharp.gsIOCallBackMain(gsIO); + m_ghostscript.gsDLLProblemMain += new ghostsharp.gsDLLProblem(gsDLL); m_convertwin = null; m_extractwin = null; m_selection = null; @@ -1198,6 +1199,11 @@ namespace gsview } } + private void gsDLL(object gsObject, String mess) + { + ShowMessage(NotifyType_t.MESS_STATUS, mess); + } + private void gsIO(object gsObject, String mess, int len) { m_gsoutput.Update(mess, len); @@ -3934,12 +3940,17 @@ namespace gsview { String muversion; About about = new About(this); - var desc = about.VariableDescription; + var desc_static = about.Description; + String desc; + /* Get our gs and mupdf version numbers to add to the description */ mu_doc.GetVersion(out muversion); String gs_vers = m_ghostscript.GetVersion(); - desc = desc + "\nBuilt with MuPDF Version " + muversion + "\nGhostscript DLL: " + gs_vers; - about.VariableDescription = desc; + if (gs_vers == null) + desc = desc_static + "\nBuilt with MuPDF Version " + muversion + "\nGhostscript DLL: Not Found"; + else + desc = desc_static + "\nBuilt with MuPDF Version " + muversion + "\nGhostscript DLL: " + gs_vers; + about.description.Text = desc; about.ShowDialog(); } diff --git a/platform/winrt/gsview/ghostsharp.cs b/platform/winrt/gsview/ghostsharp.cs index e4610d79..4b0cf311 100644 --- a/platform/winrt/gsview/ghostsharp.cs +++ b/platform/winrt/gsview/ghostsharp.cs @@ -210,6 +210,251 @@ namespace gsview public static extern void gsapi_run_string_end(IntPtr instance, int usererr, ref int exitcode); + + /* In case the DLL is not found we need to wrap the methods up with + * a try/catch */ + private int tc_gsapi_revision(ref gsapi_revision_t vers, int size) + { + int code = 0; + try + { + code = gsapi_revision(ref vers, size); + } + catch (DllNotFoundException) + { + /* DLL not found */ + String output = "DllNotFoundException: Ghostscript DLL not found"; + gsDLLProblemMain(this, output); + return -1; + } + catch (BadImageFormatException) + { + /* Using 32 bit with 64 or vice versa */ + String output = "BadImageFormatException: Incorrect Ghostscript DLL"; + gsDLLProblemMain(this, output); + return -1; + } + return code; + } + + private int tc_gsapi_new_instance(out IntPtr pinstance, IntPtr caller_handle) + { + int code = 0; + pinstance = IntPtr.Zero; + try + { + code = gsapi_new_instance(out pinstance, caller_handle); + } + catch (DllNotFoundException) + { + /* DLL not found */ + String output = "DllNotFoundException: Ghostscript DLL not found"; + gsDLLProblemMain(this, output); + return -1; + } + catch (BadImageFormatException) + { + /* Using 32 bit with 64 or vice versa */ + String output = "BadImageFormatException: Incorrect Ghostscript DLL"; + gsDLLProblemMain(this, output); + return -1; + } + return code; + } + + private int tc_gsapi_delete_instance(IntPtr instance) + { + try + { + gsapi_delete_instance(instance); + } + catch (DllNotFoundException) + { + /* DLL not found */ + String output = "DllNotFoundException: Ghostscript DLL not found"; + gsDLLProblemMain(this, output); + return -1; + } + catch (BadImageFormatException) + { + /* Using 32 bit with 64 or vice versa */ + String output = "BadImageFormatException: Incorrect Ghostscript DLL"; + gsDLLProblemMain(this, output); + return -1; + } + return 0; + } + + private int tc_gsapi_init_with_args(IntPtr instance, int argc, IntPtr argv) + { + int code; + try + { + code = gsapi_init_with_args(instance, argc, argv); + } + catch (DllNotFoundException) + { + /* DLL not found */ + String output = "DllNotFoundException: Ghostscript DLL not found"; + gsDLLProblemMain(this, output); + return -1; + } + catch (BadImageFormatException) + { + /* Using 32 bit with 64 or vice versa */ + String output = "BadImageFormatException: Incorrect Ghostscript DLL"; + gsDLLProblemMain(this, output); + return -1; + } + return code; + } + + private int tc_gsapi_exit(IntPtr instance) + { + int code; + try + { + code = gsapi_exit(instance); + } + catch (DllNotFoundException) + { + /* DLL not found */ + String output = "DllNotFoundException: Ghostscript DLL not found"; + gsDLLProblemMain(this, output); + return -1; + } + catch (BadImageFormatException) + { + /* Using 32 bit with 64 or vice versa */ + String output = "BadImageFormatException: Incorrect Ghostscript DLL"; + gsDLLProblemMain(this, output); + return -1; + } + return code; + } + + private int tc_gsapi_set_arg_encoding(IntPtr instance, int encoding) + { + int code; + try + { + code = gsapi_set_arg_encoding(instance, encoding); + } + catch (DllNotFoundException) + { + /* DLL not found */ + String output = "DllNotFoundException: Ghostscript DLL not found"; + gsDLLProblemMain(this, output); + return -1; + } + catch (BadImageFormatException) + { + /* Using 32 bit with 64 or vice versa */ + String output = "BadImageFormatException: Incorrect Ghostscript DLL"; + gsDLLProblemMain(this, output); + return -1; + } + return code; + } + + private int tc_gsapi_set_stdio(IntPtr instance, gsStdIOHandler stdin, + gsStdIOHandler stdout, gsStdIOHandler stderr) + { + int code; + try + { + code = gsapi_set_stdio(instance, stdin, stdout, stderr); + } + catch (DllNotFoundException) + { + /* DLL not found */ + String output = "DllNotFoundException: Ghostscript DLL not found"; + gsDLLProblemMain(this, output); + return -1; + } + catch (BadImageFormatException) + { + /* Using 32 bit with 64 or vice versa */ + String output = "BadImageFormatException: Incorrect Ghostscript DLL"; + gsDLLProblemMain(this, output); + return -1; + } + return code; + } + + private int tc_gsapi_run_string_begin(IntPtr instance, int usererr, + ref int exitcode) + { + try + { + gsapi_run_string_begin(instance, usererr, ref exitcode); + } + catch (DllNotFoundException) + { + /* DLL not found */ + String output = "DllNotFoundException: Ghostscript DLL not found"; + gsDLLProblemMain(this, output); + return -1; + } + catch (BadImageFormatException) + { + /* Using 32 bit with 64 or vice versa */ + String output = "BadImageFormatException: Incorrect Ghostscript DLL"; + gsDLLProblemMain(this, output); + return -1; + } + return 0; + } + + private int tc_gsapi_run_string_continue(IntPtr instance, IntPtr command, + int count, int usererr, ref int exitcode) + { + try + { + gsapi_run_string_continue(instance, command, count, usererr, + ref exitcode); + } + catch (DllNotFoundException) + { + /* DLL not found */ + String output = "DllNotFoundException: Ghostscript DLL not found"; + gsDLLProblemMain(this, output); + return -1; + } + catch (BadImageFormatException) + { + /* Using 32 bit with 64 or vice versa */ + String output = "BadImageFormatException: Incorrect Ghostscript DLL"; + gsDLLProblemMain(this, output); + return -1; + } + return 0; + } + + private int tc_gsapi_run_string_end(IntPtr instance, int usererr, + ref int exitcode) + { + try + { + gsapi_run_string_end(instance, usererr, ref exitcode); + } + catch (DllNotFoundException) + { + /* DLL not found */ + String output = "DllNotFoundException: Ghostscript DLL not found"; + gsDLLProblemMain(this, output); + return -1; + } + catch (BadImageFormatException) + { + /* Using 32 bit with 64 or vice versa */ + String output = "BadImageFormatException: Incorrect Ghostscript DLL"; + gsDLLProblemMain(this, output); + return -1; + } + return 0; + } + private int StdInCallback(IntPtr handle, IntPtr pointer, int count) { String output = Marshal.PtrToStringAnsi(pointer); @@ -277,6 +522,8 @@ namespace gsview BackgroundWorker m_worker; gsParams_t m_params; /* Callbacks to Main */ + internal delegate void gsDLLProblem(object gsObject, String mess); + internal event gsDLLProblem gsDLLProblemMain; internal delegate void gsIOCallBackMain(object gsObject, String mess, int len); internal event gsIOCallBackMain gsIOUpdateMain; internal delegate void gsCallBackMain(object gsObject, gsEventArgs info); @@ -337,7 +584,7 @@ namespace gsview GCHandle argPtrsStable; /* New instance */ - int code = gsapi_new_instance(out gsInstance, IntPtr.Zero); + int code = tc_gsapi_new_instance(out gsInstance, IntPtr.Zero); if (code < 0) { gsparams.result = GS_Result_t.gsFAILED; @@ -354,9 +601,9 @@ namespace gsview var stdErrPtr = Marshal.GetFunctionPointerForDelegate(RaiseStdErrCallback); // Setup stdio callback functions - code = gsapi_set_stdio(gsInstance, RaiseStdInCallback, RaiseStdOutCallback, RaiseStdErrCallback); + code = tc_gsapi_set_stdio(gsInstance, RaiseStdInCallback, RaiseStdOutCallback, RaiseStdErrCallback); - code = gsapi_set_arg_encoding(gsInstance, (int) gsEncoding.GS_ARG_ENCODING_UTF8); + code = tc_gsapi_set_arg_encoding(gsInstance, (int)gsEncoding.GS_ARG_ENCODING_UTF8); if (code == 0) { @@ -446,7 +693,7 @@ namespace gsview /* Also stick the array of pointers into memory that will not be GCd */ argPtrsStable = GCHandle.Alloc(argPtrs, GCHandleType.Pinned); - code = gsapi_init_with_args(gsInstance, num_params, argPtrsStable.AddrOfPinnedObject()); + code = tc_gsapi_init_with_args(gsInstance, num_params, argPtrsStable.AddrOfPinnedObject()); /* All the pinned items need to be freed so the GC can do its job */ for (int k = 0; k < num_params; k++) @@ -462,7 +709,7 @@ namespace gsview } } - int code1 = gsapi_exit(gsInstance); + int code1 = tc_gsapi_exit(gsInstance); if ((code == 0) || (code == gsConstants.E_QUIT)) code = code1; @@ -470,7 +717,7 @@ namespace gsview RaiseStdOutCallback = null; RaiseStdErrCallback = null; - gsapi_delete_instance(gsInstance); + tc_gsapi_delete_instance(gsInstance); if ((code == 0) || (code == gsConstants.E_QUIT)) { gsparams.result = GS_Result_t.gsOK; @@ -508,7 +755,7 @@ namespace gsview var fs = new FileStream(in_file, FileMode.Open); var len = (int) fs.Length; /* New instance */ - int code = gsapi_new_instance(out gsInstance, IntPtr.Zero); + int code = tc_gsapi_new_instance(out gsInstance, IntPtr.Zero); if (code < 0) { Params.result = GS_Result_t.gsFAILED; @@ -525,9 +772,9 @@ namespace gsview var stdErrPtr = Marshal.GetFunctionPointerForDelegate(RaiseStdErrCallback); // Setup stdio callback functions - code = gsapi_set_stdio(gsInstance, RaiseStdInCallback, RaiseStdOutCallback, RaiseStdErrCallback); + code = tc_gsapi_set_stdio(gsInstance, RaiseStdInCallback, RaiseStdOutCallback, RaiseStdErrCallback); - code = gsapi_set_arg_encoding(gsInstance, (int)gsEncoding.GS_ARG_ENCODING_UTF8); + code = tc_gsapi_set_arg_encoding(gsInstance, (int)gsEncoding.GS_ARG_ENCODING_UTF8); if (code == 0) { @@ -567,7 +814,7 @@ namespace gsview /* Also stick the array of pointers into memory that will not be GCd */ argPtrsStable = GCHandle.Alloc(argPtrs, GCHandleType.Pinned); - code = gsapi_init_with_args(gsInstance, num_params, argPtrsStable.AddrOfPinnedObject()); + code = tc_gsapi_init_with_args(gsInstance, num_params, argPtrsStable.AddrOfPinnedObject()); /* First pin the data buffer */ Feed = GCHandle.Alloc(Buffer, GCHandleType.Pinned); @@ -581,10 +828,10 @@ namespace gsview double perc; int total = 0; - gsapi_run_string_begin(gsInstance, 0, ref exitcode); + tc_gsapi_run_string_begin(gsInstance, 0, ref exitcode); while ((count = fs.Read(Buffer, 0, gsConstants.GS_READ_BUFFER)) > 0) { - gsapi_run_string_continue(gsInstance, FeedPtr, count, 0, ref exitcode); + tc_gsapi_run_string_continue(gsInstance, FeedPtr, count, 0, ref exitcode); if (exitcode < 0) { code = exitcode; @@ -599,7 +846,7 @@ namespace gsview break; } } - gsapi_run_string_end(gsInstance, 0, ref exitcode); + tc_gsapi_run_string_end(gsInstance, 0, ref exitcode); if (code == 0) code = exitcode; } @@ -613,11 +860,11 @@ namespace gsview Feed.Free(); } - int code1 = gsapi_exit(gsInstance); + int code1 = tc_gsapi_exit(gsInstance); if ((code == 0) || (code == gsConstants.E_QUIT)) code = code1; - gsapi_delete_instance(gsInstance); + tc_gsapi_delete_instance(gsInstance); if ((code == 0) || (code == gsConstants.E_QUIT)) { Params.result = GS_Result_t.gsOK; @@ -747,7 +994,7 @@ namespace gsview vers.revisiondate = 0; int size = System.Runtime.InteropServices.Marshal.SizeOf(vers); - if (gsapi_revision(ref vers, size) == 0) + if (tc_gsapi_revision(ref vers, size) == 0) { String product = Marshal.PtrToStringAnsi(vers.product); String output; diff --git a/platform/winrt/gsview/gsview.csproj b/platform/winrt/gsview/gsview.csproj index 51970af2..04718d5f 100644 --- a/platform/winrt/gsview/gsview.csproj +++ b/platform/winrt/gsview/gsview.csproj @@ -264,11 +264,6 @@ <WCFMetadata Include="Service References\" /> </ItemGroup> <ItemGroup> - <Resource Include="AboutLogo.png"> - <SubType>Image</SubType> - </Resource> - </ItemGroup> - <ItemGroup> <Resource Include="Resources\banner.png" /> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |