Some additions

This commit is contained in:
CreepyCrafter24 2020-03-13 19:19:55 +01:00
parent 748e5322ab
commit 0cc87fa5d5
10 changed files with 123 additions and 269 deletions

View File

@ -442,7 +442,7 @@ namespace CC_Functions.Misc
DataGridViewNumericUpDownEditingControl numericUpDownEditingControl =
DataGridView.EditingControl as DataGridViewNumericUpDownEditingControl;
return numericUpDownEditingControl != null && rowIndex ==
((IDataGridViewEditingControl) numericUpDownEditingControl).EditingControlRowIndex;
((IDataGridViewEditingControl) numericUpDownEditingControl).EditingControlRowIndex;
}
/// <summary>

View File

@ -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<T>().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;
}
}
}

View File

@ -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<ManagementBaseObject>().ToArray();
for (int j = 0; j < array.Length; j++)
try
{
ManagementBaseObject[] array = moc.OfType<ManagementBaseObject>().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;
}

View File

@ -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);
}
}

View File

@ -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);

View File

@ -1,83 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{B80D5E09-B935-4602-A173-BAF7C1974999}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CC_Functions.Misc</RootNamespace>
<AssemblyName>CC_Functions.Misc</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
<LangVersion>8</LangVersion>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<UseWindowsForms>true</UseWindowsForms>
<TargetFrameworks>net461;netcoreapp3.1</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\Misc.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\Misc.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Management" />
<Reference Include="System.Security" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ArrayFormatter.cs" />
<Compile Include="DataGridViewNumericUpDownCell.cs" />
<Compile Include="DataGridViewNumericUpDownColumn.cs" />
<Compile Include="DataGridViewNumericUpDownEditingControl.cs">
<Compile Update="DataGridViewNumericUpDownEditingControl.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Forms.cs" />
<Compile Include="GenericExtensions.cs" />
<Compile Include="HID.cs" />
<Compile Include="IO.cs" />
<Compile Include="MathEx.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RotatingIndicator.cs">
<Compile Update="RotatingIndicator.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Security.cs" />
<Compile Include="SelectBox.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="SelectBox.Designer.cs">
<DependentUpon>SelectBox.cs</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="HIDClasses.txt" />
<EmbeddedResource Include="SelectBox.resx">
<DependentUpon>SelectBox.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<PackageReference Include="System.Management" Version="4.7.0" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="4.7.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.IO.Compression" Condition="'$(TargetFramework)' == 'net461'" />
<Reference Include="System.IO.Compression.FileSystem" Condition="'$(TargetFramework)' == 'net461'" />
</ItemGroup>
</Project>

View File

@ -1,99 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{6121A6D3-7C73-4EDE-A5A9-09DC52150824}</ProjectGuid>
<TargetFramework>netcoreapp3.0</TargetFramework>
<OutputType>WinExe</OutputType>
<RootNamespace>CC_Functions.W32.Test</RootNamespace>
<AssemblyName>CC_Functions.W32.Test</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
<LangVersion>8</LangVersion>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\W32.Test.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\W32.Test.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<ProjectReference Include="..\Misc\Misc.csproj" />
<ProjectReference Include="..\W32\W32.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="MainForm.Designer.cs">
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Misc\Misc.csproj">
<Project>{B80D5E09-B935-4602-A173-BAF7C1974999}</Project>
<Name>Misc</Name>
</ProjectReference>
<ProjectReference Include="..\W32\W32.csproj">
<Project>{23de4ae0-5075-4ccc-8440-4d131ca0fbba}</Project>
<Name>W32</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -5,7 +5,7 @@ using CC_Functions.W32.Native;
namespace CC_Functions.W32
{
/// <summary>
/// Functions for manipulating the mouse
/// Functions for manipulating the mouse
/// </summary>
public static class Mouse
{
@ -15,13 +15,13 @@ namespace CC_Functions.W32
private const int MouseEventFRightUp = 0x10;
/// <summary>
/// Emulates a click at the cursors position
/// Emulates a click at the cursors position
/// </summary>
/// <param name="right">Set to true to perform right-clicks instead of left-clicks</param>
public static void Click(bool right = false) => Click(Cursor.Position, right);
/// <summary>
/// Emulates a click at the specified position
/// Emulates a click at the specified position
/// </summary>
/// <param name="location">The position to perform the click at</param>
/// <param name="right">Set to true to perform right-clicks instead of left-clicks</param>

View File

@ -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
{

View File

@ -1,79 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{23DE4AE0-5075-4CCC-8440-4D131CA0FBBA}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CC_Functions.W32</RootNamespace>
<AssemblyName>CC-Functions.W32</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
<LangVersion>8</LangVersion>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<UseWindowsForms>true</UseWindowsForms>
<TargetFrameworks>net461;netcoreapp3.1</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DocumentationFile>bin\Debug\W32.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DocumentationFile>bin\Release\W32.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DCDrawer\DCBuffered.cs" />
<Compile Include="DCDrawer\DCUnbuffered.cs" />
<Compile Include="DCDrawer\IDCDrawer.cs" />
<Compile Include="DeskMan.cs" />
<Compile Include="GenericExtensions.cs" />
<Compile Include="Hooks\MouseHook.cs" />
<Compile Include="Hooks\KeyboardHook.cs" />
<Compile Include="Hooks\KeyboardHookEventArgs.cs" />
<Compile Include="KeyboardReader.cs" />
<Compile Include="Hooks\MouseHookEventArgs.cs" />
<Compile Include="Mouse.cs" />
<Compile Include="Native\advapi32.cs" />
<Compile Include="Native\gdi32.cs" />
<Compile Include="Native\kernel32.cs" />
<Compile Include="Native\ntdll.cs" />
<Compile Include="Native\RECT.cs" />
<Compile Include="Native\shell32.cs" />
<Compile Include="Native\user32.cs" />
<Compile Include="Power.cs" />
<Compile Include="Privileges.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScreenMan.cs" />
<Compile Include="Time.cs" />
<Compile Include="Wnd32.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>