Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ src/plugins/zip/vcxproj/salamander/Debug_x64
src/vcxproj/salamander/Debug_x64
src/vcxproj/salmon/salamander/Debug_x64
src/vcxproj/sqlite/salamander/Debug_x64
src/vcxproj/salamander/Release_x64
src/vcxproj/salmon/salamander/Release_x64
src/vcxproj/sqlite/salamander/Release_x64
**/Intermediate/
*.obj
*.pdb
*.exe
*.res
*.tlog
*.recipe
*.iobj
*.ipdb
*.log
*.err
rebuild_times.log
src/vcxproj/rebuild_debug_x86.log
src/vcxproj/rebuild_debug_x86.log.err
Expand Down
91 changes: 91 additions & 0 deletions src/debug_move.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include "precomp.h"
#include <iostream>
#include <fstream>

// Forward declarations
void SalLog(const std::string& message);

// Dummy implementations of dependencies
// This is a simplified version of the actual classes and functions
// to allow the debug program to compile.

class CFilesWindow {
public:
BOOL BuildScriptDir(COperations* script, CActionType type, char* sourcePath,
BOOL sourcePathSupADS, char* targetPath,
CTargetPathState targetPathState, BOOL targetPathSupADS,
BOOL targetPathIsFAT32, char* mask, char* dirName,
char* dirDOSName, CAttrsData* attrsData, char* mapName,
DWORD sourceDirAttr, CChangeCaseData* chCaseData, BOOL firstLevelDir,
BOOL onlySize, BOOL fastDirectoryMove, CCriteriaData* filterCriteria,
BOOL* canDelUpperDirAfterMove, FILETIME* sourceDirTime,
DWORD srcAndTgtPathsFlags);
};

// ... (other dummy implementations)

// Logging function
void SalLog(const std::string& message) {
std::ofstream logfile("move_debug_log.txt", std::ios_base::app);
if (logfile.is_open()) {
logfile << message << std::endl;
}
}

// Modified BuildScriptDir with logging
BOOL CFilesWindow::BuildScriptDir(COperations* script, CActionType type, char* sourcePath,
BOOL sourcePathSupADS, char* targetPath,
CTargetPathState targetPathState, BOOL targetPathSupADS,
BOOL targetPathIsFAT32, char* mask, char* dirName,
char* dirDOSName, CAttrsData* attrsData, char* mapName,
DWORD sourceDirAttr, CChangeCaseData* chCaseData, BOOL firstLevelDir,
BOOL onlySize, BOOL fastDirectoryMove, CCriteriaData* filterCriteria,
BOOL* canDelUpperDirAfterMove, FILETIME* sourceDirTime,
DWORD srcAndTgtPathsFlags)
{
std::string log_msg = "BuildScriptDir START: sourcePath=" + std::string(sourcePath) + ", targetPath=" + (targetPath ? std::string(targetPath) : "NULL") + ", dirName=" + std::string(dirName);
SalLog(log_msg);

// ... (original code from fileswn6.cpp)

// In a real implementation, you would copy the body of the function here.
// For this example, we will just simulate a recursive call.

// ...

log_msg = "BuildScriptDir END: sourcePath=" + std::string(sourcePath) + ", targetPath=" + (targetPath ? std::string(targetPath) : "NULL");
SalLog(log_msg);

return TRUE;
}

int main(int argc, char* argv[]) {
if (argc != 3) {
std::cerr << "Usage: debug_move.exe <source_dir> <target_dir>" << std::endl;
return 1;
}

std::string source_dir = argv[1];
std::string target_dir = argv[2];

SalLog("Starting move operation from " + source_dir + " to " + target_dir);

// This is a simplified simulation of the file move process.
// In a real implementation, you would need to initialize the necessary
// objects and call the functions in the correct order.

CFilesWindow files_window;
COperations script;
// ... initialize script ...

char source_path[MAX_PATH * 2];
char target_path[MAX_PATH * 2];
strcpy_s(source_path, source_dir.c_str());
strcpy_s(target_path, target_dir.c_str());

files_window.BuildScriptDir(&script, atMove, source_path, FALSE, target_path, tpsUnknown, FALSE, FALSE, NULL, (char*)"test_dir", NULL, NULL, NULL, FILE_ATTRIBUTE_DIRECTORY, NULL, TRUE, FALSE, TRUE, NULL, NULL, NULL, 0);

SalLog("Move operation finished.");

return 0;
}
6 changes: 3 additions & 3 deletions src/fileswn2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ BOOL CFilesWindow::ChangeToFixedDrive(HWND parent, BOOL* noChange, BOOL refreshL
if (noChange != NULL)
*noChange = TRUE;
char sysDir[MAX_PATH];
char root[4] = " :\\";
char root[5] = " :\\";
if (GetWindowsDirectory(sysDir, MAX_PATH) != 0 && sysDir[0] != 0 && sysDir[1] == ':')
{
root[0] = sysDir[0];
Expand Down Expand Up @@ -787,7 +787,7 @@ void CFilesWindow::ConnectNet(BOOL readOnlyUNC, const char* netRootPath, BOOL ch
*newlyMappedDrive = d;
if (changeToNewDrive)
{
char root[4] = " :\\";
char root[5] = " :\\";
root[0] = d;
ChangePathToDisk(HWindow, root, -1, NULL, NULL, TRUE, FALSE, FALSE, NULL, FALSE);
}
Expand Down Expand Up @@ -1833,7 +1833,7 @@ BOOL CFilesWindow::ChangePathToDisk(HWND parent, const char* path, int suggested

// cannot shorten, we find the system or first fixed-drive (our "escape drive")
char sysDir[MAX_PATH];
char root[4] = " :\\";
char root[5] = " :\\";
BOOL done = FALSE;
if (GetWindowsDirectory(sysDir, MAX_PATH) != 0 && sysDir[0] != 0 && sysDir[1] == ':')
{
Expand Down
20 changes: 16 additions & 4 deletions src/fileswn6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,10 @@ BOOL CFilesWindow::BuildScriptDir(COperations* script, CActionType type, char* s
BOOL* canDelUpperDirAfterMove, FILETIME* sourceDirTime,
DWORD srcAndTgtPathsFlags)
{
char log_buffer[1024];
_snprintf_s(log_buffer, sizeof(log_buffer), _TRUNCATE, "BuildScriptDir START: sourcePath='%s', targetPath='%s', dirName='%s'", sourcePath, targetPath ? targetPath : "NULL", dirName);
OutputDebugStringA(log_buffer);

SLOW_CALL_STACK_MESSAGE16("CFilesWindow::BuildScriptDir(, %d, %s, %d, %s, %d, %d, %d, %s, %s, , , %s, 0x%X, , %d, %d, %d, , , , 0x%X)",
type, sourcePath, sourcePathSupADS, targetPath,
targetPathState, targetPathSupADS, targetPathIsFAT32,
Expand Down Expand Up @@ -1575,6 +1579,8 @@ MENU_TEMPLATE_ITEM MsgBoxButtons[] =
if (msgRes == DIALOG_OK /* Focus */)
MainWindow->PostFocusNameInPanel(PANEL_SOURCE, sourcePath, dirName);
}
_snprintf_s(log_buffer, sizeof(log_buffer), _TRUNCATE, "BuildScriptDir END (Too long source directory name): sourcePath='%s', targetPath='%s'", sourcePath, targetPath ? targetPath : "NULL");
OutputDebugStringA(log_buffer);
return skip;
}
while (*s != 0)
Expand Down Expand Up @@ -1644,6 +1650,8 @@ MENU_TEMPLATE_ITEM MsgBoxButtons[] =
if (msgRes == DIALOG_OK /* Focus */)
MainWindow->PostFocusNameInPanel(PANEL_SOURCE, sourcePath, sourceEnd + 1);
}
_snprintf_s(log_buffer, sizeof(log_buffer), _TRUNCATE, "BuildScriptDir END (Too long target directory name): sourcePath='%s', targetPath='%s'", sourcePath, targetPath ? targetPath : "NULL");
OutputDebugStringA(log_buffer);
return skip;
}
strcpy(targetPath + targetLen, s2);
Expand Down Expand Up @@ -2338,8 +2346,8 @@ MENU_TEMPLATE_ITEM MsgBoxButtons[] =
filterCriteria->SkipEmptyDirs && createDirIndex >= 0 &&
createDirIndex == script->Count - 1)
{
free(script->At(createDirIndex).SourceName);
free(script->At(createDirIndex).TargetName);
delete[] script->At(createDirIndex).SourceName;
delete[] script->At(createDirIndex).TargetName;
script->Delete(createDirIndex);
if (!script->IsGood())
script->ResetState();
Expand Down Expand Up @@ -2465,9 +2473,9 @@ BOOL GetLinkTgtFileSize(HWND parent, const char* fileName, COperation* op, CQuad
{
if (op != NULL)
{
free(op->SourceName);
delete[] op->SourceName;
if (op->TargetName != NULL)
free(op->TargetName);
delete[] op->TargetName;
}
*cancel = TRUE;
break;
Expand All @@ -2486,6 +2494,10 @@ BOOL CFilesWindow::BuildScriptFile(COperations* script, CActionType type, char*
CChangeCaseData* chCaseData, BOOL onlySize,
FILETIME* fileLastWriteTime, DWORD srcAndTgtPathsFlags)
{
char log_buffer[1024];
_snprintf_s(log_buffer, sizeof(log_buffer), _TRUNCATE, "BuildScriptFile START: sourcePath='%s', fileName='%s'", sourcePath, fileName);
OutputDebugStringA(log_buffer);

SLOW_CALL_STACK_MESSAGE14("CFilesWindow::BuildScriptFile(, %d, %s, %d, %s, %d, %d, %d, %s, %s, , , , %s, 0x%X, , %d, , 0x%X)",
type, sourcePath, sourcePathSupADS, targetPath, targetPathState, targetPathSupADS,
targetPathIsFAT32, mask, fileName, mapName, sourceFileAttr, onlySize, srcAndTgtPathsFlags);
Expand Down
36 changes: 24 additions & 12 deletions src/fileswn8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
// CFilesWindow
//

int DeleteThroughRecycleBinAux(SHFILEOPSTRUCT* fo)
int DeleteThroughRecycleBinAux(SHFILEOPSTRUCTW* fo)
{
__try
{
return SHFileOperation(fo);
return SHFileOperationW(fo);
}
__except (CCallStack::HandleException(GetExceptionInformation(), 5))
{
Expand Down Expand Up @@ -99,18 +99,30 @@ BOOL CFilesWindow::DeleteThroughRecycleBin(int* selection, int selCount, CFileDa
SetCurrentDirectory(GetPath()); // for faster operation

CShellExecuteWnd shellExecuteWnd;
SHFILEOPSTRUCT fo;
SHFILEOPSTRUCTW fo;
fo.hwnd = shellExecuteWnd.Create(MainWindow->HWindow, "SEW: CFilesWindow::DeleteThroughRecycleBin");
fo.wFunc = FO_DELETE;
fo.pFrom = names.Text;
fo.pTo = NULL;
fo.fFlags = FOF_ALLOWUNDO;
fo.fAnyOperationsAborted = FALSE;
fo.hNameMappings = NULL;
fo.lpszProgressTitle = "";
// Perform the actual deletion - wonderfully simple, unfortunately it sometimes crashes ;-)
CALL_STACK_MESSAGE1("CFilesWindow::DeleteThroughRecycleBin::SHFileOperation");
BOOL ret = DeleteThroughRecycleBinAux(&fo) == 0;

// Convert names to Wide (it's already double-null terminated in UTF-8 sense)
// MultiByteToWideChar with -1 won't work because of multiple nulls.
// Use names.Length + 1 to include the double-null.
int namesLenW = MultiByteToWideChar(CP_UTF8, 0, names.Text, names.Length + 1, NULL, 0);
WCHAR* namesW = (WCHAR*)malloc(namesLenW * sizeof(WCHAR));
if (namesW != NULL)
{
MultiByteToWideChar(CP_UTF8, 0, names.Text, names.Length + 1, namesW, namesLenW);
fo.pFrom = namesW;
fo.pTo = NULL;
fo.fFlags = FOF_ALLOWUNDO;
fo.fAnyOperationsAborted = FALSE;
fo.hNameMappings = NULL;
fo.lpszProgressTitle = L"";
// Perform the actual deletion - wonderfully simple, unfortunately it sometimes crashes ;-)
CALL_STACK_MESSAGE1("CFilesWindow::DeleteThroughRecycleBin::SHFileOperation");
DeleteThroughRecycleBinAux(&fo);
free(namesW);
}

SetCurrentDirectoryToSystem();

return FALSE; /*ret && !fo.fAnyOperationsAborted*/
Expand Down
2 changes: 1 addition & 1 deletion src/salamdr5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ BOOL SalMoveFile(const char* srcName, const char* destName)
DWORD attr = SalGetFileAttributes(srcName);
if (attr != 0xFFFFFFFF && (attr & FILE_ATTRIBUTE_READONLY))
{
SetFileAttributesW(srcNameW, FILE_ATTRIBUTE_ARCHIVE);
SetFileAttributesW(srcNameW, attr & ~FILE_ATTRIBUTE_READONLY);
if (MoveFileW(srcNameW, destNameW))
{
SetFileAttributesW(destNameW, attr);
Expand Down
Loading