| 585 | } |
| 586 | |
| 587 | bool Load_Watches(bool clear, const char* filename) |
| 588 | { |
| 589 | const char DELIM = '\t'; |
| 590 | FILE* WatchFile = fopen(filename,"rb"); |
| 591 | if (!WatchFile) |
| 592 | { |
| 593 | MessageBox(MESSAGEBOXPARENT,"Error opening file.","Ram Watch",MB_OK | MB_ICONERROR); |
| 594 | return false; |
| 595 | } |
| 596 | if(clear) |
| 597 | { |
| 598 | if(!ResetWatches()) |
| 599 | { |
| 600 | fclose(WatchFile); |
| 601 | return false; |
| 602 | } |
| 603 | } |
| 604 | strcpy(currentWatch,filename); |
| 605 | RWAddRecentFile(currentWatch); |
| 606 | AddressWatcher Temp; |
| 607 | Temp.Address = 0; // default values |
| 608 | Temp.Size = 'b'; |
| 609 | Temp.Type = 'h'; |
| 610 | char mode; |
| 611 | char Str_Tmp[1024]; |
| 612 | fgets(Str_Tmp,1024,WatchFile); |
| 613 | sscanf(Str_Tmp,"%c%*s",&mode); |
| 614 | int WatchAdd; |
| 615 | fgets(Str_Tmp,1024,WatchFile); |
| 616 | sscanf(Str_Tmp,"%d%*s",&WatchAdd); |
| 617 | WatchAdd+=WatchCount; |
| 618 | for (int i = WatchCount; i < WatchAdd; i++) |
| 619 | { |
| 620 | if (i < 0) i = 0; |
| 621 | memset(Str_Tmp, 0, 1024); |
| 622 | do |
| 623 | { |
| 624 | fgets(Str_Tmp, 1024, WatchFile); |
| 625 | } while (Str_Tmp[0] == '\n'); |
| 626 | sscanf(Str_Tmp, "%*05X%*c%04X%*c%c%*c%c%*c%*c", &(Temp.Address), &(Temp.Size), &(Temp.Type)); |
| 627 | Temp.WrongEndian = false; |
| 628 | char *Comment = strrchr(Str_Tmp, DELIM); |
| 629 | if (Comment) |
| 630 | { |
| 631 | Comment++; |
| 632 | char *CommentEnd = strrchr(Comment, '\n'); |
| 633 | if (CommentEnd) |
| 634 | { |
| 635 | *CommentEnd = '\0'; |
| 636 | Temp.comment = Comment; |
| 637 | InsertWatch(Temp); |
| 638 | } else |
| 639 | { |
| 640 | // the wch file is probably corrupted |
| 641 | Temp.comment = Comment; |
| 642 | InsertWatch(Temp); |
| 643 | break; |
| 644 | } |
no test coverage detected