Various windows fixes (microsoft plz)

This commit is contained in:
Phillip 2016-01-23 21:06:54 -08:00
parent 5d5dfdc3da
commit 9114be2a4d
7 changed files with 69 additions and 30 deletions

View File

@ -77,22 +77,24 @@ int main(int argc, char* argv[])
else if (!strcasecmp(argv[1], _S("makegcn"))) else if (!strcasecmp(argv[1], _S("makegcn")))
{ {
#if NOD_UCS2 #if NOD_UCS2
if (_wcslen(argv[2]) < 6) if (wcslen(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"));
#else #else
if (strlen(argv[2]) < 6) 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 #endif
/* Pre-validate paths */ /* Pre-validate paths */
NOD::Sstat theStat; NOD::Sstat theStat;
if (NOD::Stat(argv[4], &theStat) || !S_ISDIR(theStat.st_mode)) 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)) 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)) 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, "unable to stat %s as file", argv[6]);
NOD::SystemUTF8View gameId(argv[2]);
NOD::SystemUTF8View gameTitle(argv[3]);
size_t lastIdx = -1; size_t lastIdx = -1;
auto progFunc = [&](size_t idx, const NOD::SystemString& name, size_t bytes) 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]); NOD::SystemString outPath(argv[4]);
outPath.append(_S(".iso")); 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]); b.buildFromDirectory(argv[4], argv[5], argv[6]);
} }
else 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]); 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"))) else if (!strcasecmp(argv[1], _S("makewiisl")) || !strcasecmp(argv[1], _S("makewiidl")))
{ {
#if NOD_UCS2 #if NOD_UCS2
if (_wcslen(argv[2]) < 6) if (wcslen(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"));
#else #else
if (strlen(argv[2]) < 6) 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 #endif
/* Pre-validate paths */ /* Pre-validate paths */
NOD::Sstat theStat; NOD::Sstat theStat;
if (NOD::Stat(argv[4], &theStat) || !S_ISDIR(theStat.st_mode)) 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)) 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)) 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)) 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; size_t lastIdx = -1;
auto progFunc = [&](size_t idx, const NOD::SystemString& name, size_t bytes) 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]); NOD::SystemString outPath(argv[4]);
outPath.append(_S(".iso")); 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]); b.buildFromDirectory(argv[4], argv[5], argv[6], argv[7]);
} }
else 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]); b.buildFromDirectory(argv[4], argv[5], argv[6], argv[7]);
} }

View File

@ -7,6 +7,7 @@
#include <unordered_map> #include <unordered_map>
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <functional>
#include "Util.hpp" #include "Util.hpp"
#include "IDiscIO.hpp" #include "IDiscIO.hpp"
#include "IFileIO.hpp" #include "IFileIO.hpp"

View File

@ -20,11 +20,37 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <string> #include <string>
#include <cstring>
#include <algorithm> #include <algorithm>
#include <LogVisor/LogVisor.hpp> #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 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 */ /* Log Module */
extern LogVisor::LogModule LogModule; extern LogVisor::LogModule LogModule;
@ -49,7 +75,7 @@ static inline void ToLower(SystemString& str)
{std::transform(str.begin(), str.end(), str.begin(), towlower);} {std::transform(str.begin(), str.end(), str.begin(), towlower);}
static inline void ToUpper(SystemString& str) static inline void ToUpper(SystemString& str)
{std::transform(str.begin(), str.end(), str.begin(), towupper);} {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 class SystemUTF8View
{ {
std::string m_utf8; std::string m_utf8;
@ -108,7 +134,7 @@ public:
static inline void Unlink(const SystemChar* file) static inline void Unlink(const SystemChar* file)
{ {
#if _WIN32 #if NOD_UCS2
_wunlink(file); _wunlink(file);
#else #else
unlink(file); unlink(file);
@ -117,8 +143,8 @@ static inline void Unlink(const SystemChar* file)
static inline int StrCmp(const SystemChar* str1, const SystemChar* str2) static inline int StrCmp(const SystemChar* str1, const SystemChar* str2)
{ {
#if HECL_UCS2 #if NOD_UCS2
return _wcscmp(str1, str2); return wcscmp(str1, str2);
#else #else
return strcmp(str1, str2); return strcmp(str1, str2);
#endif #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) static inline int StrCaseCmp(const SystemChar* str1, const SystemChar* str2)
{ {
#if HECL_UCS2 #if NOD_UCS2
return _wcsicmp(str1, str2); return _wcsicmp(str1, str2);
#else #else
return strcasecmp(str1, str2); return strcasecmp(str1, str2);

View File

@ -1,4 +1,4 @@
#ifdef WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
#else #else
#include <sys/stat.h> #include <sys/stat.h>

View File

@ -5,6 +5,7 @@
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#ifndef _WIN32 #ifndef _WIN32
#include <unistd.h> #include <unistd.h>
#endif #endif
@ -138,9 +139,14 @@ static uint64_t GetInode(const SystemChar* path)
{ {
uint64_t inode; uint64_t inode;
#if _WIN32 #if _WIN32
OFSTRUCT ofs; HANDLE fp = CreateFileW(path,
HFILE fp = OpenFile(path, &ofs, OF_READ); GENERIC_READ | GENERIC_WRITE,
if (fp == HFILE_ERROR) 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); LogModule.report(LogVisor::FatalError, _S("unable to open %s"), path);
BY_HANDLE_FILE_INFORMATION info; BY_HANDLE_FILE_INFORMATION info;
if (!GetFileInformationByHandle(fp, &info)) if (!GetFileInformationByHandle(fp, &info))
@ -212,7 +218,7 @@ void DiscBuilderBase::PartitionBuilderBase::recursiveBuildNodes(bool system, con
++m_parent.m_progressIdx; ++m_parent.m_progressIdx;
while (xferSz < e.m_fileSz) 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) if (!rdSz)
break; break;
ws->write(buf, rdSz); ws->write(buf, rdSz);
@ -263,12 +269,12 @@ bool DiscBuilderBase::PartitionBuilderBase::buildFromDirectory(const SystemChar*
const SystemChar* apploaderIn) const SystemChar* apploaderIn)
{ {
if (!dirIn || !dolIn || !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 */ /* Clear file */
m_parent.getFileIO().beginWriteStream(); m_parent.getFileIO().beginWriteStream();
++m_parent.m_progressIdx; ++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 */ /* Add root node */
m_buildNodes.emplace_back(true, m_buildNameOff, 0, 1); m_buildNodes.emplace_back(true, m_buildNameOff, 0, 1);

View File

@ -361,7 +361,7 @@ public:
std::unique_ptr<IDiscIO::IReadStream> rs = m_parent.getDiscIO().beginReadStream(m_offset); std::unique_ptr<IDiscIO::IReadStream> rs = m_parent.getDiscIO().beginReadStream(m_offset);
while (rem) while (rem)
{ {
size_t rdSz = std::min(rem, 8192ul); size_t rdSz = NOD::min(rem, size_t(8192ul));
rs->read(buf, rdSz); rs->read(buf, rdSz);
fwrite(buf, 1, rdSz, fp); fwrite(buf, 1, rdSz, fp);
rem -= rdSz; rem -= rdSz;
@ -792,7 +792,7 @@ bool DiscBuilderWii::buildFromDirectory(const SystemChar* dirIn, const SystemCha
} }
++m_progressIdx; ++m_progressIdx;
m_progressCB(m_progressIdx, "Finishing Disc", -1); m_progressCB(m_progressIdx, _S("Finishing Disc"), -1);
/* Populate disc header */ /* Populate disc header */
std::unique_ptr<IFileIO::IWriteStream> ws = imgOut->beginWriteStream(0); std::unique_ptr<IFileIO::IWriteStream> ws = imgOut->beginWriteStream(0);

View File

@ -16,7 +16,9 @@
# define SHA_BIG_ENDIAN # define SHA_BIG_ENDIAN
# endif # endif
#else // ! defined __LITTLE_ENDIAN__ #else // ! defined __LITTLE_ENDIAN__
#ifndef _WIN32
# include <endian.h> // machine/endian.h # include <endian.h> // machine/endian.h
#endif
# if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ # if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# define SHA_BIG_ENDIAN # define SHA_BIG_ENDIAN
# endif # endif