Esempio n. 1
0
void cupdatenetlib::procUpdate(){
	
	if (_wmkdir(szUpdfilesPath) < 0 && errno == EEXIST){
        //if(szaLists.GetCount() <= 0){
        //    downloadList() ;
        //}
        if(m_UpdateFileArray.GetCount() <= 0){
            downloadList() ;
        }
		if ( m_UpdateFileArray.GetCount() >0 ){
//			SVP_LogMsg( _T("GOT UPDATE LIST: "));
//			SVP_LogMsg( svpToolBox.Implode(_T("\t") , &szaLists) );
            SVP_LogMsg( _T("DOWNLOAD UPDATE "));
            downloadFiles();
			//int i = 0;
			//while(  downloadFiles() != 0 ){
			//	i++;
			//	SVP_LogMsg( _T("DOWNLOAD UPDATE "));
			//	if(i > 3) break;
			//}
			SVP_LogMsg( _T("REAL UPDATE") );
			tryRealUpdate();
		}
	}else{
		SVP_LogMsg( _T("UPD dir not exist and write able: "));
	}
	bSVPCU_DONE = 1;
}
Esempio n. 2
0
BOOL CSVPNet::CheckUpdaterExe(CString szFileVerHash, CString szPath){
	FILE* stream_updater_exe;
	CString szTmpFilename = this->svpToolBox.getTmpFileName();
	if ( _wfopen_s( &stream_updater_exe, szTmpFilename, _T("wb") ) != 0){
		return 0; //input file open error
	}
	CURL *curl;
	CURLcode res;
	CString szPostPerm;
  szPostPerm.Format(_T( "branch=updater%s&current=%s" ), BRANCHVER, szFileVerHash);
	int rret = 0;
	curl = curl_easy_init();
	if(curl) {
		long respcode;

		this->SetCURLopt(curl);

		curl_easy_setopt(curl, CURLOPT_URL, GetUrlByType('upda' , iTryID));

		int iDescLen = 0;
		char* szPostFields = svpToolBox.CStringToUTF8(szPostPerm, &iDescLen) ;
		curl_easy_setopt(curl, CURLOPT_POSTFIELDS, (void *)szPostFields);
		
		curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)stream_updater_exe);

		res = curl_easy_perform(curl);
		if(res == 0){
			curl_easy_getinfo(curl,CURLINFO_RESPONSE_CODE, &respcode);

			if(respcode == 200){
				//good to go
				rret = 1;
				
			}else{
				//error
				SVP_LogMsg(_T("None Update Required For Updater"));
			}
		}else{
			//error
			SVP_LogMsg5(_T("HTTP connection error %d %s ") , res, CStringW(curl_easy_strerror(res))); //TODO handle this
		}
		curl_easy_cleanup(curl);
	}
	fclose(stream_updater_exe);
	if (rret){
		
		if ( this->svpToolBox.unpackGZfile( szTmpFilename , szPath) == 0 ){	
			SVP_LogMsg(_T("Copy Updater.exe Sucesssed"));
		}else{
			SVP_LogMsg(_T("Copy Updater.exe Failed"));
			rret = 0;
		}
	}
	return rret;
}
Esempio n. 3
0
int CSVPNet::ExtractDataFromAiSubRecvBuffer_STL(std::wstring szFilePath,
                                            FILE* sAiSubRecvBuff)
{
  char szSBuff[2] = {0,0};
  int ret = 0;
  fseek(sAiSubRecvBuff, 0, SEEK_SET); // move point yo begining of file

  if (fread(szSBuff, sizeof(char), 1, sAiSubRecvBuff) < 1)
    SVP_LogMsg(_T("Fail to retrive First Stat Code"));

  int iStatCode = szSBuff[0];
  if (iStatCode <= 0)
  {
    if (iStatCode == -1)
    {
      SVP_LogMsg(ResStr(IDS_LOG_MSG_SVPSUB_NONE_MATCH_SUB), 31);
      ret = -2;
    }
    else
    {
      //TODO error handle
      SVP_LogMsg(ResStr(IDS_LOG_MSG_SVPSUB_DOWNLOAD_FAIL));//, 31
      ret = -1;
      //SVP_LogMsg(_T("First Stat Code TODO: 显示有错误发生"));
    }
    goto releaseALL;
  }
  else
    SVP_LogMsg(ResStr(IDS_LOG_MSG_SVPSUB_GOTMATCHED_AND_DOWNLOADING), 31);

  //handle SubFiles
  svpToolBox.szaSubDescs.RemoveAll();
  svpToolBox.szaSubTmpFileList.RemoveAll();

  for(int j = 0; j < iStatCode; j++)
  {
    int exterr = svpToolBox.HandleSubPackage(sAiSubRecvBuff);
    if(exterr)
    {
      ret = exterr;
      break;
    }
  }


releaseALL:
  fclose(sAiSubRecvBuff);

  svpToolBox.ClearTmpFiles();
  return ret;
}
Esempio n. 4
0
bool cupdatenetlib::PostUsingCurl(CString strFields, CString strReturnFile, curl_progress_callback pCallback)
{
    FILE* stream_file_list;
    if ( _wfopen_s( &stream_file_list, strReturnFile, _T("wb") ) != 0){
        return false; //input file open error
    }
    CURL *curl;
    CURLcode res;
    CString szPostPerm = strFields;
    bool rret = false;
    SVP_LogMsg(strFields);
    curl = curl_easy_init();
    if(curl) {
        long respcode;
        this->SetCURLopt(curl);
        curl_easy_setopt(curl, CURLOPT_URL, szUrl);
        //curl_easy_setopt(curl, CURLOPT_URL, "http://svplayer.shooter.cn/api/updater.php");
        int iDescLen = 0;
        char* szPostFields = svpToolBox.CStringToUTF8(szPostPerm, &iDescLen) ;
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, (void *)szPostFields);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)stream_file_list);

        if (pCallback)
        {
            curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
            curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, pCallback);
            curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, this);
        }
        res = curl_easy_perform(curl);
        if (szPostFields)
            delete szPostFields;
        if(res == 0){
            curl_easy_getinfo(curl,CURLINFO_RESPONSE_CODE, &respcode);
            if(respcode == 200){
                //good to go
                rret = true;

            }else{
                //error
                SVP_LogMsg(_T("None Update Required "));
            }
        }else{
            //error
            SVP_LogMsg5(_T("HTTP connection error %d "), res); //TODO handle this
        }
        curl_easy_cleanup(curl);
    }
    fclose(stream_file_list);
    return rret;
}
Esempio n. 5
0
void ISubPicAllocatorPresenterImpl::AlphaBltSubPic(CSize size, SubPicDesc* pTarget)
{
	size.cy -= AfxGetMyApp()->GetBottomSubOffset();

	CComPtr<ISubPic> pSubPic;
	CComPtr<ISubPic> pSubPic2;
	BOOL bltSub1 = false, bltSub2 = false;
	CRect rcSource1, rcSource2, rcDest1, rcDest2;
#ifdef LOGSUBRECT
	CString szD1, szD2;
#endif
	if(m_pSubPicQueue->LookupSubPic(m_rtNow, pSubPic))
	{
		if (SUCCEEDED (pSubPic->GetSourceAndDest(&size, rcSource1, rcDest1))){
			//pSubPic->AlphaBlt(rcSource, rcDest, pTarget);
			bltSub1 = true;
		}
#ifdef LOGSUBRECT
		UINT iTotalLenSec = (UINT)( (INT64) m_rtNow / 10000000 );
		szD1.Format(_T("  sub1 size %d %d   , source %d %d %d %d , dest  %d %d %d %d , time %d:%02d") , 
			size.cx, size.cy, rcSource1.top, rcSource1.right, rcSource1.bottom, rcSource1.left, 
			 rcDest1.top, rcDest1.right, rcDest1.bottom, rcDest1.left,(int)iTotalLenSec/60, iTotalLenSec % 60 );
#endif

	}
	
	if(m_pSubPicQueue2->LookupSubPic(m_rtNow2, pSubPic2))
	{
		if (SUCCEEDED (pSubPic2->GetSourceAndDest(&size, rcSource2, rcDest2))){
			bltSub2 = true;
		}
#ifdef LOGSUBRECT
		UINT iTotalLenSec = (UINT)( (INT64) m_rtNow2 / 10000000 );
		szD2.Format(_T("  sub2 size %d %d   , source %d %d %d %d , dest  %d %d %d %d , time %d:%02d") , 
			size.cx, size.cy, rcSource2.top, rcSource2.right, rcSource2.bottom, rcSource2.left, 
			rcDest2.top, rcDest2.right, rcDest2.bottom, rcDest2.left,(int)iTotalLenSec/60, iTotalLenSec % 60 );
#endif			
	}

	m_sublib2.CalcDualSubPosisiton(bltSub1 , bltSub2 , rcDest1 , rcDest2 , size , !!pSubPic, !!pSubPic2) ;
	
	if(bltSub1)
		pSubPic->AlphaBlt(rcSource1, rcDest1, pTarget);
	if(bltSub2){
		pSubPic2->AlphaBlt(rcSource2, rcDest2, pTarget);
	}

	
#ifdef LOGSUBRECT
	if(bltSub1 || bltSub2){
		SVP_LogMsg(szD1 + szD2);
	}
#endif
}
Esempio n. 6
0
BOOL cupdatenetlib::downloadList(){
	if ( !(_wmkdir(szUpdfilesPath) < 0 && errno == EEXIST) ){
		SVP_LogMsg( _T("UPD dir not exist and writeable! "));
		return 0;
	}
	resetCounter();

	CString szBranch = svpToolBox.fileGetContent(szUpdfilesPath + _T("branch") );

	if(szBranch.IsEmpty() ){
		/* 如果 mtime 小于 stable 版本的 mtime 就更新 stable , 大于就更新 beta */
//		struct __stat64  sbuf;
		CString szPlayerPath = svpToolBox.GetPlayerPath(_T("splayer.exe"));
		if(!svpToolBox.ifFileExist(szPlayerPath) ){
			szPlayerPath = svpToolBox.GetPlayerPath(_T("mplayerc.exe"));
			if (!svpToolBox.ifFileExist(szPlayerPath)){
				szPlayerPath = svpToolBox.GetPlayerPath(_T("svplayer.exe"));
			}
		}
		if(svpToolBox.ifFileExist(szPlayerPath) ){
      std::wstring str = HashController::GetInstance()->GetMD5Hash(szPlayerPath.GetBuffer());
      szBranch = str.c_str();
		}
		else
			szBranch = _T("stable");
	}

	WCHAR* wsz = this->svpToolBox.getTmpFileName();
    CString szTmpFilename(wsz);
	delete wsz;

    CString szPostPerm;
    szPostPerm.Format(_T("ver=%s&branch=%s"), BRANCHVER, szBranch);

	int rret = 0;
	CString szLog;
	
    DeleteFile(szTmpFilename);
	return rret;
}
Esempio n. 7
0
int CSVPNet::WetherNeedUploadSub(CString fnVideoFilePath, CString szFileHash,CString fnSubHash, int iDelayMS){
	CURL *curl;
	CURLcode res;
	CString szPostPerm ;
	szPostPerm.Format(_T( "pathinfo=%s&filehash=%s&subhash=%s&subdelay=%d" ) , fnVideoFilePath ,szFileHash , fnSubHash, iDelayMS);
	
	int rret = -1;
	curl = curl_easy_init();
	if(curl) {
		long respcode;

		this->SetCURLopt(curl);

		curl_easy_setopt(curl, CURLOPT_URL,  GetUrlByType('upsb', iTryID));

		int iDescLen = 0;
		char* szPostFields = svpToolBox.CStringToUTF8(szPostPerm, &iDescLen) ;
		curl_easy_setopt(curl, CURLOPT_POSTFIELDS, (void *)szPostFields);

		res = curl_easy_perform(curl);
		if(res == 0){
			curl_easy_getinfo(curl,CURLINFO_RESPONSE_CODE, &respcode);

			if(respcode == 200){
				//good to go // continues to upload sub
				rret = 1;
			}if(respcode == 404){
				//error
				rret = 0;
				SVP_LogMsg(_T("Already Have same sub in databases"));
			}
		}else{
			//error
			SVP_LogMsg5(_T("HTTP connection error %d %s ") , res, CStringW(curl_easy_strerror(res))); //TODO handle this
		}
		curl_easy_cleanup(curl);
	}
	return rret;
}
Esempio n. 8
0
STDMETHODIMP ISubPicImpl::GetSourceAndDest(SIZE* pSize, RECT* pRcSource, RECT* pRcDest)
{
	CheckPointer (pRcSource, E_POINTER);
	CheckPointer (pRcDest,	 E_POINTER);

	if(m_size.cx > 0 && m_size.cy > 0)
	{
		CRect		rcTemp = m_rcDirty;

		// FIXME
		rcTemp.DeflateRect(1, 1);

		*pRcSource = rcTemp;
		
		

		CRect RcDest (rcTemp.left   * pSize->cx / m_VirtualTextureSize.cx,
						  rcTemp.top    * pSize->cy / m_VirtualTextureSize.cy,
						  rcTemp.right  * pSize->cx / m_VirtualTextureSize.cx,
						  rcTemp.bottom * pSize->cy / m_VirtualTextureSize.cy);
		LONG cy = min ( pSize->cx * 4/5 , pSize->cy );
		if(cy < pSize->cy ){
			cy = pSize->cy - cy;
			RcDest.DeflateRect( RcDest.Width() *  cy  / pSize->cy / 2 , RcDest.Height() *   cy  / pSize->cy / 2);
		}
		
		 *pRcDest = RcDest;
#ifdef LOGSUBRECT
		CString szLog ;
		szLog.Format(_T(" resize w %d %d h %d %d") , pSize->cx , m_VirtualTextureSize.cx ,pSize->cy , m_VirtualTextureSize.cy);
		SVP_LogMsg(szLog);
#endif
		return S_OK;
	}
	else
		return E_INVALIDARG;
}
Esempio n. 9
0
int CSVPNet::QuerySubByVideoPathOrHash_STL(std::wstring szFilePath,
                                       std::wstring szFileHash,
                                       std::wstring szVHash,
                                       std::wstring szLang)
{
  CURL *curl;
  CURLcode res;
  int ret = 0;
  std::wstring szPostPerm = L"pathinfo=" + szFilePath + L"&filehash="
    + szFileHash + L"&vhash=" + szVHash + L"&lang=" + szLang + L"&shortname="
    + svpToolBox.GetShortFileNameForSearch_STL(szFilePath);

  struct curl_httppost *formpost=NULL;
  struct curl_httppost *lastptr=NULL;


  curl_global_init(CURL_GLOBAL_ALL);
  char* szTerm2;
  char* szTerm3;
  int iDescLen = 0;
  szTerm2 = svpToolBox.CStringToUTF8(szFilePath.c_str(), &iDescLen);
  curl_formadd(&formpost,	&lastptr, CURLFORM_COPYNAME, "pathinfo", CURLFORM_COPYCONTENTS, szTerm2,CURLFORM_END);

  szTerm3 = svpToolBox.CStringToUTF8(szFileHash.c_str(), &iDescLen);
  curl_formadd(&formpost,	&lastptr, CURLFORM_COPYNAME, "filehash", CURLFORM_COPYCONTENTS, szTerm3,CURLFORM_END);

  szVHash = genVHash(szTerm2, szTerm3, uniqueIDHash);


  free(szTerm2);
  free(szTerm3);

  if (!szVHash.empty())
  {
    szTerm2 = svpToolBox.CStringToUTF8(szVHash.c_str(), &iDescLen);
    curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "vhash", CURLFORM_COPYCONTENTS, szTerm2,CURLFORM_END);
    free(szTerm2);
  }

  AppSettings& s = AfxGetAppSettings();
  std::wstring szSVPSubPerf = (LPCTSTR)s.szSVPSubPerf;
  if (!szSVPSubPerf.empty())
  {
    szTerm2 = svpToolBox.CStringToUTF8(szSVPSubPerf.c_str(), &iDescLen);
    curl_formadd(&formpost,	&lastptr, CURLFORM_COPYNAME, "perf", CURLFORM_COPYCONTENTS, szTerm2,CURLFORM_END);
    free(szTerm2);
  }

  if (!szLang.empty())
  {
    szTerm2 = svpToolBox.CStringToUTF8(szLang.c_str(), &iDescLen);
    curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "lang", CURLFORM_COPYCONTENTS, szTerm2,CURLFORM_END);
    free(szTerm2);
  }

  szTerm2 = svpToolBox.CStringToUTF8(svpToolBox.GetShortFileNameForSearch_STL(szFilePath).c_str(), &iDescLen);
  curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "shortname", CURLFORM_COPYCONTENTS, szTerm2,CURLFORM_END);
  free(szTerm2);

  FILE *stream_http_recv_buffer = svpToolBox.getTmpFileSteam();
  if (!stream_http_recv_buffer)
  {
    SVP_LogMsg(_T("TmpFile Creation for http recv buff fail")); //// TODO: 1. warning!! OR switch to memfile system
    return -1;
  }
  int err = 0;


  curl = curl_easy_init();
  if (curl)
  {
    long respcode;
    wchar_t szFailMsg[1024];

    SetCURLopt(curl);

    curl_easy_setopt(curl, CURLOPT_URL, GetUrlByType('sapi', iTryID));
    //curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION , &(this->handleSubQuery));
    curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);

    curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)stream_http_recv_buffer);
    //int iDescLen = 0;
    //char* szPostFields = svpToolBox.CStringToUTF8(szPostPerm, &iDescLen) ;
    //curl_easy_setopt(curl, CURLOPT_POSTFIELDS, (void *)szPostFields);
    //curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, iDescLen);
    res = curl_easy_perform(curl);
    if (res == 0)
    {
      curl_easy_getinfo(curl,CURLINFO_RESPONSE_CODE, &respcode);
      //double contentlength;
      //curl_easy_getinfo(curl,CURLINFO_SIZE_DOWNLOAD, &contentlength);
      //SVP_LogMsg5(L" contentlength %f", contentlength);
      if (respcode == 200)
      {
        //good to go
        //SVP_LogMsg(_T("字幕已经找到,正在处理..."), 31);
        ret = 1;
      }
      else
      {
        //error
        SVP_LogMsg5(_T("HTTP return code is not 200 but %d") , respcode);
        err = 1;
      }
    }
    else
    {
      //error
      LONG l_oserr = 0;
      curl_easy_getinfo(curl,CURLINFO_OS_ERRNO,&l_oserr);
      err = 2;
      swprintf_s(szFailMsg, 1024, L"%s", CStringW(curl_easy_strerror(res)));
      //szFailMsg.Format(L"%s",CStringW(curl_easy_strerror(res)));
      if(!lstrcmp(szFailMsg, L"Couldn't connect to server"));
        lstrcat(szFailMsg, ResStr(IDS_LOG_MSG_SVPSUB_PLEASE_CHECK_FIREWALL));

      SVP_LogMsg5(_T("HTTP connection error  %s %d"), szFailMsg, l_oserr); //TODO handle this
    }

    /* always cleanup */
    curl_easy_cleanup(curl);

    //free(szPostFields);

    //if not error, process data
    if (ret)
    {
      int extErr  = ExtractDataFromAiSubRecvBuffer_STL(szFilePath, stream_http_recv_buffer);
      if (extErr && extErr != -2)
      { // -2 if there is none match subtile
        SVP_LogMsg(_T("Error On Extract DataFromAiSubRecvBuffer ")); //TODO handle this
        err = 3;
      }
    }
    else
    {
      wchar_t szMsg[1024];
      swprintf_s(szMsg, 1024, ResStr(IDS_LOG_MSG_SVPSUB_NETWORK_FAIL), szFailMsg);
      SVP_LogMsg(szMsg);//,31
      m_lastFailedMsg = szMsg;
      err = 4;
    }
    /*
    if (this->mainBufferSize > 0){
    char statCode = this->mainBuffer[0];
    if(statCode <= 0){
    //error handle
    }else{
    //handSubFiles

    }

    }
    if (this->mainBuffer){
    free(this->mainBuffer);
    }*/
  }

  //this->mainBuffer = NULL;
  //this->mainBufferSize = 0;
  fclose(stream_http_recv_buffer);

  return err;
}
Esempio n. 10
0
int CSVPNet::UploadSubFileByVideoAndHash(std::wstring fnVideoFilePath,
                                         std::wstring szFileHash,
                                         std::wstring szSubHash,
                                         std::vector<std::wstring>* fnSubPaths,
                                         int iDelayMS,
                                         std::vector<std::wstring>* szaPostTerms)
{
  CURL *curl;
  CURLcode res;
  //CString szPostPerm = _T( "pathinfo=" ) + fnVideoFilePath + _T("&filehash=") + szFileHash ;
  int iTotalFiles = fnSubPaths -> size();
  SVP_LogMsg(_T("Upload Begin"));
  struct curl_httppost *formpost = NULL;
  struct curl_httppost *lastptr  = NULL;
  char errorbuf[CURL_ERROR_SIZE];

  curl_global_init(CURL_GLOBAL_ALL);

  char* szTerm2;
  char* szTerm3;
  int iDescLen = 0;

  szTerm2 = svpToolBox.CStringToUTF8(fnVideoFilePath.c_str(), &iDescLen);
  curl_formadd(&formpost,	&lastptr, CURLFORM_COPYNAME, "pathinfo",
    CURLFORM_COPYCONTENTS, szTerm2,CURLFORM_END);
  free(szTerm2);

  szTerm2 = svpToolBox.CStringToUTF8(szSubHash.c_str(), &iDescLen);
  curl_formadd(&formpost,	&lastptr, CURLFORM_COPYNAME, "subhash",
    CURLFORM_COPYCONTENTS, szTerm2,CURLFORM_END);
  free(szTerm2);

  szTerm3 = svpToolBox.CStringToUTF8(szFileHash.c_str(), &iDescLen);
  curl_formadd(&formpost,	&lastptr, CURLFORM_COPYNAME, "filehash",
    CURLFORM_COPYCONTENTS, szTerm3,CURLFORM_END);
  free(szTerm3);

  std::wstring szVHash = (LPCTSTR)genVHash(szTerm2, szTerm3, uniqueIDHash);
  if (!szVHash.empty())
  {
    szTerm2 = svpToolBox.CStringToUTF8(szVHash.c_str(), &iDescLen);
    curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "vhash",
      CURLFORM_COPYCONTENTS, szTerm2,CURLFORM_END);
    free(szTerm2);
  }

  szTerm2 = (char*)malloc(64);
  _itoa_s(iDelayMS , szTerm2, 64, 10);
  curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "subdelay",
    CURLFORM_COPYCONTENTS, szTerm2, CURLFORM_END);
  free(szTerm2);


  for (int i = 0; i < fnSubPaths -> size(); i++)
  {
    char szFname[22];
    /* Fill in the file upload field */
    std::wstring szgzFile = svpToolBox.getSameTmpName(fnSubPaths -> at(i).c_str()) ;
    SVP_LogMsg(_T("Gziping ") +  CString(fnSubPaths -> at(i).c_str()) +
      _T(" to ") + szgzFile.c_str());
    svpToolBox.packGZfile(fnSubPaths -> at(i).c_str(), szgzFile.c_str());

    szTerm2 = svpToolBox.CStringToUTF8(szgzFile.c_str(), &iDescLen, CP_ACP);
    //SVP_LogMsg(fnSubPaths->GetAt(i));
    sprintf_s(szFname, 22, "subfile[%d]", i);
    curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, szFname,
      CURLFORM_FILE, szTerm2,CURLFORM_END);
    free(szTerm2);
  }
  int retx = -1;

  curl = curl_easy_init();
  if (curl)
  {
    long respcode;
    SetCURLopt(curl);
    curl_easy_setopt(curl,  CURLOPT_ERRORBUFFER, errorbuf );
    curl_easy_setopt(curl, CURLOPT_URL,  GetUrlByType('upsb',iTryID));

    curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);

    res = curl_easy_perform(curl);
    if (res == 0)
    {
      curl_easy_getinfo(curl,CURLINFO_RESPONSE_CODE, &respcode);
      if (respcode == 200)
      {
        //good to go // continues to upload sub
        retx = 0;
        SVP_LogMsg(ResStr(IDS_LOG_MSG_SVPSUB_UPLOAD_FINISHED), 31);
      }
      else if (respcode == 404)
      {
        //error
        retx = 0;
        SVP_LogMsg(_T("Already Have same sub in databases"));
      }
    }
    else
      //error
      SVP_LogMsg5(_T("HTTP connection error %d %s ") , res,
        CStringW(curl_easy_strerror(res))); //TODO handle this
    curl_easy_cleanup(curl);
  }
  /* then cleanup the formpost chain */
  curl_formfree(formpost);
  return retx;
}
Esempio n. 11
0
BOOL cupdatenetlib::downloadList(){
	if ( !(_wmkdir(szUpdfilesPath) < 0 && errno == EEXIST) ){
		SVP_LogMsg( _T("UPD dir not exist and writeable! "));
		return 0;
	}
	resetCounter();

	CString szBranch = svpToolBox.fileGetContent(szUpdfilesPath + _T("branch") );

	if(szBranch.IsEmpty() ){
		/* 如果 mtime 小于 stable 版本的 mtime 就更新 stable , 大于就更新 beta */
//		struct __stat64  sbuf;
		CString szPlayerPath = svpToolBox.GetPlayerPath(_T("splayer.exe"));
		if(!svpToolBox.ifFileExist(szPlayerPath) ){
			szPlayerPath = svpToolBox.GetPlayerPath(_T("mplayerc.exe"));
			if (!svpToolBox.ifFileExist(szPlayerPath)){
				szPlayerPath = svpToolBox.GetPlayerPath(_T("svplayer.exe"));
			}
		}
		if(svpToolBox.ifFileExist(szPlayerPath) ){
			CMD5Checksum cmd5;
			//szBranch.Format( _T("%I64d") , sbuf.st_mtime );
			szBranch = cmd5.GetMD5((LPCTSTR)szPlayerPath).c_str();
			//AfxMessageBox(szBranch);
		}
		else
			szBranch = _T("stable");
	}

	WCHAR* wsz = this->svpToolBox.getTmpFileName();
    CString szTmpFilename(wsz);
	delete wsz;

    CString szPostPerm;
    szPostPerm.Format(_T("ver=%s&branch=%s"), BRANCHVER, szBranch);

	int rret = 0;
	CString szLog;
	if (PostUsingCurl(szPostPerm, szTmpFilename)){
        rret = 1;
		GetD3X9Dll();
		//iSVPCU_TOTAL_FILE = 0;
		iSVPCU_TOTAL_FILEBYTE  = 0;
		CString szData = svpToolBox.fileGetContent( szTmpFilename ) ;
		CStringArray szaLines;
		svpToolBox.Explode( szData, _T("\n") , &szaLines );
		for(int i = 0; i < szaLines.GetCount(); i++){
			if (szaLines.GetAt(i).IsEmpty()){break;}
			this->iSVPCU_TOTAL_FILE++;
			
			//szLog.Format(_T("Total Files need to download: %d"), iSVPCU_TOTAL_FILE);
			//SVP_LogMsg(szLog);
			CStringArray szaTmp;
			svpToolBox.Explode( szaLines.GetAt(i), _T(";") , &szaTmp );
			if(szaTmp.GetCount() < LFILETOTALPARMS){
				continue;
			}

            if (SkipThisFile(szaTmp.GetAt(LFILESETUPPATH), szaTmp.GetAt(LFILEACTION)))
                continue;

            //检查是否需要下载
			CString szSetupPath = szaTmp.GetAt(LFILESETUPPATH);

			if (szSetupPath.CompareNoCase( _T("splayer.exe")) == 0){
				if(!svpToolBox.ifFileExist(szBasePath + szSetupPath) ){
					if (svpToolBox.ifFileExist(szBasePath + _T("mplayerc.exe")))
						szSetupPath = _T("mplayerc.exe");
					if (svpToolBox.ifFileExist(szBasePath + _T("svplayer.exe")))
						szSetupPath = _T("svplayer.exe");
				}
			}

			bool bDownloadThis = FALSE;

      //check file hash
      CMD5Checksum cmd5;
      CString updTmpHash ;
      CString currentHash ;
      if( svpToolBox.ifFileExist(szUpdfilesPath + szaTmp.GetAt(LFILETMPATH)))
      {
        updTmpHash = cmd5.GetMD5((LPCTSTR)(szUpdfilesPath +
          szaTmp.GetAt(LFILETMPATH))).c_str(); //Get Hash for current Temp File
      }

      if( svpToolBox.ifFileExist(szBasePath + szSetupPath ) ){
        currentHash = cmd5.GetMD5((LPCTSTR)(szBasePath + szSetupPath)).c_str(); //Get Hash for bin file
      }

            if (currentHash.CompareNoCase( szaTmp.GetAt(LFILEHASH) ) == 0 )
                continue;
            if ( updTmpHash.CompareNoCase( szaTmp.GetAt(LFILEHASH) ) != 0 ){
                bDownloadThis = TRUE;
            }

            UpdateInfo* puinfo = new UpdateInfo;
            puinfo->bDownload = bDownloadThis;
            puinfo->dwDowloadedLength = _wtoi(szaTmp.GetAt(LFILEGZLEN));
            puinfo->dwFileLength = _wtoi(szaTmp.GetAt(LFILELEN));
            puinfo->strId = (szaTmp.GetAt(LFILEID));
            puinfo->strAction = szaTmp.GetAt(LFILEACTION);
            puinfo->strDownloadfileMD5 = szaTmp.GetAt(LFILEGZHASH);
            puinfo->strFileMd5 = szaTmp.GetAt(LFILEHASH);
            puinfo->strPath = szaTmp.GetAt(LFILESETUPPATH);
            puinfo->strTempName = szaTmp.GetAt(LFILETMPATH);
            puinfo->strCurrentMD5 = currentHash;
            puinfo->bReadyToCopy = !bDownloadThis;

            m_UpdateFileArray.Add(puinfo);

			if(bDownloadThis){
				iSVPCU_TOTAL_FILEBYTE += _wtoi(szaTmp.GetAt(LFILEGZLEN));
				//szaTmp.SetSize(LFILETOTALPARMS);
				//szaLists.Append( szaTmp );
			}
		}
		szLog.Format(_T("Total Files: %d ; Total Len %d"), iSVPCU_TOTAL_FILE, iSVPCU_TOTAL_FILEBYTE);
		SVP_LogMsg(szLog);
	}
    DeleteFile(szTmpFilename);
	return rret;
}