Merge branch 'Tryibion-script-recycle' into 1.12

This commit is contained in:
Wojtek Figat
2026-03-10 14:16:11 +01:00
5 changed files with 42 additions and 11 deletions

View File

@@ -754,6 +754,10 @@ namespace FlaxEditor.Modules
// Delete asset by using content pool
FlaxEngine.Content.DeleteAsset(path);
}
else if (item is ScriptItem)
{
FlaxEngine.Content.DeleteScript(path);
}
else if (deletedByUser)
{
// Delete file
@@ -901,7 +905,7 @@ namespace FlaxEditor.Modules
{
// Item doesn't exist anymore
Editor.Log(string.Format($"Content item \'{child.Path}\' has been removed"));
Delete(child, false);
Delete(child);
i--;
}
else if (canHaveAssets && child is AssetItem childAsset)

View File

@@ -316,7 +316,7 @@ void Asset::OnDeleteObject()
// Delete file
if (!IsVirtual())
Content::deleteFileSafety(path, id);
Content::deleteFileSafety(path, &id);
}
#endif
}

View File

@@ -791,6 +791,27 @@ void Content::DeleteAsset(Asset* asset)
asset->DeleteObject();
}
void Content::DeleteScript(const StringView& path)
{
PROFILE_CPU();
if (path.IsEmpty())
return;
// Return if asset
Asset* asset = GetAsset(path);
if (asset != nullptr)
{
return;
}
#if USE_EDITOR
LOG(Info, "Deleting script '{0}'", path);
// Delete file
deleteFileSafety(path);
#endif
}
void Content::DeleteAsset(const StringView& path)
{
PROFILE_CPU();
@@ -819,13 +840,13 @@ void Content::DeleteAsset(const StringView& path)
}
// Delete file
deleteFileSafety(path, info.ID);
deleteFileSafety(path, &info.ID);
#endif
}
void Content::deleteFileSafety(const StringView& path, const Guid& id)
void Content::deleteFileSafety(const StringView& path, const Guid* id)
{
if (!id.IsValid())
if (id && !id->IsValid())
{
LOG(Warning, "Cannot remove file \'{0}\'. Given ID is invalid.", path);
return;
@@ -834,12 +855,12 @@ void Content::deleteFileSafety(const StringView& path, const Guid& id)
// Ensure that file has the same ID (prevent from deleting different assets)
auto storage = ContentStorageManager::TryGetStorage(path);
if (storage)
if (storage && id)
{
storage->CloseFileHandles(); // Close file handle to allow removing it
if (!storage->HasAsset(id))
if (!storage->HasAsset(*id))
{
LOG(Warning, "Cannot remove file \'{0}\'. It doesn\'t contain asset {1}.", path, id);
LOG(Warning, "Cannot remove file \'{0}\'. It doesn\'t contain asset {1}.", path, *id);
return;
}
}

View File

@@ -306,6 +306,12 @@ public:
/// </summary>
/// <param name="asset">The asset.</param>
API_FUNCTION() static void DeleteAsset(Asset* asset);
/// <summary>
/// Deletes the script item at the specified path.
/// </summary>
/// <param name="path">The script path.</param>
API_FUNCTION() static void DeleteScript(const StringView& path);
/// <summary>
/// Deletes the asset at the specified path.
@@ -389,7 +395,7 @@ private:
static void onAssetLoaded(Asset* asset);
static void onAssetUnload(Asset* asset);
static void onAssetChangeId(Asset* asset, const Guid& oldId, const Guid& newId);
static void deleteFileSafety(const StringView& path, const Guid& id);
static void deleteFileSafety(const StringView& path, const Guid* id = nullptr);
// Internal bindings
#if !COMPILE_WITHOUT_CSHARP

View File

@@ -17,7 +17,7 @@
#define __shobjidl_h__
#define LPFNADDPROPSHEETPAGE void*
#include <ShlObj.h>
#include <ShellAPI.h>
#include <shellapi.h>
#include <KnownFolders.h>
#undef ShellExecute
@@ -111,7 +111,7 @@ bool WindowsFileSystem::MoveFileToRecycleBin(const StringView& path)
op.wFunc = FO_DELETE;
op.pFrom = pathNullNull;
op.pTo = nullptr;
op.fFlags = FOF_ALLOWUNDO | FOF_NO_UI;
op.fFlags = FOF_ALLOWUNDO | FOF_NO_UI | FOF_NOCONFIRMATION;
op.fAnyOperationsAborted = FALSE;
op.hNameMappings = nullptr;
op.lpszProgressTitle = nullptr;