예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            Form form = new FormAdd(2);

            if (form.ShowDialog(this) == DialogResult.OK && !String.IsNullOrEmpty(addString))
            {
                filesList.Add(new List <string>()
                {
                    addString
                });
                createButton(addString);
                prepareToWrite();
            }
            form.Dispose();
            addString = null;
        }
예제 #2
0
 private void textBox1_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter && textBox1.Text.Length > 0)
     {
         userPassword = textBox1.Text;
         Visible      = false;
         textBox1.Clear();
         textBox1.Visible = false;
         textBox1.Enabled = false;
         Size             = new Size(778, 400);
         Location         = new Point((Screen.PrimaryScreen.WorkingArea.Width - Width) / 2, (Screen.PrimaryScreen.WorkingArea.Height - Height) / 2);
         button1.Enabled  = true;
         button2.Enabled  = true;
         button3.Enabled  = true;
         button4.Enabled  = true;
         string      dateString = null;
         RegistryKey regkey     = Registry.CurrentUser.OpenSubKey(regKey, true);
         if (regkey != null)
         {
             pathFile   = (string)regkey.GetValue(regPath);
             dateString = (string)regkey.GetValue(regDate);
         }
         if (pathFile != null && dateString != null)
         {
             pathFile   = decryptString(pathFile);
             dateString = decryptString(dateString);
             if (dateString != null && dateString.Length == 19)
             {
                 dateFile = DateTime.ParseExact(dateString, "dd.MM.yyyy HH:mm:ss", CultureInfo.InvariantCulture);
             }
         }
         else
         {
             regkey = Registry.CurrentUser.CreateSubKey(regKey);
             Form form = new FormAdd(0);
             form.ShowDialog(this);
             form.Dispose();
             regkey.SetValue(regDate, encryptString(dateFile.ToString("dd.MM.yyyy HH:mm:ss")));
             form = new FormAdd(1);
             if (form.ShowDialog(this) == DialogResult.OK && !String.IsNullOrEmpty(addString))
             {
                 pathFile = addString;
                 if (!File.Exists(pathFile) || (File.Exists(pathFile) && new FileInfo(pathFile).Length == 0))
                 {
                     prepareToWrite();
                 }
                 if (File.Exists(pathFile) && new FileInfo(pathFile).Length > 0)
                 {
                     regkey.SetValue(regPath, encryptString(pathFile));
                 }
             }
             form.Dispose();
         }
         regkey.Close();
         if (File.Exists(pathFile) && new FileInfo(pathFile).Length > 0)
         {
             List <string> cacheFile = new List <string>();
             cacheFile.AddRange(File.ReadAllLines(pathFile));
             if (cacheFile.Count > 1 && decryptString(cacheFile[0]) == "PassMan file test string.")
             {
                 string head = decryptString(cacheFile[1]);
                 if (!String.IsNullOrEmpty(head))
                 {
                     bool     start     = false;
                     string[] tabsStart = head.Split(new string[] { "|" }, StringSplitOptions.None);
                     for (int i = 2; i < cacheFile.Count; i++)
                     {
                         if (!String.IsNullOrEmpty(cacheFile[i]))
                         {
                             if (tabsStart.Length > tabIndex && tabsStart[tabIndex] == i.ToString())
                             {
                                 string line = decryptString(cacheFile[i]);
                                 if (!String.IsNullOrEmpty(line))
                                 {
                                     filesList.Add(new List <string>()
                                     {
                                         line
                                     });
                                     createButton(line);
                                     start = true;
                                 }
                             }
                             else if (start)
                             {
                                 filesList[filesList.Count - 1].Add(cacheFile[i]);
                             }
                         }
                     }
                 }
             }
         }
         else
         {
             button3.ForeColor = Color.Red;
             button4.ForeColor = Color.Red;
         }
         Visible = true;
     }
 }