From 59ace5d01b24f7598c35f9369a57246d4ec4b7ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Fri, 9 May 2014 08:47:05 +0200 Subject: [PATCH] new shorthand Exts.(Try)ParseIntegerInvariant --- OpenRA.Game/Exts.cs | 13 ++++- OpenRA.Game/FieldLoader.cs | 54 +++++++++---------- OpenRA.Game/FileSystem/MixFile.cs | 2 +- OpenRA.Game/Graphics/CursorProvider.cs | 5 +- OpenRA.Game/Graphics/CursorSequence.cs | 11 ++-- OpenRA.Game/Graphics/Sequence.cs | 15 +++--- OpenRA.Game/Manifest.cs | 5 +- OpenRA.Game/Map/Map.cs | 9 ++-- OpenRA.Game/Server/Server.cs | 5 +- OpenRA.Game/Support/Evaluator.cs | 5 +- OpenRA.Game/WRange.cs | 9 ++-- OpenRA.Irc/IrcClient.cs | 3 +- OpenRA.Irc/IrcClientUser.cs | 5 +- OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs | 27 +++++----- .../Widgets/Logic/DirectConnectLogic.cs | 5 +- .../Widgets/Logic/ServerBrowserLogic.cs | 3 +- .../Widgets/Logic/ServerCreationLogic.cs | 5 +- OpenRA.Mods.RA/Widgets/Logic/SettingsLogic.cs | 9 ++-- OpenRA.Utility/Command.cs | 7 ++- OpenRA.Utility/LegacyMapImporter.cs | 34 ++++++------ OpenRA.Utility/UpgradeRules.cs | 9 ++-- 21 files changed, 117 insertions(+), 123 deletions(-) mode change 100755 => 100644 OpenRA.Game/FieldLoader.cs diff --git a/OpenRA.Game/Exts.cs b/OpenRA.Game/Exts.cs index 41d98389b0..05f6b44570 100755 --- a/OpenRA.Game/Exts.cs +++ b/OpenRA.Game/Exts.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2014 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; using System.Drawing; +using System.Globalization; using System.Linq; using System.Reflection; @@ -251,6 +252,16 @@ namespace OpenRA throw new InvalidOperationException("ToBits only accepts up to 32 values."); return result; } + + public static int ParseIntegerInvariant(string s) + { + return int.Parse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo); + } + + public static bool TryParseIntegerInvariant(string s, out int i) + { + return int.TryParse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out i); + } } public static class Enum diff --git a/OpenRA.Game/FieldLoader.cs b/OpenRA.Game/FieldLoader.cs old mode 100755 new mode 100644 index 51a8cb4956..ed4f02eea5 --- a/OpenRA.Game/FieldLoader.cs +++ b/OpenRA.Game/FieldLoader.cs @@ -116,7 +116,7 @@ namespace OpenRA if (fieldType == typeof(int)) { int res; - if (int.TryParse(value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out res)) + if (Exts.TryParseIntegerInvariant(value, out res)) return res; return InvalidValueAction(value, fieldType, fieldName); } @@ -165,15 +165,15 @@ namespace OpenRA var parts = value.Split(','); if (parts.Length == 3) return Color.FromArgb( - int.Parse(parts[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo).Clamp(0, 255), - int.Parse(parts[1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo).Clamp(0, 255), - int.Parse(parts[2], NumberStyles.Integer, NumberFormatInfo.InvariantInfo).Clamp(0, 255)); + Exts.ParseIntegerInvariant(parts[0]).Clamp(0, 255), + Exts.ParseIntegerInvariant(parts[1]).Clamp(0, 255), + Exts.ParseIntegerInvariant(parts[2]).Clamp(0, 255)); if (parts.Length == 4) return Color.FromArgb( - int.Parse(parts[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo).Clamp(0, 255), - int.Parse(parts[1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo).Clamp(0, 255), - int.Parse(parts[2], NumberStyles.Integer, NumberFormatInfo.InvariantInfo).Clamp(0, 255), - int.Parse(parts[3], NumberStyles.Integer, NumberFormatInfo.InvariantInfo).Clamp(0, 255)); + Exts.ParseIntegerInvariant(parts[0]).Clamp(0, 255), + Exts.ParseIntegerInvariant(parts[1]).Clamp(0, 255), + Exts.ParseIntegerInvariant(parts[2]).Clamp(0, 255), + Exts.ParseIntegerInvariant(parts[3]).Clamp(0, 255)); return InvalidValueAction(value, fieldType, fieldName); } @@ -184,9 +184,9 @@ namespace OpenRA // Allow old ColorRamp format to be parsed as HSLColor if (parts.Length == 3 || parts.Length == 4) return new HSLColor( - (byte)int.Parse(parts[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo).Clamp(0, 255), - (byte)int.Parse(parts[1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo).Clamp(0, 255), - (byte)int.Parse(parts[2], NumberStyles.Integer, NumberFormatInfo.InvariantInfo).Clamp(0, 255)); + (byte)Exts.ParseIntegerInvariant(parts[0]).Clamp(0, 255), + (byte)Exts.ParseIntegerInvariant(parts[1]).Clamp(0, 255), + (byte)Exts.ParseIntegerInvariant(parts[2]).Clamp(0, 255)); return InvalidValueAction(value, fieldType, fieldName); } @@ -238,7 +238,7 @@ namespace OpenRA else if (fieldType == typeof(WAngle)) { int res; - if (int.TryParse(value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out res)) + if (Exts.TryParseIntegerInvariant(value, out res)) return new WAngle(res); return InvalidValueAction(value, fieldType, fieldName); } @@ -249,9 +249,9 @@ namespace OpenRA if (parts.Length == 3) { int rr, rp, ry; - if (int.TryParse(value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out rr) - && int.TryParse(value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out rp) - && int.TryParse(value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out ry)) + if (Exts.TryParseIntegerInvariant(value, out rr) + && Exts.TryParseIntegerInvariant(value, out rp) + && Exts.TryParseIntegerInvariant(value, out ry)) return new WRot(new WAngle(rr), new WAngle(rp), new WAngle(ry)); } @@ -262,16 +262,16 @@ namespace OpenRA { var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); return new CPos( - int.Parse(parts[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo), - int.Parse(parts[1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo)); + Exts.ParseIntegerInvariant(parts[0]), + Exts.ParseIntegerInvariant(parts[1])); } else if (fieldType == typeof(CVec)) { var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); return new CVec( - int.Parse(parts[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo), - int.Parse(parts[1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo)); + Exts.ParseIntegerInvariant(parts[0]), + Exts.ParseIntegerInvariant(parts[1])); } else if (fieldType.IsEnum) @@ -306,16 +306,16 @@ namespace OpenRA { var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); return new Size( - int.Parse(parts[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo), - int.Parse(parts[1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo)); + Exts.ParseIntegerInvariant(parts[0]), + Exts.ParseIntegerInvariant(parts[1])); } else if (fieldType == typeof(int2)) { var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); return new int2( - int.Parse(parts[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo), - int.Parse(parts[1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo)); + Exts.ParseIntegerInvariant(parts[0]), + Exts.ParseIntegerInvariant(parts[1])); } else if (fieldType == typeof(float2)) @@ -335,10 +335,10 @@ namespace OpenRA { var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); return new Rectangle( - int.Parse(parts[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo), - int.Parse(parts[1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo), - int.Parse(parts[2], NumberStyles.Integer, NumberFormatInfo.InvariantInfo), - int.Parse(parts[3], NumberStyles.Integer, NumberFormatInfo.InvariantInfo)); + Exts.ParseIntegerInvariant(parts[0]), + Exts.ParseIntegerInvariant(parts[1]), + Exts.ParseIntegerInvariant(parts[2]), + Exts.ParseIntegerInvariant(parts[3])); } else if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(Bits<>)) diff --git a/OpenRA.Game/FileSystem/MixFile.cs b/OpenRA.Game/FileSystem/MixFile.cs index 5a9d2b442b..54298d729f 100644 --- a/OpenRA.Game/FileSystem/MixFile.cs +++ b/OpenRA.Game/FileSystem/MixFile.cs @@ -142,7 +142,7 @@ namespace OpenRA.FileSystem // Maybe we were given a raw hash? uint raw; if (!uint.TryParse(filename, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out raw)) - return null; + return null; if ("{0:X}".F(raw) == filename && index.ContainsKey(raw)) return raw; diff --git a/OpenRA.Game/Graphics/CursorProvider.cs b/OpenRA.Game/Graphics/CursorProvider.cs index b84fdef6c3..e5e26101bd 100644 --- a/OpenRA.Game/Graphics/CursorProvider.cs +++ b/OpenRA.Game/Graphics/CursorProvider.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2013 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2014 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, @@ -9,7 +9,6 @@ #endregion using System; -using System.Globalization; using System.Collections.Generic; using System.Linq; using OpenRA.FileSystem; @@ -42,7 +41,7 @@ namespace OpenRA.Graphics if (sequences.NodesDict.ContainsKey("ShadowIndex")) { Array.Resize(ref shadowIndex, shadowIndex.Length + 1); - int.TryParse(sequences.NodesDict["ShadowIndex"].Value, NumberStyles.Any, NumberFormatInfo.InvariantInfo, + Exts.TryParseIntegerInvariant(sequences.NodesDict["ShadowIndex"].Value, out shadowIndex[shadowIndex.Length - 1]); } diff --git a/OpenRA.Game/Graphics/CursorSequence.cs b/OpenRA.Game/Graphics/CursorSequence.cs index 1672261e6e..ae4405d573 100644 --- a/OpenRA.Game/Graphics/CursorSequence.cs +++ b/OpenRA.Game/Graphics/CursorSequence.cs @@ -8,7 +8,6 @@ */ #endregion -using System.Globalization; using OpenRA.FileFormats; namespace OpenRA.Graphics @@ -31,22 +30,22 @@ namespace OpenRA.Graphics sprites = Game.modData.SpriteLoader.LoadAllSprites(cursorSrc); var d = info.NodesDict; - start = int.Parse(d["start"].Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo); + start = Exts.ParseIntegerInvariant(d["start"].Value); this.palette = palette; if ((d.ContainsKey("length") && d["length"].Value == "*") || (d.ContainsKey("end") && d["end"].Value == "*")) length = sprites.Length - start; else if (d.ContainsKey("length")) - length = int.Parse(d["length"].Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo); + length = Exts.ParseIntegerInvariant(d["length"].Value); else if (d.ContainsKey("end")) - length = int.Parse(d["end"].Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo) - start; + length = Exts.ParseIntegerInvariant(d["end"].Value) - start; else length = 1; if (d.ContainsKey("x")) - int.TryParse(d["x"].Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out Hotspot.X); + Exts.TryParseIntegerInvariant(d["x"].Value, out Hotspot.X); if (d.ContainsKey("y")) - int.TryParse(d["y"].Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out Hotspot.Y); + Exts.TryParseIntegerInvariant(d["y"].Value, out Hotspot.Y); } public Sprite GetSprite(int frame) diff --git a/OpenRA.Game/Graphics/Sequence.cs b/OpenRA.Game/Graphics/Sequence.cs index e816a41c96..c0e9a63ee7 100644 --- a/OpenRA.Game/Graphics/Sequence.cs +++ b/OpenRA.Game/Graphics/Sequence.cs @@ -9,7 +9,6 @@ #endregion using System; -using System.Globalization; using System.Linq; namespace OpenRA.Graphics @@ -41,7 +40,7 @@ namespace OpenRA.Graphics try { if (d.ContainsKey("Start")) - Start = int.Parse(d["Start"].Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo); + Start = Exts.ParseIntegerInvariant(d["Start"].Value); if (d.ContainsKey("Offset")) offset = FieldLoader.GetValue("Offset", d["Offset"].Value); @@ -59,16 +58,16 @@ namespace OpenRA.Graphics else if (d["Length"].Value == "*") Length = sprites.Length - Start; else - Length = int.Parse(d["Length"].Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo); + Length = Exts.ParseIntegerInvariant(d["Length"].Value); if (d.ContainsKey("Stride")) - Stride = int.Parse(d["Stride"].Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo); + Stride = Exts.ParseIntegerInvariant(d["Stride"].Value); else Stride = Length; if (d.ContainsKey("Facings")) { - var f = int.Parse(d["Facings"].Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo); + var f = Exts.ParseIntegerInvariant(d["Facings"].Value); Facings = Math.Abs(f); reverseFacings = f < 0; } @@ -76,7 +75,7 @@ namespace OpenRA.Graphics Facings = 1; if (d.ContainsKey("Tick")) - Tick = int.Parse(d["Tick"].Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo); + Tick = Exts.ParseIntegerInvariant(d["Tick"].Value); else Tick = 40; @@ -84,10 +83,10 @@ namespace OpenRA.Graphics transpose = bool.Parse(d["Transpose"].Value); if (d.ContainsKey("Frames")) - Frames = Array.ConvertAll(d["Frames"].Value.Split(','), (s) => int.Parse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo)); + Frames = Array.ConvertAll(d["Frames"].Value.Split(','), Exts.ParseIntegerInvariant); if (d.ContainsKey("ShadowStart")) - ShadowStart = int.Parse(d["ShadowStart"].Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo); + ShadowStart = Exts.ParseIntegerInvariant(d["ShadowStart"].Value); else ShadowStart = -1; diff --git a/OpenRA.Game/Manifest.cs b/OpenRA.Game/Manifest.cs index 2eddc94166..3efa61b6ee 100644 --- a/OpenRA.Game/Manifest.cs +++ b/OpenRA.Game/Manifest.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2013 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2014 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, @@ -10,7 +10,6 @@ using System.Collections.Generic; using System.Drawing; -using System.Globalization; using System.IO; using System.Linq; using OpenRA.Primitives; @@ -69,7 +68,7 @@ namespace OpenRA LobbyDefaults = yaml["LobbyDefaults"]; Fonts = yaml["Fonts"].NodesDict.ToDictionary(x => x.Key, x => Pair.New(x.Value.NodesDict["Font"].Value, - int.Parse(x.Value.NodesDict["Size"].Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo))); + Exts.ParseIntegerInvariant(x.Value.NodesDict["Size"].Value))); if (yaml.ContainsKey("TileSize")) TileSize = FieldLoader.GetValue("TileSize", yaml["TileSize"].Value); diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index 96fee98d73..392b4e03f7 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2014 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, @@ -11,7 +11,6 @@ using System; using System.Collections.Generic; using System.Drawing; -using System.Globalization; using System.IO; using System.Linq; using System.Security.Cryptography; @@ -203,9 +202,9 @@ namespace OpenRA var vals = kv.Key.Split(' '); var loc = vals[1].Split(','); ret.Add(new SmudgeReference(vals[0], new int2( - int.Parse(loc[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo), - int.Parse(loc[1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo)), - int.Parse(vals[2], NumberStyles.Integer, NumberFormatInfo.InvariantInfo))); + Exts.ParseIntegerInvariant(loc[0]), + Exts.ParseIntegerInvariant(loc[1])), + Exts.ParseIntegerInvariant(vals[2]))); } return ret; diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index c016dcef14..a07fc1361c 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2012 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2014 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, @@ -11,7 +11,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Globalization; using System.IO; using System.Linq; using System.Net; @@ -467,7 +466,7 @@ namespace OpenRA.Server case "Pong": { int pingSent; - if (!int.TryParse(so.Data, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out pingSent)) + if (!OpenRA.Exts.TryParseIntegerInvariant(so.Data, out pingSent)) { Log.Write("server", "Invalid order pong payload: {0}", so.Data); break; diff --git a/OpenRA.Game/Support/Evaluator.cs b/OpenRA.Game/Support/Evaluator.cs index d807213e88..da5e90cf0d 100644 --- a/OpenRA.Game/Support/Evaluator.cs +++ b/OpenRA.Game/Support/Evaluator.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2014 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, @@ -10,7 +10,6 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.Linq; namespace OpenRA.Support @@ -37,7 +36,7 @@ namespace OpenRA.Support case '-': ApplyBinop(s, (x, y) => y - x); break; case '*': ApplyBinop(s, (x, y) => y * x); break; case '/': ApplyBinop(s, (x, y) => y / x); break; - default: s.Push(int.Parse(t, NumberStyles.Integer, NumberFormatInfo.InvariantInfo)); break; + default: s.Push(Exts.ParseIntegerInvariant(t)); break; } } diff --git a/OpenRA.Game/WRange.cs b/OpenRA.Game/WRange.cs index c1e22c8ed5..c28183bbd7 100644 --- a/OpenRA.Game/WRange.cs +++ b/OpenRA.Game/WRange.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2013 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2014 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, @@ -9,7 +9,6 @@ #endregion using System; -using System.Globalization; using System.Linq; namespace OpenRA @@ -57,12 +56,12 @@ namespace OpenRA switch (components.Length) { case 2: - if (!int.TryParse(components[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out cell) || - !int.TryParse(components[1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out subcell)) + if (!Exts.TryParseIntegerInvariant(components[0], out cell) || + !Exts.TryParseIntegerInvariant(components[1], out subcell)) return false; break; case 1: - if (!int.TryParse(components[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out subcell)) + if (!Exts.TryParseIntegerInvariant(components[0], out subcell)) return false; break; default: return false; diff --git a/OpenRA.Irc/IrcClient.cs b/OpenRA.Irc/IrcClient.cs index 8f60cafc52..c2f06cfbc6 100644 --- a/OpenRA.Irc/IrcClient.cs +++ b/OpenRA.Irc/IrcClient.cs @@ -9,7 +9,6 @@ #endregion using System; -using System.Globalization; using System.IO; using System.Linq; using System.Net.Sockets; @@ -281,7 +280,7 @@ namespace OpenRA.Irc OnLineRead(l); int numeric; - if (int.TryParse(l.Command, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out numeric)) + if (Exts.TryParseIntegerInvariant(l.Command, out numeric)) { var nl = new NumericLine(l, numeric); LocalUser.OnNumeric(nl); diff --git a/OpenRA.Irc/IrcClientUser.cs b/OpenRA.Irc/IrcClientUser.cs index 68e97f1300..33be998592 100644 --- a/OpenRA.Irc/IrcClientUser.cs +++ b/OpenRA.Irc/IrcClientUser.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2013 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2014 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, @@ -9,7 +9,6 @@ #endregion using System; -using System.Globalization; using System.Linq; using OpenRA.Primitives; @@ -48,7 +47,7 @@ namespace OpenRA.Irc { var topic = line.GetChannel().Topic; topic.Author = new User(line[4]); - topic.Time = IrcUtils.DateTimeFromUnixTime(int.Parse(line[5], NumberStyles.Integer, NumberFormatInfo.InvariantInfo)); + topic.Time = IrcUtils.DateTimeFromUnixTime(Exts.ParseIntegerInvariant(line[5])); } break; case NumericCommand.ERR_NICKNAMEINUSE: diff --git a/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs b/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs index 6236aaa52a..bd1721f8e6 100644 --- a/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs +++ b/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2014 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, @@ -10,7 +10,6 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.Linq; using OpenRA.Graphics; using OpenRA.Network; @@ -226,7 +225,7 @@ namespace OpenRA.Mods.RA.Server var slot = server.LobbyInfo.Slots[parts[0]]; var bot = server.LobbyInfo.ClientInSlot(parts[0]); int controllerClientIndex; - if (!int.TryParse(parts[1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out controllerClientIndex)) + if (!Exts.TryParseIntegerInvariant(parts[1], out controllerClientIndex)) { Log.Write("server", "Invalid bot controller client index: {0}", parts[1]); return false; @@ -414,7 +413,7 @@ namespace OpenRA.Mods.RA.Server } int teamCount; - if (!int.TryParse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out teamCount)) + if (!Exts.TryParseIntegerInvariant(s, out teamCount)) { server.SendOrderTo(conn, "Message", "Number of teams could not be parsed: {0}".F(s)); return true; @@ -537,7 +536,7 @@ namespace OpenRA.Mods.RA.Server return true; } - server.LobbyInfo.GlobalSettings.StartingCash = int.Parse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo); + server.LobbyInfo.GlobalSettings.StartingCash = Exts.ParseIntegerInvariant(s); server.SyncLobbyInfo(); return true; }}, @@ -558,7 +557,7 @@ namespace OpenRA.Mods.RA.Server } int kickClientID; - int.TryParse(split[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out kickClientID); + Exts.TryParseIntegerInvariant(split[0], out kickClientID); var kickConn = server.Conns.SingleOrDefault(c => server.GetClient(c) != null && server.GetClient(c).Index == kickClientID); if (kickConn == null) @@ -597,7 +596,7 @@ namespace OpenRA.Mods.RA.Server s => { var parts = s.Split(' '); - var targetClient = server.LobbyInfo.ClientWithIndex(int.Parse(parts[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo)); + var targetClient = server.LobbyInfo.ClientWithIndex(Exts.ParseIntegerInvariant(parts[0])); // Only the host can change other client's info if (targetClient.Index != client.Index && !client.IsAdmin) @@ -615,7 +614,7 @@ namespace OpenRA.Mods.RA.Server s => { var parts = s.Split(' '); - var targetClient = server.LobbyInfo.ClientWithIndex(int.Parse(parts[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo)); + var targetClient = server.LobbyInfo.ClientWithIndex(Exts.ParseIntegerInvariant(parts[0])); // Only the host can change other client's info if (targetClient.Index != client.Index && !client.IsAdmin) @@ -626,7 +625,7 @@ namespace OpenRA.Mods.RA.Server return true; int team; - if (!int.TryParse(parts[1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out team)) + if (!Exts.TryParseIntegerInvariant(parts[1], out team)) { Log.Write("server", "Invalid team: {0}", s ); return false; @@ -640,7 +639,7 @@ namespace OpenRA.Mods.RA.Server s => { var parts = s.Split(' '); - var targetClient = server.LobbyInfo.ClientWithIndex(int.Parse(parts[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo)); + var targetClient = server.LobbyInfo.ClientWithIndex(Exts.ParseIntegerInvariant(parts[0])); // Only the host can change other client's info if (targetClient.Index != client.Index && !client.IsAdmin) @@ -655,14 +654,14 @@ namespace OpenRA.Mods.RA.Server return true; int spawnPoint; - if (!int.TryParse(parts[1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out spawnPoint) + if (!Exts.TryParseIntegerInvariant(parts[1], out spawnPoint) || spawnPoint < 0 || spawnPoint > server.Map.GetSpawnPoints().Length) { Log.Write("server", "Invalid spawn point: {0}", parts[1]); return true; } - if (server.LobbyInfo.Clients.Where( cc => cc != client ).Any( cc => (cc.SpawnPoint == spawnPoint) && (cc.SpawnPoint != 0) )) + if (server.LobbyInfo.Clients.Where(cc => cc != client).Any(cc => (cc.SpawnPoint == spawnPoint) && (cc.SpawnPoint != 0))) { server.SendOrderTo(conn, "Message", "You can't be at the same spawn point as another player"); return true; @@ -676,7 +675,7 @@ namespace OpenRA.Mods.RA.Server s => { var parts = s.Split(' '); - var targetClient = server.LobbyInfo.ClientWithIndex(int.Parse(parts[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo)); + var targetClient = server.LobbyInfo.ClientWithIndex(Exts.ParseIntegerInvariant(parts[0])); // Only the host can change other client's info if (targetClient.Index != client.Index && !client.IsAdmin) @@ -686,7 +685,7 @@ namespace OpenRA.Mods.RA.Server if (targetClient.Slot == null || server.LobbyInfo.Slots[targetClient.Slot].LockColor) return true; - var ci = parts[1].Split(',').Select(cc => int.Parse(cc, NumberStyles.Integer, NumberFormatInfo.InvariantInfo)).ToArray(); + var ci = parts[1].Split(',').Select(cc => Exts.ParseIntegerInvariant(cc)).ToArray(); targetClient.Color = targetClient.PreferredColor = new HSLColor((byte)ci[0], (byte)ci[1], (byte)ci[2]); server.SyncLobbyInfo(); return true; diff --git a/OpenRA.Mods.RA/Widgets/Logic/DirectConnectLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/DirectConnectLogic.cs index 7758134caa..e060b7e369 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/DirectConnectLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/DirectConnectLogic.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2014 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, @@ -9,7 +9,6 @@ #endregion using System; -using System.Globalization; using OpenRA.Widgets; namespace OpenRA.Mods.RA.Widgets.Logic @@ -29,7 +28,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic panel.Get("JOIN_BUTTON").OnClick = () => { - var port = Exts.WithDefault(1234, () => int.Parse(portField.Text, NumberStyles.Integer, NumberFormatInfo.InvariantInfo)); + var port = Exts.WithDefault(1234, () => Exts.ParseIntegerInvariant(portField.Text)); Game.Settings.Player.LastServer = "{0}:{1}".F(ipField.Text, port); Game.Settings.Save(); diff --git a/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs index 89ae287e77..1581b3d050 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs @@ -10,7 +10,6 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.Linq; using System.Drawing; using System.Net; @@ -285,7 +284,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic return; var host = server.Address.Split(':')[0]; - var port = int.Parse(server.Address.Split(':')[1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo); + var port = Exts.ParseIntegerInvariant(server.Address.Split(':')[1]); ConnectionLogic.Connect(host, port, "", OpenLobby, DoNothing); } diff --git a/OpenRA.Mods.RA/Widgets/Logic/ServerCreationLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/ServerCreationLogic.cs index 51927c5d8f..6d07aa304f 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/ServerCreationLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/ServerCreationLogic.cs @@ -9,7 +9,6 @@ #endregion using System; -using System.Globalization; using System.Net; using OpenRA.GameRules; using OpenRA.Widgets; @@ -82,10 +81,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic { var name = panel.Get("SERVER_NAME").Text; int listenPort, externalPort; - if (!int.TryParse(panel.Get("LISTEN_PORT").Text, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out listenPort)) + if (!Exts.TryParseIntegerInvariant(panel.Get("LISTEN_PORT").Text, out listenPort)) listenPort = 1234; - if (!int.TryParse(panel.Get("EXTERNAL_PORT").Text, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out externalPort)) + if (!Exts.TryParseIntegerInvariant(panel.Get("EXTERNAL_PORT").Text, out externalPort)) externalPort = 1234; var passwordField = panel.GetOrNull("PASSWORD"); diff --git a/OpenRA.Mods.RA/Widgets/Logic/SettingsLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/SettingsLogic.cs index f92b91caa7..3f0ba1076c 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/SettingsLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/SettingsLogic.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2013 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2014 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, @@ -11,7 +11,6 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.Linq; using OpenRA.GameRules; using OpenRA.Graphics; @@ -152,7 +151,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic frameLimitTextfield.OnLoseFocus = () => { int fps; - int.TryParse(frameLimitTextfield.Text, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out fps); + Exts.TryParseIntegerInvariant(frameLimitTextfield.Text, out fps); ds.MaxFramerate = fps.Clamp(20, 200); frameLimitTextfield.Text = ds.MaxFramerate.ToString(); Game.SetIdealFrameTime(ds.MaxFramerate); @@ -163,8 +162,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic return () => { int x, y; - int.TryParse(windowWidth.Text, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out x); - int.TryParse(windowHeight.Text, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out y); + Exts.TryParseIntegerInvariant(windowWidth.Text, out x); + Exts.TryParseIntegerInvariant(windowHeight.Text, out y); ds.WindowedSize = new int2(x, y); frameLimitTextfield.YieldKeyboardFocus(); }; diff --git a/OpenRA.Utility/Command.cs b/OpenRA.Utility/Command.cs index 753b3d3cd9..e3d0aa52c1 100644 --- a/OpenRA.Utility/Command.cs +++ b/OpenRA.Utility/Command.cs @@ -13,7 +13,6 @@ using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using System.IO; -using System.Globalization; using System.Linq; using System.Reflection; using System.Runtime.InteropServices; @@ -236,9 +235,9 @@ namespace OpenRA.Utility for (var z = 3; z < args.Length - 2; z += 3) { - var start = int.Parse(args[z], NumberStyles.Integer, NumberFormatInfo.InvariantInfo); - var m = int.Parse(args[z + 1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo); - var n = int.Parse(args[z + 2], NumberStyles.Integer, NumberFormatInfo.InvariantInfo); + var start = Exts.ParseIntegerInvariant(args[z]); + var m = Exts.ParseIntegerInvariant(args[z + 1]); + var n = Exts.ParseIntegerInvariant(args[z + 2]); for (var i = 0; i < m; i++) for (var j = 0; j < n; j++) diff --git a/OpenRA.Utility/LegacyMapImporter.cs b/OpenRA.Utility/LegacyMapImporter.cs index 40b38545b3..ca6e08bf41 100644 --- a/OpenRA.Utility/LegacyMapImporter.cs +++ b/OpenRA.Utility/LegacyMapImporter.cs @@ -129,11 +129,11 @@ namespace OpenRA.Utility var file = new IniFile(GlobalFileSystem.Open(iniFile)); var basic = file.GetSection("Basic"); var mapSection = file.GetSection("Map"); - var legacyMapFormat = (IniMapFormat)int.Parse(basic.GetValue("NewINIFormat", "0"), NumberStyles.Integer, NumberFormatInfo.InvariantInfo); - var offsetX = int.Parse(mapSection.GetValue("X", "0"), NumberStyles.Integer, NumberFormatInfo.InvariantInfo); - var offsetY = int.Parse(mapSection.GetValue("Y", "0"), NumberStyles.Integer, NumberFormatInfo.InvariantInfo); - var width = int.Parse(mapSection.GetValue("Width", "0"), NumberStyles.Integer, NumberFormatInfo.InvariantInfo); - var height = int.Parse(mapSection.GetValue("Height", "0"), NumberStyles.Integer, NumberFormatInfo.InvariantInfo); + var legacyMapFormat = (IniMapFormat)Exts.ParseIntegerInvariant(basic.GetValue("NewINIFormat", "0")); + var offsetX = Exts.ParseIntegerInvariant(mapSection.GetValue("X", "0")); + var offsetY = Exts.ParseIntegerInvariant(mapSection.GetValue("Y", "0")); + var width = Exts.ParseIntegerInvariant(mapSection.GetValue("Width", "0")); + var height = Exts.ParseIntegerInvariant(mapSection.GetValue("Height", "0")); mapSize = (legacyMapFormat == IniMapFormat.RedAlert) ? 128 : 64; map.Title = basic.GetValue("Name", Path.GetFileNameWithoutExtension(iniFile)); @@ -174,9 +174,9 @@ namespace OpenRA.Utility LoadPlayer(file, p, legacyMapFormat == IniMapFormat.RedAlert); var wps = file.GetSection("Waypoints") - .Where(kv => int.Parse(kv.Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo) > 0) - .Select(kv => Pair.New(int.Parse(kv.Key, NumberStyles.Integer, NumberFormatInfo.InvariantInfo), - LocationFromMapOffset(int.Parse(kv.Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo), mapSize))) + .Where(kv => Exts.ParseIntegerInvariant(kv.Value) > 0) + .Select(kv => Pair.New(Exts.ParseIntegerInvariant(kv.Key), + LocationFromMapOffset(Exts.ParseIntegerInvariant(kv.Value), mapSize))) .ToArray(); // Add waypoint actors @@ -298,7 +298,7 @@ namespace OpenRA.Utility foreach (KeyValuePair kv in terrain) { - var loc = int.Parse(kv.Key, NumberStyles.Integer, NumberFormatInfo.InvariantInfo); + var loc = Exts.ParseIntegerInvariant(kv.Key); map.Actors.Value.Add("Actor" + actorCount++, new ActorReference(kv.Value.ToLowerInvariant()) { @@ -332,7 +332,7 @@ namespace OpenRA.Utility foreach (KeyValuePair kv in overlay) { - var loc = int.Parse(kv.Key, NumberStyles.Integer, NumberFormatInfo.InvariantInfo); + var loc = Exts.ParseIntegerInvariant(kv.Key); var cell = new CPos(loc % mapSize, loc / mapSize); var res = Pair.New((byte)0, (byte)0); @@ -359,7 +359,7 @@ namespace OpenRA.Utility foreach (KeyValuePair kv in terrain) { - var loc = int.Parse(kv.Key, NumberStyles.Integer, NumberFormatInfo.InvariantInfo); + var loc = Exts.ParseIntegerInvariant(kv.Key); map.Actors.Value.Add("Actor" + actorCount++, new ActorReference(kv.Value.Split(',')[0].ToLowerInvariant()) { @@ -379,7 +379,7 @@ namespace OpenRA.Utility try { var parts = s.Value.Split(','); - var loc = int.Parse(parts[3]); + var loc = Exts.ParseIntegerInvariant(parts[3]); if (parts[0] == "") parts[0] = "Neutral"; @@ -392,12 +392,12 @@ namespace OpenRA.Utility new OwnerInit(parts[0]), new HealthInit(float.Parse(parts[2], NumberFormatInfo.InvariantInfo) / 256), new FacingInit((section == "INFANTRY") - ? int.Parse(parts[6], NumberStyles.Integer, NumberFormatInfo.InvariantInfo) - : int.Parse(parts[4], NumberStyles.Integer, NumberFormatInfo.InvariantInfo)), + ? Exts.ParseIntegerInvariant(parts[6]) + : Exts.ParseIntegerInvariant(parts[4])), }; if (section == "INFANTRY") - actor.Add(new SubCellInit(int.Parse(parts[4], NumberStyles.Integer, NumberFormatInfo.InvariantInfo))); + actor.Add(new SubCellInit(Exts.ParseIntegerInvariant(parts[4]))); if (!Rules.Info.ContainsKey(parts[1].ToLowerInvariant())) errorHandler("Ignoring unknown actor type: `{0}`".F(parts[1].ToLowerInvariant())); @@ -417,8 +417,8 @@ namespace OpenRA.Utility { // loc=type,loc,depth var parts = s.Value.Split(','); - var loc = int.Parse(parts[1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo); - map.Smudges.Value.Add(new SmudgeReference(parts[0].ToLowerInvariant(), new int2(loc % mapSize, loc / mapSize), int.Parse(parts[2], NumberStyles.Integer, NumberFormatInfo.InvariantInfo))); + var loc = Exts.ParseIntegerInvariant(parts[1]); + map.Smudges.Value.Add(new SmudgeReference(parts[0].ToLowerInvariant(), new int2(loc % mapSize, loc / mapSize), Exts.ParseIntegerInvariant(parts[2]))); } } diff --git a/OpenRA.Utility/UpgradeRules.cs b/OpenRA.Utility/UpgradeRules.cs index 2ae8900a13..992ace75e3 100644 --- a/OpenRA.Utility/UpgradeRules.cs +++ b/OpenRA.Utility/UpgradeRules.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2013 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2014 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, @@ -13,7 +13,6 @@ using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using System.IO; -using System.Globalization; using System.Linq; using System.Reflection; using System.Runtime.InteropServices; @@ -43,7 +42,7 @@ namespace OpenRA.Utility static void ConvertPxToRange(ref string input, int scaleMult, int scaleDiv) { - var value = int.Parse(input, NumberStyles.Integer, NumberFormatInfo.InvariantInfo); + var value = Exts.ParseIntegerInvariant(input); var ts = Game.modData.Manifest.TileSize; var world = value * 1024 * scaleMult / (scaleDiv * ts.Height); var cells = world / 1024; @@ -338,7 +337,7 @@ namespace OpenRA.Utility public static void UpgradeMap(string[] args) { var map = new Map(args[1]); - var engineDate = int.Parse(args[2], NumberStyles.Integer, NumberFormatInfo.InvariantInfo); + var engineDate = Exts.ParseIntegerInvariant(args[2]); Game.modData = new ModData(map.RequiresMod); UpgradeWeaponRules(engineDate, ref map.Weapons, null, 0); @@ -350,7 +349,7 @@ namespace OpenRA.Utility public static void UpgradeMod(string[] args) { var mod = args[1]; - var engineDate = int.Parse(args[2], NumberStyles.Integer, NumberFormatInfo.InvariantInfo); + var engineDate = Exts.ParseIntegerInvariant(args[2]); Game.modData = new ModData(mod); Game.modData.MapCache.LoadMaps();