Compare commits
No commits in common. '20250109' and '20230911' have entirely different histories.
11 changed files with 0 additions and 3571 deletions
@ -1,381 +0,0 @@ |
|||||||
using System; |
|
||||||
using System.Collections.Generic; |
|
||||||
using System.Linq; |
|
||||||
using System.IO; |
|
||||||
using System.Security.Cryptography; |
|
||||||
|
|
||||||
namespace UTIL |
|
||||||
{ |
|
||||||
#region CRC8 |
|
||||||
public class CRC8_2 |
|
||||||
{ |
|
||||||
//CRC8Calc crc_dallas = new CRC8Calc(CRC8_POLY.CRC8_DALLAS_MAXIM); |
|
||||||
//checksum = crc_dallas.Checksum(testVal); |
|
||||||
//CRC8Calc crc = new CRC8Calc(CRC8_POLY.CRC8_CCITT); |
|
||||||
//checksum = crc.Checksum(testVal); |
|
||||||
|
|
||||||
public enum CRC8_POLY |
|
||||||
{ |
|
||||||
CRC8 = 0xd5, |
|
||||||
CRC8_CCITT = 0x07, |
|
||||||
CRC8_DALLAS_MAXIM = 0x31, |
|
||||||
CRC8_SAE_J1850 = 0x1D, |
|
||||||
CRC_8_WCDMA = 0x9b, |
|
||||||
}; |
|
||||||
private byte[] table = new byte[256]; |
|
||||||
|
|
||||||
public byte Checksum(params byte[] val) |
|
||||||
{ |
|
||||||
if (val == null) |
|
||||||
throw new ArgumentNullException("val"); |
|
||||||
byte c = 0; |
|
||||||
foreach (byte b in val) |
|
||||||
c = table[c ^ b]; |
|
||||||
return c; |
|
||||||
} |
|
||||||
|
|
||||||
public byte[] Table |
|
||||||
{ |
|
||||||
get |
|
||||||
{ |
|
||||||
return this.table; |
|
||||||
} |
|
||||||
set |
|
||||||
{ |
|
||||||
this.table = value; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public byte[] GenerateTable(CRC8_POLY polynomial) |
|
||||||
{ |
|
||||||
byte[] csTable = new byte[256]; |
|
||||||
for (int i = 0; i < 256; ++i) |
|
||||||
{ |
|
||||||
int curr = i; |
|
||||||
for (int j = 0; j < 8; ++j) |
|
||||||
{ |
|
||||||
if ((curr & 0x80) != 0) |
|
||||||
curr = (curr << 1) ^ (int)polynomial; |
|
||||||
else |
|
||||||
curr <<= 1; |
|
||||||
} |
|
||||||
csTable[i] = (byte)curr; |
|
||||||
} |
|
||||||
return csTable; |
|
||||||
} |
|
||||||
|
|
||||||
public CRC8_2(CRC8_POLY polynomial) |
|
||||||
{ |
|
||||||
this.table = this.GenerateTable(polynomial); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public static class CRC8_3 |
|
||||||
{ |
|
||||||
static byte[] CRC8_TABLE = new byte[]{ |
|
||||||
0, 94, 188, 226, 97, 63, 221, 131, 194, 156, 126, 32, 163, 253, 31, 65, |
|
||||||
157, 195, 33, 127, 252, 162, 64, 30, 95, 1, 227, 189, 62, 96, 130, 220, |
|
||||||
35, 125, 159, 193, 66, 28, 254, 160, 225, 191, 93, 3, 128, 222, 60, 98, |
|
||||||
190, 224, 2, 92, 223, 129, 99, 61, 124, 34, 192, 158, 29, 67, 161, 255, |
|
||||||
70, 24, 250, 164, 39, 121, 155, 197, 132, 218, 56, 102, 229, 187, 89, 7, |
|
||||||
219, 133, 103, 57, 186, 228, 6, 88, 25, 71, 165, 251, 120, 38, 196, 154, |
|
||||||
101, 59, 217, 135, 4, 90, 184, 230, 167, 249, 27, 69, 198, 152, 122, 36, |
|
||||||
248, 166, 68, 26, 153, 199, 37, 123, 58, 100, 134, 216, 91, 5, 231, 185, |
|
||||||
140, 210, 48, 110, 237, 179, 81, 15, 78, 16, 242, 172, 47, 113, 147, 205, |
|
||||||
17, 79, 173, 243, 112, 46, 204, 146, 211, 141, 111, 49, 178, 236, 14, 80, |
|
||||||
175, 241, 19, 77, 206, 144, 114, 44, 109, 51, 209, 143, 12, 82, 176, 238, |
|
||||||
50, 108, 142, 208, 83, 13, 239, 177, 240, 174, 76, 18, 145, 207, 45, 115, |
|
||||||
202, 148, 118, 40, 171, 245, 23, 73, 8, 86, 180, 234, 105, 55, 213, 139, |
|
||||||
87, 9, 235, 181, 54, 104, 138, 212, 149, 203, 41, 119, 244, 170, 72, 22, |
|
||||||
233, 183, 85, 11, 136, 214, 52, 106, 43, 117, 151, 201, 74, 20, 246, 168, |
|
||||||
116, 42, 200, 150, 21, 75, 169, 247, 182, 232, 10, 84, 215, 137, 107, 53 |
|
||||||
}; |
|
||||||
|
|
||||||
public static byte Calculate(byte[] data, byte init = 0) |
|
||||||
{ |
|
||||||
byte result = init; |
|
||||||
for (var i = 0; i < data.Length; i++) |
|
||||||
{ |
|
||||||
result = CRC8_TABLE[result ^ data[i]]; |
|
||||||
} |
|
||||||
return result; |
|
||||||
} |
|
||||||
} |
|
||||||
#endregion |
|
||||||
|
|
||||||
#region CRC16 |
|
||||||
public static class Crc16_1 |
|
||||||
{ |
|
||||||
static Byte[] auchCRCHi = new Byte[] |
|
||||||
{ |
|
||||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, |
|
||||||
0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, |
|
||||||
0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, |
|
||||||
0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, |
|
||||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, |
|
||||||
0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, |
|
||||||
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, |
|
||||||
0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, |
|
||||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, |
|
||||||
0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, |
|
||||||
0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, |
|
||||||
0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, |
|
||||||
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, |
|
||||||
0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, |
|
||||||
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, |
|
||||||
0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, |
|
||||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, |
|
||||||
0x40 |
|
||||||
}; |
|
||||||
static Byte[] auchCRCLo = new Byte[] |
|
||||||
{ |
|
||||||
0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4, |
|
||||||
0x04, 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, |
|
||||||
0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, |
|
||||||
0x1D, 0x1C, 0xDC, 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3, |
|
||||||
0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32, 0x36, 0xF6, 0xF7, |
|
||||||
0x37, 0xF5, 0x35, 0x34, 0xF4, 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A, |
|
||||||
0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38, 0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA, 0xEE, |
|
||||||
0x2E, 0x2F, 0xEF, 0x2D, 0xED, 0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26, |
|
||||||
0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60, 0x61, 0xA1, 0x63, 0xA3, 0xA2, |
|
||||||
0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F, |
|
||||||
0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68, 0x78, 0xB8, 0xB9, 0x79, 0xBB, |
|
||||||
0x7B, 0x7A, 0xBA, 0xBE, 0x7E, 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5, |
|
||||||
0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, 0x70, 0xB0, 0x50, 0x90, 0x91, |
|
||||||
0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C, |
|
||||||
0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98, 0x88, |
|
||||||
0x48, 0x49, 0x89, 0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C, |
|
||||||
0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80, |
|
||||||
0x40 |
|
||||||
}; |
|
||||||
|
|
||||||
public static UInt16 CRC16(ref Byte[] d, UInt16 len) |
|
||||||
{ |
|
||||||
Byte crc_hi = 0xFF; |
|
||||||
Byte crc_lo = 0xFF; |
|
||||||
Byte j = 0; |
|
||||||
do |
|
||||||
{ |
|
||||||
Byte i = (Byte)(crc_hi ^ d[j++]); |
|
||||||
crc_hi = (Byte)(crc_lo ^ (Byte)auchCRCHi[i]); |
|
||||||
crc_lo = (Byte)(auchCRCLo[i]); |
|
||||||
} while (--len != 0); |
|
||||||
return (UInt16)((crc_hi << 8) | crc_lo); |
|
||||||
} |
|
||||||
} |
|
||||||
#endregion |
|
||||||
|
|
||||||
#region CRC32 |
|
||||||
public static class Crc32_1 |
|
||||||
{ |
|
||||||
private static readonly uint[] crcTable = new uint[256]; |
|
||||||
|
|
||||||
static Crc32_1() |
|
||||||
{ |
|
||||||
const uint polynomial = 0xDEADDEAD; |
|
||||||
for (uint i = 0; i < 256; i++) |
|
||||||
{ |
|
||||||
uint crc = i; |
|
||||||
for (int j = 0; j < 8; j++) |
|
||||||
{ |
|
||||||
if ((crc & 1) == 1) |
|
||||||
{ |
|
||||||
crc = (crc >> 1) ^ polynomial; |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
crc >>= 1; |
|
||||||
} |
|
||||||
} |
|
||||||
crcTable[i] = crc; |
|
||||||
} |
|
||||||
} |
|
||||||
public static uint Calculate(byte[] data) |
|
||||||
{ |
|
||||||
uint crc = 0xFFFFFFFF; |
|
||||||
|
|
||||||
foreach (byte b in data) |
|
||||||
{ |
|
||||||
byte tableIndex = (byte)(((crc) & 0xFF) ^ b); |
|
||||||
crc = crcTable[tableIndex] ^ (crc >> 8); |
|
||||||
} |
|
||||||
|
|
||||||
return ~crc; |
|
||||||
} |
|
||||||
} |
|
||||||
public class Crc32_2 : HashAlgorithm |
|
||||||
{ |
|
||||||
public const UInt32 DefaultPolynomial = 0xedb88320; |
|
||||||
public const UInt32 DefaultSeed = 0xffffffff; |
|
||||||
|
|
||||||
private UInt32 hash; |
|
||||||
private UInt32 seed; |
|
||||||
private UInt32[] table; |
|
||||||
private static UInt32[] defaultTable; |
|
||||||
|
|
||||||
public Crc32_2() |
|
||||||
{ |
|
||||||
table = InitializeTable(DefaultPolynomial); |
|
||||||
seed = DefaultSeed; |
|
||||||
Initialize(); |
|
||||||
} |
|
||||||
|
|
||||||
public Crc32_2(UInt32 polynomial, UInt32 seed) |
|
||||||
{ |
|
||||||
table = InitializeTable(polynomial); |
|
||||||
this.seed = seed; |
|
||||||
Initialize(); |
|
||||||
} |
|
||||||
|
|
||||||
public override void Initialize() |
|
||||||
{ |
|
||||||
hash = seed; |
|
||||||
} |
|
||||||
|
|
||||||
protected override void HashCore(byte[] buffer, int start, int length) |
|
||||||
{ |
|
||||||
hash = CalculateHash(table, hash, buffer, start, length); |
|
||||||
} |
|
||||||
|
|
||||||
protected override byte[] HashFinal() |
|
||||||
{ |
|
||||||
byte[] hashBuffer = UInt32ToBigEndianBytes(~hash); |
|
||||||
this.HashValue = hashBuffer; |
|
||||||
return hashBuffer; |
|
||||||
} |
|
||||||
|
|
||||||
public override int HashSize |
|
||||||
{ |
|
||||||
get { return 32; } |
|
||||||
} |
|
||||||
|
|
||||||
public static UInt32 Compute(byte[] buffer) |
|
||||||
{ |
|
||||||
return ~CalculateHash(InitializeTable(DefaultPolynomial), DefaultSeed, buffer, 0, buffer.Length); |
|
||||||
} |
|
||||||
|
|
||||||
public static UInt32 Compute(UInt32 seed, byte[] buffer) |
|
||||||
{ |
|
||||||
return ~CalculateHash(InitializeTable(DefaultPolynomial), seed, buffer, 0, buffer.Length); |
|
||||||
} |
|
||||||
|
|
||||||
public static UInt32 Compute(UInt32 polynomial, UInt32 seed, byte[] buffer) |
|
||||||
{ |
|
||||||
return ~CalculateHash(InitializeTable(polynomial), seed, buffer, 0, buffer.Length); |
|
||||||
} |
|
||||||
|
|
||||||
private static UInt32[] InitializeTable(UInt32 polynomial) |
|
||||||
{ |
|
||||||
if (polynomial == DefaultPolynomial && defaultTable != null) |
|
||||||
return defaultTable; |
|
||||||
|
|
||||||
UInt32[] createTable = new UInt32[256]; |
|
||||||
for (int i = 0; i < 256; i++) |
|
||||||
{ |
|
||||||
UInt32 entry = (UInt32)i; |
|
||||||
for (int j = 0; j < 8; j++) |
|
||||||
if ((entry & 1) == 1) |
|
||||||
entry = (entry >> 1) ^ polynomial; |
|
||||||
else |
|
||||||
entry = entry >> 1; |
|
||||||
createTable[i] = entry; |
|
||||||
} |
|
||||||
|
|
||||||
if (polynomial == DefaultPolynomial) |
|
||||||
defaultTable = createTable; |
|
||||||
|
|
||||||
return createTable; |
|
||||||
} |
|
||||||
|
|
||||||
private static UInt32 CalculateHash(UInt32[] table, UInt32 seed, byte[] buffer, int start, int size) |
|
||||||
{ |
|
||||||
UInt32 crc = seed; |
|
||||||
for (int i = start; i < size; i++) |
|
||||||
unchecked |
|
||||||
{ |
|
||||||
crc = (crc >> 8) ^ table[buffer[i] ^ crc & 0xff]; |
|
||||||
} |
|
||||||
return crc; |
|
||||||
} |
|
||||||
|
|
||||||
private byte[] UInt32ToBigEndianBytes(UInt32 x) |
|
||||||
{ |
|
||||||
return new byte[] { |
|
||||||
(byte)((x >> 24) & 0xff), |
|
||||||
(byte)((x >> 16) & 0xff), |
|
||||||
(byte)((x >> 8) & 0xff), |
|
||||||
(byte)(x & 0xff) |
|
||||||
}; |
|
||||||
} |
|
||||||
|
|
||||||
public string Get(string FilePath) |
|
||||||
{ |
|
||||||
Crc32_2 crc32 = new Crc32_2(); |
|
||||||
String hash = String.Empty; |
|
||||||
|
|
||||||
using (FileStream fs = File.Open(FilePath, FileMode.Open)) |
|
||||||
foreach (byte b in crc32.ComputeHash(fs)) hash += b.ToString("x2").ToLower(); |
|
||||||
|
|
||||||
return hash; |
|
||||||
} |
|
||||||
} |
|
||||||
public class Crc32_3 |
|
||||||
{ |
|
||||||
private readonly uint[] _table; |
|
||||||
private const uint Poly = 0xedb88320; |
|
||||||
|
|
||||||
private uint ComputeChecksum(IEnumerable<byte> bytes) |
|
||||||
{ |
|
||||||
var crc = 0xffffffff; |
|
||||||
foreach (var t in bytes) |
|
||||||
{ |
|
||||||
var index = (byte)((crc & 0xff) ^ t); |
|
||||||
crc = (crc >> 8) ^ _table[index]; |
|
||||||
} |
|
||||||
return ~crc; |
|
||||||
} |
|
||||||
|
|
||||||
public IEnumerable<byte> ComputeChecksumBytes(IEnumerable<byte> bytes) |
|
||||||
{ |
|
||||||
return BitConverter.GetBytes(ComputeChecksum(bytes)); |
|
||||||
} |
|
||||||
|
|
||||||
public Crc32_3() |
|
||||||
{ |
|
||||||
_table = new uint[256]; |
|
||||||
for (uint i = 0; i < _table.Length; ++i) |
|
||||||
{ |
|
||||||
var temp = i; |
|
||||||
for (var j = 8; j > 0; --j) |
|
||||||
if ((temp & 1) == 1) |
|
||||||
temp = (temp >> 1) ^ Poly; |
|
||||||
else |
|
||||||
temp >>= 1; |
|
||||||
_table[i] = temp; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
public class Crc32_4 |
|
||||||
{ |
|
||||||
byte[] GetCRC32(IEnumerable<byte> bytes) |
|
||||||
{ |
|
||||||
var crcTable = new uint[256]; |
|
||||||
uint crc; |
|
||||||
|
|
||||||
for (uint i = 0; i < 256; i++) |
|
||||||
{ |
|
||||||
crc = i; |
|
||||||
for (uint j = 0; j < 8; j++) |
|
||||||
crc = (crc & 1) != 0 ? (crc >> 1) ^ 0xEDB88320 : crc >> 1; |
|
||||||
|
|
||||||
crcTable[i] = crc; |
|
||||||
} |
|
||||||
|
|
||||||
crc = bytes.Aggregate(0xFFFFFFFF, (current, s) => crcTable[(current ^ s) & 0xFF] ^ (current >> 8)); |
|
||||||
|
|
||||||
crc ^= 0xFFFFFFFF; |
|
||||||
return BitConverter.GetBytes(crc); |
|
||||||
} |
|
||||||
} |
|
||||||
#endregion |
|
||||||
} |
|
||||||
@ -1,150 +0,0 @@ |
|||||||
using System; |
|
||||||
using System.Collections.Generic; |
|
||||||
using System.Linq; |
|
||||||
using System.Reflection; |
|
||||||
using System.Text; |
|
||||||
using System.Runtime.InteropServices; |
|
||||||
using System.Drawing; |
|
||||||
using System.Windows.Forms; |
|
||||||
using System.Windows.Forms.VisualStyles; |
|
||||||
using System.ComponentModel; |
|
||||||
using System.Drawing.Imaging; |
|
||||||
using System.Globalization; |
|
||||||
using static System.Net.Mime.MediaTypeNames; |
|
||||||
using System.Diagnostics; |
|
||||||
using System.Net.NetworkInformation; |
|
||||||
using System.Net; |
|
||||||
using System.Management; |
|
||||||
using System.IO.Ports; |
|
||||||
using System.IO; |
|
||||||
using System.Security.Cryptography; |
|
||||||
using System.Windows.Forms.Design; |
|
||||||
|
|
||||||
namespace UTIL |
|
||||||
{ |
|
||||||
#region Циклический буфер |
|
||||||
public class CircularBuffer<T> |
|
||||||
{ |
|
||||||
T[] _buffer; |
|
||||||
Int32 _head; |
|
||||||
Int32 _tail; |
|
||||||
Int32 _length; |
|
||||||
Int32 _bufferSize; |
|
||||||
Int32 _pos; |
|
||||||
Object _lock = new object(); |
|
||||||
public CircularBuffer(Int32 bufferSize) |
|
||||||
{ |
|
||||||
_buffer = new T[bufferSize]; |
|
||||||
_bufferSize = bufferSize; |
|
||||||
_head = bufferSize - 1; |
|
||||||
_tail = 0; |
|
||||||
_length = 0; |
|
||||||
} |
|
||||||
public Int32 Count |
|
||||||
{ |
|
||||||
get { return _length; } |
|
||||||
} |
|
||||||
public Int32 Head |
|
||||||
{ |
|
||||||
get { return _head; } |
|
||||||
} |
|
||||||
public Int32 Tail |
|
||||||
{ |
|
||||||
get { return _tail; } |
|
||||||
} |
|
||||||
public bool IsEmpty |
|
||||||
{ |
|
||||||
get { return _length == 0; } |
|
||||||
} |
|
||||||
public bool IsFull |
|
||||||
{ |
|
||||||
get { return _length == _bufferSize; } |
|
||||||
} |
|
||||||
public bool IsNoData |
|
||||||
{ |
|
||||||
get { return _tail + _pos >= _head; } |
|
||||||
} |
|
||||||
public T Dequeue() |
|
||||||
{ |
|
||||||
if (IsEmpty) throw new InvalidOperationException("Queue exhausted"); |
|
||||||
|
|
||||||
T dequeued = _buffer[_tail]; |
|
||||||
_tail = NextPosition(_tail); |
|
||||||
_length--; |
|
||||||
return dequeued; |
|
||||||
} |
|
||||||
public T Peek(int pos) |
|
||||||
{ |
|
||||||
_pos = pos; |
|
||||||
if (IsEmpty) throw new InvalidOperationException("Queue exhausted"); |
|
||||||
if (_tail + pos > _head) throw new InvalidOperationException("End data"); |
|
||||||
|
|
||||||
T dequeued = _buffer[_tail + pos]; |
|
||||||
return dequeued; |
|
||||||
} |
|
||||||
public T Peek() |
|
||||||
{ |
|
||||||
if (IsEmpty) throw new InvalidOperationException("Queue exhausted"); |
|
||||||
if (_tail > _head) throw new InvalidOperationException("End data"); |
|
||||||
T dequeued = _buffer[_tail]; |
|
||||||
return dequeued; |
|
||||||
} |
|
||||||
private int NextPosition(int position) |
|
||||||
{ |
|
||||||
return (position + 1) % _bufferSize; |
|
||||||
} |
|
||||||
public void Enqueue(T toAdd) |
|
||||||
{ |
|
||||||
_head = NextPosition(_head); |
|
||||||
_buffer[_head] = toAdd; |
|
||||||
if (IsFull) |
|
||||||
_tail = NextPosition(_tail); |
|
||||||
else |
|
||||||
_length++; |
|
||||||
} |
|
||||||
} |
|
||||||
public class CircularBuffer2<T> |
|
||||||
{ |
|
||||||
T[] _buffer; |
|
||||||
Int32 _head; |
|
||||||
Int32 _tail; |
|
||||||
Int32 _length; |
|
||||||
Int32 _bufferSize; |
|
||||||
Int32 _pos; |
|
||||||
Object _lock = new object(); |
|
||||||
public CircularBuffer2(Int32 bufferSize) |
|
||||||
{ |
|
||||||
_buffer = new T[bufferSize]; |
|
||||||
_bufferSize = bufferSize; |
|
||||||
_head = bufferSize - 1; |
|
||||||
_tail = 0; |
|
||||||
_length = 0; |
|
||||||
} |
|
||||||
public T Dequeue() |
|
||||||
{ |
|
||||||
T dequeued = _buffer[_tail]; |
|
||||||
_tail = (_tail + 1) % _bufferSize; |
|
||||||
_length--; |
|
||||||
return dequeued; |
|
||||||
} |
|
||||||
public T Peek() |
|
||||||
{ |
|
||||||
if (_length == 0) throw new InvalidOperationException("No data"); |
|
||||||
return _buffer[_tail]; |
|
||||||
} |
|
||||||
private int NextPosition(int position) |
|
||||||
{ |
|
||||||
return (position + 1) % _bufferSize; |
|
||||||
} |
|
||||||
public void Enqueue(T toAdd) |
|
||||||
{ |
|
||||||
_head = (_head + 1) % _bufferSize; |
|
||||||
_buffer[_head] = toAdd; |
|
||||||
if (_length == _bufferSize) |
|
||||||
_tail = (_tail + 1) % _bufferSize; |
|
||||||
else |
|
||||||
_length++; |
|
||||||
} |
|
||||||
} |
|
||||||
#endregion |
|
||||||
} |
|
||||||
@ -1,63 +0,0 @@ |
|||||||
using System.Drawing; |
|
||||||
using System.Windows.Forms; |
|
||||||
|
|
||||||
namespace UTIL |
|
||||||
{ |
|
||||||
#region Расширенные методы RichTextBox |
|
||||||
public static class RichTextBoxExtensions |
|
||||||
{ |
|
||||||
public static void AppendText(this RichTextBox box, string text, Color color) |
|
||||||
{ |
|
||||||
if (box.InvokeRequired) |
|
||||||
{ |
|
||||||
box.Invoke((MethodInvoker)(delegate |
|
||||||
{ |
|
||||||
box.SelectionStart = box.TextLength; |
|
||||||
box.SelectionLength = 0; |
|
||||||
box.SelectionColor = color; |
|
||||||
box.AppendText(text); |
|
||||||
box.SelectionColor = box.ForeColor; |
|
||||||
box.ScrollToCaret(); |
|
||||||
})); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
box.SelectionStart = box.TextLength; |
|
||||||
box.SelectionLength = 0; |
|
||||||
box.SelectionColor = color; |
|
||||||
box.AppendText(text); |
|
||||||
box.SelectionColor = box.ForeColor; |
|
||||||
box.ScrollToCaret(); |
|
||||||
} |
|
||||||
} |
|
||||||
public static void AppendText(this RichTextBox box, string text, Color bgcolor, Color fgcolor) |
|
||||||
{ |
|
||||||
if (box.InvokeRequired) |
|
||||||
{ |
|
||||||
box.Invoke((MethodInvoker)(delegate |
|
||||||
{ |
|
||||||
box.SelectionStart = box.TextLength; |
|
||||||
box.SelectionLength = 0; |
|
||||||
box.SelectionColor = fgcolor; |
|
||||||
box.SelectionBackColor = bgcolor; |
|
||||||
box.AppendText(text); |
|
||||||
box.SelectionColor = box.ForeColor; |
|
||||||
box.SelectionBackColor = box.BackColor; |
|
||||||
box.ScrollToCaret(); |
|
||||||
})); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
box.SelectionStart = box.TextLength; |
|
||||||
box.SelectionLength = 0; |
|
||||||
box.SelectionColor = fgcolor; |
|
||||||
box.SelectionBackColor = bgcolor; |
|
||||||
box.AppendText(text); |
|
||||||
box.SelectionColor = box.ForeColor; |
|
||||||
box.SelectionBackColor = box.BackColor; |
|
||||||
box.ScrollToCaret(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
#endregion |
|
||||||
} |
|
||||||
@ -1,171 +0,0 @@ |
|||||||
using System.Reflection; |
|
||||||
|
|
||||||
namespace UTIL |
|
||||||
{ |
|
||||||
#region Методы доступа к атрибутам сборки |
|
||||||
public static class ASMBL |
|
||||||
{ |
|
||||||
public static string AssemblyTitle |
|
||||||
{ |
|
||||||
get |
|
||||||
{ |
|
||||||
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false); |
|
||||||
if (attributes.Length > 0) |
|
||||||
{ |
|
||||||
AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0]; |
|
||||||
if (titleAttribute.Title != "") |
|
||||||
{ |
|
||||||
return titleAttribute.Title; |
|
||||||
} |
|
||||||
} |
|
||||||
return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase); |
|
||||||
} |
|
||||||
} |
|
||||||
public static string AssemblyVersion |
|
||||||
{ |
|
||||||
get |
|
||||||
{ |
|
||||||
return Assembly.GetExecutingAssembly().GetName().Version.ToString(); |
|
||||||
} |
|
||||||
} |
|
||||||
public static string AssemblyDescription |
|
||||||
{ |
|
||||||
get |
|
||||||
{ |
|
||||||
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false); |
|
||||||
if (attributes.Length == 0) |
|
||||||
{ |
|
||||||
return ""; |
|
||||||
} |
|
||||||
return ((AssemblyDescriptionAttribute)attributes[0]).Description; |
|
||||||
} |
|
||||||
} |
|
||||||
public static string AssemblyProduct |
|
||||||
{ |
|
||||||
get |
|
||||||
{ |
|
||||||
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false); |
|
||||||
if (attributes.Length == 0) |
|
||||||
{ |
|
||||||
return ""; |
|
||||||
} |
|
||||||
#if DEBUG |
|
||||||
return ((AssemblyProductAttribute)attributes[0]).Product + " Debug version"; |
|
||||||
#else |
|
||||||
return ((AssemblyProductAttribute)attributes[0]).Product + " Release version"; |
|
||||||
#endif |
|
||||||
} |
|
||||||
} |
|
||||||
public static string AssemblyCopyright |
|
||||||
{ |
|
||||||
get |
|
||||||
{ |
|
||||||
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); |
|
||||||
if (attributes.Length == 0) |
|
||||||
{ |
|
||||||
return ""; |
|
||||||
} |
|
||||||
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright; |
|
||||||
} |
|
||||||
} |
|
||||||
public static string AssemblyCompany |
|
||||||
{ |
|
||||||
get |
|
||||||
{ |
|
||||||
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false); |
|
||||||
if (attributes.Length == 0) |
|
||||||
{ |
|
||||||
return ""; |
|
||||||
} |
|
||||||
return ((AssemblyCompanyAttribute)attributes[0]).Company; |
|
||||||
} |
|
||||||
} |
|
||||||
public static string AssemblyConfiguration |
|
||||||
{ |
|
||||||
get |
|
||||||
{ |
|
||||||
#if DEBUG |
|
||||||
return "Debug version"; |
|
||||||
#else |
|
||||||
return "Release version"; |
|
||||||
#endif |
|
||||||
} |
|
||||||
} |
|
||||||
public static string[] AssemblyConf |
|
||||||
{ |
|
||||||
get |
|
||||||
{ |
|
||||||
string[] s = new string[11]; |
|
||||||
|
|
||||||
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyConfigurationAttribute), false); |
|
||||||
#if DEBUG |
|
||||||
s[0] = "Debug version"; |
|
||||||
#else |
|
||||||
s[0] = "Release version"; |
|
||||||
#endif |
|
||||||
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyAlgorithmIdAttribute), false); |
|
||||||
if (attributes.Length == 0) |
|
||||||
s[1] = "AssemblyAlgorithmId = "; |
|
||||||
else |
|
||||||
s[1] = "AssemblyAlgorithmId = " + ((AssemblyAlgorithmIdAttribute)attributes[0]).AlgorithmId; |
|
||||||
|
|
||||||
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false); |
|
||||||
if (attributes.Length == 0) |
|
||||||
s[2] = "AssemblyCompany = "; |
|
||||||
else |
|
||||||
s[2] = "AssemblyCompany = " + ((AssemblyCompanyAttribute)attributes[0]).Company; |
|
||||||
|
|
||||||
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); |
|
||||||
if (attributes.Length == 0) |
|
||||||
s[3] = "AssemblyCopyright = "; |
|
||||||
else |
|
||||||
s[3] = "AssemblyCopyright = " + ((AssemblyCopyrightAttribute)attributes[0]).Copyright; |
|
||||||
|
|
||||||
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false); |
|
||||||
if (attributes.Length == 0) |
|
||||||
s[4] = "AssemblyDescription = "; |
|
||||||
else |
|
||||||
s[4] = "AssemblyDescription = " + ((AssemblyDescriptionAttribute)attributes[0]).Description; |
|
||||||
|
|
||||||
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false); |
|
||||||
if (attributes.Length == 0) |
|
||||||
s[5] = "AssemblyFileVersion = "; |
|
||||||
else |
|
||||||
s[5] = "AssemblyFileVersion = " + ((AssemblyFileVersionAttribute)attributes[0]).Version; |
|
||||||
|
|
||||||
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false); |
|
||||||
if (attributes.Length == 0) |
|
||||||
s[6] = "AssemblyInformationalVersion = "; |
|
||||||
else |
|
||||||
s[6] = "AssemblyInformationalVersion = " + ((AssemblyInformationalVersionAttribute)attributes[0]).InformationalVersion; |
|
||||||
|
|
||||||
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false); |
|
||||||
if (attributes.Length == 0) |
|
||||||
s[7] = "AssemblyProduct = "; |
|
||||||
else |
|
||||||
s[7] = "AssemblyProduct = " + ((AssemblyProductAttribute)attributes[0]).Product; |
|
||||||
|
|
||||||
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false); |
|
||||||
if (attributes.Length == 0) |
|
||||||
s[8] = "AssemblyTitle = "; |
|
||||||
else |
|
||||||
s[8] = "AssemblyTitle = " + ((AssemblyTitleAttribute)attributes[0]).Title; |
|
||||||
|
|
||||||
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTrademarkAttribute), false); |
|
||||||
if (attributes.Length == 0) |
|
||||||
s[9] = "AssemblyTrademark = "; |
|
||||||
else |
|
||||||
s[9] = "AssemblyTrademark = " + ((AssemblyTrademarkAttribute)attributes[0]).Trademark; |
|
||||||
|
|
||||||
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyVersionAttribute), false); |
|
||||||
if (attributes.Length == 0) |
|
||||||
s[10] = "AssemblyVersion = "; |
|
||||||
else |
|
||||||
s[10] = "AssemblyVersion = " + ((AssemblyVersionAttribute)attributes[0]).Version; |
|
||||||
|
|
||||||
return s; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
#endregion |
|
||||||
} |
|
||||||
@ -1,106 +0,0 @@ |
|||||||
using System; |
|
||||||
using System.Collections.Generic; |
|
||||||
using System.Text; |
|
||||||
using System.Runtime.InteropServices; |
|
||||||
using System.IO; |
|
||||||
|
|
||||||
namespace UTIL |
|
||||||
{ |
|
||||||
#region Работа с INI файлами |
|
||||||
public class IniFile |
|
||||||
{ |
|
||||||
[DllImport("kernel32.dll")] |
|
||||||
private extern static int GetPrivateProfileString(String AppName, String KeyName, String Default, StringBuilder ReturnedString, UInt32 Size, String FileName); |
|
||||||
[DllImport("kernel32.dll")] |
|
||||||
private extern static int WritePrivateProfileString(String AppName, String KeyName, String Str, String FileName); |
|
||||||
public IniFile(string filename) |
|
||||||
{ |
|
||||||
IniFileName = filename; |
|
||||||
//if (!File.Exists(filename)) |
|
||||||
// File.Create(filename); |
|
||||||
IniFileName = new FileInfo(IniFileName).FullName.ToString(); |
|
||||||
} |
|
||||||
public String IniFileName |
|
||||||
{ |
|
||||||
get; |
|
||||||
set; |
|
||||||
} |
|
||||||
|
|
||||||
//Читаем ini-файл и возвращаем значение указного ключа из заданной секции. |
|
||||||
public string ReadINI(string Section, string Key) |
|
||||||
{ |
|
||||||
var RetVal = new StringBuilder(255); |
|
||||||
if (GetPrivateProfileString(Section, Key, "", RetVal, 255, IniFileName).ToString().Length > 0) |
|
||||||
return RetVal.ToString(); |
|
||||||
else |
|
||||||
return null; |
|
||||||
} |
|
||||||
//Записываем в ini-файл. Запись происходит в выбранную секцию в выбранный ключ. |
|
||||||
public void Write(string Section, string Key, string Value) |
|
||||||
{ |
|
||||||
WritePrivateProfileString(Section, Key, Value, IniFileName); |
|
||||||
} |
|
||||||
public void WriteINI(string Section, string Key, string Value) |
|
||||||
{ |
|
||||||
WritePrivateProfileString(Section, Key, Value, IniFileName); |
|
||||||
} |
|
||||||
|
|
||||||
//Удаляем ключ из выбранной секции. |
|
||||||
public void DeleteKey(string Key, string Section = null) |
|
||||||
{ |
|
||||||
Write(Section, Key, null); |
|
||||||
} |
|
||||||
//Удаляем выбранную секцию |
|
||||||
public void DeleteSection(string Section = null) |
|
||||||
{ |
|
||||||
Write(Section, null, null); |
|
||||||
} |
|
||||||
//Проверяем, есть ли такой ключ, в этой секции |
|
||||||
public bool KeyExists(string Key, string Section = null) |
|
||||||
{ |
|
||||||
return ReadINI(Section, Key).Length > 0; |
|
||||||
} |
|
||||||
|
|
||||||
public String GetString(String section, String key) |
|
||||||
{ |
|
||||||
StringBuilder s1 = new StringBuilder(255); |
|
||||||
s1.Append(ReadINI(section, key).ToString()); |
|
||||||
return s1.ToString(); |
|
||||||
} |
|
||||||
public Int64 GetInt(String section, String key) |
|
||||||
{ |
|
||||||
StringBuilder s1 = new StringBuilder(255); |
|
||||||
s1.Append(ReadINI(section, key).ToString()); |
|
||||||
return Int64.Parse(s1.ToString()); |
|
||||||
} |
|
||||||
public Boolean GetBool(String section, String key) |
|
||||||
{ |
|
||||||
StringBuilder s1 = new StringBuilder(255); |
|
||||||
s1.Append(ReadINI(section, key).ToString()); |
|
||||||
return Boolean.Parse(s1.ToString()); |
|
||||||
} |
|
||||||
public Double GetDouble(String section, String key) |
|
||||||
{ |
|
||||||
StringBuilder s1 = new StringBuilder(255); |
|
||||||
s1.Append(ReadINI(section, key).ToString()); |
|
||||||
return Double.Parse(s1.ToString()); |
|
||||||
} |
|
||||||
public void SetString(String section, String key, String val) |
|
||||||
{ |
|
||||||
Write(section, key, val); |
|
||||||
} |
|
||||||
public void SetInt(String section, String key, Int64 val) |
|
||||||
{ |
|
||||||
Write(section, key, val.ToString()); |
|
||||||
} |
|
||||||
public void SetDouble(String section, String key, Double val) |
|
||||||
{ |
|
||||||
Write(section, key, val.ToString()); |
|
||||||
} |
|
||||||
public void SetBool(String section, String key, Boolean val) |
|
||||||
{ |
|
||||||
Write(section, key, val.ToString()); |
|
||||||
} |
|
||||||
} |
|
||||||
#endregion |
|
||||||
} |
|
||||||
@ -1,132 +0,0 @@ |
|||||||
using System; |
|
||||||
/* |
|
||||||
using System.Collections.Generic; |
|
||||||
using System.Linq; |
|
||||||
using System.Reflection; |
|
||||||
using System.Text; |
|
||||||
using System.Runtime.InteropServices; |
|
||||||
using System.Drawing; |
|
||||||
using System.Windows.Forms; |
|
||||||
using System.Windows.Forms.VisualStyles; |
|
||||||
using System.ComponentModel; |
|
||||||
using System.Drawing.Imaging; |
|
||||||
using System.Globalization; |
|
||||||
using static System.Net.Mime.MediaTypeNames; |
|
||||||
using System.Diagnostics; |
|
||||||
using System.Net.NetworkInformation; |
|
||||||
using System.Net; |
|
||||||
using System.Management; |
|
||||||
using System.IO.Ports; |
|
||||||
using System.IO; |
|
||||||
using System.Security.Cryptography; |
|
||||||
using System.Windows.Forms.Design; |
|
||||||
*/ |
|
||||||
|
|
||||||
namespace UTIL |
|
||||||
{ |
|
||||||
#region Медианный фильтр |
|
||||||
public class GMedian<T> where T : IComparable<T> |
|
||||||
{ |
|
||||||
private T[] buf; |
|
||||||
byte _count = 0; |
|
||||||
UInt16 _num = 0; |
|
||||||
|
|
||||||
public GMedian(UInt16 num) |
|
||||||
{ |
|
||||||
buf = new T[num]; |
|
||||||
_count = 0; |
|
||||||
_num = num; |
|
||||||
} |
|
||||||
public T filtered(T newVal) |
|
||||||
{ |
|
||||||
buf[_count] = newVal; |
|
||||||
if ((_count < _num - 1) && (buf[_count].CompareTo(buf[_count + 1]) > 0)) |
|
||||||
{ |
|
||||||
for (int i = _count; i < _num - 1; i++) |
|
||||||
{ |
|
||||||
if (buf[i].CompareTo(buf[i + 1]) > 0) |
|
||||||
{ |
|
||||||
T buff = buf[i]; |
|
||||||
buf[i] = buf[i + 1]; |
|
||||||
buf[i + 1] = buff; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
if ((_count > 0) && (buf[_count - 1].CompareTo(buf[_count])) > 0) |
|
||||||
{ |
|
||||||
for (int i = _count; i > 0; i--) |
|
||||||
{ |
|
||||||
if (buf[i].CompareTo(buf[i - 1]) < 0) |
|
||||||
{ |
|
||||||
T buff = buf[i]; |
|
||||||
buf[i] = buf[i - 1]; |
|
||||||
buf[i - 1] = buff; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
if (++_count >= _num) _count = 0; |
|
||||||
return buf[_num / 2]; |
|
||||||
} |
|
||||||
} |
|
||||||
#endregion |
|
||||||
|
|
||||||
#region Медианный фильтр 2 |
|
||||||
public class GMedian3 |
|
||||||
{ |
|
||||||
public UInt16 filtered(UInt16 value) |
|
||||||
{ // возвращает фильтрованное значение |
|
||||||
bufUI16[_counter] = value; |
|
||||||
if (++_counter > 2) |
|
||||||
_counter = 0; |
|
||||||
return (Math.Max(bufUI16[0], bufUI16[1]) == Math.Max(bufUI16[1], bufUI16[2])) ? Math.Max(bufUI16[0], bufUI16[2]) : Math.Max(bufUI16[1], Math.Min(bufUI16[0], bufUI16[2])); |
|
||||||
} |
|
||||||
public Int16 filtered(Int16 value) |
|
||||||
{ // возвращает фильтрованное значение |
|
||||||
bufI16[_counter] = value; |
|
||||||
if (++_counter > 2) |
|
||||||
_counter = 0; |
|
||||||
return (Math.Max(bufI16[0], bufI16[1]) == Math.Max(bufI16[1], bufI16[2])) ? Math.Max(bufI16[0], bufI16[2]) : Math.Max(bufI16[1], Math.Min(bufI16[0], bufI16[2])); |
|
||||||
} |
|
||||||
public UInt32 filtered(UInt32 value) |
|
||||||
{ // возвращает фильтрованное значение |
|
||||||
bufUI32[_counter] = value; |
|
||||||
if (++_counter > 2) |
|
||||||
_counter = 0; |
|
||||||
return (Math.Max(bufUI32[0], bufUI32[1]) == Math.Max(bufUI32[1], bufUI32[2])) ? Math.Max(bufUI32[0], bufUI32[2]) : Math.Max(bufUI32[1], Math.Min(bufUI32[0], bufUI32[2])); |
|
||||||
} |
|
||||||
public Int32 filtered(Int32 value) |
|
||||||
{ // возвращает фильтрованное значение |
|
||||||
bufI32[_counter] = value; |
|
||||||
if (++_counter > 2) |
|
||||||
_counter = 0; |
|
||||||
return (Math.Max(bufI32[0], bufI32[1]) == Math.Max(bufI32[1], bufI32[2])) ? Math.Max(bufI32[0], bufI32[2]) : Math.Max(bufI32[1], Math.Min(bufI32[0], bufI32[2])); |
|
||||||
} |
|
||||||
public float filtered(float value) |
|
||||||
{ // возвращает фильтрованное значение |
|
||||||
buff[_counter] = value; |
|
||||||
if (++_counter > 2) |
|
||||||
_counter = 0; |
|
||||||
return (Math.Max(buff[0], buff[1]) == Math.Max(buff[1], buff[2])) ? Math.Max(buff[0], buff[2]) : Math.Max(buff[1], Math.Min(buff[0], buff[2])); |
|
||||||
} |
|
||||||
public Double filtered(Double value) |
|
||||||
{ // возвращает фильтрованное значение |
|
||||||
bufd[_counter] = value; |
|
||||||
if (++_counter > 2) |
|
||||||
_counter = 0; |
|
||||||
return (Math.Max(bufd[0], bufd[1]) == Math.Max(bufd[1], bufd[2])) ? Math.Max(bufd[0], bufd[2]) : Math.Max(bufd[1], Math.Min(bufd[0], bufd[2])); |
|
||||||
} |
|
||||||
|
|
||||||
UInt16[] bufUI16 = new UInt16[3]; |
|
||||||
Int16[] bufI16 = new Int16[3]; |
|
||||||
UInt32[] bufUI32 = new UInt32[3]; |
|
||||||
Int32[] bufI32 = new Int32[3]; |
|
||||||
Double[] bufd = new Double[3]; |
|
||||||
Single[] buff = new Single[3]; |
|
||||||
Byte _counter = 0; |
|
||||||
}; |
|
||||||
#endregion |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,253 +0,0 @@ |
|||||||
using System; |
|
||||||
using System.Drawing; |
|
||||||
using System.Windows.Forms; |
|
||||||
using System.ComponentModel; |
|
||||||
using System.Windows.Forms.Design; |
|
||||||
|
|
||||||
namespace UTIL |
|
||||||
{ |
|
||||||
#region Компоненты меню |
|
||||||
[System.ComponentModel.DesignerCategory("code")] |
|
||||||
[ToolStripItemDesignerAvailability( |
|
||||||
ToolStripItemDesignerAvailability.ContextMenuStrip | |
|
||||||
ToolStripItemDesignerAvailability.MenuStrip | |
|
||||||
ToolStripItemDesignerAvailability.StatusStrip | |
|
||||||
ToolStripItemDesignerAvailability.ToolStrip)] |
|
||||||
public partial class ToolStripTrackBar : ToolStripControlHost |
|
||||||
{ |
|
||||||
public ToolStripTrackBar() : base(CreateControlInstance()) |
|
||||||
{ |
|
||||||
} |
|
||||||
/// <summary> |
|
||||||
/// Create a strongly typed property called TrackBar - handy to prevent casting everywhere. |
|
||||||
/// </summary> |
|
||||||
public TrackBar TrackBar |
|
||||||
{ |
|
||||||
get |
|
||||||
{ |
|
||||||
return Control as TrackBar; |
|
||||||
} |
|
||||||
} |
|
||||||
/// <summary> |
|
||||||
/// Create the actual control, note this is static so it can be called from the |
|
||||||
/// constructor. |
|
||||||
/// |
|
||||||
/// </summary> |
|
||||||
/// <returns></returns> |
|
||||||
private static Control CreateControlInstance() |
|
||||||
{ |
|
||||||
TrackBar t = new TrackBar(); |
|
||||||
t.AutoSize = false; |
|
||||||
// Add other initialization code here. |
|
||||||
return t; |
|
||||||
} |
|
||||||
[DefaultValue(0)] |
|
||||||
public int Value |
|
||||||
{ |
|
||||||
get { return TrackBar.Value; } |
|
||||||
set { TrackBar.Value = value; } |
|
||||||
} |
|
||||||
/// <summary> |
|
||||||
/// Attach to events we want to re-wrap |
|
||||||
/// </summary> |
|
||||||
/// <param name="control"></param> |
|
||||||
[DefaultValue(0)] |
|
||||||
public int Minimum |
|
||||||
{ |
|
||||||
get { return TrackBar.Minimum; } |
|
||||||
set { TrackBar.Minimum = value; } |
|
||||||
} |
|
||||||
[DefaultValue(100)] |
|
||||||
public int Maximum |
|
||||||
{ |
|
||||||
get { return TrackBar.Maximum; } |
|
||||||
set { TrackBar.Maximum = value; } |
|
||||||
} |
|
||||||
[DefaultValue(10)] |
|
||||||
public int TickFrequency |
|
||||||
{ |
|
||||||
get { return TrackBar.TickFrequency; } |
|
||||||
set { TrackBar.TickFrequency = value; } |
|
||||||
} |
|
||||||
public TickStyle TickStyle |
|
||||||
{ |
|
||||||
get { return TrackBar.TickStyle; } |
|
||||||
set { TrackBar.TickStyle = value; } |
|
||||||
} |
|
||||||
protected override void OnSubscribeControlEvents(Control control) |
|
||||||
{ |
|
||||||
base.OnSubscribeControlEvents(control); |
|
||||||
TrackBar trackBar = control as TrackBar; |
|
||||||
trackBar.ValueChanged += new EventHandler(trackBar_ValueChanged); |
|
||||||
} |
|
||||||
/// <summary> |
|
||||||
/// Detach from events. |
|
||||||
/// </summary> |
|
||||||
/// <param name="control"></param> |
|
||||||
protected override void OnUnsubscribeControlEvents(Control control) |
|
||||||
{ |
|
||||||
base.OnUnsubscribeControlEvents(control); |
|
||||||
TrackBar trackBar = control as TrackBar; |
|
||||||
trackBar.ValueChanged -= new EventHandler(trackBar_ValueChanged); |
|
||||||
} |
|
||||||
/// <summary> |
|
||||||
/// Routing for event |
|
||||||
/// TrackBar.ValueChanged -> ToolStripTrackBar.ValueChanged |
|
||||||
/// </summary> |
|
||||||
/// <param name="sender"></param> |
|
||||||
/// <param name="e"></param> |
|
||||||
void trackBar_ValueChanged(object sender, EventArgs e) |
|
||||||
{ |
|
||||||
// when the trackbar value changes, fire an event. |
|
||||||
if (this.ValueChanged != null) |
|
||||||
{ |
|
||||||
ValueChanged(sender, e); |
|
||||||
} |
|
||||||
} |
|
||||||
// add an event that is subscribable from the designer. |
|
||||||
public event EventHandler ValueChanged; |
|
||||||
// set other defaults that are interesting |
|
||||||
protected override Size DefaultSize |
|
||||||
{ |
|
||||||
get |
|
||||||
{ |
|
||||||
return new Size(200, 16); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
[System.ComponentModel.DesignerCategory("code")] |
|
||||||
[ToolStripItemDesignerAvailability( |
|
||||||
ToolStripItemDesignerAvailability.ContextMenuStrip | |
|
||||||
ToolStripItemDesignerAvailability.MenuStrip | |
|
||||||
ToolStripItemDesignerAvailability.StatusStrip | |
|
||||||
ToolStripItemDesignerAvailability.ToolStrip)] |
|
||||||
public partial class ToolStripNumericUpDown : ToolStripControlHost |
|
||||||
{ |
|
||||||
public ToolStripNumericUpDown() : base(CreateControlInstance()) |
|
||||||
{ |
|
||||||
} |
|
||||||
/// <summary> |
|
||||||
/// Create a strongly typed property called TrackBar - handy to prevent casting everywhere. |
|
||||||
/// </summary> |
|
||||||
public NumericUpDown NumericUpDown |
|
||||||
{ |
|
||||||
get |
|
||||||
{ |
|
||||||
return Control as NumericUpDown; |
|
||||||
} |
|
||||||
} |
|
||||||
/// <summary> |
|
||||||
/// Create the actual control, note this is static so it can be called from the |
|
||||||
/// constructor. |
|
||||||
/// |
|
||||||
/// </summary> |
|
||||||
/// <returns></returns> |
|
||||||
private static Control CreateControlInstance() |
|
||||||
{ |
|
||||||
NumericUpDown t = new NumericUpDown(); |
|
||||||
t.AutoSize = false; |
|
||||||
// Add other initialization code here. |
|
||||||
return t; |
|
||||||
} |
|
||||||
[DefaultValue(0)] |
|
||||||
public int Value |
|
||||||
{ |
|
||||||
get { return (int)NumericUpDown.Value; } |
|
||||||
set { NumericUpDown.Value = value; } |
|
||||||
} |
|
||||||
/// <summary> |
|
||||||
/// Attach to events we want to re-wrap |
|
||||||
/// </summary> |
|
||||||
/// <param name="control"></param> |
|
||||||
[DefaultValue(0)] |
|
||||||
public int Minimum |
|
||||||
{ |
|
||||||
get { return (int)NumericUpDown.Minimum; } |
|
||||||
set { NumericUpDown.Minimum = value; } |
|
||||||
} |
|
||||||
[DefaultValue(100)] |
|
||||||
public int Maximum |
|
||||||
{ |
|
||||||
get { return (int)NumericUpDown.Maximum; } |
|
||||||
set { NumericUpDown.Maximum = value; } |
|
||||||
} |
|
||||||
[DefaultValue(10)] |
|
||||||
public int Increment |
|
||||||
{ |
|
||||||
get { return (int)NumericUpDown.Increment; } |
|
||||||
set { NumericUpDown.Increment = value; } |
|
||||||
} |
|
||||||
protected override void OnSubscribeControlEvents(Control control) |
|
||||||
{ |
|
||||||
base.OnSubscribeControlEvents(control); |
|
||||||
NumericUpDown t = control as NumericUpDown; |
|
||||||
t.ValueChanged += new EventHandler(updown_ValueChanged); |
|
||||||
} |
|
||||||
/// <summary> |
|
||||||
/// Detach from events. |
|
||||||
/// </summary> |
|
||||||
/// <param name="control"></param> |
|
||||||
protected override void OnUnsubscribeControlEvents(Control control) |
|
||||||
{ |
|
||||||
base.OnUnsubscribeControlEvents(control); |
|
||||||
NumericUpDown t = control as NumericUpDown; |
|
||||||
t.ValueChanged -= new EventHandler(updown_ValueChanged); |
|
||||||
} |
|
||||||
/// <summary> |
|
||||||
/// Routing for event |
|
||||||
/// TrackBar.ValueChanged -> ToolStripTrackBar.ValueChanged |
|
||||||
/// </summary> |
|
||||||
/// <param name="sender"></param> |
|
||||||
/// <param name="e"></param> |
|
||||||
void updown_ValueChanged(object sender, EventArgs e) |
|
||||||
{ |
|
||||||
// when the trackbar value changes, fire an event. |
|
||||||
if (this.ValueChanged != null) |
|
||||||
{ |
|
||||||
ValueChanged(sender, e); |
|
||||||
} |
|
||||||
} |
|
||||||
// add an event that is subscribable from the designer. |
|
||||||
public event EventHandler ValueChanged; |
|
||||||
// set other defaults that are interesting |
|
||||||
protected override Size DefaultSize |
|
||||||
{ |
|
||||||
get |
|
||||||
{ |
|
||||||
return new Size(200, 16); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
[System.ComponentModel.DesignerCategory("code")] |
|
||||||
[ToolStripItemDesignerAvailability( |
|
||||||
ToolStripItemDesignerAvailability.ContextMenuStrip | |
|
||||||
ToolStripItemDesignerAvailability.MenuStrip | |
|
||||||
ToolStripItemDesignerAvailability.StatusStrip | |
|
||||||
ToolStripItemDesignerAvailability.ToolStrip)] |
|
||||||
public partial class ToolStripLabel : ToolStripControlHost |
|
||||||
{ |
|
||||||
public ToolStripLabel() : base(CreateControlInstance()) |
|
||||||
{ |
|
||||||
} |
|
||||||
public Label Label |
|
||||||
{ |
|
||||||
get |
|
||||||
{ |
|
||||||
return Control as Label; |
|
||||||
} |
|
||||||
} |
|
||||||
private static Control CreateControlInstance() |
|
||||||
{ |
|
||||||
Label t = new Label(); |
|
||||||
t.AutoSize = false; |
|
||||||
t.Height = 15; |
|
||||||
// t.Width = 120; |
|
||||||
t.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; |
|
||||||
// Add other initialization code here. |
|
||||||
return t; |
|
||||||
} |
|
||||||
} |
|
||||||
#endregion |
|
||||||
} |
|
||||||
@ -1,128 +0,0 @@ |
|||||||
using System; |
|
||||||
using System.Collections.Generic; |
|
||||||
using System.Linq; |
|
||||||
using System.Windows.Forms; |
|
||||||
using System.Diagnostics; |
|
||||||
using System.Net.NetworkInformation; |
|
||||||
using System.Net; |
|
||||||
|
|
||||||
namespace UTIL |
|
||||||
{ |
|
||||||
#region Работа с сетевыми адаптерами |
|
||||||
public class SetNet |
|
||||||
{ |
|
||||||
public void setIP(string caption, string ipaddress, Boolean dhcp) |
|
||||||
{ |
|
||||||
// SetIP(EthStatic, "/c netsh interface ip set address \"" + EthName + "\" static " + Properties.Settings.Default.EthIPac + " " + Properties.Settings.Default.Subnet + " " + Properties.Settings.Default.EthDnsac + " & netsh interface ip set dns \"" + EthName + "\" static " + Properties.Settings.Default.EthDnsac); |
|
||||||
String arg = ""; |
|
||||||
if (!dhcp) |
|
||||||
{ |
|
||||||
arg = $"/c netsh interface ipv4 set address \"{caption}\" static \"{ipaddress}\" \"255.0.0.0\""; |
|
||||||
// arg = $"/c netsh interface ipv4 set address \"{caption}\" static \"{ipaddress}\" \"255.0.0.0\" \"192.168.1.2\" & netsh interface ipv4 set dns \"{caption}\" static \"192.168.1.2\""; |
|
||||||
// arg = $"/c netsh interface ip set address \"{caption}\" static \"{ipaddress}\" \"255.0.0.0\" \"192.168.1.2\" & netsh interface ip set dns \"{caption}\" static \"192.168.1.2\""; |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
arg = $"/c netsh interface ipv4 set address \"{caption}\" dhcp & netsh interface ipv4 set dns \"{caption}\" dhcp"; |
|
||||||
// arg = $"/c netsh interface ip set address \"{caption}\" dhcp & netsh interface ip set dns \"{caption}\" dhcp"; |
|
||||||
} |
|
||||||
|
|
||||||
try |
|
||||||
{ |
|
||||||
ProcessStartInfo psi = new ProcessStartInfo("cmd.exe"); |
|
||||||
psi.UseShellExecute = true; |
|
||||||
psi.WindowStyle = ProcessWindowStyle.Hidden; |
|
||||||
psi.Verb = "runas"; |
|
||||||
psi.Arguments = arg; |
|
||||||
Process ps = Process.Start(psi); |
|
||||||
ps.WaitForExit(); |
|
||||||
if (ps.HasExited) |
|
||||||
{ |
|
||||||
MessageBox.Show("Адрес изменен", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information); |
|
||||||
} |
|
||||||
} |
|
||||||
catch (Exception ex) |
|
||||||
{ |
|
||||||
MessageBox.Show(ex.Message); |
|
||||||
} |
|
||||||
} |
|
||||||
public List<String[]> getadapters() |
|
||||||
{ |
|
||||||
List<String[]> adapters = new List<string[]>(); |
|
||||||
String ip = ""; |
|
||||||
String dns = ""; |
|
||||||
String nic = ""; |
|
||||||
String gw = ""; |
|
||||||
String dhcp = ""; |
|
||||||
String ipen = ""; |
|
||||||
String sub = ""; |
|
||||||
|
|
||||||
string[] NwDesc = { "TAP", "VMware", "Windows", "Virtual", "WAN", "Microsoft", "NDIS", "Bluetooth" }; // Adapter types (Description) to be ommited |
|
||||||
foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces()) |
|
||||||
{ |
|
||||||
if (ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet && !NwDesc.Any(ni.Description.Contains)) // check for adapter type and its description |
|
||||||
{ |
|
||||||
nic = ni.Name; |
|
||||||
Console.WriteLine($"Name: {nic} # Desc: {ni.Description} # Mac: {ni.GetPhysicalAddress().ToString()} # Status: {ni.OperationalStatus}"); |
|
||||||
|
|
||||||
if (ni.GetIPProperties().UnicastAddresses.Count == 0) |
|
||||||
ip = ""; |
|
||||||
else |
|
||||||
{ |
|
||||||
foreach (UnicastIPAddressInformation ips in ni.GetIPProperties().UnicastAddresses) |
|
||||||
{ |
|
||||||
if (ips.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) |
|
||||||
{ |
|
||||||
ip = ips.Address.ToString(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
if (ni.GetIPProperties().DnsAddresses.Count == 0) |
|
||||||
dns = ""; |
|
||||||
else |
|
||||||
{ |
|
||||||
foreach (IPAddress dnsAdress in ni.GetIPProperties().DnsAddresses) |
|
||||||
{ |
|
||||||
if (dnsAdress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) |
|
||||||
{ |
|
||||||
dns = dnsAdress.ToString(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
if (ni.GetIPProperties().GatewayAddresses.Count == 0) |
|
||||||
gw = ""; |
|
||||||
else |
|
||||||
{ |
|
||||||
foreach (GatewayIPAddressInformation gwAdress in ni.GetIPProperties().GatewayAddresses) |
|
||||||
{ |
|
||||||
gw = gwAdress.Address.ToString(); |
|
||||||
} |
|
||||||
} |
|
||||||
if (ni.GetIPProperties().DhcpServerAddresses.Count == 0) |
|
||||||
dhcp = ""; |
|
||||||
else |
|
||||||
{ |
|
||||||
foreach (IPAddress dhcpAdress in ni.GetIPProperties().DhcpServerAddresses) |
|
||||||
{ |
|
||||||
dhcp = dhcpAdress.ToString(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
sub = "255.255.255.0"; |
|
||||||
if (ni.OperationalStatus.ToString() == "Down") |
|
||||||
ipen = "False"; |
|
||||||
else |
|
||||||
ipen = "True"; |
|
||||||
|
|
||||||
// Caption IPAddress IPSubnet DHCPEnabled IPEnabled |
|
||||||
Console.WriteLine($"{nic}-{ip}-{sub}-{dhcp}-{ipen}"); |
|
||||||
adapters.Add(new String[] { ni.Description, ip, sub, (dhcp == "" ? "False" : "True"), ipen, nic }); |
|
||||||
} |
|
||||||
} |
|
||||||
return adapters; |
|
||||||
} |
|
||||||
} |
|
||||||
#endregion |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,84 +0,0 @@ |
|||||||
using System; |
|
||||||
using System.Collections.Generic; |
|
||||||
using System.Linq; |
|
||||||
using System.Reflection; |
|
||||||
using System.Text; |
|
||||||
using System.Runtime.InteropServices; |
|
||||||
using System.Drawing; |
|
||||||
using System.Windows.Forms; |
|
||||||
using System.Windows.Forms.VisualStyles; |
|
||||||
using System.ComponentModel; |
|
||||||
using System.Drawing.Imaging; |
|
||||||
using System.Globalization; |
|
||||||
using static System.Net.Mime.MediaTypeNames; |
|
||||||
using System.Diagnostics; |
|
||||||
using System.Net.NetworkInformation; |
|
||||||
using System.Net; |
|
||||||
using System.Management; |
|
||||||
using System.IO.Ports; |
|
||||||
using System.IO; |
|
||||||
using System.Security.Cryptography; |
|
||||||
using System.Windows.Forms.Design; |
|
||||||
|
|
||||||
namespace UTIL |
|
||||||
{ |
|
||||||
#region Параметры командной строки |
|
||||||
public class ParParse |
|
||||||
{ |
|
||||||
private List<(bool, String, String, bool, String)> Pars = new List<(bool, string, string, bool, string)>(); |
|
||||||
private int _num = 0; |
|
||||||
private (bool, string, string, bool, string) nullitem = (false, null, null, false, null); |
|
||||||
public int NumofPar { get; } |
|
||||||
public (bool, string, string, bool, string) GetPar(UInt16 num) |
|
||||||
{ |
|
||||||
if (Pars[num].Item1) |
|
||||||
return Pars[num]; |
|
||||||
else |
|
||||||
return nullitem; |
|
||||||
} |
|
||||||
public (bool, string, string, bool, string) GetPar(String par) |
|
||||||
{ |
|
||||||
for (int j = 0; j < _num; j++) |
|
||||||
{ |
|
||||||
if ((par == Pars[j].Item2 || par == Pars[j].Item3) && Pars[j].Item1) |
|
||||||
return Pars[j]; |
|
||||||
} |
|
||||||
return nullitem; |
|
||||||
} |
|
||||||
public void AddPar(String shrt, String lng, Boolean key) |
|
||||||
{ |
|
||||||
Pars.Add((false, shrt, lng, key, "")); |
|
||||||
_num = Pars.Count; |
|
||||||
} |
|
||||||
public int Parse(String[] arg) |
|
||||||
{ |
|
||||||
int rez = 0; |
|
||||||
if (_num == 0) |
|
||||||
return -1; |
|
||||||
|
|
||||||
if (arg.Length == 0) |
|
||||||
return -1; |
|
||||||
|
|
||||||
for (int i = 0; i < arg.Length; i++) |
|
||||||
{ |
|
||||||
for (int j = 0; j < _num; j++) |
|
||||||
{ |
|
||||||
if (arg[i] == Pars[j].Item2 || arg[i] == Pars[j].Item3) |
|
||||||
{ |
|
||||||
(bool, string, string, bool, string) tmp = Pars[j]; |
|
||||||
if (Pars[j].Item4) |
|
||||||
{ |
|
||||||
tmp.Item5 = arg[i + 1]; |
|
||||||
} |
|
||||||
tmp.Item1 = true; |
|
||||||
Pars[j] = tmp; |
|
||||||
rez++; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
return rez; |
|
||||||
} |
|
||||||
} |
|
||||||
#endregion |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,87 +0,0 @@ |
|||||||
using System; |
|
||||||
using System.Collections.Generic; |
|
||||||
|
|
||||||
namespace UTIL |
|
||||||
{ |
|
||||||
public class ParParse |
|
||||||
{ |
|
||||||
private List<(bool, string, string, bool, string, string)> Pars = new List<(bool, string, string, bool, string, string)>(); |
|
||||||
private int _num = 0; |
|
||||||
private (bool, string, string, bool, string, string) nullitem = (false, null, null, false, null,null); |
|
||||||
public int NumofPar { get; } |
|
||||||
|
|
||||||
public ParParse() |
|
||||||
{ |
|
||||||
AddPar("-h","--help",false, "Использование"); |
|
||||||
} |
|
||||||
public (bool, string, string, bool, string, string) GetPar(UInt16 num) |
|
||||||
{ |
|
||||||
if (Pars[num].Item1) |
|
||||||
return Pars[num]; |
|
||||||
else |
|
||||||
return nullitem; |
|
||||||
} |
|
||||||
public (bool, string, string, bool, string, string) GetPar(string par) |
|
||||||
{ |
|
||||||
for (int j = 0; j < _num; j++) |
|
||||||
{ |
|
||||||
if ((par == Pars[j].Item2 || par == Pars[j].Item3) && Pars[j].Item1) |
|
||||||
return Pars[j]; |
|
||||||
} |
|
||||||
return nullitem; |
|
||||||
} |
|
||||||
public void AddPar(string shrt, string lng, Boolean key, string info) |
|
||||||
{ |
|
||||||
Pars.Add((false, shrt, lng, key, "", info)); |
|
||||||
_num = Pars.Count; |
|
||||||
} |
|
||||||
public int Parse(String[] arg) |
|
||||||
{ |
|
||||||
int rez = 0; |
|
||||||
if (_num == 0) |
|
||||||
return -1; |
|
||||||
|
|
||||||
if (arg.Length == 0) |
|
||||||
return -1; |
|
||||||
|
|
||||||
for (int i = 0; i < arg.Length; i++) |
|
||||||
{ |
|
||||||
for (int j = 0; j < _num; j++) |
|
||||||
{ |
|
||||||
if (arg[i] == Pars[j].Item2 || arg[i] == Pars[j].Item3) |
|
||||||
{ |
|
||||||
(bool, string, string, bool, string, string) tmp = Pars[j]; |
|
||||||
if (Pars[j].Item4) |
|
||||||
{ |
|
||||||
tmp.Item5 = arg[i + 1]; |
|
||||||
} |
|
||||||
tmp.Item1 = true; |
|
||||||
Pars[j] = tmp; |
|
||||||
rez++; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
return rez; |
|
||||||
} |
|
||||||
public void help() |
|
||||||
{ |
|
||||||
string s = ""; |
|
||||||
for (int i = 0; i < _num; i++) |
|
||||||
{ |
|
||||||
if (Pars[i].Item3 != "") |
|
||||||
s += $" {Pars[i].Item2}|{Pars[i].Item3}"; |
|
||||||
else |
|
||||||
s += $" {Pars[i].Item2}"; |
|
||||||
} |
|
||||||
Console.WriteLine($"Использование:\r\nGetVer3.exe{s}"); |
|
||||||
for (int i = 0; i < _num; i++) |
|
||||||
{ |
|
||||||
if (Pars[i].Item3 != "") |
|
||||||
Console.WriteLine($"{Pars[i].Item2} {Pars[i].Item3}\t{Pars[i].Item6}"); |
|
||||||
else |
|
||||||
Console.WriteLine($"{Pars[i].Item2}\t{Pars[i].Item6}"); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
Loading…
Reference in new issue