示例#1
0
        private bool TestQsvNv12(AdapterInfo qsvAdapter)
        {
            try
            {
                var options = new VideoRenderOptions(VideoRenderType.HardwareSpecific, qsvAdapter.Name, IntPtr.Zero, false, 0);
                var dx      = DirectXContextFactory.CreateDevice(options);
                using var dxContext = new DirectXContext(dx.Item1, options, dx.Item2, dx.Item3, null);

                if (!dxContext.Nv12Supported)
                {
                    Core.LogInfo($"Device {qsvAdapter.Name} does not have n12 format support");
                }

                if (Test <EncoderContextQsvDx>("", "", EncoderContextQsvDx.TypeName, dxContext))
                {
                    Core.LogInfo($"Device {qsvAdapter.Name} successfully tested for nv12 support");
                    return(true);
                }
            }
            catch (Exception e)
            {
                Core.LogError(e, $"Device {qsvAdapter.Name} failed in test for nv12 support");
            }
            return(false);
        }
        private void ReadAdapterFiles()
        {
            try
            {
                string path = Paths.ADAPTERS;

                if (Directory.Exists(path))
                {
                    var files = Directory.GetFiles(path, Files.ADAPTER_INI, SearchOption.AllDirectories);
                    if (files != null)
                    {
                        AdapterItems.Clear();

                        foreach (var file in files)
                        {
                            var info = AdapterInfo.Read(file);

                            var item = new Controls.AdapterItem(info);
                            item.RemoveClicked += AdapterItem_RemoveClicked;
                            AdapterItems.Add(item);
                        }
                    }
                }
            }
            catch (Exception ex) { Console.WriteLine(ex.Message); }
        }
        public override unsafe bool QuerySupportedAdapters(bool allowSoftwareAdapters, out AdapterInfo[] adapters)
        {
            const int maxNameLength = 64, maxAdapters = 32;
            uint      adapterNameCount = maxAdapters;
            byte **   adapterNamesPtr  = stackalloc byte *[maxAdapters];

            for (int i = 0; i != maxAdapters; ++i)
            {
                byte *adapterNamePtr = stackalloc byte[maxNameLength];
                adapterNamesPtr[i] = adapterNamePtr;
            }
            uint *adapterIndices = stackalloc uint[maxAdapters];

            if (Orbital_Video_Vulkan_Instance_QuerySupportedAdapters(handle, adapterNamesPtr, maxNameLength, adapterIndices, &adapterNameCount) == 0)
            {
                adapters = null;
                return(false);
            }

            adapters = new AdapterInfo[adapterNameCount];
            for (int i = 0; i != adapterNameCount; ++i)
            {
                string name = Marshal.PtrToStringAnsi((IntPtr)adapterNamesPtr[i]);
                adapters[i] = new AdapterInfo((int)adapterIndices[i], name);
            }
            return(true);
        }
示例#4
0
        private void GetAdapterList()
        {
            ListAdapter = new ObservableCollection <AdapterObject>();

            if (adapterInfo != null)
            {
                adapterInfo.RefreshInfos();
            }

            adapterInfo = AdapterInfo.CreateInstance();

            adapterInfo.listAdapter.ForEach(adapter =>
            {
                var adp = ListAdapter.Where(x => x.Name == adapter.Name).FirstOrDefault();
                if (adp != null)
                {
                    adp.IsDHCPEnabled = adapter.IsDHCPEnabled;
                }
                else
                {
                    ListAdapter.Add(adapter);
                }
            });

            ListAdapter = new ObservableCollection <AdapterObject>(ListAdapter.OrderByDescending(x => x.IsOperationalStatusUp));
        }
        /// <summary>
        /// Releases the adapter and associated unmanaged references.
        /// </summary>
        private void ReleaseAdapter()
        {
            if (CurrentAdapterInfo.AdapterHandle != 0)
            {
                try
                {
                    var closeInfo = default(CloseAdapterInfo);
                    closeInfo.AdapterHandle = CurrentAdapterInfo.AdapterHandle;

                    // This will return 0 on success, and another value for failure.
                    var closeAdapterResult = NativeMethods.D3DKMTCloseAdapter(ref closeInfo);
                }
                catch
                {
                    // ignore
                }
            }

            if (CurrentAdapterInfo.DCHandle != IntPtr.Zero)
            {
                try
                {
                    // this will return 1 on success, 0 on failure.
                    var deleteContextResult = NativeMethods.DeleteDC(CurrentAdapterInfo.DCHandle);
                }
                catch
                {
                    // ignore
                }
            }

            DisplayDevice      = null;
            CurrentAdapterInfo = default;
            VerticalSyncEvent  = default;
        }
        /// <summary>
        /// Ensures the adapter is avaliable.
        /// If the adapter cannot be created, the <see cref="IsAvailable"/> property is permanently set to false.
        /// </summary>
        /// <returns>True if the adapter is available, and false otherwise.</returns>
        private bool EnsureAdapter()
        {
            if (DisplayDevice == null)
            {
                DisplayDevice = PrimaryDisplayDevice;
                if (DisplayDevice == null)
                {
                    IsAvailable = false;
                    return(false);
                }
            }

            if (CurrentAdapterInfo.DCHandle == IntPtr.Zero)
            {
                try
                {
                    CurrentAdapterInfo          = default;
                    CurrentAdapterInfo.DCHandle = NativeMethods.CreateDC(DisplayDevice.Value.DeviceName, null, null, IntPtr.Zero);
                    if (CurrentAdapterInfo.DCHandle == IntPtr.Zero)
                    {
                        throw new NotSupportedException("Unable to create DC for adapter.");
                    }
                }
                catch
                {
                    ReleaseAdapter();
                    IsAvailable = false;
                    return(false);
                }
            }

            if (VerticalSyncEvent.AdapterHandle == 0 && CurrentAdapterInfo.DCHandle != IntPtr.Zero)
            {
                try
                {
                    var openAdapterResult = NativeMethods.D3DKMTOpenAdapterFromHdc(ref CurrentAdapterInfo);
                    if (openAdapterResult == 0)
                    {
                        VerticalSyncEvent = default;
                        VerticalSyncEvent.AdapterHandle   = CurrentAdapterInfo.AdapterHandle;
                        VerticalSyncEvent.DeviceHandle    = 0;
                        VerticalSyncEvent.PresentSourceId = CurrentAdapterInfo.PresentSourceId;
                    }
                    else
                    {
                        throw new NotSupportedException("Unable to open D3D adapter.");
                    }
                }
                catch
                {
                    ReleaseAdapter();
                    IsAvailable = false;
                    return(false);
                }
            }

            return(VerticalSyncEvent.AdapterHandle != 0);
        }
示例#7
0
        public static IList <AdapterInfo> getIPAddresses()
        {
            var   adapters  = new List <AdapterInfo>();
            uint  outBufLen = 0;
            ERROR err       = (ERROR)Sockets.SocketsApi.GetAdapterAddresses(AddressFamily.InterNetwork, (uint)0, IntPtr.Zero, ref outBufLen);

            if (ERROR.ERROR_BUFFER_OVERFLOW == err)
            {
                byte[] buffer = new byte[outBufLen];

                var bufferHandle = Microsoft.Phone.InteropServices.GCHandle.Alloc(buffer, GCHandleType.Pinned);

                IntPtr pAdapterAddresses = bufferHandle.AddrOfPinnedObject();
                try
                {
                    err = (ERROR)Sockets.SocketsApi.GetAdapterAddresses(AddressFamily.InterNetwork, (uint)0, pAdapterAddresses, ref outBufLen);
                    if (ERROR.ERROR_SUCCESS == err)
                    {
                        IntPtr currPtr = pAdapterAddresses;
                        while (IntPtr.Zero != currPtr)
                        {
                            IP_ADAPTER_ADDRESSES addr = (IP_ADAPTER_ADDRESSES)Microsoft.Phone.InteropServices.Marshal.PtrToStructure(currPtr, typeof(IP_ADAPTER_ADDRESSES));

                            AdapterInfo ainfo = new AdapterInfo();

                            ainfo.FriendlyName = addr.FriendlyName;
                            ainfo.Description  = addr.Description;

                            if (IntPtr.Zero != addr.FirstUnicastAddress)
                            {
                                IP_ADAPTER_UNICAST_ADDRESS unicastAddr = (IP_ADAPTER_UNICAST_ADDRESS)Microsoft.Phone.InteropServices.Marshal.PtrToStructure(addr.FirstUnicastAddress, typeof(IP_ADAPTER_UNICAST_ADDRESS));
                                if (IntPtr.Zero != unicastAddr.Address.lpSockAddr)
                                {
                                    // TODO check ipv4 and ipv6

                                    SOCKADDR  socketAddr = (SOCKADDR)Microsoft.Phone.InteropServices.Marshal.PtrToStructure(unicastAddr.Address.lpSockAddr, typeof(SOCKADDR));
                                    byte[]    saData     = socketAddr.sa_data; // skip take
                                    IPAddress ipAddr     = new IPAddress(GetBytes(saData));
                                    ainfo.Address = ipAddr;
                                }
                            }
                            adapters.Add(ainfo);
                            currPtr = addr.Next;
                        }
                    }
                }
                finally
                {
                    bufferHandle.Free();
                }
            }
            return(adapters);
        }
示例#8
0
        private void InterfacesList_Load(object sender, EventArgs e)
        {
            this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
            this.dataGridView2.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;

            NetworkInterfaceList nil = new NetworkInterfaceList();

            this.dataGridView1.DataSource = null;
            this.dataGridView1.DataSource = nil.Interfaces;
            this.dataGridView2.DataSource = null;
            this.dataGridView2.DataSource = AdapterInfo.GetAdapters();
        }
示例#9
0
        public AdapterItem(AdapterInfo info)
        {
            Init();

            adapterInfo = info;

            ServiceName = info.ServiceName;
            FocusHost   = info.FocusHost;
            Port        = info.Port;

            ServerMonitor_Initialize();
        }
 public HostInformation(byte[] b, AdapterInfo info)
 {
     if (b == null)
     {
         throw new ArgumentNullException("b");
     }
     if (b.Length != 8)
     {
         throw new ArgumentOutOfRangeException("b");
     }
     _address = new byte[b.Length];
     Array.Copy(b, _address, b.Length);
 }
        private void AdapterItem_RemoveClicked(AdapterInfo info)
        {
            if (info != null)
            {
                UninstallAdapter(info);
            }

            int i = AdapterItems.ToList().FindIndex(x => x.ServiceName == info.ServiceName);

            if (i >= 0)
            {
                AdapterItems.RemoveAt(i);
            }
        }
        public DirectXContext(Device device, VideoRenderOptions options, AdapterInfo item2, bool adapterIsEqualToWindowAdapter, IStreamerBase streamer)
        {
            AdapterIsEqualToWindowAdapter = AdapterIsEqualToWindowAdapter;
            _refCount       = 1;
            Device          = device;
            CreationOptions = options;
            ImagingFactory2 = new ImagingFactory();
            Pool            = new DirectXResourcePool(this);

            var nv12Support = device.CheckFormatSupport(SharpDX.DXGI.Format.NV12);

            AdapterInfo   = item2;
            _streamer     = streamer;
            Nv12Supported = nv12Support.HasFlag(FormatSupport.RenderTarget) && nv12Support.HasFlag(FormatSupport.Texture2D);
        }
示例#13
0
        public AdapterInfo GetAdapterInfoByIP(IPAddress IP)
        {
            if (UpdateInterfaces)
            {
                UpdateNetworks();
            }

            AdapterInfo Info = null;

            if (!AdapterInfoByIP.TryGetValue(IP, out Info))
            {
                Info         = new AdapterInfo();
                Info.Profile = DefaultProfile;
            }
            return(Info);
        }
        private bool EnsureAdapter()
        {
            if (IsAdapterOpen)
            {
                return(true);
            }

            var displayDevices = EnumerateDisplayDevices();

            if (displayDevices.Length == 0)
            {
                ReleaseAdapter();
                return(false);
            }

            var primaryDisplayName = displayDevices.FirstOrDefault(d => d.StateFlags.HasFlag(DisplayDeviceStateFlags.PrimaryDevice)).DeviceName;

            CurrentAdapterInfo          = default;
            CurrentAdapterInfo.DCHandle = NativeMethods.CreateDC(primaryDisplayName, null, null, IntPtr.Zero);

            var openAdapterResult = NativeMethods.D3DKMTOpenAdapterFromHdc(ref CurrentAdapterInfo);

            if (openAdapterResult == 0)
            {
                IsAdapterOpen     = true;
                VerticalSyncEvent = default;
                VerticalSyncEvent.AdapterHandle   = CurrentAdapterInfo.AdapterHandle;
                VerticalSyncEvent.DeviceHandle    = 0;
                VerticalSyncEvent.PresentSourceId = CurrentAdapterInfo.PresentSourceId;
            }
            else
            {
                IsAdapterOpen     = false;
                VerticalSyncEvent = default;
            }

            return(IsAdapterOpen);
        }
        public List <HostInformation> GetMacAddresses()
        {
            int size = 0;

            int r = GetAdaptersInfo(null, ref size);

            if ((r != IPConfigConst.ERROR_SUCCESS) && (r != IPConfigConst.ERROR_BUFFER_OVERFLOW))
            {
                return(null);
            }
            Byte[] buffer = new Byte[size];
            r = GetAdaptersInfo(buffer, ref size);
            if (r != IPConfigConst.ERROR_SUCCESS)
            {
                return(null);
            }
            AdapterInfo Adapter = new AdapterInfo();

            ByteArray_To_IPAdapterInfo(ref Adapter, buffer, Marshal.SizeOf(Adapter));

            List <HostInformation> addresses = new List <HostInformation>();

            do
            {
                addresses.Add(new HostInformation(Adapter.Address, Adapter));
                IntPtr p = Adapter.NextPointer;
                if (p != IntPtr.Zero)
                {
                    IntPtr_To_IPAdapterInfo(ref Adapter, p, Marshal.SizeOf(Adapter));
                }
                else
                {
                    break;
                }
            } while (true);

            return(addresses);
        }
        private void UninstallAdapter(AdapterInfo info)
        {
            Cursor = System.Windows.Input.Cursors.Wait;

            try
            {
                AdapterManagement.Stop(info.ServiceName);
                AdapterManagement.Uninstall(info.ServiceName);

                // Remove adapter from Agent Configuration File (agent.cfg);
                var adapterInfos = ReadAgentAdapters();
                var match1       = adapterInfos.Find(x => x.DeviceName == info.DeviceName);
                if (match1 != null)
                {
                    adapterInfos.Remove(match1);
                }

                AgentConfigurationFile.WriteAdapters(adapterInfos);

                // Remove Device node from Agent's devices.xml file
                var deviceInfos = AgentDevicesFile.ReadDeviceInfos();
                var match2      = deviceInfos.Find(x => x.DeviceName == info.DeviceName);
                if (match2 != null)
                {
                    string id = match2.DeviceId;

                    AgentDevicesFile.DeleteDeviceNode("//Device[@id=\"" + id + "\"]");
                }

                // Delete adapter folder in "Adapters"
                string path = Path.GetDirectoryName(info.Path);
                Directory.Delete(path, true);
            }
            catch (Exception ex) { Console.WriteLine(ex.Message); }

            Cursor = System.Windows.Input.Cursors.Arrow;
        }
示例#17
0
        public static List <MacAddress> GetMacAddresses()
        {
            int size = 0;
            // this chunk of code teases out the first adapter info
            int r = GetAdaptersInfo(null, ref size);

            if ((r != IPConfigConst.ERROR_SUCCESS) && (r != IPConfigConst.ERROR_BUFFER_OVERFLOW))
            {
                return(null);
            }
            Byte[] buffer = new Byte[size];
            r = GetAdaptersInfo(buffer, ref size);
            if (r != IPConfigConst.ERROR_SUCCESS)
            {
                return(null);
            }
            AdapterInfo Adapter = new AdapterInfo();

            ByteArray_To_IPAdapterInfo(ref Adapter, buffer, Marshal.SizeOf(Adapter));

            List <MacAddress> addresses = new List <MacAddress>();

            do
            {
                addresses.Add(new MacAddress(Adapter.Address));
                IntPtr p = Adapter.NextPointer;
                if (p != IntPtr.Zero)
                {
                    IntPtr_To_IPAdapterInfo(ref Adapter, p, Marshal.SizeOf(Adapter));
                }
                else
                {
                    break;
                }
            } while (true);
            return(addresses);
        }
示例#18
0
        public override unsafe bool QuerySupportedAdapters(bool allowSoftwareAdapters, out AdapterInfo[] adapters)
        {
            const int maxAdapters = 16, maxNameLength = 64;
            int       adapterNameCount = maxAdapters;
            var       adapters_Native  = stackalloc AdapterInfo_NativeInterop[maxAdapters];

            for (int i = 0; i != maxAdapters; ++i)
            {
                char *adapterNamePtr = stackalloc char[maxNameLength];
                adapters_Native[i].name = (IntPtr)adapterNamePtr;
            }

            if (Orbital_Video_D3D12_Instance_QuerySupportedAdapters(handle, (byte)(allowSoftwareAdapters ? 1 : 0), adapters_Native, &adapterNameCount, maxNameLength) == 0)
            {
                adapters = null;
                return(false);
            }

            adapters = new AdapterInfo[adapterNameCount];
            for (int i = 0; i != adapterNameCount; ++i)
            {
                var adapter = &adapters_Native[i];
                adapters[i] = new AdapterInfo
                              (
                    adapter->isPrimary != 0 ? true : false,
                    adapter->index,
                    Marshal.PtrToStringUni(adapter->name),
                    adapter->vendorID,
                    adapter->nodeCount,
                    adapter->dedicatedGPUMemory.ToUInt64(),
                    adapter->deticatedSystemMemory.ToUInt64(),
                    adapter->sharedSystemMemory.ToUInt64()
                              );
            }
            return(true);
        }
示例#19
0
        public AdapterInfo GetAdapterInfoByIP(IPAddress IP)
        {
            AdapterInfo Info = null;

            if (!AdapterInfoByIP.TryGetValue(IP, out Info))
            {
                // if the last network list update was more than a second ago, update again and retry
                if (MiscFunc.GetTickCount64() - LastNetworkUpdate >= 1000)
                {
                    UpdateNetworks();

                    // retry
                    AdapterInfoByIP.TryGetValue(IP, out Info);
                }
            }

            if (Info == null)
            {
                Info         = new AdapterInfo();
                Info.Profile = DefaultProfile;
            }

            return(Info);
        }
        private void ReadAdapterFiles()
        {
            string path = Paths.ADAPTER_TEMPLATES;

            if (Directory.Exists(path))
            {
                var files = Directory.GetFiles(path, Files.ADAPTER_INI, SearchOption.AllDirectories);
                if (files != null)
                {
                    foreach (var file in files)
                    {
                        string type = Directory.GetParent(file).Name;

                        var info = AdapterInfo.Read(file);

                        var bt = new ListButton();
                        bt.Selected  += Adapter_Selected;
                        bt.Text       = type;
                        bt.DataObject = Directory.GetParent(file).FullName;
                        Adapters.Add(bt);
                    }
                }
            }
        }
 public static extern uint D3DKMTOpenAdapterFromHdc(ref AdapterInfo adapterInfo);
示例#22
0
 private static bool TryCreate(string name, ref bool deviceCreationFailed, ref (Device, AdapterInfo) device, Func <(Device, AdapterInfo)> creator)
        private void GraphicsConfiguration_Load(object sender, EventArgs e)
        {
            int num = DllExterns._GetNumberOfAdapters();

            if (num > 0)
            {
                this.Adapter_Combo.Enabled            = true;
                this.Resolution_Combo.Enabled         = true;
                this.AA_Combo.Enabled                 = true;
                this.Vsync_combo.Enabled              = true;
                this.NoAdapterWarning_label.Visible   = false;
                GlobalDefs.OutputAdapter.ValidAdapter = true;
                DisplayModes item = default(DisplayModes);
                item.modeNo = 0;
                this.mDisplayModesList.Add(item);
                item.modeNo = 1;
                this.mDisplayModesList.Add(item);
                LowHigh item2 = default(LowHigh);
                item2.bIsHigh = true;
                this.mShadowList.Add(item2);
                this.mReflectionList.Add(item2);
                item2.bIsHigh = false;
                this.mShadowList.Add(item2);
                this.mReflectionList.Add(item2);
                OnOff item3 = default(OnOff);
                item3.bVsync = true;
                this.mVsyncList.Add(item3);
                item3.bVsync = false;
                this.mVsyncList.Add(item3);
                for (int i = 0; i < num; i++)
                {
                    AdapterInfo item4 = default(AdapterInfo);
                    DllExterns._GetAdapterData(i, ref item4);
                    Array.Resize <Resolution>(ref item4.AResArray, item4.NoOfRes);
                    item4.AAList[0] = 0;
                    item4.AAList[1] = 1;
                    Array.Resize <int>(ref item4.AAList, 2);
                    this.mGraphicsAdapterList.Add(item4);
                }
                int num2 = 0;
                int num3 = 0;
                int num4 = 0;
                foreach (AdapterInfo adapterInfo in this.mGraphicsAdapterList)
                {
                    if (adapterInfo.AdapterDescription == GlobalDefs.OutputAdapter.AdapterDescription && adapterInfo.AdapterName == GlobalDefs.OutputAdapter.AdapterName)
                    {
                        num3 = num2;
                        break;
                    }
                    num2++;
                }
                int selectedIndex = this.mGraphicsAdapterList[num3].DefaultResIndex;
                num2 = 0;
                foreach (Resolution resolution in this.mGraphicsAdapterList[num3].AResArray)
                {
                    if (resolution.DisplayName == GlobalDefs.OutputAdapter.OutputRes.DisplayName)
                    {
                        selectedIndex = num2;
                        break;
                    }
                    num2++;
                }
                num2 = 0;
                foreach (int num5 in this.mGraphicsAdapterList[num3].AAList)
                {
                    if (num5 == GlobalDefs.OutputAdapter.AA)
                    {
                        num4 = num2;
                        break;
                    }
                    num2++;
                }
                this.Adapter_Combo.DataSource = null;
                this.Adapter_Combo.Items.Clear();
                this.Adapter_Combo.DataSource       = this.mGraphicsAdapterList;
                this.Adapter_Combo.DisplayMember    = "DisplayName";
                this.Adapter_Combo.SelectedIndex    = num3;
                this.Resolution_Combo.SelectedIndex = selectedIndex;
                if (this.mAATypesList.Count <AATypes>() > num4)
                {
                    this.AA_Combo.SelectedIndex = num4;
                }
                else
                {
                    this.AA_Combo.SelectedIndex = 0;
                }
                bool flag;
                bool flag2;
                bool flag3;
                bool flag4;
                if (GlobalDefs.GraphicsConfigFileRead)
                {
                    this.Windowed_Check.Checked = GlobalDefs.OutputAdapter.bWindowed;
                    flag  = GlobalDefs.OutputAdapter.ShadQuality;
                    flag2 = GlobalDefs.OutputAdapter.ReflectQuality;
                    flag3 = GlobalDefs.OutputAdapter.DisplayMode;
                    flag4 = GlobalDefs.OutputAdapter.bVSync;
                }
                else
                {
                    this.Windowed_Check.Checked = true;
                    this.VSync_Check.Checked    = true;
                    flag  = true;
                    flag2 = true;
                    flag3 = false;
                    flag4 = true;
                }
                this.DispMode_combo.DataSource = null;
                this.DispMode_combo.Items.Clear();
                this.DispMode_combo.DataSource    = this.mDisplayModesList;
                this.DispMode_combo.DisplayMember = "DisplayName";
                if (flag3)
                {
                    this.DispMode_combo.SelectedIndex = 1;
                }
                else
                {
                    this.DispMode_combo.SelectedIndex = 0;
                }
                this.Shadow_Combo.DataSource = null;
                this.Shadow_Combo.Items.Clear();
                this.Shadow_Combo.DataSource    = this.mShadowList;
                this.Shadow_Combo.DisplayMember = "DisplayName";
                if (flag)
                {
                    this.Shadow_Combo.SelectedIndex = 0;
                }
                else
                {
                    this.Shadow_Combo.SelectedIndex = 1;
                }
                this.Reflection_Combo.DataSource = null;
                this.Reflection_Combo.Items.Clear();
                this.Reflection_Combo.DataSource    = this.mReflectionList;
                this.Reflection_Combo.DisplayMember = "DisplayName";
                if (flag2)
                {
                    this.Reflection_Combo.SelectedIndex = 0;
                }
                else
                {
                    this.Reflection_Combo.SelectedIndex = 1;
                }
                this.Vsync_combo.DataSource = null;
                this.Vsync_combo.Items.Clear();
                this.Vsync_combo.DataSource    = this.mVsyncList;
                this.Vsync_combo.DisplayMember = "DisplayName";
                if (flag4)
                {
                    this.Vsync_combo.SelectedIndex = 0;
                }
                else
                {
                    this.Vsync_combo.SelectedIndex = 1;
                }
            }
            else
            {
                GlobalDefs globalDefs = new GlobalDefs();
                this.Adapter_Combo.Enabled                  = false;
                this.Resolution_Combo.Enabled               = false;
                this.AA_Combo.Enabled                       = false;
                this.VSync_Check.Enabled                    = false;
                this.DispMode_combo.Enabled                 = false;
                this.Shadow_Combo.Enabled                   = false;
                this.Reflection_Combo.Enabled               = false;
                this.Vsync_combo.Enabled                    = false;
                this.NoAdapterWarning_label.Visible         = true;
                GlobalDefs.OutputAdapter.AdapterDescription = "";
                GlobalDefs.OutputAdapter.AdapterName        = "";
                GlobalDefs.OutputAdapter.DeviceGUID         = globalDefs.ZERO_GUID;
                GlobalDefs.OutputAdapter.AdapterID          = "";
                GlobalDefs.OutputAdapter.OutputRes.Height   = 0;
                GlobalDefs.OutputAdapter.OutputRes.Refresh  = 0;
                GlobalDefs.OutputAdapter.OutputRes.Width    = 0;
                GlobalDefs.OutputAdapter.ValidAdapter       = false;
                GlobalDefs.OutputAdapter.DisplayMode        = false;
                GlobalDefs.OutputAdapter.ShadQuality        = false;
                GlobalDefs.OutputAdapter.ReflectQuality     = false;
            }
            this.DressText();
        }
示例#24
0
        public bool UpdateNetworks()
        {
            //  foreach (NetworkInterface adapter in Interfaces)
            // todo: get data rates etc... adapter.GetIPStatistics()

            if (!UpdateInterfaces)
            {
                return(false);
            }
            UpdateInterfaces = false;

            Dictionary <string, FirewallRule.Profiles> NetworkProfiles = new Dictionary <string, FirewallRule.Profiles>();

            foreach (INetwork network in netMgr.GetNetworks(NLM_ENUM_NETWORK.NLM_ENUM_NETWORK_CONNECTED).Cast <INetwork>())
            {
                FirewallRule.Profiles FirewallProfile = FirewallRule.Profiles.Undefined;
                switch (network.GetCategory())
                {
                case NLM_NETWORK_CATEGORY.NLM_NETWORK_CATEGORY_PRIVATE:                 FirewallProfile = FirewallRule.Profiles.Private; break;

                case NLM_NETWORK_CATEGORY.NLM_NETWORK_CATEGORY_PUBLIC:                  FirewallProfile = FirewallRule.Profiles.Public; break;

                case NLM_NETWORK_CATEGORY.NLM_NETWORK_CATEGORY_DOMAIN_AUTHENTICATED:    FirewallProfile = FirewallRule.Profiles.Domain; break;
                }

                foreach (INetworkConnection connection in network.GetNetworkConnections().Cast <INetworkConnection>())
                {
                    string id = ("{" + connection.GetAdapterId().ToString() + "}").ToLower();

                    NetworkProfiles.Add(id, FirewallProfile);
                }
            }

            //DefaultProfile = App.engine.FirewallManager.GetCurrentProfiles();

            AdapterInfoByIP.Clear();
            //AppLog.Debug("ListingNetworks:");

            Interfaces = NetworkInterface.GetAllNetworkInterfaces(); // this is a bit slow!
            foreach (NetworkInterface adapter in Interfaces)
            {
                try
                {
                    //AppLog.Debug("{0} {1} {2} {3}", adapter.Description, adapter.Id, adapter.NetworkInterfaceType.ToString(), adapter.OperationalStatus.ToString());

                    string id = adapter.Id.ToLower();

                    AdapterInfo Info = new AdapterInfo();
                    if (!NetworkProfiles.TryGetValue(id, out Info.Profile))
                    {
                        Info.Profile = DefaultProfile;
                    }

                    switch (adapter.NetworkInterfaceType)
                    {
                    case NetworkInterfaceType.Ethernet:
                    case NetworkInterfaceType.GigabitEthernet:
                    case NetworkInterfaceType.FastEthernetT:
                    case NetworkInterfaceType.FastEthernetFx:
                    case NetworkInterfaceType.Ethernet3Megabit:
                    case NetworkInterfaceType.TokenRing: Info.Type = FirewallRule.Interfaces.Lan; break;

                    case NetworkInterfaceType.Wireless80211: Info.Type = FirewallRule.Interfaces.Wireless; break;

                    case NetworkInterfaceType.Ppp: Info.Type = FirewallRule.Interfaces.RemoteAccess; break;

                    default: Info.Type = FirewallRule.Interfaces.All; break;
                    }

                    Info.Addresses = new List <UnicastIPAddressInformation>();
                    IPInterfaceProperties ip_info = adapter.GetIPProperties();
                    Info.GatewayAddresses = new List <IPAddress>();
                    foreach (var gw in ip_info.GatewayAddresses)
                    {
                        Info.GatewayAddresses.Add(gw.Address);
                    }
                    Info.DnsAddresses         = ip_info.DnsAddresses;
                    Info.DhcpServerAddresses  = ip_info.DhcpServerAddresses;
                    Info.WinsServersAddresses = ip_info.WinsServersAddresses;

                    foreach (UnicastIPAddressInformation ip in adapter.GetIPProperties().UnicastAddresses)
                    {
                        Info.Addresses.Add(ip);

                        // Sanitize IPv6 addresses
                        IPAddress _ip = new IPAddress(ip.Address.GetAddressBytes());

                        //AppLog.Debug("{2}({5}) has IP {0}/{3}/{4} has profile {1}", ip.Address.ToString(), ((FirewallRule.Profiles)Info.Profile).ToString(),
                        //    adapter.Description, ip.IPv4Mask.ToString(), ip.PrefixLength.ToString(), adapter.NetworkInterfaceType.ToString());

                        if (!AdapterInfoByIP.ContainsKey(_ip))
                        {
                            AdapterInfoByIP[_ip] = Info;
                        }
                    }
                }
                catch { } // in case a adapter becomes invalid justa fter the enumeration
            }
            //AppLog.Debug("+++");

            NetworksChanged?.Invoke(this, new EventArgs());
            return(true);
        }
    public static List <AdapterInfo> GetAdapters()
    {
        var    adapters   = new List <AdapterInfo>();
        long   structSize = Marshal.SizeOf(typeof(IP_ADAPTER_INFO));
        IntPtr pArray     = Marshal.AllocHGlobal(new IntPtr(structSize));
        int    ret        = GetAdaptersInfo(pArray, ref structSize);

        if (ret == ERROR_BUFFER_OVERFLOW)     // ERROR_BUFFER_OVERFLOW == 111
        {
            // Buffer was too small, reallocate the correct size for the buffer.
            pArray = Marshal.ReAllocHGlobal(pArray, new IntPtr(structSize));
            ret    = GetAdaptersInfo(pArray, ref structSize);
        }
        if (ret == 0)
        {
            // Call Succeeded
            IntPtr pEntry = pArray;
            do
            {
                var adapter = new AdapterInfo();
                // Retrieve the adapter info from the memory address
                var entry = (IP_ADAPTER_INFO)Marshal.PtrToStructure(pEntry, typeof(IP_ADAPTER_INFO));
                // Adapter Type
                switch (entry.Type)
                {
                case MIB_IF_TYPE_ETHERNET:
                    adapter.Type = "Ethernet";
                    break;

                case MIB_IF_TYPE_TOKENRING:
                    adapter.Type = "Token Ring";
                    break;

                case MIB_IF_TYPE_FDDI:
                    adapter.Type = "FDDI";
                    break;

                case MIB_IF_TYPE_PPP:
                    adapter.Type = "PPP";
                    break;

                case MIB_IF_TYPE_LOOPBACK:
                    adapter.Type = "Loopback";
                    break;

                case MIB_IF_TYPE_SLIP:
                    adapter.Type = "Slip";
                    break;

                default:
                    adapter.Type = "Other/Unknown";
                    break;
                }     // switch
                adapter.Name        = entry.AdapterName;
                adapter.Description = entry.AdapterDescription;
                // MAC Address (data is in a byte[])
                adapter.MAC = string.Join("-", Enumerable.Range(0, (int)entry.AddressLength).Select(s => string.Format("{0:X2}", entry.Address[s])));
                // Get next adapter (if any)
                adapters.Add(adapter);
                pEntry = entry.Next;
            }while (pEntry != IntPtr.Zero);
            Marshal.FreeHGlobal(pArray);
        }
        else
        {
            Marshal.FreeHGlobal(pArray);
            throw new InvalidOperationException("GetAdaptersInfo failed: " + ret);
        }
        return(adapters);
    }
示例#26
0
        private void Settings_Load(object sender, System.EventArgs e)
        {
            // Retrieve all adapters and the active one
            AdapterRetriever adapterRetriever = new AdapterRetriever();
            AdapterInfo      adapterInfo      = adapterRetriever.Info();
            int activeIndex = -1;

            string[] adapters = new string[adapterInfo.All.Count];
            foreach (Tuple <int, string, string> singleAdapter in adapterInfo.All)
            {
                // Set active adapter if no settings were defined
                if (singleAdapter.Item2.Equals(adapterInfo.Active))
                {
                    activeIndex = singleAdapter.Item1;
                }
                adapters[singleAdapter.Item1] = singleAdapter.Item3;
            }

            // Populate adapters
            combox_adapt.Items.AddRange(adapters);

            // Load the settings
            cbox_run_background.Checked = Properties.Settings.Default.backgroundservice;
            cbox_autostart.Checked      = Properties.Settings.Default.autostart;
            if (Properties.Settings.Default.adapter == -1)
            {
                combox_adapt.SelectedIndex = activeIndex;
            }
            else
            {
                combox_adapt.SelectedIndex = Properties.Settings.Default.adapter;
            }
            int methodIPv4 = Properties.Settings.Default.ipv4_dt_method;

            switch (methodIPv4)
            {
            case (1):
                rbtn_remote_ipv4.Checked           = true;
                cbox_remote_alternate_ipv4.Checked = false;
                break;

            case (2):
                rbtn_remote_ipv4.Checked           = true;
                cbox_remote_alternate_ipv4.Checked = true;
                break;

            case (3):
                rbtn_local_net_adapter_ipv4.Checked = true;
                break;
            }

            int methodIPv6 = Properties.Settings.Default.ipv6_dt_method;

            switch (methodIPv6)
            {
            case (1):
                rbtn_remote_ipv6.Checked           = true;
                cbox_remote_alternate_ipv6.Checked = false;
                break;

            case (2):
                rbtn_remote_ipv6.Checked           = true;
                cbox_remote_alternate_ipv6.Checked = true;
                break;

            case (3):
                rbtn_local_net_adapter_ipv6.Checked = true;
                break;

            case (4):
                rbtn_wanip_adapter.Checked = true;
                break;

            case (5):
                rbtn_wanip_adapter_tmp.Checked = true;
                break;
            }
        }
 public static extern void _GetAdapterData(int Index, ref AdapterInfo AI);
示例#28
0
        public FirewallRule.Profiles DefaultProfile = FirewallRule.Profiles.Public; // default windows behavioure: default profile is public

        public void UpdateNetworks()
        {
            LastNetworkUpdate = MiscFunc.GetTickCount64();

            Dictionary <string, FirewallRule.Profiles> NetworkProfiles = new Dictionary <string, FirewallRule.Profiles>();

            foreach (INetwork network in netMgr.GetNetworks(NLM_ENUM_NETWORK.NLM_ENUM_NETWORK_CONNECTED).Cast <INetwork>())
            {
                FirewallRule.Profiles FirewallProfile = FirewallRule.Profiles.Undefined;
                switch (network.GetCategory())
                {
                case NLM_NETWORK_CATEGORY.NLM_NETWORK_CATEGORY_PRIVATE:                 FirewallProfile = FirewallRule.Profiles.Private; break;

                case NLM_NETWORK_CATEGORY.NLM_NETWORK_CATEGORY_PUBLIC:                  FirewallProfile = FirewallRule.Profiles.Public; break;

                case NLM_NETWORK_CATEGORY.NLM_NETWORK_CATEGORY_DOMAIN_AUTHENTICATED:    FirewallProfile = FirewallRule.Profiles.Domain; break;
                }

                foreach (INetworkConnection connection in network.GetNetworkConnections().Cast <INetworkConnection>())
                {
                    string id = ("{" + connection.GetAdapterId().ToString() + "}").ToLower();

                    NetworkProfiles.Add(id, FirewallProfile);
                }
            }

            //DefaultProfile = App.engine.FirewallManager.GetCurrentProfiles();

            AdapterInfoByIP.Clear();
            //AppLog.Debug("ListingNetworks:");

            foreach (NetworkInterface adapter in NetworkInterface.GetAllNetworkInterfaces()) // this is a bit slow!
            {
                string id = adapter.Id.ToLower();

                AdapterInfo Info = new AdapterInfo();
                if (!NetworkProfiles.TryGetValue(id, out Info.Profile))
                {
                    Info.Profile = DefaultProfile;
                }

                switch (adapter.NetworkInterfaceType)
                {
                case NetworkInterfaceType.Ethernet:
                case NetworkInterfaceType.GigabitEthernet:
                case NetworkInterfaceType.FastEthernetT:
                case NetworkInterfaceType.FastEthernetFx:
                case NetworkInterfaceType.Ethernet3Megabit:
                case NetworkInterfaceType.TokenRing: Info.Type = FirewallRule.Interfaces.Lan; break;

                case NetworkInterfaceType.Wireless80211: Info.Type = FirewallRule.Interfaces.Wireless; break;

                case NetworkInterfaceType.Ppp: Info.Type = FirewallRule.Interfaces.RemoteAccess; break;

                default: Info.Type = FirewallRule.Interfaces.All; break;
                }

                Info.Addresses = new List <UnicastIPAddressInformation>();
                IPInterfaceProperties ip_info = adapter.GetIPProperties();
                Info.GatewayAddresses = new List <IPAddress>();
                foreach (var gw in ip_info.GatewayAddresses)
                {
                    Info.GatewayAddresses.Add(gw.Address);
                }
                Info.DnsAddresses         = ip_info.DnsAddresses;
                Info.DhcpServerAddresses  = ip_info.DhcpServerAddresses;
                Info.WinsServersAddresses = ip_info.WinsServersAddresses;

                foreach (UnicastIPAddressInformation ip in adapter.GetIPProperties().UnicastAddresses)
                {
                    Info.Addresses.Add(ip);

                    // Sanitize IPv6 addresses
                    IPAddress _ip = new IPAddress(ip.Address.GetAddressBytes());

                    //AppLog.Debug("{2}({5}) has IP {0}/{3}/{4} has profile {1}", ip.Address.ToString(), ((FirewallRule.Profiles)Info.Profile).ToString(),
                    //    adapter.Description, ip.IPv4Mask.ToString(), ip.PrefixLength.ToString(), adapter.NetworkInterfaceType.ToString());

                    if (!AdapterInfoByIP.ContainsKey(_ip))
                    {
                        AdapterInfoByIP[_ip] = Info;
                    }
                }
            }
            //AppLog.Debug("+++");
        }
示例#29
0
 private static extern void IntPtr_To_IPAdapterInfo(ref AdapterInfo dst, IntPtr src, int size);
示例#30
0
 private static extern void ByteArray_To_IPAdapterInfo(ref AdapterInfo dst, Byte[] src, int size);