void CDialogProcess::CalFpjBySingleModel() { CLineComputeView* pView = (CLineComputeView*)((CMainFrame *)AfxGetMainWnd())->GetActiveView(); if(PathFileExists(pView->m_data->m_workspace + _T("\\single"))) DeleteFolder(pView->m_data->m_workspace + _T("\\single")); if(PathFileExists(pView->m_data->m_workspace + _T("\\sp"))) DeleteFolder(pView->m_data->m_workspace + _T("\\sp")); pView->m_data->CopyFilesToWorkspace(_T("mac\\single_main.mac"), pView->m_data->m_workspace + _T("\\single\\single_main.mac"));//将基本的mac文件拷贝到工作目录 pView->m_data->outputParamsToMac(pView->m_data->m_workspace + _T("\\single\\single_input.mac"));//输出参数 CString exeName = pView->m_data->m_ansysPath; exeName += _T(" -dir ") + pView->m_data->m_workspace + _T("\\single\\ -b -p ane3fl -i ") + pView->m_data->m_workspace + _T("\\single\\single_main.mac -o ") + pView->m_data->m_workspace + _T("\\single\\single.out"); STARTUPINFO si = {sizeof(si)}; PROCESS_INFORMATION pi; si.dwFlags = STARTF_USESHOWWINDOW; si.wShowWindow = TRUE; //TRUE表示显示创建的进程的窗口 BOOL bRet = ::CreateProcess(NULL, (LPWSTR)(LPCTSTR)exeName, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi); int error = GetLastError(); CString str; if(bRet) { ::CloseHandle(pi.hThread); ::CloseHandle(pi.hProcess); //CMenu* pMenu = this->GetSystemMenu(FALSE); //pMenu->EnableMenuItem(SC_CLOSE, MF_DISABLED); processOk = false; DetectSingleProcess(); } else { str.Format(_T("调用ANSYS出错,请检查ANSYS路径是否正确!code:%d"), error); MessageBox(str, MsgCaption); } }
Void DeleteFolder(LPWSTR lpPath, LPWIN32_FIND_DATAW pWfd) { LPWSTR lpEnd; HANDLE hFind; if (GetFileAttributesW(lpPath) == -1) return; lpEnd = lpPath + lstrlenW(lpPath); lstrcpyW(lpEnd, L"\\*.*"); hFind = FindFirstFileW(lpPath, pWfd); if (hFind != INVALID_HANDLE_VALUE) { do { if (IsParentDirectory(pWfd->cFileName)) continue; lstrcpyW(lpEnd + 1, pWfd->cFileName); if (pWfd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { DeleteFolder(lpPath, pWfd); } else { _DeleteFile(lpPath); } } while (FindNextFileW(hFind, pWfd)); FindClose(hFind); } *lpEnd = 0; }
void ForceInline main2(int argc, WChar **argv) { LPWSTR lpFileName; WCHAR szPath[MAX_PATH]; HANDLE hFind; WIN32_FIND_DATAW wfd; // setlocale(LC_CTYPE, ""); for (int i = 1; i != argc; ++i) { hFind = FindFirstFileW(argv[i], &wfd); if (hFind == INVALID_HANDLE_VALUE) continue; lstrcpyW(szPath, argv[i]); lpFileName = findnamew(szPath); do { if (IsParentDirectory(wfd.cFileName)) continue; lstrcpyW(lpFileName, wfd.cFileName); if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) DeleteFolder(szPath, &wfd); else _DeleteFile(szPath); } while (FindNextFileW(hFind, &wfd)); FindClose(hFind); } }
//删除一个目录 bool TraverseFolder::DeleteFolder(LPCSTR path) { WIN32_FIND_DATA findData; HANDLE hSearch; char FilePathName[MAX_PATH]; char FullPathName[MAX_PATH]; strcpy(FilePathName,path); strcat(FilePathName,"\\*.*"); hSearch = FindFirstFile(FilePathName,&findData); if( hSearch == INVALID_HANDLE_VALUE) { //std::cout<<"cann't search file\n"; return false; } while(::FindNextFile(hSearch,&findData)) { if( strcmp(findData.cFileName,".")==0 || strcmp(findData.cFileName,"..")==0) { continue; } sprintf(FullPathName,"%s//%s",path,findData.cFileName); if( findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { DeleteFolder(FullPathName); RemoveDirectory(FullPathName); } DeleteFile(FullPathName); } ::FindClose(hSearch); ::RemoveDirectory(path); return true; }
/** * @brief Delete folder and recursively removes its contents. * @param pszFolder - folder name. * @return true if operation was completed successfully. */ BOOL DeleteFolder(PCTSTR pszFolder) { TCHAR szFindFileTemplate[MAX_PATH]; PathCombine(szFindFileTemplate, pszFolder, _T("*")); WIN32_FIND_DATA FindData; HANDLE hFindFile = FindFirstFile(szFindFileTemplate, &FindData); if (hFindFile != INVALID_HANDLE_VALUE) { BOOL bMore = TRUE; while (bMore) { TCHAR szFileName[MAX_PATH]; if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if (_tcscmp(FindData.cFileName, _T(".")) != 0 && _tcscmp(FindData.cFileName, _T("..")) != 0) { PathCombine(szFileName, pszFolder, FindData.cFileName); if (! DeleteFolder(szFileName)) break; } } else { PathCombine(szFileName, pszFolder, FindData.cFileName); if (! DeleteFile(szFileName)) break; } bMore = FindNextFile(hFindFile, &FindData); } FindClose(hFindFile); } return RemoveDirectory(pszFolder); }
void DeleteFolder(CString dir) { if(FileIsDirectory(dir)) { //SHFILEOPSTRUCT Op; //ZeroMemory(&Op, sizeof(Op)); //删除文件夹 //Op.hwnd = NULL; //Op.wFunc = FO_DELETE; //Op.pFrom = dir; //Op.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION; //SHFileOperation(&Op); CFindFile tempFind; CString tempFileFind; tempFileFind.Format(_T("%s\\*.*"),dir); BOOL IsFinded = tempFind.FindFile(tempFileFind); while (IsFinded) { IsFinded = tempFind.FindNextFile(); if(!tempFind.IsDots()) { if(tempFind.IsDirectory()) DeleteFolder(tempFind.GetFilePath()); else DeleteFile(tempFind.GetFilePath()); } } tempFind.Close(); RemoveDirectory(dir); } }
bool cFile::Delete(const AString & a_Path) { if (IsFolder(a_Path)) { return DeleteFolder(a_Path); } else { return DeleteFile(a_Path); } }
void customQListWidget::addActionsToFolder() { this->folderContextMenu = new QMenu(this); QAction *qAction1 = new QAction("Rename Folder", folderContextMenu); connect(qAction1, SIGNAL(triggered()),this,SLOT(RenameFolder())); folderContextMenu->addAction(qAction1); QAction *qAction2 = new QAction("Delete Folder", folderContextMenu); connect(qAction2, SIGNAL(triggered()),this,SLOT(DeleteFolder())); folderContextMenu->addAction(qAction2); }
/** * Deletes a material or material folder. */ void MaterialTreeView::OnDeleteMaterial() { CTreeCtrl &tree = GetTreeCtrl(); HTREEITEM item = tree.GetSelectedItem(); DWORD itemType = tree.GetItemData( item ); if( itemType == TYPE_MATERIAL_FOLDER ) { int result = MessageBox( "Are you sure you want to delete this folder?", "Delete?", MB_ICONQUESTION | MB_YESNO ); if( result == IDYES ) { DeleteFolder( item ); } } else if( itemType == TYPE_MATERIAL ) { int result = MessageBox( "Are you sure you want to delete this material?", "Delete?", MB_ICONQUESTION | MB_YESNO ); if( result == IDYES ) { materialDocManager->DeleteMaterial( materialDocManager->GetCurrentMaterialDoc() ); } } }
void CDialogProcess::DeleteFolder(CString folder) //删除一个文件夹下的所有内容 { CFileFind finder; CString path; path.Format(_T("%s/*.*"), folder); BOOL bWorking = finder.FindFile(path); while(bWorking){ bWorking = finder.FindNextFile(); if(finder.IsDirectory() && !finder.IsDots()){//处理文件夹 DeleteFolder(finder.GetFilePath()); //递归删除文件夹 RemoveDirectory(finder.GetFilePath()); } else{//处理文件 DeleteFile(finder.GetFilePath()); } } }
/* * DeleteFolder - delete all files in a folder */ void DeleteFolder( HWND hDlg, LPCSTR pszFolder, LPCSTR pszUninstallFile ) { char szFilter[MAX_PATH]; char szFilePath[MAX_PATH]; char *pch; WIN32_FIND_DATA wfd; HANDLE hFindFile; MSG msg; strcpy( szFilter, pszFolder ); strcat( szFilter, "\\*.*" ); strcpy( szFilePath, pszFolder ); strcat( szFilePath, "\\" ); pch = szFilePath + strlen( szFilePath ); hFindFile = FindFirstFile( szFilter, &wfd ); do { /* Let the progress dialog handle any messages. */ while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) { if( !IsDialogMessage( hDlg, &msg ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } } if( !strcmp( wfd.cFileName, "." ) || !strcmp( wfd.cFileName, ".." ) ) { /* Skip over the special directories. */ } else if( pszUninstallFile != NULL && !stricmp( wfd.cFileName, pszUninstallFile ) ) { /* Just skip over the uninstaller file for now. */ } else { strcpy( pch, wfd.cFileName ); if( wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { DeleteFolder( hDlg, szFilePath, NULL ); RemoveDirectory( szFilePath ); } else { SetDlgItemText( hDlg, IDC_STATUS, wfd.cFileName ); DeleteFile( szFilePath ); } } } while( FindNextFile( hFindFile, &wfd ) ); FindClose( hFindFile ); } /* DeleteFolder */
void CDialogProcess::DetectCoupleProcess() { CLineComputeView* pView = (CLineComputeView*)((CMainFrame *)AfxGetMainWnd())->GetActiveView(); fPath = pView->m_data->m_workspace + _T("\\sp\\"); if(PathFileExists(fPath)) { DeleteFolder(fPath); } timerInterval = 1000; fName[0] = _T("model.sta"); fName[1] = _T("dxzx.sta"); fName[2] = _T("compute.sta"); fName[3] = _T("post.sta"); SetTimer(10001, timerInterval, 0); m_progressSolve.SetRange(0, 100); m_progressSolve.SetPos(0); m_staticModel.SetWindowTextW(_T("(进行中)")); }
// // ZapFolder // // Moves the entire content of the given directory up one level and then "zaps" the directory. // // @param p_hParentWnd Handle of parent window for dialog boxes. // If this is set to 0, we will not show any UI. // @param p_Folder Folder path. // @param p_rYesToAll true if user chose to answer "Yes" to all confirmations. // @return Result code. // HRESULT CLevelZapContextMenuExt::ZapFolder(const HWND p_hParentWnd, CString p_Folder, bool& p_rYesToAll) const { CString folderName = Util::PathFindFolderName(p_Folder); // Ask for confirmation. CString confirmMsg1(MAKEINTRESOURCE(IDS_ZAP_CONFIRM_MESSAGE_1)); CString confirmMsg2(MAKEINTRESOURCE(IDS_ZAP_CONFIRM_MESSAGE_2)); CString confirmMsgComplete = confirmMsg1 + folderName + confirmMsg2; CString confirmMsgOld1(MAKEINTRESOURCE(IDS_ZAP_CONFIRM_MESSAGE_OLD_1)); CString confirmMsgOld2(MAKEINTRESOURCE(IDS_ZAP_CONFIRM_MESSAGE_OLD_2)); CString confirmMsgCompleteOld = confirmMsgOld1 + folderName + confirmMsgOld2; if (!p_rYesToAll && !m_bRecursive) if (!Dialog::doModal(p_hParentWnd, Util::GetVersionEx2()>=6?confirmMsgComplete.GetBuffer():confirmMsgCompleteOld.GetBuffer())) return E_ABORT; // Check for name collission BOOL bRename = Util::PathFindFile(p_Folder, Util::PathFindFolderName(p_Folder), m_bRecursive); CString _p_Folder(p_Folder); if (bRename) p_Folder.Empty(); if (bRename) { if (!SUCCEEDED(Util::MoveFolderEx(_p_Folder, p_Folder))) return E_FAIL; } // create list of files to move CString szlFrom, szlTo; if (!SUCCEEDED(FindFiles(p_hParentWnd, Util::PathFindPreviousComponent(p_Folder), p_Folder, szlFrom, szlTo))) { if (bRename) Util::MoveFolderEx(p_Folder, _p_Folder); return E_FAIL; } // move files and don't leave an empty folder if (SUCCEEDED(MoveFile(p_hParentWnd, szlFrom, szlTo)) || Util::PathIsDirectoryEmptyEx(p_Folder)) { // Delete source directory DeleteFolder(p_hParentWnd, p_Folder); return S_OK; } else return E_FAIL; return S_OK; }
BOOL DeleteFolder(LPCWSTR path, DELFOLDER_PROGRESS_PROC proc, PVOID context) { std::vector<std::wstring> file_list; if (!EnumFileList(path, L"*", file_list, TRUE, FALSE)) { return FALSE; } ULONG attributes = 0; ULONG current_index = 0; ULONG total = file_list.size(); for (std::vector<std::wstring>::iterator it = file_list.begin(); it != file_list.end(); ++it) { if (proc != NULL) { if (!proc(it->c_str(), total, ++current_index, context)) { continue; } } attributes = GetFileAttributesW(it->c_str()); if (attributes == INVALID_FILE_ATTRIBUTES) { return FALSE; } if (attributes & FILE_ATTRIBUTE_DIRECTORY) { SetFileAttributesW(it->c_str(), FILE_ATTRIBUTE_NORMAL); if (!DeleteFolder(it->c_str(), proc, context)) { return FALSE; } } else { SetFileAttributesW(it->c_str(), FILE_ATTRIBUTE_NORMAL); if (!DeleteFileW(it->c_str())) { return FALSE; } } } return RemoveDirectoryW(path); }
BOOL CRTFolder::DeleteFolder(LPCTSTR lpFolder) { WIN32_FIND_DATA wfd; char FolderFind[MAX_PATH]; ZeroMemory(FolderFind,MAX_PATH); strcpy(FolderFind,lpFolder); strcat(FolderFind,"\\*.*"); HANDLE hFind = FindFirstFile(FolderFind,&wfd); if(hFind != NULL) { do { if((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) { if(wfd.cFileName[0] == '.')continue; char NextFolder[MAX_PATH]; ZeroMemory(NextFolder,MAX_PATH); strcpy(NextFolder,lpFolder); strcat(NextFolder,"\\"); strcat(NextFolder,wfd.cFileName); DeleteFolder(NextFolder); } else { char NextFile[MAX_PATH]; ZeroMemory(NextFile,MAX_PATH); strcpy(NextFile,lpFolder); strcat(NextFile,"\\"); strcat(NextFile,wfd.cFileName); DeleteFile(NextFile); } }while(FindNextFile(hFind,&wfd)); FindClose(hFind); } return RemoveDirectory(lpFolder); }
std::wstring Cx_TempFolder::CreateFolder(const std::wstring& wstrPrefix) { ASSERT(!m_wstrRootPath.empty()); Cx_Interface<Ix_FileUtility> pIFUtility(CLSID_FileUtility); DeleteFolder(); for (int i = 1; i < 9999; i++) { WCHAR szFileName[MAX_PATH] = { 0 }; swprintf_s(szFileName, _countof(szFileName), L"%s%03d", wstrPrefix.c_str(), i); std::wstring wstrPath (pIFUtility->RelToAbs(szFileName, false, m_wstrRootPath.c_str(), false)); if (!pIFUtility->IsPathFileExists(wstrPath.c_str())) { m_wstrPath = wstrPath; break; } } bool bRet = !m_wstrPath.empty() && pIFUtility->CreateDirectory(m_wstrPath.c_str(), true); return bRet ? m_wstrPath : L"?"; }
/* De-allocate all folder memory */ void FreeFolders(void) { int i = 0; if (treeFolders != NULL) { if (numExtraFolders) { FreeExtraFolders(); numFolders -= numExtraFolders; } for (i = numFolders - 1; i >= 0; i--) { DeleteFolder(treeFolders[i]); treeFolders[i] = NULL; numFolders--; } free(treeFolders); treeFolders = NULL; } numFolders = 0; }
/* * RD / RMDIR */ BOOL DeleteFolder(LPTSTR FileName) { TCHAR Base[MAX_PATH]; TCHAR TempFileName[MAX_PATH]; HANDLE hFile; WIN32_FIND_DATA f; _tcscpy(Base,FileName); _tcscat(Base,_T("\\*")); hFile = FindFirstFile(Base, &f); Base[_tcslen(Base) - 1] = _T('\0'); if (hFile != INVALID_HANDLE_VALUE) { do { if (!_tcscmp(f.cFileName, _T(".")) || !_tcscmp(f.cFileName, _T(".."))) continue; _tcscpy(TempFileName,Base); _tcscat(TempFileName,f.cFileName); if (f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) DeleteFolder(TempFileName); else { SetFileAttributes(TempFileName,FILE_ATTRIBUTE_NORMAL); if (!DeleteFile(TempFileName)) { FindClose (hFile); return 0; } } }while (FindNextFile (hFile, &f)); FindClose (hFile); } return RemoveDirectory(FileName); }
bool cFile::DeleteFolderContents(const AString & a_FolderName) { auto Contents = cFile::GetFolderContents(a_FolderName); for (const auto & item: Contents) { // Skip "." and ".." altogether: if ((item == ".") || (item == "..")) { continue; } // Remove the item: auto WholePath = a_FolderName + GetPathSeparator() + item; if (IsFolder(WholePath)) { if (!DeleteFolderContents(WholePath)) { return false; } if (!DeleteFolder(WholePath)) { return false; } } else { if (!DeleteFile(WholePath)) { return false; } } } // for item - Contents[] // All deletes succeeded return true; }
/* * WinMain - entry point for the uninstaller */ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { char szExePath[MAX_PATH]; char szCheckPath[MAX_PATH]; char szInstallPath[MAX_PATH]; char *pch; char *pszTitle; char *pszMessage; char *pszUninstallFile; HWND hDlg; WIN32_FIND_DATA wfd; HANDLE hFindFile; LPITEMIDLIST pidlPrograms; char szProgramsPath[MAX_PATH]; /* * Load the title for message boxes. */ pszTitle = AllocRCString( UNINS_TITLE ); /* * Get the directory where the uninstaller is located. */ GetModuleFileName( NULL, szExePath, MAX_PATH ); strcpy( szInstallPath, szExePath ); pch = strrchr( szInstallPath, '\\' ); *pch = '\0'; /* * Look for the check file to ensure that the uninstaller is being actually run from * an Open Watcom installation directory. */ strcpy( szCheckPath, szInstallPath ); strcat( szCheckPath, "\\" ); strcat( szCheckPath, CHECK_FILE_NAME ); hFindFile = FindFirstFile( szCheckPath, &wfd ); if( hFindFile == INVALID_HANDLE_VALUE ) { pszMessage = GetRCString( UNINS_NO_OW_INST ); MessageBox( NULL, pszMessage, pszTitle, MB_OK | MB_ICONSTOP ); FreeRCString( pszTitle ); return( 1 ); } FindClose( hFindFile ); /* * Check that the user actually wants to uninstall Open Watcom. */ pszMessage = GetRCString( UNINS_CONFIRM ); if( MessageBox( NULL, pszMessage, pszTitle, MB_YESNO | MB_ICONQUESTION ) == IDNO ) { FreeRCString( pszTitle ); return( 0 ); } /* * Display the progress dialog box during the uninstallation. */ hDlg = CreateDialog( hInstance, "PROGRESS", NULL, ProgressDlgProc ); /* * Get the name of the uninstaller. */ pszUninstallFile = strrchr( szExePath, '\\' ); pszUninstallFile++; /* * Delete all files except the uninstaller. */ DeleteFolder( hDlg, szInstallPath, pszUninstallFile ); /* * Delete the Open Watcom program folder from the start menu. */ if( SUCCEEDED( SHGetSpecialFolderLocation( NULL, CSIDL_PROGRAMS, &pidlPrograms ) ) ) { if( SHGetPathFromIDList( pidlPrograms, szProgramsPath ) ) { pch = szProgramsPath + strlen( szProgramsPath ); *pch = '\\'; pch++; strcpy( pch, "Open Watcom C - C++" ); DeleteFolder( hDlg, szProgramsPath, NULL ); RemoveDirectory( szProgramsPath ); strcpy( pch, "Open Watcom C - C++ Tools Help" ); DeleteFolder( hDlg, szProgramsPath, NULL ); RemoveDirectory( szProgramsPath ); } } /* * Tell Windows to delete the uninstaller and the folder in which it lives the next * time the computer is restarted. */ MoveFileEx( szExePath, NULL, MOVEFILE_DELAY_UNTIL_REBOOT ); MoveFileEx( szInstallPath, NULL, MOVEFILE_DELAY_UNTIL_REBOOT ); /* * Remove the uninstaller from the Add/Remove Programs list. */ RegDeleteKey( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" UNINSTALL_NAME ); /* * Take away the progress dialog. */ EndDialog( hDlg, 0 ); /* * Inform the user that the uninstallation has been completed. */ pszMessage = GetRCString( UNINS_COMPLETED ); MessageBox( NULL, pszMessage, pszTitle, MB_OK ); FreeRCString( pszTitle ); return( 0 ); } /* WinMain */
Cx_TempFolder::~Cx_TempFolder() { DeleteFolder(); }
INT cmd_rmdir (LPTSTR param) { TCHAR ch; INT args; INT dirCount; LPTSTR *arg; INT i; BOOL RD_SUB = FALSE; BOOL RD_QUIET = FALSE; INT res; INT nError = 0; TCHAR szFullPath[MAX_PATH]; if (!_tcsncmp (param, _T("/?"), 2)) { ConOutResPaging(TRUE,STRING_RMDIR_HELP); return 0; } arg = split (param, &args, FALSE, FALSE); dirCount = 0; /* check for options anywhere in command line */ for (i = 0; i < args; i++) { if (*arg[i] == _T('/')) { /*found a command, but check to make sure it has something after it*/ if (_tcslen (arg[i]) == 2) { ch = _totupper (arg[i][1]); if (ch == _T('S')) { RD_SUB = TRUE; } else if (ch == _T('Q')) { RD_QUIET = TRUE; } } } else { dirCount++; } } if (dirCount == 0) { /* No folder to remove */ error_req_param_missing(); freep(arg); return 1; } for (i = 0; i < args; i++) { if (*arg[i] == _T('/')) continue; if (RD_SUB) { /* ask if they want to delete evrything in the folder */ if (!RD_QUIET) { res = FilePromptYNA (STRING_DEL_HELP2); if (res == PROMPT_NO || res == PROMPT_BREAK) { nError = 1; continue; } if (res == PROMPT_ALL) RD_QUIET = TRUE; } /* get the folder name */ GetFullPathName(arg[i],MAX_PATH,szFullPath,NULL); /* remove trailing \ if any, but ONLY if dir is not the root dir */ if (_tcslen (szFullPath) >= 2 && szFullPath[_tcslen (szFullPath) - 1] == _T('\\')) szFullPath[_tcslen(szFullPath) - 1] = _T('\0'); res = DeleteFolder(szFullPath); } else { res = RemoveDirectory(arg[i]); } if (!res) { /* Couldn't delete the folder, print out the error */ nError = GetLastError(); ErrorMessage(nError, _T("RD")); } } freep (arg); return nError; }
/********************************************** ReadFileLine(): Read a single line from a file. Used to read from stdin. Process line elements. Returns: 1 of read data, 0=no data, -1=EOF. NOTE: It only returns 1 if a filename changes! **********************************************/ int ReadFileLine (FILE *Fin) { int C='@'; int i=0; /* index */ char FullLine[MAXLINE]; char *L; int rc=0; /* assume no data */ int Type=0; /* 0=undefined; 1=delete; 2=list */ int Target=0; /* 0=undefined; 1=upload; 2=license; 3=folder */ long Id; memset(FullLine,0,MAXLINE); /* inform scheduler that we're ready for data */ printf("OK\n"); alarm(60); fflush(stdout); if (feof(Fin)) { return(-1); } /* read a line */ while(!feof(Fin) && (i < MAXLINE-1) && (C != '\n') && (C>0)) { C=fgetc(Fin); if ((C>0) && (C!='\n')) { FullLine[i]=C; i++; } else if ((C=='\n') && (i==0)) { C='@'; /* ignore blank lines */ } } if ((i==0) && feof(Fin)) return(-1); if (Verbose > 1) fprintf(stderr,"DEBUG: Line='%s'\n",FullLine); /* process the line. */ L = FullLine; while(isspace(L[0])) L++; /** Get the type of command: delete or list **/ if (!strncasecmp(L,"DELETE",6) && isspace(L[6])) { Type=1; /* delete */ L+=6; } else if (!strncasecmp(L,"LIST",4) && isspace(L[4])) { Type=2; /* list */ L+=4; } while(isspace(L[0])) L++; /** Get the target **/ if (!strncasecmp(L,"UPLOAD",6) && (isspace(L[6]) || !L[6])) { Target=1; /* upload */ L+=6; } else if (!strncasecmp(L,"LICENSE",7) && (isspace(L[7]) || !L[7])) { Target=2; /* license */ L+=7; } else if (!strncasecmp(L,"FOLDER",6) && (isspace(L[6]) || !L[6])) { Target=3; /* folder */ L+=6; } while(isspace(L[0])) L++; Id = atol(L); /* Handle the request */ if ((Type==1) && (Target==1)) { DeleteUpload(Id); rc=1; } else if ((Type==1) && (Target==2)) { DeleteLicense(Id); rc=1; } else if ((Type==1) && (Target==3)) { DeleteFolder(Id); rc=1; } else if ((Type==2) && (Target==1)) { ListUploads(); rc=1; } else if ((Type==2) && (Target==2)) { ListUploads(); rc=1; } else if ((Type==2) && (Target==3)) { ListFolders(); rc=1; } else { printf("ERROR: Unknown command: '%s'\n",FullLine); } return(rc); } /* ReadFileLine() */
int main (int argc, char *argv[]) { int c; int ListProj=0, ListFolder=0; long DelUpload=0, DelFolder=0, DelLicense=0; int Scheduler=0; /* should it run from the scheduler? */ int GotArg=0; char *agent_desc = "Deletes upload. Other list/delete options available from the command line."; while((c = getopt(argc,argv,"ifF:lL:sTuU:v")) != -1) { switch(c) { case 'i': DB = DBopen(); if (!DB) { fprintf(stderr,"ERROR: Unable to open DB\n"); exit(-1); } GetAgentKey(DB, basename(argv[0]), 0, SVN_REV, agent_desc); DBclose(DB); return(0); case 'f': ListFolder=1; GotArg=1; break; case 'F': DelFolder=atol(optarg); GotArg=1; break; case 'L': DelLicense=atol(optarg); GotArg=1; break; case 'l': ListProj=1; GotArg=1; break; case 's': Scheduler=1; GotArg=1; break; case 'T': Test++; break; case 'u': ListProj=1; GotArg=1; break; case 'U': DelUpload=atol(optarg); GotArg=1; break; case 'v': Verbose++; break; default: Usage(argv[0]); exit(-1); } } if (!GotArg) { Usage(argv[0]); exit(-1); } DB = DBopen(); if (!DB) { fprintf(stderr,"ERROR: Unable to open DB\n"); exit(-1); } GetAgentKey(DB, basename(argv[0]), 0, SVN_REV, agent_desc); signal(SIGALRM,ShowHeartbeat); if (ListProj) ListUploads(); if (ListFolder) ListFolders(); alarm(60); /* from this point on, handle the alarm */ if (DelUpload) { DeleteUpload(DelUpload); } if (DelFolder) { DeleteFolder(DelFolder); } if (DelLicense) { DeleteLicense(DelLicense); } /* process from the scheduler */ if (Scheduler) { while(ReadFileLine(stdin) >= 0) ; } DBclose(DB); return(0); } /* main() */
/* Can be called to re-initialize the array of treeFolders */ BOOL InitFolders(void) { int i = 0; DWORD dwFolderFlags; LPFOLDERDATA fData = 0; if (treeFolders != NULL) { for (i = numFolders - 1; i >= 0; i--) { DeleteFolder(treeFolders[i]); treeFolders[i] = 0; numFolders--; } } numFolders = 0; if (folderArrayLength == 0) { folderArrayLength = 200; treeFolders = (TREEFOLDER **)malloc(sizeof(TREEFOLDER **) * folderArrayLength); if (!treeFolders) { folderArrayLength = 0; return 0; } else { memset(treeFolders,'\0', sizeof(TREEFOLDER **) * folderArrayLength); } } // built-in top level folders for (i = 0; g_lpFolderData[i].m_lpTitle; i++) { fData = &g_lpFolderData[i]; /* get the saved folder flags */ dwFolderFlags = GetFolderFlags(numFolders); /* create the folder */ AddFolder(NewFolder(fData->m_lpTitle, fData->m_nFolderId, -1, fData->m_nIconId, dwFolderFlags)); } numExtraFolders = InitExtraFolders(); for (i = 0; i < numExtraFolders; i++) { LPEXFOLDERDATA fExData = ExtraFolderData[i]; // OR in the saved folder flags dwFolderFlags = fExData->m_dwFlags | GetFolderFlags(numFolders); // create the folder //dprintf("creating top level custom folder with icon %i",fExData->m_nIconId); AddFolder(NewFolder(fExData->m_szTitle,fExData->m_nFolderId,fExData->m_nParent, fExData->m_nIconId,dwFolderFlags)); } CreateAllChildFolders(); CreateTreeIcons(); ResetWhichGamesInFolders(); ResetTreeViewFolders(); SelectTreeViewFolder(GetSavedFolderID()); return TRUE; }
bool CFileView::DeleteFolder(CString lpPath) { TCHAR szFind[MAX_PATH]={0}; TCHAR szFile[MAX_PATH]={0}; WIN32_FIND_DATA FindFileData; wcscpy_s(szFind,lpPath); wcscat_s(szFind,_T("*.*")); HANDLE hFind=::FindFirstFile(szFind,&FindFileData); if(INVALID_HANDLE_VALUE == hFind) return false; while(TRUE) { if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if(FindFileData.cFileName[0]!=_T('.')) { //9-6修改Bug,老是提示无法读源或磁盘 wcscpy_s(szFile,lpPath); wcscat_s(szFile,FindFileData.cFileName); CString csDelFolder=szFile; wcscat_s(szFile,_T("\\")); if(DeleteFolder(szFile)) { wchar_t wpath[MAX_PATH]; ::memset(wpath,0,sizeof(wchar_t)*MAX_PATH); LPCTSTR pPath=csDelFolder; wcscpy(wpath,pPath); SHFILEOPSTRUCT op; op.fFlags = FOF_NOCONFIRMATION; op.hNameMappings = NULL; op.hwnd = NULL; op.lpszProgressTitle = NULL; op.pFrom = wpath; op.pTo = wpath; op.wFunc = FO_DELETE; int nRet=::SHFileOperation(&op); if(nRet!=0) return false; } else return false; } } else { CString csFileName=FindFileData.cFileName; csFileName.Trim(); CString csFileEx=csFileName.Right(2); CString csTFile; csTFile.Format(_T("%s%s"),lpPath,csFileName); if(0==::wcscmp(csFileEx,_T(".t"))) { ::DeleteFile(csTFile); ((CTCApp*)AfxGetApp())->TCDeleteTFileView(csTFile); } ::DeleteFile(csTFile); } if(!FindNextFile(hFind,&FindFileData)) break; } FindClose(hFind); return true; }
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_CREATE: { SendMessage(hwnd, (UINT)WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(ICON_MAIN))); init(hwnd); return 0; } case WM_INITDIALOG: { } case WM_DESTROY: { if (tempFolder != NULL) { StripSlash(tempFolder); DeleteFolder(tempFolder); } PostQuitMessage(0); return 0; } case WM_COMMAND: { if (lParam == (LPARAM)CButton->Wnd) { pages = NULL; SendMessage(hwnd, WM_CLOSE, 0, 0); } else if (pages != NULL) { if ((DWORD)lParam == (DWORD)langlist->Wnd) { if (CBN_SELCHANGE == HIWORD(wParam)) { delete language->setCurrentByLabel(langlist->getCurText()); controls->setCurLanguage(); } // } else if (lParam == (LPARAM)CButton->Wnd) { // SendMessage(hwnd, WM_DESTROY, 0, 0); } else if (Accept->event(hwnd, wParam, lParam)) { return 0; } else if (NoAccept->event(hwnd, wParam, lParam)) { return 0; } else if (pages->nextButton->event(hwnd, wParam, lParam)) { return 0; } else if (pages->prevButton->event(hwnd, wParam, lParam)) { return 0; } } } case WM_TIMER:{ switch (wParam) { case TIMER_START: { KillTimer(hwnd,TIMER_START); init_second(hwnd); return 0; } case TIMER_STEP1: { KillTimer(hwnd,TIMER_STEP1); runIt(hwnd,1); return 0; } case TIMER_STEP2: { KillTimer(hwnd,TIMER_STEP2); runIt(hwnd,2); return 0; } } } } return DefWindowProc(hwnd, msg, wParam, lParam); }
bool CleanFolder(KString FolderName, bool bRecursive, bool bSafe) { FolderName = SlashedFolderName(FolderName); bool bSuccess = true; // Files TEST_BLOCK_BEGIN { KStrings Files; EnlistFiles(FolderName + TEXT("*.*"), Files, false); for(KStrings::TConstIterator Iter = Files.GetFirst() ; Iter.IsValid() ; ++Iter) { TEST_BLOCK_BEGIN { TFile(FolderName + *Iter).Remove(); } TEST_BLOCK_EXCEPTION_HANDLER { if(!bSafe) throw 1; EMPTY_DEBUG_FAILURE_MESSAGE; bSuccess = false; } TEST_BLOCK_END } } TEST_BLOCK_EXCEPTION_HANDLER { if(!bSafe) throw 1; EMPTY_DEBUG_FAILURE_MESSAGE; bSuccess = false; } TEST_BLOCK_END // Folders TEST_BLOCK_BEGIN { KStrings Folders; EnlistFolders(FolderName + TEXT("*.*"), Folders, false); if(!Folders.IsEmpty()) { if(!bRecursive) return false; for(KStrings::TConstIterator Iter = Folders.GetFirst() ; Iter.IsValid() ; ++Iter) { if(!DeleteFolder(FolderName + *Iter, bRecursive, bSafe)) bSuccess = false; } } } TEST_BLOCK_EXCEPTION_HANDLER { if(!bSafe) throw 1; EMPTY_DEBUG_FAILURE_MESSAGE; bSuccess = false; } TEST_BLOCK_END return bSuccess; }