-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCFile.cpp
More file actions
216 lines (180 loc) · 4.07 KB
/
CFile.cpp
File metadata and controls
216 lines (180 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#define _CRT_SECURE_NO_DEPRECATE
#include <wchar.h>
#include "CFile.h"
/* Define File Flags
* 1 - Music
* 2 - Graphic
* 3 - FullScr
*/
// Konstruktor: No spezific function actually
CFile::CFile()
{}
// Dekonstruktor: Close and End the file
CFile::~CFile()
{
Textout("End of Options");
fclose(m_File);
}
inline bool CFile::CSettingsExist(const char *FileName)
{
if (FILE *file = fopen(FileName, "r"))
{
fclose(file);
return true;
}
else
{
return false;
}
}
// CCreateSetting: If setting file not exist, create a setting file
void CFile::CCreateSetting(const char *FileName)
{
if (CSettingsExist(FileName) == false)
{
// if new setting file, so clear this and write the head
m_File = fopen(FileName, "w");
Textout("------- Settings ----------");
Textout("\r\n");
// actually build konfiguration write
#ifdef _DEBUG
Textout("BUILD: DEBUG\r\n");
#else
Textout("BUILD: RELEASE\r\n");
#endif
// Settings closed and reopen with append
fclose(m_File);
m_File = fopen(FileName, "a");
CCreateBasic(FileName);
}
else
COpenFile(FileName);
}
void CFile::CCreateFile(const char* FileName)
{
if (CSettingsExist(FileName) == false)
{
// if new setting file, so clear this and write the head
m_File = fopen(FileName, "w");
Textout("------- Settings ----------");
Textout("\r\n");
// actually build konfiguration write
#ifdef _DEBUG
Textout("BUILD: DEBUG\r\n");
#else
Textout("BUILD: RELEASE\r\n");
#endif
// Settings closed and reopen with append
fclose(m_File);
m_File = fopen(FileName, "a");
}
else
COpenFile(FileName);
}
// CWriteMusic: Write the Music settings to the setting file
void CFile::CWriteMusic(int Music)
{
if (Music == NULL)
{
Music = 50;
Textout("Music: %i", Music, 1);
}
Textout("Music: %i", Music, 1);
}
// CWriteGraphic: Write the Graphic settings to the settings file
void CFile::CWriteGraphic(int x, int y)
{
Textout("Graphic: %i x %i", x, y, 2);
}
// CWriteFullscr: Window Fullscreen or not, write this to setting file
// Fullscreen has two states, 0 for no full screen and 1 for full screen.
void CFile::CWriteFullScr(int FullScr)
{
Textout("Fullscreen: %i", FullScr, 3);
}
// Textout functions.
// Simple Textout for only text.
void CFile::Textout(const char *Text)
{
fprintf(m_File, Text);
fflush(m_File);
}
void CFile::sTextout(const wchar_t *Text2, ...)
{
fwprintf_s(m_File, Text2);
fflush(m_File);
}
void CFile::wTextout(const char *Text, const wchar_t *Text2, ...)
{
fprintf(m_File, Text);
fwprintf(m_File, Text2);
fflush(m_File);
}
void CFile::wTextout(const wchar_t *Text, ...)
{
fprintf(m_File, "Test: ");
fwprintf(m_File, Text);
fflush(m_File);
}
void CFile::wTextout(const wchar_t *Text[], ...)
{
fprintf(m_File, "Test2: ");
for (int i = 0; i < sizeof(Text[i]); i++)
fwprintf(m_File, Text[i]);
fflush(m_File);
}
void CFile::Textout(const char *Text, const char *Text2, ...)
{
fprintf(m_File, Text, Text2);
fflush(m_File);
}
// Textout with one parameter
void CFile::Textout(const char *Text, int x, ...)
{
fprintf(m_File, Text, x);
fflush(m_File);
}
// Textout with one parameter and flag
void CFile::Textout(const char *Text, int x, int flag, ...)
{
switch (flag)
{
default:
break;
}
fprintf(m_File, Text, x);
fflush(m_File);
}
// Textout with two parameter and flag
void CFile::Textout(const char *Text, int x, int y, int flag, ...)
{
fprintf(m_File, Text, x, y);
fflush(m_File);
}
// CCreateBasic: Create a basic file for starting
void CFile::CCreateBasic(const char *FileName)
{
Textout("Music: 50%\r\n");
Textout("Graphic: 800 x 600\r\n");
Textout("Full Screen: 0 (false)\r\n");
}
// COpenFile: Open the file for write and read.
void CFile::COpenFile(const char *FileName)
{
if (CSettingsExist(FileName) == false)
{
CCreateSetting(FileName);
}
else
{
m_File = fopen(FileName, "a");
}
}
// Read functions
// CReadMusic: Read the actually value of Music to see on window
int CFile::CReadMusic()
{
int Music = 0;
fopen("settings.txt", "r");
return Music;
}