Skip to content

Commit

Permalink
refactor: improve date handling and streamline output formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
N4gtan committed Jan 3, 2025
1 parent 2c027b0 commit 344ae42
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 31 deletions.
17 changes: 7 additions & 10 deletions src/dumpsxiso/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1028,20 +1028,17 @@ void ParseISO(cd::IsoReader& reader) {
return left.entry.entryOffs.lsb < right.entry.entryOffs.lsb;
});

unsigned totalLenLBA = descriptor.volumeSize.lsb;
if (!param::QuietMode) {
printf(" Files Total: %zu\n", entries.size() - numEntries);
printf(" Directories: %zu\n", numEntries - 1);
}

unsigned totalLenLBA = descriptor.volumeSize.lsb;
for (auto it = entries.rbegin(); it != entries.rend(); it++) {
if (it->type != EntryType::EntryDA) {
unsigned endFS = it->entry.entryOffs.lsb + GetSizeInSectors(it->entry.entrySize.lsb);
endFS += totalLenLBA - endFS < 150 ? totalLenLBA - endFS : 150;
if (!param::QuietMode) {
for (auto it = entries.rbegin(); it != entries.rend(); it++) {
if (it->type != EntryType::EntryDA) {
unsigned endFS = it->entry.entryOffs.lsb + GetSizeInSectors(it->entry.entrySize.lsb);
endFS += totalLenLBA - endFS < 150 ? totalLenLBA - endFS : 150;
printf(" Total file system size: %u bytes (%u sectors)\n", endFS * CD_SECTOR_SIZE, endFS);
break;
}
break;
}
}

Expand Down Expand Up @@ -1142,7 +1139,7 @@ void ParseISO(cd::IsoReader& reader) {
else if (totalLenLBA - currentLBA < postGap) {
postGap = totalLenLBA - currentLBA;
if (postGap && !param::noWarns) {
printf("WARNING: Size of DATA track postgap sector is %u instead of 150.\n", postGap);
printf("WARNING: Size of DATA track postgap is of %u sectors instead of 150.\n", postGap);
}
}
else if (!DAfiles.empty() && DAfiles[0]->entry.entryOffs.lsb - postGap == currentLBA) {
Expand Down
2 changes: 1 addition & 1 deletion src/mkpsxiso/cdwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void IsoWriter::SectorView::CalculateForm2()
EDC_ECC_GEN.ComputeEdcBlock(sector->data, sizeof(sector->data) - 4, &sector->data[2332]);
}
else {
std::memset(&sector->data[2332], 0, 4);
memset(&sector->data[2332], 0, 4);
}
}, sector));
}
Expand Down
1 change: 1 addition & 0 deletions src/mkpsxiso/iso.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,7 @@ void iso::DirTreeClass::OutputLBAlisting(FILE* fp, int level) const
// Print first the files in the directory
for (const auto& e : entriesInDir) {
const DIRENTRY& entry = e.get();
// Skip directories and postgap dummy
if (entry.type == EntryType::EntryDir || (entry.type == EntryType::EntryDummy && level == 0 && entry.lba > maxlba)) {
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions src/mkpsxiso/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1195,9 +1195,9 @@ int ParseISOfileSystem(const tinyxml2::XMLElement* trackElement, const fs::path&
volumeDate.second = imageTime.tm_sec;
volumeDate.GMToffs = static_cast<signed char>(-SYSTEM_TIMEZONE / 60 / 15); // Seconds to 15-minute units

// Convert volumeDate to const char*
static char dateBuffer[20] {};
snprintf(dateBuffer, sizeof(dateBuffer), "%04hu%02hhu%02hhu%02hhu%02hhu%02hhu00%hhd",
// Convert ISO_DATESTAMP to ISO_LONG_DATESTAMP char*
static char dateBuffer[20];
snprintf(dateBuffer, sizeof(dateBuffer), "%04u%02hhu%02hhu%02hhu%02hhu%02hhu00%+hhd",
volumeDate.year + 1900, volumeDate.month, volumeDate.day,
volumeDate.hour, volumeDate.minute, volumeDate.second, volumeDate.GMToffs);

Expand Down
27 changes: 10 additions & 17 deletions src/shared/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ ISO_DATESTAMP GetDateFromString(const char* str, bool* success)

ISO_DATESTAMP result {};

unsigned short year;
const int argsRead = sscanf( str, "%04hu%02hhu%02hhu%02hhu%02hhu%02hhu%*2u%hhd",
unsigned int year;
const int argsRead = sscanf( str, "%4u%2hhu%2hhu%2hhu%2hhu%2hhu%*2u%hhd",
&year, &result.month, &result.day,
&result.hour, &result.minute, &result.second, &result.GMToffs );
if (argsRead >= 6)
Expand All @@ -40,10 +40,9 @@ ISO_LONG_DATESTAMP GetLongDateFromString(const char* str)
ISO_LONG_DATESTAMP result {};

if (str) {
unsigned short year;
unsigned char month, day, hour, minute, second, hsecond;
unsigned int year, month, day, hour, minute, second, hsecond {};

const unsigned char argsRead = sscanf( str, "%04hu%02hhu%02hhu%02hhu%02hhu%02hhu%02hhu%hhd",
const int argsRead = sscanf( str, "%4u%2u%2u%2u%2u%2u%2u%hhd",
&year, &month, &day, &hour, &minute, &second, &hsecond, &result.GMToffs );

if (argsRead >= 6) {
Expand All @@ -52,10 +51,10 @@ ISO_LONG_DATESTAMP GetLongDateFromString(const char* str)
result.GMToffs = 36;
}

auto intToChars = [](unsigned short value, char* buf, unsigned char size) {
for (signed char i = size - 1; i >= 0; --i) {
buf[i] = '0' + (value % 10);
value /= 10;
auto intToChars = [](unsigned int src, char* dest, unsigned int size) {
for (int i = size - 1; i >= 0; --i) {
dest[i] = '0' + (src % 10);
src /= 10;
}
};

Expand All @@ -78,13 +77,7 @@ ISO_LONG_DATESTAMP GetUnspecifiedLongDate()
{
ISO_LONG_DATESTAMP result;

strncpy(result.year, "0000", std::size(result.year));
strncpy(result.month, "00", std::size(result.month));
strncpy(result.day, "00", std::size(result.day));
strncpy(result.hour, "00", std::size(result.hour));
strncpy(result.minute, "00", std::size(result.minute));
strncpy(result.second, "00", std::size(result.second));
strncpy(result.hsecond, "00", std::size(result.hsecond));
memset(&result, '0', sizeof(result));
result.GMToffs = 0;

return result;
Expand All @@ -97,7 +90,7 @@ std::string LongDateToString(const cd::ISO_LONG_DATESTAMP& src)

std::string result(srcStr, srcStr+16);

char GMTbuf[8];
char GMTbuf[4];
snprintf(GMTbuf, sizeof(GMTbuf), "%+hhd", src.GMToffs);
result.append(GMTbuf);

Expand Down

0 comments on commit 344ae42

Please sign in to comment.