fix legacy migration not working properly with people using Penumbra mod folder with a backslash at the end

This commit is contained in:
Stanley Dimant
2022-09-25 16:39:48 +02:00
parent ea411811e4
commit 807d778b6b
3 changed files with 21 additions and 6 deletions

View File

@@ -131,10 +131,11 @@ public class FileDbManager
private FileCache? MigrateLegacy(FileCache fileCache) private FileCache? MigrateLegacy(FileCache fileCache)
{ {
if (fileCache.OriginalFilepath.Contains(PenumbraPrefix) || fileCache.OriginalFilepath.Contains(CachePrefix)) return fileCache; if (fileCache.OriginalFilepath.Contains(PenumbraPrefix + "\\") || fileCache.OriginalFilepath.Contains(CachePrefix)) return fileCache;
var fileInfo = new FileInfo(fileCache.OriginalFilepath); var fileInfo = new FileInfo(fileCache.OriginalFilepath);
var penumbraDir = _ipcManager.PenumbraModDirectory()!; var penumbraDir = _ipcManager.PenumbraModDirectory()!;
if (penumbraDir.Last() != '\\') penumbraDir += "\\";
// check if it's a cache file // check if it's a cache file
if (fileInfo.Exists && fileInfo.Name.Length == 40) if (fileInfo.Exists && fileInfo.Name.Length == 40)
{ {
@@ -143,7 +144,12 @@ public class FileDbManager
else if (fileInfo.Exists && fileInfo.FullName.ToLowerInvariant().Contains(penumbraDir)) else if (fileInfo.Exists && fileInfo.FullName.ToLowerInvariant().Contains(penumbraDir))
{ {
// attempt to replace penumbra mod folder path with {penumbra} // attempt to replace penumbra mod folder path with {penumbra}
var newPath = PenumbraPrefix + fileCache.OriginalFilepath.ToLowerInvariant().Replace(_ipcManager.PenumbraModDirectory()!, string.Empty); var newPath = PenumbraPrefix + "\\" + fileCache.OriginalFilepath.ToLowerInvariant().Replace(penumbraDir, string.Empty);
MigrateLegacyFilePath(fileCache, newPath);
}
else if (fileInfo.FullName.ToLowerInvariant().Contains(PenumbraPrefix))
{
var newPath = PenumbraPrefix + "\\" + fileCache.OriginalFilepath.ToLowerInvariant().Replace(PenumbraPrefix, string.Empty);
MigrateLegacyFilePath(fileCache, newPath); MigrateLegacyFilePath(fileCache, newPath);
} }
else else
@@ -203,11 +209,20 @@ public class FileDbManager
LastModifiedDate = cache.LastModifiedDate LastModifiedDate = cache.LastModifiedDate
}; };
db.Remove(cache); db.Remove(cache);
db.SaveChanges();
var existingCache = db.FileCaches.FirstOrDefault(f => f.Filepath == newPath && f.Hash == cache.Hash);
if (existingCache != null)
{
fileCacheToMigrate.UpdateFileCache(existingCache);
}
else
{
db.FileCaches.Add(newcache); db.FileCaches.Add(newcache);
fileCacheToMigrate.UpdateFileCache(newcache); fileCacheToMigrate.UpdateFileCache(newcache);
db.SaveChanges(); db.SaveChanges();
} }
} }
}
private void DeleteFromDatabase(IEnumerable<FileCache> markedForDeletion) private void DeleteFromDatabase(IEnumerable<FileCache> markedForDeletion)
{ {

View File

@@ -80,7 +80,7 @@ public class PeriodicFileScanner : IDisposable
{ {
while (!token.IsCancellationRequested) while (!token.IsCancellationRequested)
{ {
isForced = RecalculateFileCacheSize(); isForced |= RecalculateFileCacheSize();
if (!_pluginConfiguration.FileScanPaused || isForced) if (!_pluginConfiguration.FileScanPaused || isForced)
{ {
isForced = false; isForced = false;

View File

@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<Authors></Authors> <Authors></Authors>
<Company></Company> <Company></Company>
<Version>0.4.11</Version> <Version>0.4.12</Version>
<Description></Description> <Description></Description>
<Copyright></Copyright> <Copyright></Copyright>
<PackageProjectUrl>https://github.com/Penumbra-Sync/client</PackageProjectUrl> <PackageProjectUrl>https://github.com/Penumbra-Sync/client</PackageProjectUrl>