Misc simplifications

This commit is contained in:
Kurt 2018-02-28 21:05:50 -08:00
parent faab067f80
commit 24982fe8c5
5 changed files with 13 additions and 15 deletions

View file

@ -184,7 +184,7 @@ namespace PKHeX.Core
if ((_pk = value) == null)
return;
var pkdata = value.Data.SequenceEqual(new byte[value.Data.Length])
var pkdata = value.Data.All(z => z == 0)
? value.Data
: PKX.EncryptArray45(value.Data);
pkdata.CopyTo(Data, 8);

View file

@ -142,9 +142,9 @@ namespace PKHeX.Core
// Check to see if the save is initialized completely
// if the block is not initialized, fall back to the other save.
if (GetData(0x00000, 10).SequenceEqual(Enumerable.Repeat((byte)0xFF, 10)))
if (GetData(0x00000, 10).All(z => z == 0xFF))
{ generalBlock = 1; return; }
if (GetData(0x40000, 10).SequenceEqual(Enumerable.Repeat((byte)0xFF, 10)))
if (GetData(0x40000, 10).All(z => z == 0xFF))
{ generalBlock = 0; return; }
// Check SaveCount for current save
@ -166,9 +166,9 @@ namespace PKHeX.Core
// Check to see if the save is initialized completely
// if the block is not initialized, fall back to the other save.
if (GetData(ofs + 0x00000, 10).SequenceEqual(Enumerable.Repeat((byte)0xFF, 10)))
if (GetData(ofs + 0x00000, 10).All(z => z == 0xFF))
{ storageBlock = 1; return; }
if (GetData(ofs + 0x40000, 10).SequenceEqual(Enumerable.Repeat((byte)0xFF, 10)))
if (GetData(ofs + 0x40000, 10).All(z => z == 0xFF))
{ storageBlock = 0; return; }
storageBlock = BitConverter.ToUInt16(Data, ofs) >= BitConverter.ToUInt16(Data, ofs + 0x40000) ? 0 : 1;

View file

@ -1,7 +1,6 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using PKHeX.Core;
using PKHeX.WinForms.Properties;

View file

@ -396,7 +396,7 @@ namespace PKHeX.WinForms
public static IEnumerable<StringInstruction> GetFilters(IEnumerable<string> lines)
{
var raw = GetRelevantStrings(lines, new[] { '!', '=' });
var raw = GetRelevantStrings(lines, '!', '=');
return from line in raw
let eval = line[0] == '='
let split = line.Substring(1).Split('=')
@ -405,13 +405,13 @@ namespace PKHeX.WinForms
}
public static IEnumerable<StringInstruction> GetInstructions(IEnumerable<string> lines)
{
var raw = GetRelevantStrings(lines, new[] { '.' }).Select(line => line.Substring(1));
var raw = GetRelevantStrings(lines, '.').Select(line => line.Substring(1));
return from line in raw
select line.Split('=') into split
where split.Length == 2
select new StringInstruction { PropertyName = split[0], PropertyValue = split[1] };
}
private static IEnumerable<string> GetRelevantStrings(IEnumerable<string> lines, IEnumerable<char> pieces)
private static IEnumerable<string> GetRelevantStrings(IEnumerable<string> lines, params char[] pieces)
{
return lines
.Where(line => !string.IsNullOrEmpty(line))
@ -634,8 +634,7 @@ namespace PKHeX.WinForms
PKM.SetRandomIVs();
return;
}
int MaxIV = PKM.Format <= 2 ? 15 : 31;
ReflectFrameworkUtil.SetValue(PKM, cmd.PropertyName, Util.Rand32() & MaxIV);
ReflectFrameworkUtil.SetValue(PKM, cmd.PropertyName, Util.Rand32() & PKM.MaxIV);
}
}
@ -689,9 +688,9 @@ namespace PKHeX.WinForms
{
if (type == typeof(DateTime?)) // Used for PKM.MetDate and other similar properties
{
return DateTime.TryParseExact(value.ToString(), "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateValue)
? new DateTime?(dateValue)
: null;
if (DateTime.TryParseExact(value.ToString(), "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateValue))
return dateValue;
return null;
}
// Convert.ChangeType is suitable for most things

View file

@ -308,7 +308,7 @@ namespace PKHeX.WinForms
}
private void ExportQRFromView()
{
if (mg.Data.SequenceEqual(new byte[mg.Data.Length]))
if (mg.Data.All(z => z == 0))
{
WinFormsUtil.Alert("No wondercard data found in loaded slot!");
return;