Ejemplo n.º 1
0
        static SecureString GetKeyPassword(string keyId, string userId)
        {
            PasswordForm form = new PasswordForm();

            form.DescriptionText = "A password is needed to unlock the secret key for " + userId;
            return(form.ShowDialog() == DialogResult.OK ? form.GetPassword() : null);
        }
Ejemplo n.º 2
0
        static SecureString GetDecryptionPassword()
        {
            PasswordForm form = new PasswordForm();

            form.DescriptionText = "This data is encrypted with a password. Enter the password to decrypt the data.";
            return(form.ShowDialog() == DialogResult.OK ? form.GetPassword() : null);
        }
Ejemplo n.º 3
0
        private bool AskAndGetConfirmedPassword()
        {
            PasswordForm passwordForm = new PasswordForm();

            passwordForm.Text             = "Enter the password:"******"password:"******"";
            passwordForm.Text             = "Confirm the password:"******"Confirm the password:"******"Password not confirmed!", "Operation canceled!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }

            confirmedPassword = passwordForm.txtPassword.Text;
            return(true);
        }
Ejemplo n.º 4
0
        public static bool AuthenticatePasswordWindow()
        {
            PasswordForm passwordForm = new PasswordForm();

            passwordForm.ShowDialog();
            return(passwordForm.PasswordEntered);
        }
Ejemplo n.º 5
0
        private void BTN_Password_Click(object sender, EventArgs e)
        {
            var password = new PasswordForm("Hello World", "This is password windows form.");

            //password.SetFont(this.Font);
            password.ShowDialog();
        }
Ejemplo n.º 6
0
 private static string PromptForPassword()
 {
     using (var form = new PasswordForm())
     {
         var result = form.ShowDialog();
         return(result != DialogResult.OK ? null : form.Password);
     }
 }
Ejemplo n.º 7
0
        private static DialogResult AskForPassword()
        {
            PasswordForm passwordForm = new PasswordForm();
            var          result       = passwordForm.ShowDialog();

            Settings.EncryptionPass = passwordForm.Password;
            return(result);
        }
Ejemplo n.º 8
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Settings settings = new Settings();

            Database.SetSettings(settings);

            Database.CheckPassword();
            if (Database.IsPasswordProtected)
            {
                PasswordForm form = new PasswordForm(settings);
                form.ShowDialog();

                if (!Database.PasswordIsOk())
                {
                    return;
                }
            }

            Database.Create();
            Database.ReadSetting();

            Application.Run(new MainForm(settings));

            /*
             * TODO:
             *
             * Если будет желание, можно переделать Bookmarks и Desires. Сделать их в виде дерева (как в браузере).
             * https://www.codeproject.com/Articles/23746/TreeView-with-Columns
             * https://www.codeproject.com/Articles/3273/ContainerListView-and-TreeListView-Writing-VS-NET
             * https://sourceforge.net/projects/treeviewadv/
             * Так можно будет создавать подкатегории. К примеру, здоровье, спорт, программы.
             *
             * Также неплохо было б избавиться от лишних библиотек, если найдутся нормальные стандартные средства для парсинга json и html.
             *
             * Добавить новую настройку - что отображать для состояния All. Выбирать через чекбоксы нужные состояния.
             * Удобно, к примеру, для сокрытия удаленных.
             *
             * К Desires добавить приоритеты, стоимость. В иерархическом виде (если сделать в виде дерева)
             * будет удобно смотреть, насколько что дорого. Например, велосипед со всеми аксессуарами.
             *
             * Добавить Problems. Типа какие проблемы у меня висят и что нужно для их решения.
             *
             * Добавить к фильмам и книгам мои оценки, чтоб советовать.
             *
             * Добавить Minds. Мысли, идеи, лайфхаки и прочее. Можно назвать типа Useful или еще как.
             *
             * Сделать ссылки на Bookmarks. Типа {ref=id}.
             * Можно через "Правая кнопка - Вставить ссылку - Выбор ссылки из сохраненных".
             * Можно сделать проверку текста после сохранения. Если в тексте есть корректные ссылки, искать их среди Bookmarks
             * и выделять синим с возможностью клика.
             *
             * Переработать регулярные дела. Или убрать. На ПК ими пользоваться не удобно. Нужна или синхронизация с телефоном или другой формат.
             */
        }
Ejemplo n.º 9
0
        private void button4_Click_1(object sender, EventArgs e)
        {
            PasswordForm frm = new PasswordForm();

            if (frm.ShowDialog() != DialogResult.OK)
            {
                // The user canceled.
                this.Close();
            }
            frm.Close();
        }
Ejemplo n.º 10
0
        private void sowEditing()
        {
            PasswordForm frm = new PasswordForm();

            if (frm.ShowDialog() != DialogResult.OK)
            {
                // The user canceled.
                this.Close();
            }
            frm.Close();
        }
Ejemplo n.º 11
0
        private void changePasswordToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PasswordForm pswdForm = new PasswordForm(User.CurrentUser);

            if (DialogResult.OK != pswdForm.ShowDialog())
            {
                return;
            }
            User.CurrentUser.Password = pswdForm.NewPassword;
            ServicesProvider.GetInstance().GetUserServices().SaveUser(User.CurrentUser);
            Notify("passwordChanged");
        }
Ejemplo n.º 12
0
        public void Start()
        {
            form        = new T();
            correctPass = false;

            using (var passwordForm = new PasswordForm("Please re enter you password to continue."))
            {
                passwordForm.OnCorrectPassword += PasswordForm_OnCorrectPassword;
                passwordForm.Disposed          += PasswordForm_Disposed;
                passwordForm.ShowDialog();
            }
        }
Ejemplo n.º 13
0
        private bool CheckPassword(String content)
        {
            Text2OpCodeServices text2OpCodeServices = new Text2OpCodeServices(content);

            text2OpCodeServices.GetHeaderInformation();
            if (text2OpCodeServices.AskPassword)
            {
                bool         passwordOK   = false;
                PasswordForm passwordForm = new PasswordForm();
                passwordForm.Text             = "Type the password (1/2):";
                passwordForm.lblPassword.Text = "Password:"******"Operation canceled!", "LadderApp", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return(false);
                    }
                    else
                    {
                        if (text2OpCodeServices.password != passwordForm.txtPassword.Text)
                        {
                            passwordForm.txtPassword.Text = "";
                            passwordForm.Text             = "Type the password (1/2):";
                        }
                        else
                        {
                            passwordOK = true;
                            i          = 5; //sai
                        }
                    }
                }
                if (!passwordOK)
                {
                    MessageBox.Show("Operation canceled!", "LadderApp", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 14
0
        public async Task <DialogResult> ShowUpdatePasswordDialogAsync()
        {
            var settings = await SettingsService.Instance.GetSettingsAsync();

            var detail = settings.SelectedConnection;
            var dialog = new PasswordForm(detail)
            {
                UserLogin  = detail.UserName,
                UserDomain = detail.UserDomain,
            };

            dialog.ShowDialog();
            if (dialog.DialogResult == DialogResult.OK)
            {
                detail.SetPassword(dialog.UserPassword, false);
                if (dialog.SavePassword)
                {
                    detail.SavePassword = true;
                    settings.Save();
                }
            }
            return(dialog.DialogResult);
        }
Ejemplo n.º 15
0
        private void LabelClicked(object sender, EventArgs e)
        {
            Label  label = (Label)sender;
            string tag   = label.Tag.ToString();

            foreach (Control control in pnlMenu.Controls)
            {
                if (control is Label)
                {
                    Label lbl = (Label)control;
                    lbl.BackColor = SystemColors.ControlLightLight;
                    lbl.ForeColor = Color.DimGray;
                    lbl.Font      = new Font("Calibri", lbl.Font.Size, FontStyle.Regular);
                }
            }

            label.BackColor = Color.AliceBlue;
            label.ForeColor = Color.DodgerBlue;
            label.Font      = new Font("Calibri", label.Font.Size, FontStyle.Bold);

            UserControl uc = new UserControl();

            switch (tag)
            {
            case "home": uc = homeView;
                break;

            case "document": uc = docView;
                break;

            case "disc": uc = discView;
                break;

            case "application":
                if (!GlobalService.IsPasswordInput)
                {
                    PasswordForm form = new PasswordForm();
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        uc = applicationView;
                    }
                    else
                    {
                        uc = null;
                    }
                }
                else
                {
                    uc = applicationView;
                }
                break;

            case "form": uc = eform;
                break;

            case "setting": uc = settingView;
                break;
            }

            if (uc != null)
            {
                this.LoadControl(uc);
            }
        }
Ejemplo n.º 16
0
        public void Run(int hWndMain, Automate automate, KConnection connection, KConnection destination, Form parent)
        {
            string password;

            do
            {
                // Open the password form
                PasswordForm pf = new PasswordForm();
                pf.StartPosition = FormStartPosition.CenterParent;
                if (pf.ShowDialog() == DialogResult.OK)
                {
                    password = pf.textBoxPassword.Text;
                }
                else
                {
                    break;
                }

                // Wait for main window to become active
                int hWnd = Automate.WinWait("KCMLMasterForm_32", "", Automate.WinMatchMode.Start, 3);
                if (hWnd == 0)
                {
                    // If the main window did not become active check for a system info windows
                    hWnd = Automate.WinWait("#32770", "System", Automate.WinMatchMode.Any, 3);

                    if (hWnd != 0)
                    {
                        // System info window found, click on the button to close it
                        int hSystemInfoButton = Automate.ControlGetHandle(hWnd, "Button", "");
                        if (hSystemInfoButton != 0)
                        {
                            automate.MediumDelay();
                            Automate.ControlClick(hSystemInfoButton);
                        }
                        else
                        {
                            WinApi.SetForegroundWindow(hWndMain);
                            MessageBox.Show("System info button not found");
                            break;
                        }
                    }
                    else
                    {
                        // System info window not found either, end process
                        WinApi.SetForegroundWindow(hWndMain);
                        MessageBox.Show("Main form not found");
                        break;
                    }
                }

                WinApi.SetForegroundWindow(hWnd);
                automate.MediumDelay();

                // At this point the Autoline library form should be displayed and we need to select "Kerridge mode" to break into code
                // Get the handle of the Kerridge mode button
                int hKerridgeModeButton = Automate.ControlGetHandle(hWnd, "KCMLButton_32", 5);
                if (hKerridgeModeButton == 0)
                {
                    WinApi.SetForegroundWindow(hWndMain);
                    MessageBox.Show("Kerridge mode button not found");
                    break;
                }
                automate.ShortDelay();
                Automate.ControlClick(hKerridgeModeButton);

                // Enter the daily password got from the password form
                int hPasswordCtrl = Automate.ControlGetHandle(hWnd, "KCMLEdit32", 1);
                if (hPasswordCtrl == 0)
                {
                    WinApi.SetForegroundWindow(hWndMain);
                    MessageBox.Show("Password control not found");
                    break;
                }
                automate.ShortDelay();
                automate.Send(password + "{ENTER}");

                automate.MediumDelay();

                automate.Send("{TAB}");

                automate.MediumDelay();

                automate.Send("CLEARP{ENTER}");

                automate.MediumDelay();

                automate.Send("LOAD \"GB/MKMOD\"{ENTER}");      // This if for loading the make modules program

                automate.MediumDelay();

                automate.Send("TRAP 'ExecuteScript{ENTER}");    // This is to stop the execution right after the module build sript has been created and before it's executed

                automate.MediumDelay();

                automate.Send("RUN{ENTER}");

                automate.LongDelay();

                // At this point the Make Modules form will be displayed, now we need to press the Build button

                // Wait for the next form
                hWnd = Automate.WinWait("KCMLMasterForm_32", "", Automate.WinMatchMode.Start, 5);
                if (hWnd == 0)
                {
                    WinApi.SetForegroundWindow(hWndMain);
                    MessageBox.Show("Build modules form not found");
                    break;
                }

                // Click on the button to build
                int hCtrlBuild = Automate.ControlGetHandle(hWnd, "KCMLButton_32", 2);
                if (hCtrlBuild == 0)
                {
                    WinApi.SetForegroundWindow(hWndMain);
                    MessageBox.Show("Build button not found");
                    break;
                }
                automate.MediumDelay();
                Automate.ControlClick(hCtrlBuild);

                // The build modules process will start, now we need to wait for it to reach the trap
                // as this process can take very variable amounts of time to complete it requires it's own delay time
                automate.CustomDelay();

                automate.Send("{TAB}");
                automate.MediumDelay();

                // Capture the module build script name by writing it into a known file name that we can get through FTP
                automate.Send(
                    Automate.ConvertKeys("stream = OPEN $PRINTF(\"%s/%s\", ENV(\"WORKSPACE\"), \"ScriptFileName.txt\"), \"w\"")
                    + "{ENTER}");
                automate.Send(
                    Automate.ConvertKeys("pointer = WRITE #stream, ScriptName$")
                    + "{ENTER}");

                // Get the file through FTP
                // Get the object used to communicate with the server.
                FtpWebRequest requestFile = (FtpWebRequest)WebRequest.Create(
                    //"ftp://" + connection.Host + "/%2f" + connection.Home.Substring(1).Replace("home", "work") + "/ScriptFileName.txt");
                    "ftp://" + connection.Host + "/%2f" + ReplaceLastOccurrence(connection.Home.Substring(1), "home", "work") + "/ScriptFileName.txt");
                requestFile.Method = WebRequestMethods.Ftp.DownloadFile;

                // This example assumes the FTP site uses anonymous logon.
                requestFile.Credentials = new NetworkCredential(connection.User, connection.Password);
                FtpWebResponse responseFile = (FtpWebResponse)requestFile.GetResponse();
                // Get the file from the response
                Stream       responseStreamFile = responseFile.GetResponseStream();
                StreamReader readerFile         = new StreamReader(responseStreamFile);

                string line = readerFile.ReadLine();
                if (line != null)
                {
                    string           test    = line.Substring(1);
                    StringCollection result2 = new StringCollection();

                    FtpWebRequest requestFile2 = (FtpWebRequest)WebRequest.Create("ftp://" + connection.Host + "/%2f" + line.Substring(1));
                    requestFile2.Method = WebRequestMethods.Ftp.DownloadFile;

                    // This example assumes the FTP site uses anonymous logon.
                    requestFile2.Credentials = new NetworkCredential(connection.User, connection.Password);
                    FtpWebResponse responseFile2 = (FtpWebResponse)requestFile2.GetResponse();

                    Stream       responseStreamFile2 = responseFile2.GetResponseStream();
                    StreamReader readerFile2         = new StreamReader(responseStreamFile2);

                    line = readerFile2.ReadLine();
                    while (line != null)
                    {
                        result2.Add(line);
                        line = readerFile2.ReadLine();
                    }

                    readerFile2.Close();

                    int firstIndex = result2.IndexOf("CLEAR P");
                    int lastIndex  = 0;

                    foreach (string s in result2)
                    {
                        if (s.Contains("SAVE <G>"))
                        {
                            lastIndex = result2.IndexOf(s);
                        }
                    }

                    for (int index = firstIndex; index <= lastIndex; index++)
                    {
                        string lineCommand = result2[index];

                        // We now have each command ready to send to the console
                        automate.Send(lineCommand + "{ENTER}");

                        automate.LongDelay();
                    }
                }

                readerFile.Close();
            } while (false);
        }
Ejemplo n.º 17
0
        public static SecureString PasswordDialog(string passwordName = null, bool verify = true)
        {
            var passwordForm = new PasswordForm(passwordName, verify);

            return(passwordForm.ShowDialog() == DialogResult.OK ? passwordForm.Password.ConvertToSecureString() : "".ConvertToSecureString());
        }
Ejemplo n.º 18
0
    //*******************************************
    // event handling method for the idTextBox
    //
    public void IdTextBoxKeyUp(object source, KeyEventArgs e)
    {
        // We only want to act if the Enter key is pressed
        if (e.KeyCode == Keys.Enter)
        {
            // First, clear the fields reflecting the
            // previous student's information.
            ClearFields();

            // We'll try to construct a Student based on
            // the id we read, and if a file containing
            // Student's information cannot be found,
            // we have a problem.

            currentUser = new Student(idTextBox.Text + ".dat");
            currentUser.ReadStudentData(schedule);

            // Test to see if the Student fields were properly
            // initialized. If not, reset currentUser to null
            // and display a message box

            if (!currentUser.StudentSuccessfullyInitialized())
            {
                // Drat!  The ID was invalid.
                currentUser = null;

                // Let the user know that login failed,
                string message = "Invalid student ID; please try again.";
                MessageBox.Show(message, "Invalid Student ID",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                // Hooray!  We found one!  Now, we need
                // to request and validate the password.
                passwordDialog = new PasswordForm();
                passwordDialog.ShowDialog(this);

                string password = passwordDialog.Password;
                passwordDialog.Dispose();

                if (currentUser.ValidatePassword(password))
                {
                    // Let the user know that the
                    // login succeeded.
                    string message =
                        "Log in succeeded for " + currentUser.Name + ".";
                    MessageBox.Show(message, "Log In Succeeded",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);

                    // Load the data for the current user into the TextBox and
                    // ListBox components.
                    SetFields(currentUser);
                }
                else
                {
                    // The id was okay, but the password validation failed;
                    // notify the user of this.
                    string message = "Invalid password; please try again.";
                    MessageBox.Show(message, "Invalid Password",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            // Check states of the various buttons.
            ResetButtons();
        }
    }
Ejemplo n.º 19
0
    public void writeCodeplug()
    {
        int num  = 0;
        int num2 = 0;
        int num3 = 0;
        int num4 = 0;

        byte[]     array  = new byte[160];
        byte[]     array2 = MainForm.DataToByte();
        List <int> list   = new List <int>();
        List <int> list2  = new List <int>();
        int        num5   = 0;
        int        num6   = 0;
        int        i      = 0;
        int        num7   = 0;
        int        num8   = 0;
        int        num9   = 0;
        int        num10  = 0;
        bool       flag   = false;

        byte[] array3 = new byte[6];
        int    year   = DateTime.Now.Year;
        int    month  = DateTime.Now.Month;
        int    day    = DateTime.Now.Day;
        int    hour   = DateTime.Now.Hour;
        int    minute = DateTime.Now.Minute;

        array3[0] = (byte)(year / 1000 << 4 | year / 100 % 10);
        array3[1] = (byte)(year % 100 / 10 << 4 | year % 10);
        array3[2] = (byte)(month / 10 << 4 | month % 10);
        array3[3] = (byte)(day / 10 << 4 | day % 10);
        array3[4] = (byte)(hour / 10 << 4 | hour % 10);
        array3[5] = (byte)(minute / 10 << 4 | minute % 10);
        Array.Copy(array3, 0, array2, Class15.ADDR_DEVICE_INFO + Class15.OFS_LAST_PRG_TIME, 6);
        SpecifiedDevice specifiedDevice = SpecifiedDevice.FindSpecifiedDevice(HID_VID, 0x0073);

        if (specifiedDevice == null)
        {
            if (this.OnFirmwareUpdateProgress != null)
            {
                this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs(0f, Class15.SZ_DEVICE_NOT_FOUND, true, true));
            }
        }
        else
        {
            try
            {
                while (true)
                {
                    specifiedDevice.SendData(Class19.CMD_PRG);
                    Array.Clear(array, 0, array.Length);
                    specifiedDevice.ReceiveData(array);
                    if (array[0] != Class19.CMD_ACK[0])
                    {
                        break;
                    }
                    specifiedDevice.SendData(Class19.CMD_PRG2);
                    Array.Clear(array, 0, array.Length);
                    specifiedDevice.ReceiveData(array);
                    byte[] array4 = new byte[8];
                    Buffer.BlockCopy(array, 0, array4, 0, 8);
                    if (array4.smethod_4(Class15.CUR_MODEL))
                    {
                        specifiedDevice.SendData(Class19.CMD_ACK);
                        Array.Clear(array, 0, array.Length);
                        specifiedDevice.ReceiveData(array);
                        if (array[0] == Class19.CMD_ACK[0])
                        {
                            if (!flag && Class15.CUR_PWD != "DT8168")
                            {
                                i    = Class15.ADDR_PWD;
                                num5 = 8;
                                byte[] data = new byte[4]
                                {
                                    82,
                                    (byte)(i >> 8),
                                    (byte)i,
                                    8
                                };
                                Array.Clear(array, 0, array.Length);
                                specifiedDevice.SendData(data, 0, 4);
                                specifiedDevice.ReceiveData(array);
                                string text = "";
                                for (num = 0; num < 8; num++)
                                {
                                    char c = Convert.ToChar(array[num + 4]);
                                    if ("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\b".IndexOf(c) < 0)
                                    {
                                        break;
                                    }
                                    text += c;
                                }
                                if (string.IsNullOrEmpty(text))
                                {
                                    Array.Clear(array, 0, array.Length);
                                    specifiedDevice.SendData(Class19.CMD_ENDW);
                                    specifiedDevice.ReceiveData(array);
                                    if (array[0] != Class19.CMD_ACK[0])
                                    {
                                        break;
                                    }
                                    flag = true;
                                }
                                else
                                {
                                    if (text != Class15.CUR_PWD)
                                    {
                                        Class15.CUR_PWD = "";
                                        PasswordForm passwordForm = new PasswordForm();
                                        if (passwordForm.ShowDialog() == DialogResult.OK)
                                        {
                                            Array.Clear(array, 0, array.Length);
                                            specifiedDevice.SendData(Class19.CMD_ENDW);
                                            specifiedDevice.ReceiveData(array);
                                            if (array[0] != Class19.CMD_ACK[0])
                                            {
                                                break;
                                            }
                                            flag = true;
                                            continue;
                                        }
                                        this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs(0f, "", true, true));
                                        return;
                                    }
                                    Array.Clear(array, 0, array.Length);
                                    specifiedDevice.SendData(Class19.CMD_ENDW);
                                    specifiedDevice.ReceiveData(array);
                                    if (array[0] != Class19.CMD_ACK[0])
                                    {
                                        break;
                                    }
                                    flag = true;
                                }
                                continue;
                            }
                            byte[] array5 = new byte[16];
                            Array.Copy(array2, Class15.ADDR_CHANNEL, array5, 0, array5.Length);
                            BitArray bitArray = new BitArray(array5);
                            list.Add(Class15.ADDR_CHANNEL);
                            list2.Add(Class15.ADDR_CHANNEL + 16);
                            for (num = 0; num < 128; num++)
                            {
                                if (bitArray[num])
                                {
                                    num9  = Class15.ADDR_CHANNEL + 16 + num * ChannelForm.SPACE_CH;
                                    num10 = num9 + ChannelForm.SPACE_CH;
                                    list.Add(num9);
                                    list2.Add(num10);
                                }
                            }
                            for (num2 = 1; num2 < 8; num2++)
                            {
                                num7 = Class15.ADDR_EX_CH + (num2 - 1) * ChannelForm.SPACE_CH_GROUP;
                                Array.Copy(array2, num7, array5, 0, array5.Length);
                                bitArray = new BitArray(array5);
                                list.Add(num7);
                                list2.Add(num7 + 16);
                                for (num = 0; num < 128; num++)
                                {
                                    if (bitArray[num])
                                    {
                                        num9  = num7 + 16 + num * ChannelForm.SPACE_CH;
                                        num10 = num9 + ChannelForm.SPACE_CH;
                                        list.Add(num9);
                                        list2.Add(num10);
                                    }
                                }
                            }
                            byte[] array6 = new byte[32];
                            num7 = Class15.ADDR_EX_ZONE_LIST;
                            Array.Copy(array2, num7, array6, 0, array6.Length);
                            bitArray = new BitArray(array6);
                            list.Add(num7);
                            list2.Add(num7 + 32);
                            for (num = 0; num < 250; num++)
                            {
                                num7 = Class15.ADDR_EX_ZONE_LIST + 32;
                                if (bitArray[num])
                                {
                                    num9  = num7 + num * ZoneForm.SPACE_ZONE;
                                    num10 = num9 + ZoneForm.SPACE_ZONE;
                                    list.Add(num9);
                                    list2.Add(num10);
                                }
                            }
                            for (num = 0; num < this.START_ADDR.Length; num++)
                            {
                                list.Add(this.START_ADDR[num]);
                                list2.Add(this.END_ADDR[num]);
                            }
                            for (num = 0; num < list.Count; num++)
                            {
                                num9  = list[num];
                                num10 = list2[num];
                                for (i = num9; i < num10; i += num5)
                                {
                                    num6 = i % 32;
                                    num5 = ((i + 32 <= num10) ? (32 - num6) : (num10 - i));
                                    num4++;
                                }
                            }
                            num7 = 0;
                            num  = 0;
                            while (true)
                            {
                                if (num < list.Count)
                                {
                                    num9  = list[num];
                                    num10 = list2[num];
                                    i     = num9;
                                    while (i < num10)
                                    {
                                        if (!this.method_0())
                                        {
                                            if (num7 >> 16 != i >> 16)
                                            {
                                                byte[] array7 = new byte[8]
                                                {
                                                    67,
                                                    87,
                                                    66,
                                                    4,
                                                    0,
                                                    0,
                                                    0,
                                                    0
                                                };
                                                num7      = i >> 16 << 16;
                                                array7[4] = (byte)(num7 >> 24);
                                                array7[5] = (byte)(num7 >> 16);
                                                array7[6] = (byte)(num7 >> 8);
                                                array7[7] = (byte)num7;
                                                Array.Clear(array, 0, array.Length);
                                                specifiedDevice.SendData(array7, 0, array7.Length);
                                                specifiedDevice.ReceiveData(array);
                                                if (array[0] == Class19.CMD_ACK[0])
                                                {
                                                    goto IL_06e2;
                                                }
                                                goto IL_083e;
                                            }
                                            goto IL_06e2;
                                        }
                                        specifiedDevice.SendData(Class19.CMD_ENDR);
                                        specifiedDevice.ReceiveData(array);
                                        return;

IL_06e2:
                                        num6 = i % 32;
                                        num5 = ((i + 32 <= num10) ? (32 - num6) : (num10 - i));
                                        num8 = i - num7;
                                        byte[] array8 = new byte[num5 + 4];
                                        array8[0] = 87;
                                        array8[1] = (byte)(num8 >> 8);
                                        array8[2] = (byte)num8;
                                        array8[3] = (byte)num5;
                                        Array.Clear(array, 0, array.Length);
                                        Array.Copy(array2, i, array8, 4, num5);
                                        specifiedDevice.SendData(array8, 0, 4 + num5);
                                        specifiedDevice.ReceiveData(array);
                                        if (array[0] == Class19.CMD_ACK[0])
                                        {
                                            if (this.OnFirmwareUpdateProgress != null)
                                            {
                                                this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs((float)(++num3) * 100f / (float)num4, i.ToString(), false, false));
                                            }
                                            i += num5;
                                            continue;
                                        }
                                        goto IL_0857;
                                    }
                                    num++;
                                    continue;
                                }
                                Array.Clear(array, 0, array.Length);
                                specifiedDevice.SendData(Class19.CMD_ENDW);
                                specifiedDevice.ReceiveData(array);
                                if (array[0] != Class19.CMD_ACK[0])
                                {
                                    break;
                                }
                                if (this.OnFirmwareUpdateProgress != null)
                                {
                                    this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs(100f, "", false, true));
                                }
                                return;

IL_0857:
                                specifiedDevice.SendData(Class19.CMD_ENDW);
                                specifiedDevice.ReceiveData(array);
                                break;
IL_083e:
                                specifiedDevice.SendData(Class19.CMD_ENDW);
                                specifiedDevice.ReceiveData(array);
                                break;
                            }
                        }
                        break;
                    }
                    if (this.OnFirmwareUpdateProgress != null)
                    {
                        this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs(0f, Class15.SZ_MODEL_NOT_MATCH, true, true));
                    }
                    return;
                }
                if (this.OnFirmwareUpdateProgress != null)
                {
                    this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs(0f, Class15.SZ_COMM_ERROR, true, true));
                }
            }
            catch (TimeoutException ex)
            {
                Console.WriteLine(ex.Message);
                if (this.OnFirmwareUpdateProgress != null)
                {
                    this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs(0f, Class15.SZ_COMM_ERROR, false, false));
                }
            }
            finally
            {
                if (specifiedDevice != null)
                {
                    specifiedDevice.Dispose();
                }
            }
        }
    }
Ejemplo n.º 20
0
        private async void buttonSend_Click(object sender, EventArgs e)
        {
            buttonSend.Enabled = false;

            string wallet  = comboBoxWallet.Text;
            string account = comboBoxAccount.Text;

            List <RecipientModel> recipients = new List <RecipientModel>();

            Money how = Money.FromUnit(numericTextBoxAmount.DecimalValue, MoneyUnit.BTC);

            recipients.Add(new RecipientModel(textBoxPayTo.Text.Trim(), how.ToString()));

            List <OutpointRequest> outpoints = null;

            if (SelectedTransactions != null)
            {
                outpoints = new List <OutpointRequest>();

                foreach (var item in SelectedTransactions)
                {
                    outpoints.Add(new OutpointRequest(item.TxId.ToString(), item.Index));
                }

                //свой адрес для сдачи можно установить если сами выбираем входа, иначе не узнать какие выберет программа
                if (checkBoxCustomChangeAddress.Checked && !String.IsNullOrEmpty(textBoxCustomChangeAddress.Text.Trim()))
                {
                    //нужно посчитать сколько будет сдачи и, если больше 0, направить все это на адрес
                    string changeAddress = textBoxCustomChangeAddress.Text.Trim();
                    Money  change        = Money.FromUnit(SelectedTransactions.Sum(x => x.Amount), MoneyUnit.Satoshi) - how - Common.CurrentSettings.MinTxFee;
                    if (change > Money.Zero)
                    {
                        recipients.Add(new RecipientModel(changeAddress, change.ToString()));
                    }
                }
            }

            #region Fee - на Stratis MainNet почти тестировал!!!
            if (Common.CurrentSettings.IsStratis)
            {
                //Оценка комиссии - Для Статиса только? Но все равно комиссия посчитается автоматически так как передаю ее тип а не значение
                //х42 фии нет но для стратиса можно оценить api/wallet/estimate-txfee по POST а у х42 GET
                ApiClient client = new ApiClient();
                var       fee    = await client.GetEstimateFee(wallet, account, recipients, outpoints);

                if (fee == null)
                {
                    ErrorMessage("Error GetEstimateFee: " + client.Error);
                    return;
                }
                if (fee > Money.Zero) //нужно подтверждение
                {
                    if (DialogResult.Yes != MessageBox.Show($"The commission will be {fee} coins. Do you agree to pay for it?", "Commission", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1))
                    {
                        ErrorMessage($"You refused to pay a commission in {fee}");
                        return;
                    }
                }
            }
            #endregion Fee

            //Запросим пароль
            string       password;
            PasswordForm pass = new PasswordForm();
            pass.ShowDialog();
            if (DialogResult.OK == pass.DialogResult)
            {
                password = pass.Password;
            }
            else
            {
                ErrorMessage("You have not entered a password");
                return;
            }

            var result = await SendTransaction(wallet, account, password, recipients, outpoints);

            if (result != null)
            {
                MessageForm frm = new MessageForm();
                frm.InputBox("Transaction ID: ", "Transaction has been successfully sent", result);
            }
            else
            {
                MessageBox.Show("Error: see in log ", "Failed to send transaction", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 21
0
        private void btnChgPwd_Click(object sender, EventArgs e)
        {
            bool changed = false;
            try
            {
                PasswordForm pwdform = new PasswordForm();
                pwdform.ShowDialog(this);
                //try to change the password for this user.
                if (pwdform.Password != null)
                {
                    UserStorageView[] users = new UserStorageView[1];
                    users[0] = _User;
                    _User.Password = pwdform.Password;
                    console.Manager.Admon_UpdateUsers(console.Credentials, users);

                    changed = true;

                    //update the console credentials if needed
                    if (console.Credentials.Username == _User.Username)
                    {
                        console.Credentials.Password = pwdform.Password;
                    }
                }
            }
            catch (Exception ex)
            {
                changed = false;
                MessageBox.Show("Error changing password:"******"Change Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (changed)
                {
                    MessageBox.Show("Password changed successfully.", "Change Password", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
Ejemplo n.º 22
0
        public void openPasswordForm()
        {
            PasswordForm form = new PasswordForm(currentUser);

            form.ShowDialog();
        }
Ejemplo n.º 23
0
    //**********************************************
    // event handling method for "Log In" Button
    //
    public void LogInButtonClicked(object source, EventArgs e)
    {
        // First, clear the fields reflecting the
          // previous student's information.
          ClearFields();

          //  Display password dialog
          passwordDialog = new PasswordForm();
          passwordDialog.ShowDialog(this);

          string password = passwordDialog.Password;
          string id = passwordDialog.Id;
          passwordDialog.Dispose();

          // We'll try to construct a Student based on
          // the id we read, and if a file containing
          // Student's information cannot be found,
          // we have a problem.

          currentUser = new Student(id+".dat");
          currentUser.ReadStudentData(schedule);

          // Test to see if the Student fields were properly
          // initialized. If not, reset currentUser to null
          // and display a message box

          if (!currentUser.StudentSuccessfullyInitialized()) {
        // Drat!  The ID was invalid.
        currentUser = null;

        // Let the user know that login failed,
        string message = "Invalid student ID; please try again.";
        MessageBox.Show(message, "Invalid Student ID",
                 MessageBoxButtons.OK, MessageBoxIcon.Warning);
          }
          else {
        // We have a valid Student.  Now, we need
        // to validate the password.

        if (currentUser.ValidatePassword(password)) {

          // Let the user know that the login succeeded.
          string message =
               "Log in succeeded for " + currentUser.Name + ".";
          MessageBox.Show(message, "Log In Succeeded",
                 MessageBoxButtons.OK, MessageBoxIcon.Information);

          // Load the data for the current user into the TextBox and
          // ListBox components.
          SetFields(currentUser);
        }
        else {
          // The id was okay, but the password validation failed;
          // notify the user of this.
          currentUser = null;
          string message = "Invalid password; please try again.";
          MessageBox.Show(message, "Invalid Password",
                 MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
          }
          // Check states of the various buttons.
          ResetButtons();
    }
Ejemplo n.º 24
0
        void ExtractFile(ZipFile zip, Manifest.File FileM, string DestinationPath)
        {
            bool CanOverwrite = false;

            // NeedRollback is set to true as soon as we've created the new file.  If an error occurs before we complete
            // the new file, we need to delete the file we've created.  Once we finish the new file successfully, we no
            // longer need a rollback (delete) operation.
            bool NeedRollback = false;

            for (; ;)
            {
                try
                {
                    ZippyForm.LogWriteLine(LogLevel.HeavyDebug, "Extracting file '" + FileM.RelativePath + "' from archive path '" + FileM.PathInArchive + "' in archive '" + FileM.ArchiveFile + "'...");

                    if (File.Exists(DestinationPath))
                    {
                        if (OverwriteAll)
                        {
                            CanOverwrite = true;
                        }
                        if (OverwriteNone)
                        {
                            return;
                        }

                        if (!CanOverwrite)
                        {
                            OverwritePromptForm.Result res = OverwritePromptForm.Show("The file '" + DestinationPath + "' already exists.  Overwrite?");
                            if (res == OverwritePromptForm.Result.Cancel)
                            {
                                throw new CancelException();
                            }
                            else if (res == OverwritePromptForm.Result.Yes)
                            {
                                CanOverwrite = true;
                            }
                            else if (res == OverwritePromptForm.Result.No)
                            {
                                return;
                            }
                            else if (res == OverwritePromptForm.Result.YesToAll)
                            {
                                CanOverwrite = true; OverwriteAll = true;
                            }
                            else if (res == OverwritePromptForm.Result.NoToAll)
                            {
                                OverwriteNone = true; return;
                            }
                            else
                            {
                                throw new Exception();
                            }
                        }

                        // In case the file is marked read-only, unmark it.  We'll correctly set the attributes after we create the file.
                        File.SetAttributes(DestinationPath, FileM.WindowsAttributes & ~System.IO.FileAttributes.ReadOnly & ~System.IO.FileAttributes.Hidden & ~System.IO.FileAttributes.System);
                    }

                    ZipEntry ze;
                    try
                    {
                        string PathInArchive = FileM.PathInArchive.Replace('\\', '/').Replace('’', '\'');
                        ze = zip[PathInArchive];
                        if (ze == null)
                        {
                            /*
                             * if ((int)ZippyForm.MainList.Logging >= (int)LogLevel.HeavyDebug)
                             * {
                             *  ZippyForm.LogWriteLine(LogLevel.HeavyDebug, "All entries in this archive:");
                             *  foreach (ZipEntry zeDiag in zip)
                             *      ZippyForm.LogWriteLine(LogLevel.HeavyDebug, "\t" + zeDiag.FileName);
                             * }
                             */

                            // I've had this exception trigger before when a special character had been silently replaced in the zip file
                            // archive name.  In that case, it was a special apostrophe character that had been silently replaced with an
                            // ordinary apostrophe.  So, maybe the zip directoy abuses unicode characters?

                            throw new FileNotFoundException();
                        }
                    }
                    catch (CancelException ce) { throw ce; }
                    catch (Exception ex)
                    {
                        throw new FileNotFoundException(ex.Message + "\nThe file '" + FileM.RelativePath + "' is missing from archive '" + FileM.ArchiveFile + "'.", ex);
                    }

                    using (FileStream Dest = new FileStream(DestinationPath, CanOverwrite ? FileMode.Create : FileMode.CreateNew,
                                                            FileAccess.ReadWrite, FileShare.Read))
                    {
                        NeedRollback = true;

                        bool FirstPasswordPrompt = true;
                        for (; ;)
                        {
                            try
                            {
                                if (String.IsNullOrEmpty(Project.SafePassword.Password))
                                {
                                    ze.Extract(Dest);
                                }
                                else
                                {
                                    ze.ExtractWithPassword(Dest, Project.SafePassword.Password);
                                }
                                if (ZipError != null)
                                {
                                    throw ZipError;
                                }
                                break;
                            }
                            catch (Ionic.Zip.BadPasswordException bpe)
                            {
                                Dest.SetLength(0); Dest.Seek(0, System.IO.SeekOrigin.Begin);
                                try
                                {
                                    if (!String.IsNullOrEmpty(Project.AlternativePassword))
                                    {
                                        ze.ExtractWithPassword(Dest, Project.AlternativePassword);
                                    }
                                    else
                                    {
                                        throw bpe;
                                    }
                                    if (ZipError != null)
                                    {
                                        throw ZipError;
                                    }
                                    break;
                                }
                                catch (Ionic.Zip.BadPasswordException)
                                {
                                    Dest.SetLength(0); Dest.Seek(0, System.IO.SeekOrigin.Begin);

                                    PasswordForm pf = new PasswordForm();
                                    if (FirstPasswordPrompt)
                                    {
                                        pf.Prompt = "The archive '" + FileM.ArchiveFile + "' was created with a different password.  (121)";
                                    }
                                    else
                                    {
                                        pf.Prompt = "That was not a valid password for the archive '" + FileM.ArchiveFile + "'.";
                                    }
                                    FirstPasswordPrompt = false;
                                    if (pf.ShowDialog() != DialogResult.OK)
                                    {
                                        throw new CancelException();
                                    }
                                    Project.AlternativePassword = pf.Password;
                                    continue;
                                }
                            }
                        }
                    }
                    NeedRollback = false;
                    return;
                }
                catch (CancelException ce) { throw ce; }
                catch (Exception ex)
                {
                    ZippyForm.LogWriteLine(LogLevel.Information, "Error extracting file '" + FileM.RelativePath + "' from archive path '" + FileM.PathInArchive + "' in archive '" + FileM.ArchiveFile + "': " + ex.Message);
                    ZippyForm.LogWriteLine(LogLevel.LightDebug, "Detailed Error: " + ex.ToString());

#                   if DEBUG
                    DialogResult dr = MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.AbortRetryIgnore);
#                   else
                    DialogResult dr = MessageBox.Show(ex.Message, "Error", MessageBoxButtons.AbortRetryIgnore);
#                   endif
                    if (dr == DialogResult.Abort)
Ejemplo n.º 25
0
        void ExtractAndDeleteFile(ZipFile zip, Manifest.File FileM, string DestinationPath)
        {
            for (; ;)
            {
                try
                {
                    if (File.Exists(DestinationPath))
                    {
                        // In case the file is marked read-only, unmark it.  We'll correctly set the attributes after we create the file.
                        File.SetAttributes(DestinationPath, FileM.WindowsAttributes & ~System.IO.FileAttributes.ReadOnly & ~System.IO.FileAttributes.Hidden & ~System.IO.FileAttributes.System);
                    }

                    ZipEntry ze;
                    try
                    {
                        string PathInArchive = FileM.PathInArchive.Replace('\\', '/').Replace('’', '\'');
                        ze = zip[PathInArchive];
                        if (ze == null)
                        {
                            throw new FileNotFoundException();
                        }
                    }
                    catch (CancelException ce) { throw ce; }
                    catch (Exception ex)
                    {
                        throw new FileNotFoundException(ex.Message + "\nThe file '" + FileM.RelativePath + "' is missing from archive '" + FileM.ArchiveFile + "'.", ex);
                    }

                    using (FileStream Dest = new FileStream(DestinationPath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read))
                    {
                        bool FirstPasswordPrompt = true;
                        for (; ;)
                        {
                            try
                            {
                                if (String.IsNullOrEmpty(Project.SafePassword.Password))
                                {
                                    ze.Extract(Dest);
                                }
                                else
                                {
                                    ze.ExtractWithPassword(Dest, Project.SafePassword.Password);
                                }
                                if (ZipError != null)
                                {
                                    throw ZipError;
                                }
                                break;
                            }
                            catch (Ionic.Zip.BadPasswordException bpe)
                            {
                                Dest.SetLength(0); Dest.Seek(0, System.IO.SeekOrigin.Begin);
                                try
                                {
                                    if (!String.IsNullOrEmpty(Project.AlternativePassword))
                                    {
                                        ze.ExtractWithPassword(Dest, Project.AlternativePassword);
                                    }
                                    else
                                    {
                                        throw bpe;
                                    }
                                    if (ZipError != null)
                                    {
                                        throw ZipError;
                                    }
                                    break;
                                }
                                catch (Ionic.Zip.BadPasswordException)
                                {
                                    Dest.SetLength(0); Dest.Seek(0, System.IO.SeekOrigin.Begin);

                                    PasswordForm pf = new PasswordForm();
                                    if (FirstPasswordPrompt)
                                    {
                                        pf.Prompt = "The archive '" + FileM.ArchiveFile + "' was created with a different password.  (121)";
                                    }
                                    else
                                    {
                                        pf.Prompt = "That was not a valid password for the archive '" + FileM.ArchiveFile + "'.";
                                    }
                                    FirstPasswordPrompt = false;
                                    if (pf.ShowDialog() != DialogResult.OK)
                                    {
                                        throw new CancelException();
                                    }
                                    Project.AlternativePassword = pf.Password;
                                    continue;
                                }
                            }
                        }
                    }
                    ZippyForm.LogWriteLine(LogLevel.HeavyDebug, "Success extracting file '" + FileM.RelativePath + "'.");
                    break;
                }
                catch (CancelException ce) { throw ce; }
                catch (Ionic.Zip.ZipException ze) { throw ze; }
                catch (Ionic.Zlib.ZlibException ze) { throw ze; }
                catch (FileNotFoundException fe) { throw fe; }
                catch (Exception ex)
                {
#                   if DEBUG
                    DialogResult dr = MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.AbortRetryIgnore);
#                   else
                    DialogResult dr = MessageBox.Show(ex.Message, "Error", MessageBoxButtons.AbortRetryIgnore);
#                   endif
                    if (dr == DialogResult.Abort)
Ejemplo n.º 26
0
    public void readCodeplug()
    {
        int num  = 0;
        int num2 = 0;
        int num3 = 0;
        int num4 = 0;

        byte[]          array           = new byte[Class15.EEROM_SPACE];
        byte[]          array2          = new byte[160];
        List <int>      list            = new List <int>();
        List <int>      list2           = new List <int>();
        int             num5            = 0;
        int             num6            = 0;
        int             i               = 0;
        int             num7            = 0;
        int             num8            = 0;
        int             num9            = 0;
        int             num10           = 0;
        bool            flag            = false;
        float           num11           = 0f;
        int             num12           = 0;
        SpecifiedDevice specifiedDevice = null;

        try
        {
            specifiedDevice = SpecifiedDevice.FindSpecifiedDevice(HID_VID, HID_PID);            //0x152A HID_PID
            if (specifiedDevice == null)
            {
                if (this.OnFirmwareUpdateProgress != null)
                {
                    this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs(0f, Class15.SZ_DEVICE_NOT_FOUND, true, true));
                }
            }
            else
            {
                while (true)
                {
                    Array.Clear(array2, 0, array2.Length);
                    specifiedDevice.SendData(Class19.CMD_PRG);
                    specifiedDevice.ReceiveData(array2);
                    if (array2[0] != Class19.CMD_ACK[0])
                    {
                        break;
                    }
                    specifiedDevice.SendData(Class19.CMD_PRG2);
                    Array.Clear(array2, 0, array2.Length);
                    specifiedDevice.ReceiveData(array2);
                    byte[] array3 = new byte[8];
                    Buffer.BlockCopy(array2, 0, array3, 0, 8);
                    if (array3.smethod_4(Class15.CUR_MODEL))
                    {
                        specifiedDevice.SendData(Class19.CMD_ACK);
                        Array.Clear(array2, 0, array2.Length);
                        specifiedDevice.ReceiveData(array2);
                        if (array2[0] == Class19.CMD_ACK[0])
                        {
                            if (!flag && Class15.CUR_PWD != "DT8168")
                            {
                                i    = Class15.ADDR_PWD;
                                num5 = 8;
                                byte[] data = new byte[4]
                                {
                                    82,
                                    (byte)(i >> 8),
                                    (byte)i,
                                    8
                                };
                                Array.Clear(array2, 0, array2.Length);
                                specifiedDevice.SendData(data, 0, 4);
                                specifiedDevice.ReceiveData(array2);
                                string text = "";
                                for (num = 0; num < 8; num++)
                                {
                                    char c = Convert.ToChar(array2[num + 4]);
                                    if ("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\b".IndexOf(c) < 0)
                                    {
                                        break;
                                    }
                                    text += c;
                                }
                                if (string.IsNullOrEmpty(text))
                                {
                                    Array.Clear(array2, 0, array2.Length);
                                    specifiedDevice.SendData(Class19.CMD_ENDR);
                                    specifiedDevice.ReceiveData(array2);
                                    if (array2[0] != Class19.CMD_ACK[0])
                                    {
                                        break;
                                    }
                                    flag = true;
                                }
                                else
                                {
                                    if (text != Class15.CUR_PWD)
                                    {
                                        Array.Clear(array2, 0, array2.Length);
                                        specifiedDevice.SendData(Class19.CMD_ENDR);
                                        specifiedDevice.ReceiveData(array2);
                                        if (array2[0] != Class19.CMD_ACK[0])
                                        {
                                            break;
                                        }
                                        Class15.CUR_PWD = "";
                                        PasswordForm passwordForm = new PasswordForm();
                                        if (passwordForm.ShowDialog() == DialogResult.OK)
                                        {
                                            num12++;
                                            if (num12 < 3)
                                            {
                                                continue;
                                            }
                                            this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs(0f, "Password error more than three times, quit communication!", true, true));
                                        }
                                        else
                                        {
                                            this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs(0f, "", true, true));
                                        }
                                        return;
                                    }
                                    Array.Clear(array2, 0, array2.Length);
                                    specifiedDevice.SendData(Class19.CMD_ENDR);
                                    specifiedDevice.ReceiveData(array2);
                                    if (array2[0] != Class19.CMD_ACK[0])
                                    {
                                        break;
                                    }
                                    flag = true;
                                }
                                continue;
                            }
                            List <int> list3 = new List <int>();
                            List <int> list4 = new List <int>();
                            list3.Add(Class15.ADDR_CHANNEL);
                            list4.Add(Class15.ADDR_CHANNEL + 16);
                            for (num2 = 1; num2 < 8; num2++)
                            {
                                num8 = Class15.ADDR_EX_CH + (num2 - 1) * ChannelForm.SPACE_CH_GROUP;
                                list3.Add(num8);
                                list4.Add(num8 + 16);
                            }
                            num8 = Class15.ADDR_EX_ZONE_LIST;
                            list3.Add(num8);
                            list4.Add(num8 + 32);
                            num3 = 0;
                            num4 = 0;
                            for (num = 0; num < list3.Count; num++)
                            {
                                num9  = list3[num];
                                num10 = list4[num];
                                for (i = num9; i < num10; i += num5)
                                {
                                    num6 = i % 32;
                                    num5 = ((i + 32 <= num10) ? (32 - num6) : (num10 - i));
                                    num4++;
                                }
                            }
                            num8 = 0;
                            num  = 0;
                            while (true)
                            {
                                if (num < list3.Count)
                                {
                                    num9  = list3[num];
                                    num10 = list4[num];
                                    i     = num9;
                                    while (i < num10)
                                    {
                                        if (!this.method_0())
                                        {
                                            if (num8 >> 16 != i >> 16)
                                            {
                                                byte[] array4 = new byte[8]
                                                {
                                                    67,
                                                    87,
                                                    66,
                                                    4,
                                                    0,
                                                    0,
                                                    0,
                                                    0
                                                };
                                                num8      = i >> 16 << 16;
                                                array4[4] = (byte)(num8 >> 24);
                                                array4[5] = (byte)(num8 >> 16);
                                                array4[6] = (byte)(num8 >> 8);
                                                array4[7] = (byte)num8;
                                                Array.Clear(array2, 0, array2.Length);
                                                specifiedDevice.SendData(array4, 0, array4.Length);
                                                specifiedDevice.ReceiveData(array2);
                                                if (array2[0] != Class19.CMD_ACK[0])
                                                {
                                                    goto end_IL_02a2;
                                                }
                                            }
                                            num6 = i % 32;
                                            num5 = ((i + 32 <= num10) ? (32 - num6) : (num10 - i));
                                            num7 = i - num8;
                                            byte[] data2 = new byte[4]
                                            {
                                                82,
                                                (byte)(num7 >> 8),
                                                (byte)num7,
                                                (byte)num5
                                            };
                                            Array.Clear(array2, 0, array2.Length);
                                            specifiedDevice.SendData(data2, 0, 4);
                                            if (!specifiedDevice.ReceiveData(array2))
                                            {
                                                goto end_IL_02a2;
                                            }
                                            Array.Copy(array2, 4, array, i, num5);
                                            if (this.OnFirmwareUpdateProgress != null)
                                            {
                                                this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs((float)(++num3) * 5f / (float)num4, i.ToString(), false, false));
                                            }
                                            i += num5;
                                            continue;
                                        }
                                        specifiedDevice.SendData(Class19.CMD_ENDR);
                                        specifiedDevice.ReceiveData(array2);
                                        return;
                                    }
                                    num++;
                                    continue;
                                }
                                byte[] array5 = new byte[16];
                                Array.Copy(array, Class15.ADDR_CHANNEL, array5, 0, array5.Length);
                                BitArray bitArray = new BitArray(array5);
                                list.Add(Class15.ADDR_CHANNEL);
                                list2.Add(Class15.ADDR_CHANNEL + 16);
                                for (num = 0; num < 128; num++)
                                {
                                    if (bitArray[num])
                                    {
                                        num9  = Class15.ADDR_CHANNEL + 16 + num * ChannelForm.SPACE_CH;
                                        num10 = num9 + ChannelForm.SPACE_CH;
                                        list.Add(num9);
                                        list2.Add(num10);
                                    }
                                }
                                for (num2 = 1; num2 < 8; num2++)
                                {
                                    num8 = Class15.ADDR_EX_CH + (num2 - 1) * ChannelForm.SPACE_CH_GROUP;
                                    Array.Copy(array, num8, array5, 0, array5.Length);
                                    bitArray = new BitArray(array5);
                                    list.Add(num8);
                                    list2.Add(num8 + 16);
                                    for (num = 0; num < 128; num++)
                                    {
                                        if (bitArray[num])
                                        {
                                            num9  = num8 + 16 + num * ChannelForm.SPACE_CH;
                                            num10 = num9 + ChannelForm.SPACE_CH;
                                            list.Add(num9);
                                            list2.Add(num10);
                                        }
                                    }
                                }
                                byte[] array6 = new byte[32];
                                num8 = Class15.ADDR_EX_ZONE_LIST;
                                Array.Copy(array, num8, array6, 0, array6.Length);
                                bitArray = new BitArray(array6);
                                list.Add(num8);
                                list2.Add(num8 + 32);
                                for (num = 0; num < 250; num++)
                                {
                                    num8 = Class15.ADDR_EX_ZONE_LIST + 32;
                                    if (bitArray[num])
                                    {
                                        num9  = num8 + num * ZoneForm.SPACE_ZONE;
                                        num10 = num9 + ZoneForm.SPACE_ZONE;
                                        list.Add(num9);
                                        list2.Add(num10);
                                    }
                                }
                                for (num = 0; num < this.START_ADDR.Length; num++)
                                {
                                    list.Add(this.START_ADDR[num]);
                                    list2.Add(this.END_ADDR[num]);
                                }
                                num3 = 0;
                                num4 = 0;
                                for (num = 0; num < list.Count; num++)
                                {
                                    num9  = list[num];
                                    num10 = list2[num];
                                    for (i = num9; i < num10; i += num5)
                                    {
                                        num6 = i % 32;
                                        num5 = ((i + 32 <= num10) ? (32 - num6) : (num10 - i));
                                        num4++;
                                    }
                                }
                                num8 = 0;
                                num  = 0;
                                while (true)
                                {
                                    if (num < list.Count)
                                    {
                                        num9  = list[num];
                                        num10 = list2[num];
                                        i     = num9;
                                        while (i < num10)
                                        {
                                            if (!this.method_0())
                                            {
                                                if (num8 >> 16 != i >> 16)
                                                {
                                                    byte[] array7 = new byte[8]
                                                    {
                                                        67,
                                                        87,
                                                        66,
                                                        4,
                                                        0,
                                                        0,
                                                        0,
                                                        0
                                                    };
                                                    num8      = i >> 16 << 16;
                                                    array7[4] = (byte)(num8 >> 24);
                                                    array7[5] = (byte)(num8 >> 16);
                                                    array7[6] = (byte)(num8 >> 8);
                                                    array7[7] = (byte)num8;
                                                    Array.Clear(array2, 0, array2.Length);
                                                    specifiedDevice.SendData(array7, 0, array7.Length);
                                                    specifiedDevice.ReceiveData(array2);
                                                    if (array2[0] == Class19.CMD_ACK[0])
                                                    {
                                                        goto IL_08b4;
                                                    }
                                                    goto IL_0a1f;
                                                }
                                                goto IL_08b4;
                                            }
                                            specifiedDevice.SendData(Class19.CMD_ENDR);
                                            specifiedDevice.ReceiveData(array2);
                                            return;

IL_08b4:
                                            num6 = i % 32;
                                            num5 = ((i + 32 <= num10) ? (32 - num6) : (num10 - i));
                                            num7 = i - num8;
                                            byte[] array8 = new byte[4]
                                            {
                                                82,
                                                (byte)(num7 >> 8),
                                                (byte)num7,
                                                (byte)num5
                                            };
                                            Array.Clear(array2, 0, array2.Length);
                                            specifiedDevice.SendData(array8, 0, 4);
                                            if (specifiedDevice.ReceiveData(array2))
                                            {
                                                if (Class15.smethod_18(array8, array2, 4))
                                                {
                                                    Array.Copy(array2, 4, array, i, num5);
                                                    if (this.OnFirmwareUpdateProgress != null)
                                                    {
                                                        num11 = 5f + (float)(++num3) * 95f / (float)num4;
                                                        this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs(num11, i.ToString(), false, false));
                                                    }
                                                    i += num5;
                                                    continue;
                                                }
                                                goto IL_0a51;
                                            }
                                            goto IL_0a38;
                                        }
                                        num++;
                                        continue;
                                    }
                                    Array.Clear(array2, 0, array2.Length);
                                    specifiedDevice.SendData(Class19.CMD_ENDR);
                                    specifiedDevice.ReceiveData(array2);
                                    if (array2[0] != Class19.CMD_ACK[0])
                                    {
                                        break;
                                    }
                                    MainForm.ByteToData(array);
                                    if (this.OnFirmwareUpdateProgress != null)
                                    {
                                        this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs(100f, "", false, true));
                                    }
                                    return;

IL_0a51:
                                    specifiedDevice.SendData(Class19.CMD_ENDR);
                                    specifiedDevice.ReceiveData(array2);
                                    break;
IL_0a38:
                                    specifiedDevice.SendData(Class19.CMD_ENDR);
                                    specifiedDevice.ReceiveData(array2);
                                    break;
IL_0a1f:
                                    specifiedDevice.SendData(Class19.CMD_ENDR);
                                    specifiedDevice.ReceiveData(array2);
                                    break;
                                }
                                break;
                            }
                        }
                        break;
                    }
                    if (this.OnFirmwareUpdateProgress != null)
                    {
                        this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs(0f, Class15.SZ_MODEL_NOT_MATCH, true, true));
                    }
                    return;

                    continue;                    // Roger Clark. There is a known compiler warning here. This may be an artifact caused by the decompiler
end_IL_02a2:
                    break;
                }
                if (this.OnFirmwareUpdateProgress != null)
                {
                    this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs(0f, Class15.SZ_COMM_ERROR, true, true));
                }
            }
        }
        catch (TimeoutException ex)
        {
            Console.WriteLine(ex.Message);
            if (this.OnFirmwareUpdateProgress != null)
            {
                this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs(0f, Class15.SZ_COMM_ERROR, false, false));
            }
        }
        finally
        {
            if (specifiedDevice != null)
            {
                specifiedDevice.Dispose();
            }
        }
    }
Ejemplo n.º 27
0
    public void method_8()
    {
        int num  = 0;
        int num2 = 0;
        int num3 = 0;

        byte[] array  = new byte[160];
        byte[] array2 = MainForm.DataToByte();
        int    num4   = 0;
        int    num5   = 0;
        int    num6   = 0;
        int    num7   = 0;
        int    i      = 0;
        int    num8   = 0;
        int    num9   = 0;
        bool   flag   = false;

        byte[] array3 = new byte[6];
        int    year   = DateTime.Now.Year;
        int    month  = DateTime.Now.Month;
        int    day    = DateTime.Now.Day;
        int    hour   = DateTime.Now.Hour;
        int    minute = DateTime.Now.Minute;

        array3[0] = (byte)(year / 1000 << 4 | year / 100 % 10);
        array3[1] = (byte)(year % 100 / 10 << 4 | year % 10);
        array3[2] = (byte)(month / 10 << 4 | month % 10);
        array3[3] = (byte)(day / 10 << 4 | day % 10);
        array3[4] = (byte)(hour / 10 << 4 | hour % 10);
        array3[5] = (byte)(minute / 10 << 4 | minute % 10);
        Array.Copy(array3, 0, array2, Settings.ADDR_DEVICE_INFO + Settings.OFS_LAST_PRG_TIME, 6);
        Stopwatch  stopwatch  = Stopwatch.StartNew();
        SerialPort serialPort = new SerialPort(MainForm.CurCom, MainForm.CurCbr);

        try
        {
            for (num = 0; num < this.START_ADDR.Length; num++)
            {
                num8 = this.START_ADDR[num];
                num9 = this.END_ADDR[num];
                for (i = num8; i < num9; i += num5)
                {
                    num6 = i % 128;
                    num5 = ((i + 128 <= num9) ? (128 - num6) : (num9 - i));
                    num3++;
                }
            }
            serialPort.ReadTimeout  = 5000;
            serialPort.WriteTimeout = 1000;
            try
            {
                serialPort.Open();
                if (serialPort.IsOpen)
                {
                    goto end_IL_01aa;
                }
                return;

                end_IL_01aa :;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                if (this.OnFirmwareUpdateProgress != null)
                {
                    this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs(0f, Settings.dicCommon["80000003"], false, false));
                }
                return;
            }
            while (true)
            {
                Array.Clear(array, 0, array.Length);
                serialPort.DiscardInBuffer();
                serialPort.Write(Class10.CMD_PRG, 0, Class10.CMD_PRG.Length);
                stopwatch.Reset();
                while (true)
                {
                    Array.Clear(array, 0, array.Length);
                    num7 = serialPort.Read(array, 0, 1);
                    if (array[0] != Class10.CMD_ACK[0])
                    {
                        if (stopwatch.ElapsedMilliseconds < 5000L)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        Array.Clear(array, 0, array.Length);
                        serialPort.DiscardInBuffer();
                        serialPort.Write(Class10.CMD_PRG2, 0, Class10.CMD_PRG2.Length);
                        num4 = 16;
                        for (num7 = serialPort.Read(array, 0, 16); num7 < num4; num7 += serialPort.Read(array, num7, num4 - num7))
                        {
                            Thread.Sleep(20);
                        }
                        Array.Clear(array, 0, array.Length);
                        serialPort.DiscardInBuffer();
                        serialPort.Write(Class10.CMD_ACK, 0, Class10.CMD_ACK.Length);
                        num4 = 1;
                        for (num7 = serialPort.Read(array, 0, 1); num7 < num4; num7 += serialPort.Read(array, num7, num4 - num7))
                        {
                            Thread.Sleep(20);
                        }
                        if (array[0] == Class10.CMD_ACK[0])
                        {
                            if (!flag && Settings.CUR_PWD != "DT8168")
                            {
                                i    = Settings.ADDR_PWD;
                                num5 = 8;
                                byte[] buffer = new byte[4]
                                {
                                    82,
                                    (byte)(i >> 8),
                                    (byte)i,
                                    8
                                };
                                Array.Clear(array, 0, array.Length);
                                serialPort.DiscardInBuffer();
                                serialPort.Write(buffer, 0, 4);
                                num4 = 12;
                                for (num7 = serialPort.Read(array, 0, 12); num7 < num4; num7 += serialPort.Read(array, num7, num4 - num7))
                                {
                                    Thread.Sleep(20);
                                }
                                string text = "";
                                for (num = 0; num < 8; num++)
                                {
                                    char c = Convert.ToChar(array[num + 4]);
                                    if ("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\b".IndexOf(c) < 0)
                                    {
                                        break;
                                    }
                                    text += c;
                                }
                                if (string.IsNullOrEmpty(text))
                                {
                                    Array.Clear(array, 0, array.Length);
                                    serialPort.DiscardInBuffer();
                                    serialPort.Write(Class10.CMD_ENDW, 0, Class10.CMD_ENDW.Length);
                                    num4 = 1;
                                    for (num7 = serialPort.Read(array, 0, 1); num7 < num4; num7 += serialPort.Read(array, num7, num4 - num7))
                                    {
                                        Thread.Sleep(20);
                                    }
                                    if (array[0] == Class10.CMD_ACK[0])
                                    {
                                        flag = true;
                                        break;
                                    }
                                }
                                else
                                {
                                    if (text != Settings.CUR_PWD)
                                    {
                                        Settings.CUR_PWD = "";
                                        PasswordForm passwordForm = new PasswordForm();
                                        if (passwordForm.ShowDialog() == DialogResult.OK)
                                        {
                                            Array.Clear(array, 0, array.Length);
                                            serialPort.DiscardInBuffer();
                                            serialPort.Write(Class10.CMD_ENDW, 0, Class10.CMD_ENDW.Length);
                                            num4 = 1;
                                            for (num7 = serialPort.Read(array, 0, 1); num7 < num4; num7 += serialPort.Read(array, num7, num4 - num7))
                                            {
                                                Thread.Sleep(20);
                                            }
                                            if (array[0] == Class10.CMD_ACK[0])
                                            {
                                                flag = true;
                                                break;
                                            }
                                            goto IL_07ef;
                                        }
                                        this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs(0f, "", true, true));
                                        serialPort.Close();
                                        return;
                                    }
                                    Array.Clear(array, 0, array.Length);
                                    serialPort.DiscardInBuffer();
                                    serialPort.Write(Class10.CMD_ENDW, 0, Class10.CMD_ENDW.Length);
                                    num4 = 1;
                                    for (num7 = serialPort.Read(array, 0, 1); num7 < num4; num7 += serialPort.Read(array, num7, num4 - num7))
                                    {
                                        Thread.Sleep(20);
                                    }
                                    if (array[0] == Class10.CMD_ACK[0])
                                    {
                                        flag = true;
                                        flag = true;
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                num = 0;
                                while (true)
                                {
                                    if (num < this.START_ADDR.Length)
                                    {
                                        num8 = this.START_ADDR[num];
                                        num9 = this.END_ADDR[num];
                                        i    = num8;
                                        while (i < num9)
                                        {
                                            if (!this.getCancelCom())
                                            {
                                                num6 = i % 128;
                                                num5 = ((i + 128 <= num9) ? (128 - num6) : (num9 - i));
                                                byte[] array4 = new byte[num5 + 4];
                                                array4[0] = 87;
                                                array4[1] = (byte)(i >> 8);
                                                array4[2] = (byte)i;
                                                array4[3] = (byte)num5;
                                                Array.Clear(array, 0, array.Length);
                                                Array.Copy(array2, i, array4, 4, num5);
                                                serialPort.DiscardInBuffer();
                                                serialPort.Write(array4, 0, 4 + num5);
                                                num4 = 1;
                                                for (num7 = serialPort.Read(array, 0, 1); num7 < num4; num7 += serialPort.Read(array, num7, num4 - num7))
                                                {
                                                    Thread.Sleep(20);
                                                }
                                                if (array[0] == Class10.CMD_ACK[0])
                                                {
                                                    if (this.OnFirmwareUpdateProgress != null)
                                                    {
                                                        this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs((float)(++num2) * 100f / (float)num3, i.ToString(), false, false));
                                                    }
                                                    i += num5;
                                                    continue;
                                                }
                                                goto IL_07ef;
                                            }
                                            Array.Clear(array, 0, array.Length);
                                            serialPort.DiscardInBuffer();
                                            serialPort.Write(Class10.CMD_ENDR, 0, Class10.CMD_ENDR.Length);
                                            num4 = 1;
                                            for (num7 = serialPort.Read(array, 0, 1); num7 < num4; num7 += serialPort.Read(array, num7, num4 - num7))
                                            {
                                                Thread.Sleep(20);
                                            }
                                            serialPort.Close();
                                            return;
                                        }
                                        num++;
                                        continue;
                                    }
                                    Array.Clear(array, 0, array.Length);
                                    serialPort.DiscardInBuffer();
                                    serialPort.Write(Class10.CMD_ENDW, 0, Class10.CMD_ENDW.Length);
                                    num4 = 1;
                                    for (num7 = serialPort.Read(array, 0, 1); num7 < num4; num7 += serialPort.Read(array, num7, num4 - num7))
                                    {
                                        Thread.Sleep(20);
                                    }
                                    if (array[0] != Class10.CMD_ACK[0])
                                    {
                                        break;
                                    }
                                    serialPort.Close();
                                    if (this.OnFirmwareUpdateProgress != null)
                                    {
                                        this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs(100f, Settings.dicCommon["80000102"], false, true));
                                    }
                                    return;
                                }
                            }
                        }
                    }
                    goto IL_07ef;
IL_07ef:
                    if (this.OnFirmwareUpdateProgress != null)
                    {
                        this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs(0f, Settings.dicCommon["80000004"], true, true));
                    }
                    serialPort.Close();
                    return;
                }
            }
        }
        catch (TimeoutException ex2)
        {
            Console.WriteLine(ex2.Message);
            if (this.OnFirmwareUpdateProgress != null)
            {
                this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs(0f, Settings.dicCommon["80000004"], false, false));
            }
            serialPort.Close();
        }
    }
Ejemplo n.º 28
0
    public void method_7()
    {
        int num  = 0;
        int num2 = 0;
        int num3 = 0;

        byte[]     array      = new byte[Settings.EEROM_SPACE];
        byte[]     array2     = new byte[160];
        int        num4       = 0;
        int        num5       = 0;
        int        num6       = 0;
        int        num7       = 0;
        int        i          = 0;
        int        num8       = 0;
        int        num9       = 0;
        bool       flag       = false;
        Stopwatch  stopwatch  = Stopwatch.StartNew();
        SerialPort serialPort = new SerialPort(MainForm.CurCom, MainForm.CurCbr);

        serialPort.ReadTimeout  = 5000;
        serialPort.WriteTimeout = 1000;
        try
        {
            serialPort.Open();
            if (serialPort.IsOpen)
            {
                goto end_IL_0066;
            }
            return;

            end_IL_0066 :;
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            if (this.OnFirmwareUpdateProgress != null)
            {
                this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs(0f, Settings.dicCommon["80000003"], false, false));
            }
            return;
        }
        try
        {
            for (num = 0; num < this.START_ADDR.Length; num++)
            {
                num8 = this.START_ADDR[num];
                num9 = this.END_ADDR[num];
                for (i = num8; i < num9; i += num5)
                {
                    num6 = i % 128;
                    num5 = ((i + 128 <= num9) ? (128 - num6) : (num9 - i));
                    num3++;
                }
            }
            while (true)
            {
                Array.Clear(array2, 0, array2.Length);
                serialPort.DiscardInBuffer();
                serialPort.Write(Class10.CMD_PRG, 0, Class10.CMD_PRG.Length);
                stopwatch.Reset();
                while (true)
                {
                    Array.Clear(array2, 0, array2.Length);
                    num7 = serialPort.Read(array2, 0, 1);
                    if (array2[0] != Class10.CMD_ACK[0])
                    {
                        if (stopwatch.ElapsedMilliseconds < 5000L)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        Array.Clear(array2, 0, array2.Length);
                        serialPort.DiscardInBuffer();
                        serialPort.Write(Class10.CMD_PRG2, 0, Class10.CMD_PRG2.Length);
                        num4 = 16;
                        for (num7 = serialPort.Read(array2, 0, 16); num7 < num4; num7 += serialPort.Read(array2, num7, num4 - num7))
                        {
                            Thread.Sleep(20);
                        }
                        Array.Clear(array2, 0, array2.Length);
                        serialPort.DiscardInBuffer();
                        serialPort.Write(Class10.CMD_ACK, 0, Class10.CMD_ACK.Length);
                        num4 = 1;
                        for (num7 = serialPort.Read(array2, 0, 1); num7 < num4; num7 += serialPort.Read(array2, num7, num4 - num7))
                        {
                            Thread.Sleep(20);
                        }
                        if (array2[0] == Class10.CMD_ACK[0])
                        {
                            if (!flag && Settings.CUR_PWD != "DT8168")
                            {
                                i    = Settings.ADDR_PWD;
                                num5 = 8;
                                byte[] buffer = new byte[4]
                                {
                                    82,
                                    (byte)(i >> 8),
                                    (byte)i,
                                    8
                                };
                                Array.Clear(array2, 0, array2.Length);
                                serialPort.DiscardInBuffer();
                                serialPort.Write(buffer, 0, 4);
                                num4 = 12;
                                for (num7 = serialPort.Read(array2, 0, 12); num7 < num4; num7 += serialPort.Read(array2, num7, num4 - num7))
                                {
                                    Thread.Sleep(20);
                                }
                                string text = "";
                                for (num = 0; num < 8; num++)
                                {
                                    char c = Convert.ToChar(array2[num + 4]);
                                    if ("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\b".IndexOf(c) < 0)
                                    {
                                        break;
                                    }
                                    text += c;
                                }
                                if (string.IsNullOrEmpty(text))
                                {
                                    Array.Clear(array2, 0, array2.Length);
                                    serialPort.DiscardInBuffer();
                                    serialPort.Write(Class10.CMD_ENDR, 0, Class10.CMD_ENDR.Length);
                                    num4 = 1;
                                    for (num7 = serialPort.Read(array2, 0, 1); num7 < num4; num7 += serialPort.Read(array2, num7, num4 - num7))
                                    {
                                        Thread.Sleep(20);
                                    }
                                    if (array2[0] == Class10.CMD_ACK[0])
                                    {
                                        flag = true;
                                        break;
                                    }
                                }
                                else
                                {
                                    if (text != Settings.CUR_PWD)
                                    {
                                        Settings.CUR_PWD = "";
                                        PasswordForm passwordForm = new PasswordForm();
                                        if (passwordForm.ShowDialog() == DialogResult.OK)
                                        {
                                            Array.Clear(array2, 0, array2.Length);
                                            serialPort.DiscardInBuffer();
                                            serialPort.Write(Class10.CMD_ENDR, 0, Class10.CMD_ENDR.Length);
                                            num4 = 1;
                                            for (num7 = serialPort.Read(array2, 0, 1); num7 < num4; num7 += serialPort.Read(array2, num7, num4 - num7))
                                            {
                                                Thread.Sleep(20);
                                            }
                                            if (array2[0] == Class10.CMD_ACK[0])
                                            {
                                                flag = true;
                                                break;
                                            }
                                            goto IL_0735;
                                        }
                                        this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs(0f, "", true, true));
                                        serialPort.Close();
                                        return;
                                    }
                                    Array.Clear(array2, 0, array2.Length);
                                    serialPort.DiscardInBuffer();
                                    serialPort.Write(Class10.CMD_ENDR, 0, Class10.CMD_ENDR.Length);
                                    num4 = 1;
                                    for (num7 = serialPort.Read(array2, 0, 1); num7 < num4; num7 += serialPort.Read(array2, num7, num4 - num7))
                                    {
                                        Thread.Sleep(20);
                                    }
                                    if (array2[0] == Class10.CMD_ACK[0])
                                    {
                                        flag = true;
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                for (num = 0; num < this.START_ADDR.Length; num++)
                                {
                                    num8 = this.START_ADDR[num];
                                    num9 = this.END_ADDR[num];
                                    i    = num8;
                                    while (i < num9)
                                    {
                                        if (!this.getCancelCom())
                                        {
                                            num6 = i % 128;
                                            num5 = ((i + 128 <= num9) ? (128 - num6) : (num9 - i));
                                            byte[] buffer2 = new byte[4]
                                            {
                                                82,
                                                (byte)(i >> 8),
                                                (byte)i,
                                                (byte)num5
                                            };
                                            Array.Clear(array2, 0, array2.Length);
                                            serialPort.DiscardInBuffer();
                                            serialPort.Write(buffer2, 0, 4);
                                            num4 = num5 + 4;
                                            for (num7 = serialPort.Read(array2, 0, num4); num7 < num4; num7 += serialPort.Read(array2, num7, num4 - num7))
                                            {
                                                Thread.Sleep(20);
                                            }
                                            Array.Copy(array2, 4, array, i, num5);
                                            if (this.OnFirmwareUpdateProgress != null)
                                            {
                                                this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs((float)(++num2) * 100f / (float)num3, i.ToString(), false, false));
                                            }
                                            i += num5;
                                            continue;
                                        }
                                        Array.Clear(array2, 0, array2.Length);
                                        serialPort.DiscardInBuffer();
                                        serialPort.Write(Class10.CMD_ENDR, 0, Class10.CMD_ENDR.Length);
                                        num4 = 1;
                                        for (num7 = serialPort.Read(array2, 0, 1); num7 < num4; num7 += serialPort.Read(array2, num7, num4 - num7))
                                        {
                                            Thread.Sleep(20);
                                        }
                                        serialPort.Close();
                                        return;
                                    }
                                }
                                Array.Clear(array2, 0, array2.Length);
                                serialPort.DiscardInBuffer();
                                serialPort.Write(Class10.CMD_ENDR, 0, Class10.CMD_ENDR.Length);
                                num4 = 1;
                                for (num7 = serialPort.Read(array2, 0, 1); num7 < num4; num7 += serialPort.Read(array2, num7, num4 - num7))
                                {
                                    Thread.Sleep(20);
                                }
                                if (array2[0] == Class10.CMD_ACK[0])
                                {
                                    serialPort.Close();
                                    MainForm.ByteToData(array);
                                    if (this.OnFirmwareUpdateProgress != null)
                                    {
                                        this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs(100f, Settings.dicCommon["80000101"], false, true));
                                    }
                                    return;
                                }
                            }
                        }
                    }
                    goto IL_0735;
IL_0735:
                    if (this.OnFirmwareUpdateProgress != null)
                    {
                        this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs(0f, Settings.dicCommon["80000004"], true, true));
                    }
                    serialPort.Close();
                    return;
                }
            }
        }
        catch (TimeoutException ex2)
        {
            Console.WriteLine(ex2.Message);
            if (this.OnFirmwareUpdateProgress != null)
            {
                this.OnFirmwareUpdateProgress(this, new FirmwareUpdateProgressEventArgs(0f, Settings.dicCommon["80000004"], false, false));
            }
            serialPort.Close();
        }
    }
Ejemplo n.º 29
0
 /// <summary>
 /// LoadArchiveManifest decompresses the manifest information from the backup archive into RAM
 /// and converts it from XML into a Manifest object.  An exception is thrown if the manifest
 /// cannot be retrieved.
 ///
 /// Precondition: Access to the backup folder must be available - thus any impersonation should
 /// be done before calling.
 /// </summary>
 /// <returns>The manifest from this backup archive.</returns>
 public Manifest LoadArchiveManifest(BackupProject Project, bool PromptForPassword)
 {
     try
     {
         using (ZipFile zip = ZipFile.Read(Project.CompleteBackupFolder + "\\" + this.ToString()))
         {
             foreach (ZipEntry ze in zip)
             {
                 if (ze.FileName.ToLowerInvariant() == "manifest.xml")
                 {
                     using (MemoryStream ms = new MemoryStream())
                     {
                         try
                         {
                             if (String.IsNullOrEmpty(Project.SafePassword.Password))
                             {
                                 ze.Extract(ms);
                             }
                             else
                             {
                                 ze.ExtractWithPassword(ms, Project.SafePassword.Password);
                             }
                         }
                         catch (Ionic.Zip.BadPasswordException bpe1)
                         {
                             try
                             {
                                 if (!String.IsNullOrEmpty(Project.AlternativePassword))
                                 {
                                     ze.ExtractWithPassword(ms, Project.AlternativePassword);
                                 }
                                 else
                                 {
                                     throw bpe1;
                                 }
                             }
                             catch (Ionic.Zip.BadPasswordException)
                             {
                                 bool FirstPrompt = true;
                                 if (!PromptForPassword)
                                 {
                                     throw bpe1;
                                 }
                                 while (PromptForPassword)
                                 {
                                     PasswordForm pf = new PasswordForm();
                                     if (FirstPrompt)
                                     {
                                         pf.Prompt = "The archive '" + ToString() + "' was created with a different password.  (242)";
                                     }
                                     else
                                     {
                                         pf.Prompt = "That was not a valid password for the archive '" + ToString() + "'.";
                                     }
                                     FirstPrompt = false;
                                     if (pf.ShowDialog() != DialogResult.OK)
                                     {
                                         throw new CancelException();
                                     }
                                     Project.AlternativePassword = pf.Password;
                                     try { ze.ExtractWithPassword(ms, Project.AlternativePassword); break; }
                                     catch (Ionic.Zip.BadPasswordException) { }
                                 }
                             }
                         }
                         ms.Seek(0, System.IO.SeekOrigin.Begin);
                         try
                         {
                             Manifest ret = Manifest.FromXml(ms);
                             if (ret == null)
                             {
                                 throw new FormatException();
                             }
                             return(ret);
                         }
                         catch (Exception ex)
                         {
                             throw new FormatException("Unable to parse archive's manifest.  Error: " + ex.Message + "\n\n" +
                                                       "Project: " + Project.ToString() + "\nArchive: " + ToString() + "\nManifest File: " + ze.FileName);
                         }
                     }
                 }
             }
             throw new FileNotFoundException("Manifest was not found within the archive.");
         }
     }
     catch (CancelException ce) { throw ce; }
     catch (Ionic.Zip.BadPasswordException ex)
     {
         throw new Ionic.Zip.BadPasswordException(ex.Message + "\nUnable to retrieve archive manifest.\nArchive name: " + this.ToString(), ex);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message + "\nUnable to retrieve archive manifest.\nArchive name: " + this.ToString(), ex);
     }
 }
Ejemplo n.º 30
0
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            using (var dlg = new PasswordForm())
            {
                var dr = dlg.ShowDialog(this);
                if (dr == System.Windows.Forms.DialogResult.Cancel)
                {
                    e.Cancel = true;
                    return;
                }
            }

            if (Properties.Settings.Default.StartInFullScreen)
            {
                EnterFullScreenMode(false);
            }

            controller.Stop();

            if ((thread != null) && (thread.IsAlive))
            {
                thread.Abort();
            }

            if (lastSelCamID != null)
            {
                Properties.Settings.Default.LastSelCamID = (int)this.lastSelCamID;
            }
            try
            {
                _navController.NavReturnDefultPos();
            }
            catch { }

            Properties.Settings.Default.WorkingMode = (int)switchMode.EditValue;
            Debug.WriteLine(Properties.Settings.Default.WorkingMode);
            Properties.Settings.Default.Save();

            dockManager1.SaveLayoutToXml(GetLayoutPath());
        }