Skip to content

Commit 3ebe09f

Browse files
committed
oop, accidently forgot to pull :p
1 parent 530460a commit 3ebe09f

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# kate.shared
2-
kate's C# Shared Resources!
2+
kate's C# Shared Library!
33

44
A collection of code that I frequently use in my personal projects, and work projects.
55

kate.shared.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ VisualStudioVersion = 17.1.32328.378
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "kate.shared", "kate.shared\kate.shared.csproj", "{8C341BD2-36EB-47FD-8C3F-F52866531D69}"
77
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "kate.shared.System.CommandLine", "kate.shared.Console\kate.shared.System.CommandLine.csproj", "{94E30ECA-A90C-4140-B5C3-7BC6A6298D9E}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
1517
{8C341BD2-36EB-47FD-8C3F-F52866531D69}.Debug|Any CPU.Build.0 = Debug|Any CPU
1618
{8C341BD2-36EB-47FD-8C3F-F52866531D69}.Release|Any CPU.ActiveCfg = Release|Any CPU
1719
{8C341BD2-36EB-47FD-8C3F-F52866531D69}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{94E30ECA-A90C-4140-B5C3-7BC6A6298D9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{94E30ECA-A90C-4140-B5C3-7BC6A6298D9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{94E30ECA-A90C-4140-B5C3-7BC6A6298D9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{94E30ECA-A90C-4140-B5C3-7BC6A6298D9E}.Release|Any CPU.Build.0 = Release|Any CPU
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE

kate.shared/Helpers/GeneralHelper.cs

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,15 @@ public static bool EmbeddedResourceExists(string resourceName, Assembly assembly
123123
}
124124
return false;
125125
}
126+
126127
/// <summary>
127-
/// Convert an array of bytes to hexadecimal.
128+
/// Convert an array of bytes to hexadecimal characters.
128129
/// </summary>
129130
public static string ToHex(byte[] data)
130131
{
131132
return BitConverter.ToString(data).Replace("-", "");
132133
}
134+
133135
/// <summary>
134136
/// Create a SHA256 based off the <paramref name="content"/> provided.
135137
/// </summary>
@@ -182,7 +184,7 @@ public static string CreateSha256Hash(string content)
182184
/// Allocates a new console for the calling process.
183185
/// </summary>
184186
/// <returns>
185-
/// When `false`, the function has failed. You can call <see href="https://learn.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-getlasterror">GetLastError</see> to get more details.</returns>
187+
/// When <see langword="false"/>, the function has failed. You can call <see href="https://learn.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-getlasterror">GetLastError</see> to get more details.</returns>
186188
[DllImport("kernel32.dll", SetLastError = true)]
187189
[return: MarshalAs(UnmanagedType.Bool)]
188190
public static extern bool AllocConsole();
@@ -235,6 +237,7 @@ public static string FormatLineEndings(string content, string lineEnding="\n")
235237

236238
return string.Join(lineEnding, lines);
237239
}
240+
238241
/// <summary>
239242
/// Trim an Array to make sure it's length doesn't exceed the <paramref name="length"/> provided.
240243
/// </summary>
@@ -298,7 +301,7 @@ public static float[] ToFloatArray(int[] array)
298301
public static List<T> GetEnumList<T>()
299302
{
300303
T[] array = (T[])Enum.GetValues(typeof(T));
301-
List<T> list = new List<T>(array);
304+
var list = new List<T>(array);
302305
return list;
303306
}
304307
/// <summary>
@@ -322,13 +325,21 @@ public static long GetNanoseconds()
322325
/// <summary>
323326
/// Get microseconds from <see cref="Stopwatch.GetTimestamp"/>
324327
/// </summary>
325-
/// <returns></returns>
326328
public static long GetMicroseconds()
327329
{
328330
double timestamp = Stopwatch.GetTimestamp();
329331
double microseconds = 1_000_000.0 * timestamp / Stopwatch.Frequency;
330332
return (long)microseconds;
331333
}
334+
/// <summary>
335+
/// Get milliseconds from <see cref="Stopwatch.GetTimestamp"/>
336+
/// </summary>
337+
public static long GetMilliseconds()
338+
{
339+
double timestamp = Stopwatch.GetTimestamp();
340+
double microseconds = 1_000.0 * timestamp / Stopwatch.Frequency;
341+
return (long)microseconds;
342+
}
332343
public static string ToBase62(ulong number)
333344
{
334345
var alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
@@ -735,7 +746,7 @@ public static void RecursiveMove(string oldDirectory, string newDirectory)
735746
/// </summary>
736747
public static string GetExtension(string filename)
737748
{
738-
return Path.GetExtension(filename).Trim('.').ToLower();
749+
return Path.GetExtension(filename).TrimStart('.').ToLower();
739750
}
740751

741752
public static int GetMaxPathLength(string directory)
@@ -812,7 +823,6 @@ public static void CreateBackup(string filename)
812823
string backupFilename = filename + @"." + DateTime.Now.Ticks + @".bak";
813824
if (File.Exists(filename) && !File.Exists(backupFilename))
814825
{
815-
// Debug.Log(@"Backup created: " + backupFilename);
816826
File.Move(filename, backupFilename);
817827
}
818828
}
@@ -828,23 +838,6 @@ public static string GetRelativePath(string path, string folder)
828838
return path.Substring(folder.Length + 1);
829839
}
830840

831-
public static string GetTempPath(string suffix = "")
832-
{
833-
string directory = Path.Combine(Path.GetTempPath(), @"osu!");
834-
Directory.CreateDirectory(directory);
835-
return Path.Combine(directory, suffix);
836-
}
837-
838-
/// <summary>
839-
/// Returns the path without the extension of the file.
840-
/// Contrarily to Path.GetFileNameWithoutExtension, it keeps the path to the file ("sb/triangle.png" becomes "sb/triangle" and not "triangle")
841-
/// </summary>
842-
public static string StripExtension(string filepath)
843-
{
844-
int dotIndex = filepath.LastIndexOf('.');
845-
return dotIndex == -1 ? filepath : filepath.Substring(0, dotIndex);
846-
}
847-
848841
public static string FormatHeader(string content, int screenWidth = 80, char padChar = '=')
849842
{
850843
int halfWidth = Convert.ToInt32(Math.Floor(screenWidth / 2.0f));

kate.shared/kate.shared.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
<TargetFrameworks>netstandard2.1;net48;net6.0;net8.0;net9.0</TargetFrameworks>
55
<Nullable>disable</Nullable>
66
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
7-
<Title>Kate's Utility Library</Title>
7+
<Version>1.3.0</Version>
8+
9+
<Title>Kate's Shared Library</Title>
810
<Authors>$(AssemblyName)</Authors>
911
<PackageProjectUrl>https://github.com/ktwrd/csharp-kate.shared</PackageProjectUrl>
1012
<PackageReadmeFile>README.md</PackageReadmeFile>
@@ -15,7 +17,6 @@
1517
<IncludeSymbols>True</IncludeSymbols>
1618
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
1719
<AutoGenerateBindingRedirects>True</AutoGenerateBindingRedirects>
18-
<Version>1.3.0</Version>
1920
<UserSecretsId>e29538d2-b40d-4a48-bc10-89cfa4af1c82</UserSecretsId>
2021
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
2122
</PropertyGroup>

0 commit comments

Comments
 (0)