Add project files.
This commit is contained in:
52
CarManagerV2/SafeManager.cs
Normal file
52
CarManagerV2/SafeManager.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user