Skip to content

Commit

Permalink
Added contextual menu for options
Browse files Browse the repository at this point in the history
  • Loading branch information
julienblitte committed Jun 6, 2021
1 parent f6646ce commit 7a546d9
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 65 deletions.
4 changes: 2 additions & 2 deletions UniversalScanner/Arecont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,14 @@ private void deviceFound(string protocol, int version, List<IPAddress> addresses
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
if (!hasNonAutoIPv4 || Config.forceZeroConf)
if (!hasNonAutoIPv4 || Config.getInstance().ForceZeroConf)
{
viewer.deviceFound(protocol, version, ip, deviceModel, serial);
}
}
if (ip.AddressFamily == AddressFamily.InterNetworkV6)
{
if (!hasNonAutoIPv6 || Config.forceLinkLocal)
if (!hasNonAutoIPv6 || Config.getInstance().ForceLinkLocal)
{
viewer.deviceFound(protocol, version, ip, deviceModel, serial);
}
Expand Down
4 changes: 2 additions & 2 deletions UniversalScanner/Axis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ private void deviceFound(string protocol, int version, List<IPAddress> addresses
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
if (!hasNonAutoIPv4 || Config.forceZeroConf)
if (!hasNonAutoIPv4 || Config.getInstance().ForceZeroConf)
{
viewer.deviceFound(protocol, version, ip, deviceModel, serial);
}
}
if (ip.AddressFamily == AddressFamily.InterNetworkV6)
{
if (!hasNonAutoIPv6 || Config.forceLinkLocal)
if (!hasNonAutoIPv6 || Config.getInstance().ForceLinkLocal)
{
viewer.deviceFound(protocol, version, ip, deviceModel, serial);
}
Expand Down
58 changes: 47 additions & 11 deletions UniversalScanner/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,33 @@

namespace UniversalScanner
{
public static class Config
public class Config
{
public static bool enableIPv6;
public static bool forceLinkLocal;
public static bool enableIPv4;
public static bool forceZeroConf;
public static bool forceGenericProtocols;
public static bool debugMode;
public static bool portSharing;
public static bool onvifVerbatim;
public static bool dahuaNetScan;
private bool enableIPv6;
private bool forceLinkLocal;
private bool enableIPv4;
private bool forceZeroConf;
private bool forceGenericProtocols;
private bool debugMode;
private bool portSharing;
private bool onvifVerbatim;
private bool dahuaNetScan;

public bool EnableIPv6 { get => enableIPv6; set { enableIPv6 = value; updateBool(nameof(enableIPv6), value); } }
public bool ForceLinkLocal { get => forceLinkLocal; set { forceLinkLocal = value; updateBool(nameof(forceLinkLocal), value); } }
public bool EnableIPv4 { get => enableIPv4; set { enableIPv4 = value; updateBool(nameof(enableIPv4), value); } }
public bool ForceZeroConf { get => forceZeroConf; set { forceZeroConf = value; updateBool(nameof(forceZeroConf), value); } }
public bool ForceGenericProtocols { get => forceGenericProtocols; set { forceGenericProtocols = value; updateBool(nameof(forceGenericProtocols), value); } }
public bool DebugMode { get => debugMode; set { debugMode = value; updateBool(nameof(debugMode), value); } }
public bool PortSharing { get => portSharing; set { portSharing = value; updateBool(nameof(portSharing), value); } }
public bool OnvifVerbatim { get => onvifVerbatim; set { onvifVerbatim = value; updateBool(nameof(onvifVerbatim), value); } }
public bool DahuaNetScan { get => dahuaNetScan; set { dahuaNetScan = value; updateBool(nameof(dahuaNetScan), value); } }

private static readonly string path = @"Software\UniversalScanner";

static Config()
private static Config instance;

private Config()
{
RegistryKey key;

Expand Down Expand Up @@ -61,7 +73,31 @@ static Config()

dahuaNetScan = key.readBool(nameof(dahuaNetScan), dahuaNetScan);
key.writeBool(nameof(dahuaNetScan), dahuaNetScan);

key.Close();
}
}

public void updateBool(string variable, bool value)
{
RegistryKey key;

key = Registry.CurrentUser.openOrCreate(path);
if (key != null)
{
key.writeBool(variable, value);

key.Close();
}
}

public static Config getInstance()
{
if (instance == null)
{
instance = new Config();
}
return instance;
}
}
}
2 changes: 1 addition & 1 deletion UniversalScanner/Dahua2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public override void scan()
#endif
sendMulticast(IPAddress.Parse(multicastIP), port);
sendBroadcast(port);
if (Config.dahuaNetScan)
if (Config.getInstance().DahuaNetScan)
{
sendNetScan(port);
}
Expand Down
2 changes: 1 addition & 1 deletion UniversalScanner/ScanEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public int listenUdpGlobal(int localPort = 0)
if (!isFreeUdpPort(localPort))
{
Logger.getInstance().WriteLine(Logger.DebugLevel.Warn, String.Format("Warning: ScanEngine.listenUdpGlobal(): Local UDP port {0} is already in use...", localPort));
if (Config.portSharing)
if (Config.getInstance().PortSharing)
{
Logger.getInstance().WriteLine(Logger.DebugLevel.Warn, String.Format("Warning: ScanEngine.listenUdpGlobal(): Trying to share the port {0}...", localPort));
reuseAddress = true;
Expand Down
115 changes: 84 additions & 31 deletions UniversalScanner/UniversalScanner.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7a546d9

Please sign in to comment.