Skip to content

Commit

Permalink
Fixed copy_directory
Browse files Browse the repository at this point in the history
  • Loading branch information
MiranDMC committed Sep 29, 2024
1 parent 636901f commit 02c93bb
Showing 1 changed file with 10 additions and 53 deletions.
63 changes: 10 additions & 53 deletions cleo_plugins/FileSystemOperations/FileSystemOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,66 +610,23 @@ class FileSystemOperations
return OR_CONTINUE;
}

static BOOL CopyDir(const char *path, const char *newPath)
{
char mask[MAX_PATH];
HANDLE hSearch = NULL;
WIN32_FIND_DATA wfd;
char subPath[MAX_PATH], newSubPath[MAX_PATH];
DWORD fattr;

//create parent directory
if (!CreateDirectory(newPath, NULL))
return FALSE;

memset(&wfd, 0, sizeof(wfd));
//search mask
sprintf(mask, "%s\\*", path);

//copy all files and folders into new directory
if ((hSearch = FindFirstFile(mask, &wfd)) != INVALID_HANDLE_VALUE)
{
do
{
sprintf(subPath, "%s\\%s", path, wfd.cFileName);
sprintf(newSubPath, "%s\\%s", newPath, wfd.cFileName);
//copy subdirectories
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if ((strcmp(wfd.cFileName, "..") != 0) && (strcmp(wfd.cFileName, ".") != 0))
{
if (!CopyDir(subPath, newSubPath))
return FALSE;
}
}
else
{
//copy file into new directory
if (CopyFile(subPath, newSubPath, FALSE))
{
fattr = GetFileAttributes(subPath);
SetFileAttributes(newSubPath, fattr);
}
else return FALSE;
}


} while (FindNextFile(hSearch, &wfd));
FindClose(hSearch);
}

return TRUE;
}

// 0B05=2, copy_directory %1d% to %2d% //IF and SET
static OpcodeResult WINAPI Script_FS_CopyDir(CScriptThread* thread)
{
OPCODE_READ_PARAM_FILEPATH(filepath);
OPCODE_READ_PARAM_FILEPATH(newFilepath);

BOOL result = CopyDir(filepath, newFilepath);
auto path = FS::path(filepath);
if (!FS::is_directory(path))
{
OPCODE_CONDITION_RESULT(false);
return OR_CONTINUE;
}

std::error_code err;
FS::copy(filepath, newFilepath, FS::copy_options::update_existing | FS::copy_options::recursive, err);

OPCODE_CONDITION_RESULT(result);
OPCODE_CONDITION_RESULT(!err);
return OR_CONTINUE;
}

Expand Down

0 comments on commit 02c93bb

Please sign in to comment.