Plug-In Configuration System

3DS Max Plug-In SDK

Plug-In Configuration System

Developers often need to store configuration files for use with their plug-in 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\IO\WSD\WSD.CPP demonstrates one approach a developer may use to read and write configuration files:

#define WSDCONFIGNAME _T("wsd.ini")

#define WSDSECTION _T("Default State")

#define WSDHOSTKEY _T("Hostname")

#define WSDSYSKEY _T("System")

#define WSDDEFAULT _T("accom")

#define WSDDEFSYS _T("ntsc")

// GetCfgFilename()

void BitmapIO_WSD::GetCfgFilename( TCHAR *filename ) {

 _tcscpy(filename,TheManager->GetDir(APP_PLUGCFG_DIR));

 int len = _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()

int BitmapIO_WSD::ReadCfg() {

 TCHAR filename[MAX_PATH];

 TCHAR system[64];

 GetCfgFilename(filename);

 int res = 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()

void BitmapIO_WSD::WriteCfg() {

 TCHAR filename[MAX_PATH];

 TCHAR system[64];

 if (ntsc)

  _tcscpy(system,WSDDEFSYS);

 else

  _tcscpy(system,_T("pal"));

 GetCfgFilename(filename);

 WritePrivateProfileString(WSDSECTION,WSDHOSTKEY,hostname,filename);

 WritePrivateProfileString(WSDSECTION,WSDSYSKEY,system,filename);

}