| 176 | } |
| 177 | |
| 178 | int CScriptBuilder::LoadScriptSection(const char* filename) |
| 179 | { |
| 180 | // Open the script file |
| 181 | string scriptFile = filename; |
| 182 | #if _MSC_VER >= 1500 && !defined(__S3E__) |
| 183 | #ifdef _WIN32 |
| 184 | // Convert the filename from UTF8 to UTF16 |
| 185 | wchar_t bufUTF16_name[10000] = {0}; |
| 186 | wchar_t bufUTF16_mode[10] = {0}; |
| 187 | MultiByteToWideChar(CP_UTF8, 0, filename, -1, bufUTF16_name, 10000); |
| 188 | MultiByteToWideChar(CP_UTF8, 0, "rb", -1, bufUTF16_mode, 10); |
| 189 | |
| 190 | FILE *f = 0; |
| 191 | _wfopen_s(&f, bufUTF16_name, bufUTF16_mode); |
| 192 | #else |
| 193 | FILE* f = 0; |
| 194 | fopen_s(&f, scriptFile.c_str(), "rb"); |
| 195 | #endif |
| 196 | #else |
| 197 | FILE *f = fopen(scriptFile.c_str(), "rb"); |
| 198 | #endif |
| 199 | if( f == 0 ) |
| 200 | { |
| 201 | // Write a message to the engine's message callback |
| 202 | string msg = "Failed to open script file '" + GetAbsolutePath(scriptFile) + "'"; |
| 203 | engine->WriteMessage(filename, 0, 0, asMSGTYPE_ERROR, msg.c_str()); |
| 204 | |
| 205 | // TODO: Write the file where this one was included from |
| 206 | |
| 207 | return -1; |
| 208 | } |
| 209 | |
| 210 | // Determine size of the file |
| 211 | fseek(f, 0, SEEK_END); |
| 212 | int len = ftell(f); |
| 213 | fseek(f, 0, SEEK_SET); |
| 214 | |
| 215 | // On Win32 it is possible to do the following instead |
| 216 | // int len = _filelength(_fileno(f)); |
| 217 | |
| 218 | // Read the entire file |
| 219 | string code; |
| 220 | size_t c = 0; |
| 221 | if( len > 0 ) |
| 222 | { |
| 223 | code.resize(len); |
| 224 | c = fread(&code[0], len, 1, f); |
| 225 | } |
| 226 | |
| 227 | fclose(f); |
| 228 | |
| 229 | if( c == 0 && len > 0 ) |
| 230 | { |
| 231 | // Write a message to the engine's message callback |
| 232 | string msg = "Failed to load script file '" + GetAbsolutePath(scriptFile) + "'"; |
| 233 | engine->WriteMessage(filename, 0, 0, asMSGTYPE_ERROR, msg.c_str()); |
| 234 | return -1; |
| 235 | } |
nothing calls this directly
no test coverage detected