Esempio n. 1
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
            }
        }
Esempio n. 2
0
        private void FormSetting_Load(object sender, EventArgs e)
        {
            RegSetting.GetSettingsFromRegistry();

            //// Version Text
            label_Version.Text = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion.ToString();

            //// Advanced - LogLevel
            comboBox_LogLevel.DataSource         = Enum.GetValues(typeof(FConstants.FreyaLogLevel));
            comboBox_LogLevel.SelectedItem       = RegSetting.LogLevel;
            checkBox_SMTPLogWriterEnable.Checked = RegSetting.SMTPLogWriterEnable;

            //// Mail - Email Addres
            textBox_Email.Text = RegSetting.EMail;
            if (textBox_Email.Text.Length == 0)
            {
                Options_OK.Enabled = false;
            }

            //// Mail - Password
            textBox_Password.Text = RegSetting.getPassword();
            if (textBox_Password.Text.Length == 0)
            {
                Options_OK.Enabled = false;
            }

            //// Mail - IMAP Server
            textBox_IMAPServer.Text = RegSetting.IMAPServerIP;
            if (textBox_IMAPServer.Text.Length == 0)
            {
                Options_OK.Enabled = false;
            }

            //// Mail - SMTP Server
            textBox_SMTPServer.Text = RegSetting.SMTPServerIP;
            if (textBox_SMTPServer.Text.Length == 0)
            {
                Options_OK.Enabled = false;
            }

            //// Mail - WebService
            textBox_WebService.Text = RegSetting.WebServiceIP;
            if (textBox_WebService.Text.Length == 0)
            {
                Options_OK.Enabled = false;
            }

            //// Mail - SMTPLogLevel
            string[] SMTPLogLevels = { "None", "Critical", "Error", "Warning", "Information", "Verbose", "Raw" };
            comboBox_SMTPLogLevel.Items.AddRange(SMTPLogLevels);
            string SMTPLogLevel = RegSetting.SMTPLogLevel;

            comboBox_SMTPLogLevel.SelectedItem = (SMTPLogLevel == null) ? SMTPLogLevels[0] : SMTPLogLevel;

            //// DMS - Enable/Disable
            checkBox_DMSEnable.Checked = RegSetting.DMS_Enable;
            setDMSControlsStatus();

            textBox_DMS_UserID.Text            = RegSetting.DMS_Setting.UserID;
            textBox_DMS_Password.Text          = RegSetting.DMS_Setting.getPassword();
            textBox_DMS_Action.Text            = RegSetting.DMS_Setting.Action;
            textBox_DMS_Target.Text            = RegSetting.DMS_Setting.Target;
            textBox_DMS_Event.Text             = RegSetting.DMS_Setting.Event;
            dateTimePicker_DMS_From.Value      = RegSetting.DMS_Setting.From;
            dateTimePicker_DMS_To.Value        = RegSetting.DMS_Setting.To;
            dateTimePicker_DMS_TriggerAt.Value = RegSetting.DMS_TriggerAt;
            numericUpDown_DMS_Items.Value      = (RegSetting.DMS_Setting.Items >= numericUpDown_DMS_Items.Minimum && RegSetting.DMS_Setting.Items <= numericUpDown_DMS_Items.Maximum) ? RegSetting.DMS_Setting.Items : numericUpDown_DMS_Items.Minimum;
            label_DMS_hours.Text = string.Format("Total hours : {0}",
                                                 dateTimePicker_DMS_To.Value.TimeOfDay.Subtract(dateTimePicker_DMS_From.Value.TimeOfDay).TotalHours.ToString());

            Dictionary <string, string> ComboboxItem = new Dictionary <string, string>();

            ComboboxItem.Add(RegSetting.DMS_Setting.project, RegSetting.DMS_Setting.projectname);
            comboBox_DMS_Projects.DisplayMember = "Value";
            comboBox_DMS_Projects.ValueMember   = "Key";
            comboBox_DMS_Projects.DataSource    = new BindingSource(ComboboxItem, null);
            comboBox_DMS_Projects.SelectedIndex = 0;


            /// --------------------------------------------------------------
            /// Encryotion
            /// --------------------------------------------------------------
            ///
            string[] EncryptionMethods = { "StringCipher", "CeasarCipher" };
            comboBox_EncryptionMethod.Items.AddRange(EncryptionMethods);
            comboBox_EncryptionMethod.SelectedItem = EncryptionMethods[1];


            // 把每個tabpage都跑一次,讓每個控制項都initialize
            for (int i = 0; i < tabControl1.TabCount; i++)
            {
                tabControl1.SelectedIndex = i;
            }
            tabControl1.SelectedIndex = 0;

            //// 確認哪些UI要顯示
            if (RegSetting.hasRight(FConstants.FeatureByte.Hide))
            {
                UI_Adjust(0);   //Hide mode
            }
            else if (RegSetting.hasRight(FConstants.FeatureByte.Odin))
            {
                UI_Adjust(3);   //Odie mode
            }
            else
            {
                UI_Adjust(1);   //Normal mode
            }
            //reset switchs
            sw_needIMAPAuthCheck = false;
            restartProxy         = false;
        }