From 7b32405471e1dc1efa79a53810b315a793467dc6 Mon Sep 17 00:00:00 2001 From: Roman Glebsky Date: Mon, 13 Nov 2023 07:47:35 +0700 Subject: [PATCH 1/2] added saving UniqueDeviceName GUID between SWYH starts --- SWYH/Properties/Settings.Designer.cs | 15 +++++++++++++++ SWYH/UPnP/SwyhDevice.cs | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/SWYH/Properties/Settings.Designer.cs b/SWYH/Properties/Settings.Designer.cs index 476d1f2..51307c0 100644 --- a/SWYH/Properties/Settings.Designer.cs +++ b/SWYH/Properties/Settings.Designer.cs @@ -83,6 +83,21 @@ public string AudioDevice { } } + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string UniqueDeviceName + { + get + { + return ((string)(this["UniqueDeviceName"])); + } + set + { + this["UniqueDeviceName"] = value; + } + } + [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("True")] diff --git a/SWYH/UPnP/SwyhDevice.cs b/SWYH/UPnP/SwyhDevice.cs index d00e49a..c70161c 100644 --- a/SWYH/UPnP/SwyhDevice.cs +++ b/SWYH/UPnP/SwyhDevice.cs @@ -63,6 +63,13 @@ public SwyhDevice() this.Device.ModelNumber = string.Format("{0}.{1}", fileVersion.ProductMajorPart, fileVersion.ProductMinorPart); this.Device.SerialNumber = string.Format("SWYH_UPNP_{0}{1}", fileVersion.ProductMajorPart, fileVersion.ProductMinorPart); + if (!Guid.TryParse(SWYH.Properties.Settings.Default.UniqueDeviceName, out _)) + { + SWYH.Properties.Settings.Default.UniqueDeviceName = Guid.NewGuid().ToString(); + SWYH.Properties.Settings.Default.Save(); + } + this.Device.UniqueDeviceName = SWYH.Properties.Settings.Default.UniqueDeviceName; + this.Device.HasPresentation = true; this.Device.PresentationURL = "about/swyh.html"; this.Device.DeviceURN = "urn:schemas-upnp-org:device:MediaServer:1"; From 6f8968deeab009cfcc24146830d3c324dcb9c9e6 Mon Sep 17 00:00:00 2001 From: Roman Glebsky Date: Mon, 13 Nov 2023 08:37:03 +0700 Subject: [PATCH 2/2] added saving UniqueDeviceName GUID between SWYH starts --- SWYH/App.xaml.cs | 9 ++++++++- SWYH/UPnP/SwyhDevice.cs | 8 +++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/SWYH/App.xaml.cs b/SWYH/App.xaml.cs index 80ce879..9c3b202 100644 --- a/SWYH/App.xaml.cs +++ b/SWYH/App.xaml.cs @@ -107,7 +107,14 @@ private void Application_Startup(object sender, StartupEventArgs e) this.rendererDiscovery = new AVRendererDiscovery((new AVRendererDiscovery.DiscoveryHandler(RendererAddedSink))); this.rendererDiscovery.OnRendererRemoved += new AVRendererDiscovery.DiscoveryHandler(new AVRendererDiscovery.DiscoveryHandler(RendererRemovedSink)); this.wasapiProvider = new WasapiProvider(); - this.swyhDevice = new SwyhDevice(); + + if (!Guid.TryParse(SWYH.Properties.Settings.Default.UniqueDeviceName, out _)) + { + SWYH.Properties.Settings.Default.UniqueDeviceName = Guid.NewGuid().ToString(); + SWYH.Properties.Settings.Default.Save(); + } + + this.swyhDevice = new SwyhDevice(SWYH.Properties.Settings.Default.UniqueDeviceName); this.swyhDevice.Start(); notifyIcon.ShowBalloonTip(2000, "Stream What You Hear is running", "Right-click on this icon to show the menu !", System.Windows.Forms.ToolTipIcon.Info); } diff --git a/SWYH/UPnP/SwyhDevice.cs b/SWYH/UPnP/SwyhDevice.cs index c70161c..0625b36 100644 --- a/SWYH/UPnP/SwyhDevice.cs +++ b/SWYH/UPnP/SwyhDevice.cs @@ -48,7 +48,7 @@ internal class SwyhDevice public DvContentDirectory ContentDirectory { get; private set; } public DvConnectionManager ConnectionManager { get; private set; } - public SwyhDevice() + public SwyhDevice(string UniqueDeviceName = "") { this.Device = UPnPDevice.CreateRootDevice(1800, 1.0, "\\"); @@ -63,12 +63,10 @@ public SwyhDevice() this.Device.ModelNumber = string.Format("{0}.{1}", fileVersion.ProductMajorPart, fileVersion.ProductMinorPart); this.Device.SerialNumber = string.Format("SWYH_UPNP_{0}{1}", fileVersion.ProductMajorPart, fileVersion.ProductMinorPart); - if (!Guid.TryParse(SWYH.Properties.Settings.Default.UniqueDeviceName, out _)) + if (Guid.TryParse(UniqueDeviceName, out _)) { - SWYH.Properties.Settings.Default.UniqueDeviceName = Guid.NewGuid().ToString(); - SWYH.Properties.Settings.Default.Save(); + this.Device.UniqueDeviceName = UniqueDeviceName; } - this.Device.UniqueDeviceName = SWYH.Properties.Settings.Default.UniqueDeviceName; this.Device.HasPresentation = true; this.Device.PresentationURL = "about/swyh.html";