MCPcopy Create free account
hub / github.com/ClassiCube/ClassiCube / OpenChatLog

Function OpenChatLog

src/Chat.c:124–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

122}
123
124static void OpenChatLog(struct cc_datetime* now) {
125 cc_filepath raw_path;
126 cc_result res;
127 int i;
128 if (Platform_ReadonlyFilesystem || !CreateLogsDirectory()) return;
129
130 /* Ensure multiple instances do not end up overwriting each other's log entries. */
131 for (i = 0; i < 20; i++) {
132 logPath.length = 0;
133 String_Format3(&logPath, "logs/%p4-%p2-%p2 ", &now->year, &now->month, &now->day);
134
135 if (i > 0) {
136 String_Format2(&logPath, "%s _%i.txt", &logName, &i);
137 } else {
138 String_Format1(&logPath, "%s.txt", &logName);
139 }
140
141 Platform_EncodePath(&raw_path, &logPath);
142 res = Stream_AppendPath(&logStream, &raw_path);
143
144 if (res && res != ReturnCode_FileShareViolation) {
145 Chat_DisableLogging();
146 Logger_IOWarn2(res, "appending to", &raw_path);
147 return;
148 }
149
150 if (res == ReturnCode_FileShareViolation) continue;
151 return;
152 }
153
154 Chat_DisableLogging();
155 Chat_Add1("&cFailed to open a chat log file after %i tries, giving up", &i);
156}
157
158static void AppendChatLog(const cc_string* text) {
159 cc_string str; char strBuffer[DRAWER2D_MAX_TEXT_LENGTH];

Callers 1

AppendChatLogFunction · 0.85

Calls 9

CreateLogsDirectoryFunction · 0.85
String_Format3Function · 0.85
String_Format2Function · 0.85
String_Format1Function · 0.85
Stream_AppendPathFunction · 0.85
Chat_DisableLoggingFunction · 0.85
Logger_IOWarn2Function · 0.85
Chat_Add1Function · 0.85
Platform_EncodePathFunction · 0.70

Tested by

no test coverage detected