Fix FxCop complaints.

This commit is contained in:
gibbed
2019-03-30 13:18:53 -05:00
parent 51ddcc0e37
commit 407d35b8b5
17 changed files with 458 additions and 43 deletions

View File

@@ -0,0 +1,47 @@
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Scope = "member", Target = "SAM.Game.KeyValue.#LoadAsBinary(System.String)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Scope = "member", Target = "SAM.Game.KeyValue.#ReadAsBinary(System.IO.Stream)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Scope = "member", Target = "SAM.Game.Manager.#LoadUserGameStatsSchema()")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Scope = "member", Target = "SAM.Game.Manager.#OnIconDownload(System.Object,System.Net.DownloadDataCompletedEventArgs)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Scope = "member", Target = "SAM.Game.Manager.#OnUserStatsReceived(SAM.API.Types.UserStatsReceived)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1064:ExceptionsShouldBePublic", Scope = "type", Target = "SAM.Game.Stats.StatIsProtectedException")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA2210:AssembliesShouldHaveValidStrongNames")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Windows.Forms.ColumnHeader.set_Text(System.String)", Scope = "member", Target = "SAM.Game.Manager.#InitializeComponent()")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Windows.Forms.Control.set_Text(System.String)", Scope = "member", Target = "SAM.Game.Manager.#InitializeComponent()")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Windows.Forms.Form.set_Text(System.String)", Scope = "member", Target = "SAM.Game.Manager.#.ctor(System.Int64,SAM.API.Client)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Windows.Forms.MessageBox.Show(System.String,System.String,System.Windows.Forms.MessageBoxButtons,System.Windows.Forms.MessageBoxIcon)", Scope = "member", Target = "SAM.Game.Manager.#OnResetAllStats(System.Object,System.EventArgs)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Windows.Forms.MessageBox.Show(System.String,System.String,System.Windows.Forms.MessageBoxButtons,System.Windows.Forms.MessageBoxIcon)", Scope = "member", Target = "SAM.Game.Manager.#OnUserStatsReceived(SAM.API.Types.UserStatsReceived)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Windows.Forms.MessageBox.Show(System.String,System.String,System.Windows.Forms.MessageBoxButtons,System.Windows.Forms.MessageBoxIcon)", Scope = "member", Target = "SAM.Game.Program.#Main(System.String[])")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Windows.Forms.MessageBox.Show(System.Windows.Forms.IWin32Window,System.String,System.String,System.Windows.Forms.MessageBoxButtons,System.Windows.Forms.MessageBoxIcon)", Scope = "member", Target = "SAM.Game.Manager.#OnCheckAchievement(System.Object,System.Windows.Forms.ItemCheckEventArgs)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Windows.Forms.MessageBox.Show(System.Windows.Forms.IWin32Window,System.String,System.String,System.Windows.Forms.MessageBoxButtons,System.Windows.Forms.MessageBoxIcon)", Scope = "member", Target = "SAM.Game.Manager.#OnResetAllStats(System.Object,System.EventArgs)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Windows.Forms.MessageBox.Show(System.Windows.Forms.IWin32Window,System.String,System.String,System.Windows.Forms.MessageBoxButtons,System.Windows.Forms.MessageBoxIcon)", Scope = "member", Target = "SAM.Game.Manager.#OnStore(System.Object,System.EventArgs)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Windows.Forms.MessageBox.Show(System.Windows.Forms.IWin32Window,System.String,System.String,System.Windows.Forms.MessageBoxButtons,System.Windows.Forms.MessageBoxIcon)", Scope = "member", Target = "SAM.Game.Manager.#RefreshStats()")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Windows.Forms.MessageBox.Show(System.Windows.Forms.IWin32Window,System.String,System.String,System.Windows.Forms.MessageBoxButtons,System.Windows.Forms.MessageBoxIcon)", Scope = "member", Target = "SAM.Game.Manager.#Store()")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Windows.Forms.MessageBox.Show(System.Windows.Forms.IWin32Window,System.String,System.String,System.Windows.Forms.MessageBoxButtons,System.Windows.Forms.MessageBoxIcon)", Scope = "member", Target = "SAM.Game.Manager.#StoreAchievements()")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Windows.Forms.MessageBox.Show(System.Windows.Forms.IWin32Window,System.String,System.String,System.Windows.Forms.MessageBoxButtons,System.Windows.Forms.MessageBoxIcon)", Scope = "member", Target = "SAM.Game.Manager.#StoreStatistics()")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Windows.Forms.ToolStripItem.set_Text(System.String)", Scope = "member", Target = "SAM.Game.Manager.#DownloadNextIcon()")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Windows.Forms.ToolStripItem.set_Text(System.String)", Scope = "member", Target = "SAM.Game.Manager.#InitializeComponent()")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Windows.Forms.ToolStripItem.set_Text(System.String)", Scope = "member", Target = "SAM.Game.Manager.#OnUserStatsReceived(SAM.API.Types.UserStatsReceived)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Windows.Forms.ToolStripItem.set_Text(System.String)", Scope = "member", Target = "SAM.Game.Manager.#RefreshStats()")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Windows.Forms.ToolStripItem.set_ToolTipText(System.String)", Scope = "member", Target = "SAM.Game.Manager.#InitializeComponent()")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1309:UseOrdinalStringComparison", MessageId = "System.String.StartsWith(System.String,System.StringComparison)", Scope = "member", Target = "SAM.Game.Manager.#GetAchievements()")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "wstring", Scope = "member", Target = "SAM.Game.KeyValue.#ReadAsBinary(System.IO.Stream)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily", Scope = "member", Target = "SAM.Game.Manager.#GetStatistics()")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily", Scope = "member", Target = "SAM.Game.Manager.#StoreStatistics()")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "SAM.Game.Stats.AchievementInfo.#ImageIndex")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "SAM.Game.Stats.StatInfo.#DisplayName")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "SAM.Game.Stats.StatInfo.#Extra")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "SAM.Game.Stats.StatInfo.#IsIncrementOnly")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "SAM.Game.Stats.StatIsProtectedException.#.ctor(System.String)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "SAM.Game.Stats.StatIsProtectedException.#.ctor(System.String,System.Exception)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "SAM.Game.StreamHelpers.#ReadStringAscii(System.IO.Stream)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields", Scope = "member", Target = "SAM.Game.Stats.AchievementDefinition.#IsHidden")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields", Scope = "member", Target = "SAM.Game.Stats.FloatStatDefinition.#DefaultValue")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields", Scope = "member", Target = "SAM.Game.Stats.FloatStatDefinition.#MaxChange")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields", Scope = "member", Target = "SAM.Game.Stats.FloatStatDefinition.#MaxValue")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields", Scope = "member", Target = "SAM.Game.Stats.FloatStatDefinition.#MinValue")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields", Scope = "member", Target = "SAM.Game.Stats.IntegerStatDefinition.#DefaultValue")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields", Scope = "member", Target = "SAM.Game.Stats.IntegerStatDefinition.#MaxChange")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields", Scope = "member", Target = "SAM.Game.Stats.IntegerStatDefinition.#MaxValue")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields", Scope = "member", Target = "SAM.Game.Stats.IntegerStatDefinition.#MinValue")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "SAM.Game.Manager.#.ctor(System.Int64,SAM.API.Client)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "SAM.Game.Manager.#InitializeComponent()")]

View File

@@ -47,7 +47,7 @@ namespace SAM.Game
}
var child = this.Children.SingleOrDefault(
c => c.Name.ToLowerInvariant() == key.ToLowerInvariant());
c => string.Compare(c.Name, key, StringComparison.InvariantCultureIgnoreCase) == 0);
if (child == null)
{
@@ -202,7 +202,11 @@ namespace SAM.Game
return this.Name;
}
return string.Format("{0} = {1}", this.Name, this.Value);
return string.Format(
System.Globalization.CultureInfo.CurrentCulture,
"{0} = {1}",
this.Name,
this.Value);
}
public static KeyValue LoadAsBinary(string path)
@@ -214,16 +218,15 @@ namespace SAM.Game
try
{
var input = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
var kv = new KeyValue();
if (kv.ReadAsBinary(input) == false)
using (var input = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
return null;
var kv = new KeyValue();
if (kv.ReadAsBinary(input) == false)
{
return null;
}
return kv;
}
input.Close();
return kv;
}
catch (Exception)
{

View File

@@ -156,12 +156,15 @@ namespace SAM.Game
return;
}
if (this._IconDownloader.IsBusy)
if (this._IconDownloader.IsBusy == true)
{
return;
}
this._DownloadStatusLabel.Text = string.Format("Downloading {0} icons...", this._IconQueue.Count);
this._DownloadStatusLabel.Text = string.Format(
CultureInfo.CurrentCulture,
"Downloading {0} icons...",
this._IconQueue.Count);
this._DownloadStatusLabel.Visible = true;
var info = this._IconQueue[0];
@@ -169,13 +172,15 @@ namespace SAM.Game
this._IconDownloader.DownloadDataAsync(
new Uri(string.Format("http://media.steamcommunity.com/steamcommunity/public/images/apps/{0}/{1}",
this._GameId,
info.IsAchieved == true ? info.IconNormal : info.IconLocked)),
new Uri(string.Format(
CultureInfo.InvariantCulture,
"http://media.steamcommunity.com/steamcommunity/public/images/apps/{0}/{1}",
this._GameId,
info.IsAchieved == true ? info.IconNormal : info.IconLocked)),
info);
}
private string TranslateError(int id)
private static string TranslateError(int id)
{
switch (id)
{
@@ -188,7 +193,7 @@ namespace SAM.Game
return id.ToString(CultureInfo.InvariantCulture);
}
private string GetLocalizedString(KeyValue kv, string language, string defaultValue)
private static string GetLocalizedString(KeyValue kv, string language, string defaultValue)
{
var name = kv[language].AsString("");
if (string.IsNullOrEmpty(name) == false)
@@ -223,7 +228,10 @@ namespace SAM.Game
path = API.Steam.GetInstallPath();
path = Path.Combine(path, "appcache");
path = Path.Combine(path, "stats");
path = Path.Combine(path, string.Format("UserGameStatsSchema_{0}.bin", this._GameId));
path = Path.Combine(path, string.Format(
CultureInfo.InvariantCulture,
"UserGameStatsSchema_{0}.bin",
this._GameId));
if (File.Exists(path) == false)
{
@@ -268,7 +276,7 @@ namespace SAM.Game
var type = (APITypes.UserStatType)rawType;
switch (type)
{
case API.Types.UserStatType.Invalid:
case APITypes.UserStatType.Invalid:
{
break;
}
@@ -318,7 +326,7 @@ namespace SAM.Game
if (stat.Children != null)
{
foreach (var bits in stat.Children.Where(
b => b.Name.ToLowerInvariant() == "bits"))
b => string.Compare(b.Name, "bits", StringComparison.InvariantCultureIgnoreCase) == 0))
{
if (bits.Valid == false ||
bits.Children == null)
@@ -364,6 +372,7 @@ namespace SAM.Game
if (param.Result != 1)
{
this._GameStatusLabel.Text = string.Format(
CultureInfo.CurrentCulture,
"Error while retrieving stats: {0}",
TranslateError(param.Result));
this.EnableInput();
@@ -395,6 +404,7 @@ namespace SAM.Game
}
this._GameStatusLabel.Text = string.Format(
CultureInfo.CurrentCulture,
"Retrieved {0} achievements and {1} statistics.",
this._AchievementListView.Items.Count,
this._StatisticsDataGridView.Rows.Count);
@@ -428,7 +438,7 @@ namespace SAM.Game
foreach (var def in this._AchievementDefinitions)
{
if (def.Id == string.Empty)
if (string.IsNullOrEmpty(def.Id) == true)
{
continue;
}
@@ -460,7 +470,7 @@ namespace SAM.Game
info.Item = item;
if (item.Text.StartsWith("#") == true)
if (item.Text.StartsWith("#", StringComparison.InvariantCulture) == true)
{
item.Text = info.Id;
}
@@ -580,7 +590,10 @@ namespace SAM.Game
{
MessageBox.Show(
this,
string.Format("An error occured while setting the state for {0}, aborting store.", info.Id),
string.Format(
CultureInfo.CurrentCulture,
"An error occurred while setting the state for {0}, aborting store.",
info.Id),
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
@@ -615,7 +628,10 @@ namespace SAM.Game
{
MessageBox.Show(
this,
string.Format("An error occured while setting the value for {0}, aborting store.", stat.Id),
string.Format(
CultureInfo.CurrentCulture,
"An error occurred while setting the value for {0}, aborting store.",
stat.Id),
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
@@ -631,7 +647,10 @@ namespace SAM.Game
{
MessageBox.Show(
this,
string.Format("An error occured while setting the value for {0}, aborting store.", stat.Id),
string.Format(
CultureInfo.CurrentCulture,
"An error occurred while setting the value for {0}, aborting store.",
stat.Id),
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
@@ -640,7 +659,7 @@ namespace SAM.Game
}
else
{
throw new Exception();
throw new InvalidOperationException("unsupported stat type");
}
}
@@ -701,7 +720,7 @@ namespace SAM.Game
{
MessageBox.Show(
this,
"An error occured while storing, aborting.",
"An error occurred while storing, aborting.",
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
@@ -735,7 +754,11 @@ namespace SAM.Game
MessageBox.Show(
this,
string.Format("Stored {0} achievements and {1} statistics.", achievements, stats),
string.Format(
CultureInfo.CurrentCulture,
"Stored {0} achievements and {1} statistics.",
achievements,
stats),
"Information",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
@@ -746,18 +769,17 @@ namespace SAM.Game
{
if (e.Context == DataGridViewDataErrorContexts.Commit)
{
var view = (DataGridView)sender;
if (e.Exception is Stats.StatIsProtectedException)
{
e.ThrowException = false;
e.Cancel = true;
var view = (DataGridView)sender;
view.Rows[e.RowIndex].ErrorText = "Stat is protected! -- you can't modify it";
}
else
{
e.ThrowException = false;
e.Cancel = true;
var view = (DataGridView)sender;
view.Rows[e.RowIndex].ErrorText = "Invalid value";
}
}

View File

@@ -43,7 +43,7 @@ namespace SAM.Game
if (long.TryParse(args[0], out appId) == false)
{
MessageBox.Show(
"Could not parse application ID from commandline argument.",
"Could not parse application ID from command line argument.",
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);

View File

@@ -73,6 +73,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="Stats\AchievementInfo.cs" />
<Compile Include="DoubleBufferedListView.cs">
<SubType>Component</SubType>

View File

@@ -34,7 +34,11 @@ namespace SAM.Game.Stats
public override string ToString()
{
return string.Format("{0}: {1}", this.Name ?? this.Id ?? base.ToString(), this.Permission);
return string.Format(
System.Globalization.CultureInfo.CurrentCulture,
"{0}: {1}",
this.Name ?? this.Id ?? base.ToString(),
this.Permission);
}
}
}

View File

@@ -32,7 +32,7 @@ namespace SAM.Game.Stats
get { return this.FloatValue; }
set
{
var f = float.Parse((string)value);
var f = float.Parse((string)value, System.Globalization.CultureInfo.CurrentCulture);
if ((this.Permission & 2) != 0 &&
this.FloatValue.Equals(f) == false)

View File

@@ -32,7 +32,7 @@ namespace SAM.Game.Stats
get { return this.IntValue; }
set
{
var i = int.Parse((string)value);
var i = int.Parse((string)value, System.Globalization.CultureInfo.CurrentCulture);
if ((this.Permission & 2) != 0 &&
this.IntValue != i)

View File

@@ -21,10 +21,30 @@
*/
using System;
using System.Runtime.Serialization;
namespace SAM.Game.Stats
{
[Serializable]
internal class StatIsProtectedException : Exception
{
public StatIsProtectedException()
{
}
public StatIsProtectedException(string message)
: base(message)
{
}
public StatIsProtectedException(string message, Exception innerException)
: base(message, innerException)
{
}
protected StatIsProtectedException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}