Пример #1
0
///////////////////////////////////////////////////////////////////////////////
//
// 函数功能描述:Save线程消息分发
// 输入:
// 输出:
// 返回值:
// 其它说明:
//
///////////////////////////////////////////////////////////////////////////////
DWORD CUpdateThread::DispatchMessage(T_Message *Msg)
{
    DWORD dwRet = 0;
	if (!bIsinit)
	{
		InitServer();
		bIsinit = TRUE;
	}

    switch (Msg->dwMsgParam)
    {
	case E_FTP_GET_FILE_FROM_SERVER:  //下载网站dat文件及其他单个文件
        {
			if (bFtpDownload)
			{
				StartDownload(E_FTP_GET_FILE_FROM_SERVER,Msg->dwData);
			}
			else
			{
				StartDownload(E_HTTP_GET_FILE_FROM_SERVER,Msg->dwData);
			}
			
        }
		break;
	case MSG_TIMER:
		{
			
		}
		break;
    default:
        break;
    }
    return 0;
}
Пример #2
0
int LuaVFSDownload::DownloadArchive(lua_State* L)
{
	const std::string filename = luaL_checkstring(L, 1);
	const std::string categoryStr = luaL_checkstring(L, 2);
	if (filename.empty()) {
		return luaL_error(L, "Missing download archive name.");
	}

	DownloadEnum::Category cat;
	if (categoryStr == "map") {
		cat = DownloadEnum::CAT_MAP;
	} else if (categoryStr == "game") {
		cat = DownloadEnum::CAT_GAME;
	} else if (categoryStr == "engine") {
		cat = DownloadEnum::CAT_ENGINE;
	} else {
		return luaL_error(L, "Category must be one of: map, game, engine.");
	}

	queueIDCount++;
	queueMutex.lock();
	queue.push_back(DownloadItem(queueIDCount, filename, cat));
	queueMutex.unlock();
	eventHandler.DownloadQueued(queueIDCount, filename, categoryStr);
	if (!isDownloading) {
		if (queue.size() == 1) {
			StartDownload();
		}
	}
	return 0;
}
Пример #3
0
void StartDownload() {
	isDownloading = true;
	const DownloadItem downloadItem = queue.front();
	queue.pop_front();
	const std::string& filename = downloadItem.filename;
	DownloadEnum::Category cat = downloadItem.cat;
	int ID = downloadItem.ID;
	if (!filename.empty()) {
		LOG_L(L_DEBUG, "DOWNLOADING: %s", filename.c_str());
	}
	boost::thread {[ID, filename, cat]() {
			const int result = Download(ID, filename, cat);
			if (result == 0) {
				QueueDownloadFinished(ID);
			} else {
				QueueDownloadFailed(ID, result);
			}

			queueMutex.lock();
			if (!queue.empty()) {
				queueMutex.unlock();
				StartDownload();
			} else {
				isDownloading = false;
				queueMutex.unlock();
			}
		}
	}.detach();
}
Пример #4
0
bool Installer::Install(const QString& appName, const QString& appVersion, eAppType type) {
    Logger::GetInstance()->AddLog(tr("Installing %1").arg(appName));

    const AppsConfig::AppMap* apps = GetAppMap(type);
    if (!apps)
        return false;

    AppsConfig::AppMap::const_iterator appIter = apps->find(appName);
    if (appIter == apps->end())
        return false;

    AppsConfig::AppVersion::const_iterator iter = appIter.value().find(appVersion);
    if (iter == appIter->end())
        return false;

    const AppConfig& config = iter.value();

    m_pReply = m_pNetworkManager->get(QNetworkRequest(config.m_Url));
    connect(m_pReply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(OnDownloadProgress(qint64, qint64)));
    connect(m_pReply, SIGNAL(finished()), this, SLOT(OnAppDownloaded()));
    m_pReply->setProperty(INSTALL_TYPE, type);
    m_pReply->setProperty(INSTALL_NAME, appName);
    m_pReply->setProperty(INSTALL_VERISON, appVersion);

    emit StartDownload();

    return true;
}
Пример #5
0
void CEvolverDlg::OnTimer(UINT nIDEvent)
{
	if(nIDEvent == m_NotifyTimer)
	{
		if(m_Counter == 0)
		{
			// Show changelog
			CFrameMain* pFrame = (CFrameMain*) AfxGetApp()->GetMainWnd();
			pFrame->OpenBrowser("http://www.gnucleus.com/update2/ChangeLog.txt");
		}

		m_Counter++;
		m_progBar.SetPos(m_Counter);
		m_stcProgress.SetWindowText("Evolution in " + DWrdtoStr((150 - m_Counter) / 10) + " seconds...");
	
		if(m_Counter == 150)
			StartDownload();
	}

	if(nIDEvent == m_UpgradeTimer)
	{
		// Get File IDs
		std::vector<int> FileIDs;

		VARIANT var = m_autUpdate->GetFileIDs();
		SAFEARRAY* psa = var.parray;

		int* nArray;
		SafeArrayAccessData(psa, reinterpret_cast<void**> (&nArray));

		for(int i = 0; i < psa->rgsabound->cElements; i++)
			FileIDs.push_back(nArray[i]);

		SafeArrayUnaccessData(psa);
		VariantClear(&var);

		// Update status
		if(m_autUpdate->GetTotalCompleted())
			m_stcProgress.SetWindowText("Downloading Files...");

		if(m_autUpdate->GetTotalSize())
			m_progBar.SetPos(m_autUpdate->GetTotalCompleted() * 100 / m_autUpdate->GetTotalSize());
	}

	if(nIDEvent == m_CloseTimer)
	{
		m_Counter++;
		m_progBar.SetPos(m_Counter);
		m_stcProgress.SetWindowText("Restarting in " + DWrdtoStr((150 - m_Counter) / 10) + " seconds...");
	
		if(m_Counter == 150)
		{
			Restart();
			return;
		}
	}

	CDialog::OnTimer(nIDEvent);
}
Пример #6
0
//==========================================================
//--Guosen 2012.8.7
//int     
//CSMLoginScene::OnProcess(int nPercent)
//{
//    CUIExp* pProcess = (CUIExp*)m_layer->GetChild(ID_LOADING_PROCESS);
//	if (!pProcess) {
//        return 0;
//    }
//    pProcess->SetProcess(nPercent);
//    return 0;
//}
//==========================================================
//--Guosen 2012.8.7
//int     
//CSMLoginScene::OnFail(const char* pszStrErr)
//{
//    return 0;
//}
//==========================================================
//--Guosen 2012.8.7
//int		
//CSMLoginScene::OnComplete(void)
//{
//    m_bUpdOk = true;
//    return 0; 
//}
//===========================================================================
// 开启更新
bool CSMLoginScene::StartUpdate()
{
	if ( kDeqUpdateUrl.empty() )
	{
		return false;
	}
	//请求第一个包
	std::string url = *kDeqUpdateUrl.begin();
	m_strUpdateURL	= url;
	m_pTimer->SetTimer( this, TAG_TIMER_UPDATE, 0.5f );	
	StartDownload();
	return true;
}
Пример #7
0
void CEvolverDlg::OnBnClickedButtonEvolve()
{
	if(m_NotifyTimer)
	{
		StartDownload();
	}

	// Else Restart 
	else
	{
		Restart();
		return;
	}
}
Пример #8
0
client_download_status
UserDownload(char * ticket)
{
	client_download_status ret = DOWNLOAD_OK;
	request_t request;
	download_header_t download_info;
	FILE *fd;
	void *data;
	u_size size;
	
	strcpy(request.ticket,ticket);
	size = GetRequestData(request,&data);
	/* Mando el pedido */
	download_info = SendDownloadRequest(data, size);
	free(data);
	/* Proceso la respuesta */
	switch (download_info.ret_code) {
		case __DOWNLOAD_ERROR__:
			ret = DOWNLOAD_ERROR;
			break;
		case __USER_ACCESS_DENY__:
			ret = DOWNLOAD_USER_NOT_LOG;
			/* El usuario debe loguearse devuelta */
			if( strcmp(log_user, "anonimo") != 0 )
				strcpy(log_user, "anonimo");
			break;
		case __USER_IS_NOT_LOG__:
			ret = DOWNLOAD_USER_NOT_LOG;
			/* El usuario debe loguearse devuelta */
			if( strcmp(log_user, "anonimo") != 0 )
				strcpy(log_user, "anonimo");
			break;
		case __DOWNLOAD_START__:
			ret = DOWNLOAD_OK;
			/* Reservo espacio en el disco local para el archivo que voy a bajar */
			printf("Archivo a descargar (%s)\n",download_info.title);
			if( (fd = CreateFile(download_info.title,download_info.size)) == NULL )
				ret = DOWNLOAD_ERROR;
			/* Comienzo a descargar */
			else if( StartDownload(fd,ticket) == ERROR )
				ret = DOWNLOAD_ERROR;
			break;
		default:
			ret = DOWNLOAD_CONNECT_ERROR;
			break;
	}
	
	return ret;
}
Пример #9
0
void UBPDownloader::HandleHeaderReceived(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded)
{
	if (bSucceeded && HttpResponse.IsValid())
	{
		FString FileLength = HttpResponse->GetHeader(L"Content-Length");// ();
		FileTotalBytes = (float)UKismetStringLibrary::Conv_StringToInt(FileLength);
		//Start Downloading
		StartDownload();
	}
	else
	{
		RemoveFromRoot();
		OnFail.Broadcast(0.f);//FilePath
	}
}
Пример #10
0
LRESULT CUpdateDlg::OnBnClickedButtonUpdate(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	GetDlgItem(IDC_BUTTON_UPDATE).ShowWindow(SW_HIDE);

	CString updater = m_ProPath + _T("mupdater.exe");
	CopyFileW(m_Progrom, updater, FALSE);
	if(FileExist(updater)) {
		CString sCmdLine;
		sCmdLine.Format(_T("--download-update --filename \"%s\" --url \"%s\" --urlbase \"%s\""),
			m_filename.c_str(), m_url.c_str(), m_urlbase.c_str());
		ShellExecute(NULL, _T("open"), updater, sCmdLine, NULL, SW_SHOW);

		PostMessage(WM_CLOSE, 0, 0);
	} else {
		StartDownload();
	}

	return 0;
}
Пример #11
0
LRESULT CUpdateDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	CenterWindow(GetParent());

	// set icons
	HICON hIcon = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME), 
		IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);
	SetIcon(hIcon, TRUE);

	HICON hIconSmall = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME), 
		IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
	SetIcon(hIconSmall, FALSE);
	
	m_progress.Attach(GetDlgItem(IDC_PROGRESS));

	m_progress.SetRange(0,100);
	m_progress.SetPos(0);

	m_progress.ShowWindow(SW_HIDE);

	DoDataExchange(false);

	s_uTBBC = RegisterWindowMessage(L"TaskbarButtonCreated");
	HINSTANCE user32 = GetModuleHandle(L"user32.dll");
	if(user32) ChangeWindowMessageFilterDLL = (ChangeWindowMessageFilterFunction)GetProcAddress(user32, "ChangeWindowMessageFilter");
	if(ChangeWindowMessageFilterDLL) ChangeWindowMessageFilterDLL(s_uTBBC, MSGFLT_ADD);

	SetWindowPos(HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);

	m_info1 = str_checkupdate;

	m_path = m_ProPath.GetBuffer();
	m_ProPath.ReleaseBuffer();
	m_path += L"update_mp";

	if(m_bDownload)
		StartDownload();
	else {
		SetTimer(0, 100, 0);
		CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)CheckUpdate, this, 0, 0);
	}
	return TRUE;
}
Пример #12
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    this->setWindowTitle(tr("Launcher %1").arg(QString(LAUNCER_VER)));

    m_pInstaller = new Installer(this);
    connect(m_pInstaller, SIGNAL(SoftWareAvailable(AvailableSoftWare)), this, SLOT(AvailableSoftWareUpdated(AvailableSoftWare)));
    connect(m_pInstaller, SIGNAL(StartDownload()), this, SLOT(OnDownloadStarted()));
    connect(m_pInstaller, SIGNAL(DownloadFinished()), this, SLOT(OnDownloadFinished()));
    connect(m_pInstaller, SIGNAL(DownloadProgress(int)), this, SLOT(OnDownloadProgress(int)));

    m_pUpdateTimer = new QTimer(this);
    connect(m_pUpdateTimer, SIGNAL(timeout()), this, SLOT(on_btnRefresh_clicked()));
    m_pUpdateTimer->start(Settings::GetInstance()->GetUpdateTimerInterval());

    ui->stableTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
    ui->developmentTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
    ui->dependenciesTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);

    connect(ui->stableTable, SIGNAL(itemSelectionChanged()), this, SLOT(UpdateBtn()));
    connect(ui->dependenciesTable, SIGNAL(itemSelectionChanged()), this, SLOT(UpdateBtn()));
    connect(ui->developmentTable, SIGNAL(itemSelectionChanged()), this, SLOT(UpdateBtn()));
    connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(UpdateBtn()));

    connect(ui->stableTable, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(on_btnRun_clicked()));
    connect(ui->developmentTable, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(on_btnRun_clicked()));

    connect(Logger::GetInstance(), SIGNAL(LogAdded(QString)), this, SLOT(OnLogAdded(QString)));

    ui->downloadProgress->setVisible(false);
    ui->downloadProgress->setRange(0, 100);

    m_bBusy = false;
    UpdateBtn();
    m_pInstaller->Init();
}
Пример #13
0
size_t VSICurlStreamingHandle::Read( void *pBuffer, size_t nSize, size_t nMemb )
{
    GByte* pabyBuffer = (GByte*)pBuffer;
    size_t nBufferRequestSize = nSize * nMemb;
    if (nBufferRequestSize == 0)
        return 0;
    size_t nRemaining = nBufferRequestSize;

    AcquireMutex();
    int bHastComputedFileSizeLocal = bHastComputedFileSize;
    vsi_l_offset fileSizeLocal = fileSize;
    ReleaseMutex();

    if (bHastComputedFileSizeLocal && curOffset >= fileSizeLocal)
    {
        CPLDebug("VSICURL", "Read attempt beyond end of file");
        bEOF = TRUE;
    }
    if (bEOF)
        return 0;

    if (curOffset < nRingBufferFileOffset)
        PutRingBufferInCache();

    if (ENABLE_DEBUG)
        CPLDebug("VSICURL", "Read [" CPL_FRMT_GUIB ", " CPL_FRMT_GUIB "[ in %s",
                 curOffset, curOffset + nBufferRequestSize, pszURL);

#ifdef notdef
    if( pCachedData != NULL && nCachedSize >= 1024 &&
        nRecomputedChecksumOfFirst1024Bytes == 0 )
    {
        for(size_t i = 0; i < 1024 / sizeof(int); i ++)
        {
            int nVal;
            memcpy(&nVal, pCachedData + i * sizeof(int), sizeof(int));
            nRecomputedChecksumOfFirst1024Bytes += nVal;
        }

        if( bHastComputedFileSizeLocal )
        {
            poFS->AcquireMutex();
            CachedFileProp* cachedFileProp = poFS->GetCachedFileProp(pszURL);
            if( cachedFileProp->nChecksumOfFirst1024Bytes == 0 )
            {
                cachedFileProp->nChecksumOfFirst1024Bytes = nRecomputedChecksumOfFirst1024Bytes;
            }
            else if( nRecomputedChecksumOfFirst1024Bytes != cachedFileProp->nChecksumOfFirst1024Bytes )
            {
                CPLDebug("VSICURL", "Invalidating previously cached file size. First bytes of file have changed!");
                AcquireMutex();
                bHastComputedFileSize = FALSE;
                cachedFileProp->bHastComputedFileSize = FALSE;
                cachedFileProp->nChecksumOfFirst1024Bytes = 0;
                ReleaseMutex();
            }
            poFS->ReleaseMutex();
        }
    }
#endif

    /* Can we use the cache ? */
    if( pCachedData != NULL && curOffset < nCachedSize )
    {
        size_t nSz = MIN(nRemaining, (size_t)(nCachedSize - curOffset));
        if (ENABLE_DEBUG)
            CPLDebug("VSICURL", "Using cache for [%d, %d[ in %s",
                     (int)curOffset, (int)(curOffset + nSz), pszURL);
        memcpy(pabyBuffer, pCachedData + curOffset, nSz);
        pabyBuffer += nSz;
        curOffset += nSz;
        nRemaining -= nSz;
    }

    /* Is the request partially covered by the cache and going beyond file size ? */
    if ( pCachedData != NULL && bHastComputedFileSizeLocal &&
         curOffset <= nCachedSize &&
         curOffset + nRemaining > fileSizeLocal &&
         fileSize == nCachedSize )
    {
        size_t nSz = (size_t) (nCachedSize - curOffset);
        if (ENABLE_DEBUG && nSz != 0)
            CPLDebug("VSICURL", "Using cache for [%d, %d[ in %s",
                    (int)curOffset, (int)(curOffset + nSz), pszURL);
        memcpy(pabyBuffer, pCachedData + curOffset, nSz);
        pabyBuffer += nSz;
        curOffset += nSz;
        nRemaining -= nSz;
        bEOF = TRUE;
    }

    /* Has a Seek() being done since the last Read() ? */
    if (!bEOF && nRemaining > 0 && curOffset != nRingBufferFileOffset)
    {
        /* Backward seek : we need to restart the download from the start */
        if (curOffset < nRingBufferFileOffset)
            StopDownload();

        StartDownload();

#define SKIP_BUFFER_SIZE    32768
        GByte* pabyTmp = (GByte*)CPLMalloc(SKIP_BUFFER_SIZE);

        CPLAssert(curOffset >= nRingBufferFileOffset);
        vsi_l_offset nBytesToSkip = curOffset - nRingBufferFileOffset;
        while(nBytesToSkip > 0)
        {
            vsi_l_offset nBytesToRead = nBytesToSkip;

            AcquireMutex();
            if (nBytesToRead > oRingBuffer.GetSize())
                nBytesToRead = oRingBuffer.GetSize();
            if (nBytesToRead > SKIP_BUFFER_SIZE)
                nBytesToRead = SKIP_BUFFER_SIZE;
            oRingBuffer.Read(pabyTmp, (size_t)nBytesToRead);

            /* Signal to the producer that we have ingested some bytes */
            CPLCondSignal(hCondConsumer);
            ReleaseMutex();

            if (nBytesToRead)
                AddRegion(nRingBufferFileOffset, (size_t)nBytesToRead, pabyTmp);

            nBytesToSkip -= nBytesToRead;
            nRingBufferFileOffset += nBytesToRead;

            if (nBytesToRead == 0 && nBytesToSkip != 0)
            {
                if (ENABLE_DEBUG)
                    CPLDebug("VSICURL", "Waiting for writer to produce some bytes...");

                AcquireMutex();
                while(oRingBuffer.GetSize() == 0 && bDownloadInProgress)
                    CPLCondWait(hCondProducer, hRingBufferMutex);
                int bBufferEmpty = (oRingBuffer.GetSize() == 0);
                ReleaseMutex();

                if (bBufferEmpty && !bDownloadInProgress)
                    break;
            }
        }

        CPLFree(pabyTmp);

        if (nBytesToSkip != 0)
        {
            bEOF = TRUE;
            return 0;
        }
    }

    if (!bEOF && nRemaining > 0)
    {
        StartDownload();
        CPLAssert(curOffset == nRingBufferFileOffset);
    }

    /* Fill the destination buffer from the ring buffer */
    while(!bEOF && nRemaining > 0)
    {
        AcquireMutex();
        size_t nToRead = oRingBuffer.GetSize();
        if (nToRead > nRemaining)
            nToRead = nRemaining;
        oRingBuffer.Read(pabyBuffer, nToRead);

        /* Signal to the producer that we have ingested some bytes */
        CPLCondSignal(hCondConsumer);
        ReleaseMutex();

        if (nToRead)
            AddRegion(curOffset, nToRead, pabyBuffer);

        nRemaining -= nToRead;
        pabyBuffer += nToRead;
        curOffset += nToRead;
        nRingBufferFileOffset += nToRead;

        if (nToRead == 0 && nRemaining != 0)
        {
            if (ENABLE_DEBUG)
                CPLDebug("VSICURL", "Waiting for writer to produce some bytes...");

            AcquireMutex();
            while(oRingBuffer.GetSize() == 0 && bDownloadInProgress)
                CPLCondWait(hCondProducer, hRingBufferMutex);
            int bBufferEmpty = (oRingBuffer.GetSize() == 0);
            ReleaseMutex();

            if (bBufferEmpty && !bDownloadInProgress)
                break;
        }
    }

    if (ENABLE_DEBUG)
        CPLDebug("VSICURL", "Read(%d) = %d",
                (int)nBufferRequestSize, (int)(nBufferRequestSize - nRemaining));
    size_t nRet = (nBufferRequestSize - nRemaining) / nSize;
    if (nRet < nMemb)
        bEOF = TRUE;

    return nRet;
}
Пример #14
0
//===========================================================================
void CSMLoginScene::OnTimer( OBJID idTag )
{
	static bool bFirst = true;

	if (bFirst)
	{
		LOGD("Entry First OnTimer");
		//idTag = TAG_TIMER_UPDATE;
		bFirst = false;
	}

	if ( idTag == TAG_TIMER_UPDATE ) 
	{
		if ( !rename( m_strSavePath.c_str(), m_strSavePath.c_str() ) )
		{
			if ( remove( m_strSavePath.c_str() ) )
			{ 
				m_pTimer->KillTimer(this, TAG_TIMER_UPDATE);
				return;
			}
		}

		FromUrl(m_strUpdateURL.c_str());
		ToPath(m_strSavePath.c_str()); 
		Download();
		m_pTimer->KillTimer(this, TAG_TIMER_UPDATE);
	}
	else if ( idTag == TAG_TIMER_DOWNLOAD_SUCCESS )
	{
		m_pTimer->KillTimer(this, TAG_TIMER_DOWNLOAD_SUCCESS);
        
		LOGD("Entry TAG_TIMER_DOWNLOAD_SUCCESS process.");
		UnZipFile( m_strSavePath.c_str(), m_strCachePath.c_str());
	}
    else if ( idTag == TAG_TIMER_UNZIP_SUCCESS )
	{
		m_pTimer->KillTimer(this, TAG_TIMER_UNZIP_SUCCESS);
		if ( remove(m_strSavePath.c_str()) )
		{
		    NDLog("delete:%s failed",m_strSavePath.c_str());
		    //return;
		}
        std::string szListFile = NDPath::GetCashesPath() + SZ_DEL_FILE;
		DeleteFileFromFile( szListFile );
    
		if(kDeqUpdateUrl.size() > 0)
		{
		    kDeqUpdateUrl.pop_front();
		}

		PackageCount++;
		//查找下载队列
		if (kDeqUpdateUrl.size() > 0)
		{
		    //定义保存路径
		    m_strUpdateURL = *kDeqUpdateUrl.begin();
		    //m_savePath = [[NSString stringWithFormat:@"%s/update%d.zip", m_cachPath.c_str(), PackageCount] UTF8String];
		    m_pTimer->SetTimer( this, TAG_TIMER_UPDATE, 0.5f );
		    StartDownload();
		}
		else
		{
		    //跳转到启动界面
		    StartEntry();
		}
	}
	else if ( TAG_TIMER_CHECK_WIFI == idTag )
	{
		//如果检测没开启WIFI则不断检测//
    	if ( NDBeforeGameMgrObj.isWifiNetWork() )
    	{
			m_pTimer->KillTimer( this, TAG_TIMER_CHECK_WIFI );
			CloseConfirmDlg();
			StartUpdate();
    	}
	}
	else if ( TAG_TIMER_CHECK_UPDATE == idTag )
	{
        m_pTimer->KillTimer(this, TAG_TIMER_CHECK_UPDATE);
        ShowUpdateOff();
	}
	else if ( TAG_TIMER_CHECK_COPY == idTag )
	{
        int copyStatus = NDBeforeGameMgr::GetCopyStatus();
        switch (copyStatus) 
        {
            case -1:
                m_pTimer->KillTimer( this, TAG_TIMER_CHECK_COPY );
                //NSLog( @"Copy files error!" );
                exit(0);
                break;
            case 0:
                break;
            case 1:
                m_pTimer->KillTimer( this, TAG_TIMER_CHECK_COPY );
                NDBeforeGameMgrObj.doNDSdkLogin();
                ShowWaitingAni();
                break;
            default:
                break;
        }
	}
    else if ( TAG_TIMER_FIRST_RUN == idTag )
	{
		LOGD("Entry TAG_TIMER_FIRST_RUN == idTag");
		m_pTimer->KillTimer( this, TAG_TIMER_FIRST_RUN );
		CreateUpdateUILayer();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
		CCLog( "@@login02: to call OnEvent_LoginOKNormal()\r\n" );

        m_iAccountID = NDBeforeGameMgrObj.GetCurrentUser();
		OnEvent_LoginOKNormal(m_iAccountID);
#else
#ifdef USE_MGSDK
		NDUIImage * pImage = (NDUIImage *)m_pLayerUpdate->GetChild( TAG_CTRL_PIC_BG);
		if ( pImage )
		{
			NDPicture * pPicture = new NDPicture;
			pPicture->Initialization( NDPath::GetUIImgPath( SZ_MOBAGE_BG_PNG_PATH ).c_str() );
			pImage->SetPicture( pPicture, true );
		}
#endif
#if CACHE_MODE == 1
    	if ( NDBeforeGameMgrObj.CheckFirstTimeRuning() )
        {
        	if ( m_pLabelPromtp )
            {
        		m_pLabelPromtp->SetText( NDCommonCString2(SZ_FIRST_INSTALL).c_str() );
        		m_pLabelPromtp->SetVisible( true );
                ShowWaitingAni();
#ifdef USE_MGSDK
        		m_pLabelPromtp->SetVisible( false );//Mobage的版本暂将文字绘在背景图上
#endif
            }
            m_pTimer->SetTimer( this, TAG_TIMER_CHECK_COPY, 0.5f );
        }
        else
#endif
        {
            NDBeforeGameMgrObj.doNDSdkLogin();
            ShowWaitingAni();
		}
#endif
    	//CreateUpdateUILayer();
		//NDBeforeGameMgrObj.CheckClientVersion(SZ_UPDATE_URL);
	}
	else if ( TAG_TIMER_LOAD_RES_OK == idTag )
	{
		m_pTimer->KillTimer( this, TAG_TIMER_LOAD_RES_OK );
		CloseWaitingAni();
		CloseUpdateUILayer();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
		//if ( m_iAccountID == 0 )
		m_iAccountID = ScriptMgrObj.excuteLuaFuncRetN( "GetAccountID", "Login_ServerUI" );
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
		m_iAccountID = NDBeforeGameMgrObj.GetCurrentUser();
#endif
		ScriptMgrObj.excuteLuaFunc( "ShowUI", "Entry", m_iAccountID );
		//    ScriptMgrObj.excuteLuaFunc("ProecssLocalNotification", "MsgLoginSuc");
	}
}
Пример #15
0
void DemoInit(NaCLContext* psNaCLContext, int width, int height)
{
    PP_Resource context = psNaCLContext->hRenderContext;
    PPB_OpenGLES2* gl = psNaCLContext->psGL;

    const float aspectRatio = (float)width / (float)height;
    const float fieldOfView = 45.0f;

    if(!psDemoContext)
    {
        psDemoContext = new DemoContext();

#ifdef ENABLE_LOADING_ICON
        DownloadContext* psLoadingTextureDownloadContext = &psDemoContext->sDownloadLoadingTexture;
        psLoadingTextureDownloadContext->id = 2;
        psLoadingTextureDownloadContext->iDownloaded = 0;

        StartDownload(psNaCLContext, "dload/loading.jpg", psLoadingTextureDownloadContext, FileDownloaded);
#endif

        DownloadContext* psBaseTextureDownloadContext = &psDemoContext->sDownloadBaseTexture;
        psBaseTextureDownloadContext->id = 0;
        psBaseTextureDownloadContext->iDownloaded = 0;

        StartDownload(psNaCLContext, "dload/checkerboard.jpg", psBaseTextureDownloadContext, FileDownloaded);

        DownloadContext* psMeshDownloadContext = &psDemoContext->sDownloadMesh;
        psMeshDownloadContext->id = 1;
        psMeshDownloadContext->iDownloaded = 0;

        StartDownload(psNaCLContext, "dload/cube.json", psMeshDownloadContext, FileDownloaded);
    }

#if 0
#ifdef ENABLE_LOADING_ICON
    if(psDemoContext->sDownloadLoadingTexture.iDownloaded == 2)
    {
        //Re-create GL objects
        psDemoContext->sDownloadLoadingTexture.iDownloaded = 1;
    }
#endif

    if(psDemoContext->sDownloadBaseTexture.iDownloaded == 2)
    {
        //Re-create GL objects
        psDemoContext->sDownloadBaseTexture.iDownloaded = 1;
    }

    if(psDemoContext->sDownloadMesh.iDownloaded == 2)
    {
        //Re-create GL objects
        psDemoContext->sDownloadMesh.iDownloaded = 1;
    }
#endif

    Identity(psDemoContext->sMeshTransform.projection);
    Persp(psDemoContext->sMeshTransform.projection, fieldOfView, aspectRatio,
        1.0, 1000.0);

    if(!psDemoContext->sDisplacementMap.image) //First time init has been called
    {
        int i;

        GLubyte* textureImage = new GLubyte[iDispMapWidth*iDispMapHeight];

        for(i=0; i<(iDispMapWidth*iDispMapHeight); ++i)
        {
            textureImage[i] = 0;
        }

        psDemoContext->sDisplacementMap.image = textureImage;

        gettimeofday(&psDemoContext->startTime, NULL);

        psDemoContext->ui64BaseTimeMS = GetElapsedTimeMS();
        psDemoContext->fAngleY = 0;
        psDemoContext->fAngleX = 0;
        psDemoContext->fDispCoeff = 0.5f;
    }

    psDemoContext->hDisplacementMapShader = CreateProgram(context, gl, psz_dispmapped_vs, psz_textured_ps);

#ifdef ENABLE_LOADING_ICON
    psDemoContext->hBaseMapShader = CreateProgram(context, gl, psz_textured_vs, psz_textured_ps);

    CreateQuadMesh(context,
        gl,
        &psDemoContext->sQuad.iIdxCount,
        &psDemoContext->sQuad.iVtxCount,
        &psDemoContext->sQuad.hVBO,
        &psDemoContext->sQuad.hIBO);
#endif

    gl->GenTextures(context, 1, &psDemoContext->sDisplacementMap.hTextureGL);

    gl->BindTexture(context, GL_TEXTURE_2D, psDemoContext->sDisplacementMap.hTextureGL);

    gl->TexImage2D(context, GL_TEXTURE_2D, 0, GL_LUMINANCE, iDispMapWidth, iDispMapHeight, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, psDemoContext->sDisplacementMap.image);

    gl->TexParameteri(context, GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    gl->TexParameteri(context, GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    Identity(psDemoContext->sMeshTransform.camera);
    LookAt(psDemoContext->sMeshTransform.camera,
        0.f,0.f,3.f,
        0.f,0.f,-5.f,
        0.f,1.f,0.f);

    gl->Enable(context, GL_CULL_FACE);
}
void CDownloadMenu::HandleCommands( const idStr &cmd, idUserInterface *gui ) {
	if( cmd == "mainmenu_heartbeat" ) {
		// Update download progress
		if( _selectedMods.Num() > 0 ) {
			UpdateDownloadProgress( gui );
		}
		// Do we have a pending mission list request?
		if( gameLocal.m_MissionManager->IsDownloadableModsRequestInProgress() ) {
			CMissionManager::RequestStatus status =
				gameLocal.m_MissionManager->ProcessReloadDownloadableModsRequest();
			switch( status ) {
			case CMissionManager::FAILED: {
				gui->HandleNamedEvent( "onAvailableMissionsRefreshed" ); // hide progress dialog
				// Issue a failure message
				gameLocal.Printf( "Connection Error.\n" );
				GuiMessage msg;
				msg.title = common->Translate( "#str_02140" );	// Unable to contact Mission Archive
				msg.message = common->Translate( "#str_02007" );	// Cannot connect to server.
				msg.type = GuiMessage::MSG_OK;
				msg.okCmd = "close_msg_box";
				gameLocal.AddMainMenuMessage( msg );
			}
			break;
			case CMissionManager::SUCCESSFUL: {
				gui->HandleNamedEvent( "onAvailableMissionsRefreshed" ); // hide progress dialog
				UpdateGUI( gui );
				UpdateDownloadProgress( gui );
			}
			break;
			default:
				break;
			};
		}
		// Process pending details download request
		if( gameLocal.m_MissionManager->IsModDetailsRequestInProgress() ) {
			CMissionManager::RequestStatus status =
				gameLocal.m_MissionManager->ProcessReloadModDetailsRequest();
			switch( status ) {
			case CMissionManager::FAILED: {
				gui->HandleNamedEvent( "onDownloadableMissionDetailsDownloadFailed" ); // hide progress dialog
				// Issue a failure message
				gameLocal.Printf( "Connection Error.\n" );
				GuiMessage msg;
				msg.title = common->Translate( "#str_02008" );	// Mission Details Download Failed
				msg.message = common->Translate( "#str_02009" );	// Failed to download the details XML file.
				msg.type = GuiMessage::MSG_OK;
				msg.okCmd = "close_msg_box";
				gameLocal.AddMainMenuMessage( msg );
			}
			break;
			case CMissionManager::SUCCESSFUL: {
				gui->HandleNamedEvent( "onDownloadableMissionDetailsLoaded" ); // hide progress dialog
				UpdateModDetails( gui );
				UpdateScreenshotItemVisibility( gui );
			}
			break;
			default:
				break;
			};
		}
		// Process pending screenshot download request
		if( gameLocal.m_MissionManager->IsMissionScreenshotRequestInProgress() ) {
			CMissionManager::RequestStatus status =
				gameLocal.m_MissionManager->ProcessMissionScreenshotRequest();
			switch( status ) {
			case CMissionManager::FAILED: {
				gui->HandleNamedEvent( "onFailedToDownloadScreenshot" );
				// Issue a failure message
				gameLocal.Printf( "Connection Error.\n" );
				GuiMessage msg;
				msg.title = common->Translate( "#str_02002" ); // "Connection Error"
				msg.message = common->Translate( "#str_02139" ); // "Failed to download the screenshot file."
				msg.type = GuiMessage::MSG_OK;
				msg.okCmd = "close_msg_box";
				gameLocal.AddMainMenuMessage( msg );
			}
			break;
			case CMissionManager::SUCCESSFUL: {
				// Load data into GUI
				// Get store "next" number from the GUI
				int nextScreenNum = gui->GetStateInt( "av_mission_next_screenshot_num" );
				UpdateNextScreenshotData( gui, nextScreenNum );
				// Ready to fade
				gui->HandleNamedEvent( "onStartFadeToNextScreenshot" );
			}
			break;
			default:
				break;
			};
		}
	} else if( cmd == "refreshavailablemissionlist" ) {
		if( !cv_tdm_allow_http_access.GetBool() || gameLocal.m_HttpConnection == NULL ) {
			gui->HandleNamedEvent( "onAvailableMissionsRefreshed" ); // hide progress dialog
			// HTTP Access disallowed, display message
			gameLocal.Printf( "HTTP requests disabled, cannot check for available missions.\n" );
			GuiMessage msg;
			msg.type = GuiMessage::MSG_OK;
			msg.okCmd = "close_msg_box";
			msg.title = common->Translate( "#str_02140" ); // "Unable to contact Mission Archive"
			msg.message = common->Translate( "#str_02141" ); // "HTTP Requests have been disabled,\n cannot check for available missions."
			gameLocal.AddMainMenuMessage( msg );
			return;
		}
		// Clear data before updating the list
		_selectedListTop = 0;
		_selectedMods.Clear();
		UpdateGUI( gui );
		UpdateDownloadProgress( gui );
		// Start refreshing the list, will be handled in mainmenu_heartbeat
		if( gameLocal.m_MissionManager->StartReloadDownloadableMods() == -1 ) {
			gameLocal.Error( "No URLs specified to download the mission list XML." );
		}
	} else if( cmd == "ondownloadablemissionselected" ) {
		int selectedMission = gui->GetStateInt( "av_mission_selected" );
		int missionIndex = selectedMission + _availListTop;
		// Update mission details
		const DownloadableModList &mods = gameLocal.m_MissionManager->GetDownloadableMods();
		if( missionIndex > mods.Num() ) {
			return;
		}
		gui->SetStateString( "av_mission_title", mods[missionIndex]->title );
		gui->SetStateString( "av_mission_author", mods[missionIndex]->author );
		gui->SetStateString( "av_mission_release_date", mods[missionIndex]->releaseDate );
		gui->SetStateString( "av_mission_type", mods[missionIndex]->type == DownloadableMod::Multi ?
							 common->Translate( "#str_04353" ) : // Campaign
							 common->Translate( "#str_04352" ) ); // Single Mission
		gui->SetStateString( "av_mission_version", va( "%d", mods[missionIndex]->version ) );
		gui->SetStateString( "av_mission_size", va( "%0.1f %s", mods[missionIndex]->sizeMB, common->Translate( "#str_02055" ) ) );	// MB
		gui->SetStateBool( "av_mission_details_visible", true );
		gui->HandleNamedEvent( "UpdateAvailableMissionColours" );
	} else if( cmd == "onselectmissionfordownload" ) {
		int selectedMission = gui->GetStateInt( "av_mission_selected" );
		int missionIndex = selectedMission + _availListTop;
		_selectedMods.AddUnique( missionIndex );
		gui->SetStateInt( "av_mission_selected", -1 );
		gui->SetStateBool( "av_mission_details_visible", false );
		UpdateGUI( gui );
	} else if( cmd == "ondeselectmissionfordownload" ) {
		int selectedItem = gui->GetStateInt( "dl_mission_selected" );
		int index = selectedItem + _selectedListTop;
		if( index >= _selectedMods.Num() ) {
			return;
		}
		_selectedMods.Remove( _selectedMods[index] );
		UpdateGUI( gui );
		UpdateDownloadProgress( gui );
	} else if( cmd == "ondownloadablemissionscrollup" ) {
		int numMissionsPerPage = gui->GetStateInt( "packagesPerPage", "5" );
		_availListTop -= numMissionsPerPage;
		if( _availListTop < 0 ) {
			_availListTop = 0;
		}
		UpdateGUI( gui );
	} else if( cmd == "ondownloadablemissionscrolldown" ) {
		int numMissionsPerPage = gui->GetStateInt( "packagesPerPage", "5" );
		_availListTop += numMissionsPerPage;
		UpdateGUI( gui );
	} else if( cmd == "onselectedmissionscrollup" ) {
		int itemsPerPage = gui->GetStateInt( "selectedPackagesPerPage", "5" );
		_selectedListTop -= itemsPerPage;
		if( _selectedListTop < 0 ) {
			_selectedListTop = 0;
		}
		UpdateGUI( gui );
	} else if( cmd == "onselectedmissionscrolldown" ) {
		int itemsPerPage = gui->GetStateInt( "selectedPackagesPerPage", "5" );
		_selectedListTop += itemsPerPage;
		UpdateGUI( gui );
	} else if( cmd == "ondownloadablemissionshowdetails" ) {
		int selectedMission = gui->GetStateInt( "av_mission_selected" );
		int missionIndex = selectedMission + _availListTop;
		// Issue a new download request
		gameLocal.m_MissionManager->StartDownloadingModDetails( missionIndex );
		gui->HandleNamedEvent( "onDownloadableMissionDetailsLoaded" );
	} else if( cmd == "onstartdownload" ) {
		StartDownload( gui );
		UpdateDownloadProgress( gui ); // do this first
		UpdateGUI( gui );
	} else if( cmd == "ondownloadcompleteconfirm" ) {
		// Let the GUI request another refresh of downloadable missions (with delay)
		gui->HandleNamedEvent( "QueueDownloadableMissionListRefresh" );
	} else if( cmd == "ongetnextscreenshotforavailablemission" ) {
		PerformScreenshotStep( gui, +1 );
		UpdateScreenshotItemVisibility( gui );
	} else if( cmd == "ongetprevscreenshotforavailablemission" ) {
		PerformScreenshotStep( gui, -1 );
		UpdateScreenshotItemVisibility( gui );
	}
}