Archived

This topic is now archived and is closed to further replies.

Internet Update feature for your game

This topic is 6598 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

You want code? You got code!
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

Share this post


Link to post
Share on other sites
Hi there, I often make cool little bits and pieces to put in people's games and/or programs. If anybody is interested, I can send you a library and header for my Internet Update feature - checks for a new version, downloads if you want it to, and runs an update program!

Anybody?

Share this post


Link to post
Share on other sites