mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 04:07:40 +02:00
[PT Run] Clear binary and json storage files on version upgrade (#4479)
* Clean termination of powertoys process. * Fixed issue with run not responding to WM_CLOSE * Fixed serialization error in pinyin and image cache * Fixed merge conflict * Fixed nit wrt to master * Basic framework of clearing up of cache is working * formatting * removed the default argument of load * fixed nit comment * rewriting the PowerToys version * Each storage file has an associated version file which helps decide whether or not to delete that file on loading * removed unnecessary reference * renamed file to StoragePowerToysVersionInfo * adding log files * Checking whether the version strings are null, if so, we would clear the cache * Added filepath to log files to make it more informative * fixed nit naming * using lesser than to compare instead of portable version Co-authored-by: Divyansh Srivastava <somm14divi@gmail.com>
This commit is contained in:
@@ -14,6 +14,10 @@ namespace Wox.Infrastructure.Storage
|
||||
/// </summary>
|
||||
public class BinaryStorage<T>
|
||||
{
|
||||
// This storage helper returns whether or not to delete the binary storage items
|
||||
private static readonly int BINARY_STORAGE = 0;
|
||||
private StoragePowerToysVersionInfo _storageHelper;
|
||||
|
||||
public BinaryStorage(string filename)
|
||||
{
|
||||
const string directoryName = "Cache";
|
||||
@@ -28,6 +32,17 @@ namespace Wox.Infrastructure.Storage
|
||||
|
||||
public T TryLoad(T defaultData)
|
||||
{
|
||||
_storageHelper = new StoragePowerToysVersionInfo(FilePath, BINARY_STORAGE);
|
||||
// Depending on the version number of the previously installed PT Run, delete the cache if it is found to be incompatible
|
||||
if (_storageHelper.clearCache)
|
||||
{
|
||||
if(File.Exists(FilePath))
|
||||
{
|
||||
File.Delete(FilePath);
|
||||
Log.Info($"|BinaryStorage.TryLoad|Deleting cached data| <{FilePath}>");
|
||||
}
|
||||
}
|
||||
|
||||
if (File.Exists(FilePath))
|
||||
{
|
||||
if (new FileInfo(FilePath).Length == 0)
|
||||
@@ -110,6 +125,8 @@ namespace Wox.Infrastructure.Storage
|
||||
Log.Exception($"|BinaryStorage.Save|serialize error for file <{FilePath}>", e);
|
||||
}
|
||||
}
|
||||
_storageHelper.Close();
|
||||
Log.Info($"|BinaryStorage.Save|Saving cached data| <{FilePath}>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user