Disable cache deletion when file in use, cache avatars.

This commit is contained in:
Natsumi
2021-08-10 17:03:42 +12:00
parent f5098485f0
commit e1898e27b8
3 changed files with 62 additions and 19 deletions

View File

@@ -87,16 +87,26 @@ namespace VRCX
return Path.Combine(cachePath, idHash, versionLocation);
}
public long CheckVRChatCache(string id, int version, string cacheDir)
public long[] CheckVRChatCache(string id, int version, string cacheDir)
{
long FileSize = -1;
long IsLocked = 0;
var FullLocation = GetVRChatCacheFullLocation(id, version, cacheDir);
var FileLocation = Path.Combine(FullLocation, "__data");
if (File.Exists(FileLocation))
{
FileInfo data = new FileInfo(FileLocation);
return data.Length;
FileSize = data.Length;
}
return -1;
if (File.Exists(Path.Combine(FullLocation, "__lock")))
{
IsLocked = 1;
}
return new long[]
{
FileSize,
IsLocked
};
}
public void DownloadCacheFile(string cacheDir, string url, string id, int version, int sizeInBytes, string md5, string AppVersion, bool IsUpdate)

View File

@@ -9188,7 +9188,10 @@ speechSynthesis.getVoices();
rooms: [],
treeData: [],
fileCreatedAt: '',
fileSize: ''
fileSize: '',
inCache: false,
cacheSize: 0,
cacheLocked: false
};
API.$on('LOGOUT', function () {
@@ -9283,6 +9286,7 @@ speechSynthesis.getVoices();
D.loading = true;
D.inCache = false;
D.cacheSize = 0;
D.cacheLocked = false;
D.rooms = [];
API.getCachedWorld({
worldId: L.worldId
@@ -9561,7 +9565,8 @@ speechSynthesis.getVoices();
fileCreatedAt: '',
fileSize: '',
inCache: false,
cacheSize: 0
cacheSize: 0,
cacheLocked: false
};
API.$on('LOGOUT', function () {
@@ -9597,6 +9602,7 @@ speechSynthesis.getVoices();
D.fileSize = '';
D.inCache = false;
D.cacheSize = 0;
D.cacheLocked = false;
D.isQuestFallback = false;
D.isFavorite = API.cachedFavoritesByObjectId.has(avatarId);
var ref = API.cachedAvatars.get(avatarId);
@@ -12487,10 +12493,14 @@ speechSynthesis.getVoices();
if (D.visible) {
D.inCache = false;
D.cacheSize = 0;
this.checkVRChatCache(D.ref).then((cacheSize) => {
if (cacheSize > 0) {
D.cacheLocked = false;
this.checkVRChatCache(D.ref).then((cacheInfo) => {
if (cacheInfo[0] > 0) {
D.inCache = true;
D.cacheSize = `${(cacheSize / 1048576).toFixed(2)} MiB`;
D.cacheSize = `${(cacheInfo[0] / 1048576).toFixed(2)} MiB`;
}
if (cacheInfo[1] === 1) {
D.cacheLocked = true;
}
});
}
@@ -12501,10 +12511,14 @@ speechSynthesis.getVoices();
if (D.visible) {
D.inCache = false;
D.cacheSize = 0;
this.checkVRChatCache(D.ref).then((cacheSize) => {
if (cacheSize > 0) {
D.cacheLocked = false;
this.checkVRChatCache(D.ref).then((cacheInfo) => {
if (cacheInfo[0] > 0) {
D.inCache = true;
D.cacheSize = `${(cacheSize / 1048576).toFixed(2)} MiB`;
D.cacheSize = `${(cacheInfo[0] / 1048576).toFixed(2)} MiB`;
}
if (cacheInfo[1] === 1) {
D.cacheLocked = true;
}
});
}
@@ -12690,8 +12704,8 @@ speechSynthesis.getVoices();
worldId: L.worldId
}).then((args) => {
var { ref } = args;
this.checkVRChatCache(ref).then((cacheSize) => {
if (cacheSize === -1) {
this.checkVRChatCache(ref).then((cacheInfo) => {
if ((cacheInfo[0] === -1) && (cacheInfo[1] === 0)) {
this.downloadQueue.set(ref.id, { ref, type, userId, location });
this.downloadQueueTable.data = Array.from(this.downloadQueue.values());
if (!this.downloadInProgress) {
@@ -12724,11 +12738,19 @@ speechSynthesis.getVoices();
if (this.worldDialog.id === this.downloadCurrent.id) {
this.updateVRChatWorldCache();
}
if (this.avatarDialog.id === this.downloadCurrent.id) {
this.updateVRChatAvatarCache();
}
if (this.downloadCurrent.type === 'Manual') {
this.$message({
message: 'World cache complete',
type: 'success'
});
} else if (this.downloadCurrent.type === 'Avatar') {
this.$message({
message: 'Avatar cache complete',
type: 'success'
});
}
this.downloadCurrent.status = 'Success';
this.downloadCurrent.date = Date.now();
@@ -12777,6 +12799,9 @@ speechSynthesis.getVoices();
if (this.worldDialog.id === this.downloadCurrent.id) {
this.updateVRChatWorldCache();
}
if (this.avatarDialog.id === this.downloadCurrent.id) {
this.updateVRChatAvatarCache();
}
if (this.downloadCurrent.type === 'Manual') {
this.$message({
message: 'File already in cache',

View File

@@ -1271,11 +1271,11 @@ html
span(v-show="worldDialog.ref.name !== worldDialog.ref.description" v-text="worldDialog.ref.description" style="font-size:12px")
div(style="flex:none;margin-left:10px")
el-tooltip(v-if="worldDialog.inCache" placement="top" content="Delete world from cache" :disabled="hideTooltips")
el-button(icon="el-icon-delete" circle @click="deleteVRChatCache(worldDialog.ref)")
el-button(icon="el-icon-delete" circle @click="deleteVRChatCache(worldDialog.ref)" :disabled="worldDialog.cacheLocked")
el-tooltip(v-else-if="downloadCurrent.id === worldDialog.id || downloadQueue.has(worldDialog.id)" placement="top" content="Show download progress" :disabled="hideTooltips")
el-button(icon="el-icon-loading" circle @click="showDownloadDialog")
el-tooltip(v-else placement="top" content="Download world to cache" :disabled="hideTooltips")
el-button(icon="el-icon-download" circle @click="queueCacheDownload(worldDialog.ref, 'Manual')")
el-button(icon="el-icon-download" circle @click="queueCacheDownload(worldDialog.ref, 'Manual')" :disabled="worldDialog.cacheLocked")
el-tooltip(v-if="worldDialog.isFavorite" placement="top" content="Remove from favorites" :disabled="hideTooltips")
el-button(type="warning" icon="el-icon-star-on" circle @click="worldDialogCommand('Delete Favorite')" style="margin-left:5px")
el-tooltip(v-else placement="top" content="Add to favorites" :disabled="hideTooltips")
@@ -1417,7 +1417,11 @@ html
span(v-show="avatarDialog.ref.name !== avatarDialog.ref.description" v-text="avatarDialog.ref.description" style="font-size:12px")
div(style="flex:none;margin-left:10px")
el-tooltip(v-if="avatarDialog.inCache" placement="top" content="Delete avatar from cache" :disabled="hideTooltips")
el-button(icon="el-icon-delete" circle @click="deleteVRChatCache(avatarDialog.ref)")
el-button(icon="el-icon-delete" circle @click="deleteVRChatCache(avatarDialog.ref)" :disabled="avatarDialog.cacheLocked")
el-tooltip(v-else-if="downloadCurrent.id === avatarDialog.id || downloadQueue.has(avatarDialog.id)" placement="top" content="Show download progress" :disabled="hideTooltips")
el-button(icon="el-icon-loading" circle @click="showDownloadDialog")
el-tooltip(v-else-if="avatarDialog.ref.id && avatarDialog.ref.version && avatarDialog.ref.assetUrl" placement="top" content="Download avatar to cache" :disabled="hideTooltips")
el-button(icon="el-icon-download" circle @click="queueCacheDownload(avatarDialog.ref, 'Avatar')" :disabled="avatarDialog.cacheLocked")
el-tooltip(v-if="avatarDialog.isFavorite" placement="top" content="Remove from favorites" :disabled="hideTooltips")
el-button(type="warning" icon="el-icon-star-on" circle @click="avatarDialogCommand('Delete Favorite')" style="margin-left:5px")
el-tooltip(v-else placement="top" content="Add to favorites" :disabled="hideTooltips")
@@ -1717,8 +1721,9 @@ html
//- dialog: Cache Download
el-dialog.x-dialog(ref="downloadDialog" :visible.sync="downloadDialog.visible" title="Download History" width="770px")
div(v-if="downloadInProgress")
span.x-link(v-if="downloadCurrent.ref" @click="showWorldDialog(downloadCurrent.location)" v-text="downloadCurrent.ref.name")
div(v-if="downloadInProgress && downloadCurrent.ref")
span.x-link(v-if="downloadCurrent.type === 'Avatar'" @click="showAvatarDialog(downloadCurrent.location)" v-text="downloadCurrent.ref.name")
span.x-link(v-else @click="showWorldDialog(downloadCurrent.location)" v-text="downloadCurrent.ref.name")
el-button(type="text" icon="el-icon-close" size="mini" @click="cancelVRChatCacheDownload(downloadCurrent.id)" style="margin-left:5px")
el-progress(:percentage="downloadProgress" :format="downloadProgressText")
template(v-if="downloadQueueTable.data.length >= 1")
@@ -1726,7 +1731,8 @@ html
data-tables(v-bind="downloadQueueTable" style="margin-top:10px")
el-table-column(label="Name" prop="name")
template(v-once #default="scope")
span.x-link(v-text="scope.row.ref.name" @click="showWorldDialog(scope.row.location)")
span.x-link(v-if="scope.row.type === 'Avatar'" v-text="scope.row.ref.name" @click="showAvatarDialog(scope.row.location)")
span.x-link(v-else v-text="scope.row.ref.name" @click="showWorldDialog(scope.row.location)")
el-table-column(label="User Name" prop="name" width="150")
template(v-once #default="scope")
span.x-link(v-text="getDisplayName(scope.row.userId)" @click="showUserDialog(scope.row.userId)")
@@ -1743,6 +1749,8 @@ html
template(v-once #default="scope")
template(v-if="scope.row.ref.id === 'VRCXUpdate'")
el-button(size="small" @click="showVRCXUpdateDialog") VRCX Update
template(v-else-if="scope.row.type === 'Avatar'")
span.x-link(v-text="scope.row.ref.name" @click="showAvatarDialog(scope.row.location)")
template(v-else)
span.x-link(v-text="scope.row.ref.name" @click="showWorldDialog(scope.row.location)")
el-table-column(label="User Name" prop="name" width="150")