Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // 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 bool isFirstInstance))
            {
                if (isFirstInstance)
                {
                    // Fix path
                    Directory.SetCurrentDirectory(Application.StartupPath);

                    // Set motherboard vendor and CPU info
                    initVendorInfo();

                    // Check service running/installed
                    ServiceController svc = new ServiceController("ZenStatesSrv");

                    try
                    {
                        ServiceControllerStatus svc_status = svc.Status;
                    }
                    catch (InvalidOperationException ex)
                    {
                        //MessageBox.Show("ZenStatesSrv not installed, attempting to install ...", MessageBoxTitle);
                        ProcessStartInfo info = new ProcessStartInfo("sc.exe", "create ZenStatesSrv binPath= \"" + Path.Combine(Application.StartupPath, "ZenStatesSrv.exe") + "\" DisplayName= \"ZenStates\" start= auto")
                        {
                            UseShellExecute = true,
                            Verb            = "runas"
                        };
                        try
                        {
                            Process process = Process.Start(info);
                            process.WaitForExit(10000);
                            ServiceControllerStatus svc_status = svc.Status;
                        }
                        catch (Exception ex2)
                        {
                            MessageBox.Show("Could not install ZenStatesSrv", MessageBoxTitle);
                            return;
                        }
                    }

                    if (svc.Status != ServiceControllerStatus.Running)
                    {
                        // Service not running, try to start it
                        //MessageBox.Show("ZenStatesSrv is not running", MessageBoxTitle);
                        ProcessStartInfo info = new ProcessStartInfo("sc.exe", "start ZenStatesSrv")
                        {
                            UseShellExecute = true,
                            Verb            = "runas"
                        };
                        try
                        {
                            Process process = Process.Start(info);
                            process.WaitForExit(10000);
                            svc.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(5));
                            if (svc.Status != ServiceControllerStatus.Running)
                            {
                                throw new Exception("ZenStatesSrv couldn't start.");
                            }
                        }
                        catch (Exception ex2)
                        {
                            MessageBox.Show("Could not start ZenStatesSrv, 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
        }
Esempio n. 3
0
        void ButtonApplyClick(object sender, EventArgs e)
        {
            // Apply new settings
            try
            {
                if (radioManualControl.Checked)
                {
                    UInt64 ocFid = Convert.ToUInt64(((CustomListItem)PstateOcFid.SelectedItem).value);
                    UInt64 ocDid = Convert.ToUInt64(((CustomListItem)PstateOcDid.SelectedItem).value);
                    UInt64 ocVid = Convert.ToUInt64(((CustomListItem)PstateOcVid.SelectedItem).value);
                    UInt64 ocPs  = NotificationIcon.di.MemRead(DataInterface.REG_PSTATE_OC);

                    ocPs &= 0xFFFFFFFFFFC00000;
                    ocPs |= (ocVid & 0xFF) << 14 | (ocDid & 0xFF) << 8 | ocFid & 0xFF;

                    NotificationIcon.di.MemWrite(DataInterface.REG_PSTATE_OC, ocPs);
                    if (!isZen2)
                    {
                        for (int i = 0; i < PSTATES - 1; i++)
                        {
                            UInt64 en = Convert.ToUInt64(PstateEn[i].Checked);
                            ocPs |= (en & 1) << 63;
                            NotificationIcon.di.MemWrite(DataInterface.REG_P0 + i, ocPs);
                            PstateFid[i].SelectedItem = PstateOcFid.SelectedItem;
                            PstateDid[i].SelectedItem = PstateOcDid.SelectedItem;
                            PstateVid[i].SelectedItem = PstateOcVid.SelectedItem;
                        }
                    }
                }
                else
                {
                    if (isZen2)
                    {
                        // Pstate2
                        UInt64 fid = Convert.ToUInt64(((CustomListItem)BoostFreqFid[2].SelectedItem).value);
                        UInt64 did = Convert.ToUInt64(((CustomListItem)BoostFreqDid[2].SelectedItem).value);

                        UInt64 ps = NotificationIcon.di.MemRead(DataInterface.REG_P2);

                        ps &= 0xFFFFFFFFFFFF0000;
                        ps |= (did & 0xFF) << 8 | fid & 0xFF;

                        NotificationIcon.di.MemWrite(DataInterface.REG_P2, ps);

                        // Max boost frequencies
                        for (int i = 0; i < 2; i++)
                        {
                            fid = Convert.ToUInt64(((CustomListItem)BoostFreqFid[i].SelectedItem).value);
                            did = Convert.ToUInt64(((CustomListItem)BoostFreqDid[i].SelectedItem).value);
                            // double freq = (25 * boostFid / (boostDid * 12.5)) * 100;
                            ps = NotificationIcon.di.MemRead(DataInterface.REG_BOOST_FREQ_0 + i);

                            ps &= 0xFFFFFFFFFFFF0000;
                            ps |= (did & 0xFF) << 8 | fid & 0xFF;

                            NotificationIcon.di.MemWrite(DataInterface.REG_BOOST_FREQ_0 + i, ps);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < PSTATES; 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);
                        }

                        NotificationIcon.di.MemWrite(DataInterface.REG_PSTATE_OC, NotificationIcon.di.MemRead(DataInterface.REG_P0));
                        PstateOcFid.SelectedItem = PstateFid[0].SelectedItem;
                        PstateOcDid.SelectedItem = PstateDid[0].SelectedItem;
                        PstateOcVid.SelectedItem = PstateVid[0].SelectedItem;
                    }
                }

                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;
                }
                if (radioManualControl.Checked)
                {
                    flags |= DataInterface.FLAG_OC;
                }

                if (!int.TryParse(textBoxPPT.Text, out int ppt))
                {
                    MessageBox.Show("Bad PPT value.");
                    return;
                }
                if (!int.TryParse(textBoxTDC.Text, out int tdc))
                {
                    MessageBox.Show("Bad TDC value.");
                    return;
                }
                if (!int.TryParse(textBoxEDC.Text, out int edc))
                {
                    MessageBox.Show("Bad EDC value.");
                    return;
                }
                if (!int.TryParse(textBoxScalar.Text, out int 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, true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }