chore: document SafeManager
This commit is contained in:
@@ -8,10 +8,20 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace CarManagerV3
|
namespace CarManagerV3
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Handles safe reading and writing of car data to files.
|
||||||
|
/// </summary>
|
||||||
internal class SafeManager
|
internal class SafeManager
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The path of the txt file that contains recently opened file paths.
|
||||||
|
/// </summary>
|
||||||
private static readonly string recentPathsFile = "recent_paths.txt";
|
private static readonly string recentPathsFile = "recent_paths.txt";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a file at a specified path if it does not already exist.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The path.</param>
|
||||||
public static void InitializeFile(string path)
|
public static void InitializeFile(string path)
|
||||||
{
|
{
|
||||||
if (!File.Exists(@path))
|
if (!File.Exists(@path))
|
||||||
@@ -24,6 +34,13 @@ namespace CarManagerV3
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads cars from a specified file path.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The path.</param>
|
||||||
|
/// <returns>
|
||||||
|
/// A <see cref="List{Car}"/> containing the cars read from the file.
|
||||||
|
/// </returns>
|
||||||
public static List<Car> ReadCars(string path)
|
public static List<Car> ReadCars(string path)
|
||||||
{
|
{
|
||||||
List<Car> cars = new List<Car>();
|
List<Car> cars = new List<Car>();
|
||||||
@@ -40,6 +57,11 @@ namespace CarManagerV3
|
|||||||
return cars;
|
return cars;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Saves the cars to a specified file path.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The path.</param>
|
||||||
|
/// <param name="cars">A <see cref="List{Car}"/> containing all cars to save.</param>
|
||||||
public static void SaveCars(string path, List<Car> cars)
|
public static void SaveCars(string path, List<Car> cars)
|
||||||
{
|
{
|
||||||
using (StreamWriter writer = new StreamWriter(@path))
|
using (StreamWriter writer = new StreamWriter(@path))
|
||||||
@@ -51,11 +73,15 @@ namespace CarManagerV3
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a file path to the recent paths list.
|
||||||
|
/// If a path is already in the list, it is moved to the top.
|
||||||
|
/// Otherwise, it is added to the top.
|
||||||
|
/// Keeps only the 5 most recent paths.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The path.</param>
|
||||||
public static void AddRecentPath(string path)
|
public static void AddRecentPath(string path)
|
||||||
{
|
{
|
||||||
// Read the file, if the path is not already in the file, add it to the top.
|
|
||||||
// If it is already in the file, move it to the top.
|
|
||||||
// Keep only the 5 most recent paths.
|
|
||||||
List<string> paths = new List<string>();
|
List<string> paths = new List<string>();
|
||||||
if (File.Exists(recentPathsFile))
|
if (File.Exists(recentPathsFile))
|
||||||
{
|
{
|
||||||
@@ -83,6 +109,12 @@ namespace CarManagerV3
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the recently opened file paths.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// A <see cref="List{String}"/> containing the recent file paths.
|
||||||
|
/// </returns>
|
||||||
public static List<string> GetRecentPaths()
|
public static List<string> GetRecentPaths()
|
||||||
{
|
{
|
||||||
List<string> paths = new List<string>();
|
List<string> paths = new List<string>();
|
||||||
|
|||||||
Reference in New Issue
Block a user