void mirrorup( TCHAR* fromPath, TCHAR* toPath, bool reverseClean = false ) { if ( !reverseClean ) mirrorup( toPath, fromPath, true ); WIN32_FIND_DATA fromFindData, toFindData; TCHAR fromMask[ BUF_LEN ]; bool ok; _stprintf( fromMask, _T("%s\\*"), fromPath ); HANDLE fromFind = FindFirstFile( fromMask, &fromFindData ); if ( fromFind == INVALID_HANDLE_VALUE ) return; do { if ( !_tcscmp( fromFindData.cFileName, _T(".")) || !_tcscmp( fromFindData.cFileName, _T(".."))) continue; bool isDir = ( fromFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ); TCHAR fromFileName[ BUF_LEN ], toFileName[ BUF_LEN ]; _stprintf( fromFileName, _T("%s\\%s"), fromPath, fromFindData.cFileName ); _stprintf( toFileName, _T("%s\\%s"), toPath, fromFindData.cFileName ); HANDLE toFind = FindFirstFile( toFileName, &toFindData ); bool toFound = ( toFind != INVALID_HANDLE_VALUE ); if ( reverseClean ) { if ( isDir ) mirrorup( fromFileName, toFileName, reverseClean ); if ( !toFound ) { ok = unprotect( fromFileName ); if ( !isDir ) ok = ok && DeleteFile( fromFileName ); if ( ok ) okCount++; else errCount++; _tprintf( _T("%s) delete %s\n"), ( ok? _T("+") : _T("-")), fromFileName ); } } else { // not reverseClean if ( !toFound || !isDir && ( fromFindData.nFileSizeHigh != toFindData.nFileSizeHigh || fromFindData.nFileSizeLow != toFindData.nFileSizeLow || CompareFileTime( &fromFindData.ftLastWriteTime, &toFindData.ftLastWriteTime ))) { if ( toFound ) unprotect( toFileName ); if ( ok = ( isDir ? CreateDirectoryEx( fromFileName, toFileName, 0 ) : CopyFile( fromFileName, toFileName, 0 ))) okCount++; else errCount++; _tprintf( _T("%s) copy %s\n"), ( ok? _T("+") : _T("-")), fromFileName ); } if ( isDir ) mirrorup( fromFileName, toFileName, reverseClean ); } if ( toFound ) FindClose( toFind ); } while ( FindNextFile( fromFind, &fromFindData )); FindClose( fromFind ); }
int _tmain( int argc, TCHAR* argv[]) { _tsetlocale( LC_ALL, _T("")); if ( argc != 3 ) { _putts( _T("mirrorup, version 1.5 2008-01-17--2008-02-26 (c) Denis Ryzhkov\n") _T("http://denis.ryzhkov.org/?soft/mirrorup\n") _T("\n") _T("usage: mirrorup C:\\proj U:\\proj\n") _T("\n") _T("means: make a mirror backup of C:\\proj to U:\\proj\n") _T("i.e. copy or delete only files and folders\n") _T("that were changed after previous backup.\n") _T("file size and modification time are only compared.\n") _T("\n") _T("source code and batch script provided.")); return 0; } TCHAR* fromPath = unslash( argv[1]); TCHAR* toPath = unslash( argv[2]); TCHAR dateTimeStr[ BUF_LEN ]; _tprintf( _T("\n%s make a mirror backup of %s to %s\n\n"), timestamp( dateTimeStr ), fromPath, toPath ); #define attrErr 0xFFFFFFFF if ( GetFileAttributes( toPath ) == attrErr ) CreateDirectoryEx( fromPath, toPath, 0 ); if ( GetFileAttributes( toPath ) == attrErr ) { _putts( _T("bad path")); return 1; } mirrorup( fromPath, toPath ); _tprintf( _T("\n%s done ok: %d, errors: %d\n"), timestamp( dateTimeStr ), okCount, errCount ); return 0; }
//----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- std::string CVProjectUtil::WriteQc( const std::string &file, unsigned int qcFlags, const std::list< std::string > &qcStuff ) { // Get the pathname for the Qc file const std::string qc( Qc( file ) ); const std::string dir( DirName( qc ) ); if ( _access( qc.c_str(), 00 ) == 0 ) { merr << "Cannot overwrite destination qc: " << qc << std::endl; return ""; } CreateDirectoryEx( Prefix().c_str(), dir.c_str(), NULL ); std::ofstream os( qc.c_str() ); if ( !os ) { merr << "Couldn't write to qc: " << qc << std::endl; return ""; } if ( qcFlags & kQcYUp ) { os << "$upaxis Y\n\n"; } else if ( qcFlags & kQcZUp ) { os << "$upaxis Z\n\n"; } else if ( qcFlags & kQcXUp ) { os << "$upaxis X\n\n"; } if ( m_path.length() ) { os << "$cdmaterials " << Path() << "\n\n"; } if ( qcFlags & kQcCollapseBones ) { os << "$collapsebones\n\n"; } if ( qcFlags & kQcCenterBonesOnVerts ) { os << "$centerbonesonverts\n\n"; } if ( qcFlags & kQcSkipBoneInBBox ) { os << "$skipboneinbbox\n\n"; } std::copy( qcStuff.begin(), qcStuff.end(), std::ostream_iterator< std::string >( os, "\n" ) ); // TODO: Ask for relative names... os << "\n"; os << "$modelname " << ( m_path.empty() ? "" : m_path + "/" ) << File( file ) << ".mdl\n"; os << "\n"; os << "$model " << File( file ) << " \"" << File( file ) << ".smd\" {\n"; os << "}\n"; os << "\n"; os << "$sequence idle \"" << File( file ) << ".smd\"" << std::endl; os << "\n"; os.close(); return qc; }
UINT CFileDiffDlg::ExportThread() { RefreshCursor(); if (m_pProgDlg == NULL) return 1; long count = 0; SetAndClearProgressInfo(m_pProgDlg, false); m_pProgDlg->SetTitle(IDS_PROGRESSWAIT); m_pProgDlg->SetAnimation(AfxGetResourceHandle(), IDR_DOWNLOAD); m_pProgDlg->ShowModeless(this); for (INT_PTR i=0; (i<m_arSelectedFileList.GetCount())&&(!m_pProgDlg->HasUserCancelled()); ++i) { CFileDiffDlg::FileDiff fd = m_arSelectedFileList[i]; CTSVNPath url1 = CTSVNPath(m_path1.GetSVNPathString() + _T("/") + fd.path.GetSVNPathString()); CTSVNPath url2 = m_bDoPegDiff ? url1 : CTSVNPath(m_path2.GetSVNPathString() + _T("/") + fd.path.GetSVNPathString()); if ((fd.node == svn_node_dir)&&(fd.kind != svn_client_diff_summarize_kind_added)) { // just create the directory CreateDirectoryEx(NULL, m_strExportDir+_T("\\")+CPathUtils::PathUnescape(fd.path.GetWinPathString()), NULL); continue; } CString sTemp; m_pProgDlg->FormatPathLine(1, IDS_PROGRESSGETFILE, (LPCTSTR)url1.GetSVNPathString()); CTSVNPath savepath = CTSVNPath(m_strExportDir); savepath.AppendPathString(_T("\\") + CPathUtils::PathUnescape(fd.path.GetWinPathString())); CPathUtils::MakeSureDirectoryPathExists(fd.node == svn_node_file ? savepath.GetContainingDirectory().GetWinPath() : savepath.GetDirectory().GetWinPath()); if (fd.node == svn_node_dir) { // exporting a folder requires calling SVN::Export() so we also export all // children of that added folder. if ((fd.kind == svn_client_diff_summarize_kind_added)&&(!Export(url2, savepath, m_bDoPegDiff ? m_peg : m_rev2, m_rev2, true, true))) { if ((!m_bDoPegDiff)||(!Export(url2, savepath, m_rev2, m_rev2, true, true))) { delete m_pProgDlg; m_pProgDlg = NULL; CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR); InterlockedExchange(&m_bThreadRunning, FALSE); RefreshCursor(); return 1; } } } else { // exporting a file requires calling SVN::Cat(), since SVN::Export() only works // with folders. if ((fd.kind != svn_client_diff_summarize_kind_deleted)&&(!Cat(url2, m_bDoPegDiff ? m_peg : m_rev2, m_rev2, savepath))) { if ((!m_bDoPegDiff)||(!Cat(url2, m_rev2, m_rev2, savepath))) { delete m_pProgDlg; m_pProgDlg = NULL; CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR); InterlockedExchange(&m_bThreadRunning, FALSE); RefreshCursor(); return 1; } } } count++; m_pProgDlg->SetProgress (count, static_cast<DWORD>(m_arSelectedFileList.GetCount())); } m_pProgDlg->Stop(); SetAndClearProgressInfo(NULL, false); delete m_pProgDlg; m_pProgDlg = NULL; InterlockedExchange(&m_bThreadRunning, FALSE); RefreshCursor(); return 0; }
//----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- std::string CVProjectUtil::WriteVmt( const std::string &file, const std::string &shader, bool translucent ) { // Get the pathname for the VMT file const std::string vmt( Vmt( file ) ); const std::string dir( DirName( vmt ) ); if ( _access( vmt.c_str(), 00 ) == 0 ) { merr << "Cannot overwrite destination vmt: " << vmt << std::endl; return ""; } CreateDirectoryEx( Prefix().c_str(), dir.c_str(), NULL ); std::ofstream os( vmt.c_str() ); if ( !os ) { merr << "Couldn't write to vmt: " << vmt << std::endl; return ""; } // Shader os << "\""; if ( shader.size() ) { os << shader; } else { os << "VertexLitGeneric"; } os << "\"\n"; // Parameters os << "{\n"; // Base Texture os << "\t\"$basetexture\" \""; const std::string path( Path() ); if ( path.size() ) { os << path + "/"; } if ( file.size() ) { os << file; } else if ( m_file.size() ) { os << m_file; } else { os << "unknown"; } os << "\"\n"; // Translucent if ( translucent ) { os << "\t\"$translucent\" \"1\"\n"; } os << "}\n"; os.close(); return vmt; }