// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
#pragma once
#include "FlaxStorageReference.h"
#include "Engine/Core/Types/TimeSpan.h"
class FlaxFile;
class FlaxPackage;
///
/// Content Storage Manager is responsible for content data management
///
class FLAXENGINE_API ContentStorageManager
{
public:
///
/// Auto-release timeout for unused asset chunks.
///
static TimeSpan UnusedDataChunksLifetime;
public:
///
/// Gets the assets data storage container.
///
/// The path.
/// True if load container, otherwise false.
/// Flax Storage or null if not package at that location
static FlaxStorageReference GetStorage(const StringView& path, bool loadIt = true);
///
/// Tries the assets data storage container if it's created.
///
/// The path.
/// Flax Storage or null in no package at that location has been opened.
static FlaxStorageReference TryGetStorage(const StringView& path);
///
/// Ensures the access to the given file location is free. Closes handles to that file from packages.
///
/// The path.
/// Flax Storage or null in no package at that location has been opened.
static FlaxStorageReference EnsureAccess(const StringView& path);
///
/// Gets total memory used by chunks (in bytes).
///
/// Memory usage in bytes.
static uint32 GetMemoryUsage();
///
/// Determines whether the specified asset exists in this container.
///
/// The asset identifier.
/// True if the specified asset exists in this container, otherwise false.
static bool HasAsset(const Guid& id);
///
/// Gets the asset entry in the storage at the given path (if it has one stored item).
///
/// The path.
/// The output.
/// True if cannot load storage container or it has more than one entry inside.
static bool GetAssetEntry(const String& path, FlaxStorage::Entry& output);
///
/// Called when asset ges renamed.
///
/// The old path.
/// The new path.
static void OnRenamed(const StringView& oldPath, const StringView& newPath);
///
/// Ensures that storage manager is unlocked (by stopping the thread if its locked).
///
static void EnsureUnlocked();
public:
///
/// Determines whether the specified path can be a binary asset file (based on it's extension).
///
/// The path.
/// True if can be a storage path (has a proper extension), otherwise false.
static bool IsFlaxStoragePath(const String& path);
///
/// Determines whether the specified extension can be a binary asset file.
///
/// The path.
/// True if can be a storage extension, otherwise false.
static bool IsFlaxStorageExtension(const String& extension);
public:
///
/// Gets the packages.
///
/// The result.
static void GetPackages(Array& result);
///
/// Gets the files.
///
/// The result.
static void GetFiles(Array& result);
///
/// Gets the storage containers (packages and files).
///
/// The result.
static void GetStorage(Array& result);
};