private void GetInfo_btn_Click(object sender, RoutedEventArgs e) { var path = Path_tb.Text.Trim(); WindowsBackup_App.remove_ending_slash(ref path); Path_tb.Text = path; var path_status = file_name_reg.get_path_status(path); if (path_status == null) { Info_text.Text = "No info"; Info_text.Visibility = Visibility.Visible; Delete_btn.Visibility = Visibility.Collapsed; } else if (path_status.is_file == false) { Info_text.Text = "Path is a directory"; Info_text.Visibility = Visibility.Visible; Delete_btn.Visibility = Visibility.Collapsed; } else if (path_status.is_file) { var sb = new StringBuilder(); sb.AppendLine("Encrypted file name: " + path_status.alt_file_name); if (path_status.modified_time != null) { sb.AppendLine("File modified time (UTC): " + path_status.modified_time.Value); } else { sb.AppendLine("File modified time unknown"); } Info_text.Text = sb.ToString(); Info_text.Visibility = Visibility.Visible; Delete_btn.Visibility = Visibility.Visible; } }
/// <summary> /// Tests the FileNameRegistration class. Retrieve names for some /// files, delete nodes, add nodes, and perform a compact operation. /// </summary> public void test_FileNameRegistration() { Console.WriteLine("About to test the FileNameRegistration. Attempt to get a " + "few alternative file names. Then delete some files to trigger " + "compaction. Press any key to continue, or ESC to skip."); if (hit_esc_key()) { return; } // Add files to the file name registration tree. var file_name_reg = new FileNameRegistration(file_name_reg_xml); Console.WriteLine(); Console.WriteLine("The test now creates a basic directory structure and " + "print information about it."); // Create a basic directory structure. var path_status = file_name_reg.get_path_status(@"E:\a"); if (path_status == null) { // .add_file(...) can only happen once per file, so this block // should run just once. Console.WriteLine(file_name_reg.add_file(@"E:\a")); Console.WriteLine(file_name_reg.add_file(@"E:\a1\b")); Console.WriteLine(file_name_reg.add_file(@"E:\a1\c")); Console.WriteLine(file_name_reg.add_file(@"E:\a1\c2\cc2")); Console.WriteLine(file_name_reg.add_file(@"E:\a1\c2\cc2b")); Console.WriteLine(file_name_reg.add_file(@"E:\a1\c2\cc2c")); Console.WriteLine(file_name_reg.add_file(@"E:\a1\c2\cc2dd\c2a")); Console.WriteLine(file_name_reg.add_file(@"E:\a1\c2\cc2dd\c2b")); Console.WriteLine(file_name_reg.add_file(@"E:\a1\c3")); } // print how things look so far file_name_reg.print(); file_name_reg.print(@"E:\temp\temp\fnr.txt"); Console.WriteLine(); // Test the .get_path_status(...) string[] paths = { @"E:\a1\c2", @"E:\a1\b", @"E:\a1\no_such_thing" }; foreach (string path in paths) { var path_info = file_name_reg.get_path_status(path); if (path_info == null) { Console.WriteLine(path + " does not exist."); } else { Console.WriteLine(path); Console.WriteLine("is_file = " + path_info.is_file + "; alt_file_name = " + path_info.alt_file_name + "; modified_time = " + path_info.modified_time); } Console.WriteLine(); } // Test the .get_names(...) List <string> sub_dir_names = null, file_names = null, alt_file_names = null; string path2 = @"E:\a1\c2"; file_name_reg.get_names(path2, ref sub_dir_names, ref file_names, ref alt_file_names); if (sub_dir_names != null) { Console.Write(path2 + " sub directory names: "); foreach (var name in sub_dir_names) { Console.Write(name + ", "); } Console.WriteLine(); } if (file_names != null) { Console.Write(path2 + " file names: "); foreach (var name in file_names) { Console.Write(name + ", "); } Console.WriteLine(); } if (alt_file_names != null) { Console.Write(path2 + " alternative file names: "); foreach (var name in alt_file_names) { Console.Write(name + ", "); } Console.WriteLine(); } pause(); // Delete Console.WriteLine(@"Delete E:\a1\c2"); file_name_reg.delete(@"E:\a1\c2"); file_name_reg.print(); pause(); file_name_reg.Dispose(); // Reload from file to trigger compaction file_name_reg = new FileNameRegistration(file_name_reg_xml); // Get modified time Console.WriteLine("Test changing the modified time."); Console.WriteLine(@"E:\a1\b modified time = " + file_name_reg.get_modified_time(@"E:\a1\b")); // Set modified time file_name_reg.set_modified_time(@"E:\a1\b", DateTime.Now); Console.WriteLine(@"E:\a1\b modified time = " + file_name_reg.get_modified_time(@"E:\a1\b")); pause(); // Try a bigger directory Console.WriteLine("Attaching files from " + @"E:\temp\temp"); string[] file_paths = Directory.GetFiles(@"E:\temp\temp", "*", SearchOption.AllDirectories); if (file_name_reg.get_path_status(file_paths[0]) == null) { foreach (string path in file_paths) { Console.Write(file_name_reg.add_file(path) + " "); } } Console.WriteLine(); file_name_reg.print(); pause(); // Try reload from disk Console.WriteLine("Reload from disk."); file_name_reg.Dispose(); file_name_reg = new FileNameRegistration(file_name_reg_xml); file_name_reg.print(); // Try to create files using explicit file IDs. This is necessary // for the restoration process. The file IDs need to be >= 1000 // per design spec. pause(); file_name_reg.Dispose(); Console.WriteLine("Adding new files with explicit file IDs\n"); file_name_reg = new FileNameRegistration(file_name_reg_xml); if (file_name_reg.get_path_status(@"c:\test\whatever\123.txt") == null) { file_name_reg.add_file(@"c:\test\whatever\123.txt", "a", 2123, 0); file_name_reg.add_file(@"c:\test\whatever\67.txt", "a", 2067, 0); file_name_reg.add_file(@"c:\test\whatever2\320.txt", "a", 2320, 0); file_name_reg.set_modified_time(@"c:\test\whatever2\320.txt", DateTime.Now); file_name_reg.add_file(@"c:\test\whatever\999.txt", "b", 2999, 0); } file_name_reg.Dispose(); file_name_reg = new FileNameRegistration(file_name_reg_xml); path_status = file_name_reg.get_path_status(@"c:\test\whatever\999.txt"); Console.WriteLine(@"c:\test\whatever\999.txt"); Console.WriteLine("is_file = " + path_status.is_file + "; alt_file_name = " + path_status.alt_file_name + "; modified_time = " + path_status.modified_time); file_name_reg.Dispose(); Console.WriteLine(); }