예제 #1
0
        public static List <Account> PasswordDeserialize(string file, string password)
        {
            string contents = File.ReadAllText(file);

            contents = StringCipher.Decrypt(contents, password);

            var    stream = new MemoryStream(Encoding.UTF8.GetBytes(contents));
            var    ser    = new XmlSerializer(typeof(List <Account>));
            object obj    = ser.Deserialize(stream);

            stream.Close();
            return((List <Account>)obj);
        }
예제 #2
0
파일: Utils.cs 프로젝트: pointydev/SAM
        public static List <Account> PasswordDeserialize(string file, string password)
        {
            object obj = null;

            try
            {
                string contents = File.ReadAllText(file);
                contents = StringCipher.Decrypt(contents, password);

                var stream = new MemoryStream(Encoding.UTF8.GetBytes(contents));

                var ser = new XmlSerializer(typeof(List <Account>));
                obj = ser.Deserialize(stream);

                stream.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

            return((List <Account>)obj);
        }
예제 #3
0
        private void postDeserializedRefresh(bool seedAcc)
        {
            if (encryptedAccounts != null)
            {
                int bCounter = 0;
                int xcounter = 0;
                int ycounter = 0;

                // Create new button and textblock for each account
                foreach (var account in encryptedAccounts)
                {
                    string temppass = StringCipher.Decrypt(account.Password, eKey);

                    if (seedAcc)
                    {
                        decryptedAccounts.Add(new Account()
                        {
                            Name = account.Name, Password = temppass, ProfUrl = account.ProfUrl, AviUrl = account.AviUrl, Description = account.Description
                        });
                    }

                    //Console.WriteLine("Name = {0}, Pass = {1}, Url = {2}", account.Name, account.Password, account.Url);
                    //Console.WriteLine("Name = {0}, Pass = {1}, Url = {2}", account.Name, temppass, account.Url);

                    Button    accountButton = new Button();
                    TextBlock accountText   = new TextBlock();

                    accountButton.Style = (Style)Resources["MyButtonStyle"];

                    accountButton.Tag = bCounter.ToString();

                    //accountButton.Name = account.Name;
                    //accountText.Name = account.Name + "Label";
                    accountText.Text = account.Name;

                    // If there is a description, set up tooltip.
                    if (account.Description != null && account.Description.Length > 0)
                    {
                        accountButton.ToolTip = account.Description;
                    }

                    accountButton.Height = 100;
                    accountButton.Width  = 100;
                    accountText.Height   = 30;
                    accountText.Width    = 100;

                    accountButton.HorizontalAlignment = HorizontalAlignment.Left;
                    accountButton.VerticalAlignment   = VerticalAlignment.Top;
                    accountText.HorizontalAlignment   = HorizontalAlignment.Left;
                    accountText.VerticalAlignment     = VerticalAlignment.Top;

                    accountButton.Margin = new Thickness(15 + (xcounter * 120), (ycounter * 120) + 14, 0, 0);
                    accountText.Margin   = new Thickness(15 + (xcounter * 120), (ycounter * 120) + 113, 0, 0);

                    accountButton.BorderBrush = null;
                    accountText.Foreground    = new SolidColorBrush(Colors.White);

                    if (account.ProfUrl == "" || account.AviUrl == null || account.AviUrl == "" || account.AviUrl == " ")
                    {
                        accountButton.Content    = account.Name;
                        accountButton.Background = System.Windows.Media.Brushes.LightGray;
                    }
                    else
                    {
                        try
                        {
                            ImageBrush  brush1 = new ImageBrush();
                            BitmapImage image1 = new BitmapImage(new Uri(account.AviUrl));
                            brush1.ImageSource       = image1;
                            accountButton.Background = brush1;
                            buttonGrid.Children.Add(accountText);
                        }
                        catch (Exception m)
                        {
                            // Probably no internet connection or avatar url is bad
                            Console.WriteLine("Error: " + m.Message);

                            accountButton.Content = account.Name;
                        }
                    }

                    buttonGrid.Children.Add(accountButton);

                    accountButton.Click += new RoutedEventHandler(AccountButton_Click);
                    ContextMenu accountContext = new ContextMenu();
                    MenuItem    deleteItem     = new MenuItem();
                    MenuItem    editItem       = new MenuItem();
                    deleteItem.Header = "Delete";
                    editItem.Header   = "Edit";
                    accountContext.Items.Add(editItem);
                    accountContext.Items.Add(deleteItem);
                    accountButton.ContextMenu = accountContext;
                    deleteItem.Click         += delegate { deleteEntry(accountButton); };
                    editItem.Click           += delegate { editEntry(accountButton); };

                    bCounter++;
                    xcounter++;

                    if ((xcounter % Int32.Parse(accPerRow) == 0) && xcounter != 0)
                    {
                        ycounter++;
                        xcounter = 0;
                    }
                }

                int xval = 0;
                int newHeight;

                // Adjust window size and info positions
                if (ycounter == 0)
                {
                    xval              = xcounter + 1;
                    newHeight         = 190;
                    buttonGrid.Height = 141;
                }
                else
                {
                    xval              = Int32.Parse(accPerRow);
                    newHeight         = 185 + (125 * ycounter);
                    buttonGrid.Height = 141 * (125 + ycounter);
                }

                int newWidth = (xval * 120) + 25;

                resize(newHeight, newWidth);
                buttonGrid.Width = newWidth;

                // Adjust new account button
                NewButton.Margin = new Thickness(33 + (xcounter * 120), (ycounter * 120) + 52, 0, 0);
            }
        }
예제 #4
0
        private void PostDeserializedRefresh(bool seedAcc)
        {
            if (encryptedAccounts != null)
            {
                int bCounter = 0;
                int xCounter = 0;
                int yCounter = 0;

                int height = 100;
                int width  = 100;

                double heightOffset = height + (height * 0.2);
                double widthOffset  = width + (width * 0.2);

                // Create new button and textblock for each account
                foreach (var account in encryptedAccounts)
                {
                    string tempPass = StringCipher.Decrypt(account.Password, eKey);

                    if (seedAcc)
                    {
                        string temp2fa = null;
                        string steamId = null;

                        if (account.SharedSecret != null && account.SharedSecret.Length > 0)
                        {
                            temp2fa = StringCipher.Decrypt(account.SharedSecret, eKey);
                        }
                        if (account.SteamId != null && account.SteamId.Length > 0)
                        {
                            steamId = account.SteamId;
                        }

                        decryptedAccounts.Add(new Account()
                        {
                            Name = account.Name, Password = tempPass, SharedSecret = temp2fa, ProfUrl = account.ProfUrl, AviUrl = account.AviUrl, SteamId = steamId, Description = account.Description
                        });
                    }

                    Button    accountButton = new Button();
                    TextBlock accountText   = new TextBlock();

                    accountButton.Style = (Style)Resources["SAMButtonStyle"];

                    accountButton.Tag = bCounter.ToString();

                    //accountButton.Name = account.Name;
                    //accountText.Name = account.Name + "Label";
                    accountText.Text = account.Name;

                    // If there is a description, set up tooltip.
                    if (account.Description != null && account.Description.Length > 0)
                    {
                        accountButton.ToolTip = account.Description;
                    }

                    accountButton.Height = height;
                    accountButton.Width  = width;
                    accountText.Height   = 30;
                    accountText.Width    = 100;

                    accountButton.HorizontalAlignment = HorizontalAlignment.Left;
                    accountButton.VerticalAlignment   = VerticalAlignment.Top;
                    accountText.HorizontalAlignment   = HorizontalAlignment.Left;
                    accountText.VerticalAlignment     = VerticalAlignment.Top;

                    accountButton.Margin = new Thickness(15 + (xCounter * widthOffset), (yCounter * heightOffset) + 14, 0, 0);
                    accountText.Margin   = new Thickness(15 + (xCounter * widthOffset), (yCounter * heightOffset) + 113, 0, 0);

                    accountButton.BorderBrush = null;
                    accountText.Foreground    = new SolidColorBrush(Colors.White);

                    if (account.ProfUrl == "" || account.AviUrl == null || account.AviUrl == "" || account.AviUrl == " ")
                    {
                        accountButton.Content    = account.Name;
                        accountButton.Background = Brushes.LightGray;
                    }
                    else
                    {
                        try
                        {
                            ImageBrush  brush1 = new ImageBrush();
                            BitmapImage image1 = new BitmapImage(new Uri(account.AviUrl));
                            brush1.ImageSource       = image1;
                            accountButton.Background = brush1;
                            buttonGrid.Children.Add(accountText);
                        }
                        catch (Exception m)
                        {
                            // Probably no internet connection or avatar url is bad
                            Console.WriteLine("Error: " + m.Message);

                            accountButton.Content = account.Name;
                        }
                    }

                    buttonGrid.Children.Add(accountButton);

                    accountButton.Click += new RoutedEventHandler(AccountButton_Click);
                    accountButton.PreviewMouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(AccountButton_MouseDown);
                    accountButton.PreviewMouseLeftButtonUp   += new System.Windows.Input.MouseButtonEventHandler(AccountButton_MouseUp);
                    accountButton.MouseLeave += new System.Windows.Input.MouseEventHandler(AccountButton_MouseLeave);

                    ContextMenu accountContext = new ContextMenu();

                    MenuItem deleteItem = new MenuItem();
                    MenuItem editItem   = new MenuItem();
                    MenuItem exportItem = new MenuItem();

                    deleteItem.Header = "Delete";
                    editItem.Header   = "Edit";
                    exportItem.Header = "Export";

                    accountContext.Items.Add(editItem);
                    accountContext.Items.Add(deleteItem);
                    accountContext.Items.Add(exportItem);

                    accountButton.ContextMenu         = accountContext;
                    accountButton.ContextMenuOpening += new ContextMenuEventHandler(ContextMenu_ContextMenuOpening);

                    deleteItem.Click += delegate { DeleteEntry(accountButton); };
                    editItem.Click   += delegate { EditEntry(accountButton); };
                    exportItem.Click += delegate { ExportAccount(Int32.Parse(accountButton.Tag.ToString())); };

                    bCounter++;
                    xCounter++;

                    if ((xCounter % Int32.Parse(accPerRow) == 0) && xCounter != 0)
                    {
                        yCounter++;
                        xCounter = 0;
                    }
                }

                int xVal = 0;
                int newHeight;

                // Adjust window size and info positions
                if (yCounter == 0)
                {
                    xVal              = xCounter + 1;
                    newHeight         = 190;
                    buttonGrid.Height = 141;
                }
                else
                {
                    xVal              = Int32.Parse(accPerRow);
                    newHeight         = 185 + (125 * yCounter);
                    buttonGrid.Height = 141 * (125 + yCounter);
                }

                int newWidth = (xVal * 120) + 25;

                Resize(newHeight, newWidth);
                buttonGrid.Width = newWidth;

                // Adjust new account and export buttons
                Thickness newThickness    = new Thickness(33 + (xCounter * widthOffset), (yCounter * heightOffset) + 52, 0, 0);
                Thickness offsetThickness = new Thickness(33 + (xCounter * widthOffset), (yCounter * heightOffset) + 92, 0, 0);

                NewButton.Margin          = newThickness;
                ExportButton.Margin       = newThickness;
                CancelExportButton.Margin = offsetThickness;
            }
        }