diff --git a/CMakeLists.txt b/CMakeLists.txt index d6a2649..c5e792d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,6 @@ cmake_minimum_required(VERSION 2.8) project(fatcat) -OPTION(DEFINE_WIN "Compiling windows" OFF) - set(SOURCES core/FatEntry.cpp core/FatFilename.cpp @@ -30,10 +28,6 @@ foreach(SOURCE ${SOURCES}) set(ALL_SOURCES ${ALL_SOURCES} src/${SOURCE}) endforeach() -IF(DEFINE_WIN) - add_definitions(-D__WIN__) -ENDIF(DEFINE_WIN) - include_directories("${CMAKE_SOURCE_DIR}/src") add_executable(fatcat "src/fatcat.cpp" ${ALL_SOURCES}) diff --git a/src/FatUtils.h b/src/FatUtils.h index 5080f2a..2b21a8e 100644 --- a/src/FatUtils.h +++ b/src/FatUtils.h @@ -6,7 +6,7 @@ #include #include #include -#ifdef __WIN__ +#ifdef _WIN32 #include #else diff --git a/src/analysis/FatExtract.cpp b/src/analysis/FatExtract.cpp index 892a085..8c8985e 100644 --- a/src/analysis/FatExtract.cpp +++ b/src/analysis/FatExtract.cpp @@ -4,12 +4,12 @@ #include #include #include -#ifndef __WIN__ +#ifndef _WIN32 #include #endif #include #include "FatExtract.h" -#ifdef __WIN__ +#ifdef _WIN32 #include #endif @@ -23,7 +23,7 @@ FatExtract::FatExtract(FatSystem &system) void FatExtract::onDirectory(FatEntry &parent, FatEntry &entry, string name) { string directory = targetDirectory + "/" + name; -#ifdef __WIN__ +#ifdef _WIN32 CreateDirectory(directory.c_str(), NULL); #else mkdir(directory.c_str(), 0755); @@ -42,11 +42,11 @@ void FatExtract::onEntry(FatEntry &parent, FatEntry &entry, string name) string target = targetDirectory + name; cout << "Extracting " << name << " to " << target << endl; - FILE *output = fopen(target.c_str(), "w+"); + FILE *output = fopen(target.c_str(), "wb+"); system.readFile(entry.cluster, entry.size, output, contiguous); fclose(output); -#ifndef __WIN__ +#ifndef _WIN32 time_t mtime = entry.changeDate.timestamp(); if (mtime == (time_t)-1) { // Files on FAT can have dates up to 2107 year inclusive (which is diff --git a/src/core/FatDate.cpp b/src/core/FatDate.cpp index bf7d0e0..e5a1bc1 100644 --- a/src/core/FatDate.cpp +++ b/src/core/FatDate.cpp @@ -35,7 +35,7 @@ string FatDate::pretty() return string(buffer); } -#ifndef __WIN__ +#ifndef _WIN32 /** * Returns date as a number of seconds elapsed since the Epoch, * 1970-01-01 00:00:00 +0000 (UTC). FAT dates are considered to be in the diff --git a/src/core/FatDate.h b/src/core/FatDate.h index ad14df2..25d4678 100644 --- a/src/core/FatDate.h +++ b/src/core/FatDate.h @@ -2,7 +2,7 @@ #define _FATCAT_FATDATE_H #include -#ifndef __WIN__ +#ifndef _WIN32 #include #endif @@ -18,7 +18,7 @@ class FatDate int y, m, d; string pretty(); - #ifndef __WIN__ + #ifndef _WIN32 time_t timestamp() const; #endif diff --git a/src/core/FatSystem.cpp b/src/core/FatSystem.cpp index 37be51c..49c2d4c 100644 --- a/src/core/FatSystem.cpp +++ b/src/core/FatSystem.cpp @@ -1,4 +1,4 @@ -#ifdef __WIN__ +#ifdef _WIN32 #include #else #include @@ -38,7 +38,7 @@ FatSystem::FatSystem(string filename_, unsigned long long globalOffset_, OutputF rootEntries(0) { this->_outputFormat = outputFormat_; - fd = open(filename.c_str(), O_RDONLY|O_LARGEFILE); + fd = open(filename.c_str(), O_RDONLY | O_LARGEFILE | O_BINARY); writeMode = false; if (fd < 0) { @@ -64,7 +64,7 @@ void FatSystem::enableCache() void FatSystem::enableWrite() { close(fd); - fd = open(filename.c_str(), O_RDWR|O_LARGEFILE); + fd = open(filename.c_str(), O_RDWR | O_LARGEFILE | O_BINARY); if (fd < 0) { ostringstream oss; @@ -199,7 +199,7 @@ void FatSystem::parseHeader() unsigned int FatSystem::nextCluster(unsigned int cluster, int fat) { int bytes = (bits == 32 ? 4 : 2); -#ifndef __WIN__ +#ifndef _MSC_VER char buffer[bytes]; #else char *buffer = new char[bytes]; @@ -249,7 +249,7 @@ unsigned int FatSystem::nextCluster(unsigned int cluster, int fat) } } } -#ifdef __WIN__ +#ifdef _MSC_VER } __finally { @@ -264,7 +264,7 @@ __finally bool FatSystem::writeNextCluster(unsigned int cluster, unsigned int next, int fat) { int bytes = (bits == 32 ? 4 : 2); -#ifndef __WIN__ +#ifndef _MSC_VER char buffer[bytes]; #else char *buffer = new char[bytes]; @@ -296,7 +296,7 @@ bool FatSystem::writeNextCluster(unsigned int cluster, unsigned int next, int fa } return writeData(offset, buffer, bytes) == bytes; -#ifdef __WIN__ +#ifdef _MSC_VER } __finally { @@ -594,7 +594,7 @@ void FatSystem::readFile(unsigned int cluster, unsigned int size, FILE *f, bool if (toRead > bytesPerCluster || size < 0) { toRead = bytesPerCluster; } -#ifndef __WIN__ +#ifndef _MSC_VER char buffer[bytesPerCluster]; #else char *buffer = new char[bytesPerCluster]; @@ -636,7 +636,7 @@ void FatSystem::readFile(unsigned int cluster, unsigned int size, FILE *f, bool cluster = currentCluster+1; } } -#ifdef __WIN__ +#ifdef _MSC_VER } __finally { @@ -865,7 +865,7 @@ void FatSystem::rewriteUnallocated(bool random) srand(time(NULL)); for (int cluster=0; cluster -#include +#include #ifdef __APPLE__ #include #else -#ifdef __WIN__ -#include -#include "xgetopt/xgetopt.h" -#else -#include -#endif +#ifdef _WIN32 + #include + #ifndef _MSC_VER + #include + #else + #include "xgetopt/xgetopt.h" + #endif + #else + #include + #endif #endif #include diff --git a/src/table/FatBackup.cpp b/src/table/FatBackup.cpp index a509348..e7ea120 100644 --- a/src/table/FatBackup.cpp +++ b/src/table/FatBackup.cpp @@ -20,7 +20,7 @@ void FatBackup::backup(string backupFile, int fat) int size = system.fatSize; int n = 0; int offset = 0; - FILE *backup = fopen(backupFile.c_str(), "w+"); + FILE *backup = fopen(backupFile.c_str(), "wb+"); if (fat == 0) { size *= 2; @@ -55,7 +55,7 @@ void FatBackup::patch(string backupFile, int fat) char buffer[CHUNKS_SIZES]; // Opening the file - FILE *backup = fopen(backupFile.c_str(), "r"); + FILE *backup = fopen(backupFile.c_str(), "rb"); if (backup == NULL) { ostringstream oss; oss << "Unable to open file " << backupFile << " for reading"; diff --git a/src/xgetopt/argcargv.cpp b/src/xgetopt/argcargv.cpp index d7c9ac8..0efd43e 100644 --- a/src/xgetopt/argcargv.cpp +++ b/src/xgetopt/argcargv.cpp @@ -7,7 +7,7 @@ // The original source for the LIBCTINY library may be // found here: www.wheaty.net -#ifdef __WIN__ +#ifdef _MSC_VER #include "stdafx.h" #include "argcargv.h" @@ -125,4 +125,4 @@ int _ConvertCommandLineToArgcArgv(LPCTSTR lpszSysCmdLine) return argc; } } -#endif \ No newline at end of file +#endif diff --git a/src/xgetopt/stdafx.cpp b/src/xgetopt/stdafx.cpp index 73f52ec..c07586c 100644 --- a/src/xgetopt/stdafx.cpp +++ b/src/xgetopt/stdafx.cpp @@ -1,10 +1,10 @@ // stdafx.cpp : source file that includes just the standard includes // XGetoptTest.pch will be the pre-compiled header // stdafx.obj will contain the pre-compiled type information -#ifdef __WIN__ +#ifdef _MSC_VER #include "stdafx.h" -#endif \ No newline at end of file +#endif diff --git a/src/xgetopt/xgetopt.cpp b/src/xgetopt/xgetopt.cpp index c39416e..411c4f3 100644 --- a/src/xgetopt/xgetopt.cpp +++ b/src/xgetopt/xgetopt.cpp @@ -22,7 +22,7 @@ // damage or loss of business that this software may cause. // /////////////////////////////////////////////////////////////////////////////// -#ifdef __WIN__ +#ifdef _MSC_VER /////////////////////////////////////////////////////////////////////////////// // if you are using precompiled headers then include this line: #include "stdafx.h" @@ -214,4 +214,4 @@ int getopt(int argc, TCHAR *argv[], TCHAR *optstring) return c; } -#endif \ No newline at end of file +#endif