Extracting many .chd files to .cue/bin
Want to extract lots of *.chd files on windows just by drag and drop? :)
#include <iostream>
#include <filesystem>
#include <sstream>
#include "windows.h"
int main(int argc, char** argv) {
if (argc < 2) {
std::cout << "Usage: convertchd.exe [filename.chd]" << std::endl;
return 0;
}
char exePathStr[256];
memset(exePathStr, 0, 256);
GetModuleFileNameA(NULL, (LPSTR)exePathStr, 256);
const std::filesystem::path exePath{ exePathStr };
const std::filesystem::path exeParentDirPath{ exePath.parent_path() };
const std::filesystem::path chdManPath{
exeParentDirPath / std::filesystem::path("chdman.exe")
};
const std::size_t numFiles{ static_cast<std::size_t>(argc) - 1 };
for (std::size_t i = 0; i < numFiles; ++i) {
const std::string chdFilename{ argv[1 + i] };
const std::string::size_type extensionPos{ chdFilename.rfind(".chd") };
if (extensionPos == std::string::npos) {
std::cout << "Invalid input file is not a .chd image: " << chdFilename << std::endl;
return 0;
}
const std::string cueFilename{ chdFilename.substr(0, extensionPos) + ".cue" };
std::cout << "Generating .cue file " << cueFilename << std::endl;
const std::string cmdLine{ chdManPath.string() + " extractcd "
"-i \"" + chdFilename +
"\" -o \"" + cueFilename + "\"" };
std::cout << "Running " << cmdLine << std::endl;
system(cmdLine.c_str());
}
std::cout << "Press 'Return' to quit." << std::endl;
::getchar();
return 0;
}
Very simple/raw Windows console application, but it does get the job done.
Save as convertchd.cpp
and compile with:
cl /EHsc convertchd.cpp /std:c++17