Files
UVtools/UVtools.Core/Extensions/FileStreamExtensions.cs
T
Tiago Conceição 95020ce2f1 v2.19.0
- **File formats:**
   - Add and remove some image types that can be open
   - (Add) `CanProcess` method to know if a file can be read under a format and to allow diferent formats with same extension
   - (Fix) `LiftHeightTotal` and `RetractHeight` was rounding to no decimals and returning wrong values
   - (Improvement) Round all float setters on `Layer` class
   - (Improvement) Decode/encode RAM usage and performance by processing in batch groups
- **Pixel Dimming:** (#262)
   - (Add) Option "Lightening pixels" to add brightness/lightening instead of dimming/subtract pixels
   - (Fix) "Dim walls only" would reset body brightness by increase pixel brightness two times it value
- **Pixel Arithmetic:**
   - (Change) Transpose "Pixel Dimming" to "Pixel Arithmetic"
   - (Improvement) New options and manipulations
- **(Fix) Exposure time finder:**
  - Generate top staircase based on selected measure (px or mm)
  - Zebra bars when used in mm measures, it was using X density instead Y to calculate the thickness
  - Move 'Unit of measure' to 'Object configuration'
  - Custom text with wrong Y position when using out of portion resolutions/LCDs
- **CTBv4:**
  - (Fix) More Unknown fields discovered and implemented
  - (Fix) Reserved table is 384 bytes instead of 420
  - (Fix) When full encoding it was forcing to change to version 3. This also affected convertions. (#263)
  - (Fix) `BottomRetractHeight2` was being set to `BottomRetractSpeed2`
  - (Fix) `RetractHeight2` was being set to `RetracSpeed2`
  - (Fix) The PrintParametersV4 table address
  - (Fix) Generates invalid files to open with Chitubox and printers (#263)
  - (Fix) Better progress report
- **(Add) PrusaSlicer printer notes variables:**
  - BottomLiftHeight2
  - BottomLiftSpeed2
  - LiftHeight2
  - LiftSpeed2
  - BottomRetractSpeed
  - BottomRetractSpeed2
  - BottomRetractHeight2
  - BottomRetractSpeed2
  - RetractHeight2
  - RetractSpeed2
- **UI:**
  - (Add) File - Open current file folder (Ctrl+Shift+L): Locate and open the folder that contain the current loaded file
  - (Improvement) Hide some virtual extensions from file open dialog filters
  - (Improvement) UI: Refresh active thumbnail when changed
  - (Change) Icon for File - Open and Open in a new file
  - (Change) Rename File - Extract to: Extract file contents
- (Upgrade) AvaloniaUI from 0.10.6 to 0.10.7
- (Fix) PW0, PWM, PWMX, PWMO, PWMS: Unable to decode some files with AntiAliasing (#143)
2021-08-17 20:17:08 +01:00

112 lines
3.9 KiB
C#

/*
* GNU AFFERO GENERAL PUBLIC LICENSE
* Version 3, 19 November 2007
* Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
using System;
using System.IO;
namespace UVtools.Core.Extensions
{
public static class FileStreamExtensions
{
public static uint ReadBytes(this FileStream fs, byte[] bytes, int offset = 0)
{
return (uint)fs.Read(bytes, offset, bytes.Length);
}
public static byte[] ReadBytes(this FileStream fs, int length, int offset = 0)
{
var buffer = new byte[length];
fs.Read(buffer, offset, length);
return buffer;
}
public static byte[] ReadBytes(this FileStream fs, uint length, int offset = 0)
=> fs.ReadBytes((int)length, offset);
public static uint ReadUShortLittleEndian(this FileStream fs, int offset = 0)
{
return BitExtensions.ToUShortLittleEndian(fs.ReadBytes(2, offset));
}
public static uint ReadUShortBigEndian(this FileStream fs, int offset = 0)
{
return BitExtensions.ToUShortBigEndian(fs.ReadBytes(2, offset));
}
public static uint ReadUIntLittleEndian(this FileStream fs, int offset = 0)
{
return BitExtensions.ToUIntLittleEndian(fs.ReadBytes(4, offset));
}
public static uint ReadUIntBigEndian(this FileStream fs, int offset = 0)
{
return BitExtensions.ToUIntBigEndian(fs.ReadBytes(4, offset));
}
public static void WriteUShortLittleEndian(this FileStream fs, ushort value, int offset = 0)
{
fs.WriteBytes(BitExtensions.ToBytesLittleEndian(value), offset);
}
public static void WriteUShortBigEndian(this FileStream fs, ushort value, int offset = 0)
{
fs.WriteBytes(BitExtensions.ToBytesBigEndian(value), offset);
}
public static void WriteUIntLittleEndian(this FileStream fs, uint value, int offset = 0)
{
fs.WriteBytes(BitExtensions.ToBytesLittleEndian(value), offset);
}
public static void WriteUIntBigEndian(this FileStream fs, uint value, int offset = 0)
{
fs.WriteBytes(BitExtensions.ToBytesBigEndian(value), offset);
}
public static uint WriteStream(this FileStream fs, MemoryStream stream, int offset = 0)
{
return fs.WriteBytes(stream.ToArray(), offset);
}
public static uint WriteBytes(this FileStream fs, byte[] bytes, int offset = 0)
{
fs.Write(bytes, offset, bytes.Length);
return (uint)bytes.Length;
}
public static uint WriteBytes(this Stream stream, byte[] bytes, int offset = 0)
{
stream.Write(bytes, offset, bytes.Length);
return (uint)bytes.Length;
}
public static uint WriteSerialize(this FileStream fs, object data, int offset = 0)
{
return Helpers.SerializeWriteFileStream(fs, data, offset);
}
/// <summary>
/// Seek to a position, do work and rewind to initial position
/// </summary>
/// <param name="fs"></param>
/// <param name="action"></param>
/// <param name="offset"></param>
/// <param name="seekOrigin"></param>
public static void SeekDoWorkAndRewind(this FileStream fs, long offset, Action action)
=> fs.SeekDoWorkAndRewind(offset, SeekOrigin.Begin, action);
public static void SeekDoWorkAndRewind(this FileStream fs, long offset, SeekOrigin seekOrigin, Action action)
{
var currentPos = fs.Position;
fs.Seek(offset, seekOrigin); // Go to
action.Invoke(); // Do work
fs.Seek(currentPos, SeekOrigin.Begin); // Rewind
}
}
}