示例#1
0
void NewInstanceDialog::OnVersion ( wxCommandEvent& event )
{
    bool btn_enabled = m_btnOK->IsEnabled();
    MinecraftVersionDialog versionDlg(this);
    versionDlg.CenterOnParent();
    MCVersion * ver;
    if(versionDlg.ShowModal() != wxID_OK)
    {
        m_btnOK->Enable(btn_enabled);
        return;
    }
    ver = versionDlg.GetSelectedVersion();
    if(!ver)
    {
        m_btnOK->Enable(btn_enabled);
        return;
    }
    m_selectedVersion = ver;
    m_versionDisplay->SetValue(m_selectedVersion->GetName());
    m_btnOK->Enable(btn_enabled);
}
示例#2
0
void
hoxCheckUpdatesUI::OnCheckUpdatesResponse( wxCommandEvent& event )
{
    const hoxResponse_APtr apResponse( wxDynamicCast(event.GetEventObject(), hoxResponse) );
    const std::string sResponse = m_pHttpSocket->getResponse();

    m_pHttpSocket->close();

    m_io_service_thread->join();   // ************ WAIT HERE
    delete m_io_service_thread;
    m_io_service_thread = NULL;

    delete m_pHttpSocket;
    m_pHttpSocket = NULL;

    this->Stop();

    const size_t nSize = sResponse.size();
    wxLogDebug("%s: Downloaded %d bytes", __FUNCTION__, nSize);

    std::string::size_type startIndex = 0;
    std::string::size_type versionIndex, osIndex, endIndex;
    const std::string sTOKEN("http://hoxchess.googlecode.com/files/HOXChess-");
    VersionInfoList versions;
    VersionInfo     ver;
    // Examples:
    //   http://hoxchess.googlecode.com/files/HOXChess-0.7.6.0-OSX.zip
    //   http://hoxchess.googlecode.com/files/HOXChess-0.7.5.0-Linux.tar.gz
    //   http://hoxchess.googlecode.com/files/HOXChess-0.7.5.0-Setup.exe
    for (;;)
    {
        startIndex = sResponse.find(sTOKEN, startIndex);
        if ( startIndex == std::string::npos ) break;
        versionIndex = startIndex + sTOKEN.size();
        osIndex = sResponse.find_first_of('-', versionIndex);
        if ( osIndex == std::string::npos ) break;
        endIndex = sResponse.find_first_of('"', osIndex);
        if ( osIndex == std::string::npos ) break;

        ver.version = sResponse.substr(versionIndex, osIndex-versionIndex);
        ver.os = sResponse.substr(osIndex+1, 1);
        ver.url = sResponse.substr(startIndex, endIndex-startIndex);
        versions.push_back(ver);
        startIndex = endIndex;
    }

    const wxOperatingSystemId osID = wxPlatformInfo::Get().GetOperatingSystemId();
    VersionInfo latestVer;

    for ( VersionInfoList::const_iterator it = versions.begin();
                                          it != versions.end(); ++it )
    {
        if (it->os == "O" && (osID & wxOS_MAC))     { latestVer = *it; break; }
        if (it->os == "L" && (osID & wxOS_UNIX))    { latestVer = *it; break; }
        if (it->os == "S" && (osID & wxOS_WINDOWS)) { latestVer = *it; break; }
    }

    hoxVersionUI versionDlg( NULL, HOX_APP_NAME,
                             wxString(latestVer.version.c_str()), wxString(latestVer.url.c_str()) );
    versionDlg.ShowModal();
}