diff --git a/!Docs/Related Files/FileGrayscaleEffect.fx b/!Docs/Related Files/FileGrayscaleEffect.fx deleted file mode 100644 index 3a6d53b..0000000 --- a/!Docs/Related Files/FileGrayscaleEffect.fx +++ /dev/null @@ -1,8 +0,0 @@ -sampler2D implicitInput : register(s0); - -float4 main(float2 uv : TEXCOORD) : COLOR -{ - float4 color = tex2D(implicitInput, uv); - color.rgb = dot(color.rgb, float3(.3, .59, .11)); - return color; -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.Cryptography/AsymmetricContentEncryption.cs b/!Examples/BytecodeApi.Cryptography/AsymmetricContentEncryption.cs deleted file mode 100644 index 2800c48..0000000 --- a/!Examples/BytecodeApi.Cryptography/AsymmetricContentEncryption.cs +++ /dev/null @@ -1,42 +0,0 @@ -using BytecodeApi.Cryptography; -using BytecodeApi.Extensions; -using BytecodeApi.Text; -using System; -using System.Security.Cryptography; - -public static class Program -{ - [STAThread] - public static void Main() - { - // This class encrypts a randomly generated AES key with an RSA key and the data with the AES key. - // The AsymmetricEncryption class can only encrypt enough data to encrypt the AES key. - // AsymmetricContentEncryption is using AsymmetricEncryption internally. - - // Data to encrypt - byte[] data = new byte[100]; // Can be any size - for (int i = 0; i < data.Length; i++) data[i] = (byte)i; - - Console.WriteLine("byte[] data ="); - Console.WriteLine(Wording.FormatBinary(data)); - - // Generate public/private key pair - AsymmetricEncryption.GenerateKeyPair(out RSAParameters publicKey, out RSAParameters privateKey); - - // Encrypt using the public key - byte[] encrypted = AsymmetricContentEncryption.Encrypt(data, publicKey); - Console.WriteLine("byte[] encrypted ="); - Console.WriteLine(Wording.FormatBinary(encrypted)); - - // Decrypt using the private key - byte[] decrypted = AsymmetricContentEncryption.Decrypt(encrypted, privateKey); - - // Compare decrypted data with original data - if (!data.Compare(decrypted)) - { - throw new Exception("Decryted data does not match oridinal data!?"); - } - - Console.ReadKey(); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.Cryptography/AsymmetricEncryption.cs b/!Examples/BytecodeApi.Cryptography/AsymmetricEncryption.cs deleted file mode 100644 index cef99d9..0000000 --- a/!Examples/BytecodeApi.Cryptography/AsymmetricEncryption.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Security.Cryptography; - -public static class Program -{ - [STAThread] - public static void Main() - { - // The maximum amount of data that can be encrypted depends on the RSA key size. - // To encrypt any amount of data, use the AsymmetricContentEncryption class. - - // Data to encrypt - byte[] data = new byte[] { 1, 2, 3, 4, 5, 6, 7 }; - Console.WriteLine("byte[] data ="); - Console.WriteLine(Wording.FormatBinary(data)); - - // Generate public/private key pair - AsymmetricEncryption.GenerateKeyPair(out RSAParameters publicKey, out RSAParameters privateKey); - - // Encrypt using the public key - byte[] encrypted = AsymmetricEncryption.Encrypt(data, publicKey); - Console.WriteLine("byte[] encrypted ="); - Console.WriteLine(Wording.FormatBinary(encrypted)); - - // Decrypt using the private key - byte[] decrypted = AsymmetricEncryption.Decrypt(encrypted, privateKey); - - // Compare decrypted data with original data - if (!data.Compare(decrypted)) - { - throw new Exception("Decryted data does not match oridinal data!?"); - } - - Console.ReadKey(); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.Cryptography/AsymmetricKeyConvert.cs b/!Examples/BytecodeApi.Cryptography/AsymmetricKeyConvert.cs deleted file mode 100644 index 7bf0cac..0000000 --- a/!Examples/BytecodeApi.Cryptography/AsymmetricKeyConvert.cs +++ /dev/null @@ -1,30 +0,0 @@ -using BytecodeApi.Cryptography; -using BytecodeApi.Text; -using System; -using System.Security.Cryptography; - -public static class Program -{ - [STAThread] - public static void Main() - { - // Generate public/private key pair - AsymmetricEncryption.GenerateKeyPair(out RSAParameters publicKey, out RSAParameters privateKey); - - // Convert to DER key - byte[] der = AsymmetricKeyConvert.ToDer(publicKey, AsymmetricKeyType.Public); - Console.WriteLine("byte[] public_der ="); - Console.WriteLine(Wording.FormatBinary(der)); - - // Convert to PEM - string pem = AsymmetricKeyConvert.ToPem(privateKey, AsymmetricKeyType.Private); - Console.WriteLine("string private_pem ="); - Console.WriteLine(pem); - - Console.WriteLine("and so on..."); - - // This class converts between PEM and DER formats, and RSAParameters objects. - - Console.ReadKey(); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.Cryptography/ContentEncryption.cs b/!Examples/BytecodeApi.Cryptography/ContentEncryption.cs deleted file mode 100644 index cb3524d..0000000 --- a/!Examples/BytecodeApi.Cryptography/ContentEncryption.cs +++ /dev/null @@ -1,39 +0,0 @@ -using BytecodeApi.Cryptography; -using BytecodeApi.Extensions; -using BytecodeApi.Text; -using System; - -public static class Program -{ - [STAThread] - public static void Main() - { - // Data to encrypt - byte[] data = new byte[] { 1, 2, 3, 4, 5, 6, 7 }; - Console.WriteLine("byte[] data ="); - Console.WriteLine(Wording.FormatBinary(data)); - - // Password - const string password = "secret"; - Console.WriteLine("string password = " + password); - Console.WriteLine(); - - // Encrypt using the password and hash the password 1000 times - byte[] encrypted = ContentEncryption.Encrypt(data, password, 1000); - Console.WriteLine("byte[] encrypted ="); - Console.WriteLine(Wording.FormatBinary(encrypted)); - - // Decrypt data using the password - // The encrypted byte[] contains the IV and information about how many times the password was hashed. - // Therefore, only the password is needed. - byte[] decrypted = ContentEncryption.Decrypt(encrypted, password); - - // Compare decrypted data with original data - if (!data.Compare(decrypted)) - { - throw new Exception("Decryted data does not match oridinal data!?"); - } - - Console.ReadKey(); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.Cryptography/Encryption.cs b/!Examples/BytecodeApi.Cryptography/Encryption.cs deleted file mode 100644 index c7cd214..0000000 --- a/!Examples/BytecodeApi.Cryptography/Encryption.cs +++ /dev/null @@ -1,42 +0,0 @@ -using BytecodeApi.Cryptography; -using BytecodeApi.Extensions; -using BytecodeApi.Text; -using System; - -public static class Program -{ - [STAThread] - public static void Main() - { - // Data to encrypt - byte[] data = new byte[] { 1, 2, 3, 4, 5, 6, 7 }; - Console.WriteLine("byte[] data ="); - Console.WriteLine(Wording.FormatBinary(data)); - - // IV is a random value - byte[] iv = Encryption.GenerateIV(); - Console.WriteLine("byte[] iv ="); - Console.WriteLine(Wording.FormatBinary(iv)); - - // Encryption key is derived from a password, hashed 1000 times - byte[] key = Hashes.ComputeBytes("password", HashType.SHA256, 1000); - Console.WriteLine("byte[] key ="); - Console.WriteLine(Wording.FormatBinary(key)); - - // Encrypt a byte[] using a specified key and IV - byte[] encrypted = Encryption.Encrypt(data, iv, key); - Console.WriteLine("byte[] encrypted ="); - Console.WriteLine(Wording.FormatBinary(encrypted)); - - // Decrypt data using the same key and IV - byte[] decrypted = Encryption.Decrypt(encrypted, iv, key); - - // Compare decrypted data with original data - if (!data.Compare(decrypted)) - { - throw new Exception("Decryted data does not match oridinal data!?"); - } - - Console.ReadKey(); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.Cryptography/Hashes.cs b/!Examples/BytecodeApi.Cryptography/Hashes.cs deleted file mode 100644 index 41c0fc2..0000000 --- a/!Examples/BytecodeApi.Cryptography/Hashes.cs +++ /dev/null @@ -1,29 +0,0 @@ -using BytecodeApi.Cryptography; -using BytecodeApi.Text; -using System; - -public static class Program -{ - [STAThread] - public static void Main() - { - const string str = "Hello, World!"; - - // Convert str to UTF8 bytes, compute hash and return hexadecimal hash string - Console.WriteLine("Hash of \"" + str + "\" ="); - Console.WriteLine(Hashes.Compute(str, HashType.SHA256)); - Console.WriteLine(); - - // Convert str to UTF8 bytes, compute hash and return byte[] - Console.WriteLine("Hash bytes of \"" + str + "\" ="); - byte[] hash = Hashes.ComputeBytes(str, HashType.SHA256); - Console.WriteLine(Wording.FormatBinary(hash)); - - // Compute hash of a byte[] and return hash as byte[] - Console.WriteLine("Hash bytes of byte[] { 1, 2, 3 } ="); - hash = Hashes.ComputeBytes(new byte[] { 1, 2, 3 }, HashType.SHA256); - Console.WriteLine(Wording.FormatBinary(hash)); - - Console.ReadKey(); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.Data/Blob.cs b/!Examples/BytecodeApi.Data/Blob.cs deleted file mode 100644 index ea05edc..0000000 --- a/!Examples/BytecodeApi.Data/Blob.cs +++ /dev/null @@ -1,71 +0,0 @@ -using BytecodeApi.Data; -using BytecodeApi.Extensions; -using System; - -public static class Program -{ - [STAThread] - public static void Main() - { - // Blob: An object that is composed of a name and binary content - // BlobCollection: A collection of blobs - // BlobTree A hierarchical structure of nodes and blobs - - // Blobs are not dedicated to be read and written from/to the file system. - // However, this example also includes file & directory opetaions. - - // Create a blob - Blob blob = new Blob("name", new byte[100]); - blob.Tag = "some additional information"; // Any object can be associated with a blob to store additional information - - // Load blob from file - blob = Blob.FromFile(@"C:\Windows\win.ini"); - - // Load a directory into a blob tree: - // (the example requires a location that is present on every OS and it shouldn't be too large...) - BlobTree blobTree = BlobTree.FromDirectory(@"C:\Windows\System32\Sysprep"); - - // Iterate through a blob tree and write to console - Console.WriteLine("Iterate through BlobTree that was loaded from a directory:"); - PrintTree(blobTree.Root); - - // Find a node or blob by a backslash delimited path - BlobTreeNode node = blobTree.Root.FindNode(@"ActionFiles"); // equivalent of a directory - Blob specificBlob = blobTree.Root.FindBlob(@"ActionFiles\Cleanup.xml"); // equivalent of a file - - // Create a blob collection - BlobCollection blobs = new BlobCollection(); - blobs.Add(new Blob("blob1", new byte[100])); - blobs.Add(new Blob("blob2", new byte[100])); - blobs.Add(new Blob("blob3", new byte[100])); - - // Save to directory - // blobs.SaveToDirectory(@"C:\path\to\directory"); - - // Load blob collection from directory. Unlike a blob tree, this collection willy only contains the files directly in this directory. - // BlobCollection.FromDirectory(@"C:\path\to\directory"); - - // Load all files recursively into a flat blob collection - // BlobCollection.FromDirectory(@"C:\path\to\directory", true); - - Console.ReadKey(); - } - - private static void PrintTree(BlobTreeNode node, int consoleIndent = 0) - { - Console.Write(" ".Repeat(consoleIndent)); - Console.Write("* " + node.Name); - Console.WriteLine(" (" + node.ComputeSize() + ")"); // Compute the size of all blobs recursively - - foreach (BlobTreeNode childNode in node.Nodes) - { - PrintTree(childNode, consoleIndent + 1); - } - - foreach (Blob blob in node.Blobs) - { - Console.Write(" ".Repeat(consoleIndent + 1)); - Console.WriteLine("> " + blob.Name + " (" + blob.Content.Length + ")"); - } - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.Extensions/Extensions.cs b/!Examples/BytecodeApi.Extensions/Extensions.cs deleted file mode 100644 index 26d6349..0000000 --- a/!Examples/BytecodeApi.Extensions/Extensions.cs +++ /dev/null @@ -1,96 +0,0 @@ -using BytecodeApi.Extensions; -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; - -public static class Program -{ - [STAThread] - public static void Main() - { - // There are a lot of extensions. To not overwhelm the examples, here are just a few of them. - // Each method represents a category of examples - - IEnumerableExtensions(); - StringExtensions(); - DefaultTypeExtensions(); - ArrayAndCollectionExtensions(); - - // And many more... - // See documentation of the BytecodeApi.Extensions namespace - } - - private static void IEnumerableExtensions() - { - int[] array = new int[1000]; - for (int i = 0; i < array.Length; i++) array[i] = i; - - // Break down an array into chunks with a chunk size of 17 - foreach (IEnumerable chunk in array.Chunk(17)) - { - // ... - } - - // Concatenate string array with CRLF - string multiLineString = new[] { "line1", "line2", "line3" }.AsMultilineString(); - - // Random sort an array - int[] randomSorted = array.SortRandom().ToArray(); - - // Equivalent of .OrderBy(i => i) - int[] sorted = array.Sort().ToArray(); - - // See the documentation for a full overview of all extension methods - } - private static void StringExtensions() - { - // Trivial, but useful - especially for producing readable LINQ queries - - string str1 = "".ToNullIfEmpty(); // null - string str2 = " ".ToNullIfEmptyOrWhiteSpace(); // null - - string str3 = "hello, world".SubstringFrom(", "); // "world" - string str4 = "hello, world".SubstringFrom("xxx"); // "hello, world" - string str5 = "hello, world".SubstringUntil(", "); // "hello" - string str6 = "begin:hello".TrimStartString("begin"); // "hello" - string str7 = str6.EnsureStartsWith("begin:"); // "begin:hello" - byte[] bytes = "hello".ToAnsiBytes(); - - int int1 = "123".ToInt32OrDefault(); // 123 - int int2 = "abc".ToInt32OrDefault(); // 0 - int? int3 = "abc".ToInt32OrNull(); // null - DateTime? date = "2021-11-15".ToDateTime("yyyy-MM-dd"); - - // And for all other default datatypes... - } - private static void DefaultTypeExtensions() - { - int? int1 = 0.ToNullIfDefault(); // null - int? int2 = 123.ToNullIfDefault(); // 123 - - // Equivalent methods implemented for all other default datatypes... - - bool isUpper = 'A'.IsUpper(); // true - bool isHex = 'A'.IsHexadecimal(); // true - } - private static void ArrayAndCollectionExtensions() - { - // IsNullOrEmpty returns true for any of these cases - bool empty1 = ((int[])null).IsNullOrEmpty(); - bool empty2 = new int[0].IsNullOrEmpty(); - bool empty3 = new object[] { null, null }.IsNullOrEmpty(); - - bool equal = new byte[] { 1, 2, 3 }.Compare(new byte[] { 1, 2, 3 }); // true - - int index = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }.FindSequence(new byte[] { 4, 5 }); // 3 - - // BitArray extensions - BitArray bitArray = new BitArray(10); - - bool[] convertedBitArray = bitArray.ToBooleanArray(); - int countTrue = bitArray.CountTrue(); // 0 - - bitArray.SetRandomValues(true); // true = cryptographic random numbers - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.FileFormats.Csv/CsvDelimiterDetector.cs b/!Examples/BytecodeApi.FileFormats.Csv/CsvDelimiterDetector.cs deleted file mode 100644 index da72cd5..0000000 --- a/!Examples/BytecodeApi.FileFormats.Csv/CsvDelimiterDetector.cs +++ /dev/null @@ -1,59 +0,0 @@ -using BytecodeApi.Extensions; -using BytecodeApi.FileFormats.Csv; -using System; -using System.IO; - -public static class Program -{ - [STAThread] - public static void Main() - { - // CSV file as string - string csvString = @" -FirstName;LastName;Age -Addison;Smith;45 -Cassidy;Johnson;12 -Delaney;Williams;31 -Fallon;Brown;24 -Harlow;Jones;86 -"; - - // We quicky convert the CSV string to a Stream. - // It's easier to demonstrate than using a file on the disk. But typically, this would be a file. - using (MemoryStream memoryStream = new MemoryStream(csvString.ToUTF8Bytes())) - { - string delimiter = CsvDelimiterDetector.CreateDefault().FromStream(memoryStream); - - // ";" was detected - } - - // CsvDelimiterDetector.CreateDefault() has default settings. - // To customize, create a custom detector like this: - CsvDelimiterDetector customDelimiter = new CsvDelimiterDetector - ( - // Test these delimiters: - new[] { ";", ",", "|", "\t" }, - // The tested file must have at least 10 lines, otherwise the delimiter is considered indeterminable. - 10, - // A maximum of 100 lines is tested before the detector exits. The file may contain less, but no less than 10. - 100 - ); - - // Typically, the delimiter detector is implemented in CsvFile and CsvIterator per default. - // Unless the delimiter is clearly defined, it is recommended to to pass null to the "delimiter" parameter. - CsvFile csv = CsvFile.FromString(csvString); // no "delimiter" parameter was passed - - // When no delimiter is explicitly passed to the CsvFile.From*() method, the CsvFile.DelimiterDetector is used. - // This static field is initialized to CsvDelimiterDetector.CreateDefault() and can be changed globally. - - // When omitting the "delimiter" parameter from the CsvIterator.From*() method, the CsvIterator.DelimiterDetector is used. - // CsvFile.DelimiterDetector and CsvIterator.DelimiterDetector can be defined separately. - using (MemoryStream memoryStream = new MemoryStream(csvString.ToUTF8Bytes())) - { - foreach (CsvRow row in CsvIterator.FromStream(memoryStream)) - { - // ... - } - } - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.FileFormats.Csv/CsvFile.Save.cs b/!Examples/BytecodeApi.FileFormats.Csv/CsvFile.Save.cs deleted file mode 100644 index 4781fc0..0000000 --- a/!Examples/BytecodeApi.FileFormats.Csv/CsvFile.Save.cs +++ /dev/null @@ -1,37 +0,0 @@ -using BytecodeApi.Extensions; -using BytecodeApi.FileFormats.Csv; -using System; -using System.IO; -using System.Text; - -public static class Program -{ - [STAThread] - public static void Main() - { - // Create a CSV object, or use a CsvFile instance retrieved from the CsvFile.From*() method. - CsvFile csv = new CsvFile(); - - // Populate with data - csv.Delimiter = ";"; - csv.Headers = new[] { "FirstName", "LastName", "Age" }; - - csv.Rows.Add(new CsvRow("Addison", "Smith", "45")); - csv.Rows.Add(new CsvRow("Cassidy", "Johnson", "12")); - csv.Rows.Add(new CsvRow("Delaney", "Williams", "31")); - csv.Rows.Add(new CsvRow("Fallon", "Brown", "24")); - csv.Rows.Add(new CsvRow("Harlow", "Jones", "86")); - - // Write CSV to a file or stream. - using (MemoryStream memoryStream = new MemoryStream()) - { - csv.Save(memoryStream, false, Encoding.Default); - - // In this example, we want to print it to the console, so we need it as a string - string str = memoryStream.ToArray().ToUTF8String(); - Console.WriteLine(str); - } - - Console.ReadKey(); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.FileFormats.Csv/CsvFile.cs b/!Examples/BytecodeApi.FileFormats.Csv/CsvFile.cs deleted file mode 100644 index 4109969..0000000 --- a/!Examples/BytecodeApi.FileFormats.Csv/CsvFile.cs +++ /dev/null @@ -1,49 +0,0 @@ -using BytecodeApi.FileFormats.Csv; -using System; - -public static class Program -{ - [STAThread] - public static void Main() - { - // CSV file as string - string csvString = @" -FirstName;LastName;Age -Addison;Smith;45 -Cassidy;Johnson;12 -Delaney;Williams;31 -Fallon;Brown;24 -Harlow;Jones;86 -"; - - // Get CSV from a string that contains CSV data - CsvFile csv = CsvFile.FromString(csvString, true, ";"); - - // or - // CsvFile csv = CsvFile.FromFile(@"C:\path\to\data.csv", true, ";"); - // CsvFile csv = CsvFile.FromBinary(byte_array_containing_csv_file, true, ";"); - // CsvFile csv = CsvFile.FromStream(fileStream, true, ";") - - string[] headers = csv.Headers; // FirstName, LastName, Age - CsvRow row = csv.Rows[0]; // Addison, Smith, 45 - - // true, if CSV parsing failed in any row - bool errors = csv.HasErrors; - - // true, if all rows contain the same amount of columns - bool columnsCorrect = csv.IsColumnCountConsistent; - - // Check, if CSV has 3 columns in every row - bool columnsAsExpected = csv.CheckColumnCount(3); - - // Get column index of "LastName", case insensitive - // In case, columns are reordered - int lastNameIndex = csv.GetColumnIndex("LastName", true); - - // Get column content by name rather than by index - string lastName = csv.Rows[0][lastNameIndex].Value; - - // Omit the "delimiter" parameter to automatically detect the delimiter - CsvFile csvAutoDetectDelimiter = CsvFile.FromString(csvString, true); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.FileFormats.Csv/CsvIterator.cs b/!Examples/BytecodeApi.FileFormats.Csv/CsvIterator.cs deleted file mode 100644 index d6b1db3..0000000 --- a/!Examples/BytecodeApi.FileFormats.Csv/CsvIterator.cs +++ /dev/null @@ -1,43 +0,0 @@ -using BytecodeApi.Extensions; -using BytecodeApi.FileFormats.Csv; -using System; -using System.IO; - -public static class Program -{ - [STAThread] - public static void Main() - { - // CSV file as string - string csvString = @" -FirstName;LastName;Age -Addison;Smith;45 -Cassidy;Johnson;12 -Delaney;Williams;31 -Fallon;Brown;24 -Harlow;Jones;86 -"; - - // We quicky convert the CSV string to a Stream. - // It's easier to demonstrate than using a file on the disk. But typically, this would be a file. - using (MemoryStream memoryStream = new MemoryStream(csvString.ToUTF8Bytes())) - { - foreach (CsvRow row in CsvIterator.FromStream(memoryStream, true, ";")) // hasHeaderRow = true: The firt row is ignored - { - // Now we can iterate over the CSV file rather than loading it into a CsvFile object. - // This way, CSV files of any size can be processed. - } - } - - using (MemoryStream memoryStream = new MemoryStream(csvString.ToUTF8Bytes())) - { - // Omit the "delimiter" parameter to automatically detect the delimiter - foreach (CsvRow row in CsvIterator.FromStream(memoryStream, true)) - { - // ... - } - } - - // Use the CsvFile class for CSV files that are small enough to be stored in memory completely. - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.FileFormats.Ini/IniFile.Read.cs b/!Examples/BytecodeApi.FileFormats.Ini/IniFile.Read.cs deleted file mode 100644 index cfc3927..0000000 --- a/!Examples/BytecodeApi.FileFormats.Ini/IniFile.Read.cs +++ /dev/null @@ -1,109 +0,0 @@ -using BytecodeApi.Extensions; -using BytecodeApi.FileFormats.Ini; -using System; -using System.IO; -using System.Text; - -public static class Program -{ - [STAThread] - public static void Main() - { - string iniString = @" -global_prop1 = hello -global_prop2 = world - -[section1] -key1 = value1 -key2 = value2 - -[section2] -key3 = value3 - -; A section that occurs multiple times -[section2] -key4 = value 4 -"; - IniFile ini; - - // We quicky convert the INI string to a Stream. - // It's easier to demonstrate than using a file on the disk. But typically, this would be a file. - using (MemoryStream memoryStream = new MemoryStream(iniString.ToUTF8Bytes())) - { - // Custom parsing options (optional) - // Where the INI file has no clear specification, IniFileParsingOptions can be used to specify details about parsing - - IniFileParsingOptions parsingOptions = new IniFileParsingOptions - { - // true add to errors to IniFile.ErrorLines; false to throw an exception - IgnoreErrors = true, - - // Trim section names like [ my_section ] - TrimSectionNames = true, - // Trim property and value names (Set to false, if you need whitespaces at the beginning or end of property names/values) - TrimPropertyNames = true, - TrimPropertyValues = true, - - // Allow global properties (without a section declaration) - AllowGlobalProperties = true, - - // Allow section names that contain closing brackets like [my]section] - AllowSectionNameClosingBracket = true, - // Empty lines should typically be acceptable - AllowEmptyLines = true, - - // Typically properties are like "key = value" (equal sign), but some may use a colon instead - PropertyDelimiter = IniPropertyDelimiter.EqualSign, - - // Allow semicolon comments (;), but no number sign comments (#) - AllowSemicolonComments = true, - AllowNumberSignComments = false, - - // Merge properties of sections where the name is equal - DuplicateSectionNameBehavior = IniDuplicateSectionNameBehavior.Merge, - // Consider the name of two sections equal, regardless of case - DuplicateSectionNameIgnoreCase = true, - - // Duplicate property names are an error - DuplicatePropertyNameBehavior = IniDuplicatePropertyNameBehavior.Abort, - // Consider the name of two properties equal, regardless of case - DuplicatePropertyNameIgnoreCase = true - }; - - ini = IniFile.FromStream(memoryStream, Encoding.Default, parsingOptions); - } - - // "global properties" are properties without a section. They are on top of *any* section declaration - Console.WriteLine("Global properties without a section:"); - foreach (IniProperty globalProperty in ini.GlobalProperties.Properties) - { - Console.WriteLine("Name: " + globalProperty.Name + ", Value: " + globalProperty.Value); - } - Console.WriteLine(); - - // Loop through all sections and their properties - foreach (IniSection section in ini.Sections) - { - Console.WriteLine("Section: " + section.Name); - foreach (IniProperty property in section.Properties) - { - Console.WriteLine("Name: " + property.Name + ", Value: " + property.Value); - } - Console.WriteLine(); - } - - // Typically, reading an INI file means going through specific sections and properties, not just looping over it - if (ini.HasSection("section1", true)) // true = ignore case - { - IniSection section = ini.Sections["section1", true]; // true = ignore case - - // true = ignore case - // "nothing" = the default value, if the property does not exist - IniProperty property = section.Properties["key1", true, "nothing"]; - - string theValue = property.Value; - } - - Console.ReadKey(); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.FileFormats.Ini/IniFile.Write.cs b/!Examples/BytecodeApi.FileFormats.Ini/IniFile.Write.cs deleted file mode 100644 index 3fb2702..0000000 --- a/!Examples/BytecodeApi.FileFormats.Ini/IniFile.Write.cs +++ /dev/null @@ -1,56 +0,0 @@ -using BytecodeApi.Extensions; -using BytecodeApi.FileFormats.Ini; -using System; -using System.IO; -using System.Text; - -public static class Program -{ - [STAThread] - public static void Main() - { - IniFile ini = new IniFile(); - - // Set global properties (before any section declaration) - ini.GlobalProperties.Properties.Add("global_prop1", "hello"); - ini.GlobalProperties.Properties.Add("global_prop2", "world"); - - // Create a section - IniSection section1 = new IniSection("section1"); - section1.Properties.Add("key1", "value1"); - section1.Properties.Add("key1", "value2"); - ini.Sections.Add(section1); - - // Create another section - IniSection section2 = new IniSection("section2"); - section2.Properties.Add("key1", "value1"); - section2.Properties.Add("key1", "value2"); - ini.Sections.Add(section2); - - using (MemoryStream memoryStream = new MemoryStream()) - { - // Custom formatting options (optional) - IniFileFormattingOptions formattingOptions = new IniFileFormattingOptions - { - // property = value (equal sign) - PropertyDelimiter = IniPropertyDelimiter.EqualSign, - - // property{SPACE}=value - UseDelimiterSpaceBefore = true, - // property={SPACE}value - UseDelimiterSpaceAfter = true, - - // Line breaks between sections look nice - UseNewLineBetweenSections = true - }; - - ini.Save(memoryStream, Encoding.Default, formattingOptions); - - // Save it to a stream so we can display in console - string iniString = memoryStream.ToArray().ToUTF8String(); - Console.WriteLine(iniString); - } - - Console.ReadKey(); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.FileFormats.PE/PEImage.cs b/!Examples/BytecodeApi.FileFormats.PE/PEImage.cs deleted file mode 100644 index d3e4256..0000000 --- a/!Examples/BytecodeApi.FileFormats.PE/PEImage.cs +++ /dev/null @@ -1,41 +0,0 @@ -using BytecodeApi.FileFormats.PE; -using System; - -public static class Program -{ - [STAThread] - public static void Main() - { - // Read explorer.exe - PEImage pe = PEImage.FromFile(@"C:\Windows\explorer.exe"); - - // Boring stuff - ImageDosHeader dosHeader = pe.DosHeader; - byte[] dosStub = pe.DosStub; - - Console.WriteLine("explorer.exe"); - Console.WriteLine(); - - Console.WriteLine(pe.CoffHeader.NumberOfSections + " Sections:"); - foreach (ImageSection section in pe.Sections) - { - Console.Write(" * " + section.Header.Name.PadRight(15)); - Console.Write(" (raw data = " + section.Header.SizeOfRawData + " bytes, "); - Console.WriteLine("virtual size = " + section.Header.VirtualSize + " bytes)"); - } - Console.WriteLine(); - - if (pe.OptionalHeader is ImageOptionalHeader32) - { - Console.WriteLine("Executable is 32-bit"); - } - else if (pe.OptionalHeader is ImageOptionalHeader64) - { - Console.WriteLine("Executable is 64-bit"); - } - - // If you are dissecting PE files, you are probably familiar with the rest of the properties... - - Console.ReadKey(); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.FileIcons/FileIcon.cs b/!Examples/BytecodeApi.FileIcons/FileIcon.cs deleted file mode 100644 index b422c91..0000000 --- a/!Examples/BytecodeApi.FileIcons/FileIcon.cs +++ /dev/null @@ -1,32 +0,0 @@ -using BytecodeApi.FileIcons; -using System; -using System.Drawing; -using System.Windows.Media.Imaging; - -public static class Program -{ - [STAThread] - public static void Main() - { - // Get the file icon for the .csproj extension - FileIcon csprojIcon = KnownFileIcons.Csproj; - - // Get as bitmap - // Available sizes are: 16, 32, 48 - Bitmap csproj16 = csprojIcon.Icon16; - // or use the shortcut - csproj16 = KnownFileIcons.Csproj.Icon16; - - // Get the bitmap source to use in WPF projects - BitmapSource csproj16Source = csprojIcon.Icon16ImageSource; - // or use the shortcut (can be used with x:Static markup extension and directly bound in a WPF - csproj16Source = KnownFileIconImages.Csproj16; - - // Get the icon from an extension string - FileIcon exeIcon = FileIcon.FromExtension("exe"); - - // Special file icons - FileIcon directory = SpecialFileIcons.Directory; - FileIcon unknwonFileType = SpecialFileIcons.Unknown; - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.IO.Cli/Cli.cs b/!Examples/BytecodeApi.IO.Cli/Cli.cs deleted file mode 100644 index 64ecaf6..0000000 --- a/!Examples/BytecodeApi.IO.Cli/Cli.cs +++ /dev/null @@ -1,64 +0,0 @@ -using BytecodeApi.IO.Cli; -using System; -using System.Collections.ObjectModel; - -public static class Program -{ - [STAThread] - public static void Main(string[] args) - { - // Define what options are available: - OptionSet optionSet = new OptionSet("-", "--") // "-" is the prefix and "--" is the prefix for "alternative" options - .Add("command1") // Add option "-command1" - .Add(new[] { "h" }, new[] { "help" }); // "-h" or "--help" ("--h" or "-help" are invalid) - - // Option -^ Alternative -^ - - // Typical parsing of commandline: - ParsedOptionSet parsed1 = optionSet.Parse(args); - // or all arguments in one string, which is then split into a string[] internally - ParsedOptionSet parsed2 = optionSet.Parse(Environment.CommandLine); - - // Examples: - ParsedOptionSet parsed3 = optionSet.Parse("-h"); // Option with prefix - ParsedOptionSet parsed4 = optionSet.Parse("--help"); // Alternative option with alternative prefix - ParsedOptionSet parsed5 = optionSet.Parse("-command1 param1 param2 param3"); // Option with parameters - - // Parsing with validators: - // There are two methods for validation: - // - Custom handlers for validation failures - // - Throwing of an exception - - ParsedOptionSet parsed6 = optionSet - .Parse("-foo -command1 param1 param2") - // Validator that throws a CliException: - .Assert.OptionRequired("command1") - // Custom validator: - .Validate.MaximumValueCount("command1", 2, () => - { - Console.WriteLine("-command1 may only have two parameters!"); - }) - .Validate.FileExists("command1", () => - { - Console.WriteLine("All parameters of -command1 must point to existing files!"); - }); - // etc... - - // "Arguments" are what is not associated with any option - // In this example, "-foo", because it's not specified in our OptionSet - ReadOnlyCollection arguments = parsed6.Arguments; - - // Handle all known options: - parsed6 - .Handle("command1", parameters => - { - // Invoked, if "-command1" was specified - Console.WriteLine("-command1 executed"); - foreach (string p in parameters) Console.WriteLine(p); - }) - .Handle("h", parameters => - { - Console.WriteLine("Help"); - }); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.IO.FileSystem/CacheFile.cs b/!Examples/BytecodeApi.IO.FileSystem/CacheFile.cs deleted file mode 100644 index 02f772f..0000000 --- a/!Examples/BytecodeApi.IO.FileSystem/CacheFile.cs +++ /dev/null @@ -1,47 +0,0 @@ -using BytecodeApi.IO.FileSystem; -using System; -using System.IO; -using System.Threading; - -public static class Program -{ - [STAThread] - public static void Main() - { - // Define a file that contains cached contents. - // This is useful to store information that take long to retrieve and should - // be kept a specific period of time before retrieving again - - // Example: List of all postal codes and street names, retrieved from a WebService - // The list only changes occasionally and should be stored on the disk to increase application startup - - CacheFile cacheFile = CacheFile.CreateWithTimeout - ( - Path.Combine(Path.GetTempPath(), "cachefile_example"), - TimeSpan.FromSeconds(10), - CacheFile_UpdateCallback - ); - - while (true) - { - // Read the file. - - // When retrieving for the first time, the update callback is invoked - // After that, the callback update is only invoked, if the timeout of 10 seconds has passed - - byte[] file = cacheFile.ReadAllBytes(); - Console.WriteLine("File was read"); - Thread.Sleep(1000); - } - } - - private static void CacheFile_UpdateCallback(FileStream stream) - { - // This Callback is invoked when the cached file needs to be updated - - // Very complex function that retrieves a lot of data through a WebService: - stream.Write(new byte[100], 0, 100); - - Console.WriteLine("UpdateCallback was invoked; Cached file was written to"); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.IO.Http/HttpClient.cs b/!Examples/BytecodeApi.IO.Http/HttpClient.cs deleted file mode 100644 index 52788e2..0000000 --- a/!Examples/BytecodeApi.IO.Http/HttpClient.cs +++ /dev/null @@ -1,44 +0,0 @@ -using BytecodeApi.IO.Http; -using System; -using System.IO; - -public static class Program -{ - [STAThread] - public static void Main() - { - // Create HTTP client - HttpClient http = new HttpClient(true, "BytecodeApi.IO.Http.HttpClient"); - - // The HTTP client wraps common HTTP functionality (GET, POST, etc.) - // and returns the content as a string, byte[], Stream or file. - - // Note, that example.com does not actually support following examples. - - string example = http - .Get("https://example.com/") // Create GET request - .ReadString(); // Execute request and store result as string - - byte[] binaryExample = http - .Get("https://example.com/") - .AddQueryParameter("param", "value") // /?param=value - .ReadBytes(); // Read as byte[] - - http - .Post("https://example.com/login") // Posting into a form - .AddQueryParameter("param", "value") // /?param=value - .AddPostValue("username", "admin") - .AddPostValue("password", "123456") - .AddPostValue("btnOk", "1") - .ReadString(); - - // Using callback for progress calculation: - http - .Post("https://example.com/large_file.zip") - .ReadFile(Path.Combine(Path.GetTempPath(), "download_test"), (bytes, totalBytes) => - { - Console.WriteLine(bytes + " bytes read since the last callback."); - Console.WriteLine(totalBytes + " bytes read in total."); - }); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.IO.Interop/DynamicLibrary.cs b/!Examples/BytecodeApi.IO.Interop/DynamicLibrary.cs deleted file mode 100644 index 53e8007..0000000 --- a/!Examples/BytecodeApi.IO.Interop/DynamicLibrary.cs +++ /dev/null @@ -1,19 +0,0 @@ -using BytecodeApi.IO.Interop; -using System; -using System.Runtime.InteropServices; - -public static class Program -{ - [STAThread] - public static void Main() - { - // Dynamically create P/Invoke methods at runtime: - - int tickCount = new DynamicLibrary("kernel32.dll") - .GetFunction("GetTickCount", CallingConvention.StdCall, CharSet.Ansi) - .Call(); - - Console.WriteLine("GetTickCount() = " + tickCount); - Console.ReadKey(); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.IO.Interop/GlobalKeyboardHook.cs b/!Examples/BytecodeApi.IO.Interop/GlobalKeyboardHook.cs deleted file mode 100644 index 4d60ef1..0000000 --- a/!Examples/BytecodeApi.IO.Interop/GlobalKeyboardHook.cs +++ /dev/null @@ -1,26 +0,0 @@ -using BytecodeApi.IO.Interop; -using System; -using System.Windows.Forms; - -public static class Program -{ - [STAThread] - public static void Main() - { - // Global keyboard hook: - // Run application, switch to any other application and start typing - // Captured keystrokes are displayed in the console window - - using (GlobalKeyboardHook hook = new GlobalKeyboardHook()) - { - hook.KeyPressed += Hook_KeyPressed; - - Application.Run(); - } - } - - private static void Hook_KeyPressed(object sender, KeyboardHookEventArgs e) - { - Console.WriteLine("Char = " + (e.KeyChar == '\0' ? "NULL" : e.KeyChar.ToString()) + ", ScanCode = " + e.ScanCode + ", KeyCode = " + e.KeyCode); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.IO.SystemInfo/DeviceManager.cs b/!Examples/BytecodeApi.IO.SystemInfo/DeviceManager.cs deleted file mode 100644 index 6781e95..0000000 --- a/!Examples/BytecodeApi.IO.SystemInfo/DeviceManager.cs +++ /dev/null @@ -1,29 +0,0 @@ -using BytecodeApi.IO.SystemInfo; -using System; -using System.Collections.Generic; - -public static class Program -{ - [STAThread] - public static void Main() - { - // Enumerate over devices - - foreach (DeviceTypeInfo type in DeviceManager.Create().DeviceTypes) - { - Console.WriteLine(type.ClassName); - - foreach (DeviceInfo device in type.Devices) - { - Console.WriteLine(" " + device.Name); - - foreach (KeyValuePair attribute in device.Attributes) - { - Console.WriteLine(" " + attribute.Key + " = " + attribute.Value); - } - } - } - - Console.ReadKey(); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.IO.SystemInfo/HostsFile.cs b/!Examples/BytecodeApi.IO.SystemInfo/HostsFile.cs deleted file mode 100644 index 28f2133..0000000 --- a/!Examples/BytecodeApi.IO.SystemInfo/HostsFile.cs +++ /dev/null @@ -1,18 +0,0 @@ -using BytecodeApi.IO.SystemInfo; -using System; - -public static class Program -{ - [STAThread] - public static void Main() - { - // Read hosts file - - foreach (HostsFileEntry entry in HostsFile.GetEntries()) - { - Console.WriteLine(entry.IPAddress + " " + entry.HostName); - } - - Console.ReadKey(); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.IO.SystemInfo/InstalledSoftware.cs b/!Examples/BytecodeApi.IO.SystemInfo/InstalledSoftware.cs deleted file mode 100644 index 1751cc8..0000000 --- a/!Examples/BytecodeApi.IO.SystemInfo/InstalledSoftware.cs +++ /dev/null @@ -1,23 +0,0 @@ -using BytecodeApi.IO.SystemInfo; -using System; - -public static class Program -{ - [STAThread] - public static void Main() - { - // Get list of installed software - - foreach (InstalledSoftwareInfo software in InstalledSoftware.GetEntries()) - { - Console.WriteLine(software.Name); - Console.WriteLine(" Version: " + software.Version); - Console.WriteLine(" Publisher: " + software.Publisher); - Console.WriteLine(" Installed on: " + software.InstallDate); - Console.WriteLine(" Installation path: " + software.InstallPath); - Console.WriteLine(new string('-', 50)); - } - - Console.ReadKey(); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.IO.SystemInfo/TcpView.cs b/!Examples/BytecodeApi.IO.SystemInfo/TcpView.cs deleted file mode 100644 index d6a1caf..0000000 --- a/!Examples/BytecodeApi.IO.SystemInfo/TcpView.cs +++ /dev/null @@ -1,24 +0,0 @@ -using BytecodeApi.Extensions; -using BytecodeApi.IO.SystemInfo; -using System; - -public static class Program -{ - [STAThread] - public static void Main() - { - // Get list of TCP & UDP connections - - foreach (TcpViewEntry entry in new TcpView(true).GetEntries()) - { - Console.Write(entry.Protocol.GetDescription() + " "); - Console.Write(entry.LocalAddress + ":" + (entry.LocalProtocolName ?? entry.LocalPort.ToString())); - Console.Write(" - "); - Console.Write(entry.RemoteAddress + ":" + (entry.RemoteProtocolName ?? entry.RemotePort.ToString())); - Console.Write(" " + entry.TcpState); - Console.WriteLine(" PID: " + entry.ProcessId); - } - - Console.ReadKey(); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.IO.Wmi/Wmi.cs b/!Examples/BytecodeApi.IO.Wmi/Wmi.cs deleted file mode 100644 index c83f16f..0000000 --- a/!Examples/BytecodeApi.IO.Wmi/Wmi.cs +++ /dev/null @@ -1,23 +0,0 @@ -using BytecodeApi.Extensions; -using BytecodeApi.IO.Wmi; -using System; -using System.Linq; - -public static class Program -{ - [STAThread] - public static void Main() - { - // WMI query using the classes in the BytecodeApi.IO.Wmi namespace - - string[] installedAntiVirus = new WmiNamespace("SecurityCenter2") - .GetClass("AntiVirusProduct") - .GetObjects("displayName") - .Select(obj => obj.Properties["displayName"].GetValue()) - .Where(item => !item.IsNullOrEmpty()) - .ToArray(); - - // Note, that WMI is typically convenient to use, but lacks the performance that the native API offers. - // If a task can be achieved without the use of WMI, it is recommended to use the WinAPI instead. - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.IO/BinaryStream.cs b/!Examples/BytecodeApi.IO/BinaryStream.cs deleted file mode 100644 index e920998..0000000 --- a/!Examples/BytecodeApi.IO/BinaryStream.cs +++ /dev/null @@ -1,36 +0,0 @@ -using BytecodeApi.IO; -using System; -using System.IO; - -public static class Program -{ - [STAThread] - public static void Main() - { - using (MemoryStream memoryStream = new MemoryStream()) - { - // BinaryStream is a wrapper that uses both BinaryReader and BinaryWriter, based on whether the stream is readable/writable. - // This abstraction layer can read and write any default data type. - // If the stream does not support writing, the Write*() methods will throw an exception. - - using (BinaryStream binaryStream = new BinaryStream(memoryStream)) - { - // Write 3 integers - binaryStream.Write(123); - binaryStream.Write(456); - binaryStream.Write(789); - - // Seek to beginning and read 3 integers - binaryStream.BaseStream.Seek(0, SeekOrigin.Begin); - int a = binaryStream.ReadInt32(); // 123 - int b = binaryStream.ReadInt32(); // 456 - - // The BinaryStream keeps track of read & written byte count: - Console.WriteLine("Bytes read: " + binaryStream.BytesRead); - Console.WriteLine("Bytes written: " + binaryStream.BytesWritten); - } - } - - Console.ReadKey(); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.IO/Compression.cs b/!Examples/BytecodeApi.IO/Compression.cs deleted file mode 100644 index e61e85b..0000000 --- a/!Examples/BytecodeApi.IO/Compression.cs +++ /dev/null @@ -1,31 +0,0 @@ -using BytecodeApi.Extensions; -using BytecodeApi.IO; -using BytecodeApi.Text; -using System; - -public static class Program -{ - [STAThread] - public static void Main() - { - // Data to compress - byte[] data = new byte[100]; - Console.WriteLine("byte[] data ="); - Console.WriteLine(Wording.FormatBinary(data)); - - // Compress data using GZip - byte[] compressed = Compression.Compress(data); - Console.WriteLine("byte[] compressed ="); - Console.WriteLine(Wording.FormatBinary(compressed)); - - byte[] decompressed = Compression.Decompress(compressed); - - // Compare decompressed data with original data - if (!data.Compare(decompressed)) - { - throw new Exception("Decompressed data does not match oridinal data!?"); - } - - Console.ReadKey(); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.IO/ProcessEx.cs b/!Examples/BytecodeApi.IO/ProcessEx.cs deleted file mode 100644 index f25c759..0000000 --- a/!Examples/BytecodeApi.IO/ProcessEx.cs +++ /dev/null @@ -1,25 +0,0 @@ -using BytecodeApi.IO; -using System; -using System.Diagnostics; - -public static class Program -{ - [STAThread] - public static void Main() - { - // Start process and read console output - Console.WriteLine("Reading console output of inconfig.exe:"); - Console.WriteLine(); - Console.WriteLine(ProcessEx.ReadProcessOutput("ipconfig.exe")); - - // Start process, wait for it to exit and retrieve the exit code - int exitCode = ProcessEx.Execute("net.exe"); - // exit code is "1", because net.exe expects arguments. - - // Start notepad.exe with low integrity level (sandbox) - // Notepad cannot save to the disk, because it has no permission. - Process sandboxedProcess = ProcessEx.StartWithIntegrity(@"notepad.exe", ProcessIntegrityLevel.Low); - - Console.ReadKey(); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.IO/ZipCompression.cs b/!Examples/BytecodeApi.IO/ZipCompression.cs deleted file mode 100644 index f1fcffa..0000000 --- a/!Examples/BytecodeApi.IO/ZipCompression.cs +++ /dev/null @@ -1,26 +0,0 @@ -using BytecodeApi.Data; -using BytecodeApi.IO; -using System; - -public static class Program -{ - [STAThread] - public static void Main() - { - // ZipCompression can be used to create ZIP files from collections or a tree of blobs. - // The result can be stored in byte[] or directly written into a file or Stream. - - // In this example, we create a collection of blobs. ZipCompression also accepts BlobTree objects. - BlobCollection blobs = new BlobCollection(); - blobs.Add(new Blob("file1.txt", new byte[1000])); - blobs.Add(new Blob("file2.txt", new byte[2000])); - - // The result of compression is a ZIP file: - // The hierarchy of a BlobTree is mapped to directories and files. - byte[] zipFile = ZipCompression.Compress(blobs); - - // Decompress a ZIP file into a BlobTree. - // This ZIP file does not need to be created by the ZipCompression class. Any ZIP file can be decompressed into a BlobTree. - BlobTree decompressed = ZipCompression.Decompress(zipFile); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.Mathematics/ByteSize.cs b/!Examples/BytecodeApi.Mathematics/ByteSize.cs deleted file mode 100644 index ca77df3..0000000 --- a/!Examples/BytecodeApi.Mathematics/ByteSize.cs +++ /dev/null @@ -1,36 +0,0 @@ -using BytecodeApi.Mathematics; -using System; - -public static class Program -{ - [STAThread] - public static void Main() - { - // The ByteSize struct represent a size, in bytes. - // There are also WPF converters to display ByteSize values in the UI. - - ByteSize a = 10000000; // 10 million bytes - - // Format automatically - Console.WriteLine(a.Format()); - - // Format with specific unit - Console.WriteLine(a.Format(ByteSizeUnit.KiloByte)); - - // Format with 3 decimals - Console.WriteLine(a.Format(ByteSizeUnit.KiloByte, 3)); - - // Use thousands separator, because the unit (KiloByte) results in a number larger than 1000 - Console.WriteLine(a.Format(ByteSizeUnit.KiloByte, 3, false, true)); - - // Get megabytes as double value - double megaBytes = a.MegaBytes; - - // Cast back to long value - long bytes = (long)a; - // or - bytes = a.Bytes; - - Console.ReadKey(); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.Text/QuotedString.cs b/!Examples/BytecodeApi.Text/QuotedString.cs deleted file mode 100644 index a61cf95..0000000 --- a/!Examples/BytecodeApi.Text/QuotedString.cs +++ /dev/null @@ -1,17 +0,0 @@ -using BytecodeApi.Text; -using System; - -public static class Program -{ - [STAThread] - public static void Main() - { - // QuotedString is a representation of a string that is quoted and escaped. - QuotedString str = "Hello, \"world\""; - - Console.WriteLine("String: " + str.OriginalString); - Console.WriteLine("Quoted: " + str.ToString()); - Console.WriteLine("Verbatim: " + str.ToVerbatimString()); - Console.ReadKey(); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.Text/SentenceGenerator.cs b/!Examples/BytecodeApi.Text/SentenceGenerator.cs deleted file mode 100644 index 0c0f52b..0000000 --- a/!Examples/BytecodeApi.Text/SentenceGenerator.cs +++ /dev/null @@ -1,28 +0,0 @@ -using BytecodeApi.Text; -using System; - -public static class Program -{ - [STAThread] - public static void Main() - { - SentenceGenerator sentenceGenerator = new SentenceGenerator - { - MinWords = 3, // Sentence has between 3 and 10 words - MaxWords = 10, - CommaChance = .1, // 10 % of words have a "," behind them - FinishPunctuation = "...?!".ToCharArray() // 60 % ".", 20 % "?" and 20 % "!" - }; - - // SentenceGenerator is injected with a WordGenerator. - //sentenceGenerator.WordGenerator = ... - - // Generate some sentences - for (int i = 0; i < 10; i++) - { - Console.WriteLine(sentenceGenerator.Generate()); - } - - Console.ReadKey(); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.Text/WordGenerator.cs b/!Examples/BytecodeApi.Text/WordGenerator.cs deleted file mode 100644 index 1647884..0000000 --- a/!Examples/BytecodeApi.Text/WordGenerator.cs +++ /dev/null @@ -1,26 +0,0 @@ -using BytecodeApi; -using BytecodeApi.Text; -using System; - -public static class Program -{ - [STAThread] - public static void Main() - { - WordGenerator wordGenerator = new WordGenerator - { - MinLength = 4, // The word has between 4 and 9 characters - MaxLength = 9, - DoubleConsonantChance = .1, // 10 % chance of a double consonant (bb, cc, dd, ..) - DoubleVovelChance = .3 // 30 % chance of a double vovel (aa, ii, oo, ...) - }; - - // Generate some words - for (int i = 0; i < 10; i++) - { - Console.WriteLine(wordGenerator.Generate(StringCasing.CamelCase)); - } - - Console.ReadKey(); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi.Text/Wording.cs b/!Examples/BytecodeApi.Text/Wording.cs deleted file mode 100644 index 470279f..0000000 --- a/!Examples/BytecodeApi.Text/Wording.cs +++ /dev/null @@ -1,29 +0,0 @@ -using BytecodeApi.Extensions; -using BytecodeApi.Mathematics; -using BytecodeApi.Text; -using System; - -public static class Program -{ - [STAThread] - public static void Main() - { - // The Wording class manipulates strings in a linguistic fashion to create readable objects. - - Console.WriteLine("Formatted binary output:"); - Console.WriteLine(Wording.FormatBinary(MathEx.Random.NextBytes(50))); - - Console.WriteLine("Join strings, but use 'and' as last separator:"); - Console.WriteLine(Wording.JoinStrings(", ", " and ", "Apples", "Pears", "Bananas")); - Console.WriteLine(); - - Console.WriteLine("Formatted timespan:"); - Console.WriteLine(Wording.FormatTimeSpan(new TimeSpan(2, 30, 11))); // To include seconds, specify the maxElements parameter - Console.WriteLine(); - - Console.WriteLine("Wrapping at 50 characters, without overflow:"); - Console.WriteLine(); - Console.WriteLine(Wording.WrapText(TextResources.LoremIpsum, 50, false)); - Console.WriteLine(); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi/ApplicationBase.cs b/!Examples/BytecodeApi/ApplicationBase.cs deleted file mode 100644 index a95a318..0000000 --- a/!Examples/BytecodeApi/ApplicationBase.cs +++ /dev/null @@ -1,49 +0,0 @@ -using BytecodeApi; -using BytecodeApi.Extensions; -using BytecodeApi.Mathematics; -using System; -using System.Linq; - -public static class Program -{ - [STAThread] - public static void Main() - { - Console.WriteLine("ApplicationBase.Path = " + ApplicationBase.Path); - Console.WriteLine("ApplicationBase.FileName = " + ApplicationBase.FileName); - Console.WriteLine("ApplicationBase.Version = " + ApplicationBase.Version); - Console.WriteLine("ApplicationBase.DebugMode = " + ApplicationBase.DebugMode); - Console.WriteLine(); - - Console.WriteLine("ApplicationBase.Process.Id = " + ApplicationBase.Process.Id); - Console.WriteLine("ApplicationBase.Process.SessionId = " + ApplicationBase.Process.SessionId); - Console.WriteLine("ApplicationBase.Process.IntegrityLevel = " + ApplicationBase.Process.IntegrityLevel); - Console.WriteLine("ApplicationBase.Process.IsElevated = " + ApplicationBase.Process.IsElevated); - Console.WriteLine("ApplicationBase.Process.ElevationType = " + ApplicationBase.Process.ElevationType); - Console.WriteLine("ApplicationBase.Process.Memory = " + new ByteSize(ApplicationBase.Process.Memory).Format()); - Console.WriteLine("ApplicationBase.Process.FrameworkVersion = " + ApplicationBase.Process.FrameworkVersion); - Console.WriteLine(); - - Console.WriteLine("ApplicationBase.Session.CurrentUser = " + ApplicationBase.Session.CurrentUser); - Console.WriteLine("ApplicationBase.Session.CurrentUserShort = " + ApplicationBase.Session.CurrentUserShort); - Console.WriteLine("ApplicationBase.Session.DomainName = " + ApplicationBase.Session.DomainName); - Console.WriteLine("ApplicationBase.Session.Workgroup = " + ApplicationBase.Session.Workgroup); - Console.WriteLine("ApplicationBase.Session.Dpi = " + ApplicationBase.Session.Dpi.Width + "x" + ApplicationBase.Session.Dpi.Height); - Console.WriteLine("ApplicationBase.Session.IsRdp = " + ApplicationBase.Session.IsRdp); - Console.WriteLine(); - - Console.WriteLine("ApplicationBase.OperatingSystem.Name = " + ApplicationBase.OperatingSystem.Name); - Console.WriteLine("ApplicationBase.OperatingSystem.InstallDate = " + ApplicationBase.OperatingSystem.InstallDate); - Console.WriteLine("ApplicationBase.OperatingSystem.InstalledAntiVirusSoftware = " + ApplicationBase.OperatingSystem.InstalledAntiVirusSoftware.AsString(", ")); - Console.WriteLine("ApplicationBase.OperatingSystem.DefaultBrowser = " + ApplicationBase.OperatingSystem.DefaultBrowser); - Console.WriteLine("ApplicationBase.OperatingSystem.FrameworkVersionNumber = " + ApplicationBase.OperatingSystem.FrameworkVersionNumber); - Console.WriteLine("ApplicationBase.OperatingSystem.FrameworkVersionName = " + ApplicationBase.OperatingSystem.FrameworkVersionName); - Console.WriteLine(); - - Console.WriteLine("ApplicationBase.Hardware.ProcessorNames = " + ApplicationBase.Hardware.ProcessorNames.Distinct().AsString(", ")); - Console.WriteLine("ApplicationBase.Hardware.Memory = " + new ByteSize(ApplicationBase.Hardware.Memory ?? 0).Format()); - Console.WriteLine("ApplicationBase.Hardware.VideoControllerName = " + ApplicationBase.Hardware.VideoControllerName); - - Console.ReadKey(); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi/CSharp.cs b/!Examples/BytecodeApi/CSharp.cs deleted file mode 100644 index 9b651db..0000000 --- a/!Examples/BytecodeApi/CSharp.cs +++ /dev/null @@ -1,58 +0,0 @@ -using BytecodeApi; -using BytecodeApi.Mathematics; -using System; - -public static class Program -{ - [STAThread] - public static void Main() - { - // Inline try/catch - Console.WriteLine("GetFirstName() = " + CSharp.Try(() => GetFirstName(), "my_default_value")); - - // Retry a function for 20 times - Console.WriteLine("GetLastName() = " + CSharp.Retry(() => GetLastName(), 20)); - - // Convert from one object to another using reflection - // Very useful if you have classes where most properties are equal (e.g. conversion of database model to entities) - ClassA objA = new ClassA - { - FirstName = "Bill", - LastName = "Smith" - }; - ClassB objB = CSharp.ConvertObject(objA); - - Console.ReadKey(); - } - - private static string GetFirstName() - { - // This method has a bug and throws: - throw new Exception(); - } - private static string GetLastName() - { - // This method connects to an unstable web service and sometimes throws: - - if (MathEx.Random.Next(3) == 0) - { - return "Smith"; - } - else - { - throw new Exception(); - } - } -} - -public class ClassA -{ - public string FirstName { get; set; } - public string LastName { get; set; } -} - -public class ClassB -{ - public string FirstName { get; set; } - public string LastName { get; set; } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi/CachedProperty.cs b/!Examples/BytecodeApi/CachedProperty.cs deleted file mode 100644 index d558473..0000000 --- a/!Examples/BytecodeApi/CachedProperty.cs +++ /dev/null @@ -1,32 +0,0 @@ -using BytecodeApi; -using System; -using System.Threading; - -public static class Program -{ - private static int TestBackingField = 0; - private static readonly CachedProperty MyProperty = new CachedProperty(() => - { - // getter - // This property increments its value each time the getter is called - return ++TestBackingField; - }, TimeSpan.FromSeconds(1)); - - // ^---- Timeout = 1 second; Specify null to call the getter only once. - - [STAThread] - public static void Main() - { - // CachedProperty serves as cache for values stored in memory, - // but retrieved only periodically after a timeout has been exceeded - - for (int i = 0; i < 30; i++) - { - // The actual getter is called only 1x per second as specified by the timeout property of our CachedProperty - Console.WriteLine(MyProperty.Get()); - Thread.Sleep(100); - } - - Console.ReadKey(); - } -} \ No newline at end of file diff --git a/!Examples/BytecodeApi/EnumEx.cs b/!Examples/BytecodeApi/EnumEx.cs deleted file mode 100644 index aa31393..0000000 --- a/!Examples/BytecodeApi/EnumEx.cs +++ /dev/null @@ -1,40 +0,0 @@ -using BytecodeApi; -using BytecodeApi.Extensions; -using System; -using System.Collections.Generic; -using System.ComponentModel; - -public static class Program -{ - [STAThread] - public static void Main() - { - // Get description - string mondayDescription = Day.Monday.GetDescription(); - Day? monday = EnumEx.FindValueByDescription("Mon"); - - // Get all enum values - Day[] enumValues = EnumEx.GetValues(); - - // Get all enum values with description - Dictionary enumDescriptionLookup = EnumEx.GetDescriptionLookup(); - } -} - -public enum Day -{ - [Description("Mon")] - Monday, - [Description("Tue")] - Tuesday, - [Description("Wed")] - Wednesday, - [Description("Thu")] - Thursday, - [Description("Fri")] - Friday, - [Description("Sat")] - Saturday, - [Description("Sun")] - Sunday -} \ No newline at end of file diff --git a/.gitignore b/.gitignore index be2577e..3698cbd 100644 --- a/.gitignore +++ b/.gitignore @@ -16,5 +16,4 @@ TestResults/ *~*.xlsx *~*.docx -$Build/ -$Help/ \ No newline at end of file +$Build/ \ No newline at end of file diff --git a/.nuget/PackageIcon.pdn b/.nuget/PackageIcon.pdn new file mode 100644 index 0000000..347df60 Binary files /dev/null and b/.nuget/PackageIcon.pdn differ diff --git a/.nuget/PackageIcon.png b/.nuget/PackageIcon.png new file mode 100644 index 0000000..ae5749a Binary files /dev/null and b/.nuget/PackageIcon.png differ diff --git a/BytecodeApi.CommandLineParser/.nuget/README.md b/BytecodeApi.CommandLineParser/.nuget/README.md new file mode 100644 index 0000000..3fe0428 --- /dev/null +++ b/BytecodeApi.CommandLineParser/.nuget/README.md @@ -0,0 +1,3 @@ +# BytecodeApi.CommandLineParser + +Library for commandline parsing and handling. \ No newline at end of file diff --git a/BytecodeApi.CommandLineParser/BytecodeApi.CommandLineParser.csproj b/BytecodeApi.CommandLineParser/BytecodeApi.CommandLineParser.csproj new file mode 100644 index 0000000..ea98de6 --- /dev/null +++ b/BytecodeApi.CommandLineParser/BytecodeApi.CommandLineParser.csproj @@ -0,0 +1,43 @@ + + + net7.0 + enable + enable + True + True + + + 3.0.0 + 3.0.0 + 3.0.0 + + + BytecodeApi.CommandLineParser + BytecodeApi.CommandLineParser + Library for commandline parsing and handling. + bytecode77 + Martin Fischer + © bytecode77, 2023. + + + BytecodeApi.CommandLineParser + commandline cli parsing cmd + https://bytecode77.com/bytecode-api + git + https://github.com/bytecode77/bytecode-api + BSD-2-Clause + .nuget\README.md + .nuget\PackageIcon.png + ../$Build + + + + + + + + + + + + \ No newline at end of file diff --git a/BytecodeApi.CommandLineParser/CommandLineParserError.cs b/BytecodeApi.CommandLineParser/CommandLineParserError.cs new file mode 100644 index 0000000..5a9f72a --- /dev/null +++ b/BytecodeApi.CommandLineParser/CommandLineParserError.cs @@ -0,0 +1,52 @@ +namespace BytecodeApi.CommandLineParser; + +/// +/// Specifies a validation source for a , if validated using the object. +/// +public enum CommandLineParserError +{ + /// + /// The exception is a general error that did not occur during validation using the object. + /// + None, + /// + /// The exception occurred in the method. + /// + OptionRequired, + /// + /// The exception occurred in the method. + /// + OptionNotDuplicate, + /// + /// The exception occurred in the method. + /// + ValueCount, + /// + /// The exception occurred in the method. + /// + MinimumValueCount, + /// + /// The exception occurred in the method. + /// + MaximumValueCount, + /// + /// The exception occurred in the method. + /// + Custom, + /// + /// The exception occurred in the method. + /// + Int32, + /// + /// The exception occurred in the method. + /// + FileExists, + /// + /// The exception occurred in the method. + /// + DirectoryExists, + /// + /// The exception occurred in the method. + /// + FileExtension +} \ No newline at end of file diff --git a/BytecodeApi.CommandLineParser/CommandLineParserException.cs b/BytecodeApi.CommandLineParser/CommandLineParserException.cs new file mode 100644 index 0000000..5b8af70 --- /dev/null +++ b/BytecodeApi.CommandLineParser/CommandLineParserException.cs @@ -0,0 +1,29 @@ +namespace BytecodeApi.CommandLineParser; + +/// +/// The exception that is thrown when commandline parsing failed or was asserted using the object. +/// +public sealed class CommandLineParserException : Exception +{ + /// + /// Gets a value that indicates what validation took place using the object. For general exceptions, is returned. + /// + public CommandLineParserError Error { get; private init; } + + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. + public CommandLineParserException(string? message) : this(CommandLineParserError.None, message) + { + } + /// + /// Initializes a new instance of the class. + /// + /// If validated using the object, indicates what validation took place. + /// The message that describes the error. + public CommandLineParserException(CommandLineParserError error, string? message) : base(message) + { + Error = error; + } +} \ No newline at end of file diff --git a/BytecodeApi.CommandLineParser/Option.cs b/BytecodeApi.CommandLineParser/Option.cs new file mode 100644 index 0000000..ce89c93 --- /dev/null +++ b/BytecodeApi.CommandLineParser/Option.cs @@ -0,0 +1,120 @@ +using BytecodeApi.Extensions; +using System.Collections.ObjectModel; +using System.Diagnostics; + +namespace BytecodeApi.CommandLineParser; + +/// +/// Represents a commandline option, specified by possible arguments and alternatives. +/// Example: "-p 12345" and "--password 12345" +/// +[DebuggerDisplay($"{nameof(Option)}: Arguments = {{string.Join(\"|\", Arguments)}}, Alternatives = {{string.Join(\"|\", Alternatives)}}")] +public sealed class Option : IEquatable