public HotkeysData(BasicTeraData basicData)
{
DefaultValue();
// Load XML File
XDocument xml;
var hotkeyFile = Path.Combine(basicData.ResourceDirectory, "config/hotkeys.xml");
try
{
var attrs = File.GetAttributes(hotkeyFile);
File.SetAttributes(hotkeyFile, attrs & ~FileAttributes.ReadOnly);
}
catch
{
//ignore
}
try
{
_filestream = new FileStream(hotkeyFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
xml = XDocument.Load(_filestream);
}
catch (Exception ex) when (ex is XmlException || ex is InvalidOperationException)
{
Save();
_filestream = new FileStream(hotkeyFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
return;
}
catch
{
return;
}
// Get Keys
var root = xml.Root;
if (root == null) return;
var topmostKey = ReadElement(root, "topmost", false);
if (topmostKey != null)
{
Topmost = (KeyValuePair<Keys, ModifierKeys>)topmostKey;
}
var pasteKey = ReadElement(root, "paste", false);
if (pasteKey != null)
{
Paste = (KeyValuePair<Keys, ModifierKeys>) pasteKey;
}
var resetKey = ReadElement(root, "reset", true);
if (resetKey != null)
{
Reset = (KeyValuePair<Keys, ModifierKeys>) resetKey;
}
var activateKey = ReadElement(root, "click_throu", true);
if (activateKey != null)
{
ClickThrou = (KeyValuePair<Keys, ModifierKeys>) activateKey;
}
var resetCurrentKey = ReadElement(root, "reset_current", true);
if (resetCurrentKey != null)
{
ResetCurrent = (KeyValuePair<Keys, ModifierKeys>) resetCurrentKey;
}
var excelSaveKey = ReadElement(root, "excel_save", true);
if (excelSaveKey != null)
{
ExcelSave = (KeyValuePair<Keys, ModifierKeys>) excelSaveKey;
}
Copy = new List<CopyKey>();
CopyData(xml);
}