AssetBundleCacher cleanup

This commit is contained in:
Natsumi
2021-05-24 18:02:23 +12:00
parent 17b8b1b29e
commit b65131a207
2 changed files with 45 additions and 42 deletions
+44 -41
View File
@@ -28,7 +28,9 @@ namespace VRCX
public static string AssetBundleCacherTemp; public static string AssetBundleCacherTemp;
public static string VRChatCacheLocation; public static string VRChatCacheLocation;
public static string CacheDestinationLocation; public static string CacheDestinationLocation;
public static string AssetBundleCacherLocation;
public static string AssetBundleCacherArgs; public static string AssetBundleCacherArgs;
public static string DownloadTempLocation;
public static int DownloadProgress; public static int DownloadProgress;
public static bool DownloadCanceled; public static bool DownloadCanceled;
public static string AssetId; public static string AssetId;
@@ -60,13 +62,25 @@ namespace VRCX
return versionHex.PadLeft(32, '0'); return versionHex.PadLeft(32, '0');
} }
public string GetVRChatCacheLocation(string id, int version, string cacheDir) public string GetVRChatCacheLocation(string cacheDir)
{ {
var cachePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"Low\VRChat\VRChat\Cache-WindowsPlayer"; var cachePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"Low\VRChat\VRChat\Cache-WindowsPlayer";
if (cacheDir != String.Empty && Directory.Exists(cacheDir)) if (!string.IsNullOrEmpty(cacheDir) && Directory.Exists(cacheDir))
{
cachePath = Path.Combine(cacheDir, @"Cache-WindowsPlayer"); cachePath = Path.Combine(cacheDir, @"Cache-WindowsPlayer");
} return cachePath;
}
public string GetAssetBundleCacherLocation(string cacheDir)
{
var cachePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"Low\VRChat\VRChat\AssetBundleCacher";
if (!string.IsNullOrEmpty(cacheDir) && Directory.Exists(cacheDir))
cachePath = Path.Combine(cacheDir, @"AssetBundleCacher");
return cachePath;
}
public string GetVRChatCacheFullLocation(string id, int version, string cacheDir)
{
var cachePath = GetVRChatCacheLocation(cacheDir);
var idHash = GetAssetId(id); var idHash = GetAssetId(id);
var versionLocation = GetAssetVersion(version); var versionLocation = GetAssetVersion(version);
return Path.Combine(cachePath, idHash, versionLocation); return Path.Combine(cachePath, idHash, versionLocation);
@@ -74,7 +88,7 @@ namespace VRCX
public long CheckVRChatCache(string id, int version, string cacheDir) public long CheckVRChatCache(string id, int version, string cacheDir)
{ {
var FullLocation = GetVRChatCacheLocation(id, version, cacheDir); var FullLocation = GetVRChatCacheFullLocation(id, version, cacheDir);
var FileLocation = Path.Combine(FullLocation, "__data"); var FileLocation = Path.Combine(FullLocation, "__data");
if (File.Exists(FileLocation)) if (File.Exists(FileLocation))
{ {
@@ -113,12 +127,9 @@ namespace VRCX
} }
} }
DownloadProgress = 0; DownloadProgress = 0;
VRChatCacheLocation = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"Low\VRChat\VRChat"; VRChatCacheLocation = GetVRChatCacheLocation(cacheDir);
if (cacheDir != String.Empty && Directory.Exists(cacheDir)) AssetBundleCacherLocation = GetAssetBundleCacherLocation(cacheDir);
{ CacheDestinationLocation = GetVRChatCacheFullLocation(id, version, cacheDir);
VRChatCacheLocation = cacheDir;
}
CacheDestinationLocation = GetVRChatCacheLocation(id, version, cacheDir);
if (File.Exists(Path.Combine(CacheDestinationLocation, "__data"))) if (File.Exists(Path.Combine(CacheDestinationLocation, "__data")))
{ {
DownloadProgress = -12; DownloadProgress = -12;
@@ -128,8 +139,8 @@ namespace VRCX
AssetMd5 = md5; AssetMd5 = md5;
AssetId = GetAssetId(id); AssetId = GetAssetId(id);
AssetVersion = GetAssetVersion(version); AssetVersion = GetAssetVersion(version);
var DownloadTempLocation = Path.Combine(VRChatCacheLocation, "AssetBundleCacher", AssetId); DownloadTempLocation = Path.Combine(AssetBundleCacherLocation, AssetId);
AssetBundleCacherTemp = Path.Combine(VRChatCacheLocation, "AssetBundleCacher\\Cache"); AssetBundleCacherTemp = Path.Combine(AssetBundleCacherLocation, "Cache");
Directory.CreateDirectory(AssetBundleCacherTemp); Directory.CreateDirectory(AssetBundleCacherTemp);
AssetBundleCacherArgs = $@" -url ""file:\\{DownloadTempLocation}"" -id ""{id}"" -ver {version} -batchmode -path ""{AssetBundleCacherTemp}"""; AssetBundleCacherArgs = $@" -url ""file:\\{DownloadTempLocation}"" -id ""{id}"" -ver {version} -batchmode -path ""{AssetBundleCacherTemp}""";
DownloadCanceled = false; DownloadCanceled = false;
@@ -150,8 +161,8 @@ namespace VRCX
if (process != null && !process.HasExited) if (process != null && !process.HasExited)
{ {
process.Kill(); process.Kill();
if (File.Exists(Path.Combine(VRChatCacheLocation, "AssetBundleCacher", AssetId))) if (File.Exists(DownloadTempLocation))
File.Delete(Path.Combine(VRChatCacheLocation, "AssetBundleCacher", AssetId)); File.Delete(DownloadTempLocation);
if (Directory.Exists(Path.Combine(AssetBundleCacherTemp, AssetId))) if (Directory.Exists(Path.Combine(AssetBundleCacherTemp, AssetId)))
Directory.Delete(Path.Combine(AssetBundleCacherTemp, AssetId), true); Directory.Delete(Path.Combine(AssetBundleCacherTemp, AssetId), true);
} }
@@ -172,23 +183,23 @@ namespace VRCX
{ {
if (DownloadCanceled) if (DownloadCanceled)
{ {
if (File.Exists(Path.Combine(VRChatCacheLocation, "AssetBundleCacher", AssetId))) if (File.Exists(DownloadTempLocation))
File.Delete(Path.Combine(VRChatCacheLocation, "AssetBundleCacher", AssetId)); File.Delete(DownloadTempLocation);
return; return;
} }
DownloadProgress = -1; DownloadProgress = -1;
if (!File.Exists(Path.Combine(VRChatCacheLocation, "AssetBundleCacher", AssetId))) if (!File.Exists(DownloadTempLocation))
{ {
DownloadProgress = -15; DownloadProgress = -15;
return; return;
} }
FileInfo data = new FileInfo(Path.Combine(VRChatCacheLocation, "AssetBundleCacher", AssetId)); FileInfo data = new FileInfo(DownloadTempLocation);
if (data.Length != AssetSize) if (data.Length != AssetSize)
{ {
DownloadProgress = -15; DownloadProgress = -15;
return; return;
} }
using (var stream = File.OpenRead(Path.Combine(VRChatCacheLocation, "AssetBundleCacher", AssetId))) using (var stream = File.OpenRead(DownloadTempLocation))
{ {
byte[] md5AsBytes = MD5.Create().ComputeHash(stream); byte[] md5AsBytes = MD5.Create().ComputeHash(stream);
var md5 = System.Convert.ToBase64String(md5AsBytes); var md5 = System.Convert.ToBase64String(md5AsBytes);
@@ -202,7 +213,7 @@ namespace VRCX
process.StartInfo.FileName = Path.Combine(Program.BaseDirectory, "AssetBundleCacher\\AssetBundleCacher.exe"); process.StartInfo.FileName = Path.Combine(Program.BaseDirectory, "AssetBundleCacher\\AssetBundleCacher.exe");
process.StartInfo.Arguments = AssetBundleCacherArgs; process.StartInfo.Arguments = AssetBundleCacherArgs;
process.Start(); process.Start();
process.WaitForExit(1000 * 60 * 2); //2mins process.WaitForExit((int) TimeSpan.FromMinutes(2).TotalMilliseconds); //2mins
if (process.ExitCode != 0) if (process.ExitCode != 0)
{ {
DownloadProgress = -13; DownloadProgress = -13;
@@ -211,16 +222,16 @@ namespace VRCX
if (DownloadCanceled) if (DownloadCanceled)
{ {
if (File.Exists(Path.Combine(VRChatCacheLocation, "AssetBundleCacher", AssetId))) if (File.Exists(DownloadTempLocation))
File.Delete(Path.Combine(VRChatCacheLocation, "AssetBundleCacher", AssetId)); File.Delete(DownloadTempLocation);
return; return;
} }
try try
{ {
if (File.Exists(Path.Combine(CacheDestinationLocation, "__data"))) if (File.Exists(Path.Combine(CacheDestinationLocation, "__data")))
{ {
if (File.Exists(Path.Combine(VRChatCacheLocation, "AssetBundleCacher", AssetId))) if (File.Exists(DownloadTempLocation))
File.Delete(Path.Combine(VRChatCacheLocation, "AssetBundleCacher", AssetId)); File.Delete(DownloadTempLocation);
if (Directory.Exists(Path.Combine(AssetBundleCacherTemp, AssetId))) if (Directory.Exists(Path.Combine(AssetBundleCacherTemp, AssetId)))
Directory.Delete(Path.Combine(AssetBundleCacherTemp, AssetId), true); Directory.Delete(Path.Combine(AssetBundleCacherTemp, AssetId), true);
DownloadProgress = -12; DownloadProgress = -12;
@@ -234,13 +245,11 @@ namespace VRCX
DownloadProgress = -13; DownloadProgress = -13;
return; return;
} }
if (!Directory.Exists(Path.Combine(VRChatCacheLocation, "Cache-WindowsPlayer", AssetId))) if (!Directory.Exists(Path.Combine(VRChatCacheLocation, AssetId)))
Directory.CreateDirectory(Path.Combine(VRChatCacheLocation, "Cache-WindowsPlayer", AssetId)); Directory.CreateDirectory(Path.Combine(VRChatCacheLocation, AssetId));
Directory.Move(CacheSource, CacheDestinationLocation); Directory.Move(CacheSource, CacheDestinationLocation);
if (File.Exists(Path.Combine(VRChatCacheLocation, "Cache-WindowsPlayer", "__info"))) Directory.Delete(Path.Combine(AssetBundleCacherTemp, AssetId), true);
File.Delete(Path.Combine(VRChatCacheLocation, "Cache-WindowsPlayer", "__info")); File.Delete(DownloadTempLocation);
Directory.Delete(Path.Combine(VRChatCacheLocation, "AssetBundleCacher\\Cache", AssetId), true);
File.Delete(Path.Combine(VRChatCacheLocation, "AssetBundleCacher", AssetId));
} }
catch catch
{ {
@@ -252,16 +261,14 @@ namespace VRCX
public void DeleteCache(string cacheDir, string id, int version) public void DeleteCache(string cacheDir, string id, int version)
{ {
var FullLocation = GetVRChatCacheLocation(id, version, cacheDir); var FullLocation = GetVRChatCacheFullLocation(id, version, cacheDir);
if (Directory.Exists(FullLocation)) if (Directory.Exists(FullLocation))
Directory.Delete(FullLocation, true); Directory.Delete(FullLocation, true);
} }
public void DeleteAllCache(string cacheDir) public void DeleteAllCache(string cacheDir)
{ {
var cachePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"Low\VRChat\VRChat\Cache-WindowsPlayer"; var cachePath = GetVRChatCacheLocation(cacheDir);
if (cacheDir != String.Empty && Directory.Exists(cacheDir))
cachePath = Path.Combine(cacheDir, @"Cache-WindowsPlayer");
if (Directory.Exists(cachePath)) if (Directory.Exists(cachePath))
{ {
Directory.Delete(cachePath, true); Directory.Delete(cachePath, true);
@@ -271,9 +278,7 @@ namespace VRCX
public void SweepCache(string cacheDir) public void SweepCache(string cacheDir)
{ {
var cachePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"Low\VRChat\VRChat\Cache-WindowsPlayer"; var cachePath = GetVRChatCacheLocation(cacheDir);
if (cacheDir != String.Empty && Directory.Exists(cacheDir))
cachePath = Path.Combine(cacheDir, @"Cache-WindowsPlayer");
if (!Directory.Exists(cachePath)) if (!Directory.Exists(cachePath))
return; return;
var directories = new DirectoryInfo(cachePath); var directories = new DirectoryInfo(cachePath);
@@ -302,9 +307,7 @@ namespace VRCX
public long GetCacheSize(string cacheDir) public long GetCacheSize(string cacheDir)
{ {
var cachePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"Low\VRChat\VRChat\Cache-WindowsPlayer"; var cachePath = GetVRChatCacheLocation(cacheDir);
if (cacheDir != String.Empty && Directory.Exists(cacheDir))
cachePath = Path.Combine(cacheDir, @"Cache-WindowsPlayer");
if (Directory.Exists(cachePath)) if (Directory.Exists(cachePath))
{ {
return DirSize(new DirectoryInfo(cachePath)); return DirSize(new DirectoryInfo(cachePath));
+1 -1
View File
@@ -11509,7 +11509,7 @@ speechSynthesis.getVoices();
(this.downloadCurrent.id === L.worldId)) { (this.downloadCurrent.id === L.worldId)) {
return; return;
} }
API.getCachedWorld({ API.getWorld({
worldId: L.worldId worldId: L.worldId
}).then((args) => { }).then((args) => {
var { ref } = args; var { ref } = args;