| 177 | } |
| 178 | |
| 179 | void |
| 180 | getlock() |
| 181 | { |
| 182 | const char *fq_lock; |
| 183 | char tbuf[BUFSZ]; |
| 184 | TCHAR wbuf[BUFSZ]; |
| 185 | HANDLE f; |
| 186 | int fd; |
| 187 | int choice; |
| 188 | |
| 189 | /* regularize(lock); */ /* already done in pcmain */ |
| 190 | Sprintf(tbuf, "%s", fqname(gl.lock, LEVELPREFIX, 0)); |
| 191 | set_levelfile_name(gl.lock, 0); |
| 192 | fq_lock = fqname(gl.lock, LEVELPREFIX, 1); |
| 193 | |
| 194 | f = CreateFile(NH_A2W(fq_lock, wbuf, BUFSZ), GENERIC_READ, 0, NULL, |
| 195 | OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
| 196 | if (f == INVALID_HANDLE_VALUE) { |
| 197 | if (GetLastError() == ERROR_FILE_NOT_FOUND) |
| 198 | goto gotlock; /* no such file */ |
| 199 | error("Cannot open %s", fq_lock); |
| 200 | } |
| 201 | |
| 202 | CloseHandle(f); |
| 203 | |
| 204 | /* prompt user that the game alredy exist */ |
| 205 | choice = MessageBox(GetNHApp()->hMainWnd, |
| 206 | TEXT("There are files from a game in progress under " |
| 207 | "your name. Recover?"), |
| 208 | TEXT("Nethack"), MB_YESNO | MB_DEFBUTTON1); |
| 209 | switch (choice) { |
| 210 | case IDYES: |
| 211 | if (recover_savefile()) { |
| 212 | goto gotlock; |
| 213 | } else { |
| 214 | error("Couldn't recover old game."); |
| 215 | } |
| 216 | break; |
| 217 | |
| 218 | case IDNO: |
| 219 | unlock_file(HLOCK); |
| 220 | error("%s", "Cannot start a new game."); |
| 221 | break; |
| 222 | }; |
| 223 | |
| 224 | gotlock: |
| 225 | fd = creat(fq_lock, FCMASK); |
| 226 | if (fd == -1) { |
| 227 | error("cannot creat lock file (%s.)", fq_lock); |
| 228 | } else { |
| 229 | if (write(fd, (char *) &svh.hackpid, sizeof(svh.hackpid)) |
| 230 | != sizeof(svh.hackpid)) { |
| 231 | error("cannot write lock (%s)", fq_lock); |
| 232 | } |
| 233 | if (close(fd) == -1) { |
| 234 | error("cannot close lock (%s)", fq_lock); |
| 235 | } |
| 236 | } |
nothing calls this directly
no test coverage detected