Option to delete original textures from disk
This commit is contained in:
@@ -406,6 +406,30 @@ public sealed class CacheMonitor : DisposableMediatorSubscriberBase
|
|||||||
SubstWatcher.EnableRaisingEvents = true;
|
SubstWatcher.EnableRaisingEvents = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void DeleteSubstOriginals()
|
||||||
|
{
|
||||||
|
var cacheDir = _configService.Current.CacheFolder;
|
||||||
|
var substDir = _fileDbManager.SubstFolder;
|
||||||
|
var allSubstFiles = Directory.GetFiles(substDir, "*.*", SearchOption.TopDirectoryOnly)
|
||||||
|
.Where(f =>
|
||||||
|
{
|
||||||
|
var val = f.Split('\\')[^1];
|
||||||
|
return val.Length == 40 || (val.Split('.').FirstOrDefault()?.Length ?? 0) == 40
|
||||||
|
|| val.EndsWith(".tmp", StringComparison.OrdinalIgnoreCase);
|
||||||
|
});
|
||||||
|
|
||||||
|
foreach (var substFile in allSubstFiles)
|
||||||
|
{
|
||||||
|
var cacheFile = Path.Join(cacheDir, Path.GetFileName(substFile));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (File.Exists(cacheFile))
|
||||||
|
File.Delete(cacheFile);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void HandleChanges(Dictionary<string, WatcherChange> changes)
|
private void HandleChanges(Dictionary<string, WatcherChange> changes)
|
||||||
{
|
{
|
||||||
lock (_fileDbManager)
|
lock (_fileDbManager)
|
||||||
|
|||||||
@@ -12,4 +12,5 @@ public class PlayerPerformanceConfig : IMareConfiguration
|
|||||||
public int TrisAutoPauseThresholdThousands { get; set; } = 375;
|
public int TrisAutoPauseThresholdThousands { get; set; } = 375;
|
||||||
public bool IgnoreDirectPairs { get; set; } = true;
|
public bool IgnoreDirectPairs { get; set; } = true;
|
||||||
public TextureShrinkMode TextureShrinkMode { get; set; } = TextureShrinkMode.Default;
|
public TextureShrinkMode TextureShrinkMode { get; set; } = TextureShrinkMode.Default;
|
||||||
|
public bool TextureShrinkDeleteOriginal { get; set; } = false;
|
||||||
}
|
}
|
||||||
@@ -303,6 +303,19 @@ public class PlayerPerformanceService : DisposableMediatorSubscriberBase
|
|||||||
File.Move(tmpFilePath, newFilePath);
|
File.Move(tmpFilePath, newFilePath);
|
||||||
_fileCacheManager.CreateSubstEntry(newFilePath);
|
_fileCacheManager.CreateSubstEntry(newFilePath);
|
||||||
shrunken = true;
|
shrunken = true;
|
||||||
|
|
||||||
|
// Make sure its a cache file before trying to delete it !!
|
||||||
|
bool shouldDelete = fileEntry.IsCacheEntry && File.Exists(filePath);
|
||||||
|
|
||||||
|
if (_playerPerformanceConfigService.Current.TextureShrinkDeleteOriginal && shouldDelete)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.LogDebug("Deleting original texture: {filePath}", filePath);
|
||||||
|
File.Delete(filePath);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1245,15 +1245,20 @@ public class SettingsUi : WindowMediatorSubscriberBase
|
|||||||
_uiShared.BigText("Global Configuration");
|
_uiShared.BigText("Global Configuration");
|
||||||
|
|
||||||
bool alwaysShrinkTextures = _playerPerformanceConfigService.Current.TextureShrinkMode == TextureShrinkMode.Always;
|
bool alwaysShrinkTextures = _playerPerformanceConfigService.Current.TextureShrinkMode == TextureShrinkMode.Always;
|
||||||
if (ImGui.Checkbox("Shrink downloaded textures", ref alwaysShrinkTextures))
|
bool deleteOriginalTextures = _playerPerformanceConfigService.Current.TextureShrinkDeleteOriginal;
|
||||||
|
|
||||||
|
using (ImRaii.Disabled(deleteOriginalTextures))
|
||||||
{
|
{
|
||||||
if (alwaysShrinkTextures)
|
if (ImGui.Checkbox("Shrink downloaded textures", ref alwaysShrinkTextures))
|
||||||
_playerPerformanceConfigService.Current.TextureShrinkMode = TextureShrinkMode.Always;
|
{
|
||||||
else
|
if (alwaysShrinkTextures)
|
||||||
_playerPerformanceConfigService.Current.TextureShrinkMode = TextureShrinkMode.Never;
|
_playerPerformanceConfigService.Current.TextureShrinkMode = TextureShrinkMode.Always;
|
||||||
_playerPerformanceConfigService.Save();
|
else
|
||||||
recalculatePerformance = true;
|
_playerPerformanceConfigService.Current.TextureShrinkMode = TextureShrinkMode.Never;
|
||||||
_cacheMonitor.ClearSubstStorage();
|
_playerPerformanceConfigService.Save();
|
||||||
|
recalculatePerformance = true;
|
||||||
|
_cacheMonitor.ClearSubstStorage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_uiShared.DrawHelpText("Automatically shrinks texture resolution of synced players to reduce VRAM utilization." + UiSharedService.TooltipSeparator
|
_uiShared.DrawHelpText("Automatically shrinks texture resolution of synced players to reduce VRAM utilization." + UiSharedService.TooltipSeparator
|
||||||
+ "Texture Size Limit (DXT/BC5/BC7 Compressed): 2048x2048" + Environment.NewLine
|
+ "Texture Size Limit (DXT/BC5/BC7 Compressed): 2048x2048" + Environment.NewLine
|
||||||
@@ -1261,6 +1266,23 @@ public class SettingsUi : WindowMediatorSubscriberBase
|
|||||||
+ "Enable to reduce lag in large crowds." + Environment.NewLine
|
+ "Enable to reduce lag in large crowds." + Environment.NewLine
|
||||||
+ "Disable this for higher quality during GPose.");
|
+ "Disable this for higher quality during GPose.");
|
||||||
|
|
||||||
|
using (ImRaii.Disabled(!alwaysShrinkTextures || _cacheMonitor.FileCacheSize < 0))
|
||||||
|
{
|
||||||
|
using var indent = ImRaii.PushIndent();
|
||||||
|
if (ImGui.Checkbox("Delete original textures from disk", ref deleteOriginalTextures))
|
||||||
|
{
|
||||||
|
_playerPerformanceConfigService.Current.TextureShrinkDeleteOriginal = deleteOriginalTextures;
|
||||||
|
_playerPerformanceConfigService.Save();
|
||||||
|
_ = Task.Run(() =>
|
||||||
|
{
|
||||||
|
_cacheMonitor.DeleteSubstOriginals();
|
||||||
|
_cacheMonitor.RecalculateFileCacheSize(CancellationToken.None);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_uiShared.DrawHelpText("Deletes original, full-sized, textures from disk after downloading and shrinking." + UiSharedService.TooltipSeparator
|
||||||
|
+ "Caution!!! This will cause a re-download of all textures when the shrink option is disabled.");
|
||||||
|
}
|
||||||
|
|
||||||
var totalVramBytes = _pairManager.GetOnlineUserPairs().Where(p => p.IsVisible && p.LastAppliedApproximateVRAMBytes > 0).Sum(p => p.LastAppliedApproximateVRAMBytes);
|
var totalVramBytes = _pairManager.GetOnlineUserPairs().Where(p => p.IsVisible && p.LastAppliedApproximateVRAMBytes > 0).Sum(p => p.LastAppliedApproximateVRAMBytes);
|
||||||
|
|
||||||
ImGui.TextUnformatted("Current VRAM utilization by all nearby players:");
|
ImGui.TextUnformatted("Current VRAM utilization by all nearby players:");
|
||||||
|
|||||||
Reference in New Issue
Block a user