CD checker

Started by
22 comments, last by funkman 20 years, 6 months ago
Hi guys, Need a little help. Anyone knows how to write a simple CD checker (that is to check if the game CD is in the drive) Cheers
Advertisement
Please do not crosspost.
Here''s (roughly) what I did for the CD check in the engine for Pac-Man:Adventures in Time (and a few other PC titles which used the same engine):


1. Put a fairly unique file in the root of your CD/DVD (say KEWLGAME.DAT), with some unique contents (a GUID for example).

2. Use GetLogicalDrives() or GetLogicalDriveStrings
() with GetDriveType() to determine which drives in the system are CD/DVD drives (remember there may be more than one, and the user may have a multichanger). Do this every time your app starts - users do change drive letters around.

3. Before doing any CD access call SetErrorMode() to prevent blue screens and error boxes when the system can''t read from a CD/DVD that''s still mounting.

4. If your software has been run previously, set up a registry key with the "last known" drive location of the game CD. ALWAYS check that location first - if you don''t, people with multichangers will hate you if the game CD is in the last of their mounted drives.

5. For each CD/DVD drive (starting at the one in the registry - see above), try to open your file, then try to read from your file and finally compare the contents of the file with your "unique" contents from step 1.

6. IMO it''s better to use the Win32 API calls directly here rather than fopen()/iostream stuff because you get much more control and much more informative error codes back.

7. Don''t rely on AutoRun or WM_DEVICECHANGE notifications - many users disable them. Sometimes properly (so WM_DEVICECHANGE still works and AutoRun doesn''t), often incorrectly (so neither work).


--
Simon O''Connor
3D Game Programmer &
Microsoft DirectX MVP

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

Interesting post
Techno Grooves
Many thanks, very much appreciated.
I''m struggling a bit with my cd-checker. Could you possibly give me a short sample code.

Cheers

P.S. oh yes sorry for crossposting, I was a bit desperate
Try this, I wrote it for a PC game back in ''99 so it might not be everything you want (although it performs most of Simon''s checklist items):

int CDInDrive(char *signature, char *dest){	BYTE	buffer[260], *p;	// Get a selection of drive strings	ZeroMemory(buffer, 260);	GetLogicalDriveStrings(260, buffer);	for (p = buffer; *p || *(p + 1); )	{		BYTE	path[260];		FILE	*fp;		// Construct a path to the CD Information File		wsprintf(path, "%s%s", p, "CDINFO.FIL");		// Validate that it is a CD drive (stops the A: thrashing)		if (GetDriveType(p) == DRIVE_CDROM)		{			// Attempt to open it			if ((fp = fopen(path, "rb")) != NULL)			{				BYTE	instore[48];				int		s;				// Can the title be read?				if (fread(instore, 1, 19, fp) == 19)				{					instore[19] = 0;					// Is it the correct title?					if (!strcmp(instore, "CD Information File"))					{						// Seek past the CR/LF						fseek(fp, 2, SEEK_CUR);						s = strlen(signature);						// Can the signature be read?						if (fread(instore, 1, s, fp) == 31)						{							instore[s] = 0;							// Is it the correct signature?							if (!strcmp(instore, signature))							{								// Copy the drive string if it''s desired								if (dest != NULL) strcpy(dest, p);								// CD is in a drive!								return (1);							}						}					}				}				fclose(fp);			}		}		// Move onto the next drive string		while (*p++) { }	}	return (0);}


It managed to get through Infogrames test department fine (which is amazingly thourough) although some of points Simon brought up would be worth extending to
Managed to figure out myself but thanks a million anyway.
I should be hanging around more oten in here, might make my life a lot easier.

One more question. I wonder if anyone had any experience using NDL middleware NetImmerse (or Gamebryo as it is called now).

Again appreciate your help.

Cheers
Sorry, another CD checker related question.
How do I you control the message box that appears when the CD is not in the drive. Currently if I press "Continue" it will launch the game anyway?
You can check the return value of the message box, however in most instances you really only need 2 buttons: one for try again, and one for exit. If you put up a message box, check its return value for the exit code. If exit was pressed, tell the program to quit. If try again was pressed, run the cd check again.
----Erzengel des Lichtes光の大天使Archangel of LightEverything has a use. You must know that use, and when to properly use the effects.♀≈♂?

This topic is closed to new replies.

Advertisement