Skip to content

Commit

Permalink
[Fix] Engine error if copying a file to its own location
Browse files Browse the repository at this point in the history
  • Loading branch information
RhenaudTheLukark committed Feb 18, 2024
1 parent 4716480 commit d34b961
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Assets/Scripts/Lua/CLRBindings/LuaFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ public void Copy(string newPath, bool overwrite = false) {
string origNewPath = newPath;
FileLoader.SanitizePath(ref newPath, "", false, true, false);

if (!File.Exists(filePath)) throw new CYFException("The file at the path \"" + filePath + "\" doesn't exist, so you can't move it.");
if (!File.Exists(filePath)) throw new CYFException("The file at the path \"" + filePath + "\" doesn't exist, so you can't copy it.");
if (File.Exists(newPath) && !overwrite) throw new CYFException("The file at the path \"" + origNewPath + "\" already exists.");
if (newPath == filePath) throw new CYFException("Cannot copy a file to its own location!");

try { File.Copy(filePath, newPath, overwrite); }
catch (DirectoryNotFoundException) { throw new CYFException("File.Copy: Could not find part or all of the path:\n\"" + origNewPath + "\"\n\nMake sure the path specified is valid, and its total length (" + origNewPath.Length + " characters, " + newPath.Length + " after sanitization) is not too long."); }
Expand Down

0 comments on commit d34b961

Please sign in to comment.