public void JoinFiles_TestMethod() { DataDepositer.Helper h = new DataDepositer.Helper(); DataDepositer.FileManipulator fm = new DataDepositer.FileManipulator(); // String filePath = "d:\\test\\datadepositor\\part\\test.txt"; String filePath = "d:\\test\\datadepositor\\parts"; String filePathJoin = "d:\\test\\datadepositor\\join\\test.txt"; bool isOk = fm.JoinFiles(filePath, filePathJoin); if (!isOk) { throw new Exception("JoinFiles_TestMethod()"); } }
public void SplitFile_TestMethod() { DataDepositer.Helper h = new DataDepositer.Helper(); DataDepositer.FileManipulator fm = new DataDepositer.FileManipulator(); // String fileName = "test.txt"; //String fileName = "d:\\test\\datadepositor\\test.txt"; String filePath = "d:\\test\\datadepositor\\test.txt"; String filePathParts = "d:\\test\\datadepositor\\parts"; int num = 3; bool isOk = fm.SplitFile(filePath, filePathParts, num); if (!isOk) { throw new Exception("SplitFile_TestMethod()"); } }
private void CreateNewStorageList() { DirectoryInfo di = new DirectoryInfo(config.StorageFolder); if (di.Exists) { FileManipulator fm = new FileManipulator(); foreach (var f in di.GetFiles()) { try { // get header from file STORED_FILE_HEADER sfh = fm.GetHeaderFromFile(f.FullName); // fill StorageItem from header string originname = f.Name.Substring(0, f.Name.IndexOf(".part") - 5); // if string not found file name ignored StorageItem si = new StorageItem(sfh.FileName, originname, sfh.Description, sfh.OriginSize, (uint)sfh.ChunksQty, (uint)sfh.ChunkNum, sfh.MD5Chunk, sfh.MD5Origin); // add Storage item into List Vault.StorageList.Add(si); } catch (Exception e) { Logger.Log.Error("Error in StoredList creation process."); Logger.Log.Error(e.Message); //throw; } } // Serialize StorageList XmlSerializer formatter = new XmlSerializer(typeof(List <StorageItem>)); using (FileStream fs = new FileStream(config.StorageFolder + "List.xml", FileMode.OpenOrCreate)) { formatter.Serialize(fs, Vault.StorageList); } } else { di.Create(); // just create empty StoredFolder } }
private void btnStartProcess_Click(object sender, EventArgs e) { if (isFileSelected && user.IsSet) { STORED_FILE_HEADER sh = new STORED_FILE_HEADER(); sh.Description = tbFileDescription.Text; Helper helper = new Helper(); FileManipulator fm = new FileManipulator(); // pack file Directory.CreateDirectory(config.TempFolder); var fileInputName = file.GetFileName(); byte[] buffer = File.ReadAllBytes(fileInputName); FileInfo fi = new FileInfo(fileInputName); sh.cb = (uint)Marshal.SizeOf(sh); // header size sh.OriginSize = (ulong)fi.Length; sh.MD5Origin = new Helper().GetFileMD5(fileInputName); var fileOutputName = config.TempFolder + "\\" + Path.GetFileName(file.GetFileName()); using (var file = File.Open(fileOutputName, FileMode.Create)) using (var stream = new DeflateStream(file, CompressionMode.Compress)) using (var writer = new BinaryWriter(stream)) { writer.Write(buffer); } // encrypt file byte[] buff = File.ReadAllBytes(fileOutputName); // var fileOutputNameEncrypted = config.TempFolder + "\\" + Path.GetFileName(file.GetFileName()) + @".enc"; // new AESEnDecryption().BinarySaveObjectWithAes(buff, fileOutputNameEncrypted, user.GetName(), user.GetPassword()); new AESEnDecryption().BinarySaveObjectWithAes(buff, fileOutputName, user.GetName(), user.GetPassword()); // split file // fm.SplitFile(fileOutputNameEncrypted, config.SendFolder, config.Chunks, sh); fm.SplitFile(fileOutputName, config.SendFolder, config.Chunks, sh); // @TODO Add SendList filling DirectoryInfo di = new DirectoryInfo(config.SendFolder); } }
public void AddHeaderToFile_TestMethod() { DataDepositer.Helper h = new DataDepositer.Helper(); DataDepositer.FileManipulator fm = new DataDepositer.FileManipulator(); String filePathFull = "d:\\test\\datadepositor\\join\\test.txt"; String MD5Origin = h.GetStringMD5("55555555555555555555555555555555"); String MD5Chunk = h.GetStringMD5("66666666666666666666666666666666"); STORED_FILE_HEADER sfh = h.FillHeader(filePathFull, " Description Описание", MD5Origin, MD5Chunk, 3, 1, 3028, 1010); //sfh.cb = ; bool isOk = fm.AddHeaderToFile(sfh, filePathFull); if (!isOk) { throw new Exception("AddHeaderToFile_TestMethod()"); } }
public void GetHeader_TestMethod() { Helper h = new DataDepositer.Helper(); FileManipulator fm = new DataDepositer.FileManipulator(); // String filePathFull = "d:\\test\\datadepositor\\join\\test.txt"; String filePathFull = "d:\\test\\datadepositor\\testHeader.txt"; String MD5Origin = h.GetStringMD5("55555555555555555555555555555555"); String MD5Chunk = h.GetStringMD5("66666666666666666666666666666666"); STORED_FILE_HEADER sfh = new STORED_FILE_HEADER(); sfh.cb = (uint)Marshal.SizeOf(sfh); // size of struct sfh.ChunkNum = 3; sfh.ChunkSize = 0x1234; sfh.ChunksQty = 5; sfh.Description = @"Проверка описания на русском языке"; sfh.FileName = Path.GetFileName(filePathFull); sfh.MD5Chunk = MD5Chunk; sfh.MD5Origin = MD5Origin; sfh.OriginSize = 0x5432; FileInfo fi = new FileInfo(filePathFull); string v = filePathFull + ".hdr"; //string headerFile = File.Delete(v); // delete before copy fi.CopyTo(v); fm.AddHeaderToFile(sfh, v); STORED_FILE_HEADER newSfh = fm.GetHeaderFromFile(v); Console.WriteLine("{0}\n {1}\n{2}\n{3}\n{4}\n", newSfh.FileName, newSfh.Description, newSfh.MD5Origin, newSfh.MD5Chunk, newSfh.OriginSize); }
public void RawSerialize_TestMethod() { DataDepositer.Helper h = new DataDepositer.Helper(); DataDepositer.FileManipulator fm = new DataDepositer.FileManipulator(); // String filePathFull = "d:\\test\\datadepositor\\join\\test.txt"; String filePathFull = "d:\\test\\datadepositor\\testHeader.txt"; String MD5Origin = h.GetStringMD5("55555555555555555555555555555555"); String MD5Chunk = h.GetStringMD5("66666666666666666666666666666666"); DISPLAY_DEVICE dd = new DISPLAY_DEVICE(); dd.cb = Marshal.SizeOf(dd); string str = "Cool Device"; dd.DeviceInstanceId = str; dd.DeviceName = MD5Origin; dd.StateFlags = 12345; byte[] test = h.RawSerialize(dd); File.WriteAllBytes(filePathFull, test); }