Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderSade committed Oct 28, 2020
1 parent f83306f commit 7e9ac03
Show file tree
Hide file tree
Showing 101 changed files with 1,082 additions and 1,231 deletions.
21 changes: 18 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ root=true

# top-most EditorConfig file

[*.cs]
# RCS1123: Add parentheses when necessary
dotnet_diagnostic.RCS1123.severity = none
# RCS1036: Remove redundant empty line
dotnet_diagnostic.RCS1036.severity = none
# RCS1063: Avoid usage of do statement to create an infinite loop
dotnet_diagnostic.RCS1063.severity = none
# RCS1197: Optimize StringBuilder.Append/AppendLine call
dotnet_diagnostic.RCS1197.severity = none
# IDE0066: Use 'switch' expression
dotnet_diagnostic.IDE0066.severity = none

# Use tabs for indentation.
[*]
indent_style=tab
Expand Down Expand Up @@ -56,6 +68,7 @@ resharper_place_simple_embedded_statement_on_same_line=false
resharper_space_within_single_line_array_initializer_braces=true
resharper_use_heuristics_for_body_style=true
resharper_wrap_object_and_collection_initializer_style=chop_always
resharper_xml_wrap_lines=false

# ReSharper inspection severities
resharper_arrange_constructor_or_destructor_body_highlighting=none
Expand Down Expand Up @@ -91,12 +104,14 @@ indent_size=4
insert_final_newline=true
charset=utf-8-bom



# Xml project files
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj,xml}]
indent_size=2

max_line_length=off
indent_style=tab
charset=utf-8
trim_trailing_whitespace=true
indent_size=2

# Xml config files
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct,cscfg,csdef}]
Expand Down
12 changes: 6 additions & 6 deletions DirLister.Core/Application/FileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ private bool FindNextFile(string path, out List<FileEntry> files)
{
var fullPath = string.Concat(path, "\\", findData.cFileName);
// Check if this is a directory and not a symbolic link since symbolic links could lead to repeated files and folders as well as infinite loops.
if (findData.dwFileAttributes.HasFlag(FileAttributes.Directory) && !findData.dwFileAttributes.HasFlag(FileAttributes.ReparsePoint))
if ((findData.dwFileAttributes & FileAttributes.Directory) != 0 && (findData.dwFileAttributes & FileAttributes.ReparsePoint) == 0)
{
if (FindNextFile(fullPath, out var subDirectoryFileList))
{
fileList.AddRange(subDirectoryFileList);
}
}
else if (!findData.dwFileAttributes.HasFlag(FileAttributes.Directory))
else if ((findData.dwFileAttributes & FileAttributes.Directory) == 0)
{
var fileEntry = GetFileEntry(fullPath, findData);
if (fileEntry != null)
Expand Down Expand Up @@ -177,14 +177,14 @@ private List<FileEntry> ParallelFindNextFile(string path)
{
var fullPath = path + findData.cFileName;
// Check if this is a directory and not a symbolic link since symbolic links could lead to repeated files and folders as well as infinite loops.
if (findData.dwFileAttributes.HasFlag(FileAttributes.Directory) && !findData.dwFileAttributes.HasFlag(FileAttributes.ReparsePoint))
if ((findData.dwFileAttributes & FileAttributes.Directory) != 0 && (findData.dwFileAttributes & FileAttributes.ReparsePoint) == 0)
{
if (_configuration.IncludeSubfolders)
{
directoryList.Add(fullPath);
}
}
else if (!findData.dwFileAttributes.HasFlag(FileAttributes.Directory))
else if ((findData.dwFileAttributes & FileAttributes.Directory) == 0)
{
var fileEntry = GetFileEntry(fullPath, findData);
if (fileEntry != null)
Expand Down Expand Up @@ -235,15 +235,15 @@ private List<FileEntry> ParallelFindNextFile(string path)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private FileEntry GetFileEntry(string fullPath, WIN32_FIND_DATAW findData)
{
if (!_configuration.IncludeHidden && findData.dwFileAttributes.HasFlag(FileAttributes.System | FileAttributes.Hidden))
if (!_configuration.IncludeHidden && (findData.dwFileAttributes & (FileAttributes.System | FileAttributes.Hidden)) == (FileAttributes.System | FileAttributes.Hidden))
{
return null;
}

var fileEntry = new FileEntry
{
Fullname = fullPath,
Size = (long)findData.nFileSizeHigh << 0x20 | findData.nFileSizeLow
Size = ((long)findData.nFileSizeHigh << 0x20) | findData.nFileSizeLow
};

if (_configuration.IncludeFileDates)
Expand Down
2 changes: 1 addition & 1 deletion DirLister.Core/Application/Media/ImageInfoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ internal static List<string> GetAdditionalExtensions()
}

var baseKey = Registry.ClassesRoot.OpenSubKey(baseKeyPath, false);
var categoryKey = baseKey?.OpenSubKey("{7ED96837-96F0-4812-B211-F13C24117ED3}" + "\\instance", false);
var categoryKey = baseKey?.OpenSubKey("{7ED96837-96F0-4812-B211-F13C24117ED3}\\instance", false);
if (categoryKey != null)
{
// Read the guids of the registered decoders
Expand Down
2 changes: 1 addition & 1 deletion DirLister.Core/Application/OutputFileWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ internal void OpenFileOrFolder()
if (_outputFiles.Count == 1)
{
_configuration.Log(TraceLevel.Info, "Opening the output file with the default viewer");
Process.Start(_outputFiles.First());
Process.Start(_outputFiles[0]);
return;
}

Expand Down
5 changes: 2 additions & 3 deletions DirLister.Core/Application/Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

namespace Sander.DirLister.Core.Application
{
/// <summary>
/// </summary>

internal sealed class Runner
{
private readonly Configuration _configuration;
Expand Down Expand Up @@ -147,7 +146,7 @@ private void ValidateInputFolders(ref bool isValid)
{
var mappedFolder = Utils.GetUncPath(inputFolder);

if (string.Compare(mappedFolder, inputFolder, StringComparison.Ordinal) != 0)
if (!string.Equals(mappedFolder, inputFolder, StringComparison.Ordinal))
{
_configuration.Log(TraceLevel.Warning, $"Using \"{inputFolder}\" as UNC path \"{mappedFolder}\"");
}
Expand Down
2 changes: 0 additions & 2 deletions DirLister.Core/Application/Writers/CsvWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ private static string Quote<T>(T value, string delimiter = ",")

return valueString;
}


}
}
}
4 changes: 2 additions & 2 deletions DirLister.Core/Application/Writers/HtmlWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ string GetMediaInfo<T>(string name, T value)
{
return value == null || value.Equals(default(T))
? string.Empty
: FormattableString.Invariant($" {name}: {value.ToString()},");
: FormattableString.Invariant($" {name}: {value},");
}

if (!_needsFileInfo)
Expand Down Expand Up @@ -204,7 +204,7 @@ private void BuildHtmlHeader()
if (string.IsNullOrWhiteSpace(Configuration.CssContent))
{
var assembly = Assembly.GetExecutingAssembly();
var resourceName = "Sander.DirLister.Core.Application.Writers.Default.css";
const string resourceName = "Sander.DirLister.Core.Application.Writers.Default.css";
using (var stream = assembly.GetManifestResourceStream(resourceName))
{
Debug.Assert(stream != null, nameof(stream) + " != null");
Expand Down
4 changes: 2 additions & 2 deletions DirLister.Core/Application/Writers/MarkdownWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private void AppendFolder(IGrouping<string, FileEntry> group)
_sb.Append($"### {WebUtility.HtmlEncode(group.Key)} `files: {group.Count()}");
if (Configuration.IncludeSize)
{
_sb.Append($"({Utils.ReadableSize(@group.Sum(x => x.Size))})");
_sb.Append($"({Utils.ReadableSize(group.Sum(x => x.Size))})");
}

_sb.AppendLine("`");
Expand Down Expand Up @@ -100,7 +100,7 @@ private string GetMediaInfo<T>(string name, T value)
{
return value == null || value.Equals(default(T))
? string.Empty
: FormattableString.Invariant($" {name}: {value.ToString()},");
: FormattableString.Invariant($" {name}: {value},");
}


Expand Down
2 changes: 1 addition & 1 deletion DirLister.Core/Application/Writers/TxtWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private string GetMediaInfo<T>(string name, T value)
{
return value == null || value.Equals(default(T))
? string.Empty
: FormattableString.Invariant($" {name}: {value.ToString()},");
: FormattableString.Invariant($" {name}: {value},");
}


Expand Down
6 changes: 3 additions & 3 deletions DirLister.Core/DTO/FileEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ public sealed class FileEntry
/// <summary>
/// File folder
/// </summary>
public string Folder => _folder ?? (_folder = Utils.GetPath(Fullname));
public string Folder => _folder ??= Utils.GetPath(Fullname);

/// <summary>
/// File name including extension
/// </summary>
public string Filename => _filename ?? (_filename = Utils.GetFileName(Fullname));
public string Filename => _filename ??= Utils.GetFileName(Fullname);

/// <summary>
/// File extension without the period (.). Does not handle multi-dot extensions.
/// </summary>
public string Extension => _extension ?? (_extension = Utils.GetExtension(Fullname));
public string Extension => _extension ??= Utils.GetExtension(Fullname);

/// <summary>
/// File size in bytes
Expand Down
4 changes: 2 additions & 2 deletions DirLister.Core/DirLister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static bool List(Configuration configuration)
/// <param name="configuration"></param>
public static async Task<bool> ListAsync(Configuration configuration)
{
return await Task.Run(() => List(configuration));
return await Task.Run(() => List(configuration)).ConfigureAwait(false);
}


Expand Down Expand Up @@ -56,7 +56,7 @@ public static List<FileEntry> Run(Configuration configuration)
/// <returns></returns>
public static async Task<List<FileEntry>> RunAsync(Configuration configuration)
{
return await Task.Run(() => Run(configuration));
return await Task.Run(() => Run(configuration)).ConfigureAwait(false);
}
}
}
14 changes: 7 additions & 7 deletions DirLister.Core/TagLib/Aac/AudioHeader.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using System;

namespace Sander.DirLister.Core.TagLib.Aac
{
/// <summary>
/// This structure implements <see cref="IAudioCodec" /> and provides
/// information about an ADTS AAC audio stream.
/// </summary>
public class AudioHeader : IAudioCodec
public sealed class AudioHeader : IAudioCodec
{
/// <summary>
/// An empty and unset header.
Expand All @@ -17,7 +17,7 @@ public class AudioHeader : IAudioCodec
/// <summary>
/// Contains a sample rate table for ADTS AAC audio.
/// </summary>
private static readonly int[] sample_rates = new int[13] { 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350 };
private static readonly int[] sample_rates = { 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350 };

/// <summary>
/// Contains a channel table for ADTS AAC audio.
Expand Down Expand Up @@ -199,7 +199,7 @@ public static bool Find(out AudioHeader header,
{
if (file == null)
{
throw new ArgumentNullException("file");
throw new ArgumentNullException(nameof(file));
}

var end = position + length;
Expand Down Expand Up @@ -234,7 +234,7 @@ public static bool Find(out AudioHeader header,
var bits = new BitStream(buffer.Mid(i, 7)
.Data);

// 12 bits sync header
// 12 bits sync header
bits.ReadInt32(12);

// 1 bit mpeg 2/4
Expand All @@ -243,13 +243,13 @@ public static bool Find(out AudioHeader header,
// 2 bits layer
bits.ReadInt32(2);

// 1 bit protection absent
// 1 bit protection absent
bits.ReadInt32(1);

// 2 bits profile object type
bits.ReadInt32(2);

// 4 bits sampling frequency index
// 4 bits sampling frequency index
var samplerateindex = bits.ReadInt32(4);
if (samplerateindex >= sample_rates.Length)
{
Expand Down
2 changes: 1 addition & 1 deletion DirLister.Core/TagLib/Aiff/StreamHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public StreamHeader(ByteVector data, long streamLength)
{
if (data == null)
{
throw new ArgumentNullException("data");
throw new ArgumentNullException(nameof(data));
}

if (!data.StartsWith(FileIdentifier))
Expand Down
34 changes: 12 additions & 22 deletions DirLister.Core/TagLib/Ape/Footer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ namespace Sander.DirLister.Core.TagLib.Ape
public enum FooterFlags : uint
{
/// <summary>
/// The tag lacks a footer object.
/// The footer is actually a header.
/// </summary>
FooterAbsent = 0x40000000,
IsHeader = 0x20000000,

/// <summary>
/// The footer is actually a header.
/// The tag lacks a footer object.
/// </summary>
IsHeader = 0x20000000,
FooterAbsent = 0x40000000,

/// <summary>
/// The tag contains a header.
Expand All @@ -35,12 +35,6 @@ public struct Footer : IEquatable<Footer>
/// </summary>
private readonly uint version;

/// <summary>
/// Contains the tag size including the footer but excluding
/// the header.
/// </summary>
private uint tag_size;

/// <summary>
/// Specifies the size of an APEv2 footer.
/// </summary>
Expand Down Expand Up @@ -82,7 +76,7 @@ public Footer(ByteVector data)
{
if (data == null)
{
throw new ArgumentNullException("data");
throw new ArgumentNullException(nameof(data));
}

if (data.Count < Size)
Expand All @@ -100,7 +94,7 @@ public Footer(ByteVector data)
version = data.Mid(8, 4)
.ToUInt(false);

tag_size = data.Mid(12, 4)
TagSize = data.Mid(12, 4)
.ToUInt(false);

ItemCount = data.Mid(16, 4)
Expand Down Expand Up @@ -150,11 +144,7 @@ public Footer(ByteVector data)
/// A <see cref="uint" /> value containing the size of the
/// tag represented by the current instance.
/// </value>
public uint TagSize
{
get => tag_size;
set => tag_size = value;
}
public uint TagSize { get; set; }

/// <summary>
/// Gets the complete size of the tag represented by the
Expand All @@ -166,8 +156,8 @@ public uint TagSize
/// </value>
public uint CompleteTagSize => TagSize + ((Flags &
FooterFlags.HeaderPresent) != 0
? Size
: 0);
? Size
: 0);


/// <summary>
Expand Down Expand Up @@ -222,7 +212,7 @@ private ByteVector Render(bool isHeader)
ByteVector.FromUInt(2000, false),

// add the tag size
ByteVector.FromUInt(tag_size, false),
ByteVector.FromUInt(TagSize, false),

// add the item count
ByteVector.FromUInt(ItemCount, false)
Expand Down Expand Up @@ -266,7 +256,7 @@ public override int GetHashCode()
{
unchecked
{
return (int)((uint)Flags ^ tag_size ^
return (int)((uint)Flags ^ TagSize ^
ItemCount ^ version);
}
}
Expand Down Expand Up @@ -312,7 +302,7 @@ public override bool Equals(object other)
public bool Equals(Footer other)
{
return Flags == other.Flags &&
tag_size == other.tag_size &&
TagSize == other.TagSize &&
ItemCount == other.ItemCount &&
version == other.version;
}
Expand Down
Loading

0 comments on commit 7e9ac03

Please sign in to comment.