mirror of https://github.com/AxioDL/nod.git
Various windows fixes (microsoft plz)
This commit is contained in:
parent
5d5dfdc3da
commit
9114be2a4d
|
@ -77,22 +77,24 @@ int main(int argc, char* argv[])
|
|||
else if (!strcasecmp(argv[1], _S("makegcn")))
|
||||
{
|
||||
#if NOD_UCS2
|
||||
if (_wcslen(argv[2]) < 6)
|
||||
NOD::LogModule.report(LogVisor::FatalError, "game-id is not at least 6 characters");
|
||||
if (wcslen(argv[2]) < 6)
|
||||
NOD::LogModule.report(LogVisor::FatalError, _S("game-id is not at least 6 characters"));
|
||||
#else
|
||||
if (strlen(argv[2]) < 6)
|
||||
NOD::LogModule.report(LogVisor::FatalError, "game-id is not at least 6 characters");
|
||||
NOD::LogModule.report(LogVisor::FatalError, _S("game-id is not at least 6 characters"));
|
||||
#endif
|
||||
|
||||
/* Pre-validate paths */
|
||||
NOD::Sstat theStat;
|
||||
if (NOD::Stat(argv[4], &theStat) || !S_ISDIR(theStat.st_mode))
|
||||
NOD::LogModule.report(LogVisor::FatalError, "unable to stat %s as directory", argv[4]);
|
||||
NOD::LogModule.report(LogVisor::FatalError, _S("unable to stat %s as directory"), argv[4]);
|
||||
if (NOD::Stat(argv[5], &theStat) || !S_ISREG(theStat.st_mode))
|
||||
NOD::LogModule.report(LogVisor::FatalError, "unable to stat %s as file", argv[5]);
|
||||
NOD::LogModule.report(LogVisor::FatalError, _S("unable to stat %s as file"), argv[5]);
|
||||
if (NOD::Stat(argv[6], &theStat) || !S_ISREG(theStat.st_mode))
|
||||
NOD::LogModule.report(LogVisor::FatalError, "unable to stat %s as file", argv[6]);
|
||||
|
||||
NOD::SystemUTF8View gameId(argv[2]);
|
||||
NOD::SystemUTF8View gameTitle(argv[3]);
|
||||
size_t lastIdx = -1;
|
||||
auto progFunc = [&](size_t idx, const NOD::SystemString& name, size_t bytes)
|
||||
{
|
||||
|
@ -112,12 +114,12 @@ int main(int argc, char* argv[])
|
|||
{
|
||||
NOD::SystemString outPath(argv[4]);
|
||||
outPath.append(_S(".iso"));
|
||||
NOD::DiscBuilderGCN b(outPath.c_str(), argv[2], argv[3], 0x0003EB60, progFunc);
|
||||
NOD::DiscBuilderGCN b(outPath.c_str(), gameId.utf8_str().c_str(), gameTitle.utf8_str().c_str(), 0x0003EB60, progFunc);
|
||||
b.buildFromDirectory(argv[4], argv[5], argv[6]);
|
||||
}
|
||||
else
|
||||
{
|
||||
NOD::DiscBuilderGCN b(argv[7], argv[2], argv[3], 0x0003EB60, progFunc);
|
||||
NOD::DiscBuilderGCN b(argv[7], gameId.utf8_str().c_str(), gameTitle.utf8_str().c_str(), 0x0003EB60, progFunc);
|
||||
b.buildFromDirectory(argv[4], argv[5], argv[6]);
|
||||
}
|
||||
|
||||
|
@ -126,24 +128,26 @@ int main(int argc, char* argv[])
|
|||
else if (!strcasecmp(argv[1], _S("makewiisl")) || !strcasecmp(argv[1], _S("makewiidl")))
|
||||
{
|
||||
#if NOD_UCS2
|
||||
if (_wcslen(argv[2]) < 6)
|
||||
NOD::LogModule.report(LogVisor::FatalError, "game-id is not at least 6 characters");
|
||||
if (wcslen(argv[2]) < 6)
|
||||
NOD::LogModule.report(LogVisor::FatalError, _S("game-id is not at least 6 characters"));
|
||||
#else
|
||||
if (strlen(argv[2]) < 6)
|
||||
NOD::LogModule.report(LogVisor::FatalError, "game-id is not at least 6 characters");
|
||||
NOD::LogModule.report(LogVisor::FatalError, _S("game-id is not at least 6 characters"));
|
||||
#endif
|
||||
|
||||
/* Pre-validate paths */
|
||||
NOD::Sstat theStat;
|
||||
if (NOD::Stat(argv[4], &theStat) || !S_ISDIR(theStat.st_mode))
|
||||
NOD::LogModule.report(LogVisor::FatalError, "unable to stat %s as directory", argv[4]);
|
||||
NOD::LogModule.report(LogVisor::FatalError, _S("unable to stat %s as directory"), argv[4]);
|
||||
if (NOD::Stat(argv[5], &theStat) || !S_ISREG(theStat.st_mode))
|
||||
NOD::LogModule.report(LogVisor::FatalError, "unable to stat %s as file", argv[5]);
|
||||
NOD::LogModule.report(LogVisor::FatalError, _S("unable to stat %s as file"), argv[5]);
|
||||
if (NOD::Stat(argv[6], &theStat) || !S_ISREG(theStat.st_mode))
|
||||
NOD::LogModule.report(LogVisor::FatalError, "unable to stat %s as file", argv[6]);
|
||||
NOD::LogModule.report(LogVisor::FatalError, _S("unable to stat %s as file"), argv[6]);
|
||||
if (NOD::Stat(argv[7], &theStat) || !S_ISREG(theStat.st_mode))
|
||||
NOD::LogModule.report(LogVisor::FatalError, "unable to stat %s as file", argv[7]);
|
||||
NOD::LogModule.report(LogVisor::FatalError, _S("unable to stat %s as file"), argv[7]);
|
||||
|
||||
NOD::SystemUTF8View gameId(argv[2]);
|
||||
NOD::SystemUTF8View gameTitle(argv[3]);
|
||||
size_t lastIdx = -1;
|
||||
auto progFunc = [&](size_t idx, const NOD::SystemString& name, size_t bytes)
|
||||
{
|
||||
|
@ -165,12 +169,12 @@ int main(int argc, char* argv[])
|
|||
{
|
||||
NOD::SystemString outPath(argv[4]);
|
||||
outPath.append(_S(".iso"));
|
||||
NOD::DiscBuilderWii b(outPath.c_str(), argv[2], argv[3], dual, progFunc);
|
||||
NOD::DiscBuilderWii b(outPath.c_str(), gameId.utf8_str().c_str(), gameTitle.utf8_str().c_str(), dual, progFunc);
|
||||
b.buildFromDirectory(argv[4], argv[5], argv[6], argv[7]);
|
||||
}
|
||||
else
|
||||
{
|
||||
NOD::DiscBuilderWii b(argv[8], argv[2], argv[3], dual, progFunc);
|
||||
NOD::DiscBuilderWii b(argv[8], gameId.utf8_str().c_str(), gameTitle.utf8_str().c_str(), dual, progFunc);
|
||||
b.buildFromDirectory(argv[4], argv[5], argv[6], argv[7]);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <unordered_map>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <functional>
|
||||
#include "Util.hpp"
|
||||
#include "IDiscIO.hpp"
|
||||
#include "IFileIO.hpp"
|
||||
|
|
|
@ -20,11 +20,37 @@
|
|||
#include <sys/stat.h>
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include <LogVisor/LogVisor.hpp>
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable : 4996)
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
|
||||
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
||||
#endif
|
||||
|
||||
#if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR)
|
||||
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
||||
#endif
|
||||
|
||||
#if !defined(S_ISLNK)
|
||||
#define S_ISLNK(m) 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#undef min
|
||||
#undef max
|
||||
|
||||
namespace NOD
|
||||
{
|
||||
/* define our own min/max to avoid MSVC BS */
|
||||
template<typename T>
|
||||
inline T min(T a, T b) { return a < b ? a : b; }
|
||||
template<typename T>
|
||||
inline T max(T a, T b) { return a > b ? a : b; }
|
||||
|
||||
/* Log Module */
|
||||
extern LogVisor::LogModule LogModule;
|
||||
|
@ -49,7 +75,7 @@ static inline void ToLower(SystemString& str)
|
|||
{std::transform(str.begin(), str.end(), str.begin(), towlower);}
|
||||
static inline void ToUpper(SystemString& str)
|
||||
{std::transform(str.begin(), str.end(), str.begin(), towupper);}
|
||||
static inline size_t StrLen(const SystemChar* str) {return _wcslen(str);}
|
||||
static inline size_t StrLen(const SystemChar* str) {return wcslen(str);}
|
||||
class SystemUTF8View
|
||||
{
|
||||
std::string m_utf8;
|
||||
|
@ -108,7 +134,7 @@ public:
|
|||
|
||||
static inline void Unlink(const SystemChar* file)
|
||||
{
|
||||
#if _WIN32
|
||||
#if NOD_UCS2
|
||||
_wunlink(file);
|
||||
#else
|
||||
unlink(file);
|
||||
|
@ -117,8 +143,8 @@ static inline void Unlink(const SystemChar* file)
|
|||
|
||||
static inline int StrCmp(const SystemChar* str1, const SystemChar* str2)
|
||||
{
|
||||
#if HECL_UCS2
|
||||
return _wcscmp(str1, str2);
|
||||
#if NOD_UCS2
|
||||
return wcscmp(str1, str2);
|
||||
#else
|
||||
return strcmp(str1, str2);
|
||||
#endif
|
||||
|
@ -126,7 +152,7 @@ static inline int StrCmp(const SystemChar* str1, const SystemChar* str2)
|
|||
|
||||
static inline int StrCaseCmp(const SystemChar* str1, const SystemChar* str2)
|
||||
{
|
||||
#if HECL_UCS2
|
||||
#if NOD_UCS2
|
||||
return _wcsicmp(str1, str2);
|
||||
#else
|
||||
return strcasecmp(str1, str2);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/stat.h>
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
@ -138,9 +139,14 @@ static uint64_t GetInode(const SystemChar* path)
|
|||
{
|
||||
uint64_t inode;
|
||||
#if _WIN32
|
||||
OFSTRUCT ofs;
|
||||
HFILE fp = OpenFile(path, &ofs, OF_READ);
|
||||
if (fp == HFILE_ERROR)
|
||||
HANDLE fp = CreateFileW(path,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
nullptr,
|
||||
OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
nullptr);
|
||||
if (!fp)
|
||||
LogModule.report(LogVisor::FatalError, _S("unable to open %s"), path);
|
||||
BY_HANDLE_FILE_INFORMATION info;
|
||||
if (!GetFileInformationByHandle(fp, &info))
|
||||
|
@ -212,7 +218,7 @@ void DiscBuilderBase::PartitionBuilderBase::recursiveBuildNodes(bool system, con
|
|||
++m_parent.m_progressIdx;
|
||||
while (xferSz < e.m_fileSz)
|
||||
{
|
||||
size_t rdSz = fread(buf, 1, std::min(0x8000ul, e.m_fileSz - xferSz), fp);
|
||||
size_t rdSz = fread(buf, 1, NOD::min(size_t(0x8000ul), e.m_fileSz - xferSz), fp);
|
||||
if (!rdSz)
|
||||
break;
|
||||
ws->write(buf, rdSz);
|
||||
|
@ -263,12 +269,12 @@ bool DiscBuilderBase::PartitionBuilderBase::buildFromDirectory(const SystemChar*
|
|||
const SystemChar* apploaderIn)
|
||||
{
|
||||
if (!dirIn || !dolIn || !apploaderIn)
|
||||
LogModule.report(LogVisor::FatalError, "all arguments must be supplied to buildFromDirectory()");
|
||||
LogModule.report(LogVisor::FatalError, _S("all arguments must be supplied to buildFromDirectory()"));
|
||||
|
||||
/* Clear file */
|
||||
m_parent.getFileIO().beginWriteStream();
|
||||
++m_parent.m_progressIdx;
|
||||
m_parent.m_progressCB(m_parent.m_progressIdx, "Preparing output image", -1);
|
||||
m_parent.m_progressCB(m_parent.m_progressIdx, _S("Preparing output image"), -1);
|
||||
|
||||
/* Add root node */
|
||||
m_buildNodes.emplace_back(true, m_buildNameOff, 0, 1);
|
||||
|
|
|
@ -361,7 +361,7 @@ public:
|
|||
std::unique_ptr<IDiscIO::IReadStream> rs = m_parent.getDiscIO().beginReadStream(m_offset);
|
||||
while (rem)
|
||||
{
|
||||
size_t rdSz = std::min(rem, 8192ul);
|
||||
size_t rdSz = NOD::min(rem, size_t(8192ul));
|
||||
rs->read(buf, rdSz);
|
||||
fwrite(buf, 1, rdSz, fp);
|
||||
rem -= rdSz;
|
||||
|
@ -792,7 +792,7 @@ bool DiscBuilderWii::buildFromDirectory(const SystemChar* dirIn, const SystemCha
|
|||
}
|
||||
|
||||
++m_progressIdx;
|
||||
m_progressCB(m_progressIdx, "Finishing Disc", -1);
|
||||
m_progressCB(m_progressIdx, _S("Finishing Disc"), -1);
|
||||
|
||||
/* Populate disc header */
|
||||
std::unique_ptr<IFileIO::IWriteStream> ws = imgOut->beginWriteStream(0);
|
||||
|
|
|
@ -16,7 +16,9 @@
|
|||
# define SHA_BIG_ENDIAN
|
||||
# endif
|
||||
#else // ! defined __LITTLE_ENDIAN__
|
||||
#ifndef _WIN32
|
||||
# include <endian.h> // machine/endian.h
|
||||
#endif
|
||||
# if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
# define SHA_BIG_ENDIAN
|
||||
# endif
|
||||
|
|
Loading…
Reference in New Issue