| 122 | } |
| 123 | |
| 124 | static 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 | |
| 158 | static void AppendChatLog(const cc_string* text) { |
| 159 | cc_string str; char strBuffer[DRAWER2D_MAX_TEXT_LENGTH]; |
no test coverage detected