Fixed usage of var
This commit is contained in:
parent
a1053d7351
commit
9425aaa972
@ -11,7 +11,7 @@ namespace Ryujinx.Common.Utilities
|
|||||||
{
|
{
|
||||||
internal static TimeSpan Measure(Action action)
|
internal static TimeSpan Measure(Action action)
|
||||||
{
|
{
|
||||||
var sw = new Stopwatch();
|
Stopwatch sw = new Stopwatch();
|
||||||
sw.Start();
|
sw.Start();
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -59,7 +59,7 @@ namespace Ryujinx.Common.Utilities
|
|||||||
{
|
{
|
||||||
if (Path.GetExtension(filename).Equals(".XCI", StringComparison.InvariantCultureIgnoreCase))
|
if (Path.GetExtension(filename).Equals(".XCI", StringComparison.InvariantCultureIgnoreCase))
|
||||||
{
|
{
|
||||||
var trimmer = new XCIFileTrimmer(filename, log);
|
XCIFileTrimmer trimmer = new XCIFileTrimmer(filename, log);
|
||||||
return trimmer.CanBeTrimmed;
|
return trimmer.CanBeTrimmed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ namespace Ryujinx.Common.Utilities
|
|||||||
{
|
{
|
||||||
if (Path.GetExtension(filename).Equals(".XCI", StringComparison.InvariantCultureIgnoreCase))
|
if (Path.GetExtension(filename).Equals(".XCI", StringComparison.InvariantCultureIgnoreCase))
|
||||||
{
|
{
|
||||||
var trimmer = new XCIFileTrimmer(filename, log);
|
XCIFileTrimmer trimmer = new XCIFileTrimmer(filename, log);
|
||||||
return trimmer.CanBeUntrimmed;
|
return trimmer.CanBeUntrimmed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,10 +172,10 @@ namespace Ryujinx.Common.Utilities
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.Pos = this.TrimmedFileSizeB;
|
this.Pos = this.TrimmedFileSizeB;
|
||||||
var freeSpaceValid = true;
|
bool freeSpaceValid = true;
|
||||||
var readSizeB = this.FileSizeB - this.TrimmedFileSizeB;
|
long readSizeB = this.FileSizeB - this.TrimmedFileSizeB;
|
||||||
|
|
||||||
var time = Performance.Measure(() =>
|
TimeSpan time = Performance.Measure(() =>
|
||||||
{
|
{
|
||||||
freeSpaceValid = CheckPadding(readSizeB);
|
freeSpaceValid = CheckPadding(readSizeB);
|
||||||
});
|
});
|
||||||
@ -210,13 +210,13 @@ namespace Ryujinx.Common.Utilities
|
|||||||
|
|
||||||
private bool CheckPadding(long readSizeB)
|
private bool CheckPadding(long readSizeB)
|
||||||
{
|
{
|
||||||
var maxReads = readSizeB / XCIFileTrimmer.BufferSize;
|
long maxReads = readSizeB / XCIFileTrimmer.BufferSize;
|
||||||
long read = 0;
|
long read = 0;
|
||||||
var buffer = new byte[BufferSize];
|
byte[] buffer = new byte[BufferSize];
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
var bytes = _fileStream.Read(buffer, 0, XCIFileTrimmer.BufferSize);
|
int bytes = _fileStream.Read(buffer, 0, XCIFileTrimmer.BufferSize);
|
||||||
if (bytes == 0)
|
if (bytes == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -266,7 +266,7 @@ namespace Ryujinx.Common.Utilities
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var info = new FileInfo(this.Filename);
|
FileInfo info = new FileInfo(this.Filename);
|
||||||
if ((info.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
|
if ((info.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -287,7 +287,7 @@ namespace Ryujinx.Common.Utilities
|
|||||||
return OperationOutcome.FileSizeChanged;
|
return OperationOutcome.FileSizeChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
var outfileStream = new FileStream(_filename, FileMode.Open, FileAccess.Write, FileShare.Write);
|
FileStream outfileStream = new FileStream(_filename, FileMode.Open, FileAccess.Write, FileShare.Write);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -323,7 +323,7 @@ namespace Ryujinx.Common.Utilities
|
|||||||
{
|
{
|
||||||
Log?.Write(LogType.Info, "Untrimming...");
|
Log?.Write(LogType.Info, "Untrimming...");
|
||||||
|
|
||||||
var info = new FileInfo(this.Filename);
|
FileInfo info = new FileInfo(this.Filename);
|
||||||
if ((info.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
|
if ((info.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -344,12 +344,12 @@ namespace Ryujinx.Common.Utilities
|
|||||||
return OperationOutcome.FileSizeChanged;
|
return OperationOutcome.FileSizeChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
var outfileStream = new FileStream(this._filename, FileMode.Append, FileAccess.Write, FileShare.Write);
|
FileStream outfileStream = new FileStream(this._filename, FileMode.Append, FileAccess.Write, FileShare.Write);
|
||||||
var bytesToWriteB = this.UntrimmedFileSizeB - this.FileSizeB;
|
long bytesToWriteB = this.UntrimmedFileSizeB - this.FileSizeB;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var time = Performance.Measure(() =>
|
TimeSpan time = Performance.Measure(() =>
|
||||||
{
|
{
|
||||||
WritePadding(outfileStream, bytesToWriteB);
|
WritePadding(outfileStream, bytesToWriteB);
|
||||||
});
|
});
|
||||||
@ -376,18 +376,18 @@ namespace Ryujinx.Common.Utilities
|
|||||||
|
|
||||||
private void WritePadding(FileStream outfileStream, long bytesToWriteB)
|
private void WritePadding(FileStream outfileStream, long bytesToWriteB)
|
||||||
{
|
{
|
||||||
var bytesLeftToWriteB = bytesToWriteB;
|
long bytesLeftToWriteB = bytesToWriteB;
|
||||||
var writes = bytesLeftToWriteB / XCIFileTrimmer.BufferSize;
|
long writes = bytesLeftToWriteB / XCIFileTrimmer.BufferSize;
|
||||||
var write = 0;
|
int write = 0;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var buffer = new byte[BufferSize];
|
byte[] buffer = new byte[BufferSize];
|
||||||
Array.Fill<byte>(buffer, XCIFileTrimmer.PaddingByte);
|
Array.Fill<byte>(buffer, XCIFileTrimmer.PaddingByte);
|
||||||
|
|
||||||
while (bytesLeftToWriteB > 0)
|
while (bytesLeftToWriteB > 0)
|
||||||
{
|
{
|
||||||
var bytesToWrite = Math.Min(XCIFileTrimmer.BufferSize, bytesLeftToWriteB);
|
long bytesToWrite = Math.Min(XCIFileTrimmer.BufferSize, bytesLeftToWriteB);
|
||||||
outfileStream.Write(buffer, 0, (int)bytesToWrite);
|
outfileStream.Write(buffer, 0, (int)bytesToWrite);
|
||||||
bytesLeftToWriteB -= bytesToWrite;
|
bytesLeftToWriteB -= bytesToWrite;
|
||||||
Log?.Progress(write, writes, "Writing padding data...", false);
|
Log?.Progress(write, writes, "Writing padding data...", false);
|
||||||
@ -427,7 +427,7 @@ namespace Ryujinx.Common.Utilities
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Attempt without key area
|
// Attempt without key area
|
||||||
var success = CheckAndReadHeader(false);
|
bool success = CheckAndReadHeader(false);
|
||||||
|
|
||||||
if (!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
@ -468,7 +468,7 @@ namespace Ryujinx.Common.Utilities
|
|||||||
|
|
||||||
// Check header
|
// Check header
|
||||||
this.Pos = _offsetB + XCIFileTrimmer.HeaderFilePos;
|
this.Pos = _offsetB + XCIFileTrimmer.HeaderFilePos;
|
||||||
var head = System.Text.Encoding.ASCII.GetString(_binaryReader.ReadBytes(4));
|
string head = System.Text.Encoding.ASCII.GetString(_binaryReader.ReadBytes(4));
|
||||||
if (head != XCIFileTrimmer.HeaderMagicValue)
|
if (head != XCIFileTrimmer.HeaderMagicValue)
|
||||||
{
|
{
|
||||||
if (!assumeKeyArea)
|
if (!assumeKeyArea)
|
||||||
@ -485,7 +485,7 @@ namespace Ryujinx.Common.Utilities
|
|||||||
|
|
||||||
// Read Cart Size
|
// Read Cart Size
|
||||||
this.Pos = _offsetB + XCIFileTrimmer.CartSizeFilePos;
|
this.Pos = _offsetB + XCIFileTrimmer.CartSizeFilePos;
|
||||||
var cartSizeId = _binaryReader.ReadByte();
|
byte cartSizeId = _binaryReader.ReadByte();
|
||||||
if (!_cartSizesGB.TryGetValue(cartSizeId, out long cartSizeNGB))
|
if (!_cartSizesGB.TryGetValue(cartSizeId, out long cartSizeNGB))
|
||||||
{
|
{
|
||||||
Log?.Write(LogType.Error, $"The source file doesn't look like an XCI file as the Cartridge Size is incorrect (0x{cartSizeId:X2})");
|
Log?.Write(LogType.Error, $"The source file doesn't look like an XCI file as the Cartridge Size is incorrect (0x{cartSizeId:X2})");
|
||||||
@ -495,7 +495,7 @@ namespace Ryujinx.Common.Utilities
|
|||||||
|
|
||||||
// Read data size
|
// Read data size
|
||||||
this.Pos = _offsetB + XCIFileTrimmer.DataSizeFilePos;
|
this.Pos = _offsetB + XCIFileTrimmer.DataSizeFilePos;
|
||||||
var records = (long)BitConverter.ToUInt32(_binaryReader.ReadBytes(4), 0);
|
long records = (long)BitConverter.ToUInt32(_binaryReader.ReadBytes(4), 0);
|
||||||
this._dataSizeB = RecordsToByte(records);
|
this._dataSizeB = RecordsToByte(records);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user