private bool ReadDictionaryReferencesFromURI(ref ReferenceDictionaries oRefDicts, string sURI) { // open list of available Nayiri dictionaries WebClient client = new WebClient(); Stream data = null; TextReader reader = null; bool nSuccess = true; //client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"); //if using queries try { data = client.OpenRead(sURI); reader = new StreamReader(data); XmlSerializer deserializer = new XmlSerializer(typeof(ReferenceDictionaries)); oRefDicts = (ReferenceDictionaries)deserializer.Deserialize(reader); } catch (Exception ex) { nSuccess = false; } finally { if (data != null) { data.Close(); } if (reader != null) { reader.Close(); } } return(nSuccess); }
private void lnkUpdateRefDicts_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { string sPrimaryURI = Properties.Settings.Default.PrimaryReferenceDictionaryURI; string sSecondaryURI = Properties.Settings.Default.SecondaryReferenceDictionaryURI; ReferenceDictionaries oRefDicts = new ReferenceDictionaries(); bool bProceed = true; if (!ReadDictionaryReferencesFromURI(ref oRefDicts, sPrimaryURI)) { if (!ReadDictionaryReferencesFromURI(ref oRefDicts, sSecondaryURI)) { MessageBox.Show("Cannot find dictionary reference XML file!", "HySpell Setup and Diagnostics [Dictionaries]", MessageBoxButtons.OK, MessageBoxIcon.Information); bProceed = false; } } if (bProceed) { // open dialog with listing for user selection DicionaryReferenceList dlg = new DicionaryReferenceList(); dlg.RefDicts = oRefDicts; DialogResult dlgResult = dlg.ShowDialog(); if (dlgResult == System.Windows.Forms.DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; string uri = sSecondaryURI.Replace("OnlineDicReferences.xml", ""); string localPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HySpell\\"; if (DownloadDictFile(uri, localPath)) { DecompressDictFile(localPath + "DictionaryUpdate.zip", localPath); } // progam writes the new XML file to the User Application Data under HySpell folder string sPath = localPath + "OnlineDicReferences.xml"; TextWriter writer = null; try { XmlSerializer xmlSer = new XmlSerializer(typeof(ReferenceDictionaries)); writer = new StreamWriter(sPath); xmlSer.Serialize(writer, dlg.OutRefDicts); writer.Close(); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message, "HySpell Setup and Diagnostics [Dictionaries]", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } finally { if (writer != null) { writer.Close(); } } Cursor.Current = Cursors.Default; } } }