Created
February 12, 2014 18:40
-
-
Save hounsell/8961811 to your computer and use it in GitHub Desktop.
Old XmlDocument-based Keyreader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Drawing; | |
using System.Text; | |
using System.Windows.Forms; | |
using System.Xml; | |
using System.IO; | |
namespace TechnetKeyReader | |
{ | |
public partial class KeyReader : Form | |
{ | |
public KeyReader() | |
{ | |
InitializeComponent(); | |
} | |
private void openDlg(object sender, EventArgs e) | |
{ | |
openXmlDlg.ShowDialog(); | |
Properties.Settings.Default.lastFile = openXmlDlg.FileName; | |
loadXmlFunc(null, null); | |
} | |
private void loadXmlFunc(object sender, EventArgs e) | |
{ | |
StreamReader readThatXml; | |
XmlTextReader parseThatXml; | |
XmlDocument thatXmlDoc = new XmlDocument(); | |
try | |
{ | |
readThatXml = new StreamReader(Properties.Settings.Default.lastFile); | |
parseThatXml = new XmlTextReader(readThatXml); | |
thatXmlDoc.Load(parseThatXml); | |
} | |
catch (XmlException XmlEx) | |
{ | |
MessageBox.Show(XmlEx.Message); | |
} | |
catch (Exception Ex) | |
{ | |
MessageBox.Show(Ex.Message); | |
} | |
/* Parse Time */ | |
XmlNodeList productNames = thatXmlDoc.SelectNodes("YourKey/Product_Key"); | |
int currentNode = 0; | |
KeyNode[] KeyGroups = new KeyNode[productNames.Count]; | |
foreach (XmlNode product in productNames) | |
{ | |
KeyGroups[currentNode] = new KeyNode(); | |
KeyGroups[currentNode].id = currentNode; | |
KeyGroups[currentNode].productName = product.Attributes["Name"].Value; | |
XmlNodeList Keys = product.SelectNodes("Key"); | |
KeyGroups[currentNode].keys = new string[Keys.Count]; | |
int currentKey = 0; | |
foreach (XmlNode key in Keys) | |
{ | |
KeyGroups[currentNode].keys[currentKey] = key.InnerText; | |
currentKey++; | |
} | |
currentNode++; | |
} | |
productTree.Nodes.Clear(); | |
string newLine = Environment.NewLine; | |
foreach (KeyNode keyInfo in KeyGroups) | |
{ | |
productTree.Nodes.Add(keyInfo.id.ToString(), keyInfo.productName); | |
foreach (string Key in keyInfo.keys) | |
{ | |
productTree.Nodes[keyInfo.id.ToString()].Nodes.Add(Key); | |
} | |
} | |
} | |
private void copyKey(object sender, EventArgs e) | |
{ | |
if (productTree.SelectedNode.Level == 0) | |
{ | |
Clipboard.SetText(productTree.SelectedNode.Nodes[0].Text); | |
} | |
else | |
{ | |
Clipboard.SetText(productTree.SelectedNode.Text); | |
} | |
} | |
private void copyName(object sender, EventArgs e) | |
{ | |
if (productTree.SelectedNode.Level == 0) | |
{ | |
Clipboard.SetText(productTree.SelectedNode.Text); | |
} | |
else | |
{ | |
Clipboard.SetText(productTree.SelectedNode.Parent.Text); | |
} | |
} | |
private void showAbout(object sender, EventArgs e) | |
{ | |
about aboutFrm = new about(); | |
aboutFrm.Show(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment