diff --git a/Misc/DataGridViewNumericUpDownCell.cs b/Misc/DataGridViewNumericUpDownCell.cs index 86242b4..90af4b7 100644 --- a/Misc/DataGridViewNumericUpDownCell.cs +++ b/Misc/DataGridViewNumericUpDownCell.cs @@ -442,7 +442,7 @@ namespace CC_Functions.Misc DataGridViewNumericUpDownEditingControl numericUpDownEditingControl = DataGridView.EditingControl as DataGridViewNumericUpDownEditingControl; return numericUpDownEditingControl != null && rowIndex == - ((IDataGridViewEditingControl) numericUpDownEditingControl).EditingControlRowIndex; + ((IDataGridViewEditingControl) numericUpDownEditingControl).EditingControlRowIndex; } /// diff --git a/Misc/GenericExtensions.cs b/Misc/GenericExtensions.cs index fb02099..f8af5e7 100644 --- a/Misc/GenericExtensions.cs +++ b/Misc/GenericExtensions.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; using System.IO; +using System.IO.Compression; using System.Linq; +using System.Net; namespace CC_Functions.Misc { @@ -66,5 +68,32 @@ namespace CC_Functions.Misc dict.Remove(dict.Keys.OfType().ToArray()[index]); public static long GetSize(this DirectoryInfo directory) => IO.GetDirectorySize(directory.FullName); + + private static ZipArchiveEntry AddDirectory(this ZipArchive archive, string folderPath, string entryName, + string[] ignoredExtensions, string[] ignoredPaths) + { + entryName = entryName.TrimEnd('/'); + ZipArchiveEntry result = archive.CreateEntry($"{entryName}/"); + string[] files = Directory.GetFiles(folderPath); + for (int i = 0; i < files.Length; i++) + if (!ignoredExtensions.Contains(Path.GetExtension(files[i])) && + !ignoredPaths.Any(s => IO.CheckPathEqual(s, files[i]))) + archive.CreateEntryFromFile(files[i], $"{entryName}/{Path.GetFileName(files[i])}"); + string[] dirs = Directory.GetDirectories(folderPath); + for (int i = 0; i < dirs.Length; i++) + if (!ignoredPaths.Any(s => IO.CheckPathEqual(s, dirs[i]))) + archive.AddDirectory(dirs[i], $"{entryName}/{Path.GetFileName(dirs[i])}", ignoredExtensions, + ignoredPaths); + return result; + } + + private static Uri Unshorten(this Uri self) + { + HttpWebRequest req = (HttpWebRequest) WebRequest.Create(self); + req.AllowAutoRedirect = true; + req.MaximumAutomaticRedirections = 100; + WebResponse resp = req.GetResponse(); + return resp.ResponseUri; + } } } \ No newline at end of file diff --git a/Misc/HID.cs b/Misc/HID.cs index d29164a..4d60021 100644 --- a/Misc/HID.cs +++ b/Misc/HID.cs @@ -32,67 +32,61 @@ Win32_NetworkAdapterConfiguration:MACAddress"; { get { - if (_fingerPrint == null) + if (_fingerPrint != null) return _fingerPrint; + string fingerprintTmp = ""; + if (forceWindows || Type.GetType("Mono.Runtime") == null) { - string fingerprintTmp = ""; - if (forceWindows || Type.GetType("Mono.Runtime") == null) + HIDClasses.Split(new[] {"\r\n"}, StringSplitOptions.None).Select(s => { - HIDClasses.Split(new[] {"\r\n"}, StringSplitOptions.None).Select(s => - { - if (s.StartsWith("\n")) - s = s.Remove(0, 1); - return s.Split(':'); - }).ToList().ForEach(s => - { - using (ManagementClass mc = new ManagementClass(s[0])) - using (ManagementObjectCollection moc = mc.GetInstances()) + if (s.StartsWith("\n")) + s = s.Remove(0, 1); + return s.Split(':'); + }).ToList().ForEach(s => + { + using ManagementClass mc = new ManagementClass(s[0]); + using ManagementObjectCollection moc = mc.GetInstances(); + ManagementBaseObject[] array = moc.OfType().ToArray(); + for (int j = 0; j < array.Length; j++) + try { - ManagementBaseObject[] array = moc.OfType().ToArray(); - for (int j = 0; j < array.Length; j++) - try - { - fingerprintTmp += array[j][s[1]].ToString(); - break; - } - catch - { - Console.WriteLine("Failed to read property"); - } + fingerprintTmp += array[j][s[1]].ToString(); + break; } - }); - } - else //Linux implementation. This will not work if you are using Mono on windows or do not have "uname", "lscpu" and "id" available - { - Process p = new Process - { - StartInfo = + catch { - UseShellExecute = false, - RedirectStandardOutput = true, - FileName = "uname", - Arguments = "-nmpio" + Console.WriteLine("Failed to read property"); } - }; - p.Start(); - fingerprintTmp = p.StandardOutput.ReadToEnd(); - p.WaitForExit(); - p.StartInfo.FileName = "lscpu"; - p.StartInfo.Arguments = "-ap"; - p.Start(); - fingerprintTmp += p.StandardOutput.ReadToEnd(); - p.WaitForExit(); - p.StartInfo.FileName = "ip"; - p.StartInfo.Arguments = "link"; - p.Start(); - fingerprintTmp += p.StandardOutput.ReadToEnd(); - p.WaitForExit(); - } - using (MD5 sec = new MD5CryptoServiceProvider()) - { - byte[] bt = Encoding.ASCII.GetBytes(fingerprintTmp); - _fingerPrint = sec.ComputeHash(bt); - } + }); } + else //Linux implementation. This will not work if you are using Mono on windows or do not have "uname", "lscpu" and "id" available + { + Process p = new Process + { + StartInfo = + { + UseShellExecute = false, + RedirectStandardOutput = true, + FileName = "uname", + Arguments = "-nmpio" + } + }; + p.Start(); + fingerprintTmp = p.StandardOutput.ReadToEnd(); + p.WaitForExit(); + p.StartInfo.FileName = "lscpu"; + p.StartInfo.Arguments = "-ap"; + p.Start(); + fingerprintTmp += p.StandardOutput.ReadToEnd(); + p.WaitForExit(); + p.StartInfo.FileName = "ip"; + p.StartInfo.Arguments = "link"; + p.Start(); + fingerprintTmp += p.StandardOutput.ReadToEnd(); + p.WaitForExit(); + } + using MD5 sec = new MD5CryptoServiceProvider(); + byte[] bt = Encoding.ASCII.GetBytes(fingerprintTmp); + _fingerPrint = sec.ComputeHash(bt); return _fingerPrint; } diff --git a/Misc/IO.cs b/Misc/IO.cs index 4de13d2..11407d3 100644 --- a/Misc/IO.cs +++ b/Misc/IO.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; namespace CC_Functions.Misc { @@ -11,5 +12,9 @@ namespace CC_Functions.Misc for (int i = 0; i < a.Length; i++) size += new FileInfo(a[i]).Length; return size; } + + public static bool CheckPathEqual(string path1, string path2) => + Path.GetFullPath(path1) + .Equals(Path.GetFullPath(path2), StringComparison.InvariantCultureIgnoreCase); } } \ No newline at end of file diff --git a/Misc/MathEx.cs b/Misc/MathEx.cs index 126efca..b2f573b 100644 --- a/Misc/MathEx.cs +++ b/Misc/MathEx.cs @@ -24,7 +24,9 @@ namespace CC_Functions.Misc public static double Floor(this double d) => Math.Floor(d); public static double Log(this double d) => Math.Log(d); public static double Log(this double d, double newBase) => Math.Log(d, newBase); + public static double Log10(this double d) => Math.Log10(d); + //Max //Min public static double Pow(this double x, double y) => Math.Pow(x, y); @@ -32,11 +34,17 @@ namespace CC_Functions.Misc public static decimal Round(this decimal d) => Math.Round(d); public static decimal Round(this decimal d, MidpointRounding mode) => Math.Round(d, mode); public static decimal Round(this decimal d, int decimals) => Math.Round(d, decimals); - public static decimal Round(this decimal d, int decimals, MidpointRounding mode) => Math.Round(d, decimals, mode); + + public static decimal Round(this decimal d, int decimals, MidpointRounding mode) => + Math.Round(d, decimals, mode); + public static double Round(this double a) => Math.Round(a); public static double Round(this double value, MidpointRounding mode) => Math.Round(value, mode); public static double Round(this double value, int digits) => Math.Round(value, digits); - public static double Round(this double value, int digits, MidpointRounding mode) => Math.Round(value, digits, mode); + + public static double Round(this double value, int digits, MidpointRounding mode) => + Math.Round(value, digits, mode); + public static int Sign(this decimal value) => Math.Sign(value); public static int Sign(this double value) => Math.Sign(value); public static int Sign(this float value) => Math.Sign(value); diff --git a/Misc/Misc.csproj b/Misc/Misc.csproj index f227746..b40bb89 100644 --- a/Misc/Misc.csproj +++ b/Misc/Misc.csproj @@ -1,83 +1,37 @@ - - - + - Debug - AnyCPU - {B80D5E09-B935-4602-A173-BAF7C1974999} Library - Properties CC_Functions.Misc CC_Functions.Misc - v4.6.1 - 512 - true - 8 enable + false + true + net461;netcoreapp3.1 - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 bin\Debug\Misc.xml - pdbonly - true - bin\Release\ - TRACE - prompt - 4 bin\Release\Misc.xml - - - - - - - - - - - - - - - - - - + Component - - - - - - - + Component - - - Form - - - SelectBox.cs - - - SelectBox.cs - - + + + + + + + + \ No newline at end of file diff --git a/W32.Test/W32.Test.csproj b/W32.Test/W32.Test.csproj index da90511..40d5adc 100644 --- a/W32.Test/W32.Test.csproj +++ b/W32.Test/W32.Test.csproj @@ -1,99 +1,22 @@ - - - + - Debug - AnyCPU - {6121A6D3-7C73-4EDE-A5A9-09DC52150824} + netcoreapp3.0 WinExe CC_Functions.W32.Test CC_Functions.W32.Test - v4.6.1 - 512 - true - true - 8 enable + false + true - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 bin\Debug\W32.Test.xml - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 bin\Release\W32.Test.xml - - - - - - - - - - - + + - - - Form - - - MainForm.cs - - - - - MainForm.cs - - - ResXFileCodeGenerator - Resources.Designer.cs - Designer - - - True - Resources.resx - True - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - True - Settings.settings - True - - - - - - - - {B80D5E09-B935-4602-A173-BAF7C1974999} - Misc - - - {23de4ae0-5075-4ccc-8440-4d131ca0fbba} - W32 - - - \ No newline at end of file diff --git a/W32/Mouse.cs b/W32/Mouse.cs index 9f1f16f..8e476f4 100644 --- a/W32/Mouse.cs +++ b/W32/Mouse.cs @@ -5,7 +5,7 @@ using CC_Functions.W32.Native; namespace CC_Functions.W32 { /// - /// Functions for manipulating the mouse + /// Functions for manipulating the mouse /// public static class Mouse { @@ -15,13 +15,13 @@ namespace CC_Functions.W32 private const int MouseEventFRightUp = 0x10; /// - /// Emulates a click at the cursors position + /// Emulates a click at the cursors position /// /// Set to true to perform right-clicks instead of left-clicks public static void Click(bool right = false) => Click(Cursor.Position, right); /// - /// Emulates a click at the specified position + /// Emulates a click at the specified position /// /// The position to perform the click at /// Set to true to perform right-clicks instead of left-clicks diff --git a/W32/Native/kernel32.cs b/W32/Native/kernel32.cs index 5c35fab..5b078ab 100644 --- a/W32/Native/kernel32.cs +++ b/W32/Native/kernel32.cs @@ -17,10 +17,10 @@ namespace CC_Functions.W32.Native [DllImport("kernel32.dll")] public static extern IntPtr GetConsoleWindow(); - + [DllImport("kernel32.dll", SetLastError = true)] public static extern bool SetSystemTime(ref SYSTEMTIME st); - + [StructLayout(LayoutKind.Sequential)] public struct SYSTEMTIME { diff --git a/W32/W32.csproj b/W32/W32.csproj index b9bbed6..3c40df7 100644 --- a/W32/W32.csproj +++ b/W32/W32.csproj @@ -1,79 +1,20 @@ - - - + - Debug - AnyCPU - {23DE4AE0-5075-4CCC-8440-4D131CA0FBBA} Library - Properties CC_Functions.W32 CC-Functions.W32 - v4.6.1 - 512 - true - 8 enable + false + true + net461;netcoreapp3.1 - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 true bin\Debug\W32.xml - pdbonly - true - bin\Release\ - TRACE - prompt - 4 true bin\Release\W32.xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file