initial commit

This commit is contained in:
i2p
2026-08-27 11:22:16 -06:00
commit 96afff7a83
600 changed files with 29291 additions and 0 deletions
@@ -0,0 +1,27 @@
using System.IO;
namespace Quasar.Common.Extensions
{
public static class DriveTypeExtensions
{
/// <summary>
/// Converts the value of the <see cref="DriveType"/> instance to its friendly string representation.
/// </summary>
/// <param name="type">The <see cref="DriveType"/>.</param>
/// <returns>The friendly string representation of the value of this <see cref="DriveType"/> instance.</returns>
public static string ToFriendlyString(this DriveType type)
{
switch (type)
{
case DriveType.Fixed:
return "Local Disk";
case DriveType.Network:
return "Network Drive";
case DriveType.Removable:
return "Removable Drive";
default:
return type.ToString();
}
}
}
}
@@ -0,0 +1,48 @@
using System;
using System.Net.Sockets;
using System.Runtime.InteropServices;
namespace Quasar.Common.Extensions
{
/// <summary>
/// Socket Extension for KeepAlive
/// </summary>
/// <Author>Abdullah Saleem</Author>
/// <Email>[email protected]</Email>
public static class SocketExtensions
{
/// <summary>
/// A structure used by SetKeepAliveEx Method
/// </summary>
[StructLayout(LayoutKind.Sequential)]
internal struct TcpKeepAlive
{
internal uint onoff;
internal uint keepalivetime;
internal uint keepaliveinterval;
};
/// <summary>
/// Sets the Keep-Alive values for the current tcp connection
/// </summary>
/// <param name="socket">Current socket instance</param>
/// <param name="keepAliveInterval">Specifies how often TCP repeats keep-alive transmissions when no response is received. TCP sends keep-alive transmissions to verify that idle connections are still active. This prevents TCP from inadvertently disconnecting active lines.</param>
/// <param name="keepAliveTime">Specifies how often TCP sends keep-alive transmissions. TCP sends keep-alive transmissions to verify that an idle connection is still active. This entry is used when the remote system is responding to TCP. Otherwise, the interval between transmissions is determined by the value of the keepAliveInterval entry.</param>
public static void SetKeepAliveEx(this Socket socket, uint keepAliveInterval, uint keepAliveTime)
{
var keepAlive = new TcpKeepAlive
{
onoff = 1,
keepaliveinterval = keepAliveInterval,
keepalivetime = keepAliveTime
};
int size = Marshal.SizeOf(keepAlive);
IntPtr keepAlivePtr = Marshal.AllocHGlobal(size);
Marshal.StructureToPtr(keepAlive, keepAlivePtr, true);
var buffer = new byte[size];
Marshal.Copy(keepAlivePtr, buffer, 0, size);
Marshal.FreeHGlobal(keepAlivePtr);
socket.IOControl(IOControlCode.KeepAliveValues, buffer, null);
}
}
}
@@ -0,0 +1,69 @@
using Quasar.Common.Enums;
namespace Quasar.Common.Extensions
{
public static class StringExtensions
{
/// <summary>
/// Converts the file extension string to its <see cref="ContentType"/> representation.
/// </summary>
/// <param name="fileExtension">The file extension string.</param>
/// <returns>The <see cref="ContentType"/> representation of the file extension string.</returns>
public static ContentType ToContentType(this string fileExtension)
{
switch (fileExtension.ToLower())
{
default:
return ContentType.Blob;
case ".exe":
return ContentType.Application;
case ".txt":
case ".log":
case ".conf":
case ".cfg":
case ".asc":
return ContentType.Text;
case ".rar":
case ".zip":
case ".zipx":
case ".tar":
case ".tgz":
case ".gz":
case ".s7z":
case ".7z":
case ".bz2":
case ".cab":
case ".zz":
case ".apk":
return ContentType.Archive;
case ".doc":
case ".docx":
case ".odt":
return ContentType.Word;
case ".pdf":
return ContentType.Pdf;
case ".jpg":
case ".jpeg":
case ".png":
case ".bmp":
case ".gif":
case ".ico":
return ContentType.Image;
case ".mp4":
case ".mov":
case ".avi":
case ".wmv":
case ".mkv":
case ".m4v":
case ".flv":
return ContentType.Video;
case ".mp3":
case ".wav":
case ".pls":
case ".m3u":
case ".m4a":
return ContentType.Audio;
}
}
}
}