Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/michaelsakharov/Prowl
Browse files Browse the repository at this point in the history
…into development
  • Loading branch information
sinnwrig committed Sep 16, 2024
2 parents 91b52fd + 10ba281 commit 5f32a67
Show file tree
Hide file tree
Showing 241 changed files with 38,424 additions and 38,725 deletions.
3 changes: 2 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ dotnet_naming_style.camel_case_underscore_style.required_prefix = _
dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case

# Code style defaults
csharp_using_directive_placement = outside_namespace:suggestion
csharp_style_namespace_declarations = file_scoped:warning
csharp_using_directive_placement = outside_namespace:error
dotnet_sort_system_directives_first = true
csharp_prefer_braces = true:silent
csharp_preserve_single_line_blocks = true:none
Expand Down
829 changes: 414 additions & 415 deletions Prowl.Editor/Assets/AssetDatabase.Core.cs

Large diffs are not rendered by default.

260 changes: 129 additions & 131 deletions Prowl.Editor/Assets/AssetDatabase.FileOperations.cs
Original file line number Diff line number Diff line change
@@ -1,163 +1,161 @@
// This file is part of the Prowl Game Engine
// Licensed under the MIT License. See the LICENSE file in the project root for details.

namespace Prowl.Editor.Assets
namespace Prowl.Editor.Assets;

public static partial class AssetDatabase
{
public static partial class AssetDatabase
{

#region Public Methods
#region Public Methods

/// <summary>
/// Moves a file to a new location.
/// </summary>
/// <param name="source">The source file.</param>
/// <param name="destination">The destination file.</param>
/// <returns>True if the file was moved successfully, false otherwise.</returns>
public static bool Move(FileInfo source, string destination)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(destination);
/// <summary>
/// Moves a file to a new location.
/// </summary>
/// <param name="source">The source file.</param>
/// <param name="destination">The destination file.</param>
/// <returns>True if the file was moved successfully, false otherwise.</returns>
public static bool Move(FileInfo source, string destination)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(destination);

// Check if source and destination are the same directory
if (source.FullName.Equals(destination, StringComparison.OrdinalIgnoreCase))
return false;
// Check if source and destination are the same directory
if (source.FullName.Equals(destination, StringComparison.OrdinalIgnoreCase))
return false;

// Source does not exist
if (!File.Exists(source.FullName)) return false;
// Source does not exist
if (!File.Exists(source.FullName)) return false;

// Destination already exists
if (File.Exists(destination)) return false;
// Destination already exists
if (File.Exists(destination)) return false;

if (source.Extension.Equals(".meta", StringComparison.OrdinalIgnoreCase))
return false;
if (source.Extension.Equals(".meta", StringComparison.OrdinalIgnoreCase))
return false;

// Move Asset file & meta file if it exists
var metaFile = new FileInfo(source.FullName + ".meta");
if (File.Exists(metaFile.FullName))
metaFile.MoveTo(destination + ".meta", true);
source.MoveTo(destination, true);
Update();
return true;
}
// Move Asset file & meta file if it exists
var metaFile = new FileInfo(source.FullName + ".meta");
if (File.Exists(metaFile.FullName))
metaFile.MoveTo(destination + ".meta", true);
source.MoveTo(destination, true);
Update();
return true;
}

/// <summary>
/// Moves a folder to a new location.
/// </summary>
/// <param name="source">The source folder.</param>
/// <param name="destination">The destination folder.</param>
/// <returns>True if the folder was moved successfully, false otherwise.</returns>
public static bool Move(DirectoryInfo source, string destination)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(destination);
/// <summary>
/// Moves a folder to a new location.
/// </summary>
/// <param name="source">The source folder.</param>
/// <param name="destination">The destination folder.</param>
/// <returns>True if the folder was moved successfully, false otherwise.</returns>
public static bool Move(DirectoryInfo source, string destination)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(destination);

// Check if source and destination are the same directory
if (source.FullName.Equals(destination, StringComparison.OrdinalIgnoreCase))
return false;
// Check if source and destination are the same directory
if (source.FullName.Equals(destination, StringComparison.OrdinalIgnoreCase))
return false;

// Source does not exist
if (!Directory.Exists(source.FullName)) return false;
// Source does not exist
if (!Directory.Exists(source.FullName)) return false;

// Destination already exists
if (Directory.Exists(destination)) return false;
// Destination already exists
if (Directory.Exists(destination)) return false;

// Move folder
source.MoveTo(destination);
Update();
return true;
}
// Move folder
source.MoveTo(destination);
Update();
return true;
}

/// <summary>
/// Renames a file.
/// </summary>
/// <param name="file">The file to rename.</param>
/// <param name="newName">The new name of the file.</param>
/// <returns>True if the file was renamed successfully, false otherwise.</returns>
public static bool Rename(FileInfo file, string newName)
{
ArgumentNullException.ThrowIfNull(file);
ArgumentException.ThrowIfNullOrEmpty(newName);
if (!File.Exists(file.FullName)) return false;

if (file.Extension.Equals(".meta", StringComparison.OrdinalIgnoreCase)) return false;

var newFile = new FileInfo(Path.Combine(file.DirectoryName!, newName + file.Extension));
if (File.Exists(newFile.FullName)) return false; // Destination already exists

// Rename Asset file & meta file if it exists
var metaFile = new FileInfo(file.FullName + ".meta");
if (File.Exists(metaFile.FullName))
{
var newMetaFile = new FileInfo(newFile.FullName + ".meta");
metaFile.MoveTo(newMetaFile.FullName, true);
}
file.MoveTo(newFile.FullName, true);
Update();
return true;
}
/// <summary>
/// Renames a file.
/// </summary>
/// <param name="file">The file to rename.</param>
/// <param name="newName">The new name of the file.</param>
/// <returns>True if the file was renamed successfully, false otherwise.</returns>
public static bool Rename(FileInfo file, string newName)
{
ArgumentNullException.ThrowIfNull(file);
ArgumentException.ThrowIfNullOrEmpty(newName);
if (!File.Exists(file.FullName)) return false;

/// <summary>
/// Renames a folder.
/// </summary>
/// <param name="folder">The folder to rename.</param>
/// <param name="newName">The new name of the folder.</param>
/// <returns>True if the folder was renamed successfully, false otherwise.</returns>
public static bool Rename(DirectoryInfo source, string newName)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentException.ThrowIfNullOrEmpty(newName);
if (!Directory.Exists(source.FullName)) return false;
if (file.Extension.Equals(".meta", StringComparison.OrdinalIgnoreCase)) return false;

var newFile = new FileInfo(Path.Combine(source.Parent!.FullName, newName));
if (Directory.Exists(newFile.FullName)) return false; // Destination already exists
var newFile = new FileInfo(Path.Combine(file.DirectoryName!, newName + file.Extension));
if (File.Exists(newFile.FullName)) return false; // Destination already exists

// Rename Asset file & meta file if it exists
source.MoveTo(newFile.FullName);
Update();
return true;
// Rename Asset file & meta file if it exists
var metaFile = new FileInfo(file.FullName + ".meta");
if (File.Exists(metaFile.FullName))
{
var newMetaFile = new FileInfo(newFile.FullName + ".meta");
metaFile.MoveTo(newMetaFile.FullName, true);
}
file.MoveTo(newFile.FullName, true);
Update();
return true;
}

/// <summary>
/// Deletes a file.
/// </summary>
/// <param name="file">The file to delete.</param>
/// <returns>True if the file was deleted successfully, false otherwise.</returns>
public static bool Delete(FileInfo file)
{
ArgumentNullException.ThrowIfNull(file);
/// <summary>
/// Renames a folder.
/// </summary>
/// <param name="folder">The folder to rename.</param>
/// <param name="newName">The new name of the folder.</param>
/// <returns>True if the folder was renamed successfully, false otherwise.</returns>
public static bool Rename(DirectoryInfo source, string newName)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentException.ThrowIfNullOrEmpty(newName);
if (!Directory.Exists(source.FullName)) return false;

if (file.Extension.Equals(".meta", StringComparison.OrdinalIgnoreCase)) return false;
var newFile = new FileInfo(Path.Combine(source.Parent!.FullName, newName));
if (Directory.Exists(newFile.FullName)) return false; // Destination already exists

// Just deleting the files should be enough for the AssetDatabase to pick it up
var metaFile = new FileInfo(file.FullName + ".meta");
if (File.Exists(metaFile.FullName))
metaFile.Delete();
if (File.Exists(file.FullName))
file.Delete();
// Rename Asset file & meta file if it exists
source.MoveTo(newFile.FullName);
Update();
return true;
}

Update();
return true;
}
/// <summary>
/// Deletes a file.
/// </summary>
/// <param name="file">The file to delete.</param>
/// <returns>True if the file was deleted successfully, false otherwise.</returns>
public static bool Delete(FileInfo file)
{
ArgumentNullException.ThrowIfNull(file);

/// <summary>
/// Deletes a folder.
/// </summary>
/// <param name="folder">The folder to delete.</param>
/// <returns>True if the folder was deleted successfully, false otherwise.</returns>
public static bool Delete(DirectoryInfo source)
{
ArgumentNullException.ThrowIfNull(source);
if (file.Extension.Equals(".meta", StringComparison.OrdinalIgnoreCase)) return false;

// Just deleting the files should be enough for the AssetDatabase to pick it up
if (Directory.Exists(source.FullName))
source.Delete();
Update();
return true;
}
// Just deleting the files should be enough for the AssetDatabase to pick it up
var metaFile = new FileInfo(file.FullName + ".meta");
if (File.Exists(metaFile.FullName))
metaFile.Delete();
if (File.Exists(file.FullName))
file.Delete();

Update();
return true;
}

#endregion
/// <summary>
/// Deletes a folder.
/// </summary>
/// <param name="folder">The folder to delete.</param>
/// <returns>True if the folder was deleted successfully, false otherwise.</returns>
public static bool Delete(DirectoryInfo source)
{
ArgumentNullException.ThrowIfNull(source);

// Just deleting the files should be enough for the AssetDatabase to pick it up
if (Directory.Exists(source.FullName))
source.Delete();
Update();
return true;
}

#endregion

}
Loading

0 comments on commit 5f32a67

Please sign in to comment.