From a9e7a3cb5bbf6ed43e275f217ea0b6c158ec9aad Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Sat, 16 Feb 2019 02:50:53 -0600 Subject: [PATCH] More enumerator usage --- DS4Windows/DS4Control/ControlService.cs | 13 +++++++++---- DS4Windows/DS4Control/ScpUtil.cs | 6 ++++-- DS4Windows/DS4Library/DS4Devices.cs | 6 ++++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/DS4Windows/DS4Control/ControlService.cs b/DS4Windows/DS4Control/ControlService.cs index 82f5fb5..30a9db5 100644 --- a/DS4Windows/DS4Control/ControlService.cs +++ b/DS4Windows/DS4Control/ControlService.cs @@ -346,9 +346,12 @@ namespace DS4Windows DS4LightBar.defaultLight = false; //foreach (DS4Device device in devices) - for (int i = 0, devCount = devices.Count(); i < devCount; i++) + //for (int i = 0, devCount = devices.Count(); i < devCount; i++) + int i = 0; + for (var devEnum = devices.GetEnumerator(); devEnum.MoveNext(); i++) { - DS4Device device = devices.ElementAt(i); + DS4Device device = devEnum.Current; + //DS4Device device = devices.ElementAt(i); if (showlog) LogDebug(Properties.Resources.FoundController + device.getMacAddress() + " (" + device.getConnectionType() + ")"); @@ -561,9 +564,11 @@ namespace DS4Windows DS4Devices.findControllers(); IEnumerable devices = DS4Devices.getDS4Controllers(); //foreach (DS4Device device in devices) - for (int i = 0, devlen = devices.Count(); i < devlen; i++) + //for (int i = 0, devlen = devices.Count(); i < devlen; i++) + for (var devEnum = devices.GetEnumerator(); devEnum.MoveNext();) { - DS4Device device = devices.ElementAt(i); + DS4Device device = devEnum.Current; + //DS4Device device = devices.ElementAt(i); if (device.isDisconnectingStatus()) continue; diff --git a/DS4Windows/DS4Control/ScpUtil.cs b/DS4Windows/DS4Control/ScpUtil.cs index 9823864..d33ba7d 100644 --- a/DS4Windows/DS4Control/ScpUtil.cs +++ b/DS4Windows/DS4Control/ScpUtil.cs @@ -3507,9 +3507,11 @@ namespace DS4Windows linkedXdoc.AppendChild(Node); Dictionary.KeyCollection serials = linkedProfiles.Keys; - for (int i = 0, itemCount = linkedProfiles.Count; i < itemCount; i++) + //for (int i = 0, itemCount = linkedProfiles.Count; i < itemCount; i++) + for (var serialEnum = serials.GetEnumerator(); serialEnum.MoveNext();) { - string serial = serials.ElementAt(i); + //string serial = serials.ElementAt(i); + string serial = serialEnum.Current; string profile = linkedProfiles[serial]; XmlElement link = linkedXdoc.CreateElement("MAC" + serial); link.InnerText = profile; diff --git a/DS4Windows/DS4Library/DS4Devices.cs b/DS4Windows/DS4Library/DS4Devices.cs index 6aaa4f1..c97ea87 100644 --- a/DS4Windows/DS4Library/DS4Devices.cs +++ b/DS4Windows/DS4Library/DS4Devices.cs @@ -179,9 +179,11 @@ namespace DS4Windows { IEnumerable devices = getDS4Controllers(); //foreach (DS4Device device in devices) - for (int i = 0, devCount = devices.Count(); i < devCount; i++) + //for (int i = 0, devCount = devices.Count(); i < devCount; i++) + for (var devEnum = devices.GetEnumerator(); devEnum.MoveNext();) { - DS4Device device = devices.ElementAt(i); + DS4Device device = devEnum.Current; + //DS4Device device = devices.ElementAt(i); device.StopUpdate(); //device.runRemoval(); device.HidDevice.CloseDevice();