diff --git a/src/MainWindow.xaml.cs b/src/MainWindow.xaml.cs index 90b185e..cf44f41 100644 --- a/src/MainWindow.xaml.cs +++ b/src/MainWindow.xaml.cs @@ -300,12 +300,16 @@ private void Initialize() _mediaFileServer = new MediaFileServer($"http://localhost:{port}/", RequestHandlerMethod); port = 0; } + catch (NotSupportedException) + { + port = 0; + } catch (HttpListenerException) { port = new Random().Next(50000, 65000); } - } while (port != 0 || count < 3); - _mediaFileServer.Run(); + } while (port != 0 && count < 3); + _mediaFileServer?.Run(); } } diff --git a/src/MediaFileServer.cs b/src/MediaFileServer.cs index aef2943..b0874c8 100644 --- a/src/MediaFileServer.cs +++ b/src/MediaFileServer.cs @@ -6,7 +6,7 @@ namespace WpfImageViewer { internal class MediaFileServer { - private readonly HttpListener _httpListener = new HttpListener(); + private readonly HttpListener _httpListener; private readonly Func _requestHandlerMethod; private string _prefix; @@ -14,6 +14,10 @@ internal class MediaFileServer public MediaFileServer(string prefix, Func requestHandlerMethod) { + if (!HttpListener.IsSupported) throw new NotSupportedException(); + + _httpListener = new HttpListener(); + _ = prefix ?? throw new ArgumentNullException(nameof(prefix)); _ = requestHandlerMethod ?? throw new ArgumentNullException(nameof(requestHandlerMethod)); diff --git a/src/Properties/AssemblyInfo.cs b/src/Properties/AssemblyInfo.cs index 83c60c1..0fc422f 100644 --- a/src/Properties/AssemblyInfo.cs +++ b/src/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("WpfImageViewer")] -[assembly: AssemblyCopyright("Copyright © 2021 thomas694 (@GH)")] +[assembly: AssemblyCopyright("Copyright © 2022 thomas694 (@GH)")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -48,5 +48,5 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("1.3.1.0")] -[assembly: AssemblyFileVersion("1.3.1.0")] +[assembly: AssemblyVersion("1.3.2.0")] +[assembly: AssemblyFileVersion("1.3.2.0")]