Fix scripts/content files getting deleted after file modifications
Some editors like Visual Studio saves the modified file to a temporary file, deletes the original file and renames the temporary file back to original filename, which rarely causes the editor to detect it as a file deletion action by user.
This commit is contained in:
@@ -748,21 +748,27 @@ namespace FlaxEditor.Modules
|
||||
if (item.Path.Contains(".Build.cs", StringComparison.Ordinal) && item.ItemType == ContentItemType.Script)
|
||||
Editor.Instance.CodeEditing.RemoveModule(item.Path);
|
||||
|
||||
// Check if it's an asset
|
||||
if (item.IsAsset)
|
||||
{
|
||||
// Delete asset by using content pool
|
||||
FlaxEngine.Content.DeleteAsset(path);
|
||||
}
|
||||
else if (item is ScriptItem)
|
||||
{
|
||||
FlaxEngine.Content.DeleteScript(path);
|
||||
}
|
||||
else if (deletedByUser)
|
||||
{
|
||||
// Delete file
|
||||
if (File.Exists(path))
|
||||
File.Delete(path);
|
||||
// Delete asset file only if it was explicitly deleted by the user.
|
||||
// Some applications might modify the file by deleting the original and replacing
|
||||
// it with a new file which sometimes is caught in the middle of these operations.
|
||||
if (deletedByUser)
|
||||
{
|
||||
// Check if it's an asset
|
||||
if (item.IsAsset)
|
||||
{
|
||||
// Delete asset by using content pool
|
||||
FlaxEngine.Content.DeleteAsset(path);
|
||||
}
|
||||
else if (item is ScriptItem)
|
||||
{
|
||||
FlaxEngine.Content.DeleteScript(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Delete file
|
||||
if (File.Exists(path))
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
|
||||
// Unlink from the parent
|
||||
|
||||
Reference in New Issue
Block a user