VectorTreeItemId BFBackupTree::GetTaskItems (wxTreeItemId idParent, bool bGoDeep /*= true*/) { VectorTreeItemId vec; wxTreeItemId idCurr; wxTreeItemIdValue idCookie; if (ItemHasChildren(idParent)) { for (idCurr = GetFirstChild(idParent, idCookie); idCurr.IsOk(); idCurr = GetNextChild(idParent, idCookie)) { if (ItemHasChildren(idCurr) == bGoDeep) { VectorTreeItemId vecSub(GetTaskItems(idCurr, true)); for (ItVectorTreeItemId it = vecSub.begin(); it != vecSub.end(); it++) { vec.push_back(*it); } } else { if (IsTask(idCurr)) vec.push_back(idCurr); } } } return vec; }
void BFBackupTree::OnDeleteTask (wxCommandEvent& rEvent) { if ( IsTask(lastItemId_) ) /* one task */ { BFTask* pTask = GetTaskByItem(lastItemId_); if (pTask == NULL) return; if ( BFMainFrame::Instance()->QuestionYesNo(_("Should this task be deleted?")) ) BFProject::Instance().DeleteTask(pTask->GetOID()); } else /* a couple of tasks */ { // get the affected tree-item-ids VectorTreeItemId vecIds( GetTaskItems(lastItemId_, true) ); // get the corrosponding BFTask BFTaskVector vecTasks; for (ItVectorTreeItemId it = vecIds.begin(); it != vecIds.end(); ++it) { vecTasks.push_back(GetTaskByItem(*it)); } // create the question string wxString str = wxString::Format("Should this %d tasks be deleted?\n", vecTasks.size()); for (BFTaskVectorIt it = vecTasks.begin(); it != vecTasks.end(); ++it) { str = str + "\n\t" + (*it)->GetName(); } // ask the user if ( BFMainFrame::Instance()->QuestionYesNo(str) ) { // delete the tasks BFProject::Instance().DeleteTasks(vecTasks); } } }
/* ----------------------------------------------------- */ int Skt4uInit (void) { int Ark; if (! bInitDone) /* Aucune socket ouverte */ { for (Ark=0 ; Ark<SizeOfTab(HistoSocket) ; Ark++) HistoSocket[Ark].skt = INVALID_SOCKET; bInitDone=TRUE; } #ifdef WINDOWS /* liberation des sockets appartenant a des taches mortes */ else { for (Ark=0 ; Ark<SizeOfTab(HistoSocket) ; Ark++) if ( HistoSocket[Ark].skt!=INVALID_SOCKET && !IsTask(HistoSocket[Ark].hTask) ) TcpClose (& HistoSocket[Ark].skt); } /* InitDone */ #endif return TCP4U_SUCCESS; } /* Skt4wInit */
// pre-process input file, creating a tmp file // In order to get the return code of the C pre-processor, I'm // spawing a batch file that invokes CL, and creates a signal file // if it is successful. VOID NEAR DoPreProcess ( ) { char szBuffer[255]; HANDLE hInstCpp; TASKENTRY taskentry; FILE * hFile; CHAR * szTempBatch; CHAR * szTempSig; CHAR * szTempRoot; ERR err = ERR_CPP; // assume error int cbTempFilenames; char * szComSpec; // figure out the names of the temp files // (note: uses OEM char set) szTempRoot = tempnam(".", "~mkt"); // get base name for temp files hFile = fopen(szTempRoot, "w"); // create the file now, to if (hFile == NULL) // reserve this set of names ParseError(ERR_CPP); fclose(hFile); cbTempFilenames = strlen(szTempRoot)+1+3+1; // base name + ext + null szTempBatch = malloc(cbTempFilenames); // for .BAT file strcpy(szTempBatch, szTempRoot); strcat(szTempBatch, ".bat"); szTempSig = malloc(cbTempFilenames); // for .SIG file strcpy(szTempSig, szTempRoot); strcat(szTempSig, ".sig"); szTempFile = malloc(cbTempFilenames); // for pre-processed oupput strcpy(szTempFile, szTempRoot); strcat(szTempFile, ".inp"); // CONSIDER: Check for existence of any of these files, if any exist, then // CONSIDER: try a different base name for the files. // open the temp .BAT file hFile = fopen(szTempBatch, "w"); if (hFile == NULL) goto cleanup2; // all errors after this point should go to 'cleanup' if (fputs(szBatchStart, hFile) < 0) // write the first part goto cleanup; sprintf(szBuffer, "%s %s%s %s>", szCppExe, szCppOpts, szCppDefs, szInputFile); // convert this string to the OEM char set AnsiToOem(szBuffer, szBuffer); // append szTempFile strcat(szBuffer, szTempFile); strcat(szBuffer, "\n"); if (fputs(szBuffer, hFile) < 0) // write the CPP command goto cleanup; sprintf(szBuffer, szBatchEnd, szTempSig); if (fputs(szBuffer, hFile) < 0) // write the error check code goto cleanup; fclose(hFile); hFile = NULL; // file no longer open szComSpec = getenv("COMSPEC"); if (szComSpec == NULL) szComSpec = "command.com"; sprintf(szBuffer, "%s /c %s", szComSpec, szTempBatch); hInstCpp = WinExec(szBuffer, SW_SHOWMINIMIZED); // shell the pre-processor if (hInstCpp < 32) // if error spawning pre-processor goto cleanup; Yield(); // give it a chance to start // find task associated with this instance. In extreme cases it may have // finished even before we're executing this code. taskentry.dwSize = sizeof(TASKENTRY); if (TaskFirst(&taskentry) == 0) { goto taskdone; } while (taskentry.hInst != hInstCpp) { if (TaskNext(&taskentry) == 0) { goto taskdone; } } hTaskCpp = taskentry.hTask; while (IsTask(hTaskCpp)) { SideAssert(TaskFindHandle(&taskentry, hTaskCpp) != 0); if (taskentry.hInst != hInstCpp) { // different hInst associated with this htask, // so the app must have terminated break; } Yield(); // wait until it's done } taskdone: // If signal file doesn't exist, then there was a problem pre-processing // the input file. If it exists, then it worked. if (!MyRemove(szTempSig)) err = ERR_NONE; // it worked! cleanup: if (hFile) // close tmp batch file if fclose(hFile); // error during write SideAssert(MyRemove(szTempBatch) == 0); // delete tmp batch file cleanup2: SideAssert(MyRemove(szTempRoot) == 0); // delete placeholder file if (err != ERR_NONE) // report any error ParseError(err); }
void BFBackupTree::OnItemMenu(wxTreeEvent& rEvent) { wxPoint point (rEvent.GetPoint()); wxMenu menu; wxMenu* pMenu_backup = NULL; wxMenu* pMenu_type = NULL; wxString strLabel_ModifyTaskType(_("modify all sub-tasks to ...")); wxString strLabel_DeleteTask(_("delete task")); wxString strLabel_CreateDest(_("create destination directory")); wxString strLabel_Backup(_("backup")); // remember the selected item lastItemId_ = rEvent.GetItem(); // check if there are task-items as childs vecLastChildTasks_ = GetTaskItems(lastItemId_); if ( IsTask(lastItemId_) ) { BFTask* pTask = GetTaskByItem(lastItemId_); if (pTask == NULL) return; // ** create destination directory ** if (pTask->GetType() == TaskDIRCOPY) menu.Append(BFBACKUPCTRL_ID_CREATEDESTINATION, strLabel_CreateDest); // ** delete task ** menu.Append(BFBACKUPCTRL_ID_DELETETASK, strLabel_DeleteTask); // ** modify types ** if ( vecLastChildTasks_.size() > 0) { BFBackupTree::GenerateBackupMenu(pMenu_type, true, false); menu.AppendSubMenu(pMenu_type, strLabel_ModifyTaskType); } // separator menu.AppendSeparator(); // ** backup ** if (pTask->GetType() == TaskFILECOPY) BFBackupTree::GenerateBackupMenu(pMenu_backup, false); else BFBackupTree::GenerateBackupMenu(pMenu_backup, true); menu.AppendSubMenu(pMenu_backup, strLabel_Backup); // separator menu.AppendSeparator(); // ** task settings ** menu.Append(BFBACKUPCTRL_ID_TASKSETTINGS, _("Task settings")); } else { // for non-existing (while backup created) directories menu.Append(BFBACKUPCTRL_ID_CREATEDESTINATION, strLabel_CreateDest); // right click on root item if (GetRootItem() == lastItemId_) { // for real existing directories menu.Append(BFBACKUPCTRL_ID_ADDDESTINATION, _("add destination directory")); menu.Append(BFBACKUPCTRL_ID_DELETETASK, strLabel_DeleteTask); // ** modify types ** if ( vecLastChildTasks_.size() > 0) { BFBackupTree::GenerateBackupMenu(pMenu_type, true, false); menu.AppendSubMenu(pMenu_type, strLabel_ModifyTaskType); } menu.AppendSeparator(); menu.Append(BFBACKUPCTRL_ID_RUNBACKUP, _("Run Backup...") ); menu.AppendSeparator(); menu.Append(BFBACKUPCTRL_ID_PROJECTSETTINGS, _("Project Settings") ); menu.Append(BFBACKUPCTRL_ID_PROJECTPLANNER, _("Project Planner") ); if ( BFSettings::Instance().GetScheduler() == 0 ) menu.Enable(BFBACKUPCTRL_ID_PROJECTPLANNER, false); menu.AppendSeparator(); menu.Append(BFBACKUPCTRL_ID_PROJECTSAVE, _("&Save Project") ); menu.Append(BFBACKUPCTRL_ID_PROJECTSAVEAS, _("Save Project &as ...") ); } else { menu.Append(BFBACKUPCTRL_ID_MODIFYDDESTINATION, _("modify destination")); menu.Append(BFBACKUPCTRL_ID_DELETETASK, strLabel_DeleteTask); // ** modify types ** if ( vecLastChildTasks_.size() > 0) { BFBackupTree::GenerateBackupMenu(pMenu_type, true, false); menu.AppendSubMenu(pMenu_type, strLabel_ModifyTaskType); } menu.AppendSeparator(); BFBackupTree::GenerateBackupMenu(pMenu_backup, true); menu.AppendSubMenu(pMenu_backup, strLabel_Backup); } } if (menu.GetMenuItemCount() > 0) PopupMenu(&menu);//, point); }