コード例 #1
0
ファイル: SocketManager.cpp プロジェクト: hsluoyz/VisualADS
///////////////////////////////////////////////////////////////////////////////
// OnEvent
// Send message to parent window to indicate connection status
void CSocketManager::OnEvent(UINT uEvent)
{
	CString strServer = _T("Server No. ") + itos(m_iIndex) + _T(": ");
	switch( uEvent )
	{
		case EVT_CONSUCCESS:
			AppendMessage(strServer + _T("Connection Established\r\n") );
			m_bConnected = TRUE;
			break;
		case EVT_CONFAILURE:
			AppendMessage(strServer + _T("Connection Failed\r\n") );
			m_bConnected = FALSE;
			break;
		case EVT_CONDROP:
			AppendMessage(strServer + _T("Connection Abandonned\r\n") );
			Output_Update_Connection(uEvent, this);
			m_bConnected = FALSE;
			break;
		case EVT_ZEROLENGTH:
			AppendMessage(strServer + _T("Zero Length Message\r\n") );
			m_bConnected = FALSE;
			break;
		default:
			TRACE("Unknown Socket event\n");
			m_bConnected = FALSE;
			break;
	}
	//pParent->PostMessage(WM_UPDATE_CONNECTION, uEvent, (LPARAM) this);

}
コード例 #2
0
///////////////////////////////////////////////////////////////////////////////
// OnEvent
// Send message to parent window to indicate connection status
void CSocketManager::OnEvent(UINT uEvent, LPVOID lpvData)
{
	if (NULL == m_pMsgCtrl)
		return;

	CWnd* pParent = m_pMsgCtrl->GetParent();
	if (!::IsWindow( pParent->GetSafeHwnd()))
		return;

	switch( uEvent )
	{
		case EVT_CONSUCCESS:
			AppendMessage( _T("Connection Established\r\n") );
			break;
		case EVT_CONFAILURE:
			AppendMessage( _T("Connection Failed\r\n") );
			break;
		case EVT_CONDROP:
			AppendMessage( _T("Connection Abandonned\r\n") );
			break;
		case EVT_ZEROLENGTH:
			AppendMessage( _T("Zero Length Message\r\n") );
			break;
		default:
			TRACE("Unknown Socket event\n");
			break;
	}

	pParent->PostMessage( WM_UPDATE_CONNECTION, uEvent, (LPARAM) this);

}
コード例 #3
0
ファイル: Dialog.cpp プロジェクト: sqba/zenfolders
BOOL CDialog::Install()
{
	BOOL result = FALSE;
	TCHAR szMessage[MAX_PATH] = {0};
	TCHAR szPath[MAX_PATH] = {0};
	int msg = IDS_INSTALL_SUCCESS;

	SetMessage( TEXT("") );

	lstrcpy(szPath, m_szDestinationPath);

	if( Exists(szPath) || ::CreateDirectory(szPath, NULL) )
	{
		if( ExtractResourceToFile(RESOURCE_ID_DLL, FILENAME_DLL, true) )
		{
			ExtractResourceToFile(RESOURCE_ID_XML, FILENAME_XML, false);

			lstrcat(szPath, "\\");
			lstrcat(szPath, FILENAME_DLL);

			HWND hwndCancel = ::GetDlgItem(m_hwnd, IDCANCEL);
			::ShowWindow(hwndCancel, SW_HIDE) ;

			if( RegisterActiveX(szPath) )
			{
				if( CreateUninstall(FALSE) )
					msg = IDS_INSTALL_SUCCESS;
				else
				{
				}

				result = TRUE;
			}
			else
				msg = IDS_REGISTERACTIVEXFAILED;
		}
		else
			msg = IDS_INSTALL_FAILED;

		AppendMessage( msg, NULL, true );
	}
	else
	{
		AppendMessage( IDS_CREATEFOLDERFAILED, szPath, true );
	}

	Finish();

	return result;
}
コード例 #4
0
ファイル: SocketManager.cpp プロジェクト: cagatay/fish-game
void CSocketManager::DisplayData(const LPBYTE lpData, DWORD dwCount, const SockAddrIn& sfrom)
{
	CString strData;
#ifndef UNICODE
	USES_CONVERSION;
	memcpy(strData.GetBuffer(dwCount), A2CT((LPSTR)lpData), dwCount);
	strData.ReleaseBuffer(dwCount);
#else
	MultiByteToWideChar(CP_ACP, 0, reinterpret_cast<LPCSTR>(lpData), dwCount, strData.GetBuffer(dwCount+1), dwCount+1 );
	strData.ReleaseBuffer(dwCount);
#endif

	if (!sfrom.IsNull())
	{
		LONG  uAddr = sfrom.GetIPAddr();
		BYTE* sAddr = (BYTE*) &uAddr;
		int nPort = ntohs( sfrom.GetPort() ); // show port in host format...
		CString strAddr;
		// Address is stored in network format...
		strAddr.Format(_T("%u.%u.%u.%u (%d)>"),
					(UINT)(sAddr[0]), (UINT)(sAddr[1]),
					(UINT)(sAddr[2]), (UINT)(sAddr[3]), nPort);

		strData = strAddr + strData;
	}
	AppendMessage( strData );
	
}
コード例 #5
0
void ExampleInit()
{
	Presage::start();

	AppendMessage(Presage::getStatus());

	g_ShowAdButton = NewButton("Show an Ad");
}
コード例 #6
0
/******** CALLBACKS ********/
static int32 playerLoggedIn(void *systemData, void *userData) 
{
	if(systemData)
	{
		s3eNOFPlayerInfo *info = (s3eNOFPlayerInfo*)systemData;
		AppendMessage("PlayerId received is %s", info->playerId);
	}
	
	return 0;
}
コード例 #7
0
ファイル: vmframe.cpp プロジェクト: ArcticPheenix/gzdoom
CVMAbortException::CVMAbortException(EVMAbortException reason, const char *moreinfo, va_list ap)
{
	SetMessage("VM execution aborted: ");
	switch (reason)
	{
	case X_READ_NIL:
		AppendMessage("tried to read from address zero.");
		break;

	case X_WRITE_NIL:
		AppendMessage("tried to write to address zero.");
		break;

	case X_TOO_MANY_TRIES:
		AppendMessage("too many try-catch blocks.");
		break;

	case X_ARRAY_OUT_OF_BOUNDS:
		AppendMessage("array access out of bounds.");
		break;

	case X_DIVISION_BY_ZERO:
		AppendMessage("division by zero.");
		break;

	case X_BAD_SELF:
		AppendMessage("invalid self pointer.");
		break;

	case X_FORMAT_ERROR:
		AppendMessage("string format failed.");
		break;

	case X_OTHER:
		// no prepended message.
		break;

	default:
	{
		size_t len = strlen(m_Message);
		mysnprintf(m_Message + len, MAX_ERRORTEXT - len, "Unknown reason %d", reason);
		break;
	}
	}
	if (moreinfo != nullptr)
	{
		AppendMessage(" ");
		size_t len = strlen(m_Message);
		myvsnprintf(m_Message + len, MAX_ERRORTEXT - len, moreinfo, ap);
	}
	stacktrace = "";
}
コード例 #8
0
ファイル: consolewindow.cpp プロジェクト: Drakonas/MultiMC4
void InstConsoleWindow::OnProcessExit( bool killed, int status )
{
	m_timerIdleWakeUp.Stop();
	//FIXME: what are the exact semantics of this?
	if(killed)
		delete m_running;
	else
		m_running->Detach();
	m_running = nullptr;
	SetCloseIsHide(false);
	
	AppendMessage(wxString::Format(_("Minecraft exited with code %i."), status));

	bool keepOpen = CheckCommonProblems(consoleTextCtrl->GetValue());

	if (killed)
	{
		AppendMessage(_("Minecraft was killed."));
		SetState(STATE_BAD);
		Show();
		Raise();
	}
	else if (status != 0)
	{
		AppendMessage(_("Minecraft has crashed!"));
		SetState(STATE_BAD);
		Show();
		Raise();
	}
	else if ((settings->GetAutoCloseConsole() || !IsShown() ) && !crashReportIsOpen && !keepOpen)
	{
		Close();
	}
	else
	{
		Show();
		Raise();
	}
}
コード例 #9
0
static int32 didDownloadAllChallengeDefinitions(void *systemData, void *userData)
{
	if(!systemData)
	{
		AppendMessage("Downloaded all challenges with 0 items");
		return 0;
	}
		
	s3eNOFArray *defArray = (s3eNOFArray*)systemData;
	AppendMessage("AllChallengeDefinitions Downloaded with count %d" , defArray->m_count);
	for (uint i=0; i < defArray->m_count; i++) {
		AppendMessage("Challenge %s, appId %s, iconUrl %s, multiAttempt %d",
					  ((s3eNOFChallengeDefinition*)defArray->m_items)[i].title,
					  ((s3eNOFChallengeDefinition*)defArray->m_items)[i].clientApplicationId,
  					  ((s3eNOFChallengeDefinition*)defArray->m_items)[i].iconUrl,
					  ((s3eNOFChallengeDefinition*)defArray->m_items)[i].multiAttempt);
	}
	if (defArray->m_count>0) {
		g_nofChallengeDefinitions = (s3eNOFChallengeDefinition*)defArray->m_items; 
	}
	return 0;
}
コード例 #10
0
			void ChatTab::handleEntryMessage (QObject *msgObj)
			{
				Plugins::IMessage *msg = qobject_cast<Plugins::IMessage*> (msgObj);
				if (!msg)
				{
					qWarning () << Q_FUNC_INFO
							<< msgObj
							<< "doesn't implement IMessage"
							<< sender ();
					return;
				}

				AppendMessage (msg);
			}
コード例 #11
0
static int32 userLaunchedChallenge(void *systemData, void *userData)
{
	if (!systemData) {
		return -1;
	}
//	s3eNOFArray *array = (s3eNOFArray*)systemData;
	s3eNOFChallengeToUser *nofChalToUser = (s3eNOFChallengeToUser*)systemData;
	AppendMessage("Challenge %s from %s to %s with id %s", 
				  nofChalToUser->challenge->challengeDefinition->title,
				  nofChalToUser->challenge->challenger->name,
				  nofChalToUser->recipient->name,
				  nofChalToUser->nofPersistentId);
	strncpy(persistentChallengeId,nofChalToUser->nofPersistentId,sizeof(persistentChallengeId));
	return 0;
}
コード例 #12
0
void CSocketManager::DisplayData(const LPBYTE lpData, DWORD dwCount, const SockAddrIn& sfrom,__int64 startTime, BYTE type)
{
	CString strData;
#ifndef UNICODE
	USES_CONVERSION;
	memcpy(strData.GetBuffer(dwCount), A2CT((LPSTR)lpData), dwCount);
	strData.ReleaseBuffer(dwCount);
#else
	MultiByteToWideChar(CP_ACP, 0, reinterpret_cast<LPCSTR>(lpData), dwCount, strData.GetBuffer(dwCount+1), dwCount+1 );
	strData.ReleaseBuffer(dwCount);
#endif
	// variables
	char temp[512];
	


	if (type == 3)
	{
		static int  laserCommandMessageCount = 0;
		static CLaserCommand command((BYTE*)A2CT((LPSTR)lpData));
		command.BytesToStatus(((BYTE*)A2CT((LPSTR)lpData)));
		// debug string for display 
		sprintf(temp, "+LASER COMMAND MESSAGE(%d)\r\n", ++laserCommandMessageCount);
		sprintf(temp, "%s|->isLaserOn = %d\r\n", temp,command.LaserCommand.IsLaserOn);
		sprintf(temp, "%s|->AZ        = %d\r\n", temp,command.LaserCommand.PWM_AZ);
		sprintf(temp, "%s|->EL        = %d\r\n", temp,command.LaserCommand.PWM_EL);
		sprintf(temp, "%s\r\n\r\n", temp);
	}
	else
	{
		static int  laserConfigMessageCount = 0;
		static CLaserConfiguration config;
		config.BytesToStatus(((BYTE*)A2CT((LPSTR)lpData)));
		// debug string for display 
		sprintf(temp, "+LASER Configuration MESSAGE(%d)\r\n", ++laserConfigMessageCount);
		sprintf(temp, "%s|->Frequency = %d\r\n", temp,config.LaserConfiguration.Frequency);
		sprintf(temp, "%s|->AZ(min)   = %d\r\n", temp,config.LaserConfiguration.PWM_AZ.MIN);
		sprintf(temp, "%s|->AZ(max)   = %d\r\n", temp,config.LaserConfiguration.PWM_AZ.MAX);
		sprintf(temp, "%s|->EL(min)   = %d\r\n", temp,config.LaserConfiguration.PWM_EL.MIN);
		sprintf(temp, "%s|->EL(max)   = %d\r\n", temp,config.LaserConfiguration.PWM_EL.MAX);
		sprintf(temp, "%s\r\n\r\n", temp);
	}

	AppendMessage( temp );
}
コード例 #13
0
void
WizChatDirector::Receive
	(
	JBroadcaster*	sender,
	const Message&	message
	)
{
	Wiz2War* connMgr = WizGetConnectionManager();

	if (sender == connMgr && message.Is(Wiz2War::kChatMessage))
		{
		const Wiz2War::ChatMessage* info =
			dynamic_cast(const Wiz2War::ChatMessage*, &message);
		assert( info != NULL );
		AppendMessage(info->GetSenderIndex(), info->GetMessage());
		(GetWindow())->Deiconify();
		}

	else if (sender == connMgr && message.Is(Wiz2War::kPlayerJoined))
コード例 #14
0
ファイル: Dialog.cpp プロジェクト: sqba/zenfolders
BOOL CDialog::Uninstall()
{
	BOOL result = TRUE;
	TCHAR szPath[MAX_PATH] = {0};
	TCHAR szMessage[MAX_PATH] = {0};

	SetMessage( TEXT("") );

	int msg = IDS_UNINSTALL_RESTART;

	lstrcpy(szPath, m_szDestinationPath);
	lstrcat(szPath, "\\");
	lstrcat(szPath, FILENAME_DLL);

	if( UnRegisterActiveX(szPath) )
	{
		RegDeleteKey( HKEY_LOCAL_MACHINE, UNINSTALL_KEY);
		if( ::DeleteFile(szPath) )
		{
			m_bCleanup = true; // Tell main to call CleanUp()
			msg = IDS_UNINSTALL_SUCCESS;
		}
		else
		{
			// Write something to RunOnce registry key
		}
	}
	else
	{
		msg = IDS_UNREGISTERACTIVEXFAILED;
		result = FALSE;
	}

	m_bUnInstall = false;

	AppendMessage( msg, NULL, true );

	Finish();

	return result;
}
コード例 #15
0
ファイル: SocketManager.cpp プロジェクト: hsluoyz/VisualADS
void CSocketManager::DisplayData(const LPBYTE lpData, DWORD dwCount, const SockAddrIn& sfrom)
{
	CString strData;
	memcpy(strData.GetBuffer(dwCount), A2CT((LPSTR)lpData), dwCount);
	strData.ReleaseBuffer();
	if (!sfrom.IsNull())
	{
		LONG  uAddr = sfrom.GetIPAddr();
		BYTE* sAddr = (BYTE*) &uAddr;
		short nPort = ntohs( sfrom.GetPort() );	// show port in host format...
		CString strAddr;
		// Address is stored in network format...
		strAddr.Format(_T("%u.%u.%u.%u (%d)>"),
					(UINT)(sAddr[0]), (UINT)(sAddr[1]),
					(UINT)(sAddr[2]), (UINT)(sAddr[3]), nPort);

		strData = strAddr + strData;
	}

	AppendMessage(strData);
}
コード例 #16
0
ファイル: MessageDlg.cpp プロジェクト: BearWare/TeamTalk5
void CMessageDlg::OnButtonSend() 
{
    CString msg;
    m_richMessage.GetWindowText(msg);

    if(IsAlive() && msg.GetLength()>0)
    {
        m_richMessage.SetWindowText(_T(""));

        TextMessage usermsg;
        usermsg.nMsgType = MSGTYPE_USER;
        usermsg.nFromUserID = m_myself.nUserID;
        usermsg.nToUserID = m_user.nUserID;
        _tcsncpy(usermsg.szMessage, msg.GetBuffer(), TT_STRLEN - 1);

        if( TT_DoTextMessage(ttInst, &usermsg)>0)
            AppendMessage(usermsg, TRUE);
        else
            AfxMessageBox(_T("Failed to send message!"));
    }
}
コード例 #17
0
ServerMessageBox::ServerMessageBox(wxIcon* icon, wxWindow* parent, const wxString& message,
				   const wxString& caption,
				   long style, const wxPoint& pos)
    : wxDialog(parent, -1, caption, pos, wxDefaultSize, style | wxFRAME_FLOAT_ON_PARENT | wxDEFAULT_DIALOG_STYLE | wxEXPAND)
{
	if (icon)
		SetIcon(*icon);

	m_messages = new wxListCtrl(this, -1, wxDefaultPosition, wxDefaultSize, wxLC_NO_HEADER | wxLC_REPORT);
	m_messages->InsertColumn(0, wxEmptyString);
	topsizer = new wxBoxSizer(wxVERTICAL);

	AppendMessage(message);

	topsizer->Add(m_messages, 1, wxALL | wxEXPAND | wxALIGN_CENTRE, 10);
	topsizer->Add(0, 10);

	wxSizer* sizerBtn = CreateButtonSizer(wxOK);
	topsizer->Add(sizerBtn, 0, wxALL | wxALIGN_CENTRE, 10);

	SetSizer(topsizer);
	Centre(wxBOTH | wxCENTER_FRAME);
}
コード例 #18
0
ファイル: consolewindow.cpp プロジェクト: Drakonas/MultiMC4
bool InstConsoleWindow::CheckCommonProblems(const wxString& output)
{
	wxRegEx idConflictRegex("([0-9]+) is already occupied by ([A-Za-z0-9.]+)@[A-Za-z0-9]+ when adding ([A-Za-z0-9.]+)@[A-Za-z0-9]+");

	if (!idConflictRegex.IsValid())
	{
		wxLogError(_("ID conflict regex is invalid!"));
		return false;
	}

	if (idConflictRegex.Matches(output))
	{
		// We have an ID conflict.
		wxArrayString values;

		for (unsigned i = 0; i < idConflictRegex.GetMatchCount(); i++)
		{
			values.Add(idConflictRegex.GetMatch(output, i));
		}

		if (values.Count() < 4)
		{
			// Something's wrong here...
			wxLogError(_("Not enough values matched ID conflict regex!"));
			return false;
		}

		// Alert the user.
		AppendMessage(wxString::Format(
			_("MultiMC found a block or item ID conflict. %s and %s are both using the same block ID (%s)."), 
			values[2].c_str(), values[3].c_str(), values[1].c_str()), MSGT_SYSTEM);
		return true;
	}

	// No common problems found.
	return false;
}
コード例 #19
0
ファイル: Dialog.cpp プロジェクト: sqba/zenfolders
bool CDialog::ExtractResourceToFile(int resourceId, LPCTSTR lpResourceFileName, bool bOverwrite)
{
	HMODULE	hLibrary;
	HRSRC	hResource;
	HGLOBAL	hResourceLoaded;
	LPBYTE	lpBuffer;
	bool	result = false;
	TCHAR	szPath[MAX_PATH] = {0};

	lstrcpy(szPath, m_szDestinationPath);
	lstrcat(szPath, "\\");
	lstrcat(szPath, lpResourceFileName);

	AppendMessage( IDS_EXTRACTING, szPath, true );
	
	hLibrary = m_hInstance;
	hResource = ::FindResource(hLibrary, MAKEINTRESOURCE(resourceId), RT_RCDATA);
	if (NULL != hResource)
	{
		hResourceLoaded = ::LoadResource(hLibrary, hResource);
		if (NULL != hResourceLoaded)        
		{
			lpBuffer = (LPBYTE)::LockResource(hResourceLoaded);            
			if (NULL != lpBuffer)            
			{                
				DWORD	dwFileSize, dwBytesWritten;
				HANDLE	hFile;
				
				dwFileSize = ::SizeofResource(hLibrary, hResource);
				
				hFile = ::CreateFile(
					szPath,
					GENERIC_WRITE,
					0,
					NULL,
					(bOverwrite ? CREATE_ALWAYS : CREATE_NEW),
					FILE_ATTRIBUTE_NORMAL,
					NULL);
				
				if (INVALID_HANDLE_VALUE != hFile)
				{
					::WriteFile(hFile, lpBuffer, dwFileSize, &dwBytesWritten, NULL);
					
					::CloseHandle(hFile);

					result = true;

					AppendMessage( IDS_EXTRACTINGOK, NULL, false );
				}
				else if(bOverwrite)
					AppendMessage( IDS_EXTRACTINGFAILED, NULL, false );
				else
					AppendMessage( IDS_EXTRACTINGSKIPPED, NULL, false );
			}
			else
				AppendMessage( IDS_LOCKRESOURCEFAILED, NULL, false );
		}  
		else
			AppendMessage( IDS_LOADRESOURCEFAILED, NULL, false );
	}
	else
		AppendMessage( IDS_RESOURCENOTFOUND, NULL, false );

	if(!result)
	{
		Finish();
	}

	return result;
}
コード例 #20
0
ファイル: MessageDlg.cpp プロジェクト: BearWare/TeamTalk5
BOOL CMessageDlg::OnInitDialog() 
{
    CDialog::OnInitDialog();

    TRANSLATE(*this, IDD);

    //load accelerators
    m_hAccel = ::LoadAccelerators(AfxGetResourceHandle(), (LPCTSTR)IDR_ACCELERATOR1);
    if (!m_hAccel)
        MessageBox(_T("The accelerator table was not loaded"));

    if(IsAlive())
    {
        for(size_t i=0;i<m_messages.size();i++)
            AppendMessage(m_messages[i], FALSE);

        CString s;
        GetWindowText(s);
        SetWindowText(s + _T(" - ") + GetDisplayName(m_user));
    }

    m_richHistory.LimitText(MAX_HISTORY_LENGTH);

    SetIcon(AfxGetApp()->LoadIcon(IDR_MAINFRAME),TRUE);

    static CResizer::CBorderInfo s_bi[] = {

        {IDC_RICHEDIT_HISTORY,    
        {CResizer::eFixed, IDC_MAIN, CResizer::eLeft}, 
        {CResizer::eFixed, IDC_MAIN, CResizer::eTop},  
        {CResizer::eFixed, IDC_MAIN, CResizer::eRight},
        {CResizer::eFixed, IDC_MAIN, CResizer::eBottom}}, 

        {IDC_STATIC_NEWMESSAGE,    
        {CResizer::eFixed, IDC_MAIN, CResizer::eLeft}, 
        {CResizer::eFixed, IDC_MAIN, CResizer::eBottom},  
        {CResizer::eFixed, IDC_MAIN, CResizer::eRight},
        {CResizer::eFixed, IDC_MAIN, CResizer::eBottom}}, 

        {IDC_RICHEDIT_MESSAGE,    
        {CResizer::eFixed, IDC_MAIN, CResizer::eLeft}, 
        {CResizer::eFixed, IDC_MAIN, CResizer::eBottom},  
        {CResizer::eFixed, IDC_MAIN, CResizer::eRight},
        {CResizer::eFixed, IDC_MAIN, CResizer::eBottom}}, 

        {IDCANCEL,
        {CResizer::eFixed, IDC_MAIN, CResizer::eLeft}, 
        {CResizer::eFixed, IDC_MAIN, CResizer::eBottom},  
        {CResizer::eFixed, IDC_MAIN, CResizer::eLeft},
        {CResizer::eFixed, IDC_MAIN, CResizer::eBottom}}, 
        {IDC_BUTTON_SEND,       
        {CResizer::eFixed, IDC_MAIN, CResizer::eRight}, 
        {CResizer::eFixed, IDC_MAIN, CResizer::eBottom},  
        {CResizer::eFixed, IDC_MAIN, CResizer::eRight},
        {CResizer::eFixed, IDC_MAIN, CResizer::eBottom}}, 

    };
    const int nSize = sizeof(s_bi)/sizeof(s_bi[0]);
    m_resizer.Init(m_hWnd, NULL, s_bi, nSize);

    if(m_lf.lfHeight>0)
    {
        m_Font.CreateFontIndirect(&m_lf);
        m_richHistory.SetFont(&m_Font);
        m_richMessage.SetFont(&m_Font);
    }

    m_richMessage.SetFocus();

    return FALSE;  // return TRUE unless you set the focus to a control
    // EXCEPTION: OCX Property Pages should return FALSE
}
コード例 #21
0
ファイル: masterlist.cpp プロジェクト: silentdark/loot
bool Masterlist::Update(const boost::filesystem::path& path, const std::string& repoUrl, const std::string& repoBranch) {
  GitHelper git;
  fs::path repoPath = path.parent_path();
  string filename = path.filename().string();

  if (repoUrl.empty() || repoBranch.empty())
    throw std::invalid_argument("Repository URL and branch must not be empty.");

// Initialise checkout options.
  BOOST_LOG_TRIVIAL(debug) << "Setting up checkout options.";
  char * paths = new char[filename.length() + 1];
  strcpy(paths, filename.c_str());
  git.GetData().checkout_options.checkout_strategy = GIT_CHECKOUT_FORCE | GIT_CHECKOUT_DONT_REMOVE_EXISTING;
  git.GetData().checkout_options.paths.strings = &paths;
  git.GetData().checkout_options.paths.count = 1;

  // Initialise clone options.
  git.GetData().clone_options.checkout_opts = git.GetData().checkout_options;
  git.GetData().clone_options.bare = 0;
  git.GetData().clone_options.checkout_branch = repoBranch.c_str();

  // Now try to access the repository if it exists, or clone one if it doesn't.
  BOOST_LOG_TRIVIAL(trace) << "Attempting to open the Git repository at: " << repoPath;
  if (!git.IsRepository(repoPath))
    git.Clone(repoPath, repoUrl);
  else {
      // Repository exists: check settings are correct, then pull updates.
    git.SetErrorMessage((boost::format(translate("An error occurred while trying to access the local masterlist repository. If this error happens again, try deleting the \".git\" folder in %1%.")) % repoPath.string()).str());

    // Open the repository.
    BOOST_LOG_TRIVIAL(info) << "Existing repository found, attempting to open it.";
    git.Call(git_repository_open(&git.GetData().repo, repoPath.string().c_str()));

    // Set the remote URL.
    BOOST_LOG_TRIVIAL(info) << "Using remote URL: " << repoUrl;
    git.Call(git_remote_set_url(git.GetData().repo, "origin", repoUrl.c_str()));

    // Now fetch updates from the remote.
    git.Fetch("origin");

    // Check that a local branch with the correct name exists.
    git.SetErrorMessage((boost::format(translate("An error occurred while trying to access the local masterlist repository. If this error happens again, try deleting the \".git\" folder in %1%.")) % repoPath.string()).str());
    int ret = git_branch_lookup(&git.GetData().reference, git.GetData().repo, repoBranch.c_str(), GIT_BRANCH_LOCAL);
    if (ret == GIT_ENOTFOUND)
        // Branch doesn't exist. Create a new branch using the remote branch's latest commit.
      git.CheckoutNewBranch("origin", repoBranch);
    else {
        // The local branch exists. Need to merge the remote branch
        // into it.
      git.Call(ret);  // Handle other errors from preceding branch lookup.

      // Check if HEAD points to the desired branch and set it to if not.
      if (!git_branch_is_head(git.GetData().reference)) {
        BOOST_LOG_TRIVIAL(trace) << "Setting HEAD to follow branch: " << repoBranch;
        git.Call(git_repository_set_head(git.GetData().repo, (string("refs/heads/") + repoBranch).c_str()));
      }

      // Get remote branch reference.
      git.Call(git_branch_upstream(&git.GetData().reference2, git.GetData().reference));

      BOOST_LOG_TRIVIAL(trace) << "Checking HEAD and remote branch's mergeability.";
      git_merge_analysis_t analysis;
      git_merge_preference_t pref;
      git.Call(git_annotated_commit_from_ref(&git.GetData().annotated_commit, git.GetData().repo, git.GetData().reference2));
      git.Call(git_merge_analysis(&analysis, &pref, git.GetData().repo, (const git_annotated_commit **)&git.GetData().annotated_commit, 1));

      if ((analysis & GIT_MERGE_ANALYSIS_FASTFORWARD) == 0 && (analysis & GIT_MERGE_ANALYSIS_UP_TO_DATE) == 0) {
          // The local branch can't be easily merged. Best just to delete and recreate it.
        BOOST_LOG_TRIVIAL(trace) << "Local branch cannot be easily merged with remote branch.";

        BOOST_LOG_TRIVIAL(trace) << "Deleting the local branch.";
        git.Call(git_branch_delete(git.GetData().reference));

        // Need to free ref before calling git.CheckoutNewBranch()
        git_reference_free(git.GetData().reference);
        git.GetData().reference = nullptr;
        git_reference_free(git.GetData().reference2);
        git.GetData().reference2 = nullptr;

        git.CheckoutNewBranch("origin", repoBranch);
      } else {
          // Get remote branch commit ID.
        git.Call(git_reference_peel(&git.GetData().object, git.GetData().reference2, GIT_OBJ_COMMIT));
        const git_oid * remote_commit_id = git_object_id(git.GetData().object);

        git_object_free(git.GetData().object);
        git.GetData().object = nullptr;
        git_reference_free(git.GetData().reference2);
        git.GetData().reference2 = nullptr;

        bool updateBranchHead = true;
        if ((analysis & GIT_MERGE_ANALYSIS_UP_TO_DATE) != 0) {
            // No merge is required, but HEAD might be ahead of the remote branch. Check
            // to see if that's the case, and move HEAD back to match the remote branch
            // if so.
          BOOST_LOG_TRIVIAL(trace) << "Local branch is up-to-date with remote branch.";
          BOOST_LOG_TRIVIAL(trace) << "Checking to see if local and remote branch heads are equal.";

          // Get local branch commit ID.
          git.Call(git_reference_peel(&git.GetData().object, git.GetData().reference, GIT_OBJ_COMMIT));
          const git_oid * local_commit_id = git_object_id(git.GetData().object);

          git_object_free(git.GetData().object);
          git.GetData().object = nullptr;

          updateBranchHead = local_commit_id->id != remote_commit_id->id;

          // If the masterlist in
          // HEAD also matches the masterlist file, no further
          // action needs to be taken. Otherwise, a checkout
          // must be performed and the checked-out file parsed.
          if (!updateBranchHead) {
            BOOST_LOG_TRIVIAL(trace) << "Local and remote branch heads are equal.";
            if (!GitHelper::IsFileDifferent(repoPath, filename)) {
              BOOST_LOG_TRIVIAL(info) << "Local branch and masterlist file are already up to date.";
              return false;
            }
          } else
            BOOST_LOG_TRIVIAL(trace) << "Local branch heads is ahead of remote branch head.";
        } else
          BOOST_LOG_TRIVIAL(trace) << "Local branch can be fast-forwarded to remote branch.";

        if (updateBranchHead) {
            // The remote branch reference points to a particular
            // commit. Update the local branch reference to point
            // to the same commit.
          BOOST_LOG_TRIVIAL(trace) << "Syncing local branch head with remote branch head.";
          git.Call(git_reference_set_target(&git.GetData().reference2, git.GetData().reference, remote_commit_id, "Setting branch reference."));

          git_reference_free(git.GetData().reference2);
          git.GetData().reference2 = nullptr;
        }

        git_reference_free(git.GetData().reference);
        git.GetData().reference = nullptr;

        BOOST_LOG_TRIVIAL(trace) << "Performing a Git checkout of HEAD.";
        git.Call(git_checkout_head(git.GetData().repo, &git.GetData().checkout_options));
      }
    }
  }

  // Now whether the repository was cloned or updated, the working directory contains
  // the latest masterlist. Try parsing it: on failure, detach the HEAD back one commit
  // and try again.

  bool parsingFailed = false;
  std::string parsingError;
  git.SetErrorMessage((boost::format(translate("An error occurred while trying to read information on the updated masterlist. If this error happens again, try deleting the \".git\" folder in %1%.")) % repoPath.string()).str());
  do {
      // Get the HEAD revision's short ID.
    string revision = git.GetHeadShortId();

    //Now try parsing the masterlist.
    BOOST_LOG_TRIVIAL(debug) << "Testing masterlist parsing.";
    try {
      this->Load(path);

      parsingFailed = false;
    } catch (std::exception& e) {
      parsingFailed = true;
      if (parsingError.empty())
        parsingError = boost::locale::translate("Masterlist revision").str() +
        " " + string(revision) +
        ": " + e.what() +
        ". " +
        boost::locale::translate("The latest masterlist revision contains a syntax error, LOOT is using the most recent valid revision instead. Syntax errors are usually minor and fixed within hours.").str();

    //There was an error, roll back one revision.
      BOOST_LOG_TRIVIAL(error) << "Masterlist parsing failed. Masterlist revision " + string(revision) + ": " + e.what();
      git.CheckoutRevision("HEAD^");
    }
  } while (parsingFailed);

  if (!parsingError.empty())
    AppendMessage(Message(MessageType::error, parsingError));

  return true;
}
コード例 #22
0
static int32 didFailDownloadChallengeDefinitions(void *systemData, void *userData)
{
	AppendMessage("Failed to download AllChallengeDefinitions");
	return 0;
}
コード例 #23
0
int pgQueryThread::Execute()
{
	wxMutexLocker lock(m_queriesLock);

	PGresult       *result           = NULL;
	wxMBConv       &conv             = *(m_conn->conv);

	wxString       &query            = m_queries[m_currIndex]->m_query;
	int            &resultToRetrieve = m_queries[m_currIndex]->m_resToRetrieve;
	long           &rowsInserted     = m_queries[m_currIndex]->m_rowsInserted;
	Oid            &insertedOid      = m_queries[m_currIndex]->m_insertedOid;
	// using the alias for the pointer here, in order to save the result back
	// in the pgBatchQuery object
	pgSet         *&dataSet          = m_queries[m_currIndex]->m_resultSet;
	int            &rc               = m_queries[m_currIndex]->m_returnCode;
	pgParamsArray  *params           = m_queries[m_currIndex]->m_params;
	bool            useCallable      = m_queries[m_currIndex]->m_useCallable;
	pgError        &err              = m_queries[m_currIndex]->m_err;

	wxCharBuffer queryBuf = query.mb_str(conv);

	if (PQstatus(m_conn->conn) != CONNECTION_OK)
	{
		rc = pgQueryResultEvent::PGQ_CONN_LOST;
		err.msg_primary = _("Connection to the database server lost");

		return(RaiseEvent(rc));
	}

	if (!queryBuf && !query.IsEmpty())
	{
		rc = pgQueryResultEvent::PGQ_STRING_INVALID;
		m_conn->SetLastResultError(NULL, _("the query could not be converted to the required encoding."));
		err.msg_primary = _("Query string is empty");

		return(RaiseEvent(rc));
	}

	// Honour the parameters (if any)
	if (params && params->GetCount() > 0)
	{
		int    pCount = params->GetCount();
		int    ret    = 0,
		       idx    = 0;

		Oid         *pOids    = (Oid *)malloc(pCount * sizeof(Oid));
		const char **pParams  = (const char **)malloc(pCount * sizeof(const char *));
		int         *pLens    = (int *)malloc(pCount * sizeof(int));
		int         *pFormats = (int *)malloc(pCount * sizeof(int));
		// modes are used only by enterprisedb callable statement
#if defined (__WXMSW__) || (EDB_LIBPQ)
		int         *pModes   = (int *)malloc(pCount * sizeof(int));
#endif

		for (; idx < pCount; idx++)
		{
			pgParam *param = (*params)[idx];

			pOids[idx] = param->m_type;
			pParams[idx] = (const char *)param->m_val;
			pLens[idx] = param->m_len;
			pFormats[idx] = param->GetFormat();
#if defined (__WXMSW__) || (EDB_LIBPQ)
			pModes[idx] = param->m_mode;
#endif
		}

		if (useCallable)
		{
#if defined (__WXMSW__) || (EDB_LIBPQ)
			wxLogInfo(wxString::Format(
			              _("using an enterprisedb callable statement (queryid:%ld, threadid:%ld)"),
			              (long)m_currIndex, (long)GetId()));
			wxString stmt = wxString::Format(wxT("pgQueryThread-%ld-%ld"), this->GetId(), m_currIndex);
			PGresult *res = PQiPrepareOut(m_conn->conn, stmt.mb_str(wxConvUTF8),
			                              queryBuf, pCount, pOids, pModes);

			if( PQresultStatus(res) != PGRES_COMMAND_OK)
			{
				rc = pgQueryResultEvent::PGQ_ERROR_PREPARE_CALLABLE;
				err.SetError(res, &conv);

				PQclear(res);

				goto return_with_error;
			}

			ret = PQiSendQueryPreparedOut(m_conn->conn, stmt.mb_str(wxConvUTF8),
			                              pCount, pParams, pLens, pFormats, 1);

			if (ret != 1)
			{
				rc = pgQueryResultEvent::PGQ_ERROR_EXECUTE_CALLABLE;

				m_conn->SetLastResultError(NULL, _("Failed to run PQsendQuery in pgQueryThread"));
				err.msg_primary = wxString(PQerrorMessage(m_conn->conn), conv);

				PQclear(res);
				res = NULL;

				goto return_with_error;
			}

			PQclear(res);
			res = NULL;
#else
			rc = -1;
			wxASSERT_MSG(false,
			             _("the program execution flow must not reach to this point in pgQueryThread"));

			goto return_with_error;
#endif
		}
		else
		{
			// assumptions: we will need the results in text format only
			ret = PQsendQueryParams(m_conn->conn, queryBuf, pCount, pOids, pParams, pLens, pFormats, 0);

			if (ret != 1)
			{
				rc = pgQueryResultEvent::PGQ_ERROR_SEND_QUERY;

				m_conn->SetLastResultError(NULL,
				                           _("Failed to run PQsendQueryParams in pgQueryThread"));

				err.msg_primary = _("Failed to run PQsendQueryParams in pgQueryThread.\n") +
				                  wxString(PQerrorMessage(m_conn->conn), conv);

				goto return_with_error;
			}
		}
		goto continue_without_error;

return_with_error:
		{
			free(pOids);
			free(pParams);
			free(pLens);
			free(pFormats);
#if defined (__WXMSW__) || (EDB_LIBPQ)
			free(pModes);
#endif
			return (RaiseEvent(rc));
		}
	}
	else
	{
		// use the PQsendQuery api in case, we don't have any parameters to
		// pass to the server
		if (!PQsendQuery(m_conn->conn, queryBuf))
		{
			rc = pgQueryResultEvent::PGQ_ERROR_SEND_QUERY;

			err.msg_primary = _("Failed to run PQsendQueryParams in pgQueryThread.\n") +
			                  wxString(PQerrorMessage(m_conn->conn), conv);

			return(RaiseEvent(rc));
		}
	}

continue_without_error:
	int resultsRetrieved = 0;
	PGresult *lastResult = 0;

	while (true)
	{
		// This is a 'joinable' thread, it is not advisable to call 'delete'
		// function on this.
		// Hence - it does not make sense to use the function 'testdestroy' here.
		// We introduced the 'CancelExecution' function for the same purpose.
		//
		// Also, do not raise event when the query execution is cancelled to
		// avoid the bugs introduced to handle events by the event handler,
		// which is missing or being deleted.
		//
		// It will be responsibility of the compononent, using the object of
		// pgQueryThread, to take the required actions to take care of the
		// issue.
		if (m_cancelled)
		{
			m_conn->CancelExecution();
			rc = pgQueryResultEvent::PGQ_EXECUTION_CANCELLED;

			err.msg_primary = _("Execution Cancelled");

			if (lastResult)
			{
				PQclear(lastResult);
				lastResult = NULL;
			}
			AppendMessage(_("Query-thread execution cancelled...\nthe query is:"));
			AppendMessage(query);

			return rc;
		}

		if ((rc = PQconsumeInput(m_conn->conn)) != 1)
		{
			if (rc == 0)
			{
				err.msg_primary = wxString(PQerrorMessage(m_conn->conn), conv);
			}
			if (PQstatus(m_conn->conn) == CONNECTION_BAD)
			{
				err.msg_primary = _("Connection to the database server lost");
				rc = pgQueryResultEvent::PGQ_CONN_LOST;
			}
			else
			{
				rc = pgQueryResultEvent::PGQ_ERROR_CONSUME_INPUT;
			}

			return(RaiseEvent(rc));
		}

		if (PQisBusy(m_conn->conn))
		{
			Yield();
			this->Sleep(10);

			continue;
		}

		// if resultToRetrieve is given, the nth result will be returned,
		// otherwise the last result set will be returned.
		// all others are discarded
		PGresult *res = PQgetResult(m_conn->conn);

		if (!res)
			break;

		if((PQresultStatus(res) == PGRES_NONFATAL_ERROR) ||
		        (PQresultStatus(res) == PGRES_FATAL_ERROR) ||
		        (PQresultStatus(res) == PGRES_BAD_RESPONSE))
		{
			result = res;
			err.SetError(res, &conv);

			// Wait for the execution to be finished
			// We need to fetch all the results, before sending the error
			// message
			do
			{
				if (PQconsumeInput(m_conn->conn) != 1)
				{
					if (m_cancelled)
					{
						rc = pgQueryResultEvent::PGQ_EXECUTION_CANCELLED;

						// Release the result as the query execution has been cancelled by the
						// user
						if (result)
							PQclear(result);

						return rc;
					}
					goto out_of_consume_input_loop;
				}

				if ((res = PQgetResult(m_conn->conn)) == NULL)
				{
					goto out_of_consume_input_loop;
				}
				// Release the temporary results
				PQclear(res);
				res = NULL;

				if (PQisBusy(m_conn->conn))
				{
					Yield();
					this->Sleep(10);
				}
			}
			while (true);

			break;
		}

#if defined (__WXMSW__) || (EDB_LIBPQ)
		// there should be 2 results in the callable statement - the first is the
		// dummy, the second contains our out params.
		if (useCallable)
		{
			PQclear(res);
			result = PQiGetOutResult(m_conn->conn);
		}
#endif
		if (PQresultStatus(res) == PGRES_COPY_IN)
		{
			rc = PGRES_COPY_IN;
			PQputCopyEnd(m_conn->conn, "not supported by pgadmin");
		}

		if (PQresultStatus(res) == PGRES_COPY_OUT)
		{
			int copyRc;
			char *buf;
			int copyRows = 0;
			int lastCopyRc = 0;

			rc = PGRES_COPY_OUT;

			AppendMessage(_("query returned copy data:\n"));

			while((copyRc = PQgetCopyData(m_conn->conn, &buf, 1)) >= 0)
			{
				if (buf != NULL)
				{
					if (copyRows < 100)
					{
						wxString str(buf, conv);
						wxCriticalSectionLocker cs(m_criticalSection);
						m_queries[m_currIndex]->m_message.Append(str);

					}
					else if (copyRows == 100)
						AppendMessage(_("Query returned more than 100 copy rows, discarding the rest...\n"));

					PQfreemem(buf);
				}
				if (copyRc > 0)
					copyRows++;

				if (m_cancelled)
				{
					m_conn->CancelExecution();
					rc = pgQueryResultEvent::PGQ_EXECUTION_CANCELLED;

					return -1;
				}
				if (lastCopyRc == 0 && copyRc == 0)
				{
					Yield();
					this->Sleep(10);
				}
				if (copyRc == 0)
				{
					if (!PQconsumeInput(m_conn->conn))
					{
						if (PQstatus(m_conn->conn) == CONNECTION_BAD)
						{
							err.msg_primary = _("Connection to the database server lost");
							rc = pgQueryResultEvent::PGQ_CONN_LOST;
						}
						else
						{
							rc = pgQueryResultEvent::PGQ_ERROR_CONSUME_INPUT;

							err.msg_primary = wxString(PQerrorMessage(m_conn->conn), conv);
						}
						return(RaiseEvent(rc));
					}
				}
				lastCopyRc = copyRc;
			}

			res = PQgetResult(m_conn->conn);

			if (!res)
				break;
		}

		resultsRetrieved++;
		if (resultsRetrieved == resultToRetrieve)
		{
			result = res;
			insertedOid = PQoidValue(res);
			if (insertedOid && insertedOid != (Oid) - 1)
				AppendMessage(wxString::Format(_("query inserted one row with oid %d.\n"), insertedOid));
			else
				AppendMessage(wxString::Format(wxPLURAL("query result with %d row will be returned.\n", "query result with %d rows will be returned.\n",
				                                        PQntuples(result)), PQntuples(result)));
			continue;
		}

		if (lastResult)
		{
			if (PQntuples(lastResult))
				AppendMessage(wxString::Format(wxPLURAL("query result with %d row discarded.\n", "query result with %d rows discarded.\n",
				                                        PQntuples(lastResult)), PQntuples(lastResult)));
			PQclear(lastResult);
		}
		lastResult = res;
	}
out_of_consume_input_loop:

	if (!result)
		result = lastResult;

	err.SetError(result, &conv);

	AppendMessage(wxT("\n"));

	rc = PQresultStatus(result);
	if (rc == PGRES_TUPLES_OK)
	{
		dataSet = new pgSet(result, m_conn, conv, m_conn->needColQuoting);
		dataSet->MoveFirst();
	}
	else if (rc == PGRES_COMMAND_OK)
	{
		char *s = PQcmdTuples(result);
		if (*s)
			rowsInserted = atol(s);
	}
	else if (rc == PGRES_FATAL_ERROR ||
	         rc == PGRES_NONFATAL_ERROR ||
	         rc == PGRES_BAD_RESPONSE)
	{
		if (result)
		{
			AppendMessage(wxString(PQresultErrorMessage(result), conv));
			PQclear(result);
			result = NULL;
		}
		else
		{
			AppendMessage(wxString(PQerrorMessage(m_conn->conn), conv));
		}

		return(RaiseEvent(rc));
	}

	insertedOid = PQoidValue(result);
	if (insertedOid == (Oid) - 1)
		insertedOid = 0;

	return(RaiseEvent(1));
}
コード例 #24
0
void ExampleInit()
{
#define NUM_MESSAGES 30
#define MESSAGE_LEN 80

    InitMessages(NUM_MESSAGES, MESSAGE_LEN);
    AppendMessageColour(GREEN, "Checking for extension");
    
    SetButtonScale(GetButtonScale()-1);
    g_MessageBox = NewButton("MessageBox");
    if (s3eNOpenFeintAvailable())
	{
		g_NOFInitialize = NewButton("OF Initialize");
		g_NOFShutdown = NewButton("OF Shutdown");
		g_NOFLaunchDashboard = NewButton("OF LaunchDashboard");
		g_NOFTestButton1 = NewButton("OF Test 1");
		g_NOFTestButton2 = NewButton("OF Test 2");
		

		// Register for callbacks
		AppendMessageColour(BLUE, "*************");
		AppendMessage("");
		AppendMessage("");
		AppendMessage("");
		AppendMessage("");
		AppendMessage("");
		AppendMessage("");
		AppendMessage("");
		AppendMessage("");
		AppendMessage("");
		AppendMessage("");
		AppendMessage("");
		AppendMessage("");		
		AppendMessage("");
		AppendMessage("");
		AppendMessageColour(GREEN, "Registering for callback");
		
		s3eNOpenFeintRegister(S3E_NOPENFEINT_CALLBACK_PLAYER_LOGGEDIN, &playerLoggedIn, NULL);
		s3eNOpenFeintRegister(S3E_NOPENFEINT_CALLBACK_DASHBOARD_DID_APPEAR, &dashBoardAppeared, NULL);
		s3eNOpenFeintRegister(S3E_NOPENFEINT_CALLBACK_DID_DOWNLOAD_ALL_CHALLENGE_DEFINITIONS,
							  &didDownloadAllChallengeDefinitions,
							  NULL);
		s3eNOpenFeintRegister(S3E_NOPENFEINT_CALLBACK_DID_FAIL_DOWNLOAD_CHALLENGE_DEFINITIONS,
							  &didFailDownloadChallengeDefinitions,
							  NULL);
		s3eNOpenFeintRegister(S3E_NOPENFEINT_CALLBACK_USER_LAUNCHED_CHALLENGE,
							  &userLaunchedChallenge,
							  NULL);
    
    s3eNOpenFeintRegister(S3E_NOPENFEINT_CALLBACK_IS_OPENFEINT_NOTIFICATION_ALLOWED,
                          &isOpenFeintNotificationAllowed,
                          NULL);
    
	}
    else
    {
        AppendMessageColour(RED,"Could not load s3eNOpenFeint extension");
      return;
    }
  
  if(s3eFacebookAvailable())
  {
    s3eFBInit("193667878484");
  }
  else
    AppendMessageColour(RED,"Could not load s3eFacebook extension");
//  if (!s3eIOSNotificationsAvailable())
//  {
//    AppendMessageColour(RED,"Extension Not Available");
//    return;
//  }
//  else {
//      // Register IOS Notification
//      //     s3eDeviceRegister(S3E_DEVICE_PUSH_NOTIFICATION, RemotePushNotificationRecieved, 0);
//           s3eIOSNotificationsRegister(S3E_IOSNOTIFICATIONS_REMOTE, RemotePushNotificationRecieved, NULL);
//
//      // s3eIOSNotificationsGetLaunchNotification();
//  }
//	g_is3eNGAvailable = NewButton("IsNGAvailable");
}
コード例 #25
0
static int32 dashBoardAppeared(void *systemData, void *userData) 
{
	AppendMessage("Dashboard appeared");
	return 0;
}