bool CContextControl::CloseTab(int tab) { if (!m_tabs) return false; if (tab < 0) return false; size_t i = 0; for (i = 0; i < m_context_controls.size(); i++) { if (m_context_controls[i].tab_index == tab) break; } if (i == m_context_controls.size()) return false; CState* pState = m_context_controls[i].pState; if (!pState->m_pCommandQueue->Idle()) { if (wxMessageBoxEx(_("Cannot close tab while busy.\nCancel current operation and close tab?"), _T("FileZilla"), wxYES_NO | wxICON_QUESTION) != wxYES) return false; Freeze(); pState->m_pCommandQueue->Cancel(); pState->GetRecursiveOperationHandler()->StopRecursiveOperation(); } else Freeze(); pState->GetComparisonManager()->SetListings(0, 0); if (m_tabs->GetPageCount() == 2) { // Get rid again of tab bar m_tabs->Disconnect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEventHandler(CContextControl::OnTabChanged), 0, this); int keep = tab ? 0 : 1; m_tabs->RemovePage(keep); size_t j; for (j = 0; j < m_context_controls.size(); j++) { if (m_context_controls[j].tab_index != keep) continue; break; } m_context_controls[j].pViewSplitter->Reparent(this); ReplaceWindow(m_tabs, m_context_controls[j].pViewSplitter); m_context_controls[j].pViewSplitter->Show(); m_context_controls[j].tab_index = 0; wxAuiNotebookEx *tabs = m_tabs; m_tabs = 0; m_context_controls[i].tab_index = -1; m_context_controls[i].site_bookmarks.clear(); CContextManager::Get()->SetCurrentContext(m_context_controls[j].pState); tabs->Destroy(); } else { if (pState == CContextManager::Get()->GetCurrentContext()) { int newsel = tab + 1; if (newsel >= (int)m_tabs->GetPageCount()) newsel = m_tabs->GetPageCount() - 2; for (size_t j = 0; j < m_context_controls.size(); j++) { if (m_context_controls[j].tab_index != newsel) continue; m_tabs->SetSelection(newsel); CContextManager::Get()->SetCurrentContext(m_context_controls[j].pState); } } for (size_t j = 0; j < m_context_controls.size(); j++) { if (m_context_controls[j].tab_index > tab) m_context_controls[j].tab_index--; } m_context_controls[i].tab_index = -1; m_context_controls[i].site_bookmarks.clear(); m_tabs->DeletePage(tab); } pState->Disconnect(); Thaw(); return true; }
void CClearPrivateDataDialog::Show() { if (!Load(m_pMainFrame, _T("ID_CLEARPRIVATEDATA"))) return; if (ShowModal() != wxID_OK) return; wxCheckBox *pSitemanagerCheck = XRCCTRL(*this, "ID_CLEARSITEMANAGER", wxCheckBox); wxCheckBox *pQueueCheck = XRCCTRL(*this, "ID_CLEARQUEUE", wxCheckBox); if (pSitemanagerCheck->GetValue() && pQueueCheck->GetValue()) { int res = wxMessageBox(_("Do you really want to delete all Site Manager entries and the transfer queue?"), _("Clear private data"), wxYES | wxNO | wxICON_QUESTION); if (res != wxYES) return; } else if (pQueueCheck->GetValue()) { int res = wxMessageBox(_("Do you really want to delete the transfer queue?"), _("Clear private data"), wxYES | wxNO | wxICON_QUESTION); if (res != wxYES) return; } else if (pSitemanagerCheck->GetValue()) { int res = wxMessageBox(_("Do you really want to delete all Site Manager entries?"), _("Clear private data"), wxYES | wxNO | wxICON_QUESTION); if (res != wxYES) return; } wxCheckBox *pCheck = XRCCTRL(*this, "ID_CLEARQUICKCONNECT", wxCheckBox); if (!pCheck) return; if (pCheck->GetValue()) { CRecentServerList::Clear(); if (m_pMainFrame->GetQuickconnectBar()) m_pMainFrame->GetQuickconnectBar()->ClearFields(); } pCheck = XRCCTRL(*this, "ID_CLEARRECONNECT", wxCheckBox); if (pCheck->GetValue()) { bool asked = false; const std::vector<CState*> *states = CContextManager::Get()->GetAllStates(); for (std::vector<CState*>::const_iterator iter = states->begin(); iter != states->end(); ++iter) { CState* pState = *iter; if (pState->IsRemoteConnected() || !pState->IsRemoteIdle()) { if (!asked) { int res = wxMessageBox(_("Reconnect information cannot be cleared while connected to a server.\nIf you continue, your connection will be disconnected."), _("Clear private data"), wxOK | wxCANCEL); if (res != wxOK) return; asked = true; } pState->GetRecursiveOperationHandler()->StopRecursiveOperation(); if (!pState->m_pCommandQueue->Cancel()) { m_timer.SetOwner(this); m_timer.Start(250, true); } else pState->Disconnect(); } } // Doesn't harm to do it now, but has to be repeated later just to be safe ClearReconnect(); } if (pSitemanagerCheck->GetValue()) { CInterProcessMutex sitemanagerMutex(MUTEX_SITEMANAGERGLOBAL, false); while (sitemanagerMutex.TryLock() == 0) { int res = wxMessageBox(_("The Site Manager is opened in another instance of FileZilla 3.\nPlease close it or the data cannot be deleted."), _("Clear private data"), wxOK | wxCANCEL); if (res != wxYES) return; } CInterProcessMutex mutex(MUTEX_SITEMANAGER); RemoveXmlFile(_T("sitemanager")); } if (pQueueCheck->GetValue()) { m_pMainFrame->GetQueue()->SetActive(false); m_pMainFrame->GetQueue()->RemoveAll(); CInterProcessMutex mutex(MUTEX_QUEUE); RemoveXmlFile(_T("queue")); } }
HRESULT CDecoder::CodeReal(ISequentialInStream *anInStream, ISequentialOutStream *anOutStream, const UINT64 *, const UINT64 *anOutSize) { if (anOutSize == NULL) return E_INVALIDARG; Init(anInStream, anOutStream); CState aState; aState.Init(); bool aPeviousIsMatch = false; BYTE aPreviousByte = 0; UINT32 aRepDistances[kNumRepDistances]; for(UINT32 i = 0 ; i < kNumRepDistances; i++) aRepDistances[i] = 0; UINT64 aNowPos64 = 0; UINT64 aSize = *anOutSize; while(aNowPos64 < aSize) { UINT64 aNext = MyMin(aNowPos64 + (1 << 18), aSize); while(aNowPos64 < aNext) { UINT32 aPosState = UINT32(aNowPos64) & m_PosStateMask; if (m_MainChoiceDecoders[aState.m_Index][aPosState].Decode(&m_RangeDecoder) == (UINT32) kMainChoiceLiteralIndex) { // aCounts[0]++; aState.UpdateChar(); if(aPeviousIsMatch) { BYTE aMatchByte = m_OutWindowStream.GetOneByte(0 - aRepDistances[0] - 1); aPreviousByte = m_LiteralDecoder.DecodeWithMatchByte(&m_RangeDecoder, UINT32(aNowPos64), aPreviousByte, aMatchByte); aPeviousIsMatch = false; } else aPreviousByte = m_LiteralDecoder.DecodeNormal(&m_RangeDecoder, UINT32(aNowPos64), aPreviousByte); m_OutWindowStream.PutOneByte(aPreviousByte); aNowPos64++; } else { aPeviousIsMatch = true; UINT32 aDistance, aLen; if(m_MatchChoiceDecoders[aState.m_Index].Decode(&m_RangeDecoder) == (UINT32) kMatchChoiceRepetitionIndex) { if(m_MatchRepChoiceDecoders[aState.m_Index].Decode(&m_RangeDecoder) == 0) { if(m_MatchRepShortChoiceDecoders[aState.m_Index][aPosState].Decode(&m_RangeDecoder) == 0) { aState.UpdateShortRep(); aPreviousByte = m_OutWindowStream.GetOneByte(0 - aRepDistances[0] - 1); m_OutWindowStream.PutOneByte(aPreviousByte); aNowPos64++; // aCounts[3 + 4]++; continue; } // aCounts[3 + 0]++; aDistance = aRepDistances[0]; } else { if(m_MatchRep1ChoiceDecoders[aState.m_Index].Decode(&m_RangeDecoder) == 0) { aDistance = aRepDistances[1]; aRepDistances[1] = aRepDistances[0]; // aCounts[3 + 1]++; } else { if (m_MatchRep2ChoiceDecoders[aState.m_Index].Decode(&m_RangeDecoder) == 0) { // aCounts[3 + 2]++; aDistance = aRepDistances[2]; } else { // aCounts[3 + 3]++; aDistance = aRepDistances[3]; aRepDistances[3] = aRepDistances[2]; } aRepDistances[2] = aRepDistances[1]; aRepDistances[1] = aRepDistances[0]; } aRepDistances[0] = aDistance; } aLen = m_RepMatchLenDecoder.Decode(&m_RangeDecoder, aPosState) + kMatchMinLen; // aCounts[aLen]++; aState.UpdateRep(); } else { aLen = kMatchMinLen + m_LenDecoder.Decode(&m_RangeDecoder, aPosState); aState.UpdateMatch(); UINT32 aPosSlot = m_PosSlotDecoder[GetLenToPosState(aLen)].Decode(&m_RangeDecoder); // aCounts[aPosSlot]++; if (aPosSlot >= (UINT32) kStartPosModelIndex) { aDistance = kDistStart[aPosSlot]; if (aPosSlot < (UINT32) kEndPosModelIndex) aDistance += m_PosDecoders[aPosSlot - kStartPosModelIndex].Decode(&m_RangeDecoder); else { aDistance += (m_RangeDecoder.DecodeDirectBits(kDistDirectBits[aPosSlot] - kNumAlignBits) << kNumAlignBits); aDistance += m_PosAlignDecoder.Decode(&m_RangeDecoder); } } else aDistance = aPosSlot; aRepDistances[3] = aRepDistances[2]; aRepDistances[2] = aRepDistances[1]; aRepDistances[1] = aRepDistances[0]; aRepDistances[0] = aDistance; // UpdateStat(aLen, aPosSlot); } if (aDistance >= aNowPos64) throw E_INVALIDDATA; m_OutWindowStream.CopyBackBlock(aDistance, aLen); aNowPos64 += aLen; aPreviousByte = m_OutWindowStream.GetOneByte(0 - 1); } } } return Flush(); }
CRemoteRecursiveOperation::CRemoteRecursiveOperation(CState &state) : CRecursiveOperation(state) { state.RegisterHandler(this, STATECHANGE_REMOTE_DIR_OTHER); state.RegisterHandler(this, STATECHANGE_REMOTE_LINKNOTDIR); }
void CSingleStateFeatureCalculator::getModifiedState(CStateCollection *stateCol, CState *featState) { CState *state = stateCol->getState(originalState); CStateProperties *properties = state->getStateProperties(); double contState = state->getContinuousState(dimension); double width = properties->getMaxValue(dimension) - properties->getMinValue(dimension); if (contState < partitions[0] && properties->getPeriodicity(dimension)) { contState += width; } unsigned int activeFeature = 0; unsigned int featureNum = 0, realfeatureNum = 0; int featureIndex = 0; double part = partitions[activeFeature]; while (activeFeature < numFeatures && part < contState) { activeFeature++; if (activeFeature < numFeatures) { part = partitions[activeFeature]; } if (part < partitions[0]) { assert(properties->getPeriodicity(dimension)); part += width; } } if (activeFeature == numFeatures && !properties->getPeriodicity(dimension)) { featureNum ++; } DebugPrint('l', "Single State Features: ["); for (; realfeatureNum < this->numActiveFeatures; realfeatureNum++, featureNum ++) { if (featureNum % 2 == 0) { featureIndex = activeFeature + featureNum / 2; } else { featureIndex = activeFeature - (featureNum / 2 + 1); } if (state->getStateProperties()->getPeriodicity(dimension)) { featureIndex = featureIndex % numFeatures; } if (featureIndex >= 0 && featureIndex < (signed int) numFeatures) { featState->setDiscreteState(realfeatureNum, featureIndex); double stateDiff = state->getSingleStateDifference(dimension, partitions[featureIndex]); double diffNextPart = 1.0; if (!state->getStateProperties()->getPeriodicity(dimension)) { if (featureIndex == 0 && stateDiff <= 0) { stateDiff = 0; } else { if (featureIndex == (signed int) (numFeatures - 1) && stateDiff > 0) { stateDiff = 0; } else { if (stateDiff <= 0) { diffNextPart = partitions[featureIndex] - partitions[featureIndex - 1]; } else { diffNextPart = partitions[featureIndex + 1] - partitions[featureIndex]; } } } } else { if (stateDiff <= 0) { diffNextPart = partitions[featureIndex] - partitions[(numPartitions + featureIndex - 1) % numPartitions]; } else { diffNextPart = partitions[(featureIndex + 1) % numPartitions] - partitions[featureIndex]; } if (diffNextPart < 0) { diffNextPart += width; } if (diffNextPart > 0) { diffNextPart -= width; } } featState->setContinuousState(realfeatureNum, getFeatureFactor(featureIndex, stateDiff, diffNextPart)); DebugPrint('l', "%f %f, ", partitions[featureIndex], featState->getContinuousState(realfeatureNum)); } else { featState->setContinuousState(realfeatureNum, 0.0); featState->setDiscreteState(realfeatureNum, 0); } } this->normalizeFeatures(featState); DebugPrint('l', "]\n"); }
void CLinearMultiFeatureCalculator::getModifiedState(CStateCollection *stateCol, CState *featState) { assert(equals(featState->getStateProperties())); memset(actualPartition, 0, sizeof(unsigned int) * numDim); unsigned int j = 0; CState *state = stateCol->getState(originalState); /* printf("State : "); for (int i = 0; i < 4; i ++) { printf("%f ", state->getNormalizedContinuousState(i)); } printf("\n");*/ getSingleActiveFeature(state, singleStateFeatures); unsigned int i; int feature = 0; //offset to add to the actual feature int featureAdd = 0; getFeaturePosition(getActiveFeature(state), activePosition); // printf("["); // for (i = 0; i < numDim; i ++) // { // printf("%f ", state->getNormalizedContinuousState(dimensions[i])); // } // printf("]"); // activePosition->saveASCII(stdout); // printf("\n"); for (i = 0; i < numDim; i ++) { int singleFeatureOffset = 0; if (areaSize[i] % 2 == 0) { //double x1 = state->getNormalizedContinuousState(dimensions[i]); //double x2 = activePosition->element(i); if (state->getNormalizedContinuousState(dimensions[i]) < activePosition->element(i)) { singleFeatureOffset ++; } singleFeatureOffset += (areaSize[i] - 1) / 2; } else { singleFeatureOffset += areaSize[i] / 2; } singleStateFeatures[i] -= singleFeatureOffset; activePosition->element(i) = activePosition->element(i) - singleFeatureOffset * 1.0 / partitions[i] * gridScale[i]; } unsigned int featureIndex = 0; for (i = 0; i < areaNumPart; i++) { feature = 0; /*for (j = 0; j < numDim; j++) { int dist = (actualPartition[j] - areaSize[j]); featurePosition->setElement(j, (activePosition->element(j) + 1.0 / partitions[j] * dist)); featureAdd = (singleStateFeatures[j] + (actualPartition[j] - areaSize[j])); if (state->getStateProperties()->getPeriodicity(j)) { featurePosition->setElement(j, featurePosition->element(j) - floor(featurePosition->element(j))); featureAdd = featureAdd - (int) floor((double) featureAdd / (double) partitions[j]) * partitions[j]; } feature = feature + featureAdd * dimensionSize[j]; } */ /*for (j = 0; j < numDim; j++) { int dist = (actualPartition[j] - 1); featurePosition->setElement(j, (activePosition->element(j) + 1.0 / partitions[j] * dist)); featureAdd = (singleStateFeatures[j] + (actualPartition[j] - 1)); if (state->getStateProperties()->getPeriodicity(j)) { featurePosition->setElement(j, featurePosition->element(j) - floor(featurePosition->element(j))); featureAdd = featureAdd - (int) floor((double) featureAdd / (double) partitions[j]) * partitions[j]; } feature = feature + featureAdd * dimensionSize[j]; } for (i = 0; i < numDim; i ++) { int singleFeatureOffset = 0; if (areaSize[i] % 2 == 0) { if (state->getContinuousState(dimensions[i]) < activePosition->element(i)) { singleFeatureOffset ++; } singleFeatureOffset += (singleFeatureOffset - 1) / 2; } else { singleFeatureOffset += areaSize[i] / 2; } singleStateFeatures[i] -= singleFeatureOffset; activePosition->setElement(i, activePosition->element(i) - singleFeatureOffset * 1.0 / partitions[i]); }*/ for (j = 0; j < numDim; j++) { //int dist = (actualPartition[j] - areaSize[j]); featurePosition->element(j) = activePosition->element(j) + (1.0 / partitions[j] * actualPartition[j]) * gridScale[j]; featureAdd = (singleStateFeatures[j] + actualPartition[j]); if (state->getStateProperties()->getPeriodicity(j) && gridScale[j] >= 1.0) { featurePosition->element(j) = featurePosition->element(j) - floor(featurePosition->element(j)); featureAdd = featureAdd - (int) floor((double) featureAdd / (double) partitions[j]) * partitions[j]; } feature = feature + featureAdd * dimensionSize[j]; } if (feature >= 0 && (unsigned int) feature < getNumFeatures()) { featState->setDiscreteState(featureIndex, feature); featState->setContinuousState(featureIndex, getFeatureFactor(state, featurePosition)); featureIndex ++; } j = 0; actualPartition[0] ++; while (j < numDim && actualPartition[j] >= areaSize[j]) { actualPartition[j] = 0; j ++; if (j < numDim) { actualPartition[j]++; } } } featState->setNumActiveContinuousStates(featureIndex); featState->setNumActiveDiscreteStates(featureIndex); for (; featureIndex < areaNumPart; featureIndex ++) { featState->setDiscreteState(featureIndex, 0); featState->setContinuousState(featureIndex, 0.0); } this->normalizeFeatures(featState); }
void CAuthModule::Handle_Login_Packet( CLoginPacket* pPacket, CConnection* pConnection ) { // Make sure username is in all lowercase std::string Name = pPacket->Get_Username(); std::transform(Name.begin(), Name.end(), Name.begin(), ::tolower); // This will try loading from disk if it isn't already in mem CUser* pUser = Get_User_By_Name( Name ); if( !pUser ) { // Not loaded in mem, can't loaded from disk // Check if we are allowing new users CStateModule* pStateModule = (CStateModule*)GETMODULE(MODULE_STATE); CState* pState = pStateModule->Get_Current_State(); // Only Master server can create new users if( (CDCEngine::GetInstance()->Get_Driver_Mode() == MODE_MASTER) && (pState->Allow_New_User()) ) { DLog(LOG_AUTH, "Creating new user: %s\n", Name.c_str()); CPlayer* pPlayer = NULL; // Create the new User obj pPlayer = (CPlayer*)Create_New_User( pPacket->Get_UserType() ); pPlayer->m_Name = Name; pPlayer->m_Password = pPacket->Get_Password(); // Establish link between connection and user pPlayer->m_pConnection = pConnection; pConnection->m_pUser = pPlayer; // Add to loaded users map m_UsersByName.insert( USER_MAP_NAME_PAIR(pPlayer->Get_Name(),pPlayer) ); m_UsersByID.insert( USER_MAP_ID_PAIR(pPlayer->Get_UserID(), pPlayer) ); // Send Ident Send_Ident( pConnection ); // Notify engine of new login CDCEngine::GetInstance()->On_New_Login( pPlayer ); return; } // Disconnect this connection Log(LOG_DRIVER, "Not allowing new users, disconnecting: %s:%d\n", pConnection->Get_Address().c_str(), pConnection->Get_Port()); m_pNetworkModule->Disconnect_Connection( pConnection->Get_ID(), DR_NO_NEW_USERS ); return; } // User is loaded DLog(LOG_AUTH, "User logged in new: %s\n", pUser->Get_Name().c_str()); // Link connection and user pUser->m_pConnection = pConnection; pConnection->m_pUser = pUser; // Send Ident Send_Ident( pConnection ); // Notify Engine CDCEngine::GetInstance()->On_New_Login( pUser ); return; }
void CFeatureRewardModel::nextStep(CStateCollection *oldState, CAction *action, double reward, CStateCollection *newState) { CFeatureMap *featMap; CState *oldS = oldState->getState(properties); CState *newS = newState->getState(properties); double oldreward = 0.0; double visits = 0.0; int actionIndex = getActions()->getIndex(action); int type = oldS->getStateProperties()->getType() & (DISCRETESTATE | FEATURESTATE); switch (type) { case FEATURESTATE: { for (unsigned int oldIndex = 0; oldIndex < oldS->getNumDiscreteStates(); oldIndex++) { int oldFeature = oldS->getDiscreteState(oldIndex); featMap = rewardTable->get(actionIndex, oldFeature); for (unsigned int newIndex = 0; newIndex < newS->getNumDiscreteStates(); newIndex++) { int newFeature = newS->getDiscreteState(newIndex); oldreward = featMap->getValue(newFeature); (*featMap)[newFeature] = oldreward + reward * newS->getContinuousState(newIndex) * oldS->getContinuousState(oldIndex); if (!bExternVisitSparse) { visits = visitTable->get(actionIndex, oldFeature)->getValue(newFeature); (*visitTable->get(actionIndex, oldFeature))[newFeature] = visits + newS->getContinuousState(newIndex) * oldS->getContinuousState(oldIndex);; } } } break; } case DISCRETESTATE: default: { featMap = rewardTable->get(actionIndex, oldS->getDiscreteStateNumber()); oldreward = featMap->getValue(newS->getDiscreteStateNumber()); int feata = oldS->getDiscreteStateNumber(); int featb = newS->getDiscreteStateNumber(); (*featMap)[featb] = oldreward + reward; if (!bExternVisitSparse) { visits = visitTable->get(actionIndex, feata)->getValue(featb); (*visitTable->get(actionIndex, feata))[featb] = visits + 1.0; } break; } } }
void MainApplication::runApplication(int argc, char *argv[]) { double dt, T, Tbath, tau, L; int nSteps, thermostat, N, calculateStatistics, saveStates; if (argc != 11) { cout << endl << "! Usage: 'dt nSteps T(MD) thermostat#(0,1,2) Tbath(MD) tau L(SI) N calculateStatistics saveStates'" << endl; if (argc == 1) { dt = 0.005; nSteps = 200; T = 1.7; // to get 0.851 thermostat = 1; Tbath = 0.851; tau = 15; L = 5.720; N = 20; calculateStatistics = 1; saveStates = 0; cout << endl << "! Using default of: dt = " << dt << ", nSteps = " << nSteps << ", T = " << T << ", thermostat# = " << thermostat << ", Tbath = " << Tbath << ", tau = " << tau << ", L = " << L << ", N = " << N << ", statistics? = " << calculateStatistics << ", save states? = " << saveStates << endl << endl; } else exit(1); } else if (argc == 11) { dt = atof(argv[1]); nSteps = atoi(argv[2]); T = atof(argv[3]); thermostat = atoi(argv[4]); Tbath = atof(argv[5]); tau = atof(argv[6]); L = atof(argv[7]); N = atoi(argv[8]); calculateStatistics = atoi(argv[9]); saveStates = atoi(argv[10]); } double tt = 1.0/10; long seed = -1; cout << "dt : " << dt << endl; cout << "Tbath : " << Tbath << endl; CState state; state = initialize(T, L, N, &seed); CStatisticsSampler sampler(state); sampler.initialize_pairCorrelation(200, 1); ostringstream filename; // state.load("./output/states/state.1000.xyz"); for (int i = 0; i < nSteps; i++) { if (i%50==0) cout << "n = " << i << " of " << nSteps << endl; filename.str(string()); filename << "./output/states/state." << setfill('0') << setw(4) << i << ".xyz"; if (saveStates) state.save(filename.str(), 1, 1); if (calculateStatistics) sampler.sample(state, 1, dt*i); // if (i>250) sampler.pairCorrelation(); if (thermostat == 1 && calculateStatistics) state.berendsen(Tbath, sampler.T, tt); else if (thermostat == 2) state.andersen(Tbath, tt, &seed); state.move(dt, calculateStatistics); } sampler.sample(state, 1, nSteps*dt); // filename.str(string()); // filename << "./output/states/state." << setfill('0') << setw(4) << nSteps << ".xyz"; // state.save(filename.str(), 0, 0); // sampler.pairCorrelation_manual("./output/pairCorrelation_final.dat", 1, 200); }