private void DecButton_Click(object sender, RoutedEventArgs e) { //Laddar in egen MessageBox. msgBox MsgBox = new msgBox(); //Bytar källa beroende på Status på MSGBOX formen. Läses in i if och else satserna. BitmapImage bmiOK = new BitmapImage(new Uri("ok_like.png", UriKind.Relative)); BitmapImage bmiER = new BitmapImage(new Uri("error_cooking.png", UriKind.Relative)); //kortar ner , ska implenteras i user applications settings senare. string contMSGOK = "Decrypted & Uncompressed"; string contMSGER = "A Error was encounted, Check Log!"; string rsaErr = "No Key!, Set it before Encrypting"; string rsaOK = "Keys are Set!"; string tarG; tarG = Properties.Settings.Default.defaultCompress; // Fetcher. cspp.KeyContainerName = keyName; rsa = new RSACryptoServiceProvider(cspp); rsa.PersistKeyInCsp = true; var selectedItem = (dynamic)lstBrow1.SelectedItems[0]; // Lagrar nyckelpar i cont. if (rsa == null) { MsgBox.imgvalid.Source = bmiER; MsgBox.txtBlock.Text = rsaErr; MsgBox.ShowDialog(); } else { DecryptFile(selectedItem.File); // Decrypt på vald fil. //Loggar lstbox1.Items.Add(Environment.NewLine + "Got the keys... " + Environment.NewLine); lstbox1.Items.Add(Environment.NewLine + "File " + selectedItem.File + "with total: " + _totalFileCount + " files " + Environment.NewLine + "was Decrypted and uncompressed" + Environment.NewLine + "Without errors" + Environment.NewLine); // Filhantering om det lyckas! string fName = EncrFolder + selectedItem.File; if (fName != null) { FileInfo fInfo = new FileInfo(fName); string name = fInfo.FullName; FileInfo enF = new FileInfo(fName); enF.Delete(); //GridView ListView, uppdateras! lstBrow1.Items.Clear(); GridVList(); uZip(Properties.Settings.Default.dec_last, tarG); // Kör igång uppackning. } } }
void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { //Laddar egen messagebox. msgBox MsgBox = new msgBox(); //Bytar källa beroende på Status på MSGBOX formen. Läses in i if och else satserna. BitmapImage bmiOK = new BitmapImage(new Uri("ok_like.png", UriKind.Relative)); BitmapImage bmiER = new BitmapImage(new Uri("error_cooking.png", UriKind.Relative)); //kortar ner , ska implenteras i user applications settings senare. string contMSGOK = "Compressed & Encrypted!"; string contMSGER = "A Error was encounted\r\nCheck Log!"; string rsaErr = "No Key!, Set it before Encrypting"; string rsaOK = "Keys are Set!"; if (e.Error != null) { MsgBox.imgvalid.Source = bmiER; MsgBox.txtBlock.Text = contMSGER; lstbox1.Items.Add(Environment.NewLine + "Processing folder: " + Environment.NewLine + fileopen.Text + "with total files: " + Environment.NewLine + _totalFileCount + "errors where predicted" + Environment.NewLine + "check settings!"); MsgBox.ShowDialog(); } else { settings Sett = new settings(); //lagrar nycklar i container. cspp.KeyContainerName = keyName; rsa = new RSACryptoServiceProvider(cspp); MsgBox.txtBlock.Text = rsaOK; MsgBox.imgvalid.Source = bmiER; MsgBox.ShowDialog(); //-------------------------------------------------------------------------------------------------------------------------------------------- // Äldre försök fungerade inte på rätt sett, ingen error handler. // //rsa.PersistKeyInCsp = true; // if (rsa == null) // lstbox1.Items.Add(Environment.NewLine + "Public: " + Environment.NewLine + cspp.KeyContainerName + Environment.NewLine); // else // lstbox1.Items.Add(Environment.NewLine + "Public: " + Environment.NewLine + cspp.KeyContainerName + Environment.NewLine); //---------------------------------------------------------------------------------------------------------------------------------------------- if (rsa == null) { MsgBox.txtBlock.Text = rsaErr; MsgBox.imgvalid.Source = bmiER; MsgBox.ShowDialog(); } else { string fName = EncrFolder + txName.Text + ".henc"; //till filhanteringen string oldenc = EncrFolder + txName.Text + ".enc"; if (fName != null) { FileInfo fInfo = new FileInfo(fName); // Pass the file name without the path. string name = fInfo.FullName; EncryptFile(name); } MsgBox.imgvalid.Source = bmiOK; MsgBox.txtBlock.Text = contMSGOK; //skickar status till Loggen... lstbox1.Items.Add(Environment.NewLine + "Folder " + fileopen.Text + "with total: " + _totalFileCount + " files " + Environment.NewLine + "was Compressed and Encrypted" + Environment.NewLine + "Without errors" + Environment.NewLine); //Hanterar gamla och nya encrypterade filer. FileInfo enF = new FileInfo(fName); enF.Delete(); FileInfo f = new FileInfo(oldenc); f.CopyTo(fName); f.Delete(); prgBar.Value = 0; lstBrow1.Items.Clear(); GridVList(); this.worker.Dispose(); return; } } }