Skip to content

Commit

Permalink
Bug fixes and improvements (#54)
Browse files Browse the repository at this point in the history
* Bug fixes and improvements

* changed xa_edc to boolean type

* changed dummy xml Attribute to UnsignedAttribute

* File Flags for games that don't have normal flags

* More date-related fixes

* fixed some compiling warnings

* Some more date-related fixes

* Support for games built with newer mastering tool

* extract files in a folder if no -x arg is given

* Some QoL and minor fixes

* reverted back to "type" entry for dummies

* compatibility with old dumped files timestamps

* minor cosmetic format changes
  • Loading branch information
N4gtan authored Oct 1, 2024
1 parent 08fa69f commit 97f6d78
Show file tree
Hide file tree
Showing 19 changed files with 566 additions and 228 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

steps:
- name: Fetch repo contents
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: mkpsxiso
submodules: recursive
Expand All @@ -22,7 +22,7 @@ jobs:
cmake --build build --config Release -t package
- name: Upload build artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: mkpsxiso-windows
path: |
Expand All @@ -40,18 +40,18 @@ jobs:
sudo apt-get install -y --no-install-recommends build-essential ninja-build
- name: Fetch repo contents
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: mkpsxiso
submodules: recursive

- name: Build and package mkpsxiso
run: |
cmake --preset ci -S mkpsxiso
cmake --build build -t package
cmake --build build --config Release -t package
- name: Upload build artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: mkpsxiso-linux
path: |
Expand All @@ -68,7 +68,7 @@ jobs:
steps:
- name: Fetch build artifacts
if: ${{ github.ref_type == 'tag' }}
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
path: .

Expand Down
25 changes: 19 additions & 6 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
{
"version": 2,
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 20,
"minor": 19,
"patch": 0
},
"configurePresets": [
{
"name": "default",
"displayName": "Default configuration",
"name": "release",
"displayName": "Release build",
"description": "Use this preset when building mkpsxiso for local installation.",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build"
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE": "Release"
}
},
{
"name": "debug",
"displayName": "Debug configuration",
"description": "Use this preset when debugging mkpsxiso.",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG": "Debug"
}
},
{
"name": "ci",
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

1. Set up CMake and a compiler toolchain. Install the `cmake` and `build-essential` packages provided by your Linux distro, or one of the following kits on Windows:
* MSVC (do not install CMake through the Visual Studio installer, download it from [here](https://cmake.org/download) instead)
* MSys2 (use the "MinGW 64-bit" shell) with the following packages: `git`, `mingw-w64-x86_64-make`, `mingw-w64-x86_64-cmake`, `mingw-w64-x86_64-g++`
* MSys2 (use the "MinGW 64-bit" shell) with the following packages: `git`, `mingw-w64-x86_64-make`, `mingw-w64-x86_64-cmake`, `mingw-w64-x86_64-gcc`
* Cygwin64 with the following packages: `git`, `make`, `cmake`, `gcc`

2. Clone/download the repo, then run the following command from the mkpsxiso directory to ensure `tinyxml2` is also downloaded and updated:
Expand All @@ -45,8 +45,8 @@
3. Run the following commands:

```bash
cmake -S . -B ./build -DCMAKE_BUILD_TYPE=Release
cmake --build ./build
cmake -S . --preset release
cmake --build ./build --config Release
cmake --install ./build
```

Expand Down
11 changes: 9 additions & 2 deletions examples/example.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@
Attributes:
type - Track type (either data or audio).
xa_edc - For data track only, specifies if the image has (true) or no (false) EDC in Form 2 sectors.
If xa_edc is not specified, defaults to 'true'.
new_type - For data track only, specifies if the image was created with the old(<2003) Sony's mastering tool.
If new_type is not specified, defaults to 'false'.
source - For audio tracks only, specifies the file name of a wav audio
file as source data for the audio track.
-->
<track type="data">
<track type="data" xa_edc="true" new_type="false">

<!-- <identifiers>
Optional, Specifies the identifier strings for the data track.
Expand Down Expand Up @@ -159,8 +163,11 @@
Attributes:
sectors - Size of dummy file in sector units (1024 = 2MB).
type - The dummy's submode value. Values between 0-255 only
'0': for a Form 1 dummy (0x00).
'32': for a Form 2 dummy (0x20).
-->
<dummy sectors="1024"/>
<dummy sectors="1024" type="0"/>

<!-- Sample DA audio file entry.
Expand Down
39 changes: 28 additions & 11 deletions src/dumpsxiso/cdreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ bool cd::IsoReader::Open(const fs::path& fileName)
totalSectors = ftell(filePtr) / CD_SECTOR_SIZE;
fseek(filePtr, 0, SEEK_SET);

fread(sectorBuff, CD_SECTOR_SIZE, 1, filePtr);
if (fread(sectorBuff, CD_SECTOR_SIZE, 1, filePtr) != 1) {
Close();
return false;
}

currentByte = 0;
currentSector = 0;
Expand All @@ -52,6 +55,10 @@ bool cd::IsoReader::Open(const fs::path& fileName)

size_t cd::IsoReader::ReadBytes(void* ptr, size_t bytes, bool singleSector)
{
if (currentSector >= totalSectors) {
return 0;
}

size_t bytesRead = 0;
char* const dataPtr = (char*)ptr;
constexpr size_t DATA_SIZE = sizeof(sectorM2F1->data);
Expand Down Expand Up @@ -81,6 +88,10 @@ size_t cd::IsoReader::ReadBytes(void* ptr, size_t bytes, bool singleSector)

size_t cd::IsoReader::ReadBytesXA(void* ptr, size_t bytes, bool singleSector)
{
if (currentSector >= totalSectors) {
return 0;
}

size_t bytesRead = 0;
char* const dataPtr = (char*)ptr;
constexpr size_t DATA_SIZE = sizeof(sectorM2F2->data);
Expand All @@ -104,12 +115,16 @@ size_t cd::IsoReader::ReadBytesXA(void* ptr, size_t bytes, bool singleSector)
}
}

return(bytesRead);
return bytesRead;

}

size_t cd::IsoReader::ReadBytesDA(void* ptr, size_t bytes, bool singleSector)
{
if (currentSector >= totalSectors) {
return 0;
}

size_t bytesRead = 0;
char* const dataPtr = (char*)ptr;
constexpr size_t DATA_SIZE = sizeof(sectorBuff);
Expand Down Expand Up @@ -139,6 +154,10 @@ size_t cd::IsoReader::ReadBytesDA(void* ptr, size_t bytes, bool singleSector)

void cd::IsoReader::SkipBytes(size_t bytes, bool singleSector) {

if (currentSector >= totalSectors) {
return;
}

constexpr size_t DATA_SIZE = sizeof(sectorM2F1->data);

while(bytes > 0) {
Expand All @@ -164,7 +183,9 @@ int cd::IsoReader::SeekToSector(int sector) {
return -1;

fseek(filePtr, CD_SECTOR_SIZE*sector, SEEK_SET);
fread(sectorBuff, CD_SECTOR_SIZE, 1, filePtr);
if (fread(sectorBuff, CD_SECTOR_SIZE, 1, filePtr) != 1) {
return -1;
}

currentSector = sector;
currentByte = 0;
Expand All @@ -181,7 +202,9 @@ size_t cd::IsoReader::SeekToByte(size_t offs) {
int sector = (offs/CD_SECTOR_SIZE);

fseek(filePtr, CD_SECTOR_SIZE*sector, SEEK_SET);
fread(sectorBuff, CD_SECTOR_SIZE, 1, filePtr);
if (fread(sectorBuff, CD_SECTOR_SIZE, 1, filePtr) != 1) {
return 0;
}

currentSector = sector;
currentByte = offs%CD_SECTOR_SIZE;
Expand Down Expand Up @@ -210,13 +233,12 @@ void cd::IsoReader::Close() {
bool cd::IsoReader::PrepareNextSector()
{
currentByte = 0;
currentSector++;

if (fread(sectorBuff, CD_SECTOR_SIZE, 1, filePtr) != 1)
{
return false;
}

currentSector++;

sectorM2F1 = (cd::SECTOR_M2F1*)sectorBuff;
sectorM2F2 = (cd::SECTOR_M2F2*)sectorBuff;
Expand Down Expand Up @@ -336,11 +358,6 @@ std::optional<cd::IsoDirEntries::Entry> cd::IsoDirEntries::ReadEntry(cd::IsoRead
entry.identifier.resize(entry.entry.identifierLen);
reader->ReadBytes(entry.identifier.data(), entry.entry.identifierLen, true);

if (entry.identifier == "ST0D_00D.BIN;1")
{
int i = 0;
}

// Strip trailing zeroes, if any
entry.identifier.resize(strlen(entry.identifier.c_str()));

Expand Down
4 changes: 3 additions & 1 deletion src/dumpsxiso/cdreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ namespace cd {
// Open ISO image
bool Open(const fs::path& fileName);

// Read data sectors in bytes (supports sequential reading)
// Read form1 data(2048) sector in bytes (supports sequential reading)
size_t ReadBytes(void* ptr, size_t bytes, bool singleSector = false);

// Read form2 subheader+data+edc(2336) sector in bytes (supports sequential reading)
size_t ReadBytesXA(void* ptr, size_t bytes, bool singleSector = false);

// Read whole(2352) sector in bytes (supports sequential reading)
size_t ReadBytesDA(void* ptr, size_t bytes, bool singleSector = false);

// Skip bytes in data sectors (supports sequential skipping)
Expand Down
Loading

0 comments on commit 97f6d78

Please sign in to comment.