| 201 | } |
| 202 | |
| 203 | void LoadCSV(string name) { |
| 204 | csv_devs.clear(); |
| 205 | // Load mappings... |
| 206 | //DebugPrint(("Opening file " + name).c_str()); |
| 207 | HANDLE file = CreateFile(name.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); |
| 208 | if (file != INVALID_HANDLE_VALUE) { |
| 209 | // read and parse... |
| 210 | size_t linePos = 0, oldLinePos = 0; |
| 211 | DWORD filesize = GetFileSize(file, NULL); |
| 212 | byte* filebuf = new byte[filesize+1]; |
| 213 | ReadFile(file, (LPVOID) filebuf, filesize, NULL, NULL); |
| 214 | filebuf[filesize] = 0; |
| 215 | string content = (char *) filebuf; |
| 216 | delete[] filebuf; |
| 217 | string line; |
| 218 | gearInfo tGear; |
| 219 | while ((linePos = content.find("\r\n", oldLinePos)) != string::npos) { |
| 220 | vector<string> fields; |
| 221 | size_t pos = 0, posOld = 1; |
| 222 | line = content.substr(oldLinePos, linePos - oldLinePos); |
| 223 | oldLinePos = linePos + 2; |
| 224 | if (!line.empty()) { |
| 225 | while ((pos = line.find("','", posOld)) != string::npos) { |
| 226 | fields.push_back(line.substr(posOld, pos - posOld)); |
| 227 | posOld = pos + 3; |
| 228 | } |
| 229 | fields.push_back(line.substr(posOld, line.length() - posOld - 1)); |
| 230 | if (tGear.found || fields.front()[0] == '3') { |
| 231 | switch (fields.front()[0]) { |
| 232 | case '0': { // device line |
| 233 | WORD vid = (WORD)atoi(fields[1].c_str()), |
| 234 | pid = (WORD)atoi(fields[2].c_str()); |
| 235 | DebugPrint("Device " + tGear.name + " - " + to_string(vid) + "/" + to_string(pid) + ": "); |
| 236 | if (tGear.found = conf->afx_dev.GetDeviceById(pid, vid)) { |
| 237 | tGear.devs.push_back({ pid, vid, NULL, fields[3] }); |
| 238 | DebugPrint("Matched.\n") |
| 239 | } |
| 240 | #ifdef _DEBUG |
| 241 | else { |
| 242 | DebugPrint("Skipped.\n"); |
| 243 | } |
| 244 | #endif // _DEBUG |
| 245 | } break; |
| 246 | case '1': { // lights line |
| 247 | byte ltId = (byte)atoi(fields[1].c_str()); |
| 248 | DWORD gridval = MAKELPARAM(tGear.devs.back().pid, ltId); |
| 249 | DWORD data = atoi(fields[2].c_str()); |
| 250 | tGear.devs.back().lights.push_back({ ltId, { LOWORD(data), HIWORD(data) }, fields[3]}); |
| 251 | // grid maps |
| 252 | for (int i = 4; i < fields.size(); i += 2) { |
| 253 | int gid = atoi(fields[i].c_str()); |
| 254 | for (auto pos = tGear.grids.begin(); pos != tGear.grids.end(); pos++) |
| 255 | if (pos->id == gid) { |
| 256 | pos->grid[atoi(fields[i + 1].c_str())].lgh = gridval; |
| 257 | break; |
| 258 | } |
| 259 | } |
| 260 | } break; |
no test coverage detected