public long GetFileSize(int countOfNames, ListBox names) { Passwords paswordLine = this; long FileSize = 0; int countOFname = 1;//для того чтобы если имен нет мы прибавляли просто по еденице к размеру файла paswordLine.PositionOnStart(); if (countOfNames != 0) { countOFname = countOfNames * paswordLine.GetCountOfNames(); } while (!paswordLine.EndOfPasswordLine()) { switch (paswordLine.GetCurrentChar()) { case PassContent.NAME: if (countOfNames == 0) { countOFname = 1; } else { FileSize = FileSize + GetCharAmount(names); } break; case PassContent.NUMBER: FileSize = FileSize + countOFname; //добавляем к размеру файла break; case PassContent.LETTER: FileSize = FileSize + countOFname; //добавляем к размеру файла break; case PassContent.SmallLetter: FileSize = FileSize + countOFname; //добавляем к размеру файла break; case PassContent.BigLetter: FileSize = FileSize + countOFname; //добавляем к размеру файла break; case PassContent.YEAR: FileSize = FileSize + 4 * countOFname; //добавляем к размеру файла break; case PassContent.LowLine: FileSize = FileSize + countOFname; //добавляем к размеру файла break; default: break; } paswordLine.StepNext(); } paswordLine.ReturnCurrentPosition(); return(FileSize); }
public int GetAmountOfPass(int countOfNames) { Passwords paswordLine = this; int amountofPass = 1; paswordLine.PositionOnStart(); while (!paswordLine.EndOfPasswordLine()) { switch (paswordLine.GetCurrentChar()) { case PassContent.NAME: if (countOfNames == 0) { amountofPass = amountofPass * 1; //если лист имен пуст чтобы не обнулялось } else { amountofPass = amountofPass * countOfNames; } break; case PassContent.NUMBER: amountofPass = amountofPass * 10; break; case PassContent.LETTER: amountofPass = amountofPass * 52; break; case PassContent.SmallLetter: amountofPass = amountofPass * 26; break; case PassContent.BigLetter: amountofPass = amountofPass * 26; break; case PassContent.YEAR: amountofPass = amountofPass * 140; break; case PassContent.LowLine: amountofPass = amountofPass * 1; break; default: break; } paswordLine.StepNext(); } paswordLine.ReturnCurrentPosition(); return(amountofPass); }
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { fileForPasswords.CloseFile(); pass.ReturnCurrentPosition(); if (e.Cancelled == true) { progressBar.Value = progressBar.Minimum; MessageBox.Show("Canceled!"); currentPassword_label.Text = "Operation canceled!"; } else if (e.Error != null) { MessageBox.Show(e.Error.Message); } else { progressBar.Value = progressBar.Maximum; MessageBox.Show("Лист паролей создан!!!"); } }