Skip to content

Commit

Permalink
use new collection initialization operator
Browse files Browse the repository at this point in the history
  • Loading branch information
13xforever committed Jun 8, 2024
1 parent 281a664 commit ec09106
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion IrdLibraryClient/Compression/CompressionMessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class CompressionMessageHandler : DelegatingHandler
{
public ICollection<ICompressor> Compressors { get; }
public static readonly string PostCompressionFlag = "X-Set-Content-Encoding";
public static readonly string[] DefaultContentEncodings = { "gzip", "deflate" };
public static readonly string[] DefaultContentEncodings = ["gzip", "deflate"];
public static readonly string DefaultAcceptEncodings = "gzip, deflate";

private bool isServer;
Expand Down
4 changes: 2 additions & 2 deletions IrdLibraryClient/IrdClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ protected virtual string GetDownloadLink(string irdFilename)
catch (Exception e)
{
Log.Warn(e, "Failed to make API call to IRD Library");
return new();
return [];
}
}
catch (Exception e)
{
Log.Error(e);
return new();
return [];
}
}

Expand Down
2 changes: 1 addition & 1 deletion IrdLibraryClient/IrdFormat/Ird.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Ird
public byte RegionCount;
public List<byte[]> RegionMd5Checksums = null!; // 16 each
public int FileCount;
public List<IrdFile> Files = new();
public List<IrdFile> Files = [];
public int Unknown; // always 0?
public byte[]? Pic; // 115, v9 only?
public byte[] Data1 = null!; // 16
Expand Down
8 changes: 4 additions & 4 deletions Ps3DiscDumper/Dumper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public partial class Dumper: IDisposable
private byte[] discSfbData;
private static readonly Dictionary<string, ImmutableArray<byte>> Detectors = new()
{
[@"\PS3_GAME\LICDIR\LIC.DAT"] = "PS3LICDA"u8.ToImmutableArray(),
[@"\PS3_GAME\USRDIR\EBOOT.BIN"] = "SCE"u8.ToArray().Concat(new byte[] { 0, 0, 0, 0, 2 }).ToImmutableArray(),
[@"\PS3_GAME\LICDIR\LIC.DAT"] = [.."PS3LICDA"u8],
[@"\PS3_GAME\USRDIR\EBOOT.BIN"] = [.."SCE"u8, 0, 0, 0, 0, 2],
};
private byte[] detectionSector;
private ImmutableArray<byte> detectionBytesExpected;
Expand Down Expand Up @@ -112,7 +112,7 @@ public long CurrentSector
get
{
var tmp = Decrypter?.SectorPosition;
if (tmp == null)
if (tmp is null)
return currentSector;
return currentSector = tmp.Value;
}
Expand Down Expand Up @@ -246,7 +246,7 @@ private List<string> EnumeratePhysicalDevicesMacOs()
private string CheckDiscSfb(byte[] discSfbData)
{
var sfb = SfbReader.Parse(discSfbData);
var flags = new HashSet<char>(sfb.KeyEntries.FirstOrDefault(e => e.Key == "HYBRID_FLAG")?.Value?.ToCharArray() ?? Array.Empty<char>());
var flags = new HashSet<char>(sfb.KeyEntries.FirstOrDefault(e => e.Key == "HYBRID_FLAG")?.Value?.ToCharArray() ?? []);
Log.Debug($"Disc flags: {string.Concat(flags)}");
if (!flags.Contains('g'))
Log.Warn("Disc is not a game disc");
Expand Down
2 changes: 1 addition & 1 deletion Ps3DiscDumper/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Settings() { }
(false, false) => BdmvFolders.Concat(Ps3UpdateFolder).ToArray(),
(false, true) => BdmvFolders,
(true, false) => Ps3UpdateFolder,
_ => Array.Empty<string>(),
_ => [],
};

private static StringComparison Comparison => OperatingSystem.IsWindows() ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
Expand Down
2 changes: 1 addition & 1 deletion Ps3DiscDumper/Sfb/Sfb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Sfb
public short VersionMajor;
public short VersionMinor;
public byte[] Unknown1; // 0x18
public readonly List<SfbKeyEntry> KeyEntries = new();
public readonly List<SfbKeyEntry> KeyEntries = [];
}

public class SfbKeyEntry
Expand Down
4 changes: 2 additions & 2 deletions Ps3DiscDumper/Utils/HexExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public static byte[] ToByteArray(this string hexString)
return null;

if (hexString.Length == 0)
return new byte[0];
return [];

if (hexString.Length % 2 != 0)
throw new FormatException("Not a valid hex string");

var result = new byte[hexString.Length / 2];
for (int i = 0; i < hexString.Length; i += 2)
for (var i = 0; i < hexString.Length; i += 2)
result[i / 2] = byte.Parse(hexString.Substring(i, 2), NumberStyles.HexNumber);
return result;
}
Expand Down
12 changes: 7 additions & 5 deletions Ps3DiscDumper/Utils/PatternFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ namespace Ps3DiscDumper.Utils;

public static class PatternFormatter
{
private static readonly char[] InvalidChars = Path.GetInvalidFileNameChars()
.Concat(Path.GetInvalidPathChars())
.Concat(new[] { ':', '/', '\\', '?', '*', '<', '>', '|' })
.Distinct()
.ToArray();
private static readonly char[] InvalidChars = [
..((char[])[
..Path.GetInvalidFileNameChars(),
..Path.GetInvalidPathChars(),
':', '/', '\\', '?', '*', '<', '>', '|'
]).Distinct()
];

public static string Format(string pattern, NameValueCollection items)
{
Expand Down
4 changes: 2 additions & 2 deletions UI.Avalonia/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ namespace UI.Avalonia;
public partial class App : Application
{
private static readonly WindowTransparencyLevel[] DesiredTransparencyHints =
{
[
WindowTransparencyLevel.Mica,
WindowTransparencyLevel.AcrylicBlur,
WindowTransparencyLevel.None,
};
];

private readonly Lazy<bool> isMicaCapable = new(() =>
Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: Window w }
Expand Down

0 comments on commit ec09106

Please sign in to comment.