Annotation of hatari/src/configuration.c, revision 1.1.1.3

1.1       root        1: /*
                      2:   Hatari
                      3: 
                      4:   Configuration File
                      5: 
1.1.1.3 ! root        6:   The configuration file is stored in a binary format to prevent tampering.
        !             7:   We also store the version number in the file to prevent people from
        !             8:   copying old .cfg files between versions.
1.1       root        9: */
                     10: 
                     11: #include "main.h"
                     12: #include "configuration.h"
                     13: #include "dialog.h"
                     14: #include "video.h"
                     15: #include "view.h"
                     16: #include "vdi.h"
1.1.1.2   root       17: #include "screen.h"
1.1       root       18: 
                     19: static FILE *ConfigFile;
                     20: /*static OFSTRUCT ConfigFileInfo;*/
                     21: BOOL bFirstTimeInstall=FALSE;              /* Has been run before? Used to set default joysticks etc... */
                     22: 
                     23: 
                     24: /*-----------------------------------------------------------------------*/
                     25: /*
1.1.1.2   root       26:   Set default configuration values
                     27:   This is new in Hatari - Winston always loaded its values from a config
                     28:   file. But since Hatari does not yet use a config file, we need this!
                     29: */
                     30: void Configuration_SetDefault(void)
                     31: {
                     32:   ConfigureParams.Sound.bEnableSound = FALSE;
                     33:   ConfigureParams.Screen.Advanced.bFrameSkip = FALSE;
                     34:   ConfigureParams.Screen.Advanced.bAllowOverscan = TRUE;
                     35:   ConfigureParams.Screen.ChosenDisplayMode = DISPLAYMODE_HICOL_LOWRES;
1.1.1.3 ! root       36:   strcpy(ConfigureParams.TOSGEM.szTOSImageFileName, "./tos.img");
        !            37:   ConfigureParams.Memory.nMemorySize = 1;  /* 0=512k, 1=1MB, 2=2MB, 3=4MB */
        !            38:   ConfigureParams.HardDisc.nDriveList = DRIVELIST_NONE;
1.1.1.2   root       39: }
                     40: 
                     41: 
                     42: /*-----------------------------------------------------------------------*/
                     43: /*
1.1       root       44:   Load program setting from configuration file
                     45: */
1.1.1.2   root       46: void Configuration_Init(void)
1.1       root       47: {
                     48: /*
                     49:   char sVersionString[VERSION_STRING_SIZE];
                     50:   int i,j;
                     51: 
                     52:   // Set default settings, incase registry does not exist or is invalid
                     53:   Dialog_DefaultConfigurationDetails();
                     54:   View_DefaultWindowPos();
                     55: 
                     56:   // Open configuration file
                     57:   if (Configuration_OpenFileToRead()) {
                     58:     // Version, check matches
                     59:     Configuration_ReadFromFile(sVersionString,VERSION_STRING_SIZE);
                     60:     if (memcmp(sVersionString,VERSION_STRING,VERSION_STRING_SIZE)==0) {
                     61:       // Configure
                     62:       Configuration_ReadFromFile(&ConfigureParams.Configure.nMinMaxSpeed,4);
                     63:       Configuration_ReadFromFile(&WindowInitRect.left,4);
                     64:       Configuration_ReadFromFile(&WindowInitRect.top,4);
                     65:       for(i=0; i<2; i++) {
                     66:         for(j=0; j<MAX_FLOPPY_MENU_IMAGES; j++) {
                     67:           Configuration_ReadFromFile(szPreviousImageFilenames[i][j],MAX_FILENAME_LENGTH);
                     68:         }
                     69:         Configuration_ReadFromFile(&nPreviousImageFilenames[i],4);
                     70:       }
                     71:       for(i=0; i<MAX_TOSIMAGE_COMBO_IMAGES; i++)
                     72:         Configuration_ReadFromFile(szComboTOSImages[i],MAX_FILENAME_LENGTH);
                     73:       // Screen
                     74:       Configuration_ReadFromFile(&ConfigureParams.Screen.bFullScreen,4);
                     75:       Configuration_ReadFromFile(&ConfigureParams.Screen.Advanced.bDoubleSizeWindow,4);
                     76:       Configuration_ReadFromFile(&ConfigureParams.Screen.Advanced.bAllowOverscan,4);
                     77:       Configuration_ReadFromFile(&ConfigureParams.Screen.Advanced.bInterlacedFullScreen,4);
                     78:       Configuration_ReadFromFile(&ConfigureParams.Screen.Advanced.bSyncToRetrace,4);
                     79:       Configuration_ReadFromFile(&ConfigureParams.Screen.ChosenDisplayMode,4);
                     80:       Configuration_ReadFromFile(&ConfigureParams.Screen.bCaptureChange,4);
                     81:       Configuration_ReadFromFile(&ConfigureParams.Screen.nFramesPerSecond,4);
                     82:       Configuration_ReadFromFile(&ConfigureParams.Screen.bUseHighRes,4);
                     83:       // Joysticks    
                     84:       Configuration_ReadFromFile(&ConfigureParams.Joysticks.bUseDirectInput,4);
                     85:       Configuration_ReadFromFile(&ConfigureParams.Joysticks.Joy[0].bCursorEmulation,4);
                     86:       Configuration_ReadFromFile(&ConfigureParams.Joysticks.Joy[0].bEnableAutoFire,4);
                     87:       Configuration_ReadFromFile(&ConfigureParams.Joysticks.Joy[1].bCursorEmulation,4);
                     88:       Configuration_ReadFromFile(&ConfigureParams.Joysticks.Joy[1].bEnableAutoFire,4);
                     89:       // Keyboard
                     90:       Configuration_ReadFromFile(&ConfigureParams.Keyboard.bDisableKeyRepeat,4);
                     91:       Configuration_ReadFromFile(&ConfigureParams.Keyboard.ShortCuts[SHORT_CUT_F11][SHORT_CUT_SHIFT],4);
                     92:       Configuration_ReadFromFile(&ConfigureParams.Keyboard.ShortCuts[SHORT_CUT_F11][SHORT_CUT_CTRL],4);
                     93:       Configuration_ReadFromFile(&ConfigureParams.Keyboard.ShortCuts[SHORT_CUT_F12][SHORT_CUT_SHIFT],4);
                     94:       Configuration_ReadFromFile(&ConfigureParams.Keyboard.ShortCuts[SHORT_CUT_F12][SHORT_CUT_CTRL],4);
                     95:       Configuration_ReadFromFile(ConfigureParams.Keyboard.szMappingFileName,sizeof(ConfigureParams.Keyboard.szMappingFileName));
                     96:       // Sound
                     97:       Configuration_ReadFromFile(&ConfigureParams.Sound.bEnableSound,4);
                     98:       Configuration_ReadFromFile(&ConfigureParams.Sound.nPlaybackQuality,4);
                     99:       Configuration_ReadFromFile(ConfigureParams.Sound.szYMCaptureFileName,sizeof(ConfigureParams.Sound.szYMCaptureFileName));
                    100:       // Memory
                    101:       Configuration_ReadFromFile(&ConfigureParams.Memory.nMemorySize,4);
                    102:       Configuration_ReadFromFile(ConfigureParams.Memory.szMemoryCaptureFileName,sizeof(ConfigureParams.Memory.szMemoryCaptureFileName));
                    103:       // DiscImage
                    104:       Configuration_ReadFromFile(&ConfigureParams.DiscImage.bAutoInsertDiscB,4);
                    105:       Configuration_ReadFromFile(ConfigureParams.DiscImage.szDiscImageDirectory,sizeof(ConfigureParams.DiscImage.szDiscImageDirectory));
                    106:       // HardDisc
                    107:       Configuration_ReadFromFile(&ConfigureParams.HardDisc.nDriveList,4);
                    108:       Configuration_ReadFromFile(&ConfigureParams.HardDisc.bBootFromHardDisc,4);
                    109:       Configuration_ReadFromFile(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_C],sizeof(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_C]));
                    110:       Configuration_ReadFromFile(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_D],sizeof(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_D]));
                    111:       Configuration_ReadFromFile(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_E],sizeof(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_E]));
                    112:       Configuration_ReadFromFile(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_F],sizeof(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_F]));
                    113:       // TOSGEM
                    114:       Configuration_ReadFromFile(ConfigureParams.TOSGEM.szTOSImageFileName,sizeof(ConfigureParams.TOSGEM.szTOSImageFileName));
                    115:       Configuration_ReadFromFile(&ConfigureParams.TOSGEM.bUseTimeDate,4);
                    116:       Configuration_ReadFromFile(&ConfigureParams.TOSGEM.bAccGEMGraphics,4);
                    117:       Configuration_ReadFromFile(&ConfigureParams.TOSGEM.bUseExtGEMResolutions,4);
                    118:       Configuration_ReadFromFile(&ConfigureParams.TOSGEM.nGEMResolution,4);
                    119:       Configuration_ReadFromFile(&ConfigureParams.TOSGEM.nGEMColours,4);
                    120:       // RS232
                    121:       Configuration_ReadFromFile(&ConfigureParams.RS232.bEnableRS232,4);
                    122:       Configuration_ReadFromFile(&ConfigureParams.RS232.nCOMPort,4);
                    123:       // Printer
                    124:       Configuration_ReadFromFile(&ConfigureParams.Printer.bEnablePrinting,4);
                    125:       Configuration_ReadFromFile(&ConfigureParams.Printer.bPrintToFile,4);
                    126:       Configuration_ReadFromFile(ConfigureParams.Printer.szPrintToFileName,sizeof(ConfigureParams.Printer.szPrintToFileName));
                    127:       // Favourites
                    128:       Configuration_ReadFromFile(&ConfigureParams.Favourites.bCheckDiscs,4);
                    129:       Configuration_ReadFromFile(&ConfigureParams.Favourites.bOnlyShowIfExist,4);
                    130: 
                    131:       bUseVDIRes = ConfigureParams.TOSGEM.bUseExtGEMResolutions;
                    132:       bUseHighRes = ConfigureParams.Screen.bUseHighRes || (bUseVDIRes && (ConfigureParams.TOSGEM.nGEMColours==GEMCOLOUR_2));
                    133:     }
                    134: 
                    135:     // And close up
                    136:     Configuration_CloseFile();
                    137:   }
                    138:   else {
                    139:     // No configuration file, assume first-time install
                    140:     bFirstTimeInstall = TRUE;
                    141:   }
                    142: 
                    143:   // Copy details to globals, TRUE
                    144:   Dialog_CopyDetailsFromConfiguration(TRUE);
                    145: */
                    146: }
                    147: 
                    148: 
                    149: /*-----------------------------------------------------------------------*/
                    150: /*
                    151:   Save program setting to configuration file
                    152: */
                    153: void Configuration_UnInit(void)
                    154: {
                    155: /* FIXME: Rewrite this, too! */
                    156: /*
                    157:   int i,j;
                    158: 
                    159:   // Open configuration file
                    160:   if (Configuration_OpenFileToWrite()) {
                    161:     // Version
                    162:     Configuration_WriteToFile(VERSION_STRING,VERSION_STRING_SIZE);
                    163:     // Configure
                    164:     Configuration_WriteToFile(&ConfigureParams.Configure.nMinMaxSpeed,4);
                    165:     ConfigureParams.Configure.nPrevMinMaxSpeed = ConfigureParams.Configure.nMinMaxSpeed;
                    166:     Configuration_WriteToFile(&WindowInitRect.left,4);
                    167:     Configuration_WriteToFile(&WindowInitRect.top,4);
                    168:     for(i=0; i<2; i++) {
                    169:       for(j=0; j<MAX_FLOPPY_MENU_IMAGES; j++) {
                    170:         Configuration_WriteToFile(szPreviousImageFilenames[i][j],MAX_FILENAME_LENGTH);
                    171:       }
                    172:       Configuration_WriteToFile(&nPreviousImageFilenames[i],4);
                    173:     }
                    174:     for(i=0; i<MAX_TOSIMAGE_COMBO_IMAGES; i++)
                    175:       Configuration_WriteToFile(szComboTOSImages[i],MAX_FILENAME_LENGTH);
                    176:     // Screen
                    177:     Configuration_WriteToFile(&ConfigureParams.Screen.bFullScreen,4);
                    178:     Configuration_WriteToFile(&ConfigureParams.Screen.Advanced.bDoubleSizeWindow,4);
                    179:     Configuration_WriteToFile(&ConfigureParams.Screen.Advanced.bAllowOverscan,4);
                    180:     Configuration_WriteToFile(&ConfigureParams.Screen.Advanced.bInterlacedFullScreen,4);
                    181:     Configuration_WriteToFile(&ConfigureParams.Screen.Advanced.bSyncToRetrace,4);
                    182:     Configuration_WriteToFile(&ConfigureParams.Screen.ChosenDisplayMode,4);
                    183:     Configuration_WriteToFile(&ConfigureParams.Screen.bCaptureChange,4);
                    184:     Configuration_WriteToFile(&ConfigureParams.Screen.nFramesPerSecond,4);
                    185:     Configuration_WriteToFile(&ConfigureParams.Screen.bUseHighRes,4);
                    186:     // Joysticks    
                    187:     Configuration_WriteToFile(&ConfigureParams.Joysticks.bUseDirectInput,4);
                    188:     Configuration_WriteToFile(&ConfigureParams.Joysticks.Joy[0].bCursorEmulation,4);
                    189:     Configuration_WriteToFile(&ConfigureParams.Joysticks.Joy[0].bEnableAutoFire,4);
                    190:     Configuration_WriteToFile(&ConfigureParams.Joysticks.Joy[1].bCursorEmulation,4);
                    191:     Configuration_WriteToFile(&ConfigureParams.Joysticks.Joy[1].bEnableAutoFire,4);
                    192:     // Keyboard
                    193:     Configuration_WriteToFile(&ConfigureParams.Keyboard.bDisableKeyRepeat,4);
                    194:     Configuration_WriteToFile(&ConfigureParams.Keyboard.ShortCuts[SHORT_CUT_F11][SHORT_CUT_SHIFT],4);
                    195:     Configuration_WriteToFile(&ConfigureParams.Keyboard.ShortCuts[SHORT_CUT_F11][SHORT_CUT_CTRL],4);
                    196:     Configuration_WriteToFile(&ConfigureParams.Keyboard.ShortCuts[SHORT_CUT_F12][SHORT_CUT_SHIFT],4);
                    197:     Configuration_WriteToFile(&ConfigureParams.Keyboard.ShortCuts[SHORT_CUT_F12][SHORT_CUT_CTRL],4);
                    198:     Configuration_WriteToFile(ConfigureParams.Keyboard.szMappingFileName,sizeof(ConfigureParams.Keyboard.szMappingFileName));
                    199:     // Sound
                    200:     Configuration_WriteToFile(&ConfigureParams.Sound.bEnableSound,4);
                    201:     Configuration_WriteToFile(&ConfigureParams.Sound.nPlaybackQuality,4);
                    202:     Configuration_WriteToFile(ConfigureParams.Sound.szYMCaptureFileName,sizeof(ConfigureParams.Sound.szYMCaptureFileName));
                    203:     // Memory
                    204:     Configuration_WriteToFile(&ConfigureParams.Memory.nMemorySize,4);
                    205:     Configuration_WriteToFile(ConfigureParams.Memory.szMemoryCaptureFileName,sizeof(ConfigureParams.Memory.szMemoryCaptureFileName));
                    206:     // DiscImage
                    207:     Configuration_WriteToFile(&ConfigureParams.DiscImage.bAutoInsertDiscB,4);
                    208:     Configuration_WriteToFile(ConfigureParams.DiscImage.szDiscImageDirectory,sizeof(ConfigureParams.DiscImage.szDiscImageDirectory));
                    209:     // HardDisc
                    210:     Configuration_WriteToFile(&ConfigureParams.HardDisc.nDriveList,4);
                    211:     Configuration_WriteToFile(&ConfigureParams.HardDisc.bBootFromHardDisc,4);
                    212:     Configuration_WriteToFile(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_C],sizeof(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_C]));
                    213:     Configuration_WriteToFile(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_D],sizeof(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_D]));
                    214:     Configuration_WriteToFile(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_E],sizeof(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_E]));
                    215:     Configuration_WriteToFile(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_F],sizeof(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_F]));
                    216:     // TOSGEM
                    217:     Configuration_WriteToFile(ConfigureParams.TOSGEM.szTOSImageFileName,sizeof(ConfigureParams.TOSGEM.szTOSImageFileName));
                    218:     Configuration_WriteToFile(&ConfigureParams.TOSGEM.bUseTimeDate,4);
                    219:     Configuration_WriteToFile(&ConfigureParams.TOSGEM.bAccGEMGraphics,4);
                    220:     Configuration_WriteToFile(&ConfigureParams.TOSGEM.bUseExtGEMResolutions,4);
                    221:     Configuration_WriteToFile(&ConfigureParams.TOSGEM.nGEMResolution,4);
                    222:     Configuration_WriteToFile(&ConfigureParams.TOSGEM.nGEMColours,4);
                    223:     // RS232
                    224:     Configuration_WriteToFile(&ConfigureParams.RS232.bEnableRS232,4);
                    225:     Configuration_WriteToFile(&ConfigureParams.RS232.nCOMPort,4);
                    226:     // Printer
                    227:     Configuration_WriteToFile(&ConfigureParams.Printer.bEnablePrinting,4);
                    228:     Configuration_WriteToFile(&ConfigureParams.Printer.bPrintToFile,4);
                    229:     Configuration_WriteToFile(ConfigureParams.Printer.szPrintToFileName,sizeof(ConfigureParams.Printer.szPrintToFileName));
                    230:     // Favourites
                    231:     Configuration_WriteToFile(&ConfigureParams.Favourites.bCheckDiscs,4);
                    232:     Configuration_WriteToFile(&ConfigureParams.Favourites.bOnlyShowIfExist,4);
                    233: 
                    234:     // And close up
                    235:     Configuration_CloseFile();
                    236:   }
                    237: */
                    238: }
                    239: 
                    240: 
                    241: /*-----------------------------------------------------------------------*/
                    242: /*
                    243:   Open configuration file to write to
                    244: */
                    245: BOOL Configuration_OpenFileToWrite(void)
                    246: {
                    247:   char szString[MAX_FILENAME_LENGTH];
                    248: 
                    249:   /* Create file */
                    250:   sprintf(szString,"%s/hatari.cfg",szWorkingDir);
                    251:   ConfigFile = fopen(szString, "wb");
                    252:   if (ConfigFile!=NULL)
                    253:     return(TRUE);
                    254: 
                    255:   /* Whoops, error */
                    256:   return(FALSE);
                    257: }
                    258: 
                    259: 
                    260: /*-----------------------------------------------------------------------*/
                    261: /*
                    262:   Open configuration file for reading
                    263: */
                    264: BOOL Configuration_OpenFileToRead(void)
                    265: {
                    266:   char szString[MAX_FILENAME_LENGTH];
                    267: 
                    268:   /* Create file */
                    269:   sprintf(szString,"%s/hatari.cfg",szWorkingDir);
                    270:   ConfigFile = fopen(szString, "rb");
                    271:   if (ConfigFile!=NULL)
                    272:     return(TRUE);
                    273: 
                    274:   /* Whoops, error */
                    275:   return(FALSE);
                    276: }
                    277: 
                    278: 
                    279: /*-----------------------------------------------------------------------*/
                    280: /*
                    281:   Close configuration
                    282: */
                    283: void Configuration_CloseFile(void)
                    284: {
                    285:   fclose(ConfigFile);
                    286: }
                    287: 
                    288: 
                    289: /*-----------------------------------------------------------------------*/
                    290: /*
                    291:   Write entry to configuration file
                    292: */
                    293: void Configuration_WriteToFile(void *pData,int nBytes)
                    294: {
                    295:   fwrite(pData, 1, nBytes, ConfigFile);
                    296: }
                    297: 
                    298: 
                    299: /*-----------------------------------------------------------------------*/
                    300: /*
                    301:   Read entry from configuration file
                    302: */
                    303: void Configuration_ReadFromFile(void *pData,int nBytes)
                    304: {
                    305:   fread(pData, 1, nBytes, ConfigFile);
                    306: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.