Ejemplo n.º 1
0
        public T Load()
        {
            _storageHelper = new StoragePowerToysVersionInfo(FilePath, JSON_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($"|JsonStorage.TryLoad|Deleting cached data|<{FilePath}>");
                }
            }

            if (File.Exists(FilePath))
            {
                var serialized = File.ReadAllText(FilePath);
                if (!string.IsNullOrWhiteSpace(serialized))
                {
                    Deserialize(serialized);
                }
                else
                {
                    LoadDefault();
                }
            }
            else
            {
                LoadDefault();
            }
            return(_data.NonNull());
        }
Ejemplo n.º 2
0
        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)
                {
                    Log.Error($"|BinaryStorage.TryLoad|Zero length cache file <{FilePath}>");
                    Save(defaultData);
                    return(defaultData);
                }

                using (var stream = new FileStream(FilePath, FileMode.Open))
                {
                    var d = Deserialize(stream, defaultData);
                    return(d);
                }
            }
            else
            {
                Log.Info("|BinaryStorage.TryLoad|Cache file not exist, load default data");
                Save(defaultData);
                return(defaultData);
            }
        }
Ejemplo n.º 3
0
        public T TryLoad(T defaultData)
        {
            _storageHelper = new StoragePowerToysVersionInfo(FilePath, _binaryStorage);

            // 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 (_fileSystem.File.Exists(FilePath))
                {
                    _fileSystem.File.Delete(FilePath);

                    Log.Info($"Deleting cached data at <{FilePath}>", GetType());
                }
            }

            if (_fileSystem.File.Exists(FilePath))
            {
                if (_fileSystem.FileInfo.FromFileName(FilePath).Length == 0)
                {
                    Log.Error($"Zero length cache file <{FilePath}>", GetType());

                    Save(defaultData);
                    return(defaultData);
                }

                using (var stream = _fileSystem.FileStream.Create(FilePath, FileMode.Open))
                {
                    var d = Deserialize(stream, defaultData);
                    return(d);
                }
            }
            else
            {
                Log.Info("Cache file not exist, load default data", GetType());

                Save(defaultData);
                return(defaultData);
            }
        }