コード例 #1
0
        private async Task ResetAsync()
        {
            if (HIOStaticValues.CheckSyncingData())
            {
                return;
            }
            HIOStaticValues.tmain.AccountManager.SourceItems.Clear();
            await UIService.Execute(async() =>
            {
                if (HIOStaticValues.CheckSyncingData())
                {
                    return;
                }
                if (HIOStaticValues.CONNECTIONBHIO == true)
                {
                    Commands ic = new Commands();
                    if (!ic.EraseAll())
                    {
                        HIOStaticValues.popUp("Something went wrong!");
                    }
                }
                else
                {
                    HIOStaticValues.popUp("HIO is not connect!");
                }
            });

            //Application.Current.Dispatcher.Invoke(new Action(() =>
            //{
            //    AddNewDevice();
            //}));
        }
コード例 #2
0
 private void _Form_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     if (IsImporting == true)
     {
         e.Cancel = true;
         HIOStaticValues.popUp("You can not close window while importing data");
     }
 }
コード例 #3
0
        private void ResetPersonalPinOK()
        {
            ShowResetPersonalPin = false;
            Commands cmd = new Backend.Commands();

            if (!cmd.EraseAll())
            {
                HIOStaticValues.popUp("Something went wrong!");
                return;
            }
            if (SetupWizard != null)
            {
                SetupWizard.ActivePage = SetupWizard.Pages.First(t => t is TNewDeviceAddingPage1);
            }
        }
コード例 #4
0
        private void OnSelectedItemChanged()
        {
            if (SelectedItem != null)
            {
                DataBase db = new DataBase();
                Dictionary <string, string> dicData = new Dictionary <string, string>();
                db.Update_LastUsed_User(SelectedItem.Id.ToString());

                HIOStaticValues.username = SelectedItem.Description;
                byte[] rowidByteArray = BitConverter.GetBytes(SelectedItem.Id).ToArray();
                /////////////////////////////////////////////
                if (SelectedItem.Url == url)
                {
                    if (GetPass)
                    {
                        if (HIOStaticValues.TPinStatus())
                        {
                            string pass = HIOStaticValues.BaS.GetPassFromSwitch(rowidByteArray).pass;
                            dicData.Add("CMD", "PASS");
                            dicData.Add("DATA", pass);
                            HIOStaticValues.BaS.Write(dicData, Source, true);
                        }
                    }
                    else
                    {
                        dicData.Add("CMD", "CHECKREADYUSER");

                        HIOStaticValues.username = SelectedItem.Description;
                        HIOStaticValues.BaS.Write(dicData, Source, false);
                    }
                }
                else
                {
                    /////////////////////////////////////////////add user from another url

                    if (GetPass)
                    {
                        if (HIOStaticValues.TPinStatus())
                        {
                            string pass = HIOStaticValues.BaS.GetPassFromSwitch(rowidByteArray).pass;
                            dicData.Add("CMD", "PASS");
                            dicData.Add("DATA", pass);
                            HIOStaticValues.BaS.Write(dicData, Source, true);
                        }
                    }
                    else
                    {
                        if (!db.CheckExistUser(SelectedItem.Description, url))
                        {
                            if (HIOStaticValues.TPinStatus())
                            {
                                if (HIOStaticValues.BaS.UpdateSwitch(SelectedItem.Id.ToString(), url, "", SelectedItem.Title, SelectedItem.Description, "", 0x0) == 0)
                                {
                                    if (db.UpdateDBFromRowID(SelectedItem.Id.ToString(), url, "", SelectedItem.Title, SelectedItem.Description))
                                    {
                                        HIOStaticValues.username = SelectedItem.Description;
                                        dicData.Add("CMD", "CHECKREADYUSER");

                                        HIOStaticValues.BaS.Write(dicData, Source, false);
                                    }
                                    else
                                    {
                                        HIOStaticValues.popUp("Sorry,We have a problem while update record\nPlease try again.");
                                    }
                                }

                                else
                                {
                                    HIOStaticValues.popUp("Sorry,We have a problem while update record\nPlease try again.");
                                }
                            }
                        }
                        else
                        {
                            HIOStaticValues.popUp("This user already exists,You can modify it in the Edit Form.");
                        }
                    }
                }
                Close();
            }
        }
コード例 #5
0
        private async void StartImportingAsync()
        {
            if (HIOStaticValues.CheckSyncingData())
            {
                return;
            }

            List <LoginFieldS> listUser = new List <LoginFieldS>();

            try
            {
                if (HIOStaticValues.CONNECTIONBHIO == true)
                {
                    Commands cmd          = new Backend.Commands();
                    int      userImported = 0;
                    DataBase dbLocal      = new DataBase();
LabelImport:
                    if (cmd.AmISync() == SyncronizingStateEnum.Synced)
                    {
                        IsImporting = true;

                        await Task.Run(() =>
                        {
                            Backup bk       = new Backup();
                            Chrome chrome   = new Chrome();
                            Firefox firefox = new Firefox();
                            Edge edge       = new Edge();
                            double progress = ImportProgressPercent;
                            //  var itemList = Items.Where(t => t.IsChecked);

                            foreach (var item in Items.Where(t => t.IsChecked))
                            {
                                if (item.Title == "Load Backup")
                                {
                                    listUser.AddRange(bk.LoadBackup());
                                }
                                if (item.Title == "Google Chrome")
                                {
                                    listUser.AddRange(chrome.getDataFromChrome());
                                }
                                if (item.Title == "Mozilla Firefox")
                                {
                                    listUser.AddRange(firefox.FetchPassword());
                                }
                                if (item.Title == "Edge")
                                {
                                    listUser.AddRange(edge.ReadPasswords());
                                }
                            }
                            listUser = listUser.Distinct(new loginFieldsCompare()).ToList();
                            int rows = listUser.Count;
                            // ImportVisible = true;

                            try
                            {
                                HIOStaticValues.IMPORT_ON = true;
                                if (rows == 0)
                                {
                                    MessageErr = "No account exist in your browsers";
                                    return;
                                }
                                for (int i = 0; i < rows; i++)
                                {
                                    ImportProgressPercent = (progress == 0) ? (i * 100) / (rows) : progress + ((i * 100) / (rows)) / 2;
                                    int res = HIOStaticValues.BaS.InsertToSwitch(new LoginFieldS {
                                        password = listUser[i].password, userName = listUser[i].userName, title = listUser[i].title, url = listUser[i].url
                                    });

                                    if (res <= 0)
                                    {
                                        if (res == -2)
                                        {
                                            throw new Exception($"Time out.\n {i}  accounts are imported successfully from {rows} accounts");
                                        }
                                        if (res == -3)
                                        {
                                            throw new Exception($"No space is available.\n {userImported} accounts are imported successfully");
                                        }

                                        break;
                                    }
                                    userImported++;
                                    dbLocal.insertToDatabase(res.ToString(), listUser[i].url, (string)listUser[i].userName, "", listUser[i].title);
                                }
                            }
                            catch (SQLiteException ex) when(ex.ErrorCode == 5)
                            {
                                MessageErr = $"HIO needs to close all browsers!{Environment.NewLine}Please save or close your Tabs if your are using any browsers.";
                                return;
                            }
                            catch (Exception ex)
                            {
                                MessageErr = ex.Message;
                                return;
                            }

                            HIOStaticValues.IMPORT_ON = false;
                            System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
                            {
                                IsImporting           = false;
                                ImportVisible         = false;
                                ImportProgressPercent = 0;
                                IsComplete            = true;
                                //  if (db_way2 != "")
                                //    System.IO.File.Delete(db_way2);
                            }));
                        });



                        if (Items.Any(t => t.IsChecked))
                        {
                            MoveNextPage();
                        }
                    }
                    else
                    {
                        HIOStaticValues.popUp("You are not sync!\nPlease wait,We are syncing data...");
                        IsImporting = true;
                        DispatcherTimer dt = new DispatcherTimer();
                        dt.Interval = TimeSpan.FromSeconds(1);
                        dt.Tick    += Dt_Tick;
                        dt.Start();
                        int res = await Task.Run(() =>
                        {
                            DataBase db       = new DataBase();
                            Commands resetCmd = new Backend.Commands();
                            resetCmd.ResetSync();
                            return(resetCmd.Sync());
                        });

                        dt.Stop();

                        if (res == 1)
                        {
                            goto LabelImport;
                        }
                    }
                }
                else
                {
                    TMessageBox.Show("HIO is not connect!");
                }
            }
            finally
            {
                IsImporting = false;

                HIOStaticValues.IMPORT_ON = false;
            }
        }