-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPrintingState.cs
47 lines (37 loc) · 1.32 KB
/
PrintingState.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
using System;
using System.Drawing;
using System.IO;
using System.Text;
using System.Xml.Serialization;
namespace autoPrint
{
[Serializable]
public class PrintingState
{
private static String FilePath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ThomasEWillson", "AutoPrint", "printingState.xml");
private static String FolderPath => Path.GetDirectoryName(FilePath);
public Point CurrentLocation { get; set; } = new Point(0, 0);
public int CurrentLineHeight { get; set; } = 0;
public static PrintingState Load()
{
if (!File.Exists(FilePath))
{
return new PrintingState();
}
var serializer = new XmlSerializer(typeof(PrintingState));
using(var file = File.OpenRead(FilePath))
{
return (PrintingState) serializer.Deserialize(file);
}
}
public static void Save(PrintingState printingState)
{
Directory.CreateDirectory(FolderPath);
var serializer = new XmlSerializer(typeof(PrintingState));
using(var writer = new StreamWriter(FilePath, false, Encoding.UTF8))
{
serializer.Serialize(writer, printingState);
}
}
}
}