Anybody?
Internet Update feature for your game
- Splat
-Geoff
That sounds like a good idea, if you could please send me a copy at: servo@dtx.net

Josh

invader@hushmail.com
------------------
http://qoy.tripod.com
To use it though, you'd need to change the directories. As i've just pasted this, I havent edited it - so it's got "voyce" all over it.
Just ignore it, its just from my voice recognition program.
Oh yeah, and make sure there's a variable hMainInstance that contains the hInstance passed to WinMain!.
It uses MFC classes, however I use it on my win32 progs too.
code:
//
// Internet Update Code - Voyce
//#include "stdafx.h" // Pre-compiled header
#include// WinInet
#include// Standard input/output
#include// Misc char support
#include// Maths
#include// Shell API
#include "licence.lic" // Licence
#include "resource.h" // Resource header/////////
extern HINSTANCE hMainInstance;
/////////int VoyceMessageBox(HWND hWnd, LPSTR lpszText, LPSTR lpszCaption, DWORD dwFlags)
{
MSGBOXPARAMS mbp;mbp.cbSize = sizeof(mbp);
mbp.hwndOwner=hWnd;
mbp.hInstance=hMainInstance;
mbp.lpszText = lpszText;
mbp.lpszCaption = lpszCaption;
mbp.dwStyle = MB_USERICON | dwFlags;
mbp.lpszIcon = MAKEINTRESOURCE(IDI_VOYCE);
mbp.dwContextHelpId = NULL;
mbp.lpfnMsgBoxCallback = NULL;
mbp.dwLanguageId = NULL;return MessageBoxIndirect(&mbp);
}void DisplayHTTPCode(DWORD dwRet, LPSTR lpszCaption)
{
char *strText;
switch (dwRet)
{
case 200:
strText = "URL located, transmission follows";
break;
case 400:
strText = "Unintelligble request";
break;
case 404:
strText = "Requested URL not found";
break;
case 405:
strText = "Server does not support requested method";
break;
case 500:
strText = "Unknown server error";
break;
case 503:
strText = "Server capacity reached";
break;
default:
sprintf(strText, "HTTP Code %d", dwRet);
break;
}VoyceMessageBox(0, strText, lpszCaption, MB_OK);
}int CheckUpdate(void)
{
CInternetSession session("Voyce Update Check");
CHttpConnection* pServer = NULL;
CHttpFile* pFile = NULL;
DWORD dwRet;
CString strBuf;try
{
CString strServerName;
CString strHeaders;
CString strObject;
INTERNET_PORT nPort;strServerName = "members.xoom.com";
nPort = 80;
strObject = "/_clotweb/voyce/update.inf";
strHeaders = "";pServer = session.GetHttpConnection(strServerName, nPort);
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET, strObject);
pFile->AddRequestHeaders(strHeaders);
pFile->SendRequest();
pFile->QueryInfoStatusCode(dwRet);if (dwRet == HTTP_STATUS_OK)
{
// Read some bytes into the buffer
pFile->ReadString(strBuf);
}
else
{
// Not quite OK
if (dwRet >= 200 && dwRet <= 299)
DisplayHTTPCode(dwRet, "Couldn't obtain update information");
}delete pFile;
delete pServer;
}
catch (CInternetException* pEx)
{
// Internet error
pEx->Delete();
VoyceMessageBox(NULL, "There was an error obtaining\nthe update information.", "Voyce Update", MB_OK);
return 0;
}
session.Close();// Check for a higher version number
if (strncmp(strBuf, VERSION, strlen(VERSION)) > 0)
{
// Higher version exists there
if (VoyceMessageBox(0, "A new version of Voyce exists.\nDo you want to update.", "Voyce Update", MB_YESNO) == IDYES)
return 1; // Get it
else
return 0; // Don't get it
}
else
{
VoyceMessageBox(0, "No new version of Voyce exists.", "Voyce Update", MB_OK);
return 0; // Nope, existing / lower version exists there
}
}void GetUpdate(void)
{
CInternetSession session("Voyce Update Download");
CFtpConnection* pConn = NULL;
char *strTempFile;
char *strTempPath;GetTempPath(1024, strTempPath);
GetTempFileName(strTempPath, "VOY", 0, strTempFile);
pConn = session.GetFtpConnection("ftp.xoom.com");// Get the file
if (!pConn->GetFile("/members/_clotweb/voyce/update.exe", strTempFile))
{
// Display an error
VoyceMessageBox(0, "An error occurred whilst trying to\ndownload the update.", "Voyce Update", MB_OK);
return;
}
else
{
// Run downloaded temp file
ShellExecute(0, "open", strTempFile, NULL, NULL, SW_SHOWNORMAL);
delete pConn;
}
session.Close();
}
Hope it works
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.