From 8ae0cd8e4f101e825097a8681564b35632d23d2c Mon Sep 17 00:00:00 2001 From: Kelly Elton Date: Sun, 20 Mar 2011 22:11:55 +0000 Subject: [PATCH] Removed xml schema test. --- ocust/ocust/DeepGameScan.xaml.cs | 55 +++++++++++++++++++++++++-- ocust/ocust/GameSelect.xaml.cs | 2 + ocust/ocust/XmlStuff.cs | 64 ++++++++++++++++++++++++++++++++ ocust/ocust/ocust.csproj | 1 + 4 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 ocust/ocust/XmlStuff.cs diff --git a/ocust/ocust/DeepGameScan.xaml.cs b/ocust/ocust/DeepGameScan.xaml.cs index 1ee078c..0c85fa2 100644 --- a/ocust/ocust/DeepGameScan.xaml.cs +++ b/ocust/ocust/DeepGameScan.xaml.cs @@ -1,5 +1,9 @@ -using System.Windows; +using System; +using System.IO; +using System.Windows; using System.Windows.Controls; +using System.Windows.Media; +using ocust.Structure; namespace ocust { @@ -13,12 +17,57 @@ public DeepGameScan() InitializeComponent(); } + private void echo(String s) + { + ListBoxItem li = new ListBoxItem(); + li.Foreground = Brushes.Black; + li.Content = s; + listBox1.Items.Add(li); + } + + private void echo(string s, Brush c) + { + ListBoxItem li = new ListBoxItem(); + li.Foreground = c; + li.Content = s; + listBox1.Items.Add(li); + } + private void btnStart_Click(object sender, RoutedEventArgs e) { btnStart.IsEnabled = false; + listBox1.Items.Clear(); + echo("Game File Location Correct :" + App.Game.Filename, Brushes.Green); + echo("Set File Locations Correct", Brushes.Green); + echo("Unzipping game file"); + App.Unzip_Files(); - listBox1.Items.Add("Game File Location Correct :" + App.Game.Filename); - listBox1.Items.Add("Set File Locations Correct"); + Octgn.Game g = new Octgn.Game(Octgn.Definitions.GameDef.FromO8G(App.Game.Filename)); + echo("Loading Relationship File..."); + App.Load_Relationships(); + echo("Verifying Relationship file targets..."); + foreach (Relationship r in App.Relationships) + { + string checkloc = App.UnzipPath + r.Target.Replace("/", "\\"); + if (File.Exists(checkloc)) + { + echo(" " + "Target: " + r.Target + " Exists.", Brushes.Green); + } + else + { + echo(" " + "Target: " + r.Target + " Doesn't Exist!", Brushes.Red); + } + } + echo("Done Verifying Relationship File Targets."); + //XmlStuff x = new XmlStuff(); + //if (x.validateXml(App.UnzipPath + "\\" + App.gameFilePrefix + ".xml")) + //{ + // echo(App.gameFilePrefix + ".xml Is valid."); + //} + //else + //{ + // echo(App.gameFilePrefix + ".xml is corrupt, you should redownload this file.", Brushes.Red); + //} btnStart.IsEnabled = true; } diff --git a/ocust/ocust/GameSelect.xaml.cs b/ocust/ocust/GameSelect.xaml.cs index 3860455..9ac221b 100644 --- a/ocust/ocust/GameSelect.xaml.cs +++ b/ocust/ocust/GameSelect.xaml.cs @@ -11,6 +11,7 @@ public partial class GameSelect : Page public GameSelect() { InitializeComponent(); + App.Game = gameSelector.Game; //MessageBox.Show(gameSelector.Game.Filename); } @@ -27,6 +28,7 @@ private void btnNext_Click(object sender, RoutedEventArgs e) private void btnDeepScan_Click(object sender, RoutedEventArgs e) { + App.Game = gameSelector.Game; NavigationService.Navigate(new DeepGameScan()); } } diff --git a/ocust/ocust/XmlStuff.cs b/ocust/ocust/XmlStuff.cs new file mode 100644 index 0000000..dbdf1a9 --- /dev/null +++ b/ocust/ocust/XmlStuff.cs @@ -0,0 +1,64 @@ +using System; +using System.IO; +using System.Xml; +using System.Xml.Schema; + +namespace ocust +{ + public class XmlStuff + { + public bool m_Success = true; + + public bool validateXml(String infile) + { + //First we create the xmltextreader + XmlTextReader xmlr = new XmlTextReader(infile); + //We pass the xmltextreader into the xmlvalidatingreader + //'This will validate the xml doc with the schema file + //'NOTE the xml file it self points to the schema file + XmlValidatingReader xmlvread = new XmlValidatingReader(xmlr); + // + // // ' Set the validation event handler + xmlvread.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack); + m_Success = true; //'make sure to reset the success var + // + // //' Read XML data + while (xmlvread.Read()) { } + + //'Close the reader. + xmlvread.Close(); + + //'The validationeventhandler is the only thing that would set m_Success to false + return m_Success; + } + + public void ValidationCallBack(Object sender, ValidationEventArgs args) + { + //'Display the validation error. This is only called on error + m_Success = false; //'Validation failed + //writertbox("Validation error: " + args.Message); + App.addDebugLine("Validation Error: " + args.Message); + } + + public bool validateSchema(String infilename) + { + //this function will validate the schema file (xsd) + + XmlSchema myschema; + m_Success = true; //'make sure to reset the success var + StreamReader sr = new StreamReader(infilename); + try + { + //sr = new StreamReader(infilename); + myschema = XmlSchema.Read(sr, new ValidationEventHandler(ValidationCallBack)); + //'This compile statement is what ususally catches the errors + myschema.Compile(new ValidationEventHandler(ValidationCallBack)); + } + finally + { + sr.Close(); + } + return m_Success; + } + } +} \ No newline at end of file diff --git a/ocust/ocust/ocust.csproj b/ocust/ocust/ocust.csproj index 9811dff..b6c2dcd 100644 --- a/ocust/ocust/ocust.csproj +++ b/ocust/ocust/ocust.csproj @@ -164,6 +164,7 @@ Splash.xaml + Designer MSBuild:Compile