summaryrefslogtreecommitdiff
path: root/src/SMAPI/Utilities
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-09-07 13:06:27 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-09-07 13:06:27 -0400
commit5e43bdbf5cd6dbab36c25287c85d42ccfeea2c83 (patch)
tree0a42305174eb84561a584549cd685c5e95670f36 /src/SMAPI/Utilities
parent8da88b8fe5b41739c5cd0df3280b9770fc7f10a4 (diff)
parentf9fac11028354f15d786d5b854608edb10716f79 (diff)
downloadSMAPI-5e43bdbf5cd6dbab36c25287c85d42ccfeea2c83.tar.gz
SMAPI-5e43bdbf5cd6dbab36c25287c85d42ccfeea2c83.tar.bz2
SMAPI-5e43bdbf5cd6dbab36c25287c85d42ccfeea2c83.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI/Utilities')
-rw-r--r--src/SMAPI/Utilities/PathUtilities.cs45
-rw-r--r--src/SMAPI/Utilities/SDate.cs6
2 files changed, 50 insertions, 1 deletions
diff --git a/src/SMAPI/Utilities/PathUtilities.cs b/src/SMAPI/Utilities/PathUtilities.cs
new file mode 100644
index 00000000..ea134468
--- /dev/null
+++ b/src/SMAPI/Utilities/PathUtilities.cs
@@ -0,0 +1,45 @@
+using System.Diagnostics.Contracts;
+using ToolkitPathUtilities = StardewModdingAPI.Toolkit.Utilities.PathUtilities;
+
+namespace StardewModdingAPI.Utilities
+{
+ /// <summary>Provides utilities for normalizing file paths.</summary>
+ public static class PathUtilities
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Get the segments from a path (e.g. <c>/usr/bin/example</c> => <c>usr</c>, <c>bin</c>, and <c>example</c>).</summary>
+ /// <param name="path">The path to split.</param>
+ /// <param name="limit">The number of segments to match. Any additional segments will be merged into the last returned part.</param>
+ [Pure]
+ public static string[] GetSegments(string path, int? limit = null)
+ {
+ return ToolkitPathUtilities.GetSegments(path, limit);
+ }
+
+ /// <summary>Normalize path separators in a file path.</summary>
+ /// <param name="path">The file path to normalize.</param>
+ [Pure]
+ public static string NormalizePathSeparators(string path)
+ {
+ return ToolkitPathUtilities.NormalizePathSeparators(path);
+ }
+
+ /// <summary>Get whether a path is relative and doesn't try to climb out of its containing folder (e.g. doesn't contain <c>../</c>).</summary>
+ /// <param name="path">The path to check.</param>
+ [Pure]
+ public static bool IsSafeRelativePath(string path)
+ {
+ return ToolkitPathUtilities.IsSafeRelativePath(path);
+ }
+
+ /// <summary>Get whether a string is a valid 'slug', containing only basic characters that are safe in all contexts (e.g. filenames, URLs, etc).</summary>
+ /// <param name="str">The string to check.</param>
+ [Pure]
+ public static bool IsSlug(string str)
+ {
+ return ToolkitPathUtilities.IsSlug(str);
+ }
+ }
+}
diff --git a/src/SMAPI/Utilities/SDate.cs b/src/SMAPI/Utilities/SDate.cs
index 03230334..cd075dcc 100644
--- a/src/SMAPI/Utilities/SDate.cs
+++ b/src/SMAPI/Utilities/SDate.cs
@@ -1,5 +1,6 @@
using System;
using System.Linq;
+using Newtonsoft.Json;
using StardewModdingAPI.Framework;
using StardewValley;
@@ -35,15 +36,18 @@ namespace StardewModdingAPI.Utilities
/// <summary>The index of the season (where 0 is spring, 1 is summer, 2 is fall, and 3 is winter).</summary>
/// <remarks>This is used in some game calculations (e.g. seasonal game sprites) and methods (e.g. <see cref="Utility.getSeasonNameFromNumber"/>).</remarks>
+ [JsonIgnore]
public int SeasonIndex { get; }
/// <summary>The year.</summary>
public int Year { get; }
/// <summary>The day of week.</summary>
+ [JsonIgnore]
public DayOfWeek DayOfWeek { get; }
/// <summary>The number of days since the game began (starting at 1 for the first day of spring in Y1).</summary>
+ [JsonIgnore]
public int DaysSinceStart { get; }
@@ -62,6 +66,7 @@ namespace StardewModdingAPI.Utilities
/// <param name="season">The season name.</param>
/// <param name="year">The year.</param>
/// <exception cref="ArgumentException">One of the arguments has an invalid value (like day 35).</exception>
+ [JsonConstructor]
public SDate(int day, string season, int year)
: this(day, season, year, allowDayZero: false) { }
@@ -264,7 +269,6 @@ namespace StardewModdingAPI.Utilities
this.Year = year;
this.DayOfWeek = this.GetDayOfWeek(day);
this.DaysSinceStart = this.GetDaysSinceStart(day, season, year);
-
}
/// <summary>Get whether a date represents 0 spring Y1, which is the date during the in-game intro.</summary>