public void CompressFile(string source, string destination) { var inFs = new FileStream(source, FileMode.Open, FileAccess.Read); var outFs = new FileStream(destination, FileMode.CreateNew, FileAccess.Write); Stream zStream = new LZipStream(outFs, CompressionMode.Compress); byte[] buffer = new byte[BUFFER_SIZE]; SetProgressBounds?.Invoke(this, new ProgressBoundsEventArgs { Minimum = 0, Maximum = inFs.Length }); while (inFs.Position + BUFFER_SIZE <= inFs.Length) { SetProgress?.Invoke(this, new ProgressEventArgs { Value = inFs.Position }); inFs.Read(buffer, 0, buffer.Length); zStream.Write(buffer, 0, buffer.Length); } buffer = new byte[inFs.Length - inFs.Position]; SetProgressBounds?.Invoke(this, new ProgressBoundsEventArgs { Minimum = 0, Maximum = inFs.Length }); inFs.Read(buffer, 0, buffer.Length); zStream.Write(buffer, 0, buffer.Length); inFs.Close(); zStream.Close(); outFs.Dispose(); }
public void Export() { SetMessage?.Invoke(this, new MessageEventArgs { Message = Localization.RetrievingRomSetFromDatabase }); using var ctx = Context.Create(Settings.Settings.Current.DatabasePath); RomSet romSet = ctx.RomSets.Find(_romSetId); if (romSet == null) { SetMessage?.Invoke(this, new MessageEventArgs { Message = Localization.CouldNotFindRomSetInDatabase }); WorkFinished?.Invoke(this, System.EventArgs.Empty); return; } SetMessage?.Invoke(this, new MessageEventArgs { Message = Localization.ExportingRoms }); _machines = ctx.Machines.Where(m => m.RomSet.Id == _romSetId).ToArray(); SetProgressBounds?.Invoke(this, new ProgressBoundsEventArgs { Minimum = 0, Maximum = _machines.Length }); _machinePosition = 0; CompressNextMachine(); }