mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-08-20 14:14:36 -05:00
Misc cleanup
removes clickonce logic/reference
This commit is contained in:
@@ -54,21 +54,23 @@ private uint RawDate
|
||||
private uint Year
|
||||
{
|
||||
get => (RawDate / 10000) + 2000;
|
||||
set => RawDate = ((value - 2000) * 10000) + (RawDate % 10000);
|
||||
set => RawDate = SetDate(value, Month, Day);
|
||||
}
|
||||
|
||||
private uint Month
|
||||
{
|
||||
get => RawDate % 10000 / 100;
|
||||
set => RawDate = ((Year - 2000) * 10000) + (value * 100) + (RawDate % 100);
|
||||
set => RawDate = SetDate(Year, value, Day);
|
||||
}
|
||||
|
||||
private uint Day
|
||||
{
|
||||
get => RawDate % 100;
|
||||
set => RawDate = ((Year - 2000) * 10000) + (Month * 100) + value;
|
||||
set => RawDate = SetDate(Year, Month, value);
|
||||
}
|
||||
|
||||
private static uint SetDate(uint year, uint month, uint day) => ((year - 2000) * 10000) + (month * 100) + day;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date of the card.
|
||||
/// </summary>
|
||||
|
||||
@@ -19,24 +19,20 @@ public sealed class WC6 : MysteryGift, IRibbonSetEvent3, IRibbonSetEvent4, ILang
|
||||
public WC6(byte[] data)
|
||||
{
|
||||
Data = data;
|
||||
if (Data.Length == SizeFull)
|
||||
{
|
||||
// Load Restrictions
|
||||
RestrictVersion = Data[0x000];
|
||||
RestrictLanguage = Data[0x1FF];
|
||||
if (Data.Length != SizeFull)
|
||||
return;
|
||||
|
||||
byte[] wc6 = new byte[Size];
|
||||
if (Data[0x205] != 0) // Valid data
|
||||
Array.Copy(Data, SizeFull - Size, wc6, 0, wc6.Length);
|
||||
Data = wc6;
|
||||
// Load Restrictions
|
||||
RestrictVersion = Data[0x000];
|
||||
RestrictLanguage = Data[0x1FF];
|
||||
|
||||
DateTime now = DateTime.Now;
|
||||
Year = (uint)now.Year;
|
||||
Month = (uint)now.Month;
|
||||
Day = (uint)now.Day;
|
||||
}
|
||||
if (Year < 2000)
|
||||
Data = new byte[Data.Length]; // Invalidate
|
||||
byte[] wc6 = new byte[Size];
|
||||
if (Data[0x205] != 0) // Valid data
|
||||
Array.Copy(Data, SizeFull - Size, wc6, 0, wc6.Length);
|
||||
Data = wc6;
|
||||
|
||||
DateTime now = DateTime.Now;
|
||||
RawDate = SetDate((uint) now.Year, (uint) now.Month, (uint) now.Day);
|
||||
}
|
||||
|
||||
public int RestrictLanguage { get; set; } = 0; // None
|
||||
@@ -76,21 +72,23 @@ private uint RawDate
|
||||
private uint Year
|
||||
{
|
||||
get => RawDate / 10000;
|
||||
set => RawDate = (value * 10000) + (RawDate % 10000);
|
||||
set => RawDate = SetDate(value, Month, Day);
|
||||
}
|
||||
|
||||
private uint Month
|
||||
{
|
||||
get => RawDate % 10000 / 100;
|
||||
set => RawDate = (Year * 10000) + (value * 100) + (RawDate % 100);
|
||||
set => RawDate = SetDate(Year, value, Day);
|
||||
}
|
||||
|
||||
private uint Day
|
||||
{
|
||||
get => RawDate % 100;
|
||||
set => RawDate = (Year * 10000) + (Month * 100) + value;
|
||||
set => RawDate = SetDate(Year, Month, value);
|
||||
}
|
||||
|
||||
private static uint SetDate(uint year, uint month, uint day) => (year * 10000) + (month * 100) + day;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date of the card.
|
||||
/// </summary>
|
||||
|
||||
@@ -28,10 +28,9 @@ public WC7(byte[] data)
|
||||
byte[] wcx = new byte[Size];
|
||||
Array.Copy(Data, SizeFull - Size, wcx, 0, wcx.Length);
|
||||
Data = wcx;
|
||||
|
||||
DateTime now = DateTime.Now;
|
||||
Year = (uint)now.Year;
|
||||
Month = (uint)now.Month;
|
||||
Day = (uint)now.Day;
|
||||
RawDate = SetDate((uint) now.Year, (uint) now.Month, (uint) now.Day);
|
||||
}
|
||||
|
||||
public int RestrictLanguage { get; set; } = 0; // None
|
||||
@@ -71,21 +70,23 @@ private uint RawDate
|
||||
private uint Year
|
||||
{
|
||||
get => (RawDate / 10000) + 2000;
|
||||
set => RawDate = ((value - 2000) * 10000) + (RawDate % 10000);
|
||||
set => RawDate = SetDate(value, Month, Day);
|
||||
}
|
||||
|
||||
private uint Month
|
||||
{
|
||||
get => RawDate % 10000 / 100;
|
||||
set => RawDate = ((Year - 2000) * 10000) + (value * 100) + (RawDate % 100);
|
||||
set => RawDate = SetDate(Year, value, Day);
|
||||
}
|
||||
|
||||
private uint Day
|
||||
{
|
||||
get => RawDate % 100;
|
||||
set => RawDate = ((Year - 2000) * 10000) + (Month * 100) + value;
|
||||
set => RawDate = SetDate(Year, Month, value);
|
||||
}
|
||||
|
||||
private static uint SetDate(uint year, uint month, uint day) => ((year - 2000) * 10000) + (month * 100) + day;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date of the card.
|
||||
/// </summary>
|
||||
|
||||
@@ -413,8 +413,10 @@ public override int Characteristic
|
||||
int pm6stat = 0;
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (IVs[pm6stat = pm6++ % 6] == maxIV)
|
||||
break;
|
||||
}
|
||||
return (pm6stat * 5) + (maxIV % 5);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -831,11 +831,10 @@ public static string GetLocationString(this PKM pk, bool eggmet)
|
||||
/// </summary>
|
||||
/// <param name="list">Source list to copy from</param>
|
||||
/// <param name="dest">Destination list/array</param>
|
||||
/// <param name="sav">Context for checking slot write protection</param>
|
||||
/// <param name="skip">Criteria for skipping a slot</param>
|
||||
/// <param name="start">Starting point to copy to</param>
|
||||
/// <returns>Count of <see cref="PKM"/> copied.</returns>
|
||||
public static int CopyTo(this IEnumerable<PKM> list, IList<PKM> dest, SaveFile sav, Func<int, int, bool> skip, int start = 0)
|
||||
public static int CopyTo(this IEnumerable<PKM> list, IList<PKM> dest, Func<int, int, bool> skip, int start = 0)
|
||||
{
|
||||
int ctr = start;
|
||||
foreach (var z in list)
|
||||
|
||||
@@ -200,7 +200,7 @@ private int GetBoxRawDataOffset(int i)
|
||||
public override int BoxSlotCount => Japanese ? 30 : 20;
|
||||
|
||||
public override bool HasParty => true;
|
||||
private int StringLength => Japanese ? PK1.STRLEN_J : PK1.STRLEN_U;
|
||||
private int StringLength => Japanese ? _K12.STRLEN_J : _K12.STRLEN_U;
|
||||
|
||||
public override bool IsPKMPresent(int Offset) => PKX.IsPKMPresentGB(Data, Offset);
|
||||
|
||||
@@ -421,15 +421,9 @@ public override int GetDaycareSlotOffset(int loc, int slot)
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void SetDaycareEXP(int loc, int slot, uint EXP)
|
||||
{
|
||||
public override void SetDaycareEXP(int loc, int slot, uint EXP) { } // todo
|
||||
|
||||
}
|
||||
|
||||
public override void SetDaycareOccupied(int loc, int slot, bool occupied)
|
||||
{
|
||||
|
||||
}
|
||||
public override void SetDaycareOccupied(int loc, int slot, bool occupied) { } // todo
|
||||
|
||||
// Storage
|
||||
public override int PartyCount
|
||||
|
||||
@@ -658,10 +658,7 @@ public override int GetDaycareSlotOffset(int loc, int slot)
|
||||
return BitConverter.ToUInt32(Data, ofs);
|
||||
}
|
||||
|
||||
public override bool? IsDaycareOccupied(int loc, int slot)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public override bool? IsDaycareOccupied(int loc, int slot) => null; // todo
|
||||
|
||||
public override void SetDaycareEXP(int loc, int slot, uint EXP)
|
||||
{
|
||||
@@ -669,10 +666,7 @@ public override void SetDaycareEXP(int loc, int slot, uint EXP)
|
||||
BitConverter.GetBytes(EXP).CopyTo(Data, ofs);
|
||||
}
|
||||
|
||||
public override void SetDaycareOccupied(int loc, int slot, bool occupied)
|
||||
{
|
||||
|
||||
}
|
||||
public override void SetDaycareOccupied(int loc, int slot, bool occupied) { } // todo
|
||||
|
||||
// Mystery Gift
|
||||
private bool MysteryGiftActive { get => (Data[GBO + 72] & 1) == 1; set => Data[GBO + 72] = (byte)((Data[GBO + 72] & 0xFE) | (value ? 1 : 0)); }
|
||||
|
||||
@@ -1028,7 +1028,7 @@ private void SetWC6(MysteryGift wc6, int index)
|
||||
}
|
||||
|
||||
// Gym History
|
||||
private ushort[][] GymTeams
|
||||
public ushort[][] GymTeams
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
@@ -835,9 +835,23 @@ public override InventoryPouch[] Inventory
|
||||
{
|
||||
get
|
||||
{
|
||||
InventoryPouch[] pouch;
|
||||
if (SM)
|
||||
pouch = new InventoryPouch[]
|
||||
var bag = GetPouches();
|
||||
foreach (var p in bag)
|
||||
p.GetPouch(Data);
|
||||
return bag;
|
||||
}
|
||||
set
|
||||
{
|
||||
foreach (var p in value)
|
||||
p.SetPouch(Data);
|
||||
}
|
||||
}
|
||||
|
||||
private InventoryPouch[] GetPouches()
|
||||
{
|
||||
if (SM)
|
||||
{
|
||||
return new InventoryPouch[]
|
||||
{
|
||||
new InventoryPouch7(InventoryType.Medicine, Legal.Pouch_Medicine_SM, 999, OFS_PouchMedicine),
|
||||
new InventoryPouch7(InventoryType.Items, Legal.Pouch_Items_SM, 999, OFS_PouchHeldItem),
|
||||
@@ -846,26 +860,17 @@ public override InventoryPouch[] Inventory
|
||||
new InventoryPouch7(InventoryType.KeyItems, Legal.Pouch_Key_SM, 1, OFS_PouchKeyItem),
|
||||
new InventoryPouch7(InventoryType.ZCrystals, Legal.Pouch_ZCrystal_SM, 1, OFS_PouchZCrystals),
|
||||
};
|
||||
else // USUM
|
||||
pouch = new InventoryPouch[]
|
||||
{
|
||||
new InventoryPouch7(InventoryType.Medicine, Legal.Pouch_Medicine_SM, 999, OFS_PouchMedicine),
|
||||
new InventoryPouch7(InventoryType.Items, Legal.Pouch_Items_SM, 999, OFS_PouchHeldItem),
|
||||
new InventoryPouch7(InventoryType.TMHMs, Legal.Pouch_TMHM_SM, 1, OFS_PouchTMHM),
|
||||
new InventoryPouch7(InventoryType.Berries, Legal.Pouch_Berries_SM, 999, OFS_PouchBerry),
|
||||
new InventoryPouch7(InventoryType.KeyItems, Legal.Pouch_Key_USUM, 1, OFS_PouchKeyItem),
|
||||
new InventoryPouch7(InventoryType.ZCrystals, Legal.Pouch_ZCrystal_USUM, 1, OFS_PouchZCrystals),
|
||||
new InventoryPouch7(InventoryType.BattleItems, Legal.Pouch_Roto_USUM, 999, OFS_BattleItems),
|
||||
};
|
||||
foreach (var p in pouch)
|
||||
p.GetPouch(Data);
|
||||
return pouch;
|
||||
}
|
||||
set
|
||||
return new InventoryPouch[] // USUM
|
||||
{
|
||||
foreach (var p in value)
|
||||
p.SetPouch(Data);
|
||||
}
|
||||
new InventoryPouch7(InventoryType.Medicine, Legal.Pouch_Medicine_SM, 999, OFS_PouchMedicine),
|
||||
new InventoryPouch7(InventoryType.Items, Legal.Pouch_Items_SM, 999, OFS_PouchHeldItem),
|
||||
new InventoryPouch7(InventoryType.TMHMs, Legal.Pouch_TMHM_SM, 1, OFS_PouchTMHM),
|
||||
new InventoryPouch7(InventoryType.Berries, Legal.Pouch_Berries_SM, 999, OFS_PouchBerry),
|
||||
new InventoryPouch7(InventoryType.KeyItems, Legal.Pouch_Key_USUM, 1, OFS_PouchKeyItem),
|
||||
new InventoryPouch7(InventoryType.ZCrystals, Legal.Pouch_ZCrystal_USUM, 1, OFS_PouchZCrystals),
|
||||
new InventoryPouch7(InventoryType.BattleItems, Legal.Pouch_Roto_USUM, 999, OFS_BattleItems),
|
||||
};
|
||||
}
|
||||
|
||||
// Battle Tree
|
||||
@@ -1421,8 +1426,10 @@ protected override bool[] MysteryGiftReceivedFlags
|
||||
|
||||
byte[] data = new byte[value.Length/8];
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
{
|
||||
if (value[i])
|
||||
data[i>>3] |= (byte)(1 << (i&7));
|
||||
}
|
||||
|
||||
data.CopyTo(Data, WondercardFlags);
|
||||
Edited = true;
|
||||
|
||||
@@ -698,7 +698,7 @@ public void SortBoxes(int BoxStart = 0, int BoxEnd = -1, Func<IEnumerable<PKM>,
|
||||
var result = Sorted.ToArray();
|
||||
var boxclone = new PKM[BD.Count];
|
||||
BD.CopyTo(boxclone, 0);
|
||||
result.CopyTo(boxclone, this, skip, start);
|
||||
result.CopyTo(boxclone, skip, start);
|
||||
|
||||
SlotPointerUtil.UpdateRepointFrom(boxclone, BD, 0, SlotPointers);
|
||||
BoxData = boxclone;
|
||||
@@ -764,7 +764,7 @@ public bool SetPCBinary(byte[] data)
|
||||
|
||||
var BD = BoxData;
|
||||
var pkdata = PKX.GetPKMDataFromConcatenatedBinary(data, BlankPKM.EncryptedBoxData.Length);
|
||||
pkdata.Select(z => GetPKM(DecryptPKM(z))).CopyTo(BD, this, IsSlotOverwriteProtected);
|
||||
pkdata.Select(z => GetPKM(DecryptPKM(z))).CopyTo(BD, IsSlotOverwriteProtected);
|
||||
BoxData = BD;
|
||||
return true;
|
||||
}
|
||||
@@ -781,7 +781,7 @@ public bool SetBoxBinary(byte[] data, int box)
|
||||
|
||||
var BD = BoxData;
|
||||
var pkdata = PKX.GetPKMDataFromConcatenatedBinary(data, BlankPKM.EncryptedBoxData.Length);
|
||||
pkdata.Select(z => GetPKM(DecryptPKM(z))).CopyTo(BD, this, IsSlotOverwriteProtected, start);
|
||||
pkdata.Select(z => GetPKM(DecryptPKM(z))).CopyTo(BD, IsSlotOverwriteProtected, start);
|
||||
BoxData = BD;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -983,8 +983,8 @@ private void ToggleViewSubEditors(SaveFile sav)
|
||||
B_CGearSkin.Enabled = sav.Generation == 5;
|
||||
B_OpenPokeBeans.Enabled = B_CellsStickers.Enabled = B_FestivalPlaza.Enabled = sav is SAV7;
|
||||
|
||||
B_OpenTrainerInfo.Enabled = B_OpenItemPouch.Enabled = sav.HasParty && !(SAV is SAV4BR) || SAV is SAV7b; // Box RS & Battle Revolution
|
||||
B_OpenTrainerInfo.Enabled = B_OpenItemPouch.Enabled = sav.HasParty && !(SAV is SAV4BR) || SAV is SAV7b; // Box RS & Battle Revolution
|
||||
B_OpenTrainerInfo.Enabled = B_OpenItemPouch.Enabled = (sav.HasParty && !(SAV is SAV4BR)) || SAV is SAV7b; // Box RS & Battle Revolution
|
||||
B_OpenTrainerInfo.Enabled = B_OpenItemPouch.Enabled = (sav.HasParty && !(SAV is SAV4BR)) || SAV is SAV7b; // Box RS & Battle Revolution
|
||||
B_OpenMiscEditor.Enabled = sav is SAV3 || sav is SAV4 || sav is SAV5;
|
||||
B_Roamer.Enabled = sav is SAV3;
|
||||
|
||||
|
||||
@@ -560,11 +560,11 @@ public void SwapBoxes(int index, int other)
|
||||
public void Dispose()
|
||||
{
|
||||
Sounds.Dispose();
|
||||
HoverWorker.Dispose();
|
||||
SE?.Dispose();
|
||||
OriginalBackground?.Dispose();
|
||||
CurrentBackground?.Dispose();
|
||||
ColorizedColor?.Dispose();
|
||||
HoverWorker?.Dispose();
|
||||
}
|
||||
|
||||
private void UpdateBoxViewAtBoxIndexes(params int[] boxIndexes)
|
||||
|
||||
@@ -94,14 +94,14 @@ private set
|
||||
|
||||
#region Path Variables
|
||||
|
||||
public static string WorkingDirectory => WinFormsUtil.IsClickonceDeployed ? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "PKHeX") : Application.StartupPath;
|
||||
public static string DatabasePath => Path.Combine(WorkingDirectory, "pkmdb");
|
||||
public static string MGDatabasePath => Path.Combine(WorkingDirectory, "mgdb");
|
||||
public static string BackupPath => Path.Combine(WorkingDirectory, "bak");
|
||||
public static string CryPath => Path.Combine(WorkingDirectory, "sounds");
|
||||
public static string SAVPaths => Path.Combine(WorkingDirectory, "savpaths.txt");
|
||||
private static string TemplatePath => Path.Combine(WorkingDirectory, "template");
|
||||
private static string PluginPath => Path.Combine(WorkingDirectory, "plugins");
|
||||
public static readonly string WorkingDirectory = Application.StartupPath;
|
||||
public static readonly string DatabasePath = Path.Combine(WorkingDirectory, "pkmdb");
|
||||
public static readonly string MGDatabasePath = Path.Combine(WorkingDirectory, "mgdb");
|
||||
public static readonly string BackupPath = Path.Combine(WorkingDirectory, "bak");
|
||||
public static readonly string CryPath = Path.Combine(WorkingDirectory, "sounds");
|
||||
public static readonly string SAVPaths = Path.Combine(WorkingDirectory, "savpaths.txt");
|
||||
private static readonly string TemplatePath = Path.Combine(WorkingDirectory, "template");
|
||||
private static readonly string PluginPath = Path.Combine(WorkingDirectory, "plugins");
|
||||
private const string ThreadPath = "https://projectpokemon.org/pkhex/";
|
||||
private const string VersionPath = "https://raw.githubusercontent.com/kwsch/PKHeX/master/PKHeX.WinForms/Resources/text/version.txt";
|
||||
|
||||
|
||||
@@ -146,9 +146,6 @@
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(Configuration)' == 'ClickOnce'">
|
||||
<Reference Include="System.Deployment" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Controls\PKM Editor\IMainEditor.cs" />
|
||||
<Compile Include="Controls\PKM Editor\CatchRate.cs">
|
||||
|
||||
@@ -275,7 +275,6 @@ private static int GetForm(IEncounterable enc)
|
||||
|
||||
private void Menu_SearchAdvanced_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void Menu_Exit_Click(object sender, EventArgs e) => Close();
|
||||
|
||||
@@ -212,7 +212,6 @@ private void B_Save_Click(object sender, EventArgs e)
|
||||
|
||||
private void HandleSpecialFlags()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void ChangeCustomFlag(object sender, EventArgs e)
|
||||
|
||||
@@ -7,13 +7,16 @@
|
||||
|
||||
namespace PKHeX.WinForms
|
||||
{
|
||||
public static class FontUtil
|
||||
public static class SafeNativeMethods
|
||||
{
|
||||
#if WINDOWS
|
||||
[DllImport("gdi32.dll")]
|
||||
private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont, IntPtr pdv, [In] ref uint pcFonts);
|
||||
internal static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont, IntPtr pdv, [In] ref uint pcFonts);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static class FontUtil
|
||||
{
|
||||
private static readonly PrivateFontCollection s_FontCollection = new PrivateFontCollection();
|
||||
|
||||
private static FontFamily[] FontFamilies
|
||||
@@ -36,7 +39,7 @@ private static void SetPKXFont()
|
||||
IntPtr fontPtr = Marshal.AllocCoTaskMem(fontData.Length);
|
||||
Marshal.Copy(fontData, 0, fontPtr, fontData.Length);
|
||||
s_FontCollection.AddMemoryFont(fontPtr, Resources.pgldings_normalregular.Length); uint dummy = 0;
|
||||
AddFontMemResourceEx(fontPtr, (uint)Resources.pgldings_normalregular.Length, IntPtr.Zero, ref dummy);
|
||||
SafeNativeMethods.AddFontMemResourceEx(fontPtr, (uint)Resources.pgldings_normalregular.Length, IntPtr.Zero, ref dummy);
|
||||
Marshal.FreeCoTaskMem(fontPtr);
|
||||
#else
|
||||
GCHandle fontHandle = GCHandle.Alloc(fontData, GCHandleType.Pinned);
|
||||
|
||||
@@ -23,7 +23,7 @@ public QRCodeData(int version)
|
||||
|
||||
private static int ModulesPerSideFromVersion(int version)
|
||||
{
|
||||
return 21 + (version - 1) * 4;
|
||||
return 21 + ((version - 1) * 4);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
// ReSharper disable UnusedMember.Local
|
||||
|
||||
// From: https://github.com/codebude/QRCoder
|
||||
namespace QRCoder
|
||||
@@ -103,15 +104,19 @@ public QRCodeData CreateQRCode(string plainText, ECCLevel eccLevel, bool forceUt
|
||||
for (var i = 0; i < Math.Max(eccInfo.CodewordsInGroup1, eccInfo.CodewordsInGroup2); i++)
|
||||
{
|
||||
foreach (var codeBlock in codeWordWithECC)
|
||||
{
|
||||
if (codeBlock.CodeWords.Count > i)
|
||||
interleavedWordsSb.Append(codeBlock.CodeWords[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < eccInfo.ECCPerBlock; i++)
|
||||
{
|
||||
foreach (var codeBlock in codeWordWithECC)
|
||||
{
|
||||
if (codeBlock.ECCWords.Count > i)
|
||||
interleavedWordsSb.Append(codeBlock.ECCWords[i]);
|
||||
}
|
||||
}
|
||||
interleavedWordsSb.Append(new string('0', remainderBits[version - 1]));
|
||||
var interleavedData = interleavedWordsSb.ToString();
|
||||
@@ -227,8 +232,8 @@ public static void PlaceVersion(ref QRCodeData qrCode, string versionStr)
|
||||
{
|
||||
for (var y = 0; y < 3; y++)
|
||||
{
|
||||
qrCode.ModuleMatrix[y + size - 11][x] = vStr[x * 3 + y] == '1';
|
||||
qrCode.ModuleMatrix[x][y + size - 11] = vStr[x * 3 + y] == '1';
|
||||
qrCode.ModuleMatrix[y + size - 11][x] = vStr[(x * 3) + y] == '1';
|
||||
qrCode.ModuleMatrix[x][y + size - 11] = vStr[(x * 3) + y] == '1';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -379,10 +384,11 @@ public static void ReserveVersionAreas(int size, int version, ref List<Rectangle
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static void PlaceDarkModule(ref QRCodeData qrCode, int version, ref List<Rectangle> blockedModules)
|
||||
{
|
||||
qrCode.ModuleMatrix[4 * version + 9][8] = true;
|
||||
blockedModules.Add(new Rectangle(8, 4 * version + 9, 1, 1));
|
||||
qrCode.ModuleMatrix[(4 * version) + 9][8] = true;
|
||||
blockedModules.Add(new Rectangle(8, (4 * version) + 9, 1, 1));
|
||||
}
|
||||
|
||||
public static void PlaceFinderPatterns(ref QRCodeData qrCode, ref List<Rectangle> blockedModules)
|
||||
@@ -515,10 +521,12 @@ public static int Score(ref QRCodeData qrCode)
|
||||
{
|
||||
for (var x = 0; x < size - 1; x++)
|
||||
{
|
||||
if (qrCode.ModuleMatrix[y][x] == qrCode.ModuleMatrix[y][x + 1] &&
|
||||
qrCode.ModuleMatrix[y][x] == qrCode.ModuleMatrix[y + 1][x] &&
|
||||
qrCode.ModuleMatrix[y][x] == qrCode.ModuleMatrix[y + 1][x + 1])
|
||||
if (qrCode.ModuleMatrix[y][x] == qrCode.ModuleMatrix[y][x + 1]
|
||||
&& qrCode.ModuleMatrix[y][x] == qrCode.ModuleMatrix[y + 1][x]
|
||||
&& qrCode.ModuleMatrix[y][x] == qrCode.ModuleMatrix[y + 1][x + 1])
|
||||
{
|
||||
score2 += 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -527,54 +535,54 @@ public static int Score(ref QRCodeData qrCode)
|
||||
{
|
||||
for (var x = 0; x < size - 10; x++)
|
||||
{
|
||||
if ((qrCode.ModuleMatrix[y][x] &&
|
||||
!qrCode.ModuleMatrix[y][x + 1] &&
|
||||
qrCode.ModuleMatrix[y][x + 2] &&
|
||||
qrCode.ModuleMatrix[y][x + 3] &&
|
||||
qrCode.ModuleMatrix[y][x + 4] &&
|
||||
!qrCode.ModuleMatrix[y][x + 5] &&
|
||||
qrCode.ModuleMatrix[y][x + 6] &&
|
||||
!qrCode.ModuleMatrix[y][x + 7] &&
|
||||
!qrCode.ModuleMatrix[y][x + 8] &&
|
||||
!qrCode.ModuleMatrix[y][x + 9] &&
|
||||
!qrCode.ModuleMatrix[y][x + 10]) ||
|
||||
(!qrCode.ModuleMatrix[y][x] &&
|
||||
!qrCode.ModuleMatrix[y][x + 1] &&
|
||||
!qrCode.ModuleMatrix[y][x + 2] &&
|
||||
!qrCode.ModuleMatrix[y][x + 3] &&
|
||||
qrCode.ModuleMatrix[y][x + 4] &&
|
||||
!qrCode.ModuleMatrix[y][x + 5] &&
|
||||
qrCode.ModuleMatrix[y][x + 6] &&
|
||||
qrCode.ModuleMatrix[y][x + 7] &&
|
||||
qrCode.ModuleMatrix[y][x + 8] &&
|
||||
!qrCode.ModuleMatrix[y][x + 9] &&
|
||||
qrCode.ModuleMatrix[y][x + 10]))
|
||||
if ((qrCode.ModuleMatrix[y][x]
|
||||
&& !qrCode.ModuleMatrix[y][x + 1]
|
||||
&& qrCode.ModuleMatrix[y][x + 2]
|
||||
&& qrCode.ModuleMatrix[y][x + 3]
|
||||
&& qrCode.ModuleMatrix[y][x + 4]
|
||||
&& !qrCode.ModuleMatrix[y][x + 5]
|
||||
&& qrCode.ModuleMatrix[y][x + 6]
|
||||
&& !qrCode.ModuleMatrix[y][x + 7]
|
||||
&& !qrCode.ModuleMatrix[y][x + 8]
|
||||
&& !qrCode.ModuleMatrix[y][x + 9]
|
||||
&& !qrCode.ModuleMatrix[y][x + 10])
|
||||
|| (!qrCode.ModuleMatrix[y][x]
|
||||
&& !qrCode.ModuleMatrix[y][x + 1]
|
||||
&& !qrCode.ModuleMatrix[y][x + 2]
|
||||
&& !qrCode.ModuleMatrix[y][x + 3]
|
||||
&& qrCode.ModuleMatrix[y][x + 4]
|
||||
&& !qrCode.ModuleMatrix[y][x + 5]
|
||||
&& qrCode.ModuleMatrix[y][x + 6]
|
||||
&& qrCode.ModuleMatrix[y][x + 7]
|
||||
&& qrCode.ModuleMatrix[y][x + 8]
|
||||
&& !qrCode.ModuleMatrix[y][x + 9]
|
||||
&& qrCode.ModuleMatrix[y][x + 10]))
|
||||
{
|
||||
score3 += 40;
|
||||
}
|
||||
|
||||
if ((qrCode.ModuleMatrix[x][y] &&
|
||||
!qrCode.ModuleMatrix[x + 1][y] &&
|
||||
qrCode.ModuleMatrix[x + 2][y] &&
|
||||
qrCode.ModuleMatrix[x + 3][y] &&
|
||||
qrCode.ModuleMatrix[x + 4][y] &&
|
||||
!qrCode.ModuleMatrix[x + 5][y] &&
|
||||
qrCode.ModuleMatrix[x + 6][y] &&
|
||||
!qrCode.ModuleMatrix[x + 7][y] &&
|
||||
!qrCode.ModuleMatrix[x + 8][y] &&
|
||||
!qrCode.ModuleMatrix[x + 9][y] &&
|
||||
!qrCode.ModuleMatrix[x + 10][y]) ||
|
||||
(!qrCode.ModuleMatrix[x][y] &&
|
||||
!qrCode.ModuleMatrix[x + 1][y] &&
|
||||
!qrCode.ModuleMatrix[x + 2][y] &&
|
||||
!qrCode.ModuleMatrix[x + 3][y] &&
|
||||
qrCode.ModuleMatrix[x + 4][y] &&
|
||||
!qrCode.ModuleMatrix[x + 5][y] &&
|
||||
qrCode.ModuleMatrix[x + 6][y] &&
|
||||
qrCode.ModuleMatrix[x + 7][y] &&
|
||||
qrCode.ModuleMatrix[x + 8][y] &&
|
||||
!qrCode.ModuleMatrix[x + 9][y] &&
|
||||
qrCode.ModuleMatrix[x + 10][y]))
|
||||
if ((qrCode.ModuleMatrix[x][y]
|
||||
&& !qrCode.ModuleMatrix[x + 1][y]
|
||||
&& qrCode.ModuleMatrix[x + 2][y]
|
||||
&& qrCode.ModuleMatrix[x + 3][y]
|
||||
&& qrCode.ModuleMatrix[x + 4][y]
|
||||
&& !qrCode.ModuleMatrix[x + 5][y]
|
||||
&& qrCode.ModuleMatrix[x + 6][y]
|
||||
&& !qrCode.ModuleMatrix[x + 7][y]
|
||||
&& !qrCode.ModuleMatrix[x + 8][y]
|
||||
&& !qrCode.ModuleMatrix[x + 9][y]
|
||||
&& !qrCode.ModuleMatrix[x + 10][y])
|
||||
|| (!qrCode.ModuleMatrix[x][y]
|
||||
&& !qrCode.ModuleMatrix[x + 1][y]
|
||||
&& !qrCode.ModuleMatrix[x + 2][y]
|
||||
&& !qrCode.ModuleMatrix[x + 3][y]
|
||||
&& qrCode.ModuleMatrix[x + 4][y]
|
||||
&& !qrCode.ModuleMatrix[x + 5][y]
|
||||
&& qrCode.ModuleMatrix[x + 6][y]
|
||||
&& qrCode.ModuleMatrix[x + 7][y]
|
||||
&& qrCode.ModuleMatrix[x + 8][y]
|
||||
&& !qrCode.ModuleMatrix[x + 9][y]
|
||||
&& qrCode.ModuleMatrix[x + 10][y]))
|
||||
{
|
||||
score3 += 40;
|
||||
}
|
||||
@@ -584,13 +592,17 @@ public static int Score(ref QRCodeData qrCode)
|
||||
//Penalty 4
|
||||
double blackModules = 0;
|
||||
foreach (var row in qrCode.ModuleMatrix)
|
||||
{
|
||||
foreach (bool bit in row)
|
||||
{
|
||||
if (bit)
|
||||
blackModules++;
|
||||
}
|
||||
}
|
||||
|
||||
var percent = (blackModules / (qrCode.ModuleMatrix.Count * qrCode.ModuleMatrix.Count)) * 100;
|
||||
var prevMultipleOf5 = Math.Abs((int) Math.Floor(percent/5)*5 - 50)/5;
|
||||
var nextMultipleOf5 = Math.Abs((int)Math.Floor(percent / 5) * 5 -45)/5;
|
||||
var prevMultipleOf5 = Math.Abs(((int) Math.Floor(percent/5)*5) - 50)/5;
|
||||
var nextMultipleOf5 = Math.Abs(((int)Math.Floor(percent / 5) * 5) - 45)/5;
|
||||
var score4 = Math.Min(prevMultipleOf5, nextMultipleOf5)*10;
|
||||
|
||||
return score1 + score2 + score3 + score4;
|
||||
@@ -600,7 +612,7 @@ public static int Score(ref QRCodeData qrCode)
|
||||
public static bool Pattern2(int x, int y) => y % 2 == 0;
|
||||
public static bool Pattern3(int x, int y) => x % 3 == 0;
|
||||
public static bool Pattern4(int x, int y) => (x + y) % 3 == 0;
|
||||
public static bool Pattern5(int x, int y) => ((y / 2) + (x / 3) % 2) == 0;
|
||||
public static bool Pattern5(int x, int y) => ((y / 2) + ((x / 3) % 2)) == 0;
|
||||
public static bool Pattern6(int x, int y) => ((x * y) % 2) + ((x * y) % 3) == 0;
|
||||
public static bool Pattern7(int x, int y) => (((x * y) % 2) + ((x * y) % 3)) % 2 == 0;
|
||||
public static bool Pattern8(int x, int y) => (((x + y) % 2) + ((x * y) % 3)) % 2 == 0;
|
||||
@@ -614,12 +626,16 @@ private List<string> CalculateECCWords(string bitString, ECCInfo eccInfo)
|
||||
var generatorPolynom = CalculateGeneratorPolynom(eccWords);
|
||||
|
||||
for (var i = 0; i < messagePolynom.PolyItems.Count; i++)
|
||||
{
|
||||
messagePolynom.PolyItems[i] = new PolynomItem(messagePolynom.PolyItems[i].Coefficient,
|
||||
messagePolynom.PolyItems[i].Exponent + eccWords);
|
||||
messagePolynom.PolyItems[i].Exponent + eccWords);
|
||||
}
|
||||
|
||||
for (var i = 0; i < generatorPolynom.PolyItems.Count; i++)
|
||||
{
|
||||
generatorPolynom.PolyItems[i] = new PolynomItem(generatorPolynom.PolyItems[i].Coefficient,
|
||||
generatorPolynom.PolyItems[i].Exponent + (messagePolynom.PolyItems.Count-1));
|
||||
generatorPolynom.PolyItems[i].Exponent + (messagePolynom.PolyItems.Count - 1));
|
||||
}
|
||||
|
||||
var leadTermSource = messagePolynom;
|
||||
for (var i = 0; (leadTermSource.PolyItems.Count > 0 && leadTermSource.PolyItems[leadTermSource.PolyItems.Count - 1].Exponent > 0); i++)
|
||||
@@ -694,7 +710,7 @@ private static bool StringAll(string input, string charGroupIn)
|
||||
private static Polynom CalculateMessagePolynom(string bitString)
|
||||
{
|
||||
var messagePol = new Polynom();
|
||||
for (var i = bitString.Length / 8 - 1; i >= 0; i--)
|
||||
for (var i = (bitString.Length / 8) - 1; i >= 0; i--)
|
||||
{
|
||||
messagePol.PolyItems.Add(new PolynomItem(BinToDec(bitString.Substring(0, 8)), i));
|
||||
bitString = bitString.Remove(0, 8);
|
||||
@@ -838,7 +854,7 @@ private string PlainTextToBinaryAlphanumeric(string plainText)
|
||||
while (plainText.Length >= 2)
|
||||
{
|
||||
var token = plainText.Substring(0, 2);
|
||||
var dec = alphanumEncDict[token[0]] * 45 + alphanumEncDict[token[1]];
|
||||
var dec = (alphanumEncDict[token[0]] * 45) + alphanumEncDict[token[1]];
|
||||
codeText += DecToBin(dec, 11);
|
||||
plainText = plainText.Substring(2);
|
||||
}
|
||||
@@ -885,8 +901,8 @@ private Polynom XORPolynoms(Polynom messagePolynom, Polynom resPolynom)
|
||||
var polItemRes = new PolynomItem
|
||||
(
|
||||
|
||||
longPoly.PolyItems[i].Coefficient ^
|
||||
(shortPoly.PolyItems.Count > i ? shortPoly.PolyItems[i].Coefficient : 0),
|
||||
longPoly.PolyItems[i].Coefficient
|
||||
^ (shortPoly.PolyItems.Count > i ? shortPoly.PolyItems[i].Coefficient : 0),
|
||||
messagePolynom.PolyItems[0].Exponent - i
|
||||
);
|
||||
resultPolynom.PolyItems.Add(polItemRes);
|
||||
@@ -1183,6 +1199,7 @@ private struct ECCInfo
|
||||
BlocksInGroup2 = blocksInGroup2;
|
||||
CodewordsInGroup2 = codewordsInGroup2;
|
||||
}
|
||||
|
||||
public int Version { get; }
|
||||
public ECCLevel ErrorCorrectionLevel { get; }
|
||||
public int TotalDataCodewords { get; }
|
||||
@@ -1200,6 +1217,7 @@ public VersionInfo(int version, List<VersionInfoDetails> versionInfoDetails)
|
||||
Version = version;
|
||||
Details = versionInfoDetails;
|
||||
}
|
||||
|
||||
public int Version { get; }
|
||||
public List<VersionInfoDetails> Details { get; }
|
||||
}
|
||||
@@ -1223,6 +1241,7 @@ public Antilog(int exponentAlpha, int integerValue)
|
||||
ExponentAlpha = exponentAlpha;
|
||||
IntegerValue = integerValue;
|
||||
}
|
||||
|
||||
public int ExponentAlpha { get; }
|
||||
public int IntegerValue { get; }
|
||||
}
|
||||
|
||||
@@ -139,12 +139,6 @@ public static IEnumerable<Control> GetAllControlsOfType(Control control, Type ty
|
||||
.Where(c => c.GetType() == type);
|
||||
}
|
||||
|
||||
#if CLICKONCE
|
||||
public static bool IsClickonceDeployed => System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed;
|
||||
#else
|
||||
public static bool IsClickonceDeployed => false;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Reads in custom extension types that allow the program to open more extensions.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user