53 lines
1.3 KiB
C#
53 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace CarManagerV2
|
|
{
|
|
internal class SafeManager
|
|
{
|
|
public static void initializeFile(string path)
|
|
{
|
|
if (!File.Exists(@path))
|
|
{
|
|
using (StreamWriter writer = new StreamWriter(@path))
|
|
{
|
|
// Create the file, empty
|
|
writer.WriteLine();
|
|
}
|
|
}
|
|
}
|
|
|
|
public static List<Car> readCars(string path)
|
|
{
|
|
List<Car> cars = new List<Car>();
|
|
using (StreamReader reader = new StreamReader(@path))
|
|
{
|
|
string line;
|
|
while ((line = reader.ReadLine()) != null)
|
|
{
|
|
// Process the line
|
|
if (line == "") continue;
|
|
cars.Add(Car.fromCsvString(line));
|
|
}
|
|
}
|
|
return cars;
|
|
}
|
|
|
|
public static void saveCars(string path, List<Car> cars)
|
|
{
|
|
using (StreamWriter writer = new StreamWriter(@path))
|
|
{
|
|
foreach (Car car in cars)
|
|
{
|
|
writer.WriteLine(car.toCsvString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|