public void Encode(string source_file_or_folder_path, string path_for_decoded_folder, string directory_path_for_encoded) { canc_token.ThrowIfCancellationRequested(); string message = "The file " + source_file_or_folder_path + " was deleted or renamed.\n" + "Please, restore it or skip it's archiving\n"; while (true) { PathChecking checked_correctness = (PathChecking)controller.Invoke(controller.OfferToSkip, source_file_or_folder_path, message); //source_file_or_folder_path); if (checked_correctness == PathChecking.wants_to_skip) { return; } if (checked_correctness == PathChecking.correct_path) { break; } } if (!Directory.Exists(source_file_or_folder_path))//if it is not a directory but a file { byte[] source = File.ReadAllBytes(source_file_or_folder_path); string[] paths = SetPathsEncodingFile(source_file_or_folder_path, path_for_decoded_folder, directory_path_for_encoded); string path_for_decoded_file = paths[0]; string destination_dictionary_path = paths[1]; string destination_file_path = paths[2]; DecodingInfo info = new DecodingInfo(); info.PathForDecoded = path_for_decoded_file; ResetPartial((int)((source.Length / interval + 1) / 0.75), source_file_or_folder_path);//25 процентов времени занимает подсчет приоритетов, далее progress_bar performstep для каждых interval байтов + 1 если длина файла меньше interval info.NumberOfCharacters = (ulong)source.Length; EncodeBytes(source, destination_dictionary_path, destination_file_path, ref info); PartialPerformStep(controller.PartialProgressBar.Maximum - controller.PartialProgressBar.Value); EntirePerformStep(1); } else { string[] sub_dirs = Directory.GetDirectories(source_file_or_folder_path); string[] sub_files = Directory.GetFiles(source_file_or_folder_path); List <string> current_folder_content = new List <string>(); current_folder_content.AddRange(sub_dirs); current_folder_content.AddRange(sub_files); string[] paths = SetPathsEncodingDirectory(source_file_or_folder_path, path_for_decoded_folder, directory_path_for_encoded); string new_directory_path_for_encoded = paths[0]; string directory_path_for_decoded = paths[1]; foreach (var sub_path in current_folder_content) { Encode(sub_path, directory_path_for_decoded, new_directory_path_for_encoded); } } }
private void OKButton_Click(object sender, EventArgs e) { PathChecking checked_correctness = CheckIfCorrectPath(_source_file_or_folder_path, "The file " + _source_file_or_folder_path + " was deleted or renamed.\n" + "Please, restore it or skip it's archiving\n"); if (checked_correctness == PathChecking.correct_path) { OKButton.Visible = false; CountAmountOfFiles(); if (_type == TypeOfOperation.encode) { EntireProgressBar.Maximum = _amount_of_files; } else { EntireProgressBar.Maximum = _amount_of_files / 2; } _calculation_task = Task.Factory.StartNew(() => this.PerformOperation(), _token_source.Token).ContinueWith((prev_task) => Application.Exit()); //запускается поток для обработки файлов } else { if (checked_correctness == PathChecking.wants_to_skip) { Application.Exit(); } } }
public void Decode(string source_directory_path, string desination_folder_path) { canc_token.ThrowIfCancellationRequested(); string message = "The file " + source_directory_path + " was deleted or renamed.\n" + "Please, restore it or skip it's archiving\n"; while (true) { PathChecking checked_correctness = (PathChecking)controller.Invoke(controller.OfferToSkip, source_directory_path, message); //source_file_or_folder_path); if (checked_correctness == PathChecking.wants_to_skip) { return; } if (checked_correctness == PathChecking.correct_path) { break; } } string[] file_to_decode = null; try { file_to_decode = Directory.GetFiles(source_directory_path, "*.bin");//an array of files because it must contain encoded file and a hidden dictionary } catch { throw new Exception("Please,select an archive folder\n"); } while (true) { if (file_to_decode.Length >= 2) { int dictionary_index = 0; Regex dictionary_regex = new Regex(@"(dictionary.bin){1}$"); if (dictionary_regex.Match(file_to_decode[1]).Value != "") { dictionary_index = 1; } byte[] source = File.ReadAllBytes(file_to_decode[1 - dictionary_index]); ResetPartial(source.Length / interval + 1, file_to_decode[1 - dictionary_index]); DecodingInfo info = null; try { IFormatter formatter = new BinaryFormatter(); Stream DictStream = new FileStream(file_to_decode[dictionary_index], FileMode.Open, FileAccess.Read, FileShare.Read); info = (DecodingInfo)formatter.Deserialize(DictStream); DictStream.Close(); } catch { string message2 = "The folder " + source_directory_path + " has been modified and does not contain an archived file\nPlease,restore it or skip it's archiving\n"; PathChecking checked_correctness2 = (PathChecking)controller.Invoke(controller.OfferToSkip, source_directory_path, message); //source_file_or_folder_path); if (checked_correctness2 == PathChecking.wants_to_skip) { return; } if (checked_correctness2 == PathChecking.restored_the_file) { continue; } } byte[] destinationBytes = DecodeBytes(source, info); WriteAll(desination_folder_path + info.PathForDecoded, destinationBytes); PartialPerformStep(controller.PartialProgressBar.Maximum - controller.PartialProgressBar.Value); EntirePerformStep(1); return; } else { string[] subdirs = Directory.GetDirectories(source_directory_path); foreach (var subdir in subdirs) { Decode(subdir, desination_folder_path); } return; } } }
private void OKButton_Click(object sender, EventArgs e) { SkipClicked = PathChecking.restored_the_file; this.Close(); }
public FileNotFoundForm(string message) { InitializeComponent(); MessageLabel.Text = message; SkipClicked = PathChecking.wants_to_skip; }