mirror of
https://github.com/fumiama/simple-kanban.git
synced 2026-07-01 16:40:26 +08:00
优化代码架构
This commit is contained in:
12
cfgwriter.c
12
cfgwriter.c
@@ -1,13 +1,8 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "config.h"
|
||||
#include "simple-protobuf/simple_protobuf.h"
|
||||
|
||||
struct CONFIG {
|
||||
char pwd[64]; //password
|
||||
char sps[64]; //set password
|
||||
};
|
||||
typedef struct CONFIG CONFIG;
|
||||
|
||||
CONFIG cfg;
|
||||
|
||||
int main() {
|
||||
@@ -19,13 +14,14 @@ int main() {
|
||||
FILE* fp = fopen("cfg.sp", "wb");
|
||||
if(fp) {
|
||||
set_pb(fp, types_len, sizeof(CONFIG), &cfg);
|
||||
memset(&cfg, 0, sizeof(CONFIG));
|
||||
fclose(fp);
|
||||
puts("Write file succeed.");
|
||||
puts("Config is saved to cfg.sp.");
|
||||
fp = NULL;
|
||||
puts("Check config...");
|
||||
fp = fopen("cfg.sp", "rb");
|
||||
if(fp) {
|
||||
SIMPLE_PB* spb = get_pb(fp);
|
||||
memset(&cfg, 0, sizeof(CONFIG));
|
||||
memcpy(&cfg, spb->target, sizeof(CONFIG));
|
||||
printf("set pwd: %s, sps: %s\n", cfg.pwd, cfg.sps);
|
||||
} else perror("[SPB]");
|
||||
|
||||
Reference in New Issue
Block a user