Skip to content

Commit

Permalink
Add a bit of documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Miepee committed Sep 11, 2022
1 parent a0818c7 commit 618c416
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
22 changes: 22 additions & 0 deletions AM2RPortHelperLib/HelperMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ namespace AM2RPortHelperLib;

public static partial class PortHelper
{
/// <summary>
/// Recursively lowercases all files and folders from a specified directory.
/// </summary>
/// <param name="directory">The path to the directory whose contents should be lowercased.</param>
private static void LowercaseFolder(string directory)
{
DirectoryInfo dir = new DirectoryInfo(directory);
Expand All @@ -19,6 +23,7 @@ private static void LowercaseFolder(string directory)
foreach(var subDir in dir.GetDirectories())
{
if (subDir.Name == subDir.Name.ToLower()) continue;
// ReSharper disable once PossibleNullReferenceException - since this is a subdirectory, it always has a parent
subDir.MoveTo(subDir.Parent.FullName + "/" + subDir.Name.ToLower());
LowercaseFolder(subDir.FullName);
}
Expand Down Expand Up @@ -56,13 +61,30 @@ private static void DirectoryCopy(string sourceDirName, string destDirName, bool
}
}

/// <summary>
/// Resizes an <see cref="Image"/>, resizes it via Nearest Neighbor to a specified dimension, and then saves it to a specified path.
/// </summary>
/// <param name="icon">The image to resize and save.</param>
/// <param name="dimensions">The dimensions <paramref name="icon"/> should be resized to.</param>
/// <param name="filePath">The filepath where the resized image should be saved to.</param>
/// <example>
/// <code>
/// Image icon = Image.Load("icon.png");
/// SaveAndroidIcon(icon, 128, "128.png");
/// </code>
/// </example>
private static void SaveAndroidIcon(Image icon, int dimensions, string filePath)
{
Image picture = icon;
picture.Mutate(x => x.Resize(dimensions, dimensions, KnownResamplers.NearestNeighbor));
picture.SaveAsPng(filePath);
}

/// <summary>
/// Calculates the SHA256 hash of a specified file.
/// </summary>
/// <param name="filename">The full filepath to a file whose SHA256 hash should be calculated.</param>
/// <returns>The SHA256 hash of <see cref="filename"/>.</returns>
private static string CalculateSHA256(string filename)
{
// Check if file exists first
Expand Down
14 changes: 14 additions & 0 deletions AM2RPortHelperLib/PortHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ namespace AM2RPortHelperLib;

public static partial class PortHelper
{
/// <summary>
/// The current version of <see cref="AM2RPortHelperLib"/>.
/// </summary>
public const string Version = "1.3";
public delegate void OutputHandlerDelegate(string output);

Expand All @@ -20,8 +23,19 @@ private static void SendOutput(string output)
Console.WriteLine(output);
}

/// <summary>
/// A temporary directory
/// </summary>
private static readonly string tmp = Path.GetTempPath();

/// <summary>
/// The current directory of the AM2RPortHelper program.
/// </summary>
private static readonly string currentDir = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);

/// <summary>
/// The "utils" folder that's shipped with the AM2RPortHelper.
/// </summary>
private static readonly string utilDir = currentDir + "/utils";

public static void PortLauncherMod(string inputLauncherZipPath, string targetOS, bool includeAndroid, string outputLauncherZipPath, OutputHandlerDelegate outputDelegate = null)
Expand Down

0 comments on commit 618c416

Please sign in to comment.