private void MainForm_Shown(object sender, EventArgs e) { // current version string current_version = Config.Local.CurrentVersion; // check latest version string lastest_version = Config.Remote.GetRemoteGlobalVersion("lastest"); if (lastest_version != null && current_version != null) { string lastest_version_checked = Config.Local.GetParameter("Last Version Check"); if (lastest_version_checked == null || lastest_version_checked == "") { lastest_version_checked = Config.Local.CurrentVersion; Config.Local.SetParameter("Last Version Check", lastest_version); Config.Local.Save(); } if (RemoteConfig.CompareVersions(lastest_version, lastest_version_checked) == 1) { // keep new version in config file Config.Local.SetParameter("Last Version Check", lastest_version); Config.Local.Save(); if (RemoteConfig.CompareVersions(lastest_version, Config.Local.CurrentVersion) == 1) { string message = "A newer version (" + lastest_version + ") of OptionsOracle is available. Download? "; string caption = "New Version is Available"; if (MessageBox.Show(message, caption, MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { Global.OpenExternalBrowser(Config.Remote.GetRemoteGlobalUrl("download")); Close(); } } } } }
private void CheckUpdates() { if (remote == null) { return; } if (remote.Xml == null) { return; } for (int i = 0; ; i++) { // get server name string server_name = remote.GetAttributeByIndex(null, i, "server", "name"); if (server_name == null) { return; } // get server node XmlNode server_nd = remote.GetNodeByNameAndAttribute(null, "server", "name", server_name); if (server_nd == null) { continue; } // get global node XmlNode global_nd = remote.GetNodeByNameAndAttribute(server_nd, "global", null, null); if (global_nd == null) { continue; } // get last-version node XmlNode version_nd = remote.GetNodeByNameAndAttribute(global_nd, "node", "name", "lastest-version"); if (version_nd == null) { continue; } string last_version = remote.GetAttrValueByName(version_nd, "value"); // get download-page node XmlNode page_nd = remote.GetNodeByNameAndAttribute(global_nd, "node", "name", "download-page"); if (page_nd == null) { continue; } string download_page = remote.GetAttrValueByName(page_nd, "value"); // get download-mode node string download_mode = null; XmlNode mode_nd = remote.GetNodeByNameAndAttribute(global_nd, "node", "name", "download-mode"); if (mode_nd != null) { download_mode = remote.GetAttrValueByName(mode_nd, "value"); } try { string path = AppDomain.CurrentDomain.BaseDirectory; string file = System.IO.Path.GetFileName(download_page); string full = Path.Combine(path, file); bool update = false; bool remove = false; string local_version = "0.0.0.0"; if (download_mode == "always" || download_mode == "upgrade") { if (File.Exists(full)) { Assembly assembly = Assembly.LoadFrom(full); if (assembly != null) { local_version = assembly.GetName().Version.ToString(); update = (RemoteConfig.CompareVersions(last_version, local_version) == 1); } } else if (download_mode == "always") { update = true; } } else if (download_mode == "remove") { if (File.Exists(full)) { remove = true; } } if (update) { update_list.Add(new UpdateInfo(server_name, local_version, last_version, download_page)); } if (remove) { remove_list.Add(new UpdateInfo(server_name, local_version, "0.0.0.0", download_page)); } } catch { } } }
public void Initialize() { // update proxy settings cap.ProxyAddress = Config.Local.ProxyAddress; cap.UseProxy = Config.Local.UseProxy; // get config directory path string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\OptionsOracle\"; string conf = path + module_file; // check if config directory exist, if not create it if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } // load / create-new configuration if (File.Exists(conf)) { try { // load xml from local configuration file xml.Load(conf); if (RemoteConfig.CompareVersions(Config.Remote.GetLatestRemoteModuleVersion(module), GetVersion()) == 1) { // newer wizard file is available online, get it XmlDocument xml_online = cap.DownloadXmlWebFile(Config.Remote.GetRemoteModuleUrl(module)); if (xml_online != null) { // update global xml file with latest one xml = xml_online; // save local xml document XmlWriterSettings wr_settings = new XmlWriterSettings(); wr_settings.Indent = true; XmlWriter wr = XmlWriter.Create(conf, wr_settings); xml.Save(wr); } } } catch { xml = new XmlDocument(); } } if (xml.FirstChild == null) { try { // get online xml document xml = cap.DownloadXmlWebFile(Config.Remote.GetRemoteModuleUrl(module)); if (xml != null && xml.FirstChild != null) { // save local xml document XmlWriterSettings wr_settings = new XmlWriterSettings(); wr_settings.Indent = true; XmlWriter wr = XmlWriter.Create(conf, wr_settings); xml.Save(wr); } } catch { } } }
public void Initialize(string config) { // update proxy settings cap.ProxyAddress = Config.Local.ProxyAddress; cap.UseProxy = Config.Local.UseProxy; // get config directory path string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\OptionsOracle\"; string conf = path + PARSER_FILE; // check if config directory exist, if not create it if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } // load / create-new configuration if (File.Exists(conf)) { try { // load xml from local configuration file xd.Load(conf); // initialize dynamic parser helper class dp = new DynamicParser(xd); if (RemoteConfig.CompareVersions(Config.Remote.GetLatestRemoteModuleVersion("parser"), dp.GetParserVersion()) == 1) { // newer parser file is available online, get it XmlDocument xd_online = cap.DownloadXmlWebFile(Config.Remote.GetRemoteModuleUrl("parser")); if (xd_online != null) { // update global xml file with latest one xd = xd_online; // save local xml document XmlWriterSettings wr_settings = new XmlWriterSettings(); wr_settings.Indent = true; XmlWriter wr = XmlWriter.Create(conf, wr_settings); xd.Save(wr); // recreate dynamic parser helper class with new xml file dp = new DynamicParser(xd); } } } catch { xd = new XmlDocument(); } } if (xd.FirstChild == null) { try { // get online xml document xd = cap.DownloadXmlWebFile(Config.Remote.GetRemoteModuleUrl("parser")); if (xd != null && xd.FirstChild != null) { // save local xml document XmlWriterSettings wr_settings = new XmlWriterSettings(); wr_settings.Indent = true; XmlWriter wr = XmlWriter.Create(conf, wr_settings); xd.Save(wr); // initialize dynamic parser helper class dp = new DynamicParser(xd); } else { dp = null; } } catch { } } }