Skip to content

Commit f3d67a7

Browse files
author
Evan Comtesse
committed
fix: generalized file overriding on copy-dropping in drop zones
1 parent 9998c74 commit f3d67a7

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

src/RayGUI.cs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -212,29 +212,26 @@ internal static DropZone ImportFiles(DropZone c)
212212
string fileName = pathArryBySlash.Last();
213213

214214
// Copy file to output directory of the container
215-
if (!c.Contains(c.OutputFilePath + "\\" +fileName))
215+
if (c.Extensions.Contains(pathArray.Last()) || c.Extensions.Length == 0)
216216
{
217-
if (c.Extensions.Contains(pathArray.Last()) || c.Extensions.Length == 0)
217+
try
218218
{
219-
try
220-
{
221-
File.Copy(path, c.OutputFilePath + "\\" + fileName, true);
222-
c.AddFile(c.OutputFilePath + "\\" + fileName);
223-
// Add file path to the container
224-
Debugger.Send($"File {fileName} received successfully", ConsoleColor.Green);
225-
}
226-
catch
227-
{
228-
Debugger.Send($"File could not be received, either wrong destination ({c.OutputFilePath}) or unsuitable source file ({path}))", ConsoleColor.Yellow);
229-
}
219+
File.Copy(path, c.OutputFilePath + "\\" + fileName, true);
220+
c.AddFile(c.OutputFilePath + "\\" + fileName);
221+
// Add file path to the container
222+
Debugger.Send($"File {fileName} received successfully", ConsoleColor.Green);
230223
}
231-
else
232-
{
233-
string err = "File could not be received, required extension(s):";
234-
for (int i = 0; i < c.Extensions.Length; i++) err += $" .{c.Extensions[i]}";
235-
Debugger.Send(err, ConsoleColor.Yellow);
224+
catch
225+
{
226+
Debugger.Send($"File could not be received, either wrong destination ({c.OutputFilePath}) or unsuitable source file ({path}))", ConsoleColor.Yellow);
236227
}
237228
}
229+
else
230+
{
231+
string err = "File could not be received, required extension(s):";
232+
for (int i = 0; i < c.Extensions.Length; i++) err += $" .{c.Extensions[i]}";
233+
Debugger.Send(err, ConsoleColor.Yellow);
234+
}
238235
UnloadDroppedFiles(filePathList);
239236

240237
// Return modified container

src/code/components/DropZone.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
/// <summary>Container component of the library.</summary>
44
public class DropZone : Component
55
{
6+
private readonly List<string> Files;
7+
68
/// <summary>The abosulte file path for the output directory.</summary>
79
public string OutputFilePath;
810

@@ -12,8 +14,8 @@ public class DropZone : Component
1214
/// <summary>Last dropped file.</summary>
1315
public string LastFile;
1416

15-
/// <summary>Paths of the container's files.</summary>
16-
private readonly List<string> Files;
17+
/// <summary>Returns the number of files contained inside of the output directory.</summary>
18+
public int FileCount { get { return Files.Count; } }
1719

1820
/// <summary>Initializes a new instance of <see cref="Container"/>.</summary>
1921
/// <param name="x">X Position of the container</param>
@@ -23,8 +25,8 @@ public class DropZone : Component
2325
public DropZone(int x, int y, int width, int height) : base(x, y, width, height)
2426
{
2527
Extensions = []; // Accept any file by default
26-
Files = new List<string>() { "" };
2728
OutputFilePath = Directory.GetCurrentDirectory(); // Working directory by default
29+
Files = [..Directory.GetFiles(OutputFilePath)]; // Retrieve already present files
2830
LastFile = "";
2931
}
3032

0 commit comments

Comments
 (0)