| 1096 | } |
| 1097 | |
| 1098 | static void parse_diskswapper (const TCHAR *s) |
| 1099 | { |
| 1100 | TCHAR path[MAX_DPATH]; |
| 1101 | int pathlen = 0; |
| 1102 | bool quoted = false; |
| 1103 | auto num = 0; |
| 1104 | |
| 1105 | for (int i = 0; ; i++) { |
| 1106 | TCHAR c = s[i]; |
| 1107 | |
| 1108 | if (c == '\0' || (c == ',' && !quoted)) { |
| 1109 | // End of a path token (maybe) |
| 1110 | path[pathlen] = '\0'; |
| 1111 | |
| 1112 | if (pathlen > 0 && num < MAX_SPARE_DRIVES) { |
| 1113 | // If this is a comma and the path doesn't exist as a file, |
| 1114 | // the comma is likely part of the filename — keep accumulating |
| 1115 | if (c == ',' && !zfile_exists(path)) { |
| 1116 | if (pathlen < MAX_DPATH - 1) |
| 1117 | path[pathlen++] = ','; |
| 1118 | continue; |
| 1119 | } |
| 1120 | |
| 1121 | auto *expanded = target_expand_environment(path, nullptr, 0); |
| 1122 | const TCHAR *use_path = expanded ? expanded : path; |
| 1123 | |
| 1124 | if (!zfile_zopen(use_path, diskswapper_cb, &num)) { |
| 1125 | _tcsncpy(currprefs.dfxlist[num], use_path, 255); |
| 1126 | num++; |
| 1127 | } |
| 1128 | |
| 1129 | xfree(expanded); |
| 1130 | } |
| 1131 | |
| 1132 | pathlen = 0; |
| 1133 | |
| 1134 | if (c == '\0') |
| 1135 | break; |
| 1136 | } else if (c == '"') { |
| 1137 | quoted = !quoted; |
| 1138 | } else { |
| 1139 | if (pathlen < MAX_DPATH - 1) |
| 1140 | path[pathlen++] = c; |
| 1141 | } |
| 1142 | } |
| 1143 | } |
| 1144 | |
| 1145 | static TCHAR *parsetext (const TCHAR *s) |
| 1146 | { |
no test coverage detected