Basic project creation

+ Added TreeNode.RemoveChild
+ Added Directory.Copy
+ Path.Combine now replaces alt directory separator
+ Project: Renamed ProjectName to Name
+ Project.Load: Save settings, if file doesn't exist
This commit is contained in:
Simon Lübeß
2023-07-31 16:35:12 +02:00
parent 17e4a6a589
commit 0d015b485e
15 changed files with 803 additions and 41 deletions
@@ -1,4 +1,5 @@
using System.Collections;
using System;
namespace GlitchyEngine.Collections
{
@@ -37,6 +38,11 @@ namespace GlitchyEngine.Collections
return newChild;
}
public bool RemoveChild(TreeNode<T> value)
{
return Children.Remove(value);
}
public Self FindNode(T value)
{
if (Value == value)
@@ -10,4 +10,53 @@ extension Directory
// TODO: This is obviously windows only
return PathIsDirectoryEmptyW(fileName.ToScopedNativeWChar!());
}
public static Result<void, Platform.BfpFileResult> Copy(StringView fromPath, StringView toPath)
{
if (fromPath.Length <= 2)
return .Err(.InvalidParameter);
if ((fromPath[0] != '/') && (fromPath[0] != '\\'))
{
if (fromPath[1] == ':')
{
if (fromPath.Length < 3)
return .Err(.InvalidParameter);
}
}
if (!Directory.Exists(fromPath))
return .Err(.NotFound);
Try!(Directory.CreateDirectory(toPath));
for (var directoryEntry in Directory.EnumerateDirectories(fromPath))
{
let dirFromPath = scope String();
directoryEntry.GetFilePath(dirFromPath);
let dirName = scope String();
directoryEntry.GetFileName(dirName);
let dirToPath = scope String();
Path.Combine(dirToPath, toPath, dirName);
Try!(Copy(dirFromPath, dirToPath));
}
for (var fileEntry in Directory.EnumerateFiles(fromPath))
{
let fileFromPath = scope String();
fileEntry.GetFilePath(fileFromPath);
let fileName = scope String();
fileEntry.GetFileName(fileName);
let fileToPath = scope String();
Path.Combine(fileToPath, toPath, fileName);
Try!(File.Copy(fileFromPath, fileToPath));
}
return .Ok;
}
}
@@ -43,5 +43,7 @@ extension Path
target.Append(Path.DirectorySeparatorChar);
target.Append(component);
}
target.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
}
}