-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfiguration.cs
More file actions
71 lines (62 loc) · 2.21 KB
/
Copy pathConfiguration.cs
File metadata and controls
71 lines (62 loc) · 2.21 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.IO;
using System.Xml.Serialization;
namespace PasswordGenerator
{
/// <summary>
/// This class is used to store user input between runs. The Password is not stored. D
/// </summary>
[Serializable]
public class ConfigPasswordGenerator
{
public string SpecialCharacters { get; set; }
public string WordFileName { get; set; }
public decimal WordCount { get; set; }
public decimal PasswordCount { get; set; }
public bool CapitalizeWord { get; set; }
[XmlIgnore]
public string ConfigFileName { get; set; } // name of file containing configuration information
public ConfigPasswordGenerator()
{
string appData = Environment.GetEnvironmentVariable("APPDATA");
string dataDir = Path.Combine(appData, "PasswordGen");
if (!Directory.Exists(dataDir))
Directory.CreateDirectory(dataDir);
ConfigFileName = Path.Combine(dataDir, "Configuration.xml");
}
public bool Serialize(string fileName)
{
try
{
using (TextWriter writer = new StreamWriter(fileName))
{
XmlSerializer ser = new XmlSerializer(typeof(ConfigPasswordGenerator));
ser.Serialize(writer, this);
}
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show("Error: " + ex.ToString());
}
return true;
}
public static bool DeSerialize(string fileName, ref ConfigPasswordGenerator cfg)
{
if (!File.Exists(fileName))
return true;
try
{
using (FileStream fileStream = new FileStream(fileName, FileMode.Open))
{
XmlSerializer ser = new XmlSerializer(typeof(ConfigPasswordGenerator));
cfg = (ConfigPasswordGenerator)ser.Deserialize(fileStream);
}
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString());
}
return true;
}
}
}