Fills given entry structure with given file's data, and adds entry to Library list
| 418 | |
| 419 | // Fills given entry structure with given file's data, and adds entry to Library list |
| 420 | int CHogEditDoc::AddFile(const char *pathname, hog_library_entry *entry) { |
| 421 | struct _stat filestat; |
| 422 | char temp_filename[_MAX_PATH]; |
| 423 | char test_filename[_MAX_PATH]; |
| 424 | char filename[PSFILENAME_LEN + 1]; |
| 425 | char ext[_MAX_EXT]; |
| 426 | unsigned length; |
| 427 | int32_t timestamp; |
| 428 | POSITION pos; |
| 429 | char path[_MAX_PATH]; |
| 430 | char drive[_MAX_PATH]; |
| 431 | char newpath[_MAX_PATH]; |
| 432 | hog_library_entry temp_entry; |
| 433 | |
| 434 | // Get file info |
| 435 | if (_stat(pathname, &filestat) != 0) { |
| 436 | return ADDFILE_STAT_ERROR; |
| 437 | } |
| 438 | |
| 439 | // Get just the filename |
| 440 | _splitpath(pathname, NULL, NULL, temp_filename, ext); |
| 441 | |
| 442 | // Check if filename is too big |
| 443 | sprintf(test_filename, "%s%s", temp_filename, ext); |
| 444 | if (strlen(test_filename) > PSFILENAME_LEN) |
| 445 | return ADDFILE_LONG_FNAME_ERROR; |
| 446 | |
| 447 | sprintf(filename, "%s%s", temp_filename, ext); |
| 448 | |
| 449 | length = filestat.st_size; |
| 450 | timestamp = filestat.st_mtime; |
| 451 | |
| 452 | _splitpath(pathname, drive, path, NULL, NULL); |
| 453 | sprintf(newpath, "%s%s", drive, path); |
| 454 | strcpy(path, filename); |
| 455 | |
| 456 | // See if this entry is already in the library |
| 457 | pos = Library.filelist.GetHeadPosition(); |
| 458 | while (pos) { |
| 459 | temp_entry = Library.filelist.GetNext(pos); |
| 460 | if (!stricmp(temp_entry.name, filename) /*&& !stricmp(temp_entry.path, newpath)*/) |
| 461 | return ADDFILE_DUP_FILE_ERROR; |
| 462 | } |
| 463 | |
| 464 | // this is a new entry, so set it up and add it to the list! |
| 465 | strcpy(entry->path, newpath); |
| 466 | strcpy(entry->name, filename); |
| 467 | entry->length = length; |
| 468 | entry->timestamp = timestamp; |
| 469 | entry->offset = -1; // Entry was not read in from a hogfile |
| 470 | |
| 471 | Library.filelist.AddTail(*entry); |
| 472 | DocModified = true; |
| 473 | |
| 474 | return ADDFILE_OK; |
| 475 | } |
| 476 | |
| 477 | // Checks to see if file has been modified, and updates entry accordingly |
no test coverage detected