Initial commit
This commit is contained in:
@@ -6,10 +6,12 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace CarManagerV2
|
||||
namespace CarManagerV3
|
||||
{
|
||||
internal class SafeManager
|
||||
{
|
||||
private static readonly string recentPathsFile = "recent_paths.txt";
|
||||
|
||||
public static void InitializeFile(string path)
|
||||
{
|
||||
if (!File.Exists(@path))
|
||||
@@ -48,5 +50,54 @@ namespace CarManagerV2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddRecentPath(string path)
|
||||
{
|
||||
// Read the file, if the path is not already in the file, add it to the top.
|
||||
// If it is already in the file, move it to the top.
|
||||
// Keep only the 5 most recent paths.
|
||||
List<string> paths = new List<string>();
|
||||
if (File.Exists(recentPathsFile))
|
||||
{
|
||||
using (StreamReader reader = new StreamReader(recentPathsFile))
|
||||
{
|
||||
string line;
|
||||
while ((line = reader.ReadLine()) != null)
|
||||
{
|
||||
paths.Add(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
paths.Remove(path);
|
||||
paths.Insert(0, path);
|
||||
if (paths.Count > 5)
|
||||
{
|
||||
paths = paths.Take(5).ToList();
|
||||
}
|
||||
using (StreamWriter writer = new StreamWriter(recentPathsFile))
|
||||
{
|
||||
foreach (string p in paths)
|
||||
{
|
||||
writer.WriteLine(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<string> GetRecentPaths()
|
||||
{
|
||||
List<string> paths = new List<string>();
|
||||
if (File.Exists(recentPathsFile))
|
||||
{
|
||||
using (StreamReader reader = new StreamReader(recentPathsFile))
|
||||
{
|
||||
string line;
|
||||
while ((line = reader.ReadLine()) != null)
|
||||
{
|
||||
paths.Add(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user