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