-
Notifications
You must be signed in to change notification settings - Fork 1
/
BadApple.cs
50 lines (45 loc) · 1.4 KB
/
BadApple.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
namespace Reverse1999
{
internal class BadApple
{
const string LAST_OPEN_FILE = "last_open.txt";
internal static void SaveLastOpenedFile(string filePath)
{
try
{
// Write the last opened directory to a text file
using StreamWriter writer = new(LAST_OPEN_FILE);
writer.WriteLine($"last_opened={filePath}");
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
internal static string GetLastOpenedFile()
{
string lastOpenedDirectory = string.Empty;
if (!File.Exists(LAST_OPEN_FILE))
return lastOpenedDirectory;
try
{
// Read the last opened directory from the text file
using StreamReader reader = new(LAST_OPEN_FILE);
string? line;
while ((line = reader.ReadLine()) != null)
{
if (line.StartsWith("last_opened="))
{
lastOpenedDirectory = line["last_opened=".Length..];
break;
}
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return lastOpenedDirectory;
}
}
}