Skip to content

Commit

Permalink
Fixed NOMINMAX redefinition warnings, added -c|--cuefile argument, de…
Browse files Browse the repository at this point in the history
…fault output name now derived from XML project name, added -l|--label argument, added ISO descriptor check in dumpsxiso
  • Loading branch information
Lameguy64 committed Jun 24, 2022
1 parent 9d3da9d commit 7bcb4ad
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 27 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.20)
project(
mkpsxiso
LANGUAGES C CXX
VERSION 2.01
VERSION 2.02
DESCRIPTION "PlayStation ISO image maker & dumping tool"
HOMEPAGE_URL "https://github.com/Lameguy64/mkpsxiso"
)
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,21 @@ The only known major issue that hasn't (or cannot) be resolved is that if you cr
</dir>
```
On Windows, browsing the subdirectories in dirb and dirc will not list the contents for some reason and trying to access it in a command prompt leads to a permission denied or similar error message. Disc image tools such as CDmage will display the contents of the aforementioned subdirectories without issue and the issue persists on disc images created with BuildCD suggesting it is likely an operating system related issue and not an ISO generator issue.
On Windows browsing the subdirectories in 'dirb' and 'dirc' will not list the contents for some reason and trying to access it in a command prompt leads to a permission denied or similar error message. Disc image tools such as CDmage will display the contents of the aforementioned subdirectories without issue and the issue persists with disc images created with BuildCD, suggesting it is likely a bug with the operating system and not mkpsxiso.
This can be avoided by minimizing identically named directories but its best to test your generated disc image before considering it ready for release.
## Changelog
**Version 2.02**
* Fixed NOMINMAX redefinition warnings.
* Added -c|--cuefile argument to specify the cue sheet file name. Overrides the name defined in the XML file.
* Output file is derived from the XML project file name if no output file was specified by arguments or the image_name attribute.
* Added -l|--label argument to specify the volume ID string. Overrides the volume ID defined in the XML file.
* Added id_file attribute for the <identifier> element. Reads identifiers from a separate XML file containing a single <identifier> element.
* Added ISO descriptor check in dumpsxiso.
**Version 2.01 (02/10/2022)**
* Fixed invalid sectors generated when no license file is specified.
* Fixed wide char string specifier for MinGW.
Expand Down
15 changes: 14 additions & 1 deletion src/dumpsxiso/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ int Main(int argc, char *argv[])
" -h|--help - Show this help text\n";

printf( "DUMPSXISO " VERSION " - PlayStation ISO dumping tool\n"
"2017 Meido-Tek Productions (Lameguy64)\n"
"2017 Meido-Tek Productions (John \"Lameguy\" Wilbert Villamor/Lameguy64)\n"
"2020 Phoenix (SadNES cITy)\n"
"2021-2022 Silent, Chromaryu, G4Vi, and spicyjpeg\n\n" );

Expand Down Expand Up @@ -1057,6 +1057,19 @@ int Main(int argc, char *argv[])
return EXIT_FAILURE;

}

// Check if file has a valid ISO9660 header
{
char sectbuff[2048];
//char descid[] = { 0x01, 0x43, 0x44, 0x30, 0x30, 0x31, 0x01 };
reader.SeekToSector(16);
reader.ReadBytes(&sectbuff, 2048);
if( memcmp(sectbuff, "\1CD001\1", 7) )
{
printf("ERROR: File does not contain a valid ISO9660 file system.\n");
return EXIT_FAILURE;
}
}

if (!param::outPath.empty())
{
Expand Down
2 changes: 2 additions & 0 deletions src/mkpsxiso/edcecc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#define _EDC_ECC_H

#ifdef _WIN32
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
#else
#include <unistd.h>
Expand Down
143 changes: 119 additions & 24 deletions src/mkpsxiso/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace global
int trackNum = 1;
int noXA = false;

std::optional<std::string> volid_override;
std::filesystem::path XMLscript;
std::filesystem::path LBAfile;
std::filesystem::path LBAheaderFile;
Expand All @@ -41,6 +42,8 @@ namespace global
std::optional<std::filesystem::path> cuefile;
int NoIsoGen = false;
std::filesystem::path RebuildXMLScript;

tinyxml2::XMLDocument xmlIdFile;
};


Expand Down Expand Up @@ -80,14 +83,16 @@ int Main(int argc, char* argv[])
" [-lbahead <file>] [-rebuildxml <file>] [-nolimit] [-noisogen] <xml>\n\n"
" -y\t\tAlways overwrite ISO image files\n"
" -q|--quiet\tQuiet mode (suppress all but warnings and errors)\n"
" -o|--output\tSpecify output file (overrides image_name but not cue_sheet)\n"
" -o|--output\tSpecify output file (overrides image_name attribute)\n"
" -c|--cuefile\tSpecify cue sheet file (overrides cue_sheet attribute)\n"
" -l|--label\tSpecify volume ID (overrides volume element)\n"
" <xml>\t\tFile name of disc image project in XML document format\n\n"
" -lba\t\tGenerate a log of file LBA locations in disc image\n"
" -lbahead\tGenerate a C header of file LBA locations in disc image\n"
" -nolimit\tRemove warning when a directory record exceeds a sector\n"
" -noisogen\tDo not generate ISO but calculates file LBA locations only\n"
"\t\t(use with -lba or -lbahead)\n"
" -noxa\t\tDo not generate CD-XA extended file attributes\n"
" -nolimit\tRemove warning when a directory record surpasses a sector\n"
" -noisogen\tDo not generate ISO, but calculate file LBA locations only\n"
"\t\t(for use with -lba or -lbahead)\n"
" -noxa\t\tDo not generate CD-XA extended file attributes (plain ISO9660)\n"
"\t\t(XA data can still be included but not recommended)\n"
" -rebuildxml\tRebuild the XML using our newest schema\n"
" -h|--help\tShow this help text\n";
Expand Down Expand Up @@ -142,6 +147,17 @@ int Main(int argc, char* argv[])
OutputOverride = true;
continue;
}
if (auto output = ParsePathArgument(args, "c", "cuefile"); output.has_value())
{
global::cuefile = *output;
OutputOverride = true;
continue;
}
if (auto label = ParseStringArgument(args, "l", "label"); label.has_value())
{
global::volid_override = label;
continue;
}
if (auto newxmlfile = ParsePathArgument(args, "rebuildxml"); newxmlfile.has_value())
{
global::RebuildXMLScript = *newxmlfile;
Expand Down Expand Up @@ -233,7 +249,9 @@ int Main(int argc, char* argv[])
// Fix XML tree to our current spec
// convert DA file source syntax to DA file trackid syntax
unsigned trackindex = 2;
for(tinyxml2::XMLElement *modifyProject = xmlFile.FirstChildElement(xml::elem::ISO_PROJECT); modifyProject != nullptr; modifyProject = modifyProject->NextSiblingElement(xml::elem::ISO_PROJECT))
for(tinyxml2::XMLElement *modifyProject = xmlFile.FirstChildElement(xml::elem::ISO_PROJECT);
modifyProject != nullptr;
modifyProject = modifyProject->NextSiblingElement(xml::elem::ISO_PROJECT))
{
tinyxml2::XMLElement *modifyTrack = modifyProject->FirstChildElement(xml::elem::TRACK);
if((modifyTrack == nullptr) || (!modifyTrack->Attribute(xml::attrib::TRACK_TYPE, "data")))
Expand Down Expand Up @@ -341,7 +359,7 @@ int Main(int argc, char* argv[])
imagesCount++;
if ( imagesCount > 1 && OutputOverride )
{
printf( "ERROR: -o switch cannot be used in multi-disc ISO "
printf( "ERROR: -o or -c switch cannot be used in multi-disc ISO "
"project.\n" );
return EXIT_FAILURE;
}
Expand All @@ -355,15 +373,18 @@ int Main(int argc, char* argv[])
}
else
{
printf( "ERROR: %s attribute not specfied in "
"<iso_project> element.\n", xml::attrib::IMAGE_NAME );
return EXIT_FAILURE;
// Use file name of XML project as the image file name
global::ImageName = global::XMLscript.stem();
global::ImageName += ".iso";
}
}

if ( const char* cue_sheet = projectElement->Attribute(xml::attrib::CUE_SHEET); cue_sheet != nullptr )
if ( !global::cuefile )
{
global::cuefile = std::filesystem::u8path(cue_sheet);
if ( const char* cue_sheet = projectElement->Attribute(xml::attrib::CUE_SHEET); cue_sheet != nullptr )
{
global::cuefile = std::filesystem::u8path(cue_sheet);
}
}

if ( !global::QuietMode )
Expand Down Expand Up @@ -411,7 +432,6 @@ int Main(int argc, char* argv[])

}


// Check if there is a track element specified
if ( projectElement->FirstChildElement(xml::elem::TRACK) == nullptr )
{
Expand Down Expand Up @@ -543,7 +563,7 @@ int Main(int argc, char* argv[])
printf( " " );
}

printf( "ERROR: %s attribute must be specified "
printf( "ERROR: %s attribute or -c parameter must be specified "
"when using audio tracks.\n", xml::attrib::CUE_SHEET );

return EXIT_FAILURE;
Expand Down Expand Up @@ -754,6 +774,7 @@ int Main(int argc, char* argv[])
if ( !global::QuietMode )
{
printf( " Packing audio %s... ", track.source.c_str() );
fflush(stdout);
}

if ( PackFileAsCDDA( sectorView->GetRawBuffer(), track.size, std::filesystem::u8path(track.source) ) )
Expand Down Expand Up @@ -790,6 +811,7 @@ int Main(int argc, char* argv[])
if ( !global::QuietMode )
{
printf( " Writing license data..." );
fflush(stdout);
}

iso::WriteLicenseData( &writer, license->data );
Expand Down Expand Up @@ -845,7 +867,7 @@ int Main(int argc, char* argv[])

// Check for next <iso_project> element
projectElement = projectElement->NextSiblingElement(xml::elem::ISO_PROJECT);

}

return 0;
Expand Down Expand Up @@ -889,16 +911,84 @@ int ParseISOfileSystem(const tinyxml2::XMLElement* trackElement, const std::file

if ( identifierElement != nullptr )
{
isoIdentifiers.SystemID = identifierElement->Attribute(xml::attrib::SYSTEM_ID);
isoIdentifiers.VolumeID = identifierElement->Attribute(xml::attrib::VOLUME_ID);
isoIdentifiers.VolumeSet = identifierElement->Attribute(xml::attrib::VOLUME_SET);
isoIdentifiers.Publisher = identifierElement->Attribute(xml::attrib::PUBLISHER);
isoIdentifiers.Application = identifierElement->Attribute(xml::attrib::APPLICATION);
isoIdentifiers.DataPreparer = identifierElement->Attribute(xml::attrib::DATA_PREPARER);
isoIdentifiers.Copyright = identifierElement->Attribute(xml::attrib::COPYRIGHT);
isoIdentifiers.CreationDate = identifierElement->Attribute(xml::attrib::CREATION_DATE);
const char* identifierFile;

// Otherwise use individual elements defined by each attribute
isoIdentifiers.SystemID = identifierElement->Attribute(xml::attrib::SYSTEM_ID);
isoIdentifiers.VolumeID = identifierElement->Attribute(xml::attrib::VOLUME_ID);
isoIdentifiers.VolumeSet = identifierElement->Attribute(xml::attrib::VOLUME_SET);
isoIdentifiers.Publisher = identifierElement->Attribute(xml::attrib::PUBLISHER);
isoIdentifiers.Application = identifierElement->Attribute(xml::attrib::APPLICATION);
isoIdentifiers.DataPreparer = identifierElement->Attribute(xml::attrib::DATA_PREPARER);
isoIdentifiers.Copyright = identifierElement->Attribute(xml::attrib::COPYRIGHT);
isoIdentifiers.CreationDate = identifierElement->Attribute(xml::attrib::CREATION_DATE);
isoIdentifiers.ModificationDate = identifierElement->Attribute(xml::attrib::MODIFICATION_DATE);

// Is an ID file specified?
if( identifierFile = identifierElement->Attribute(xml::attrib::ID_FILE) )
{
// Load the file as an XML document
{
tinyxml2::XMLError error;
if (FILE* file = OpenFile(identifierFile, "rb"); file != nullptr)
{
error = global::xmlIdFile.LoadFile(file);
fclose(file);
}
else
{
error = tinyxml2::XML_ERROR_FILE_NOT_FOUND;
}

if ( error != tinyxml2::XML_SUCCESS )
{
printf("ERROR: ");
if ( error == tinyxml2::XML_ERROR_FILE_NOT_FOUND )
{
printf("File not found.\n");
}
else if ( error == tinyxml2::XML_ERROR_FILE_COULD_NOT_BE_OPENED )
{
printf("File cannot be opened.\n");
}
else if ( error == tinyxml2::XML_ERROR_FILE_READ_ERROR )
{
printf("Error reading file.\n");
}
else
{
printf("%s on line %d\n", global::xmlIdFile.ErrorName(), global::xmlIdFile.ErrorLineNum());
}
return false;
}
}

// Get the identifier element, if there is one
if( identifierElement = global::xmlIdFile.FirstChildElement(xml::elem::IDENTIFIERS) )
{
const char *str;
// Use strings defined in file, otherwise leave ones already defined alone
if( str = identifierElement->Attribute(xml::attrib::SYSTEM_ID) )
isoIdentifiers.SystemID = str;
if( str = identifierElement->Attribute(xml::attrib::VOLUME_ID) )
isoIdentifiers.VolumeID = str;
if( str = identifierElement->Attribute(xml::attrib::VOLUME_SET) )
isoIdentifiers.VolumeSet = str;
if( str = identifierElement->Attribute(xml::attrib::PUBLISHER) )
isoIdentifiers.Publisher = str;
if( str = identifierElement->Attribute(xml::attrib::APPLICATION) )
isoIdentifiers.Application = str;
if( str = identifierElement->Attribute(xml::attrib::DATA_PREPARER) )
isoIdentifiers.DataPreparer = str;
if( str = identifierElement->Attribute(xml::attrib::COPYRIGHT) )
isoIdentifiers.Copyright = str;
if( str = identifierElement->Attribute(xml::attrib::CREATION_DATE) )
isoIdentifiers.CreationDate = str;
if( str = identifierElement->Attribute(xml::attrib::MODIFICATION_DATE) )
isoIdentifiers.ModificationDate = str;
}
}

bool hasSystemID = true;
if ( isoIdentifiers.SystemID == nullptr )
{
Expand All @@ -912,6 +1002,11 @@ int ParseISOfileSystem(const tinyxml2::XMLElement* trackElement, const std::file
hasApplication = false;
isoIdentifiers.Application = "PLAYSTATION";
}

if( global::volid_override )
{
isoIdentifiers.VolumeID = global::volid_override->c_str();
}

// Print out identifiers if present
if ( !global::QuietMode )
Expand Down Expand Up @@ -977,7 +1072,7 @@ int ParseISOfileSystem(const tinyxml2::XMLElement* trackElement, const std::file
printf( " " );
}

printf("ERROR: file attribute of <license> element is missing "
printf("ERROR: File attribute of <license> element is missing "
"or blank on line %d\n.", licenseElement->GetLineNum() );

return false;
Expand Down
2 changes: 2 additions & 0 deletions src/shared/cd.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#include <stdio.h>

#ifdef _WIN32
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
#else
#include <unistd.h>
Expand Down
2 changes: 2 additions & 0 deletions src/shared/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#include "cd.h"

#ifdef _WIN32
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
#include <io.h>
#endif
Expand Down
1 change: 1 addition & 0 deletions src/shared/xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace attrib
constexpr const char* XA_GID = "xa_gid";
constexpr const char* XA_UID = "xa_uid";

constexpr const char* ID_FILE = "id_file";
constexpr const char* SYSTEM_ID = "system";
constexpr const char* VOLUME_ID = "volume";
constexpr const char* APPLICATION = "application";
Expand Down

0 comments on commit 7bcb4ad

Please sign in to comment.