1 #include <fstream>
2 
3 #ifdef __WIN32__
4 	char file_path[50] = "C:\\Program Files\\Pengpong\\";
5 	char config_file_path[50] = "C:\\Program Files\\Pengpong\\config_file";
6 #endif
7 
8 #ifdef __GNUG__
9 	char file_path[50] = "/usr/local/share/pengpong/";
10 	char config_file_path[50] = "/.pengpong/config_file";
11 	char config_file_dir[50] = "/.pengpong/";
12 #endif
13 
14 extern object adam, david,ball;
15 extern int ai;
16 extern int difficult;
17 
read_config_file()18 void read_config_file()
19 {
20 	std::ifstream a_file;
21 	char *temp_string1, *temp_string2;
22 	char *temp_config_path;
23 	temp_string1 = new char[50];
24 	temp_string2 = new char[50];
25 	temp_config_path = new char[80];
26 
27 	#ifdef __GNUG__
28 
29 	char temp_dir[100];
30 	char temp_command[50];
31 	sprintf(temp_config_path, "%s%s", getenv("HOME"),
32 	config_file_path);
33 	sprintf(temp_dir, "%s%s", getenv("HOME"), config_file_dir);
34 	sprintf(temp_command, "mkdir %s", temp_dir);
35 	system(temp_command);
36 	sprintf(temp_command, "touch %s", temp_config_path);
37 	system(temp_command);
38 	#endif
39 	#ifdef __WIN32__
40 	strcpy(temp_config_path, config_file_path);
41 	#endif
42 
43 	a_file.open(temp_config_path);
44 
45 	while(!a_file.eof())
46 	{
47 
48 		a_file.getline(temp_string1, 50, ':');
49 		a_file.getline(temp_string2, 50);
50 		if(!strcmp(temp_string1,"player1_name"))
51 		{
52 			strcpy(adam.name, temp_string2);
53 		}
54 		if(!strcmp(temp_string1, "player2_name"))
55 		{
56 			strcpy(david.name, temp_string2);
57 		}
58 		if(!strcmp(temp_string1, "have_ai"))
59 		{
60 			if(!strcmp(temp_string2,"1"))
61 				 ai = 1;
62 			else
63 				ai = 0;
64 		}
65 		if(!strcmp(temp_string1, "difficult"))
66 		{
67 			int temp_diff;
68 			temp_diff = atoi(temp_string2);
69 			difficult  =  temp_diff;
70 		}
71 
72 	}
73 	a_file.close();
74 }
75 
write_config_file()76 void write_config_file()
77 {
78 	std::ofstream b_file;
79 	char *temp_config_path;
80 	char *temp_config_data;
81 	temp_config_data = new char[80];
82 	temp_config_path = new char[80];
83 
84 
85 	#ifdef __GNUG__
86 	sprintf(temp_config_path, "%s%s", getenv("HOME"),
87 	config_file_path);
88 	#endif
89 	#ifdef __WIN32__
90 	strcpy(temp_config_path, config_file_path);
91 	#endif
92 
93 	b_file.open(temp_config_path, std::ios::trunc);
94 
95 	sprintf(temp_config_data, "player1_name:%s\n", adam.name);
96 	b_file<<temp_config_data;
97 	sprintf(temp_config_data, "player2_name:%s\n", david.name);
98 	b_file<<temp_config_data;
99 	sprintf(temp_config_data, "have_ai:%d\n", ai);
100 	b_file<<temp_config_data;
101 	sprintf(temp_config_data, "difficult:%d\n", difficult);
102 	b_file<<temp_config_data;
103 	b_file.close();
104 
105 }
106 
107