Сегодня начал писать загрузку конфигураций и мне понравилось что получилось
Я сделал так, что если какой-нибудь умник залезет править конфиги и накосячит, то файл просто удаляется и пишется новый с дефаулт конфигами
Global fileConfig
Global fileConfigError=False
Global graphicsW
Global graphicsH
Global graphicsD
Global graphicsM
Global cameraViewSens#
Const cameraViewSensMin#=0.5
Const cameraViewSensMax#=5
Const cameraViewSensDefault#=2
LoadFileConfig() ;загрузка файла настроек
Function LoadFileConfig()
fileConfig=OpenFile("config.ini")
;-----------eсли файл есть---------------------------
If fileConfig<>0 Then
graphicsW=ReadLine(fileConfig)
graphicsH=ReadLine(fileConfig)
graphicsD=ReadLine(fileConfig)
If GfxMode3DExists(GraphicsW,GraphicsH,GraphicsD)=False Then fileConfigError=True
graphicsM=ReadLine(fileConfig)
If GraphicsM<0 Or GraphicsM>3 Then fileConfigError=True
cameraViewSens#=ReadLine(fileConfig)
If cameraViewSens<cameraViewSensMin Or cameraViewSens>cameraViewSensMax Then fileConfigError=True
If fileConfigError=False Then Graphics3D GraphicsW,GraphicsH,GraphicsD,GraphicsM
If fileConfigError=True Then DeleteFile fileConfig : fileConfig=0
EndIf
;-----------если файла нет---------------------------
If fileConfig=0 Then
;считываем все поддерживаемые видео режимы
For i=1 To CountGfxModes3D()
If GfxMode3DExists(GfxModeWidth(i),GfxModeHeight(i),GfxModeDepth(i)) Then modeN=modeN+1
Next
Graphics3D GfxModeWidth(modeN),GfxModeHeight(modeN),GfxModeDepth(modeN),1 ;выставляем самый высокий видео режим
GraphicsW=GraphicsWidth()
GraphicsH=GraphicsHeight()
GraphicsD=GraphicsDepth()
GraphicsM=1
cameraViewSens=cameraViewSensDefault
fileConfig=WriteFile("config.ini")
WriteLine(fileConfig,GraphicsW)
WriteLine(fileConfig,GraphicsH)
WriteLine(fileConfig,GraphicsD)
WriteLine(fileConfig,GraphicsM)
WriteLine(fileConfig,cameraViewSens)
EndIf
;------------------------------------------------------------
CloseFile fileConfig
End Function