Cyber-Drugs
asked on
Error on Compile
Hi guys,
I need some help please...
I have this function:
void CCustomModalDialog::Attach _Template( int argc, char **argv)
{
char TargetPath[500];
CFileOperation fo;
for (int i = 4; i < 6; i++)
{
int k = 0;
while (argv[i][k] != '\0')
{
if (argv[i][k] == '~')
argv[i][k] = ' ';
k++;
}
}
sprintf(TargetPath, "%s%s\\T\\%s\\%s.%s", ROOT, argv[1], argv[2], argv[3], argv[6]);
fo.Delete(TargetPath);
CopyFile(argv[4], TargetPath, true);
return 0;
}
and when I compile, I get these errors:
C:\Documents and Settings\Administrator\Des ktop\Brows er\CustomB rowser\Cus tomBrowser \CustomMod alDialog.c pp(163) : error C2039: 'Attach_Template' : is not a member of 'CCustomModalDialog'
c:\documents and settings\administrator\des ktop\brows er\customb rowser\cus tombrowser \custommod aldialog.h (16) : see declaration of 'CCustomModalDialog'
C:\Documents and Settings\Administrator\Des ktop\Brows er\CustomB rowser\Cus tomBrowser \CustomMod alDialog.c pp(167) : error C2065: 'CFileOperation' : undeclared identifier
C:\Documents and Settings\Administrator\Des ktop\Brows er\CustomB rowser\Cus tomBrowser \CustomMod alDialog.c pp(167) : error C2146: syntax error : missing ';' before identifier 'fo'
C:\Documents and Settings\Administrator\Des ktop\Brows er\CustomB rowser\Cus tomBrowser \CustomMod alDialog.c pp(167) : error C2065: 'fo' : undeclared identifier
C:\Documents and Settings\Administrator\Des ktop\Brows er\CustomB rowser\Cus tomBrowser \CustomMod alDialog.c pp(180) : error C2065: 'ROOT' : undeclared identifier
C:\Documents and Settings\Administrator\Des ktop\Brows er\CustomB rowser\Cus tomBrowser \CustomMod alDialog.c pp(181) : error C2228: left of '.Delete' must have class/struct/union type
C:\Documents and Settings\Administrator\Des ktop\Brows er\CustomB rowser\Cus tomBrowser \CustomMod alDialog.c pp(186) : error C2562: 'Attach_Template' : 'void' function returning a value
C:\Documents and Settings\Administrator\Des ktop\Brows er\CustomB rowser\Cus tomBrowser \CustomMod alDialog.c pp(163) : see declaration of 'Attach_Template'
Anybody able to help me out please?
Cheers!
I need some help please...
I have this function:
void CCustomModalDialog::Attach
{
char TargetPath[500];
CFileOperation fo;
for (int i = 4; i < 6; i++)
{
int k = 0;
while (argv[i][k] != '\0')
{
if (argv[i][k] == '~')
argv[i][k] = ' ';
k++;
}
}
sprintf(TargetPath, "%s%s\\T\\%s\\%s.%s", ROOT, argv[1], argv[2], argv[3], argv[6]);
fo.Delete(TargetPath);
CopyFile(argv[4], TargetPath, true);
return 0;
}
and when I compile, I get these errors:
C:\Documents and Settings\Administrator\Des
c:\documents and settings\administrator\des
C:\Documents and Settings\Administrator\Des
C:\Documents and Settings\Administrator\Des
C:\Documents and Settings\Administrator\Des
C:\Documents and Settings\Administrator\Des
C:\Documents and Settings\Administrator\Des
C:\Documents and Settings\Administrator\Des
C:\Documents and Settings\Administrator\Des
Anybody able to help me out please?
Cheers!
Please show code in CustomModalDialog.h file.
What is CFileOperation? You need to include h-file where this file is defined.
What is CFileOperation? You need to include h-file where this file is defined.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
AlexFM,
Changing 'return 0' to 'return' removed one erorr (down to 5 now)
I'm moving code form a bunch of small programs into one big program, so can I assume I need to find CFileOperation function inside the code of the the program I am taking source from?
Here is the header as requested:
//{{AFX_INCLUDES()
#include "webbrowser2.h"
//}}AFX_INCLUDES
#if !defined(AFX_CUSTOMMODALDI ALOG_H__C9 3107E0_EDD 1_4E10_B6B C_E3C6B4B9 9D2F__INCL UDED_)
#define AFX_CUSTOMMODALDIALOG_H__C 93107E0_ED D1_4E10_B6 BC_E3C6B4B 99D2F__INC LUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// CustomModalDialog.h : header file
//
////////////////////////// ////////// ////////// ////////// ////////// ////////// /
// CCustomModalDialog dialog
class CCustomModalDialog : public CDialog
{
// Construction
public:
CString cszURL;
HICON m_hIcon;
CCustomModalDialog(CWnd* pParent = NULL); // standard constructor
void ExecuteScriptFunction();
void Attach_Template(int argc, char **argv);
//void Create_CaseFolder(int argc, char **argv);
//void Confirm_EditDocument(int argc, char **argv);
// Dialog Data
//{{AFX_DATA(CCustomModalD ialog)
enum { IDD = IDD_MODAL_DIALOG };
CWebBrowser2 m_browser;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCustomMod alDialog)
protected:
virtual void DoDataExchange(CDataExchan ge* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CCustomModalDi alog)
virtual BOOL OnInitDialog();
afx_msg void OnSize(UINT nType, int cx, int cy);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_CUSTOMMODALDI ALOG_H__C9 3107E0_EDD 1_4E10_B6B C_E3C6B4B9 9D2F__INCL UDED_)
Changing 'return 0' to 'return' removed one erorr (down to 5 now)
I'm moving code form a bunch of small programs into one big program, so can I assume I need to find CFileOperation function inside the code of the the program I am taking source from?
Here is the header as requested:
//{{AFX_INCLUDES()
#include "webbrowser2.h"
//}}AFX_INCLUDES
#if !defined(AFX_CUSTOMMODALDI
#define AFX_CUSTOMMODALDIALOG_H__C
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// CustomModalDialog.h : header file
//
//////////////////////////
// CCustomModalDialog dialog
class CCustomModalDialog : public CDialog
{
// Construction
public:
CString cszURL;
HICON m_hIcon;
CCustomModalDialog(CWnd* pParent = NULL); // standard constructor
void ExecuteScriptFunction();
void Attach_Template(int argc, char **argv);
//void Create_CaseFolder(int argc, char **argv);
//void Confirm_EditDocument(int argc, char **argv);
// Dialog Data
//{{AFX_DATA(CCustomModalD
enum { IDD = IDD_MODAL_DIALOG };
CWebBrowser2 m_browser;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCustomMod
protected:
virtual void DoDataExchange(CDataExchan
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CCustomModalDi
virtual BOOL OnInitDialog();
afx_msg void OnSize(UINT nType, int cx, int cy);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_CUSTOMMODALDI
ASKER
I just found in one of the files of the code I am moving all the following, how do you think is the safest way of moving it over?
/** \file FileOperations.cpp
Project: FopDemo\n
Project type: MFC App\n
Author: Vinnichenko Alexey\n
E-mail: subj@mail.ru\n
Description: Implementation of CFileOperation class and CFileExeption class.
*/
#include "stdafx.h"
//#include "resource.h"
//#include "FileOperations.h"
//************************ ********** ********** ********** ********** ********** ********** ********** ********** ****
CFExeption::CFExeption(DWO RD dwErrCode)
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSA GE_ALLOCAT E_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSE RTS,
NULL, dwErrCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL);
m_sError = (LPTSTR)lpMsgBuf;
LocalFree(lpMsgBuf);
m_dwError = dwErrCode;
}
CFExeption::CFExeption(CSt ring sErrText)
{
m_sError = sErrText;
m_dwError = 0;
}
//************************ ********** ********** ********** ********** ********** ********** ********** ********** ****
CFileOperation::CFileOpera tion()
{
Initialize();
}
void CFileOperation::Initialize ()
{
m_sError = _T("No error");
m_dwError = 0;
m_bAskIfReadOnly = true;
m_bOverwriteMode = false;
m_bAborted = false;
m_iRecursionLimit = -1;
}
void CFileOperation::DoDelete(C String sPathName)
{
CFileFind ff;
CString sPath = sPathName;
if (CheckPath(sPath) == PATH_IS_FILE)
{
if (!CanDelete(sPath))
{
m_bAborted = true;
return;
}
if (!DeleteFile(sPath)) throw new CFExeption(GetLastError()) ;
return;
}
PreparePath(sPath);
sPath += "*.*";
BOOL bRes = ff.FindFile(sPath);
while(bRes)
{
bRes = ff.FindNextFile();
if (ff.IsDots()) continue;
if (ff.IsDirectory())
{
sPath = ff.GetFilePath();
DoDelete(sPath);
}
else DoDelete(ff.GetFilePath()) ;
}
ff.Close();
if (!RemoveDirectory(sPathNam e) && !m_bAborted) throw new CFExeption(GetLastError()) ;
}
void CFileOperation::DoFolderCo py(CString sSourceFolder, CString sDestFolder, bool bDelteAfterCopy)
{
CFileFind ff;
CString sPathSource = sSourceFolder;
BOOL bRes = ff.FindFile(sPathSource);
while (bRes)
{
bRes = ff.FindNextFile();
if (ff.IsDots()) continue;
if (ff.IsDirectory()) // source is a folder
{
if (m_iRecursionLimit == 0) continue;
sPathSource = ff.GetFilePath() + CString("\\") + CString("*.*");
CString sPathDest = sDestFolder + ff.GetFileName() + CString("\\");
if (CheckPath(sPathDest) == PATH_NOT_FOUND)
{
if (!CreateDirectory(sPathDes t, NULL))
{
ff.Close();
throw new CFExeption(GetLastError()) ;
}
}
if (m_iRecursionLimit > 0) m_iRecursionLimit --;
DoFolderCopy(sPathSource, sPathDest, bDelteAfterCopy);
}
else // source is a file
{
CString sNewFileName = sDestFolder + ff.GetFileName();
DoFileCopy(ff.GetFilePath( ), sNewFileName, bDelteAfterCopy);
}
}
ff.Close();
}
bool CFileOperation::Delete(CSt ring sPathName)
{
try
{
DoDelete(sPathName);
}
catch(CFExeption* e)
{
m_sError = e->GetErrorText();
m_dwError = e->GetErrorCode();
delete e;
if (m_dwError == 0) return true;
return false;
}
return true;
}
bool CFileOperation::Rename(CSt ring sSource, CString sDest)
{
try
{
DoRename(sSource, sDest);
}
catch(CFExeption* e)
{
m_sError = e->GetErrorText();
m_dwError = e->GetErrorCode();
delete e;
return false;
}
return true;
}
void CFileOperation::DoRename(C String sSource, CString sDest)
{
if (!MoveFile(sSource, sDest)) throw new CFExeption(GetLastError()) ;
}
void CFileOperation::DoCopy(CSt ring sSource, CString sDest, bool bDelteAfterCopy)
{
CheckSelfRecursion(sSource , sDest);
// source not found
if (CheckPath(sSource) == PATH_NOT_FOUND)
{
CString sError = sSource + CString(" not found");
throw new CFExeption(sError);
}
// dest not found
if (CheckPath(sDest) == PATH_NOT_FOUND)
{
CString sError = sDest + CString(" not found");
throw new CFExeption(sError);
}
// folder to file
if (CheckPath(sSource) == PATH_IS_FOLDER && CheckPath(sDest) == PATH_IS_FILE)
{
throw new CFExeption("Wrong operation");
}
// folder to folder
if (CheckPath(sSource) == PATH_IS_FOLDER && CheckPath(sDest) == PATH_IS_FOLDER)
{
CFileFind ff;
CString sError = sSource + CString(" not found");
PreparePath(sSource);
PreparePath(sDest);
sSource += "*.*";
if (!ff.FindFile(sSource))
{
ff.Close();
throw new CFExeption(sError);
}
if (!ff.FindNextFile())
{
ff.Close();
throw new CFExeption(sError);
}
CString sFolderName = ParseFolderName(sSource);
if (!sFolderName.IsEmpty()) // the source is not drive
{
sDest += sFolderName;
PreparePath(sDest);
if (!CreateDirectory(sDest, NULL))
{
DWORD dwErr = GetLastError();
if (dwErr != 183)
{
ff.Close();
throw new CFExeption(dwErr);
}
}
}
ff.Close();
DoFolderCopy(sSource, sDest, bDelteAfterCopy);
}
// file to file
if (CheckPath(sSource) == PATH_IS_FILE && CheckPath(sDest) == PATH_IS_FILE)
{
DoFileCopy(sSource, sDest);
}
// file to folder
if (CheckPath(sSource) == PATH_IS_FILE && CheckPath(sDest) == PATH_IS_FOLDER)
{
PreparePath(sDest);
char drive[MAX_PATH], dir[MAX_PATH], name[MAX_PATH], ext[MAX_PATH];
_splitpath(sSource, drive, dir, name, ext);
sDest = sDest + CString(name) + CString(ext);
DoFileCopy(sSource, sDest);
}
}
void CFileOperation::DoFileCopy (CString sSourceFile, CString sDestFile, bool bDelteAfterCopy)
{
BOOL bOvrwriteFails = FALSE;
if (!m_bOverwriteMode)
{
while (IsFileExist(sDestFile))
{
sDestFile = ChangeFileName(sDestFile);
}
bOvrwriteFails = TRUE;
}
if (!CopyFile(sSourceFile, sDestFile, bOvrwriteFails)) throw new CFExeption(GetLastError()) ;
if (bDelteAfterCopy)
{
DoDelete(sSourceFile);
}
}
bool CFileOperation::Copy(CStri ng sSource, CString sDest)
{
if (CheckSelfCopy(sSource, sDest)) return true;
bool bRes;
try
{
DoCopy(sSource, sDest);
bRes = true;
}
catch(CFExeption* e)
{
m_sError = e->GetErrorText();
m_dwError = e->GetErrorCode();
delete e;
if (m_dwError == 0) bRes = true;
bRes = false;
}
m_iRecursionLimit = -1;
return bRes;
}
bool CFileOperation::Replace(CS tring sSource, CString sDest)
{
if (CheckSelfCopy(sSource, sDest)) return true;
bool bRes;
try
{
bool b = m_bAskIfReadOnly;
m_bAskIfReadOnly = false;
DoCopy(sSource, sDest, true);
DoDelete(sSource);
m_bAskIfReadOnly = b;
bRes = true;
}
catch(CFExeption* e)
{
m_sError = e->GetErrorText();
m_dwError = e->GetErrorCode();
delete e;
if (m_dwError == 0) bRes = true;
bRes = false;
}
m_iRecursionLimit = -1;
return bRes;
}
CString CFileOperation::ChangeFile Name(CStri ng sFileName)
{
CString sName, sNewName, sResult;
char drive[MAX_PATH];
char dir [MAX_PATH];
char name [MAX_PATH];
char ext [MAX_PATH];
_splitpath((LPCTSTR)sFileN ame, drive, dir, name, ext);
sName = name;
int pos = sName.Find("Copy ");
if (pos == -1)
{
sNewName = CString("Copy of ") + sName + CString(ext);
}
else
{
int pos1 = sName.Find('(');
if (pos1 == -1)
{
sNewName = sName;
sNewName.Delete(0, 8);
sNewName = CString("Copy (1) of ") + sNewName + CString(ext);
}
else
{
CString sCount;
int pos2 = sName.Find(')');
if (pos2 == -1)
{
sNewName = CString("Copy of ") + sNewName + CString(ext);
}
else
{
sCount = sName.Mid(pos1 + 1, pos2 - pos1 - 1);
sName.Delete(0, pos2 + 5);
int iCount = atoi((LPCTSTR)sCount);
iCount ++;
sNewName.Format("%s%d%s%s% s", "Copy (", iCount, ") of ", (LPCTSTR)sName, ext);
}
}
}
sResult = CString(drive) + CString(dir) + sNewName;
return sResult;
}
bool CFileOperation::IsFileExis t(CString sPathName)
{
HANDLE hFile;
hFile = CreateFile(sPathName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
if (hFile == INVALID_HANDLE_VALUE) return false;
CloseHandle(hFile);
return true;
}
int CFileOperation::CheckPath( CString sPath)
{
DWORD dwAttr = GetFileAttributes(sPath);
if (dwAttr == 0xffffffff)
{
if (GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == ERROR_PATH_NOT_FOUND)
return PATH_NOT_FOUND;
return PATH_ERROR;
}
if (dwAttr & FILE_ATTRIBUTE_DIRECTORY) return PATH_IS_FOLDER;
return PATH_IS_FILE;
}
void CFileOperation::PreparePat h(CString &sPath)
{
if(sPath.Right(1) != "\\") sPath += "\\";
}
bool CFileOperation::CanDelete( CString sPathName)
{
DWORD dwAttr = GetFileAttributes(sPathNam e);
if (dwAttr == -1) return false;
if (dwAttr & FILE_ATTRIBUTE_READONLY)
{
if (m_bAskIfReadOnly)
{
CString sTmp = sPathName;
int pos = sTmp.ReverseFind('\\');
if (pos != -1) sTmp.Delete(0, pos + 1);
CString sText = sTmp + CString(" is read olny. Do you want delete it?");
int iRes = MessageBox(NULL, sText, _T("Warning"), MB_YESNOCANCEL | MB_ICONQUESTION);
switch (iRes)
{
case IDYES:
{
if (!SetFileAttributes(sPathN ame, FILE_ATTRIBUTE_NORMAL)) return false;
return true;
}
case IDNO:
{
return false;
}
case IDCANCEL:
{
m_bAborted = true;
throw new CFExeption(0);
return false;
}
}
}
else
{
if (!SetFileAttributes(sPathN ame, FILE_ATTRIBUTE_NORMAL)) return false;
return true;
}
}
return true;
}
CString CFileOperation::ParseFolde rName(CStr ing sPathName)
{
CString sFolderName = sPathName;
int pos = sFolderName.ReverseFind('\ \');
if (pos != -1) sFolderName.Delete(pos, sFolderName.GetLength() - pos);
pos = sFolderName.ReverseFind('\ \');
if (pos != -1) sFolderName = sFolderName.Right(sFolderN ame.GetLen gth() - pos - 1);
else sFolderName.Empty();
return sFolderName;
}
void CFileOperation::CheckSelfR ecursion(C String sSource, CString sDest)
{
if (sDest.Find(sSource) != -1)
{
int i = 0, count1 = 0, count2 = 0;
for(i = 0; i < sSource.GetLength(); i ++) if (sSource[i] == '\\') count1 ++;
for(i = 0; i < sDest.GetLength(); i ++) if (sDest[i] == '\\') count2 ++;
if (count2 >= count1) m_iRecursionLimit = count2 - count1;
}
}
bool CFileOperation::CheckSelfC opy(CStrin g sSource, CString sDest)
{
bool bRes = false;
if (CheckPath(sSource) == PATH_IS_FOLDER)
{
CString sTmp = sSource;
int pos = sTmp.ReverseFind('\\');
if (pos != -1)
{
sTmp.Delete(pos, sTmp.GetLength() - pos);
if (sTmp.CompareNoCase(sDest) == 0) bRes = true;
}
}
return bRes;
}
/** \file FileOperations.cpp
Project: FopDemo\n
Project type: MFC App\n
Author: Vinnichenko Alexey\n
E-mail: subj@mail.ru\n
Description: Implementation of CFileOperation class and CFileExeption class.
*/
#include "stdafx.h"
//#include "resource.h"
//#include "FileOperations.h"
//************************
CFExeption::CFExeption(DWO
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSA
NULL, dwErrCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL);
m_sError = (LPTSTR)lpMsgBuf;
LocalFree(lpMsgBuf);
m_dwError = dwErrCode;
}
CFExeption::CFExeption(CSt
{
m_sError = sErrText;
m_dwError = 0;
}
//************************
CFileOperation::CFileOpera
{
Initialize();
}
void CFileOperation::Initialize
{
m_sError = _T("No error");
m_dwError = 0;
m_bAskIfReadOnly = true;
m_bOverwriteMode = false;
m_bAborted = false;
m_iRecursionLimit = -1;
}
void CFileOperation::DoDelete(C
{
CFileFind ff;
CString sPath = sPathName;
if (CheckPath(sPath) == PATH_IS_FILE)
{
if (!CanDelete(sPath))
{
m_bAborted = true;
return;
}
if (!DeleteFile(sPath)) throw new CFExeption(GetLastError())
return;
}
PreparePath(sPath);
sPath += "*.*";
BOOL bRes = ff.FindFile(sPath);
while(bRes)
{
bRes = ff.FindNextFile();
if (ff.IsDots()) continue;
if (ff.IsDirectory())
{
sPath = ff.GetFilePath();
DoDelete(sPath);
}
else DoDelete(ff.GetFilePath())
}
ff.Close();
if (!RemoveDirectory(sPathNam
}
void CFileOperation::DoFolderCo
{
CFileFind ff;
CString sPathSource = sSourceFolder;
BOOL bRes = ff.FindFile(sPathSource);
while (bRes)
{
bRes = ff.FindNextFile();
if (ff.IsDots()) continue;
if (ff.IsDirectory()) // source is a folder
{
if (m_iRecursionLimit == 0) continue;
sPathSource = ff.GetFilePath() + CString("\\") + CString("*.*");
CString sPathDest = sDestFolder + ff.GetFileName() + CString("\\");
if (CheckPath(sPathDest) == PATH_NOT_FOUND)
{
if (!CreateDirectory(sPathDes
{
ff.Close();
throw new CFExeption(GetLastError())
}
}
if (m_iRecursionLimit > 0) m_iRecursionLimit --;
DoFolderCopy(sPathSource, sPathDest, bDelteAfterCopy);
}
else // source is a file
{
CString sNewFileName = sDestFolder + ff.GetFileName();
DoFileCopy(ff.GetFilePath(
}
}
ff.Close();
}
bool CFileOperation::Delete(CSt
{
try
{
DoDelete(sPathName);
}
catch(CFExeption* e)
{
m_sError = e->GetErrorText();
m_dwError = e->GetErrorCode();
delete e;
if (m_dwError == 0) return true;
return false;
}
return true;
}
bool CFileOperation::Rename(CSt
{
try
{
DoRename(sSource, sDest);
}
catch(CFExeption* e)
{
m_sError = e->GetErrorText();
m_dwError = e->GetErrorCode();
delete e;
return false;
}
return true;
}
void CFileOperation::DoRename(C
{
if (!MoveFile(sSource, sDest)) throw new CFExeption(GetLastError())
}
void CFileOperation::DoCopy(CSt
{
CheckSelfRecursion(sSource
// source not found
if (CheckPath(sSource) == PATH_NOT_FOUND)
{
CString sError = sSource + CString(" not found");
throw new CFExeption(sError);
}
// dest not found
if (CheckPath(sDest) == PATH_NOT_FOUND)
{
CString sError = sDest + CString(" not found");
throw new CFExeption(sError);
}
// folder to file
if (CheckPath(sSource) == PATH_IS_FOLDER && CheckPath(sDest) == PATH_IS_FILE)
{
throw new CFExeption("Wrong operation");
}
// folder to folder
if (CheckPath(sSource) == PATH_IS_FOLDER && CheckPath(sDest) == PATH_IS_FOLDER)
{
CFileFind ff;
CString sError = sSource + CString(" not found");
PreparePath(sSource);
PreparePath(sDest);
sSource += "*.*";
if (!ff.FindFile(sSource))
{
ff.Close();
throw new CFExeption(sError);
}
if (!ff.FindNextFile())
{
ff.Close();
throw new CFExeption(sError);
}
CString sFolderName = ParseFolderName(sSource);
if (!sFolderName.IsEmpty()) // the source is not drive
{
sDest += sFolderName;
PreparePath(sDest);
if (!CreateDirectory(sDest, NULL))
{
DWORD dwErr = GetLastError();
if (dwErr != 183)
{
ff.Close();
throw new CFExeption(dwErr);
}
}
}
ff.Close();
DoFolderCopy(sSource, sDest, bDelteAfterCopy);
}
// file to file
if (CheckPath(sSource) == PATH_IS_FILE && CheckPath(sDest) == PATH_IS_FILE)
{
DoFileCopy(sSource, sDest);
}
// file to folder
if (CheckPath(sSource) == PATH_IS_FILE && CheckPath(sDest) == PATH_IS_FOLDER)
{
PreparePath(sDest);
char drive[MAX_PATH], dir[MAX_PATH], name[MAX_PATH], ext[MAX_PATH];
_splitpath(sSource, drive, dir, name, ext);
sDest = sDest + CString(name) + CString(ext);
DoFileCopy(sSource, sDest);
}
}
void CFileOperation::DoFileCopy
{
BOOL bOvrwriteFails = FALSE;
if (!m_bOverwriteMode)
{
while (IsFileExist(sDestFile))
{
sDestFile = ChangeFileName(sDestFile);
}
bOvrwriteFails = TRUE;
}
if (!CopyFile(sSourceFile, sDestFile, bOvrwriteFails)) throw new CFExeption(GetLastError())
if (bDelteAfterCopy)
{
DoDelete(sSourceFile);
}
}
bool CFileOperation::Copy(CStri
{
if (CheckSelfCopy(sSource, sDest)) return true;
bool bRes;
try
{
DoCopy(sSource, sDest);
bRes = true;
}
catch(CFExeption* e)
{
m_sError = e->GetErrorText();
m_dwError = e->GetErrorCode();
delete e;
if (m_dwError == 0) bRes = true;
bRes = false;
}
m_iRecursionLimit = -1;
return bRes;
}
bool CFileOperation::Replace(CS
{
if (CheckSelfCopy(sSource, sDest)) return true;
bool bRes;
try
{
bool b = m_bAskIfReadOnly;
m_bAskIfReadOnly = false;
DoCopy(sSource, sDest, true);
DoDelete(sSource);
m_bAskIfReadOnly = b;
bRes = true;
}
catch(CFExeption* e)
{
m_sError = e->GetErrorText();
m_dwError = e->GetErrorCode();
delete e;
if (m_dwError == 0) bRes = true;
bRes = false;
}
m_iRecursionLimit = -1;
return bRes;
}
CString CFileOperation::ChangeFile
{
CString sName, sNewName, sResult;
char drive[MAX_PATH];
char dir [MAX_PATH];
char name [MAX_PATH];
char ext [MAX_PATH];
_splitpath((LPCTSTR)sFileN
sName = name;
int pos = sName.Find("Copy ");
if (pos == -1)
{
sNewName = CString("Copy of ") + sName + CString(ext);
}
else
{
int pos1 = sName.Find('(');
if (pos1 == -1)
{
sNewName = sName;
sNewName.Delete(0, 8);
sNewName = CString("Copy (1) of ") + sNewName + CString(ext);
}
else
{
CString sCount;
int pos2 = sName.Find(')');
if (pos2 == -1)
{
sNewName = CString("Copy of ") + sNewName + CString(ext);
}
else
{
sCount = sName.Mid(pos1 + 1, pos2 - pos1 - 1);
sName.Delete(0, pos2 + 5);
int iCount = atoi((LPCTSTR)sCount);
iCount ++;
sNewName.Format("%s%d%s%s%
}
}
}
sResult = CString(drive) + CString(dir) + sNewName;
return sResult;
}
bool CFileOperation::IsFileExis
{
HANDLE hFile;
hFile = CreateFile(sPathName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
if (hFile == INVALID_HANDLE_VALUE) return false;
CloseHandle(hFile);
return true;
}
int CFileOperation::CheckPath(
{
DWORD dwAttr = GetFileAttributes(sPath);
if (dwAttr == 0xffffffff)
{
if (GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == ERROR_PATH_NOT_FOUND)
return PATH_NOT_FOUND;
return PATH_ERROR;
}
if (dwAttr & FILE_ATTRIBUTE_DIRECTORY) return PATH_IS_FOLDER;
return PATH_IS_FILE;
}
void CFileOperation::PreparePat
{
if(sPath.Right(1) != "\\") sPath += "\\";
}
bool CFileOperation::CanDelete(
{
DWORD dwAttr = GetFileAttributes(sPathNam
if (dwAttr == -1) return false;
if (dwAttr & FILE_ATTRIBUTE_READONLY)
{
if (m_bAskIfReadOnly)
{
CString sTmp = sPathName;
int pos = sTmp.ReverseFind('\\');
if (pos != -1) sTmp.Delete(0, pos + 1);
CString sText = sTmp + CString(" is read olny. Do you want delete it?");
int iRes = MessageBox(NULL, sText, _T("Warning"), MB_YESNOCANCEL | MB_ICONQUESTION);
switch (iRes)
{
case IDYES:
{
if (!SetFileAttributes(sPathN
return true;
}
case IDNO:
{
return false;
}
case IDCANCEL:
{
m_bAborted = true;
throw new CFExeption(0);
return false;
}
}
}
else
{
if (!SetFileAttributes(sPathN
return true;
}
}
return true;
}
CString CFileOperation::ParseFolde
{
CString sFolderName = sPathName;
int pos = sFolderName.ReverseFind('\
if (pos != -1) sFolderName.Delete(pos, sFolderName.GetLength() - pos);
pos = sFolderName.ReverseFind('\
if (pos != -1) sFolderName = sFolderName.Right(sFolderN
else sFolderName.Empty();
return sFolderName;
}
void CFileOperation::CheckSelfR
{
if (sDest.Find(sSource) != -1)
{
int i = 0, count1 = 0, count2 = 0;
for(i = 0; i < sSource.GetLength(); i ++) if (sSource[i] == '\\') count1 ++;
for(i = 0; i < sDest.GetLength(); i ++) if (sDest[i] == '\\') count2 ++;
if (count2 >= count1) m_iRecursionLimit = count2 - count1;
}
}
bool CFileOperation::CheckSelfC
{
bool bRes = false;
if (CheckPath(sSource) == PATH_IS_FOLDER)
{
CString sTmp = sSource;
int pos = sTmp.ReverseFind('\\');
if (pos != -1)
{
sTmp.Delete(pos, sTmp.GetLength() - pos);
if (sTmp.CompareNoCase(sDest)
}
}
return bRes;
}
ASKER
Would it be easier if I maybe uploaded a copy of the project to ee-stuff.com - and you can then tell me what changes I need to make?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK, I have managed to break it down to one error:
C:\Documents and Settings\Administrator\Des ktop\Brows er\CustomB rowser\Cus tomBrowser \CustomMod alDialog.c pp(181) : error C2065: 'ROOT' : undeclared identifier
C:\Documents and Settings\Administrator\Des
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You were correct AlexFM, it was a #define.
It now compiles!
Thank you for the help. :)
It now compiles!
Thank you for the help. :)
ASKER
void Attach_Template(int argc, char **argv);
But I'm still getting these:
C:\Documents and Settings\Administrator\Des
C:\Documents and Settings\Administrator\Des
C:\Documents and Settings\Administrator\Des
C:\Documents and Settings\Administrator\Des
C:\Documents and Settings\Administrator\Des
C:\Documents and Settings\Administrator\Des
c:\documents and settings\administrator\des