Exemple #1
0
void CopyDir(TDirectory *source) {
   //copy all objects and subdirs of directory source as a subdir of the current directory   
   source->ls();
   TDirectory *savdir = gDirectory;
   TDirectory *adir = savdir->mkdir(source->GetName());
   adir->cd();
   //loop on all entries of this directory
   TKey *key;
   TIter nextkey(source->GetListOfKeys());
   while ((key = (TKey*)nextkey())) {
      const char *classname = key->GetClassName();
      TClass *cl = gROOT->GetClass(classname);
      if (!cl) continue;
      if (cl->InheritsFrom(TDirectory::Class())) {
         source->cd(key->GetName());
         TDirectory *subdir = gDirectory;
         adir->cd();
         CopyDir(subdir);
         adir->cd();
      } else if (cl->InheritsFrom(TTree::Class())) {
         TTree *T = (TTree*)source->Get(key->GetName());
         adir->cd();
         TTree *newT = T->CloneTree(-1,"fast");
         newT->Write();
      } else {
         source->cd();
         TObject *obj = key->ReadObj();
         adir->cd();
         obj->Write();
         delete obj;
     }
  }
  adir->SaveSelf(kTRUE);
  savdir->cd();
}
// Create directory and copy contents (does not overwrite existing files)
void CopyDir(const std::string &source_path, const std::string &dest_path)
{
#ifndef _WIN32
	if (source_path == dest_path) return;
	if (!File::Exists(source_path)) return;
	if (!File::Exists(dest_path)) File::CreateFullPath(dest_path);

	struct dirent dirent, *result = NULL;
	DIR *dirp = opendir(source_path.c_str());
	if (!dirp) return;

	while (!readdir_r(dirp, &dirent, &result) && result)
	{
		const std::string virtualName(result->d_name);
		// check for "." and ".."
		if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
			((virtualName[0] == '.') && (virtualName[1] == '.') &&
			(virtualName[2] == '\0')))
			continue;

		std::string source, dest;
		source = source_path + virtualName;
		dest = dest_path + virtualName;
		if (IsDirectory(source))
		{
			source += '/';
			dest += '/';
			if (!File::Exists(dest)) File::CreateFullPath(dest);
			CopyDir(source, dest);
		}
		else if (!File::Exists(dest)) File::Copy(source, dest);
	}
	closedir(dirp);
#endif
}
Exemple #3
0
UINT __stdcall InstallBranding(MSIHANDLE hModule)
{
    UINT rc;
    logStringW(hModule, L"InstallBranding: Handling branding file ...");

    WCHAR wszPathMSI[_MAX_PATH];
    rc = VBoxGetProperty(hModule, L"SOURCEDIR", wszPathMSI, sizeof(wszPathMSI));
    if (rc == ERROR_SUCCESS)
    {
        WCHAR wszPathTargetDir[_MAX_PATH];
        rc = VBoxGetProperty(hModule, L"CustomActionData", wszPathTargetDir, sizeof(wszPathTargetDir));
        if (rc == ERROR_SUCCESS)
        {
            /** @todo Check for trailing slash after %s. */
            WCHAR wszPathDest[_MAX_PATH];
            swprintf_s(wszPathDest, RT_ELEMENTS(wszPathDest), L"%s", wszPathTargetDir);

            WCHAR wszPathSource[_MAX_PATH];
            swprintf_s(wszPathSource, RT_ELEMENTS(wszPathSource), L"%s.custom", wszPathMSI);
            rc = CopyDir(hModule, wszPathDest, wszPathSource);
            if (rc == ERROR_SUCCESS)
            {
                swprintf_s(wszPathDest, RT_ELEMENTS(wszPathDest), L"%scustom", wszPathTargetDir);
                swprintf_s(wszPathSource, RT_ELEMENTS(wszPathSource), L"%s.custom", wszPathTargetDir);
                rc = RenameDir(hModule, wszPathDest, wszPathSource);
            }
        }
    }

    logStringW(hModule, L"InstallBranding: Handling done. (rc=%u (ignored))", rc);
    return ERROR_SUCCESS; /* Do not fail here. */
}
Exemple #4
0
bool OperCFThread::MoveNode( FS* srcFs, FSPath& srcPath, FSNode* srcNode, FS* destFs, FSPath& destPath )
{

	if ( srcNode->st.IsLnk() )
	{
		int r = MoveFile( srcFs, srcPath, srcNode, destFs, destPath );

		if ( r < 0 ) { return false; }

		if ( r > 0 && !CopyLink( srcFs, srcPath, srcNode, destFs, destPath, true ) ) { return false; }
	}
	else if ( srcNode->st.IsDir() )
	{
		int r = MoveDir( srcFs, srcPath, srcNode, destFs, destPath );

		if ( r < 0 ) { return false; }

		if ( r > 0 && !CopyDir( srcFs, srcPath, srcNode, destFs, destPath, true ) ) { return false; }

	}
	else
	{
		int r = MoveFile( srcFs, srcPath, srcNode, destFs, destPath );

		if ( r < 0 ) { return false; }

		if ( r > 0 && !CopyFile( srcFs, srcPath, srcNode, destFs, destPath, true ) ) { return false; }
	}

	return true;
}
bool wxGxOpenFileGDB::Copy(const CPLString &szDestPath, ITrackCancel* const pTrackCancel)
{
    wxGISDataset* pDSet = GetDatasetFast();

    if (NULL != pDSet)
    {
        pDSet->Close();
        wsDELETE(pDSet);
    }

    if (pTrackCancel)
        pTrackCancel->PutMessage(wxString::Format(_("%s %s %s"), _("Copy"), GetCategory().c_str(), m_sName.c_str()), wxNOT_FOUND, enumGISMessageInfo);

    //CPLString szFullDestPath = CPLFormFilename(szDestPath, CPLGetFilename(m_sPath), NULL);
    CPLString szFullDestPath = CheckUniqPath(szDestPath, CPLGetFilename(m_sPath), true, " ");

    bool bRet = CopyDir(m_sPath, szFullDestPath, 777, pTrackCancel);
    if (!bRet)
    {
        const char* err = CPLGetLastErrorMsg();
        wxString sErr = wxString::Format(_("Operation '%s' failed! GDAL error: %s, %s '%s'"), _("Copy"), GetCategory().c_str(), wxString(err, wxConvUTF8).c_str(), wxString(m_sPath, wxConvUTF8).c_str());
        wxLogError(sErr);
        if (pTrackCancel)
            pTrackCancel->PutMessage(sErr, wxNOT_FOUND, enumGISMessageErr);
        return false;
    }

    return true;
}
Exemple #6
0
void MainWindow::sParse() {

    // On recupere le template de base
    QFile tpl(":/runWindow/Ressources/template.tpl");
    tpl.open(QIODevice::ReadOnly | QIODevice::Text);
    QTextStream fluxR(&tpl);
    QString tplContent = fluxR.readAll();
    QString content = editor->toPlainText();
    content.replace("\n", "<br />");

    ZCode code(content);
    content = code.encode();

    tplContent.replace("TITRE_NEWS", nTitle->text());
    tplContent.replace("CONTENU_NEWS", content);

    QDir dir = QDesktopServices::storageLocation(QDesktopServices::TempLocation);
    dir.mkdir(QString("~cache/"));
    QFile file(dir.absolutePath() + "/~cache/index.htm");
    if (file.open(QFile::WriteOnly)) {
        QTextStream out(&file);
        out << tplContent;
    } else {
        QMessageBox::information(this, "Erreur", "Impossible d'accéder en écriture au fichier :" + dir.absolutePath() + "/~cache/index.htm");
    }
    QDir tmp(dir.absolutePath() + "/~cache/css");
    if(!tmp.exists()) {
        CopyDir(getRessourcePath() + "znews/", dir.absolutePath() + "/~cache");
    }


    view->load(QUrl(dir.absolutePath() + "/~cache/index.htm"));
}
Exemple #7
0
bool Path::CopyDir(String srcFolder, String dstFolder)
{
	srcFolder = Absolute(srcFolder);

	// Remove trailing seperators
	dstFolder = Absolute(dstFolder);
	dstFolder.TrimBack(Path::sep);

	if(!CreateDir(dstFolder))
		return false;

	Vector<FileInfo> files = Files::ScanFiles(srcFolder);
	for(auto& file : files)
	{
		String commonPath = RemoveBase(file.fullPath, srcFolder);
		String dstPath = dstFolder + Path::sep + commonPath;
		if(file.type == FileType::Folder)
		{
			if(!CopyDir(file.fullPath, dstPath))
				return false;
		}
		else
		{
			if(!Copy(file.fullPath, dstPath))
				return false;
		}
	}
	return true;
}
Exemple #8
0
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copy directory
BOOL CopyDir(PCTSTR ptzSrc, PCTSTR ptzDst)
{
	WIN32_FIND_DATA fd;
	TCHAR tzDst[MAX_PATH];
	TCHAR tzSrc[MAX_PATH];
	TCHAR tzFind[MAX_PATH];
	UStrPrint(tzFind, TEXT("%s\\*"), ptzSrc);
	HANDLE hFind = FindFirstFile(tzFind, &fd);
	if (hFind != INVALID_HANDLE_VALUE)
	{
		do
		{
			if (fd.cFileName[0] != '.')
			{
				UStrPrint(tzDst, TEXT("%s\\%s"), ptzDst, fd.cFileName);
				UStrPrint(tzSrc, TEXT("%s\\%s"), ptzSrc, fd.cFileName);
				if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
				{
					CopyDir(tzSrc, tzDst);
				}
				else
				{
					UDirCreate(tzDst);
					CopyFile(tzSrc, tzDst, FALSE);
				}
			}
		}
		while (FindNextFile(hFind, &fd));
		FindClose(hFind);
	}
	UStrPrint(tzDst, TEXT("%s\\"), ptzDst);
	UDirCreate(tzDst);
	return TRUE;
}
Exemple #9
0
bool CopyDirWithFilebackupRename( wxString from, wxString to, bool overwrite )
{
    wxString sep = wxFileName::GetPathSeparator();

    // append a slash if there is not one (for easier parsing)
    // because who knows what people will pass to the function.
    if ( !to.EndsWith( sep ) ) {
            to += sep;
    }
    // for both dirs
    if ( !from.EndsWith( sep ) ) {
            from += sep;
    }

    // first make sure that the source dir exists
    if(!wxDir::Exists(from)) {
            wxLogError(from + _T(" does not exist.  Can not copy directory.") );
            return false;
    }

    if (!wxDirExists(to))
        wxMkdir(to);

    wxDir dir(from);
    wxString filename;
    bool bla = dir.GetFirst(&filename);

    if (bla){
        do {

            if (wxDirExists(from + filename) )
            {
                wxMkdir(to + filename);
                CopyDir(from + filename, to + filename, overwrite);
            }
            else{
                //if files exists move it to backup, this way we can use this func on windows to replace 'active' files
                if ( wxFileExists( to + filename ) ) {
                    //delete prev backup
                    if ( wxFileExists( to + filename + _T(".old") ) ) {
                        wxRemoveFile( to + filename + _T(".old")  );
                    }
                    //make backup
                    if ( !wxRenameFile( to + filename, to + filename + _T(".old") ) ) {
						wxLogError( _T("could not rename %s, copydir aborted"), (to + filename).c_str() );
                        return false;
                    }
                }
                //do the actual copy
                if ( !wxCopyFile(from + filename, to + filename, overwrite) ) {
					wxLogError( _T("could not copy %s to %s, copydir aborted"), (from + filename).c_str(), (to + filename).c_str() );
                    return false;
                }
            }
        }
        while (dir.GetNext(&filename) );
    }
    return true;
}
Exemple #10
0
// Create directory and copy contents (does not overwrite existing files)
void CopyDir(const std::string& source_path, const std::string& dest_path, bool destructive)
{
  if (source_path == dest_path)
    return;
  if (!Exists(source_path))
    return;
  if (!Exists(dest_path))
    File::CreateFullPath(dest_path);

#ifdef _WIN32
  WIN32_FIND_DATA ffd;
  HANDLE hFind = FindFirstFile(UTF8ToTStr(source_path + "\\*").c_str(), &ffd);

  if (hFind == INVALID_HANDLE_VALUE)
  {
    FindClose(hFind);
    return;
  }

  do
  {
    const std::string virtualName(TStrToUTF8(ffd.cFileName));
#else
  DIR* dirp = opendir(source_path.c_str());
  if (!dirp)
    return;

  while (dirent* result = readdir(dirp))
  {
    const std::string virtualName(result->d_name);
#endif
    // check for "." and ".."
    if (virtualName == "." || virtualName == "..")
      continue;

    std::string source = source_path + DIR_SEP + virtualName;
    std::string dest = dest_path + DIR_SEP + virtualName;
    if (IsDirectory(source))
    {
      if (!Exists(dest))
        File::CreateFullPath(dest + DIR_SEP);
      CopyDir(source, dest, destructive);
    }
    else if (!destructive && !Exists(dest))
    {
      Copy(source, dest);
    }
    else if (destructive)
    {
      Rename(source, dest);
    }
#ifdef _WIN32
  } while (FindNextFile(hFind, &ffd) != 0);
  FindClose(hFind);
#else
  }
  closedir(dirp);
#endif
}
Exemple #11
0
eOpcodeResult WINAPI Script_FS_CopyDir(CScript* script)
/****************************************************************
Opcode Format
0B05=2,copy_directory %1d% to %2d% //IF and SET
****************************************************************/
{
	script->Collect(2);
	script->UpdateCompareFlag(CopyDir(Params[0].cVar, Params[1].cVar));

	return OR_CONTINUE;
}
Exemple #12
0
bool OperCFThread::CopyNode(FS *srcFs, FSPath &srcPath, FSNode *srcNode, FS *destFs, FSPath &destPath, bool move)
{
	if (srcNode->st.IsLnk()) {
		 if (!CopyLink(srcFs, srcPath, srcNode, destFs, destPath, move)) return false; 
	} else
	if (srcNode->st.IsDir()) { 
		if (!CopyDir(srcFs, srcPath, srcNode, destFs, destPath, move)) return false; 
	} else {
		if (!CopyFile(srcFs, srcPath, srcNode, destFs, destPath, move)) return false;
	}
	return true;
}
Exemple #13
0
// Create directory and copy contents (does not overwrite existing files)
void CopyDir(const std::string &source_path, const std::string &dest_path)
{
    if (source_path == dest_path) return;
    if (!File::Exists(source_path)) return;
    if (!File::Exists(dest_path)) File::CreateFullPath(dest_path);

#ifdef _WIN32
    WIN32_FIND_DATA ffd;
    HANDLE hFind = FindFirstFile(UTF8ToTStr(source_path + "\\*").c_str(), &ffd);

    if (hFind == INVALID_HANDLE_VALUE)
    {
        FindClose(hFind);
        return;
    }

    do
    {
        const std::string virtualName(TStrToUTF8(ffd.cFileName));
#else
    struct dirent dirent, *result = NULL;
    DIR *dirp = opendir(source_path.c_str());
    if (!dirp) return;

    while (!readdir_r(dirp, &dirent, &result) && result)
    {
        const std::string virtualName(result->d_name);
#endif
        // check for "." and ".."
        if (virtualName == "." || virtualName == "..")
            continue;

        std::string source, dest;
        source = source_path + virtualName;
        dest = dest_path + virtualName;
        if (IsDirectory(source))
        {
            source += '/';
            dest += '/';
            if (!File::Exists(dest)) File::CreateFullPath(dest);
            CopyDir(source, dest);
        }
        else if (!File::Exists(dest)) File::Copy(source, dest);
#ifdef _WIN32
    }
    while (FindNextFile(hFind, &ffd) != 0);
    FindClose(hFind);
#else
    }
    closedir(dirp);
#endif
}
Exemple #14
0
BOOL PathManager::CopyDir(CString strSrcPath, CString strDstPath)
{ // 创建目标文件夹
	if (strSrcPath.Right(1) == "\\")
	{
		strSrcPath = strSrcPath.Left(strSrcPath.GetLength() - 1);
	}
	if (strDstPath.Right(1) == "\\")
	{
		strDstPath = strDstPath.Left(strDstPath.GetLength() - 1);
	}
	CreateDirectory(strDstPath,NULL);
	CFileFind finder;
	// 打开指定的文件夹进行搜索
	BOOL bWorking = finder.FindFile(strSrcPath + "\\" + "*.*"); 
	while(bWorking) 
	{
		// 从当前目录搜索文件
		bWorking = finder.FindNextFile();
		CString strFileName = finder.GetFileName(); 
		CString strSrc = strSrcPath + "\\" + strFileName;
		CString strDst = strDstPath + "\\" + strFileName;
		// 判断搜索到的是不是"."和".."目录

		if(!finder.IsDots())

		{

			// 判断搜索到的目录是否是文件夹

			if(finder.IsDirectory())

			{

				// 如果是文件夹的话,进行递归

				if(!CopyDir(strSrc, strDst)) 
				{
					return false;
				}
			}
			else
			{
				// 如果是文件,进行复制
				if(!CopyFile(strSrc, strDst, FALSE))
				{
					return false;
				} 
			} 
		}
	}       
	return true;
} 
Exemple #15
0
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 success
	return TRUE;
}
Exemple #16
0
void CopyFile(const char *fname) {
   //Copy all objects and subdirs of file fname as a subdir of the current directory
   TDirectory *target = gDirectory;
   TFile *f = TFile::Open(fname);
   if (!f || f->IsZombie()) {
      printf("Cannot copy file: %s\n",fname);
      target->cd();
      return;
   }
   target->cd();
   CopyDir(f);
   delete f;
   target->cd();
}  
Exemple #17
0
bool CodeLiteApp::CopySettings(const wxString& destDir, wxString& installPath)
{
    wxLogNull noLog;

    ///////////////////////////////////////////////////////////////////////////////////////////
    // copy new settings from the global installation location which is currently located at
    // /usr/local/share/codelite/ (Linux) or at codelite.app/Contents/SharedSupport
    ///////////////////////////////////////////////////////////////////////////////////////////
    CopyDir(installPath + wxT("/templates/"), destDir + wxT("/templates/"));
    massCopy(installPath + wxT("/images/"), wxT("*.png"), destDir + wxT("/images/"));
    // wxCopyFile(installPath + wxT("/rc/menu.xrc"), destDir + wxT("/rc/menu.xrc"));
    wxCopyFile(installPath + wxT("/index.html"), destDir + wxT("/index.html"));
    wxCopyFile(installPath + wxT("/svnreport.html"), destDir + wxT("/svnreport.html"));
    wxCopyFile(installPath + wxT("/astyle.sample"), destDir + wxT("/astyle.sample"));
    return true;
}
    int _stdcall COPYDIRC( char* pSrcPath, int nSrcChar, char* pDesPath, int nDesChar )
    {
        char strSrc[MAXPATH];
        char strDes[MAXPATH];
        if( nSrcChar>=MAXPATH || nDesChar>=MAXPATH ) {
            return -1;
        }

        memcpy(strSrc, pSrcPath, nSrcChar*sizeof(char));
        memcpy(strDes, pDesPath, nDesChar*sizeof(char));

        strSrc[nSrcChar] = '\0';
        strDes[nDesChar] = '\0';

        return CopyDir( strSrc, strDes );
    }
Exemple #19
0
    void CopyDir(const boost::filesystem::path& src, const boost::filesystem::path& dest)
    {
        namespace bfs = boost::filesystem;

        bfs::create_directory(dest);
        
        for(bfs::directory_iterator file(src); file != bfs::directory_iterator(); ++file) {
            const bfs::path current(file->path());
            if(bfs::is_directory(current))
                CopyDir(current, dest / current.filename());
            else
                bfs::copy_file(
                    current, dest / current.filename(),
                    bfs::copy_option::overwrite_if_exists
                );
        }
    }
Exemple #20
0
// copied from http://wxforum.shadonet.com/viewtopic.php?t=2080
//slightly modified
bool CopyDir( wxString from, wxString to, bool overwrite )
{
    wxString sep = wxFileName::GetPathSeparator();

    // append a slash if there is not one (for easier parsing)
    // because who knows what people will pass to the function.
    if ( !to.EndsWith( sep ) ) {
            to += sep;
    }
    // for both dirs
    if ( !from.EndsWith( sep ) ) {
            from += sep;
    }

    // first make sure that the source dir exists
    if(!wxDir::Exists(from)) {
            wxLogError(from + _T(" does not exist.  Can not copy directory.") );
            return false;
    }

    if (!wxDirExists(to))
        wxMkdir(to);

    wxDir dir(from);
    wxString filename;
    bool bla = dir.GetFirst(&filename);

    if (bla){
        do {

            if (wxDirExists(from + filename) )
            {
                wxMkdir(to + filename);
                CopyDir(from + filename, to + filename, overwrite);
            }
            else{
                wxCopyFile(from + filename, to + filename, overwrite);
            }
        }
        while (dir.GetNext(&filename) );
    }
    return true;
}
Exemple #21
0
bool OperCFThread::CopyNode( FS* srcFs, FSPath& srcPath, FSNode* srcNode, FS* destFs, FSPath& destPath, bool move )
{
	// XXX blame, blame. In tmp panel name has full path. Strip the path from the last item
	stripPathFromLastItem(destPath);

	if ( srcNode->st.IsLnk() )
	{
		if ( !CopyLink( srcFs, srcPath, srcNode, destFs, destPath, move ) ) { return false; }
	}
	else if ( srcNode->st.IsDir() )
	{
		if ( !CopyDir( srcFs, srcPath, srcNode, destFs, destPath, move ) ) { return false; }
	}
	else
	{
		if ( !CopyFile( srcFs, srcPath, srcNode, destFs, destPath, move ) ) { return false; }
	}

	return true;
}
Exemple #22
0
    void InstallFiles()
    {
        namespace bfs = boost::filesystem;
        boost::system::error_code e;
        const bfs::path source = bfs::canonical(
            config::GetArg("-install", "webui"), e
        );

        const bfs::path destination = GetWebuiDataDir();

        if(e || !bfs::is_directory(source))
            throw std::runtime_error("Given directory is invalid or does not exist");

        // TODO: check that destination is not in source

        try {
            CopyDir(source, destination);
        } catch(...) {
            throw std::runtime_error("Could not copy webui folder to i2pd folder.");
        }
    }
Exemple #23
0
// Create directory and copy contents (does not overwrite existing files)
void CopyDir(const std::string &source_path, const std::string &dest_path)
{
#ifndef _WIN32
	if (source_path == dest_path) return;
	if (!File::Exists(source_path)) return;
	if (!File::Exists(dest_path)) File::CreateFullPath(dest_path);

	struct dirent_large { struct dirent entry; char padding[FILENAME_MAX+1]; };
	struct dirent_large diren;
	struct dirent *result = NULL;
	DIR *dirp = opendir(source_path.c_str());
	if (!dirp) return;

	while (!readdir_r(dirp, (dirent*) &diren, &result) && result)
	{
		const std::string virtualName(result->d_name);
		// check for "." and ".."
		if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
			((virtualName[0] == '.') && (virtualName[1] == '.') &&
			(virtualName[2] == '\0')))
			continue;

		std::string source, dest;
		source = source_path + virtualName;
		dest = dest_path + virtualName;
		if (IsDirectory(source))
		{
			source += '/';
			dest += '/';
			if (!File::Exists(dest)) File::CreateFullPath(dest);
			CopyDir(source, dest);
		}
		else if (!File::Exists(dest)) File::Copy(source, dest);
	}
	closedir(dirp);
#else
	ERROR_LOG(COMMON, "CopyDir not supported on this platform");
#endif
}
bool NativeFileSystem::CopyDir(const gd::String & source, const gd::String & destination)
{
    wxString sFrom = source.ToWxString();
    wxString sTo = destination.ToWxString();

    //As seen on https://forums.wxwidgets.org/viewtopic.php?t=2080
    if (sFrom[sFrom.Len() - 1] != '\\' && sFrom[sFrom.Len() - 1] != '/') sFrom += wxFILE_SEP_PATH;
    if (sTo[sTo.Len() - 1] != '\\' && sTo[sTo.Len() - 1] != '/') sTo += wxFILE_SEP_PATH;

    if (!::wxDirExists(sFrom)) {
        return false;
    }
    if (!wxDirExists(sTo)) {
        if (!wxFileName::Mkdir(sTo, 0777, wxPATH_MKDIR_FULL)) {
            return false;
        }
    }

    wxDir fDir(sFrom);
    wxString sNext = wxEmptyString;
    bool bIsFile = fDir.GetFirst(&sNext);
    while (bIsFile) {
        const wxString sFileFrom = sFrom + sNext;
        const wxString sFileTo = sTo + sNext;
        if (::wxDirExists(sFileFrom)) {
            CopyDir(sFileFrom, sFileTo);
        }
        else {
            if (!::wxFileExists(sFileTo)) {
                if (!::wxCopyFile(sFileFrom, sFileTo)) {
                    return false;
                }
            }
        }
        bIsFile = fDir.GetNext(&sNext);
    }
    return true;
}
Exemple #25
0
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// FILE or directory operation
HRESULT FILe(PTSTR ptzCmd, UINT uLen = -1)
{
	SHFILEOPSTRUCT so = {0};
	so.pFrom = ptzCmd;
	so.wFunc = FO_DELETE;
	so.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_SILENT;

	BOOL bAppend;
	PTSTR p = ptzCmd;
	for (; *p; p++)
	{
		switch (*p)
		{
		case ';':
			*p = 0;
			break;

		case '\\':
			if (!p[1])
			{
				return !UDirCreate(ptzCmd);
			}
			break;

		case '>':
			if (p[-1] == '=')
			{
				p[-1] = 0;
				so.pTo = p + 1;
				so.wFunc = FO_COPY;
			}
			else if (p[-1] == '-')
			{
				p[-1] = 0;
				so.pTo = p + 1;
				so.wFunc = FO_MOVE;
			}
			*p = 0;
			break;

		case '<':
			*p++ = 0;
			bAppend = (*p++ == '=');
			uLen = ((uLen == -1) ? UStrLen(p) : (uLen - (UINT) (p - ptzCmd)));
#ifdef _UNICODE
			CHAR szFile[MAX_STR];
			uLen = WideCharToMultiByte(CP_ACP, 0, p, uLen, szFile, sizeof(szFile), NULL, NULL);
			p = (PTSTR) szFile;
#endif
			return !UFileSave(ptzCmd, p, uLen, bAppend);

		case '{':
			*p++ = 0;
			bAppend = (*p++ == '=');
			uLen = ((uLen == -1) ? UStrLen(p) : (uLen - (UINT) (p - ptzCmd)));
#ifndef _UNICODE
			WCHAR wzFile[MAX_STR];
			uLen = MultiByteToWideChar(CP_ACP, 0, p, uLen, wzFile, _NumOf(wzFile));
			p = (PTSTR) wzFile;
#endif
			return !UFileSave(ptzCmd, p, uLen * sizeof(WCHAR), bAppend);
		}
	}

#ifdef _COPY
	if ((so.wFunc == FO_COPY) && UDirExist(so.pFrom))
	{
		return !CopyDir(so.pFrom, so.pTo);
	}
#endif

	TCHAR t = p[1];
	p[1] = 0;
	HRESULT hResult = SHFileOperation(&so);
	p[1] = t;
	return hResult;
}
BOOL CFileUtil::CopyDir(const char*szSource, const char*szDest)
{
	WIN32_FIND_DATA		sFindData;
	CChars				szFindName;
	CChars				szSourceTemp;
	CChars				szDestTemp;
	HANDLE				hFindHandle;
	BOOL				bContinue;
	BOOL				bValid;
	CChars				szSourceDirectory;
	CChars				szDestDirectory;

	szSourceDirectory.Init(szSource);
	RemoveFileSeparator(&szSourceDirectory);
	szDestDirectory.Init(szDest);
	RemoveFileSeparator(&szDestDirectory);

	szFindName.Init(szSource);
	AppendToPath(&szFindName, "*.*");

	hFindHandle = FindFirstFile(szFindName.Text(), &sFindData);
	bContinue = (hFindHandle != INVALID_HANDLE_VALUE);
	while (bContinue)
	{
		bValid = TRUE;
		if (sFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
		{
			if (!((strcmp(sFindData.cFileName, ".") == 0) || (strcmp(sFindData.cFileName, "..") == 0)))
			{
				szSourceTemp.Init(szSourceDirectory);
				szDestTemp.Init(szDestDirectory);

				AppendToPath(&szSourceTemp, sFindData.cFileName);
				AppendToPath(&szDestTemp, sFindData.cFileName);
				
				MakeDir(szDestTemp.Text());
				CopyDir(szSourceTemp.Text(), szDestTemp.Text());

				szSourceTemp.Kill();
				szDestTemp.Kill();
			}
		}
		else
		{
			szSourceTemp.Init(szSourceDirectory);
			szDestTemp.Init(szDestDirectory);

			AppendToPath(&szSourceTemp, sFindData.cFileName);
			AppendToPath(&szDestTemp, sFindData.cFileName);

			Copy(szSourceTemp.Text(), szDestTemp.Text());
			
			szSourceTemp.Kill();
			szDestTemp.Kill();
		}
		bContinue = FindNextFile(hFindHandle, &sFindData);
	}
	FindClose(hFindHandle);

	szSourceDirectory.Kill();
	szDestDirectory.Kill();
	szFindName.Kill();
	return TRUE;
}
//! DO NOT use mw() global unless fromCli is false !
bool UpdaterClass::UpdateLocale( const wxString& tempdir, bool /*unused*/ ) {
    wxString target = wxPathOnly( wxStandardPaths::Get().GetExecutablePath() ) + wxFileName::GetPathSeparator() + _T("locale");
    wxString origin = tempdir + _T("locale") + wxFileName::GetPathSeparator() ;
    return CopyDir( origin, target );
}
Exemple #28
0
void CopySubdir(const char * oldfile, const char * newfile){

  TDirectory *dirtracking; bool ok_tracking=false;
  TDirectory *dirsimhit; bool ok_simhit=false;
  TDirectory *dirrechits; bool ok_rechits=false;
  TDirectory *dirdigis; bool ok_digis=false;
  TDirectory *dirTP; bool ok_TP=false;
  TDirectory *dirtrackingrechits; bool ok_trackingrechits=false;

  TFile *oldf = TFile::Open(oldfile);
  if (oldf->cd("DQMData/Run 1/Tracking")) {
    oldf->cd("DQMData/Run 1/Tracking");
    dirtracking=gDirectory;
    ok_tracking=true;
  }
  if (oldf->cd("DQMData/Run 1/TrackerHitsV")) {
    oldf->cd("DQMData/Run 1/TrackerHitsV");
    dirsimhit=gDirectory;
    ok_simhit=true;
  }
  if (oldf->cd("DQMData/Run 1/TrackerRecHitsV")) {
    oldf->cd("DQMData/Run 1/TrackerRecHitsV");
    dirrechits=gDirectory;
    ok_rechits=true;
  }
  if (oldf->cd("DQMData/Run 1/TrackerDigisV")) {
    oldf->cd("DQMData/Run 1/TrackerDigisV");
    dirdigis=gDirectory;
    ok_digis=true;
  }
  if (oldf->cd("DQMData/Run 1/TrackingMCTruthV")) {
    oldf->cd("DQMData/Run 1/TrackingMCTruthV");
    dirTP=gDirectory;
    ok_TP=true;
  }
  if (oldf->cd("DQMData/Run 1/RecoTrackV")) {
    oldf->cd("DQMData/Run 1/RecoTrackV");
    dirtrackingrechits=gDirectory;
    ok_trackingrechits=true;
  }

  TFile *newf =new TFile(newfile,"RECREATE");
  TDirectory *dirnew=newf->mkdir("DQMData");
  dirnew=dirnew->mkdir("Run 1");
  dirnew->cd();
  if (ok_tracking) CopyDir(dirtracking);
  if (ok_simhit) CopyDir(dirsimhit);
  if (ok_rechits) CopyDir(dirrechits);
  if (ok_digis) CopyDir(dirdigis);
  if (ok_TP) CopyDir(dirTP);
  if (ok_trackingrechits) CopyDir(dirtrackingrechits);
  TList* new_list = oldf->GetListOfKeys() ;
  newf->cd();
  TIter     newkey_iter( new_list) ;
  TKey*     new_key ;
  TObject*  new_obj ;
  while ( new_key = (TKey*) newkey_iter() ) {
    new_obj = new_key->ReadObj() ;
    if (strcmp(new_obj->IsA()->GetName(),"TObjString")==0) {
      TObjString * cversion = (TObjString*) new_obj;
      if(cversion->GetString().Contains("CMSSW")){
	cversion->Write();
	break;
      }
    }
  }
}
Exemple #29
0
static int
CopyObject(char *sourceP, char *targetP, int repl, int link)
/* copy a directory, file, or symbolic link */
{
  struct stat src_stat;
  int rc;

  if (progressCallback)
    if (progressCallback(sourceP) != 0)
      return -1;

  if (periodicCallback)
    if (periodicCallback() != 0)
      return -1;

  if (lstat(sourceP, &src_stat) < 0)
    rc = errno;

  else {

copy_switch:

    switch(src_stat.st_mode & S_IFMT) {

      case S_IFDIR:
        rc = CopyDir(sourceP, targetP, repl, link, &src_stat);
        break;

      case S_IFREG:
        rc = CopyFile(sourceP, targetP, repl, &src_stat);
        break;

      case S_IFLNK:
        if (link)
          rc = CopyLink(sourceP, targetP, repl, &src_stat);
        else if (stat(sourceP, &src_stat) < 0)
          rc = errno;
        else
          goto copy_switch;
        break;

      default:
        rc = EINVAL;
    }
  }

  /*
   * Return code zero means everything is ok;
   * return code -1 means the operation is aborted.
   * In either case, propagated the return code up.
   */
  if (rc <= 0)
    return rc;

  /*
   * Return code > 0 means an error occurred in the last operation.
   * Call the the error callback function.  If the callback returns
   * zero, we return zero; this will cause the error to be ignored.
   * Otherwise we return -1 to signal that the operation is aborted.
   */
  if (!errorCallback)
    return rc;
  else if (errorCallback(sourceP, rc) == 0)
    return 0;
  else
    return -1;
}