Skip to main content
GameDev.net gamedev.net
🔒 Locked

Internet Update feature for your game

Started by kieren_j Nov 21, 1999 at 4:23 AM 6 replies 750+ views
Original Post
kieren_j
kieren_j
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?

Splat
Splat
I'll take a copy. I love looking at other people's source code.

- Splat

Enix
Enix
Ill take a copy too.
ghowland
ghowland
Id like to see the code too. If you can email me a copy at ghowland@lupinegames.com thatd be great.

-Geoff

mdavis
mdavis
Hey,

That sounds like a good idea, if you could please send me a copy at: servo@dtx.net

---
Michael Davis
Josh Neta
Josh Neta
why dont you just put it up on a page somewhere so everyone can d/l it?

Josh

Qoy
Qoy
Yeah, copy it to a page, because I would be interested in it too
invader@hushmail.com

------------------
http://qoy.tripod.com

kieren_j
kieren_j
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.