parse with NumberFormatInfo.InvariantInfo everywhere

closes #5240
This commit is contained in:
Matthias Mailänder
2014-05-05 17:28:09 +02:00
parent bf9d3a8082
commit b19d286f56
20 changed files with 132 additions and 86 deletions

View File

@@ -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,
@@ -116,7 +116,7 @@ namespace OpenRA
if (fieldType == typeof(int))
{
int res;
if (int.TryParse(value, out res))
if (int.TryParse(value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out res))
return res;
return InvalidValueAction(value, fieldType, fieldName);
}
@@ -124,7 +124,7 @@ namespace OpenRA
else if (fieldType == typeof(ushort))
{
ushort res;
if (ushort.TryParse(value, out res))
if (ushort.TryParse(value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out res))
return res;
return InvalidValueAction(value, fieldType, fieldName);
}
@@ -132,7 +132,7 @@ namespace OpenRA
if (fieldType == typeof(long))
{
long res;
if (long.TryParse(value, out res))
if (long.TryParse(value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out res))
return res;
return InvalidValueAction(value, fieldType, fieldName);
}
@@ -140,7 +140,7 @@ namespace OpenRA
else if (fieldType == typeof(float))
{
float res;
if (float.TryParse(value.Replace("%", ""), NumberStyles.Any, NumberFormatInfo.InvariantInfo, out res))
if (float.TryParse(value.Replace("%", ""), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out res))
return res * (value.Contains('%') ? 0.01f : 1f);
return InvalidValueAction(value, fieldType, fieldName);
}
@@ -148,7 +148,7 @@ namespace OpenRA
else if (fieldType == typeof(decimal))
{
decimal res;
if (decimal.TryParse(value.Replace("%", ""), NumberStyles.Any, NumberFormatInfo.InvariantInfo, out res))
if (decimal.TryParse(value.Replace("%", ""), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out res))
return res * (value.Contains('%') ? 0.01m : 1m);
return InvalidValueAction(value, fieldType, fieldName);
}
@@ -164,9 +164,16 @@ namespace OpenRA
{
var parts = value.Split(',');
if (parts.Length == 3)
return Color.FromArgb(int.Parse(parts[0]).Clamp(0, 255), int.Parse(parts[1]).Clamp(0, 255), int.Parse(parts[2]).Clamp(0, 255));
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));
if (parts.Length == 4)
return Color.FromArgb(int.Parse(parts[0]).Clamp(0, 255), int.Parse(parts[1]).Clamp(0, 255), int.Parse(parts[2]).Clamp(0, 255), int.Parse(parts[3]).Clamp(0, 255));
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));
return InvalidValueAction(value, fieldType, fieldName);
}
@@ -177,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]).Clamp(0, 255),
(byte)int.Parse(parts[1]).Clamp(0, 255),
(byte)int.Parse(parts[2]).Clamp(0, 255));
(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));
return InvalidValueAction(value, fieldType, fieldName);
}
@@ -231,7 +238,7 @@ namespace OpenRA
else if (fieldType == typeof(WAngle))
{
int res;
if (int.TryParse(value, out res))
if (int.TryParse(value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out res))
return new WAngle(res);
return InvalidValueAction(value, fieldType, fieldName);
}
@@ -242,8 +249,10 @@ namespace OpenRA
if (parts.Length == 3)
{
int rr, rp, ry;
if (int.TryParse(value, out rr) && int.TryParse(value, out rp) && int.TryParse(value, out ry))
return new WRot(new WAngle(rr), new WAngle(rp), new WAngle(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))
return new WRot(new WAngle(rr), new WAngle(rp), new WAngle(ry));
}
return InvalidValueAction(value, fieldType, fieldName);
@@ -252,13 +261,17 @@ namespace OpenRA
else if (fieldType == typeof(CPos))
{
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
return new CPos(int.Parse(parts[0]), int.Parse(parts[1]));
return new CPos(
int.Parse(parts[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo),
int.Parse(parts[1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo));
}
else if (fieldType == typeof(CVec))
{
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
return new CVec(int.Parse(parts[0]), int.Parse(parts[1]));
return new CVec(
int.Parse(parts[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo),
int.Parse(parts[1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo));
}
else if (fieldType.IsEnum)
@@ -292,13 +305,17 @@ namespace OpenRA
else if (fieldType == typeof(Size))
{
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
return new Size(int.Parse(parts[0]), int.Parse(parts[1]));
return new Size(
int.Parse(parts[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo),
int.Parse(parts[1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo));
}
else if (fieldType == typeof(int2))
{
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
return new int2(int.Parse(parts[0]), int.Parse(parts[1]));
return new int2(
int.Parse(parts[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo),
int.Parse(parts[1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo));
}
else if (fieldType == typeof(float2))
@@ -307,9 +324,9 @@ namespace OpenRA
float xx = 0;
float yy = 0;
float res;
if (float.TryParse(parts[0].Replace("%", ""), out res))
if (float.TryParse(parts[0].Replace("%", ""), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out res))
xx = res * (parts[0].Contains('%') ? 0.01f : 1f);
if (float.TryParse(parts[1].Replace("%", ""), out res))
if (float.TryParse(parts[1].Replace("%", ""), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out res))
yy = res * (parts[1].Contains('%') ? 0.01f : 1f);
return new float2(xx, yy);
}
@@ -317,7 +334,11 @@ namespace OpenRA
else if (fieldType == typeof(Rectangle))
{
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
return new Rectangle(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), int.Parse(parts[3]));
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));
}
else if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(Bits<>))

View File

@@ -9,6 +9,7 @@
#endregion
using System;
using System.Globalization;
using System.Collections.Generic;
using System.Linq;
using OpenRA.FileSystem;
@@ -41,7 +42,8 @@ namespace OpenRA.Graphics
if (sequences.NodesDict.ContainsKey("ShadowIndex"))
{
Array.Resize(ref shadowIndex, shadowIndex.Length + 1);
int.TryParse(sequences.NodesDict["ShadowIndex"].Value, out shadowIndex[shadowIndex.Length - 1]);
int.TryParse(sequences.NodesDict["ShadowIndex"].Value, NumberStyles.Any, NumberFormatInfo.InvariantInfo,
out shadowIndex[shadowIndex.Length - 1]);
}
palette = new HardwarePalette();

View File

@@ -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,
@@ -8,6 +8,7 @@
*/
#endregion
using System.Globalization;
using OpenRA.FileFormats;
namespace OpenRA.Graphics
@@ -30,22 +31,22 @@ namespace OpenRA.Graphics
sprites = Game.modData.SpriteLoader.LoadAllSprites(cursorSrc);
var d = info.NodesDict;
start = int.Parse(d["start"].Value);
start = int.Parse(d["start"].Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo);
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);
length = int.Parse(d["length"].Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo);
else if (d.ContainsKey("end"))
length = int.Parse(d["end"].Value) - start;
length = int.Parse(d["end"].Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo) - start;
else
length = 1;
if (d.ContainsKey("x"))
int.TryParse(d["x"].Value, out Hotspot.X);
int.TryParse(d["x"].Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out Hotspot.X);
if (d.ContainsKey("y"))
int.TryParse(d["y"].Value, out Hotspot.Y);
int.TryParse(d["y"].Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out Hotspot.Y);
}
public Sprite GetSprite(int frame)

View File

@@ -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,6 +9,7 @@
#endregion
using System;
using System.Globalization;
using System.Linq;
namespace OpenRA.Graphics
@@ -40,7 +41,7 @@ namespace OpenRA.Graphics
try
{
if (d.ContainsKey("Start"))
Start = int.Parse(d["Start"].Value);
Start = int.Parse(d["Start"].Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo);
if (d.ContainsKey("Offset"))
offset = FieldLoader.GetValue<float2>("Offset", d["Offset"].Value);
@@ -58,16 +59,16 @@ namespace OpenRA.Graphics
else if (d["Length"].Value == "*")
Length = sprites.Length - Start;
else
Length = int.Parse(d["Length"].Value);
Length = int.Parse(d["Length"].Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo);
if (d.ContainsKey("Stride"))
Stride = int.Parse(d["Stride"].Value);
Stride = int.Parse(d["Stride"].Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo);
else
Stride = Length;
if (d.ContainsKey("Facings"))
{
var f = int.Parse(d["Facings"].Value);
var f = int.Parse(d["Facings"].Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo);
Facings = Math.Abs(f);
reverseFacings = f < 0;
}
@@ -75,7 +76,7 @@ namespace OpenRA.Graphics
Facings = 1;
if (d.ContainsKey("Tick"))
Tick = int.Parse(d["Tick"].Value);
Tick = int.Parse(d["Tick"].Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo);
else
Tick = 40;
@@ -83,10 +84,10 @@ namespace OpenRA.Graphics
transpose = bool.Parse(d["Transpose"].Value);
if (d.ContainsKey("Frames"))
Frames = Array.ConvertAll<string, int>(d["Frames"].Value.Split(','), int.Parse);
Frames = Array.ConvertAll<string, int>(d["Frames"].Value.Split(','), (s) => int.Parse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo));
if (d.ContainsKey("ShadowStart"))
ShadowStart = int.Parse(d["ShadowStart"].Value);
ShadowStart = int.Parse(d["ShadowStart"].Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo);
else
ShadowStart = -1;

View File

@@ -10,6 +10,7 @@
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using OpenRA.Primitives;
@@ -68,7 +69,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)));
int.Parse(x.Value.NodesDict["Size"].Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo)));
if (yaml.ContainsKey("TileSize"))
TileSize = FieldLoader.GetValue<Size>("TileSize", yaml["TileSize"].Value);

View File

@@ -11,6 +11,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
@@ -201,7 +202,10 @@ namespace OpenRA
{
var vals = kv.Key.Split(' ');
var loc = vals[1].Split(',');
ret.Add(new SmudgeReference(vals[0], new int2(int.Parse(loc[0]), int.Parse(loc[1])), int.Parse(vals[2])));
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)));
}
return ret;

View File

@@ -11,6 +11,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
@@ -466,7 +467,7 @@ namespace OpenRA.Server
case "Pong":
{
int pingSent;
if (!int.TryParse(so.Data, out pingSent))
if (!int.TryParse(so.Data, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out pingSent))
{
Log.Write("server", "Invalid order pong payload: {0}", so.Data);
break;

View File

@@ -10,6 +10,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
namespace OpenRA.Support
@@ -36,7 +37,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)); break;
default: s.Push(int.Parse(t, NumberStyles.Integer, NumberFormatInfo.InvariantInfo)); break;
}
}

View File

@@ -9,6 +9,7 @@
#endregion
using System;
using System.Globalization;
using System.Linq;
namespace OpenRA
@@ -56,12 +57,12 @@ namespace OpenRA
switch (components.Length)
{
case 2:
if (!int.TryParse(components[0], out cell) ||
!int.TryParse(components[1], out subcell))
return false;
if (!int.TryParse(components[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out cell) ||
!int.TryParse(components[1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out subcell))
return false;
break;
case 1:
if (!int.TryParse(components[0], out subcell))
if (!int.TryParse(components[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out subcell))
return false;
break;
default: return false;

View File

@@ -9,6 +9,7 @@
#endregion
using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net.Sockets;
@@ -280,7 +281,7 @@ namespace OpenRA.Irc
OnLineRead(l);
int numeric;
if (int.TryParse(l.Command, out numeric))
if (int.TryParse(l.Command, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out numeric))
{
var nl = new NumericLine(l, numeric);
LocalUser.OnNumeric(nl);

View File

@@ -9,6 +9,7 @@
#endregion
using System;
using System.Globalization;
using System.Linq;
using OpenRA.Primitives;
@@ -47,7 +48,7 @@ namespace OpenRA.Irc
{
var topic = line.GetChannel().Topic;
topic.Author = new User(line[4]);
topic.Time = IrcUtils.DateTimeFromUnixTime(int.Parse(line[5]));
topic.Time = IrcUtils.DateTimeFromUnixTime(int.Parse(line[5], NumberStyles.Integer, NumberFormatInfo.InvariantInfo));
}
break;
case NumericCommand.ERR_NICKNAMEINUSE:

View File

@@ -9,6 +9,7 @@
#endregion
using System.Linq;
using System.Globalization;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
@@ -23,7 +24,7 @@ namespace OpenRA.Mods.RA
{
/* create a group */
var actors = order.TargetString.Split(',')
.Select(id => uint.Parse(id))
.Select(id => uint.Parse(id, NumberStyles.Any, NumberFormatInfo.InvariantInfo))
.Select(id => self.World.Actors.FirstOrDefault(a => a.ActorID == id))
.Where(a => a != null);

View File

@@ -10,6 +10,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Network;
@@ -225,7 +226,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], out controllerClientIndex))
if (!int.TryParse(parts[1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out controllerClientIndex))
{
Log.Write("server", "Invalid bot controller client index: {0}", parts[1]);
return false;
@@ -413,7 +414,7 @@ namespace OpenRA.Mods.RA.Server
}
int teamCount;
if (!int.TryParse(s, out teamCount))
if (!int.TryParse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out teamCount))
{
server.SendOrderTo(conn, "Message", "Number of teams could not be parsed: {0}".F(s));
return true;
@@ -536,7 +537,7 @@ namespace OpenRA.Mods.RA.Server
return true;
}
server.LobbyInfo.GlobalSettings.StartingCash = int.Parse(s);
server.LobbyInfo.GlobalSettings.StartingCash = int.Parse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo);
server.SyncLobbyInfo();
return true;
}},
@@ -557,7 +558,7 @@ namespace OpenRA.Mods.RA.Server
}
int kickClientID;
int.TryParse(split[0], out kickClientID);
int.TryParse(split[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out kickClientID);
var kickConn = server.Conns.SingleOrDefault(c => server.GetClient(c) != null && server.GetClient(c).Index == kickClientID);
if (kickConn == null)
@@ -596,7 +597,7 @@ namespace OpenRA.Mods.RA.Server
s =>
{
var parts = s.Split(' ');
var targetClient = server.LobbyInfo.ClientWithIndex(int.Parse(parts[0]));
var targetClient = server.LobbyInfo.ClientWithIndex(int.Parse(parts[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo));
// Only the host can change other client's info
if (targetClient.Index != client.Index && !client.IsAdmin)
@@ -614,7 +615,7 @@ namespace OpenRA.Mods.RA.Server
s =>
{
var parts = s.Split(' ');
var targetClient = server.LobbyInfo.ClientWithIndex(int.Parse(parts[0]));
var targetClient = server.LobbyInfo.ClientWithIndex(int.Parse(parts[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo));
// Only the host can change other client's info
if (targetClient.Index != client.Index && !client.IsAdmin)
@@ -625,7 +626,7 @@ namespace OpenRA.Mods.RA.Server
return true;
int team;
if (!int.TryParse(parts[1], out team))
if (!int.TryParse(parts[1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out team))
{
Log.Write("server", "Invalid team: {0}", s );
return false;
@@ -639,7 +640,7 @@ namespace OpenRA.Mods.RA.Server
s =>
{
var parts = s.Split(' ');
var targetClient = server.LobbyInfo.ClientWithIndex(int.Parse(parts[0]));
var targetClient = server.LobbyInfo.ClientWithIndex(int.Parse(parts[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo));
// Only the host can change other client's info
if (targetClient.Index != client.Index && !client.IsAdmin)
@@ -654,7 +655,8 @@ namespace OpenRA.Mods.RA.Server
return true;
int spawnPoint;
if (!int.TryParse(parts[1], out spawnPoint) || spawnPoint < 0 || spawnPoint > server.Map.GetSpawnPoints().Length)
if (!int.TryParse(parts[1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out spawnPoint)
|| spawnPoint < 0 || spawnPoint > server.Map.GetSpawnPoints().Length)
{
Log.Write("server", "Invalid spawn point: {0}", parts[1]);
return true;
@@ -674,7 +676,7 @@ namespace OpenRA.Mods.RA.Server
s =>
{
var parts = s.Split(' ');
var targetClient = server.LobbyInfo.ClientWithIndex(int.Parse(parts[0]));
var targetClient = server.LobbyInfo.ClientWithIndex(int.Parse(parts[0], NumberStyles.Integer, NumberFormatInfo.InvariantInfo));
// Only the host can change other client's info
if (targetClient.Index != client.Index && !client.IsAdmin)
@@ -684,7 +686,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)).ToArray();
var ci = parts[1].Split(',').Select(cc => int.Parse(cc, NumberStyles.Integer, NumberFormatInfo.InvariantInfo)).ToArray();
targetClient.Color = targetClient.PreferredColor = new HSLColor((byte)ci[0], (byte)ci[1], (byte)ci[2]);
server.SyncLobbyInfo();
return true;

View File

@@ -9,6 +9,7 @@
#endregion
using System;
using System.Globalization;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Logic
@@ -28,7 +29,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
panel.Get<ButtonWidget>("JOIN_BUTTON").OnClick = () =>
{
var port = Exts.WithDefault(1234, () => int.Parse(portField.Text));
var port = Exts.WithDefault(1234, () => int.Parse(portField.Text, NumberStyles.Integer, NumberFormatInfo.InvariantInfo));
Game.Settings.Player.LastServer = "{0}:{1}".F(ipField.Text, port);
Game.Settings.Save();

View File

@@ -10,6 +10,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Drawing;
using System.Net;
@@ -284,7 +285,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
return;
var host = server.Address.Split(':')[0];
var port = int.Parse(server.Address.Split(':')[1]);
var port = int.Parse(server.Address.Split(':')[1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo);
ConnectionLogic.Connect(host, port, "", OpenLobby, DoNothing);
}

View File

@@ -9,6 +9,7 @@
#endregion
using System;
using System.Globalization;
using System.Net;
using OpenRA.GameRules;
using OpenRA.Widgets;
@@ -81,10 +82,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{
var name = panel.Get<TextFieldWidget>("SERVER_NAME").Text;
int listenPort, externalPort;
if (!int.TryParse(panel.Get<TextFieldWidget>("LISTEN_PORT").Text, out listenPort))
if (!int.TryParse(panel.Get<TextFieldWidget>("LISTEN_PORT").Text, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out listenPort))
listenPort = 1234;
if (!int.TryParse(panel.Get<TextFieldWidget>("EXTERNAL_PORT").Text, out externalPort))
if (!int.TryParse(panel.Get<TextFieldWidget>("EXTERNAL_PORT").Text, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out externalPort))
externalPort = 1234;
var passwordField = panel.GetOrNull<PasswordFieldWidget>("PASSWORD");

View File

@@ -11,6 +11,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Graphics;
@@ -151,7 +152,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
frameLimitTextfield.OnLoseFocus = () =>
{
int fps;
int.TryParse(frameLimitTextfield.Text, out fps);
int.TryParse(frameLimitTextfield.Text, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out fps);
ds.MaxFramerate = fps.Clamp(20, 200);
frameLimitTextfield.Text = ds.MaxFramerate.ToString();
Game.SetIdealFrameTime(ds.MaxFramerate);
@@ -162,8 +163,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
return () =>
{
int x, y;
int.TryParse(windowWidth.Text, out x);
int.TryParse(windowHeight.Text, out y);
int.TryParse(windowWidth.Text, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out x);
int.TryParse(windowHeight.Text, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out y);
ds.WindowedSize = new int2(x, y);
frameLimitTextfield.YieldKeyboardFocus();
};

View File

@@ -13,6 +13,7 @@ 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;
@@ -235,9 +236,9 @@ namespace OpenRA.Utility
for (var z = 3; z < args.Length - 2; z += 3)
{
var start = int.Parse(args[z]);
var m = int.Parse(args[z + 1]);
var n = int.Parse(args[z + 2]);
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);
for (var i = 0; i < m; i++)
for (var j = 0; j < n; j++)

View File

@@ -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"));
var offsetX = int.Parse(mapSection.GetValue("X", "0"));
var offsetY = int.Parse(mapSection.GetValue("Y", "0"));
var width = int.Parse(mapSection.GetValue("Width", "0"));
var height = int.Parse(mapSection.GetValue("Height", "0"));
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);
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) > 0)
.Select(kv => Pair.New(int.Parse(kv.Key),
LocationFromMapOffset(int.Parse(kv.Value), mapSize)))
.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)))
.ToArray();
// Add waypoint actors
@@ -298,7 +298,7 @@ namespace OpenRA.Utility
foreach (KeyValuePair<string, string> kv in terrain)
{
var loc = int.Parse(kv.Key);
var loc = int.Parse(kv.Key, NumberStyles.Integer, NumberFormatInfo.InvariantInfo);
map.Actors.Value.Add("Actor" + actorCount++,
new ActorReference(kv.Value.ToLowerInvariant())
{
@@ -332,7 +332,7 @@ namespace OpenRA.Utility
foreach (KeyValuePair<string, string> kv in overlay)
{
var loc = int.Parse(kv.Key);
var loc = int.Parse(kv.Key, NumberStyles.Integer, NumberFormatInfo.InvariantInfo);
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<string, string> kv in terrain)
{
var loc = int.Parse(kv.Key);
var loc = int.Parse(kv.Key, NumberStyles.Integer, NumberFormatInfo.InvariantInfo);
map.Actors.Value.Add("Actor" + actorCount++,
new ActorReference(kv.Value.Split(',')[0].ToLowerInvariant())
{
@@ -391,11 +391,13 @@ namespace OpenRA.Utility
new LocationInit(new CPos(loc % mapSize, loc / mapSize)),
new OwnerInit(parts[0]),
new HealthInit(float.Parse(parts[2], NumberFormatInfo.InvariantInfo) / 256),
new FacingInit((section == "INFANTRY") ? int.Parse(parts[6]) : int.Parse(parts[4])),
new FacingInit((section == "INFANTRY")
? int.Parse(parts[6], NumberStyles.Integer, NumberFormatInfo.InvariantInfo)
: int.Parse(parts[4], NumberStyles.Integer, NumberFormatInfo.InvariantInfo)),
};
if (section == "INFANTRY")
actor.Add(new SubCellInit(int.Parse(parts[4])));
actor.Add(new SubCellInit(int.Parse(parts[4], NumberStyles.Integer, NumberFormatInfo.InvariantInfo)));
if (!Rules.Info.ContainsKey(parts[1].ToLowerInvariant()))
errorHandler("Ignoring unknown actor type: `{0}`".F(parts[1].ToLowerInvariant()));
@@ -415,8 +417,8 @@ namespace OpenRA.Utility
{
// loc=type,loc,depth
var parts = s.Value.Split(',');
var loc = int.Parse(parts[1]);
map.Smudges.Value.Add(new SmudgeReference(parts[0].ToLowerInvariant(), new int2(loc % mapSize, loc / mapSize), int.Parse(parts[2])));
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)));
}
}

View File

@@ -13,6 +13,7 @@ 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;
@@ -42,7 +43,7 @@ namespace OpenRA.Utility
static void ConvertPxToRange(ref string input, int scaleMult, int scaleDiv)
{
var value = int.Parse(input);
var value = int.Parse(input, NumberStyles.Integer, NumberFormatInfo.InvariantInfo);
var ts = Game.modData.Manifest.TileSize;
var world = value * 1024 * scaleMult / (scaleDiv * ts.Height);
var cells = world / 1024;
@@ -337,7 +338,7 @@ namespace OpenRA.Utility
public static void UpgradeMap(string[] args)
{
var map = new Map(args[1]);
var engineDate = int.Parse(args[2]);
var engineDate = int.Parse(args[2], NumberStyles.Integer, NumberFormatInfo.InvariantInfo);
Game.modData = new ModData(map.RequiresMod);
UpgradeWeaponRules(engineDate, ref map.Weapons, null, 0);
@@ -349,7 +350,7 @@ namespace OpenRA.Utility
public static void UpgradeMod(string[] args)
{
var mod = args[1];
var engineDate = int.Parse(args[2]);
var engineDate = int.Parse(args[2], NumberStyles.Integer, NumberFormatInfo.InvariantInfo);
Game.modData = new ModData(mod);
Game.modData.MapCache.LoadMaps();