feat: GUID

This commit is contained in:
2026-03-02 14:23:15 +01:00
parent f6b70fa387
commit 48be020dc4
7 changed files with 158 additions and 44 deletions

View File

@@ -17,6 +17,7 @@ namespace CarManagerV3
/// </summary>
private static readonly string recentPathsFile = "recent_paths.txt";
/// <summary>
/// Initializes a file at a specified path if it does not already exist.
/// </summary>
@@ -52,6 +53,7 @@ namespace CarManagerV3
{
List<Car> cars = new List<Car>();
List<string> failedLines = new List<string>();
bool isLegacy = false;
try
{
using (StreamReader reader = new StreamReader(@path))
@@ -61,17 +63,35 @@ namespace CarManagerV3
{
// Process the line
if (line == "") continue;
if (Car.isLegacyCsvString(line))
{
if (!StateManager.askForMigration())
{
MessageBox.Show("The file you are trying to open is in an old format that is no longer supported. Please select a different file.", "Unsupported Format", MessageBoxButtons.OK, MessageBoxIcon.Error);
throw new LegacyException();
//Environment.Exit(0);
}
else
{
isLegacy = true;
}
}
Car tmp = Car.FromCsvString(line);
if (tmp == null)
{
failedLines.Add(line);
continue;
}
}
cars.Add(tmp);
}
reader.Close();
}
} catch (Exception ex)
}
catch (LegacyException ex)
{
throw ex;
}
catch (Exception ex)
{
Console.Error.WriteLine($"Error reading cars from file: {ex.Message}");
}
@@ -84,6 +104,11 @@ namespace CarManagerV3
}
MessageBox.Show($"Warning: {failedLines.Count} lines in the file could not be parsed and were skipped. Check the console for details.", "Parsing Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
cars = cars.OrderBy(c => c.Order).ToList();
if(isLegacy)
{
SafeManager.SaveCars(path, cars);
}
return cars;
}
@@ -104,7 +129,8 @@ namespace CarManagerV3
}
writer.Close();
}
} catch (Exception ex)
}
catch (Exception ex)
{
Console.Error.WriteLine($"Error saving cars to file: {ex.Message}");
MessageBox.Show($"Error saving cars to file: {ex.Message}", "Save Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
@@ -149,7 +175,8 @@ namespace CarManagerV3
}
writer.Close();
}
} catch (Exception ex)
}
catch (Exception ex)
{
Console.Error.WriteLine($"Error managing recent paths: {ex.Message}");
}
@@ -178,11 +205,14 @@ namespace CarManagerV3
reader.Close();
}
}
} catch (Exception ex)
}
catch (Exception ex)
{
Console.Error.WriteLine($"Error reading recent paths: {ex.Message}");
}
return paths;
}
}
}