/// <summary> /// save compressed files thrue multiple threads /// </summary> /// <param name="pathMessenger"></param> /// <returns>success of operation</returns> private bool compress(PathMessenger pathMessenger) { //start reading the file using (FileLoader fl = new FileLoader(pathMessenger.inputPath)) { List <byte> loadedFilePart; fl.MaxListSize = HardwareExplorer.GetSizeOfByteList(); fl.errorMessage = ErrorMessage; Divider divider = new Divider(pathMessenger, MaxSizeOfSavedFile); while (fl.canRead == 1) { bool successfulLoad = fl.LoadNextPatr(); if (successfulLoad) { //load part of the file loadedFilePart = fl.LoadedFilePart; try { //Divide & compressed & Save file divider.Save(loadedFilePart); } catch (Exception ex) { ErrorMessage?.Invoke(this, $"Error during compress file save. {pathMessenger.getOutputFilePath(fl.readCount)}"); return(false); } Debug.WriteLine($"Readed part: {fl.readCount}"); //TODO } else { ErrorMessage?.Invoke(this, $"Error during file read. Part {fl.readCount}"); return(false); } } } System.GC.Collect(); return(true); }
/// <summary> /// save and compres files in single thread /// </summary> /// <param name="pathMessenger">object with stored paths</param> /// <returns>success of operation</returns> private bool compressSingleThread(PathMessenger pathMessenger) { //start reading the file using (FileLoader fl = new FileLoader(pathMessenger.inputPath)) { List <byte> loadedFilePart; fl.MaxListSize = HardwareExplorer.GetSizeOfByteList(); fl.errorMessage = ErrorMessage; while (fl.canRead == 1) { bool successfulLoad = fl.LoadNextPatr(); if (successfulLoad) { //load part of the file loadedFilePart = fl.LoadedFilePart; try { //Save compress file CompressWorker.simpleCompress(loadedFilePart.ToArray(), pathMessenger.getOutputFilePath(fl.readCount)); } catch (Exception ex) { ErrorMessage?.Invoke(this, $"Error during compress file save. {pathMessenger.getOutputFilePath(fl.readCount)}"); return(false); } Debug.WriteLine($"Readed part: {fl.readCount}"); //TODO } else { ErrorMessage?.Invoke(this, $"Error during file read. Part {fl.readCount}"); return(false); } } } return(true); }