public static void update() { if (getUpdateStatus(VERSION, getOnelineFile(versionFileURL))) { var msgbox = MessageBox.Show("A update is available! \n\nClient version: " + VERSION + "\nLatest version: " + getOnelineFile(versionFileURL) + "\n\nDo you want to downlaod the lates version now?", "Update available", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); if (msgbox == DialogResult.Yes) { cXMLdataSet set = new cXMLdataSet(); set.leftMouseCounter = Settings.Default.leftMouseCounter.ToString(); set.rightMouseCounter = Settings.Default.rightMouseCounter.ToString(); cXMLSerializer.writeXML(set, "_update_data.xml"); WebClient client = new WebClient(); client.DownloadFile(getOnelineFile(downloadFileURL), "mouseCounterUpdate.exe"); StreamWriter w = new StreamWriter("updatescript.bat"); w.WriteLine("@echo off"); w.WriteLine("if exist mouseCounter.exe ("); w.WriteLine(" del mouseCounter.exe"); w.WriteLine(" ren mouseCounterUpdate.exe mouseCounter.exe"); w.WriteLine(" start mouseCounter.exe"); w.WriteLine(") else ("); w.WriteLine(" echo You have probably renamed the file mouseCounter.exe so the update script can not find the file. Pelase rename it to the ortiginal name to continue!"); w.WriteLine(" pause )"); w.WriteLine("del updatescript.bat"); w.Close(); Process.Start("updatescript.bat"); Application.Exit(); } } }
private void fMain_Load(object sender, EventArgs e) { if (Settings.Default.testForUpdate) { cUpdate.update(); } timer.Start(); cMouseHookLEFT.Start(); cMouseHookLEFT.MouseAction += new EventHandler(eventMouseLEFT); cMouseHookRIGHT.Start(); cMouseHookRIGHT.MouseAction += new EventHandler(eventMouseRIGHT); ContextMenu cm = new ContextMenu(); cm.MenuItems.Add("Settings", new EventHandler(openSettings)); cm.MenuItems.Add("Help", new EventHandler(openHelp)); this.ContextMenu = cm; if (File.Exists("_update_data.xml")) { XmlSerializer ser = new XmlSerializer(typeof(cXMLdataSet)); FileStream read = new FileStream("_update_data.xml", FileMode.Open, FileAccess.Read, FileShare.Read); cXMLdataSet set = (cXMLdataSet)ser.Deserialize(read); Settings.Default.rightMouseCounter = Convert.ToInt32(set.rightMouseCounter); Settings.Default.leftMouseCounter = Convert.ToInt32(set.leftMouseCounter); } lbRightCounter.Text = lableRightCounter + Settings.Default.rightMouseCounter; lbLeftCounter.Text = lableLeftCounter + Settings.Default.leftMouseCounter; }
private void btInport_Click(object sender, EventArgs e) { openFileDialog.ShowDialog(); XmlSerializer ser = new XmlSerializer(typeof(cXMLdataSet)); FileStream read = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read); cXMLdataSet set = (cXMLdataSet)ser.Deserialize(read); nudLeftValue.Value = Convert.ToDecimal(set.leftMouseCounter); nudRightValue.Value = Convert.ToDecimal(set.rightMouseCounter); }
private void btExport_Click(object sender, EventArgs e) { saveFileDialog.ShowDialog(); try { cXMLdataSet set = new cXMLdataSet(); set.leftMouseCounter = Settings.Default.leftMouseCounter.ToString(); set.rightMouseCounter = Settings.Default.rightMouseCounter.ToString(); writeXML(set, saveFileDialog.FileName); MessageBox.Show("File saved in \"" + saveFileDialog.FileName + "\"!", "File saved.", MessageBoxButtons.OK); } catch (Exception ex) { MessageBox.Show(ex.Message); } }