mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 21:01:52 +00:00
advanced async copy of files
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace GlitchyEngine.Collections;
|
||||
|
||||
/*class IntrusiveLinkedList<T> : ICollection<T> where T : ILinkedListElement, var
|
||||
{
|
||||
private T _head;
|
||||
private T _tail;
|
||||
|
||||
private bool _ownsElements;
|
||||
|
||||
public void Add(T element)
|
||||
{
|
||||
element.List = this;
|
||||
if (_head == null)
|
||||
{
|
||||
_head = _tail = element;
|
||||
}
|
||||
else
|
||||
{
|
||||
//_tail.ListLink.Previous = this;
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public bool Contains(T item)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
public void CopyTo(Span<T> span)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public bool Remove(T item)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
class ListLink<T> where T : ILinkedListElement
|
||||
{
|
||||
public IntrusiveLinkedList<T> List { get; internal set; }
|
||||
public ListLink<T> Previous { get; internal set; }
|
||||
public ListLink<T> Next { get; internal set; }
|
||||
}
|
||||
|
||||
interface ILinkedListElement
|
||||
{
|
||||
}
|
||||
|
||||
[AttributeUsage(.Class | .Struct)]
|
||||
struct IntrusiveLinkedListAttribute : Attribute, IComptimeTypeApply
|
||||
{
|
||||
[Comptime]
|
||||
public void ApplyToType(Type type)
|
||||
{
|
||||
Compiler.EmitAddInterface(type, typeof(ILinkedListElement));
|
||||
|
||||
Compiler.EmitTypeBody(type, new $"""
|
||||
//ListLink<{type}> _listLink;
|
||||
public using ListLink<{type}> _listLink;
|
||||
public ListLink<{type}> ListLink => _listLink;
|
||||
""");
|
||||
}
|
||||
}
|
||||
|
||||
[IntrusiveLinkedList]
|
||||
class LLTest
|
||||
{
|
||||
}*/
|
||||
@@ -34,6 +34,7 @@ extension Path
|
||||
path.Remove(0, 1);
|
||||
}
|
||||
|
||||
|
||||
public static void Combine(String target, params StringView[] components)
|
||||
{
|
||||
for (var component in components)
|
||||
@@ -46,4 +47,32 @@ extension Path
|
||||
|
||||
target.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
|
||||
}
|
||||
|
||||
/**
|
||||
* If a file with the given path ([targetDirectory]/[wantedName][fileExtension]) already exists it will add a number at the end of the file name.
|
||||
* @param targetDirectory The directory in which the file will be put.
|
||||
* @param wantedFileName The wanted name of the file. If it already exists a number will be put behind it.
|
||||
* @param fileExtension The file extension. This should contain the dot.
|
||||
* @param outFreePath The string that will contain the resulting filepath. Note: This will be cleared before writing the file name.
|
||||
*/
|
||||
public static void FindFreePath(StringView targetDirectory, StringView wantedName, StringView fileExtension, String outFreePath)
|
||||
{
|
||||
int fileNumber = 0;
|
||||
|
||||
String currentFileName = scope $"{wantedName}{fileExtension}";
|
||||
while (true)
|
||||
{
|
||||
Path.Combine(outFreePath..Clear(), targetDirectory, currentFileName);
|
||||
|
||||
FileInfo targetInfo = scope FileInfo(outFreePath);
|
||||
|
||||
if (!targetInfo.Exists)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
fileNumber++;
|
||||
currentFileName..Clear().AppendF($"{wantedName} ({fileNumber}){fileExtension}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user