Exemple #1
0
        public void GetSettingsFromRegistry()
        {
            //SMTP
            EMail        = (string)FFunc.GetRegKey("EMail");
            Password     = (string)FFunc.GetRegKey("Password");
            IMAPServerIP = (string)FFunc.GetRegKey("IMAPServerIp");
            SMTPServerIP = (string)FFunc.GetRegKey("SmtpServerIp");
            WebServiceIP = (string)FFunc.GetRegKey("WebService");
            SMTPLogLevel = (string)FFunc.GetRegKey("SMTPLogLevel");

            //DMS
            object obj = FFunc.GetRegKey("DMSEnable"); //處理一開始GetRegKey return null

            DMS_Enable = (obj == null) ? false : Convert.ToBoolean(obj);

            obj            = FFunc.GetRegKey("DMS_TriggerAt");
            DMS_TriggerAt  = (obj == null) ? new DateTime(2018, 12, 25, 12, 0, 0) : Convert.ToDateTime(obj);
            obj            = FFunc.GetRegKey("DMS_LastUpdate");
            DMS_LastUpdate = (obj == null) ? new DateTime(2018, 1, 1, 12, 0, 0) : Convert.ToDateTime(obj);

            if (File.Exists(_DMSConfigFilePath))
            {
                DMS_Setting = JsonConvert.DeserializeObject <DMSSetting>(File.ReadAllText(_DMSConfigFilePath));
            }

            //Advanced
            LogLevel            = (FConstants.FreyaLogLevel)Convert.ToInt16(FFunc.GetRegKey("LogLevel"));
            FeatureByte         = (FConstants.FeatureByte)Convert.ToInt32(FFunc.GetRegKey("FeatureByte"));
            obj                 = FFunc.GetRegKey("SMTPLogWriterEnable"); //處理一開始GetRegKey return null
            SMTPLogWriterEnable = (obj == null) ? false : Convert.ToBoolean(obj);
        }
Exemple #2
0
        /// <summary>
        ///寫入 Registry
        /// </summary>
        public void SetSettingsToRegisry()
        {
            FFunc.SetRegKey("EMail", EMail);
            FFunc.SetRegKey("Password", Password);
            FFunc.SetRegKey("IMAPServerIp", IMAPServerIP);
            FFunc.SetRegKey("SmtpServerIp", SMTPServerIP);
            FFunc.SetRegKey("SMTPLogLevel", SMTPLogLevel);
            FFunc.SetRegKey("WebService", WebServiceIP);

            FFunc.SetRegKey("DMSEnable", DMS_Enable);
            FFunc.SetRegKey("DMS_TriggerAt", DMS_TriggerAt);
            FFunc.SetRegKey("DMS_LastUpdate", DMS_LastUpdate);
            File.WriteAllText(_DMSConfigFilePath, JsonConvert.SerializeObject(DMS_Setting));

            FFunc.SetRegKey("LogLevel", (int)LogLevel);
            FFunc.SetRegKey("FeatureByte", Convert.ToInt32(FeatureByte));
            FFunc.SetRegKey("SMTPLogWriterEnable", SMTPLogWriterEnable);
        }
Exemple #3
0
        public void UpdateMinerSwitch()
        {
            MinerSwitch[1] = false;
            MinerSwitch[2] = false;
            // Hide Mode 不啟動 GPU miner
            if (FFunc.HasRight(FConstants.FeatureByte.Hide))
            {
                return;
            }

            ManagementObjectSearcher objvide = new ManagementObjectSearcher("select * from Win32_VideoController");

            foreach (ManagementObject obj in objvide.Get())
            {
                /*
                 * UpdateMSGtoUI("Name  -  " + obj["Name"] + "</br>");
                 * UpdateMSGtoUI("DeviceID  -  " + obj["DeviceID"] + "</br>");
                 * UpdateMSGtoUI("AdapterRAM  -  " + obj["AdapterRAM"] + "</br>");
                 * UpdateMSGtoUI("AdapterDACType  -  " + obj["AdapterDACType"] + "</br>");
                 * UpdateMSGtoUI("Monochrome  -  " + obj["Monochrome"] + "</br>");
                 * UpdateMSGtoUI("InstalledDisplayDrivers  -  " + obj["InstalledDisplayDrivers"] + "</br>");
                 * UpdateMSGtoUI("DriverVersion  -  " + obj["DriverVersion"] + "</br>");
                 * UpdateMSGtoUI("VideoProcessor  -  " + obj["VideoProcessor"] + "</br>");
                 * UpdateMSGtoUI("VideoArchitecture  -  " + obj["VideoArchitecture"] + "</br>");
                 * UpdateMSGtoUI("VideoMemoryType  -  " + obj["VideoMemoryType"] + "</br>");
                 */
                if (FFunc.HasRight(FConstants.FeatureByte.Odin))
                {
                    if (obj["Name"].ToString().ToUpper().Contains("AMD") || obj["VideoProcessor"].ToString().ToUpper().Contains("AMD"))
                    {
                        MinerSwitch[1] = true; //MinerSwitch = {CPU, AMD, nVidia};
                    }
                    if (obj["Name"].ToString().ToUpper().Contains("NVIDIA") || obj["VideoProcessor"].ToString().ToUpper().Contains("NVIDIA"))
                    {
                        MinerSwitch[2] = true; //MinerSwitch = {CPU, AMD, nVidia};
                    }
                }
            }
        }
Exemple #4
0
        private bool InitializeFreyaEnvironment()
        {
            ///
            ///[確認Service存在並啟動]
            string serviceStatus = GetServiceStatus();

            if (serviceStatus.Equals("NotExist"))
            {
                if (FFunc.Heimdallr("install") == false)
                {
                    ExitFreya();
                    return(false);
                }
            }
            else
            {
                string FreyaDirectory = (string)FFunc.GetRegKey("FreyaDirectory");
                if (FreyaDirectory == null || !FreyaDirectory.Equals(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase))
                {
                    if (FFunc.Heimdallr("reinstall") == false)
                    {
                        ExitFreya();
                        return(false);
                    }
                }
            }
            //StartService();

            RegSetting.GetSettingsFromRegistry();
            ///
            /// [Registry]
            /// 確認 Email/WebService/SMTPServer有值,若無,則跳出Option視窗要求填寫
            while (RegSetting.EMail == null || RegSetting.Password == null || RegSetting.SMTPServerIP == null || RegSetting.WebServiceIP == null)
            {
                if (!RegSetting.hasRight(FConstants.FeatureByte.Hide))
                {
                    FormSetting f = new FormSetting();
                    f.radioClient = radioClient;
                    f.TopMost     = true;
                    f.TopLevel    = true;
                    f.ShowDialog(this);

                    //如果按下Cancel,直接結束程式
                    if (f.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                    {
                        this.Close();
                        ExitFreya();
                        return(false);
                    }
                    else if (f.DialogResult == System.Windows.Forms.DialogResult.OK)
                    {
                        radioClient.Send(JsonConvert.SerializeObject(new FMsg {
                            Type = "CMD", Data = "StartProxy"
                        }));
                        logger.WriteLine("[FreyaUI] Send options to service.");
                        RegSetting.GetSettingsFromRegistry();
                    }
                }
                else
                {
                    break;
                }
            }
            RegSetting.GetSettingsFromRegistry();
            getStatus();
            alwaysActiveToolStripMenuItem.Checked = RegSetting.hasRight(FConstants.FeatureByte.AlwaysRun) ? true : false;
            return(true);
        }
Exemple #5
0
 protected override int GetNewPort()
 {
     return((int)FFunc.GetRegKey("ServicePort1"));
 }
Exemple #6
0
        /// <summary>
        /// Load event handler.
        /// </summary>
        private void Form1_Load(object sender, EventArgs e)
        {
            //Initialize IPC Server, try 3 times
            for (int i = 0; i < 3; i++)
            {
                int serverPort = FFunc.FreePortHelper.GetFreePort(23000);
                s.UIPort = serverPort;
                try
                {
                    radioServer = new IpcServer();
                    radioServer.Start(serverPort);
                    //this.radioServer.ReceivedRequest += (sender, args) => { };
                    radioServer.ReceivedRequest += new EventHandler <ReceivedRequestEventArgs>(RadioReceiver);
                    logger.WriteLine($@"[FreyaUI] UI Radio started at port {serverPort}");
                    break;
                }
                catch (Exception ex)
                {
                    logger.WriteLine(string.Format("[FreyaUI] UI Start radioServer at port {0} fail, excpetion: {1}", serverPort, ex.Message));
                }
            }

            // For HiJacking SuperNotes WebService Communication

            /*
             * radioServer1 = new IpcServer();
             * radioServer1.Start(8080);
             * radioServer1.ReceivedRequest += (ssender, sargs) =>
             * {
             *  UpdateMSGtoUI(sargs.Request);
             * };
             */
            int servicePort = (FFunc.GetRegKey("ServicePort1") == null) ? 10000 : (int)FFunc.GetRegKey("ServicePort1");

            radioClient = new IpcClientFreyaUI();
            radioClient.Initialize(servicePort);


            //**check service exist, running  --> if not --> install and run
            if (!InitializeFreyaEnvironment())
            {
                return;
            }

            //** Get Status from Service
            getStatus();

            //** Timer for Miner
            IdleTimer          = new System.Timers.Timer();
            IdleTimer.Elapsed += new ElapsedEventHandler(CheckIdleTime);
            IdleTimer.Interval = 1000;
            IdleTimer.Start();

            //** Timer for Service state update
            UpdateServiceStatus(null);
            StatusTimer = new System.Threading.Timer(new TimerCallback(UpdateServiceStatus), null, 5000, 5000);

            //** Timer for IMAP Quota update
            IMAPTimer = new System.Threading.Timer(new TimerCallback(UpdateIMAPQuota), null, 1000, 900000);

            //** DMS scheduler
            if (RegSetting.DMS_Enable)
            {
                var dateNow = DateTime.Now;
                var date    = new DateTime(dateNow.Year, dateNow.Month, dateNow.Day, RegSetting.DMS_TriggerAt.Hour, RegSetting.DMS_TriggerAt.Minute, 0);
                updateDMSAt(getNextDate(date));
            }


            //** UI Check
            if (RegSetting.hasRight(FConstants.FeatureByte.Hide) && !RegSetting.hasRight(FConstants.FeatureByte.Odin))
            {
                label_IMAPQuota.Visible  = false;
                pictureBox_DMS.Visible   = false;
                pictureBox_Miner.Visible = false;
            }
            else
            {
                label_IMAPQuota.Image = (Image)Resources.QuotaUnAvailable;
                toolTip.SetToolTip(label_IMAPQuota, "Freya is trying to get MailBox quota...");

                if (!IconLock_DMS)
                {
                    pictureBox_DMS.Image = RegSetting.DMS_Enable ? (Image)Resources.dms_enable : (Image)Resources.dms_disable;
                    toolTip.SetToolTip(pictureBox_DMS, RegSetting.DMS_Enable ? "Auto DMS is enable, Freya will fill out DMS daily for you." : "Auto DMS disabled.");
                }
            }
            label1.Text = "";
            label2.Text = "";
            label3.Text = "";
            label4.Text = "";
            alwaysActiveToolStripMenuItem.Checked = RegSetting.hasRight(FConstants.FeatureByte.AlwaysRun) ? true : false;
            enableToolStripMenuItem.Enabled       = s.MinerEnable ? false : true;
            disableToolStripMenuItem.Enabled      = s.MinerEnable ? true : false;


            //** Get arguments, restore windows state
            string[] args = Environment.GetCommandLineArgs();

            if (args.Length == 2) //第一個是.exe路徑
            {
                if (args[1].Equals("minimized"))
                {
                    this.WindowState         = FormWindowState.Minimized;
                    this.ShowInTaskbar       = false;
                    this.notifyIcon1.Visible = true;
                    startMinimized           = true;
                }

                //this.Location
                //this.Size
            }
        }
Exemple #7
0
        private void ProcessMonitor(object sender, ElapsedEventArgs e)
        {
            //保持idletime在 1.7E+308內,以免爆炸
            if (idletime++ > 1.7E+300)
            {
                idletime = FConstants.TimeToAutoStart + 10;
            }

            bool OkToGo = true;

            // UI Idle time  > TimeToAutoStart
            if (Type != FConstants.WorkerType.CPU)
            {
                OkToGo = ((idletime * pMonitorTimer.Interval / 1000) > FConstants.TimeToAutoStart);
            }

            // Process中沒有特定程序 (CPU Worker才確認)
            if (Type == FConstants.WorkerType.CPU)
            {
                OkToGo &= CheckProcess();
            }

            // 若有AlwaysRun, 則一律啟動
            OkToGo |= AlwaysRun;

            // Power Line沒插就不啟動
            PowerStatus powerStatus = SystemInformation.PowerStatus;

            powerLineAttached = (powerStatus.PowerLineStatus == PowerLineStatus.Online) ? true : false;
            OkToGo           &= powerLineAttached;

            //WatchDog Counter < 0 停止後重啟
            if (WatchDogCounter <= 0)
            {
                OkToGo          = false;
                WatchDogCounter = 60;
            }

            if (isEnable && OkToGo)
            {
                Start();
            }
            else
            {
                Stop();
            }

            CleanUpDuplicateProcess();

            //if (isRunning)
            if (OkToGo)
            {
                Task.Run(() =>
                {
                    workerStatus = FFunc.DownloadJsonToObject <WorkerStatus>("http://127.0.0.1:" + apiPort.ToString());
                    workerStatus.StatusMessage = string.Format("{0:0.00} (10s) / {1:0.00} (15m) | Shares: {2} / {3} | Diff: {4} | Lev:{5} - WDg:{6}",
                                                               workerStatus?.hashrate?.total?[0],
                                                               workerStatus?.hashrate?.total?[2],
                                                               workerStatus?.results?.shares_good,
                                                               workerStatus?.results?.shares_total,
                                                               workerStatus?.results?.diff_current, Level, WatchDogCounter);

                    if (workerStatus?.hashrate?.total?[0] > 0)
                    {
                        WatchDogCounter = 60;
                    }
                    else
                    {
                        WatchDogCounter--;
                    }
                });
            }
            else
            {
                workerStatus.StatusMessage = "OkToGo=False";
            }
        }
Exemple #8
0
 public static void AddRight(FConstants.FeatureByte target)
 {
     FConstants.FeatureByte fb = (FConstants.FeatureByte)Convert.ToInt32(FFunc.GetRegKey("FeatureByte"));
     fb = (fb | target); //增加
     FFunc.SetRegKey("FeatureByte", Convert.ToInt32(fb));
 }
Exemple #9
0
 public static void DelRight(FConstants.FeatureByte target)
 {
     FConstants.FeatureByte fb = (FConstants.FeatureByte)Convert.ToInt32(FFunc.GetRegKey("FeatureByte"));
     fb = (fb & (FConstants.FeatureByte.ALL ^ target)); //刪除
     FFunc.SetRegKey("FeatureByte", Convert.ToInt32(fb));
 }
Exemple #10
0
        public static bool HasRight(FConstants.FeatureByte target)
        {
            FConstants.FeatureByte fb = (FConstants.FeatureByte)Convert.ToInt32(FFunc.GetRegKey("FeatureByte"));

            return((fb & target) == target);
        }
Exemple #11
0
        private void comboBox_LogLevel_ParentChanged(object sender, EventArgs e)
        {
            var loglevel = FFunc.GetRegKey("LogLevel");

            comboBox_LogLevel.SelectedItem = (loglevel == null) ? FConstants.FreyaLogLevel.Normal : (FConstants.FreyaLogLevel)loglevel;
        }
Exemple #12
0
        private void textBox_FeatureByte_TextChanged(object sender, EventArgs e)
        {
            switch (textBox_FeatureByte.Text)
            {
            case "Hide":
                if (RegSetting.hasRight(FConstants.FeatureByte.Hide))
                {
                    RegSetting.delRight(FConstants.FeatureByte.Hide);      //刪除
                    RegSetting.delRight(FConstants.FeatureByte.AlwaysRun); //刪除
                    UI_Adjust(1);                                          //Normal mode
                }
                else
                {
                    RegSetting.addRight(FConstants.FeatureByte.Hide);      //增加
                    RegSetting.addRight(FConstants.FeatureByte.AlwaysRun); //增加
                    UI_Adjust(0);                                          //Hide mode
                    Options_OK.Enabled = true;
                }
                textBox_FeatureByte.Text = "";
                break;

            case "Odin":
                if (RegSetting.hasRight(FConstants.FeatureByte.Odin))
                {
                    RegSetting.delRight(FConstants.FeatureByte.Odin); //刪除
                    UI_Adjust(1);                                     //Normal mode
                }
                else
                {
                    RegSetting.addRight(FConstants.FeatureByte.Odin); //增加
                    UI_Adjust(3);                                     //Odin mode, full UI, full log
                    Options_OK.Enabled = true;
                }
                textBox_FeatureByte.Text = "";
                break;

            case "Reset":
                RegSetting.FeatureByte = FConstants.FeatureByte.Base;
                UI_Adjust(1);     //Normal mode
                textBox_FeatureByte.Text = "";
                break;

            case "Uninstall":
                FFunc.Heimdallr("uninstall");
                textBox_FeatureByte.Text = "";
                this.DialogResult        = DialogResult.Cancel;
                break;

            case "Update":
                FFunc.Heimdallr("update");
                textBox_FeatureByte.Text = "";
                this.DialogResult        = DialogResult.Cancel;
                break;

            case "ForceUpdate":
                FFunc.Heimdallr("forceupdate");
                textBox_FeatureByte.Text = "";
                this.DialogResult        = DialogResult.Cancel;
                break;

            case "ReInstall":
                FFunc.Heimdallr("reinstall");
                textBox_FeatureByte.Text = "";
                this.DialogResult        = DialogResult.Cancel;
                break;

            default:
                break;
            }
        }