Plug-in Configuration System

Developers often need to store configuration files for use with their plugin applications. There is a standard location defined for these files. This allows a 3ds Max user to have all their configuration files stored together and not spread around different hard-to-find locations.

The standard location is the PlugCFG directory off the 3ds Max root directory. This location may be changed by a user using the Files > Configure Paths menu command. The developer should retrieve the location of this directory using the GetDir(APP_PLUGCFG_DIR) method of the BitmapManager class or the Interface class.

The following samples code from \MAXSDK\SAMPLES\RETIRED\WSD\WSD.CPP demonstrates one approach a developer may use to read and write configuration files:

#defineWSDCONFIGNAME_T("wsd.ini")
#defineWSDSECTION   _T(" Default State")
#defineWSDHOSTKEY   _T("Hostname")
#defineWSDSYSKEY    _T("System")
#defineWSDDEFAULT   _T("accom")
#defineWSDDEFSYS    _T("ntsc")
 
// GetCfgFilename()
voidBitmapIO_WSD::GetCfgFilename( TCHAR *filename )
{
 
   _tcscpy( filename, TheManager->GetDir(APP_PLUGCFG_DIR));
 
   intlen = _tcslen(filename);
   if (len)
   {
     if(_tcscmp(&filename[len-1,_T("\\")))
      _tcscat(filename,_T("\\"));
   }
   _tcscat(filename,WSDCONFIGNAME);
 
}

Note: The GetPrivateProfileString function retrieves a string from the specified section in an initialization file. This function is part of the Windows API. See the Windows API on-line help for more details.

// ReadCfg()
intBitmapIO_WSD::ReadCfg()
{
   TCHARfilename[MAX_PATH;
   TCHARsystem[64;
   GetCfgFilename(filename);
   intres = GetPrivateProfileString(
     WSDSECTION,
     WSDHOSTKEY,
     WSDDEFAULT,
     hostname,
     MAX_PATH,
     filename);
   if (res)
   {
     GetPrivateProfileString(
      WSDSECTION,
      WSDSYSKEY,
      WSDDEFSYS,
      system,
      64,
      filename);
   }
   else
   {
     _tcscpy(system,WSDDEFSYS);
   }
 
   if (!_tcscmp(system,WSDDEFSYS))
   {
     ntsc = TRUE;
     height = 486;
   }
   else
   {
     ntsc = FALSE;
     height = 576;
   }
   return (res);
}

Note: The WritePrivateProfileString function copies a string into the specified section of the specified initialization file. This function is part of the Windows API. See Windows API on-line help for more details.

// WriteCfg()
voidBitmapIO_WSD::WriteCfg()
{
   TCHARfilename[MAX_PATH;
   TCHARsystem[64;
   if (ntsc)
     _tcscpy(system,WSDDEFSYS);
   else
     _tcscpy(system,_T("pal"));
 
   GetCfgFilename(filename);
   WritePrivateProfileString(WSDSECTION,WSDHOSTKEY,hostname,filenam);
   WritePrivateProfileString(WSDSECTION,WSDSYSKEY,system,filename);
}