mirror of
https://github.com/sanni/cartreader.git
synced 2024-11-14 08:55:06 +01:00
Merge pull request #934 from smesgr9000/master
remove duplicate code of seeking database files for letters
This commit is contained in:
commit
15c94c110b
@ -377,24 +377,7 @@ void setCart_COL() {
|
||||
|
||||
// Open database
|
||||
if (myFile.open("colv.txt", O_READ)) {
|
||||
// Skip ahead to selected starting letter
|
||||
if ((myLetter > 0) && (myLetter <= 26)) {
|
||||
while (myFile.available()) {
|
||||
// Read current name
|
||||
get_line(gamename, &myFile, 96);
|
||||
|
||||
// Compare selected letter with first letter of current name until match
|
||||
while (gamename[0] != 64 + myLetter) {
|
||||
skip_line(&myFile);
|
||||
skip_line(&myFile);
|
||||
get_line(gamename, &myFile, 96);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Rewind one line
|
||||
rewind_line(myFile);
|
||||
}
|
||||
seek_first_letter_in_database(myFile, myLetter);
|
||||
|
||||
// Display database
|
||||
while (myFile.available()) {
|
||||
|
@ -660,7 +660,7 @@ boolean compareCRC(const char* database, uint32_t crc32sum, boolean renamerom, i
|
||||
myFile.close();
|
||||
}
|
||||
} else {
|
||||
println_Msg("OK");
|
||||
println_Msg(FS(FSTRING_OK));
|
||||
}
|
||||
return 1;
|
||||
break;
|
||||
@ -678,6 +678,35 @@ boolean compareCRC(const char* database, uint32_t crc32sum, boolean renamerom, i
|
||||
return 0;
|
||||
}
|
||||
|
||||
// move file pointer to first game line with matching letter. If no match is found the last database entry is selected
|
||||
void seek_first_letter_in_database(FsFile& database, byte myLetter) {
|
||||
char gamename_str[3];
|
||||
#ifdef ENABLE_GLOBAL_LOG
|
||||
// Disable log to prevent unnecessary logging
|
||||
println_Log(F("Select Mapping from List"));
|
||||
dont_log = true;
|
||||
#endif
|
||||
database.rewind();
|
||||
// Skip ahead to selected starting letter
|
||||
if ((myLetter > 0) && (myLetter <= 26)) {
|
||||
myLetter += 'A' - 1;
|
||||
do {
|
||||
// Read current name
|
||||
get_line(gamename_str, &database, 2);
|
||||
// Skip data line
|
||||
skip_line(&database);
|
||||
// Skip empty line
|
||||
skip_line(&database);
|
||||
|
||||
} while (database.available() && gamename_str[0] != myLetter);
|
||||
rewind_line(database, 3);
|
||||
}
|
||||
#ifdef ENABLE_GLOBAL_LOG
|
||||
// Enable log again
|
||||
dont_log = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void starting_letter__subDraw(byte selection, byte line) {
|
||||
display.setDrawColor(0);
|
||||
for (uint8_t i = 0; i < 4; i++) display.drawLine(0, 10 + i * 16, 128, 10 + i * 16);
|
||||
|
@ -770,24 +770,7 @@ void setCart_INTV() {
|
||||
|
||||
// Open database
|
||||
if (myFile.open("intv.txt", O_READ)) {
|
||||
// Skip ahead to selected starting letter
|
||||
if ((myLetter > 0) && (myLetter <= 26)) {
|
||||
while (myFile.available()) {
|
||||
// Read current name
|
||||
get_line(gamename, &myFile, 96);
|
||||
|
||||
// Compare selected letter with first letter of current name until match
|
||||
while (gamename[0] != 64 + myLetter) {
|
||||
skip_line(&myFile);
|
||||
skip_line(&myFile);
|
||||
get_line(gamename, &myFile, 96);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Rewind one line
|
||||
rewind_line(myFile);
|
||||
}
|
||||
seek_first_letter_in_database(myFile, myLetter);
|
||||
|
||||
// Display database
|
||||
while (myFile.available()) {
|
||||
|
@ -755,7 +755,7 @@ static void readDatabaseEntry(FsFile& database, struct database_entry* entry) {
|
||||
|
||||
bool selectMapping(FsFile& database) {
|
||||
// Select starting letter
|
||||
uint8_t myLetter = starting_letter();
|
||||
byte myLetter = starting_letter();
|
||||
|
||||
if (myLetter == 27) {
|
||||
// Change Mapper
|
||||
@ -766,26 +766,7 @@ bool selectMapping(FsFile& database) {
|
||||
setRAMSize();
|
||||
return 0;
|
||||
} else {
|
||||
#ifdef ENABLE_GLOBAL_LOG
|
||||
// Disable log to prevent unnecessary logging
|
||||
println_Log(F("Select Mapping from List"));
|
||||
dont_log = true;
|
||||
#endif
|
||||
database.rewind();
|
||||
// Skip ahead to selected starting letter
|
||||
if ((myLetter > 0) && (myLetter <= 26)) {
|
||||
myLetter += 'A' - 1;
|
||||
struct database_entry entry;
|
||||
// Read current name
|
||||
do {
|
||||
readDatabaseEntry(database, &entry);
|
||||
} while (database.available() && entry.filename[0] != myLetter);
|
||||
rewind_line(database, 3);
|
||||
}
|
||||
#ifdef ENABLE_GLOBAL_LOG
|
||||
// Enable log again
|
||||
dont_log = false;
|
||||
#endif
|
||||
seek_first_letter_in_database(database, myLetter);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -391,24 +391,7 @@ void setCart_WSV() {
|
||||
|
||||
// Open database
|
||||
if (myFile.open("wsv.txt", O_READ)) {
|
||||
// Skip ahead to selected starting letter
|
||||
if ((myLetter > 0) && (myLetter <= 26)) {
|
||||
while (myFile.available()) {
|
||||
// Read current name
|
||||
get_line(gamename, &myFile, 96);
|
||||
|
||||
// Compare selected letter with first letter of current name until match
|
||||
while (gamename[0] != 64 + myLetter) {
|
||||
skip_line(&myFile);
|
||||
skip_line(&myFile);
|
||||
get_line(gamename, &myFile, 96);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Rewind one line
|
||||
rewind_line(myFile);
|
||||
}
|
||||
seek_first_letter_in_database(myFile, myLetter);
|
||||
|
||||
// Display database
|
||||
while (myFile.available()) {
|
||||
|
Loading…
Reference in New Issue
Block a user