bool ThreadedWorker::Perform(Action * action_) { // is there already a thread running? if (m->action != 0) { m->TraceError(_("Internal Error: There is another action running")); return false; } // is there a context? we need one if (m->context == 0) { m->TraceError(_("Internal Error: no context available")); return false; } action_->SetContext(m->context); m->context->reset(); m->result = ACTION_NOTHING; m->state = ACTION_INIT; try { if (!action_->Prepare()) { m->result = ACTION_ABORTED; m->state = ACTION_NONE; delete action_; return false; } } catch (svn::ClientException & e) { wxString msg, errtxt(Utf8ToLocal(e.message())); msg.Printf(_("Error while preparing action: %s"), errtxt.c_str()); m->TraceError(msg); m->result = ACTION_ERROR; m->state = ACTION_NONE; delete action_; return false; } catch (...) { m->TraceError(_("Error while preparing action.")); m->result = ACTION_ERROR; m->state = ACTION_NONE; delete action_; return false; } m->actionName = action_->GetName(); m->action = action_; return true; }
/** * executes the action if there is any */ void ExecuteAction() { if (action == 0) return; ActionEvent event(parent, TOKEN_ACTION_START); { wxString msg; msg.Printf(_("Execute: %s"), actionName.c_str()); event.init(parent, TOKEN_ACTION_START, msg); event.Post(); } unsigned int actionFlags = 0; try { state = ACTION_RUNNING; if (!action->Perform()) result = ACTION_ERROR; else result = ACTION_SUCCESS; actionFlags = action->GetFlags(); state = ACTION_NONE; } catch (svn::ClientException & e) { wxString msg, errtxt(Utf8ToLocal(e.message())); msg.Printf(_("Error while performing action: %s"), errtxt.c_str()); event.init(parent, TOKEN_SVN_INTERNAL_ERROR, msg); event.Post(); state = ACTION_NONE; result = ACTION_ERROR; DeleteAction(); return; } catch (...) { wxString msg(_("Error while performing action.")); event.init(parent, TOKEN_SVN_INTERNAL_ERROR, msg); event.Post(); state = ACTION_NONE; result = ACTION_ERROR; DeleteAction(); return; } event.init(parent, TOKEN_ACTION_END, (void*) new unsigned int(actionFlags)); event.Post(); DeleteAction(); }
bool UpdateAction::Perform() { svn::Revision revision(svn::Revision::HEAD); // Did the user request a specific revision?: if (!m_data.useLatest) { TrimString(m_data.revision); if (!m_data.revision.IsEmpty()) { svn_revnum_t revnum; m_data.revision.ToLong(&revnum, 10); // If this fails, revnum is unchanged. revision = svn::Revision(revnum); } } const wxString & dir = Utf8ToLocal(GetPath().c_str()); if (!dir.empty()) wxSetWorkingDirectory(dir); svn::Client client(GetContext()); svn_depth_t depth = svn_depth_unknown; switch (m_data.depth) { default: case UPDATE_WORKING_COPY: depth = svn_depth_unknown; break; case UPDATE_FULLY_RECURSIVE: depth = svn_depth_infinity; break; case UPDATE_IMMEDIATES: depth = svn_depth_immediates; break; case UPDATE_FILES: depth = svn_depth_files; break; case UPDATE_EMPTY: depth = svn_depth_empty; break; } client.update(GetTargets(), revision, depth, m_data.stickyDepth, m_data.ignoreExternals); return true; }
bool MergeAction::Prepare() { if (!Action::Prepare()) { return false; } // Set default Destination to the selected path in the folder browser // or, if called by the log dialogue, to the source path if (m_data.calledByLogDlg) m_data.Destination = m_data.Path1; else m_data.Destination = Utf8ToLocal(GetPath().c_str()); MergeDlg dlg(GetParent(), m_data.calledByLogDlg, m_data); if (dlg.ShowModal() != wxID_OK) { return false; } return true; }
/* get a directory entry */ int VMShfReadDir( const shf_t *shf, uint32_t handle, /* 10: file handle returned by OPEN */ uint32_t index, uint32_t *status, uint32_t *dirflag, fileattr_t **fileattr, char **filename) { uint32_t datalen; int ret; if (vmshf_debug) { fprintf(stderr, "VMSHF_READ_DIR handle:%lu, index:%lu -> ", handle, index); fflush(stderr); } *status = (uint32_t)-1; *filename = NULL; memcpy(shf->buf, shf_header, sizeof(shf_header)); *(uint32_t *)&shf->buf[ 6] = VMSHF_READ_DIR; *(uint32_t *)&shf->buf[10] = handle; *(uint32_t *)&shf->buf[14] = index; datalen = 18; ret = ExecuteRpc(shf, &datalen); if (ret != VMTOOL_SUCCESS) { if (vmshf_debug) { fprintf(stderr, "rpc failed\n"); } return ret; } *status = *(uint32_t *)&shf->buf[6]; if (vmshf_debug) { fprintf(stderr, "\n len:%lu, status:%lu, dir:%ld, len:%lu, name:'%s'\n", datalen, *(uint32_t *)&shf->buf[6], *(uint32_t *)&shf->buf[10], *(uint32_t *)&shf->buf[55], *(uint32_t *)&shf->buf[55] ? (const char *)&shf->buf[59] : "(null)"); } if (datalen >= 59) { uint32_t namelen = *(uint32_t *)&shf->buf[55]; if (namelen) { *dirflag = *(uint32_t *)&shf->buf[10]; *fileattr = (fileattr_t *)&shf->buf[14]; shf->buf[59 + namelen] = '\0'; Utf8ToLocal((char *)&shf->buf[59], (char *)&shf->buf[59]); *filename = (char *)&shf->buf[59]; } } return VMTOOL_SUCCESS; }
bool ExternalProgramAction::Perform() { VerbList verb_list; // wxBusyCursor busy_cursor; // The actual target svn::Path path = GetTarget(); if (path.isUrl()) path = GetPathAsTempFile(path); wxString target_str = Utf8ToLocal(path.native().c_str()); wxFileName target = target_str; // The target we'll pass to the external program wxString target_document = target.GetFullPath(); Preferences prefs; if (m_treat_as_folder) { // Assuming target is a folder: use only folder part of filename if target // is really a file if (!wxDirExists(target_document)) target_document = target.GetPath(); } // Get verbs from the OS verb_list.InitFromDocument(target_document, m_treat_as_folder); // An explicit verb was chose that is not available if ((m_verb_id >= 0) && ((size_t)m_verb_id > verb_list.GetCount())) { // TODO: Trace this? return false; } if (m_treat_as_folder) { if (verb_list.GetCount() && !((m_verb_id == -1) && prefs.explorerAlways)) { verb_list.Launch((m_verb_id == -1 ? 0 : m_verb_id)); } else { wxString args(prefs.explorerArgs); TrimString(args); if (args.Length() == 0) args = wxT("\"") + target_document + wxT("\""); else args.Replace(wxT("%1"), target_document, true); wxString cmd(prefs.explorer + wxT(" ") + args); wxString msg; msg.Printf(_("Execute file explorer: %s"), cmd.c_str()); Trace(msg); ActionEvent::Post(m_parent, TOKEN_CMD, cmd); } } else { if (verb_list.GetCount() && !((m_verb_id == -1) && prefs.editorAlways)) { verb_list.Launch((m_verb_id == -1 ? 0 : m_verb_id)); } else { wxString args(prefs.editorArgs); TrimString(args); if (args.Length() == 0) args = wxT("\"") + target_document + wxT("\""); else args.Replace(wxT("%1"), target_document, true); wxString cmd(prefs.editor + wxT(" ") + args); wxString msg; msg.Printf(_("Execute editor: %s"), cmd.c_str()); Trace(msg); ActionEvent::Post(m_parent, TOKEN_CMD, cmd); } } return true; }