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}");
}
}
}
}