|
IntroductionWhen releasing a title, one of the issues that often arises is how to deal with the fact the files will not be located on the user's system at the same path that they are available on your development systems. Much of the problems that occur are because of absolute addressing, that is, paths that specify a location based upon the root of the drive This is easily avoided by strictly using relative addressing from the start, and with proper management is not a problem. Normally an application is started within the installed directory, and can use relative paths to access subdirectories without a hitch. The Problem of Removable MediaWith the increasing bulk of media in today's games, however, it is often not practical to place the whole game on the user's hard drive. To support a larger customer base, installers usually offer options for varying levels of file migration to the local drive, and rely on the application disk being available in the CD-ROM drive during use. This can cause a number of difficult problems:
Avoiding the Mayhem There are a variety of approaches that have been taken, some of which have shortcomings when put out in the field. I will provide a method that has worked well for me. To start, let's take a look at the basic steps that are performed:
It may look like overkill at first, but the operation is very quick and it insures less problems in the field. Often I have seen applications that will take most, but not all, of this path - sometimes resulting in system specific problems. To give an idea of the range of problems that I have seen:
I can think of many other issues that I have encountered, but you probably didn't come here to listen to me gripe ;-) So, without further adieu, I have included source code for CD detection and volume name verification. I have utilized this in quite a few applications without problem, but one note of caution : This code is freshly stripped out of my code library, and I have removed some things that are specific to my existing in-house libraries. I don't suspect any issues, but if you should have any problems e-mail me at rdunlop@mvps.org and I will update the code on this site right away. #define VOL_NAME "GAMEVOL" char dr_str[]="c:\\"; // drive path BOOL log_disk(void) { int i; // general index counter DWORD drives; // drive bit map BOOL status; // return status from volume function char vol_buf[40]; // volume name buffer DWORD max_file_len; // maximum file length DWORD system_flags; // volume file system flags int stat; // message box return value // find what drives are available lp: drives=GetLogicalDrives(); // loop through drives for (i=0;i<26;i++) { // is this drive available? if (drives&(1<<i)) { // yes, is it a CD? dr_str[0]='A'+i; UINT driveType=GetDriveType(dr_str); if (driveType==DRIVE_CDROM) { // yes, get the volume name SetErrorMode(SEM_FAILCRITICALERRORS); status=GetVolumeInformation(dr_str, vol_buf, sizeof(vol_buf), NULL, &max_file_len, &system_flags, NULL,NULL); SetErrorMode(0); // did we successfully get it? if (status) { // yes, is this the one? if (!memicmp(vol_buf,VOL_NAME,sizeof(VOL_NAME))) { // yes, return success to caller return TRUE; } } } } } // not found, display error message and query user stat=MessageBox(NULL,"Please Insert Game CD","CD Not Found", MB_ABORTRETRY|MB_ICONEXCLAMATION); // does the user want to retry? if (stat==IDRETRY) // yes, try again goto lp; // return failure to caller return FALSE; } |
Visitors Since 1/1/2000:
|