Advertisement
AFRLme

Write to config.ini [VS] (works)

Nov 4th, 2012
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.37 KB | None | 0 0
  1. -- * creates a temporary file to store edited settings which is renamed once the original config.ini file has been removed! * --
  2. function save_ini()
  3.  
  4. -- * locals * --
  5. local newIniFilename = 'config.ini.bak'
  6. local newIniFile = io.open(newIniFilename, 'w')
  7.  
  8. local fullscreen = getObject('Conditions[fullscreen?]'):getBool(VConditionValue)
  9. local subtitles = getObject('Conditions[subtitles?]'):getBool(VConditionValue)
  10. local resolution = getObject('Values[resolution?]'):getInt(VValueInt)
  11. local language = getObject('Values[language?]'):getInt(VValueInt)
  12.  
  13. -- * convert resolution integer into a string * --
  14. local res_str = 0
  15. if resolution == 1 then res_str = '1024x768'
  16. else
  17. if resolution == 2 then res_str = '1280x1024'
  18. else
  19. if resolution == 3 then res_str = '1680x1050'
  20. else
  21. if resolution == 4 then res_str = '1920x1080'
  22. end end end end
  23.  
  24. -- * convert language integer into a string * --
  25. local lang_str = 0
  26. if language == 0 then lang_str = 'English'
  27. else
  28. if language == 1 then lang_str = 'German'
  29. else
  30. if language == 2 then lang_str = 'Spanish'
  31. end end end
  32.  
  33. -- * write the data file * --
  34. newIniFile:write('File = config_ini_v5.ved\n')
  35.  
  36. -- *  write the comments for fullscreen section! * --
  37. newIniFile:write('# Fullscreen = {Yes|No}\n')
  38. newIniFile:write('# Yes - starts the game in fullscreen\n')
  39. newIniFile:write('# No - starts the game in a window\n')
  40.  
  41. if fullscreen then
  42.  newIniFile:write('Fullscreen = Yes\n')
  43.  
  44. -- * write comments for the resolution section! * --
  45.  newIniFile:write('#\n')
  46.  newIniFile:write('# Resolution = {Auto|Desktop|Custom}\n')
  47.  newIniFile:write('# Auto - wide-screen support is activated if a wide-screen display is detected\n')
  48.  newIniFile:write('# Desktop - current desktop resolution is used when game is started in full screen mode\n')
  49.  newIniFile:write('# Custom - enter a custom value eg: Resolution = 1920x1080\n')
  50.  
  51. newIniFile:write('Resolution = Auto\n')
  52. else
  53.  newIniFile:write('Fullscreen = No\n')
  54.  
  55. -- * write comments for the resolution section! * --
  56.  newIniFile:write('#\n')
  57.  newIniFile:write('# Resolution = {Auto|Desktop|Custom}\n')
  58.  newIniFile:write('# Auto - wide-screen support is activated if a wide-screen display is detected\n')
  59.  newIniFile:write('# Desktop - current desktop resolution is used when game is started in full screen mode\n')
  60.  newIniFile:write('# Custom - enter a custom value eg: Resolution = 1920x1080\n')
  61.  
  62. newIniFile:write('Resolution = ' .. res_str .. '\n')
  63. end
  64.  
  65. -- * write comments for the subtitles section! * --
  66.  newIniFile:write('#\n')
  67.  newIniFile:write('# Subtitles = {Yes|No}\n')
  68.  newIniFile:write('# Yes - show subtitles during the game and videos\n')
  69.  newIniFile:write('# No - don\'t show subtitles during the game and videos\n')
  70.  
  71. if subtitles then
  72.  newIniFile:write('Subtitles = Yes\n')
  73. else
  74.  newIniFile:write('Subtitles = No\n')
  75. end
  76.  
  77. -- * write comments for the language section! * --
  78.  newIniFile:write('#\n')
  79.  newIniFile:write('# Language = {English|German|Spanish}\n')
  80.  newIniFile:write('# this will display subtitles in the specified language and will play the appropriate voice sample if available\n')
  81.  newIniFile:write('# default voice samples are in English\n')
  82.  
  83. newIniFile:write('Language = ' .. lang_str .. '\n')
  84.  
  85. -- * write comments for log section! * --
  86.  newIniFile:write('#\n')
  87.  newIniFile:write('# LogLevel = {Info|Warning|Error}\n')
  88.  
  89. newIniFile:write('LogLevel = Error\n')
  90.  
  91. -- * write comments for volume section! * --
  92.  newIniFile:write('#\n')
  93.  newIniFile:write('# MusicVolume|SoundVolume|SpeechVolume = int value {0-100}\n')
  94.  
  95. -- * close the ini file! * --
  96. newIniFile:close()
  97.  
  98. -- * rename config.ini.bak to config.ini! * --
  99. if os.rename(newIniFilename, 'config.ini') then
  100.  print(newIniFilename .. ' was sucessfully renamed to config.ini!')
  101.  print('saving new settings to config.ini!')
  102. else
  103.  print('renaming ' .. newIniFilename .. ' to config.ini was unsuccessful!')
  104. end
  105.  
  106. -- * print various statements to the log file! * --
  107. if fullscreen then
  108.  print('fullscreen has been set to on!')
  109.  print('resolution has been set to auto!')
  110. else
  111.  print('fullscreen has been set to off!')
  112.  print('resolution has been set to ' .. res_str .. '!')
  113. end
  114.  
  115. if subtitles then
  116.  print('subtitles have been set to on!')
  117. else
  118.  print('subtitles have been set to off!')
  119. end
  120.  
  121. print('language has been set to ' .. lang_str .. '!')
  122. print('new settings have successfully been saved to config.ini!')
  123.  
  124. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement