mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-13 12:14:17 +01:00
Some readonly and private cleanup.
This commit is contained in:
parent
20cb3fbb13
commit
e1d2b8e89f
5 changed files with 29 additions and 30 deletions
|
|
@ -18,7 +18,7 @@ namespace Penumbra.Game
|
|||
public UnloadPlayerResourcesPrototype UnloadPlayerResources { get; private set; }
|
||||
|
||||
// Object addresses
|
||||
private IntPtr _playerResourceManagerAddress;
|
||||
private readonly IntPtr _playerResourceManagerAddress;
|
||||
public IntPtr PlayerResourceManagerPtr => Marshal.ReadIntPtr( _playerResourceManagerAddress );
|
||||
|
||||
public GameUtils( DalamudPluginInterface pluginInterface )
|
||||
|
|
|
|||
|
|
@ -9,45 +9,44 @@ namespace Penumbra.Models
|
|||
{
|
||||
public class Deduplicator
|
||||
{
|
||||
private DirectoryInfo baseDir;
|
||||
private int baseDirLength;
|
||||
private ModMeta mod;
|
||||
private SHA256 hasher = null;
|
||||
private readonly DirectoryInfo _baseDir;
|
||||
private readonly int _baseDirLength;
|
||||
private readonly ModMeta _mod;
|
||||
private SHA256 _hasher = null;
|
||||
|
||||
private Dictionary<long, List<FileInfo>> filesBySize;
|
||||
private readonly Dictionary<long, List<FileInfo>> _filesBySize = new();
|
||||
|
||||
private ref SHA256 Sha()
|
||||
{
|
||||
if (hasher == null)
|
||||
hasher = SHA256.Create();
|
||||
return ref hasher;
|
||||
if (_hasher == null)
|
||||
_hasher = SHA256.Create();
|
||||
return ref _hasher;
|
||||
}
|
||||
|
||||
public Deduplicator(DirectoryInfo baseDir, ModMeta mod)
|
||||
{
|
||||
this.baseDir = baseDir;
|
||||
this.baseDirLength = baseDir.FullName.Length;
|
||||
this.mod = mod;
|
||||
filesBySize = new();
|
||||
_baseDir = baseDir;
|
||||
_baseDirLength = baseDir.FullName.Length;
|
||||
_mod = mod;
|
||||
|
||||
BuildDict();
|
||||
}
|
||||
|
||||
private void BuildDict()
|
||||
{
|
||||
foreach( var file in baseDir.EnumerateFiles( "*.*", SearchOption.AllDirectories ) )
|
||||
foreach( var file in _baseDir.EnumerateFiles( "*.*", SearchOption.AllDirectories ) )
|
||||
{
|
||||
var fileLength = file.Length;
|
||||
if (filesBySize.TryGetValue(fileLength, out var files))
|
||||
if (_filesBySize.TryGetValue(fileLength, out var files))
|
||||
files.Add(file);
|
||||
else
|
||||
filesBySize[fileLength] = new(){ file };
|
||||
_filesBySize[fileLength] = new(){ file };
|
||||
}
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
foreach (var pair in filesBySize)
|
||||
foreach (var pair in _filesBySize)
|
||||
{
|
||||
if (pair.Value.Count < 2)
|
||||
continue;
|
||||
|
|
@ -81,16 +80,16 @@ namespace Penumbra.Models
|
|||
}
|
||||
}
|
||||
}
|
||||
ClearEmptySubDirectories(baseDir);
|
||||
ClearEmptySubDirectories(_baseDir);
|
||||
}
|
||||
|
||||
private void ReplaceFile(FileInfo f1, FileInfo f2)
|
||||
{
|
||||
var relName1 = f1.FullName.Substring(baseDirLength).TrimStart('\\');
|
||||
var relName2 = f2.FullName.Substring(baseDirLength).TrimStart('\\');
|
||||
var relName1 = f1.FullName.Substring(_baseDirLength).TrimStart('\\');
|
||||
var relName2 = f2.FullName.Substring(_baseDirLength).TrimStart('\\');
|
||||
|
||||
var inOption = false;
|
||||
foreach (var group in mod.Groups.Select( g => g.Value.Options))
|
||||
foreach (var group in _mod.Groups.Select( g => g.Value.Options))
|
||||
{
|
||||
foreach (var option in group)
|
||||
{
|
||||
|
|
@ -106,7 +105,7 @@ namespace Penumbra.Models
|
|||
if (!inOption)
|
||||
{
|
||||
const string duplicates = "Duplicates";
|
||||
if (!mod.Groups.ContainsKey(duplicates))
|
||||
if (!_mod.Groups.ContainsKey(duplicates))
|
||||
{
|
||||
InstallerInfo info = new()
|
||||
{
|
||||
|
|
@ -122,10 +121,10 @@ namespace Penumbra.Models
|
|||
}
|
||||
}
|
||||
};
|
||||
mod.Groups.Add(duplicates, info);
|
||||
_mod.Groups.Add(duplicates, info);
|
||||
}
|
||||
mod.Groups[duplicates].Options[0].AddFile(relName1, relName2.Replace('\\', '/'));
|
||||
mod.Groups[duplicates].Options[0].AddFile(relName1, relName1.Replace('\\', '/'));
|
||||
_mod.Groups[duplicates].Options[0].AddFile(relName1, relName2.Replace('\\', '/'));
|
||||
_mod.Groups[duplicates].Options[0].AddFile(relName1, relName1.Replace('\\', '/'));
|
||||
}
|
||||
PluginLog.Information($"File {relName1} and {relName2} are identical. Deleting the second.");
|
||||
f2.Delete();
|
||||
|
|
|
|||
|
|
@ -125,6 +125,6 @@ namespace Penumbra.UI
|
|||
|
||||
private static readonly Vector2 ZeroVector = new(0, 0);
|
||||
|
||||
private static List<(Vector2, Vector2)> labelStack = new();
|
||||
private static readonly List<(Vector2, Vector2)> labelStack = new();
|
||||
}
|
||||
}
|
||||
|
|
@ -11,9 +11,9 @@ namespace Penumbra.UI
|
|||
private const string LabelTab = "Effective File List";
|
||||
private const float TextSizePadding = 5f;
|
||||
|
||||
private ModManager _mods;
|
||||
private (string, string)[] _fileList = null;
|
||||
private float _maxGamePath = 0f;
|
||||
private readonly ModManager _mods;
|
||||
private (string, string)[] _fileList = null;
|
||||
private float _maxGamePath = 0f;
|
||||
|
||||
public TabEffective(SettingsInterface ui)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ namespace Penumbra
|
|||
{
|
||||
public static class StringPathExtensions
|
||||
{
|
||||
private static char[] _invalid = Path.GetInvalidFileNameChars();
|
||||
private static readonly char[] _invalid = Path.GetInvalidFileNameChars();
|
||||
public static string ReplaceInvalidPathSymbols( this string s, string replacement = "_" )
|
||||
{
|
||||
return string.Join( replacement, s.Split( _invalid ) );
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue