private void buttonSave_Click(object sender, EventArgs e) { try { // Send restore command NotificationIcon.Execute(DataInterface.NOTIFY_SAVE, false); buttonSave.Enabled = !NotificationIcon.SettingsSaved; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
void ButtonApplyClick(object sender, EventArgs e) { // Apply new settings try { for (int i = 0; i < PstateFid.Length; i++) { UInt64 en = Convert.ToUInt64(PstateEn[i].Checked); UInt64 fid = Convert.ToUInt64(((CustomListItem)PstateFid[i].SelectedItem).value); UInt64 did = Convert.ToUInt64(((CustomListItem)PstateDid[i].SelectedItem).value); UInt64 vid = Convert.ToUInt64(((CustomListItem)PstateVid[i].SelectedItem).value); UInt64 ps = NotificationIcon.di.MemRead(DataInterface.REG_P0 + i); ps &= 0x7FFFFFFFFFC00000; ps |= (en & 1) << 63 | (vid & 0xFF) << 14 | (did & 0xFF) << 8 | fid & 0xFF; NotificationIcon.di.MemWrite(DataInterface.REG_P0 + i, ps); } UInt64 flags = 0; if (checkBoxApplyOnStart.Checked) { flags |= DataInterface.FLAG_APPLY_AT_START; } if (checkBoxGuiOnStart.Checked) { flags |= DataInterface.FLAG_TRAY_ICON_AT_START; } if (checkBoxP80temp.Checked) { flags |= DataInterface.FLAG_P80_TEMP_EN; } if (checkBoxC6Core.Checked) { flags |= DataInterface.FLAG_C6CORE; } if (checkBoxC6Package.Checked) { flags |= DataInterface.FLAG_C6PACKAGE; } if (checkBoxCpb.Checked) { flags |= DataInterface.FLAG_CPB; } int ppt = 0, tdc = 0, edc = 0, scalar = 0; if (!int.TryParse(textBoxPPT.Text, out ppt)) { MessageBox.Show("Bad PPT value."); return; } if (!int.TryParse(textBoxTDC.Text, out tdc)) { MessageBox.Show("Bad TDC value."); return; } if (!int.TryParse(textBoxEDC.Text, out edc)) { MessageBox.Show("Bad EDC value."); return; } if (!int.TryParse(textBoxScalar.Text, out scalar) || scalar < 1 || scalar > 10) { MessageBox.Show("Bad Scalar value."); return; } NotificationIcon.di.MemWrite(DataInterface.REG_PPT, (UInt64)ppt); NotificationIcon.di.MemWrite(DataInterface.REG_TDC, (UInt64)tdc); NotificationIcon.di.MemWrite(DataInterface.REG_EDC, (UInt64)edc); NotificationIcon.di.MemWrite(DataInterface.REG_SCALAR, (UInt64)scalar); NotificationIcon.di.MemWrite(DataInterface.REG_PERF_BIAS, (UInt64)comboBoxPerfbias.SelectedIndex); NotificationIcon.di.MemWrite(DataInterface.REG_CLIENT_FLAGS, flags); // Send update flag command NotificationIcon.Execute(DataInterface.NOTIFY_CLIENT_FLAGS, false); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); bool isFirstInstance; // Please use a unique name for the mutex to prevent conflicts with other programs using (Mutex mtx = new Mutex(true, Application.ProductName + " " + Application.ProductVersion, out isFirstInstance)) { if (isFirstInstance) { // Fix path Directory.SetCurrentDirectory(Application.StartupPath); // Asus check if (!isAsus()) { MessageBox.Show("This software only works on ASUS hardware", MessageBoxTitle); return; } // Check service running/installed ServiceController svc = new ServiceController("AsusZsSrv"); try { ServiceControllerStatus svc_status = svc.Status; } catch (InvalidOperationException ex) { //MessageBox.Show("AsusZsSrv not installed, attempting to install ...", MessageBoxTitle); ProcessStartInfo info = new ProcessStartInfo("sc.exe", "create AsusZsSrv binPath= \"" + Path.Combine(Application.StartupPath, "AsusZsSrv.exe") + "\" DisplayName= \"ASUS ZenStates\" start= auto"); info.UseShellExecute = true; info.Verb = "runas"; try { Process process = Process.Start(info); process.WaitForExit(10000); ServiceControllerStatus svc_status = svc.Status; } catch (Exception ex2) { MessageBox.Show("Could not install AsusZsSrv", MessageBoxTitle); return; } } if (svc.Status != ServiceControllerStatus.Running) { // Service not running, try to start it //MessageBox.Show("AsusZsSrv is not running", MessageBoxTitle); ProcessStartInfo info = new ProcessStartInfo("sc.exe", "start AsusZsSrv"); info.UseShellExecute = true; info.Verb = "runas"; try { Process process = Process.Start(info); process.WaitForExit(10000); svc.WaitForStatus(ServiceControllerStatus.Running, System.TimeSpan.FromSeconds(5)); if (svc.Status != ServiceControllerStatus.Running) { throw new Exception("AsusZsSrv couldn't start."); } } catch (Exception ex2) { MessageBox.Show("Could not start AsusZsSrv, check the Event Log for further details", MessageBoxTitle); return; } } NotificationIcon notificationIcon; try { notificationIcon = new NotificationIcon(); } catch (Exception ex) { MessageBox.Show(ex.Message, MessageBoxTitle); return; } notificationIcon.notifyIcon.Visible = true; Application.Run(); notificationIcon.notifyIcon.Dispose(); } else { // The application is already running // TODO: Display message box or change focus to existing application instance } } // releases the Mutex }