feature: welcome screen, toolbar & chore: more docs

This commit is contained in:
2026-03-03 13:44:34 +01:00
parent 9be57d3c5f
commit 808b0c4720
8 changed files with 9953 additions and 627 deletions

View File

@@ -15,13 +15,13 @@ namespace CarManagerV3
/// <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 = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\CarManagerV3\\recent_paths.txt";
/// <summary>
/// Initializes a file at a specified path if it does not already exist.
/// </summary>
/// <param name="path">The path.</param>
/// <param name="path">The path of the file.</param>
public static void InitializeFile(string path)
{
try
@@ -31,7 +31,7 @@ namespace CarManagerV3
using (StreamWriter writer = new StreamWriter(@path))
{
// Create the file, empty
writer.WriteLine();
//writer.WriteLine();
writer.Close();
}
}
@@ -42,6 +42,27 @@ namespace CarManagerV3
}
}
/// <summary>
/// Initializes a file and its parent folders at a specified path if they do not already exist.
/// </summary>
/// <param name="path">The path of the file.</param>
public static void initializeFileAndFolders(string path)
{
try
{
string directory = Path.GetDirectoryName(path);
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
InitializeFile(path);
}
catch (Exception ex)
{
Console.Error.WriteLine($"Error initializing file and folders: {ex.Message}");
}
}
/// <summary>
/// Reads cars from a specified file path.
/// </summary>
@@ -150,18 +171,7 @@ namespace CarManagerV3
List<string> paths = new List<string>();
try
{
if (File.Exists(recentPathsFile))
{
using (StreamReader reader = new StreamReader(recentPathsFile))
{
string line;
while ((line = reader.ReadLine()) != null)
{
paths.Add(line);
}
reader.Close();
}
}
paths = GetRecentPaths();
paths.Remove(path);
paths.Insert(0, path);
if (paths.Count > 5)
@@ -194,7 +204,8 @@ namespace CarManagerV3
List<string> paths = new List<string>();
try
{
if (File.Exists(recentPathsFile))
initializeFileAndFolders(recentPathsFile);
if (File.Exists(recentPathsFile)) //TODO: Remove
{
using (StreamReader reader = new StreamReader(recentPathsFile))
{
@@ -215,9 +226,11 @@ namespace CarManagerV3
}
/// <summary>
/// Gets the folder of the most recently opened file, or the users documents folder if no recent files.
/// Gets the folder of the most recently opened file.
/// </summary>
/// <returns></returns>
/// <returns>
/// The folder path of the most recently opened file, or the users documents folder if no recent files.
/// </returns>
public static string getRecentFolder()
{
List<string> recentPaths = GetRecentPaths();
@@ -232,7 +245,23 @@ namespace CarManagerV3
return Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
}
/// <summary>
/// Clears the recently opened file paths list by deleting the recent paths file.
/// </summary>
public static void ClearRecentPaths()
{
try
{
if (File.Exists(recentPathsFile))
{
File.Delete(recentPathsFile);
}
}
catch (Exception ex)
{
Console.Error.WriteLine($"Error clearing recent paths: {ex.Message}");
}
}
}
}

View File

@@ -15,8 +15,7 @@ namespace CarManagerV3
// Initialize global static list of cars
static List<Car> cars = new List<Car>();
// Initialize default file path for car data.
// TODO: If no recent file paths are found, prompt user to select a file path instead of using a hardcoded default in the program folder.
static string filePath = "cars.csv";
static string filePath = "";
static bool hasConfirmedMigration = false;
@@ -46,7 +45,7 @@ namespace CarManagerV3
/// <summary>
/// Adds a car to the collection.
/// </summary>
/// <param name="car">The car to add.</param>
/// <param name="car">The <see cref="Car"/> to add.</param>
public static void AddCar(Car car)
{
cars = SafeManager.ReadCars(filePath);
@@ -57,7 +56,7 @@ namespace CarManagerV3
/// <summary>
/// Removes a car from the collection.
/// </summary>
/// <param name="car">The car to remove.</param>
/// <param name="car">The <see cref="Car"/> to remove.</param>
public static void RemoveCar(Car car)
{
cars = SafeManager.ReadCars(filePath);
@@ -73,7 +72,7 @@ namespace CarManagerV3
/// <remarks>
/// If the car's Id has changed during editing, this will not work correctly. Keep Id immutable!
/// </remarks>
/// <param name="car">The car to update.</param>
/// <param name="car">The <see cref="Car"/> to update.</param>
public static void UpdateCar(Car car)
{
Car existingCar = GetCarById(car.Id);
@@ -119,6 +118,11 @@ namespace CarManagerV3
filePath = path;
}
/// <summary>
/// Normalizes the orders of the cars in the collection to be sequential starting from 1, while keeping the relative order the same.
/// </summary>
/// <param name="cars">The list of <see cref="Car"/>s.</param>
/// <returns>A normalized List of <see cref="Car"/>s </returns>
public static List<Car> normalizeOrders(List<Car> cars)
{
// Normalize the Order field of all cars to be sequential starting from 1, while keeping the relative order the same.
@@ -130,6 +134,11 @@ namespace CarManagerV3
return orderedCars;
}
/// <summary>
/// Prompts the user to confirm migration if they haven't already confirmed it for the current session.
/// This is to prevent multiple annoying popups if the user tries to open multiple files that require migration.
/// </summary>
/// <returns>True if the user has accepted to migrate the file, otherwise False</returns>
public static bool askForMigration()
{
if (hasConfirmedMigration)