| 25 | // ---------------------------------------------------------------------------------------- |
| 26 | |
| 27 | void file:: |
| 28 | init ( |
| 29 | const std::string& name |
| 30 | ) |
| 31 | { |
| 32 | using namespace std; |
| 33 | |
| 34 | |
| 35 | char buf[3000]; |
| 36 | char* str; |
| 37 | if (GetFullPathNameA(name.c_str(),sizeof(buf),buf,&str) == 0) |
| 38 | { |
| 39 | // the file was not found |
| 40 | throw file_not_found("Unable to find file " + name); |
| 41 | } |
| 42 | state.full_name = buf; |
| 43 | |
| 44 | |
| 45 | string::size_type pos = state.full_name.find_last_of(directory::get_separator()); |
| 46 | if (pos == string::npos) |
| 47 | { |
| 48 | // no valid full path has no separator characters. |
| 49 | throw file_not_found("Unable to find file " + name); |
| 50 | } |
| 51 | state.name = state.full_name.substr(pos+1); |
| 52 | |
| 53 | |
| 54 | // now find the size of this file |
| 55 | WIN32_FIND_DATAA data; |
| 56 | HANDLE ffind = FindFirstFileA(state.full_name.c_str(), &data); |
| 57 | if (ffind == INVALID_HANDLE_VALUE || |
| 58 | (data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) != 0) |
| 59 | { |
| 60 | throw file_not_found("Unable to find file " + name); |
| 61 | } |
| 62 | else |
| 63 | { |
| 64 | uint64 temp = data.nFileSizeHigh; |
| 65 | temp <<= 32; |
| 66 | temp |= data.nFileSizeLow; |
| 67 | state.file_size = temp; |
| 68 | FindClose(ffind); |
| 69 | |
| 70 | ULARGE_INTEGER ull; |
| 71 | ull.LowPart = data.ftLastWriteTime.dwLowDateTime; |
| 72 | ull.HighPart = data.ftLastWriteTime.dwHighDateTime; |
| 73 | std::chrono::nanoseconds epoch(100 * (ull.QuadPart - 116444736000000000)); |
| 74 | state.last_modified = std::chrono::time_point<std::chrono::system_clock>(std::chrono::duration_cast<std::chrono::system_clock::duration>(epoch)); |
| 75 | } |
| 76 | |
| 77 | } |
| 78 | |
| 79 | // ---------------------------------------------------------------------------------------- |
| 80 |
nothing calls this directly
no test coverage detected