prefs.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #include "stdafx.h"
  2. #include <winreg.h>
  3. #include <iomanip>
  4. #include "resource.h"
  5. #include "prefs.h"
  6. #define SWAPRB(x) ( (((x)>>16)&0xff) | ((x)&0xff00) | (((x)&0xff)<<16) )
  7. Prefs prefs;
  8. void Prefs::open(){
  9. char *p=getenv( "blitzpath" );
  10. if( !p ){
  11. AfxMessageBox( "blitzpath environment variable not found!",MB_TOPMOST|MB_SETFOREGROUND|MB_ICONINFORMATION );
  12. ExitProcess(0);
  13. }
  14. homeDir=p;
  15. AddFontResource( (homeDir+"/cfg/blitz.fon").c_str() );
  16. setDefault();
  17. bool prg_windowed;
  18. ifstream in( (homeDir+"/cfg/blitzide.prefs").c_str() );
  19. if( !in.good() ) return;
  20. while( !in.eof() ){
  21. string t;in>>t;
  22. if( !t.size() ) continue;
  23. while( in.peek()=='\t' ) in.ignore();
  24. if( t=="prg_debug" ) in>>prg_debug;
  25. else if( t=="prg_lastbuild" ) getline( in,prg_lastbuild );
  26. else if( t=="prg_windowed" ) in>>prg_windowed;
  27. else if( t=="win_maximized" ) in>>win_maximized;
  28. else if( t=="win_notoolbar" ) in>>win_notoolbar;
  29. else if( t=="win_rect" ){
  30. in>>win_rect.left;in>>win_rect.top;
  31. in>>win_rect.right;in>>win_rect.bottom;
  32. }else if( t.substr( 0,5 )=="font_" ){
  33. string s;int h;in>>s;in>>h;
  34. t=t.substr( 5 );
  35. if( t=="editor" ){
  36. font_editor=s;font_editor_height=h;
  37. }else if( t=="tabs" ){
  38. font_tabs=s;font_tabs_height=h;
  39. }else if( t=="debug" ){
  40. font_debug=s;font_debug_height=h;
  41. }
  42. }else if( t.substr( 0,4 )=="rgb_" ){
  43. t=t.substr(4);
  44. string s;in>>s;int rgb=0;
  45. for( int k=0;k<s.size();++k ){
  46. int n=s[k];rgb=(rgb<<4)|(n<='9'?n-'0':(n&31)+9);
  47. }
  48. rgb=SWAPRB(rgb);
  49. if( t=="bkgrnd" ) rgb_bkgrnd=rgb;
  50. else if( t=="string" ) rgb_string=rgb;
  51. else if( t=="ident" ) rgb_ident=rgb;
  52. else if( t=="keyword" ) rgb_keyword=rgb;
  53. else if( t=="comment" ) rgb_comment=rgb;
  54. else if( t=="digit" ) rgb_digit=rgb;
  55. else if( t=="default" ) rgb_default=rgb;
  56. }else if( t=="edit_tabs" ){
  57. in>>edit_tabs;
  58. }else if( t=="edit_blkcursor" ){
  59. in>>edit_blkcursor;
  60. }else if( t=="edit_backup" ){
  61. in>>edit_backup;
  62. }else if( t=="img_toolbar" ){
  63. getline( in,img_toolbar );
  64. }else if( t=="cmd_line" ){
  65. getline( in,cmd_line );
  66. }else if( t=="file_recent" ){
  67. string l;getline( in,l );
  68. if( recentFiles.size()<10 ) recentFiles.push_back( l );
  69. }else{
  70. string s="Unrecognized option '"+t+"' in blitzide.prefs";
  71. AfxMessageBox( "Error in preferences file" );
  72. setDefault();
  73. return;
  74. }
  75. }
  76. createFonts();
  77. }
  78. void Prefs::close(){
  79. ofstream out( (homeDir+"/cfg/blitzide.prefs").c_str() );
  80. if( !out.good() ) return;
  81. out<<"prg_debug\t"<<prg_debug<<endl;
  82. out<<"prg_lastbuild\t"<<prg_lastbuild<<endl;
  83. out<<"win_maximized\t"<<win_maximized<<endl;
  84. out<<"win_notoolbar\t"<<win_notoolbar<<endl;
  85. out<<"win_rect\t"<<win_rect.left<<' '<<win_rect.top<<' '<<win_rect.right<<' '<<win_rect.bottom<<endl;
  86. out<<"font_editor\t"<<font_editor<<' '<<font_editor_height<<endl;
  87. out<<"font_tabs\t"<<font_tabs<<' '<<font_tabs_height<<endl;
  88. out<<"font_debug\t"<<font_debug<<' '<<font_debug_height<<endl;
  89. out<<hex;
  90. out<<"rgb_bkgrnd\t"<<SWAPRB(rgb_bkgrnd)<<endl;
  91. out<<"rgb_string\t"<<SWAPRB(rgb_string)<<endl;
  92. out<<"rgb_ident\t"<<SWAPRB(rgb_ident)<<endl;
  93. out<<"rgb_keyword\t"<<SWAPRB(rgb_keyword)<<endl;
  94. out<<"rgb_comment\t"<<SWAPRB(rgb_comment)<<endl;
  95. out<<"rgb_digit\t"<<SWAPRB(rgb_digit)<<endl;
  96. out<<"rgb_default\t"<<SWAPRB(rgb_default)<<endl;
  97. out<<"edit_tabs\t"<<edit_tabs<<endl;
  98. out<<"edit_blkcursor\t"<<edit_blkcursor<<endl;
  99. out<<"edit_backup\t"<<edit_backup<<endl;
  100. out<<"img_toolbar\t"<<img_toolbar<<endl;
  101. out<<"cmd_line\t"<<cmd_line<<endl;
  102. for( int k=0;k<recentFiles.size();++k ){
  103. out<<"file_recent\t"<<recentFiles[k]<<endl;
  104. }
  105. out<<dec;
  106. RemoveFontResource( (homeDir+"/cfg/blitz.fon").c_str() );
  107. }
  108. void Prefs::setDefault(){
  109. prg_debug=true;
  110. win_rect.left=win_rect.top=0;
  111. win_rect.right=640;win_rect.bottom=480;
  112. win_maximized=false;
  113. win_notoolbar=false;
  114. #ifdef PLUS
  115. font_editor="courier";
  116. font_editor_height=10;
  117. #else
  118. font_editor="blitz";
  119. font_editor_height=12;
  120. #endif
  121. font_tabs="verdana";
  122. font_tabs_height=8;
  123. font_debug="verdana";
  124. font_debug_height=8;
  125. #ifdef PRO
  126. rgb_bkgrnd=RGB( 0x22,0x55,0x88 );
  127. rgb_string=RGB( 0x00,0xff,0x66 );
  128. rgb_ident=RGB( 0xff,0xff,0xff );
  129. rgb_keyword=RGB( 0xaa,0xff,0xff );
  130. rgb_comment=RGB( 0xff,0xee,0x00 );
  131. rgb_digit=RGB( 0x33,0xff,0xdd );
  132. rgb_default=RGB( 0xee,0xee,0xee );
  133. #else
  134. #ifdef PLUS
  135. rgb_bkgrnd= SWAPRB(0x225577);
  136. rgb_string= SWAPRB(0x00ffff);
  137. rgb_ident= SWAPRB(0xffffff);
  138. rgb_keyword=SWAPRB(0xffff00);
  139. rgb_comment=SWAPRB(0x00ff00);
  140. rgb_digit= SWAPRB(0x00ffff);
  141. rgb_default=SWAPRB(0xffffff);
  142. #else
  143. rgb_bkgrnd=RGB( 32,96,96 );
  144. rgb_string=RGB( 0,255,0 );
  145. rgb_ident=RGB( 255,255,255 );
  146. rgb_keyword=RGB( 255,231,95 );
  147. rgb_comment=RGB( 0,255,255 );
  148. rgb_digit=RGB( 200,240,255 );
  149. rgb_default=RGB( 255,240,200 );
  150. #endif
  151. #endif
  152. edit_tabs=4;
  153. edit_blkcursor=false;
  154. edit_backup=2;
  155. img_toolbar="toolbar.bmp";
  156. recentFiles.clear();
  157. createFonts();
  158. }
  159. void Prefs::createFonts(){
  160. editFont.Detach();
  161. tabsFont.Detach();
  162. debugFont.Detach();
  163. conFont.Detach();
  164. editFont.CreatePointFont( font_editor_height*10,font_editor.c_str() );
  165. tabsFont.CreatePointFont( font_tabs_height*10,font_tabs.c_str() );
  166. debugFont.CreatePointFont( font_debug_height*10,font_debug.c_str() );
  167. conFont.CreatePointFont( 80,"courier" );
  168. }