Skip to content

Commit 1f09607

Browse files
committed
add user settings
1 parent 98efb44 commit 1f09607

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

main.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <time.h>
2+
#include <unistd.h>
23

34
#include "simlcd.h"
45
#include "dispcolor.h"
@@ -175,10 +176,59 @@ void simlcd_exit()
175176
simlcd_deinit(&div_buf);
176177
}
177178

179+
void save_user()
180+
{
181+
#if(_WIN32)
182+
char buf[0x400];
183+
FILE *fp;
184+
char * appdata = getenv("APPDATA");
185+
if(appdata)
186+
{
187+
snprintf(buf,sizeof(buf),"%s\\clock.config",appdata);
188+
fp=fopen(buf,"wb+");
189+
190+
fwrite(&LCD_BUFFER.wx,4,1,fp);
191+
fwrite(&LCD_BUFFER.wy,4,1,fp);
192+
fwrite(&bg,1,1,fp);
193+
fwrite(&tr,1,1,fp);
194+
fwrite(&zoom,1,1,fp);
195+
196+
fclose(fp);
197+
}
198+
#endif
199+
}
200+
201+
void load_user()
202+
{
203+
#if(_WIN32)
204+
char buf[0x400];
205+
FILE *fp;
206+
char * appdata = getenv("APPDATA");
207+
if(appdata)
208+
{
209+
snprintf(buf,sizeof(buf),"%s\\clock.config",appdata);
210+
fp=fopen(buf,"rb");
211+
212+
if(fp!=NULL)
213+
{
214+
fread(&LCD_BUFFER.wx,4,1,fp);
215+
fread(&LCD_BUFFER.wy,4,1,fp);
216+
fread(&bg,1,1,fp);
217+
fread(&tr,1,1,fp);
218+
fread(&zoom,1,1,fp);
219+
220+
fclose(fp);
221+
}
222+
}
223+
#endif
224+
}
225+
178226
int main(int argc,char *argv[])
179227
{
180228
dispcolor_Init(240*2,240*2);
229+
load_user();
181230
simlcd_play();
231+
save_user();
182232
return 0;
183233
}
184234

0 commit comments

Comments
 (0)