Sweep VRChat cache function

This commit is contained in:
Natsumi
2021-05-23 01:41:06 +12:00
parent 7c0108cf54
commit 188d4a4972
3 changed files with 53 additions and 1 deletions

View File

@@ -238,7 +238,6 @@ namespace VRCX
Directory.Move(CacheSource, CacheDestinationLocation);
if (File.Exists(Path.Combine(VRChatCacheLocation, "Cache-WindowsPlayer", "__info")))
File.Delete(Path.Combine(VRChatCacheLocation, "Cache-WindowsPlayer", "__info"));
File.Move(Path.Combine(AssetBundleCacherTemp, "__info"), Path.Combine(VRChatCacheLocation, "Cache-WindowsPlayer", "__info"));
Directory.Delete(Path.Combine(VRChatCacheLocation, "AssetBundleCacher\\Cache", AssetId), true);
File.Delete(Path.Combine(VRChatCacheLocation, "AssetBundleCacher", AssetId));
}
@@ -269,6 +268,37 @@ namespace VRCX
}
}
public void SweepCache(string cacheDir)
{
var cachePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"Low\VRChat\VRChat\Cache-WindowsPlayer";
if (cacheDir != String.Empty && Directory.Exists(cacheDir))
cachePath = Path.Combine(cacheDir, @"Cache-WindowsPlayer");
if (!Directory.Exists(cachePath))
return;
var directories = new DirectoryInfo(cachePath);
DirectoryInfo[] cacheDirectories = directories.GetDirectories();
foreach (DirectoryInfo cacheDirectory in cacheDirectories)
{
var VersionDirectories = cacheDirectory.GetDirectories().OrderBy(d => Convert.ToInt32(d.Name, 16));
int i = 0;
foreach (DirectoryInfo VersionDirectory in VersionDirectories)
{
i++;
if (VersionDirectory.GetDirectories().Length + VersionDirectory.GetFiles().Length == 0)
{
VersionDirectory.Delete();
}
else if (i < VersionDirectories.Count())
{
if (!File.Exists(Path.Combine(VersionDirectory.FullName, "__lock")))
VersionDirectory.Delete(true);
}
}
if (cacheDirectory.GetDirectories().Length + cacheDirectory.GetFiles().Length == 0)
cacheDirectory.Delete();
}
}
public long GetCacheSize(string cacheDir)
{
var cachePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"Low\VRChat\VRChat\Cache-WindowsPlayer";

View File

@@ -7064,6 +7064,7 @@ speechSynthesis.getVoices();
$app.data.worldAutoCacheGPS = configRepository.getString('VRCX_worldAutoCacheGPS');
$app.data.worldAutoCacheInviteFilter = configRepository.getBool('VRCX_worldAutoCacheInviteFilter');
$app.data.worldAutoCacheGPSFilter = configRepository.getBool('VRCX_worldAutoCacheGPSFilter');
$app.data.autoSweepVRChatCache = configRepository.getBool('VRCX_autoSweepVRChatCache');
var saveOpenVROption = function () {
configRepository.setBool('openVR', this.openVR);
configRepository.setBool('openVRAlways', this.openVRAlways);
@@ -7081,6 +7082,7 @@ speechSynthesis.getVoices();
configRepository.setString('VRCX_worldAutoCacheGPS', this.worldAutoCacheGPS);
configRepository.setBool('VRCX_worldAutoCacheInviteFilter', this.worldAutoCacheInviteFilter);
configRepository.setBool('VRCX_worldAutoCacheGPSFilter', this.worldAutoCacheGPSFilter);
configRepository.setBool('VRCX_autoSweepVRChatCache', this.autoSweepVRChatCache);
this.updateVRConfigVars();
};
$app.data.TTSvoices = speechSynthesis.getVoices();
@@ -7108,6 +7110,7 @@ speechSynthesis.getVoices();
$app.watch.worldAutoCacheGPS = saveOpenVROption;
$app.watch.worldAutoCacheInviteFilter = saveOpenVROption;
$app.watch.worldAutoCacheGPSFilter = saveOpenVROption;
$app.watch.autoSweepVRChatCache = saveOpenVROption;
$app.watch.notificationTTS = saveNotificationTTS;
$app.data.isDarkMode = configRepository.getBool('isDarkMode');
$appDarkStyle.disabled = $app.data.isDarkMode === false;
@@ -11700,6 +11703,18 @@ speechSynthesis.getVoices();
this.getVRChatCacheSize();
};
$app.methods.sweepVRChatCache = async function () {
await this.readVRChatConfigFile();
var cacheDirectory = '';
if (this.VRChatConfigFile.cache_directory) {
cacheDirectory = this.VRChatConfigFile.cache_directory;
}
await AssetBundleCacher.SweepCache(cacheDirectory);
if (this.VRChatConfigDialog.visible) {
this.getVRChatCacheSize();
}
};
$app.data.VRChatUsedCacheSize = '';
$app.data.VRChatTotalCacheSize = '';
$app.data.VRChatCacheSizeLoading = false;

View File

@@ -869,6 +869,10 @@ html
div.options-container-item
el-button-group
el-button(size="small" icon="el-icon-download" @click="showDownloadDialog()") Download History
br
div.options-container-item
span.name(style="min-width:250px") Auto sweep cache when closing VRChat
el-switch(v-model="autoSweepVRChatCache")
div.options-container
span.header Application
div.options-container-item
@@ -1523,6 +1527,9 @@ html
span Clear Cache
el-button(type="default" @click="deleteAllVRChatCache" :disabled="isGameRunning" size="small" icon="el-icon-delete" circle style="margin-left:5px")
br
span Delete all old versions from cache
el-button(size="small" style="margin-left:5px" icon="el-icon-folder-delete" @click="sweepVRChatCache()") Sweep Cache
br
div(style="display:inline-block;margin-top:10px" v-for="(item, value) in VRChatConfigList" :key="value")
span(v-text="item.name" style="word-break:keep-all")
|: