﻿using System;
using System.IO;
using Microsoft.Win32;

namespace FreenetTray.Browsers {
    class Edge: Browser {

        private static string NTVersionRegistryKey = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion";

        public Edge() {
            // for this key we want registry redirection enabled, so no registry view is used
            var reg = Registry.LocalMachine.OpenSubKey(NTVersionRegistryKey);

            string productName = reg.GetValue("ProductName") as string;

            // there's no version info but it isn't useful anyway
            _version = new System.Version(0, 0);

            _isInstalled = productName.StartsWith("Windows 10");

            _isUsable = _isInstalled;

            _args = "microsoft-edge:";

            // there is no .exe, instead a url like scheme is used with explorer.exe
            _path = Path.Combine(Environment.GetEnvironmentVariable("windir"), "explorer.exe");

            _name = "Edge";
        }

    }
}

﻿using System;
using System.IO;
using Microsoft.Win32;

namespace FreenetTray.Browsers {
    class Edge: Browser {

        private static string NTVersionRegistryKey = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion";

        public Edge() {
            RegistryKey reg = null;

            if (Environment.Is64BitOperatingSystem) {
                RegistryKey local64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
                reg = local64.OpenSubKey(NTVersionRegistryKey);
            } else {
                RegistryKey local32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
                reg = local32.OpenSubKey(NTVersionRegistryKey);
            }

            if (reg != null) {
                string productName = reg.GetValue("ProductName") as string;

                _isInstalled = productName.StartsWith("Windows 10");
            } else {
                _isInstalled = false;
            }

            _isUsable = _isInstalled;

            // there's no version info but it isn't useful anyway
            _version = new System.Version(0, 0);

            _args = "microsoft-edge:";

            // there is no .exe, instead a url like scheme is used with explorer.exe
            _path = Path.Combine(Environment.GetEnvironmentVariable("windir"), "explorer.exe");

            _name = "Edge";
        }

    }
}

Check native registry view for Windows version
Check native registry view for Windows version

This fixes Coverity CID 171806

On Windows the CurrentVersion key is only present in the native view
of the registry, so a 32-bit application checking the
windows version on 64-bit Windows needs to check the 64-bit registry
view explicitly.

In practice, the wintray app will never be running in 32-bit mode on
64-bit Windows because we let it run in AnyCPU mode.

The default behavior of checking the native registry view should have
been correct as a result, but it is technically possible for the app
to be run in x86 mode which is where the Coverity defect comes from.

This will make sure the code does the right thing either way.
