Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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})
Expand Down
2 changes: 1 addition & 1 deletion src/FatUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <string>
#include <algorithm>
#include <functional>
#ifdef __WIN__
#ifdef _WIN32
#include <ctype.h>
#else

Expand Down
10 changes: 5 additions & 5 deletions src/analysis/FatExtract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
#include <string.h>
#include <string>
#include <sys/stat.h>
#ifndef __WIN__
#ifndef _WIN32
#include <sys/time.h>
#endif
#include <sys/types.h>
#include "FatExtract.h"
#ifdef __WIN__
#ifdef _WIN32
#include <windows.h>
#endif

Expand All @@ -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);
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/core/FatDate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/core/FatDate.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define _FATCAT_FATDATE_H

#include <string>
#ifndef __WIN__
#ifndef _WIN32
#include <time.h>
#endif

Expand All @@ -18,7 +18,7 @@ class FatDate
int y, m, d;

string pretty();
#ifndef __WIN__
#ifndef _WIN32
time_t timestamp() const;
#endif

Expand Down
22 changes: 11 additions & 11 deletions src/core/FatSystem.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifdef __WIN__
#ifdef _WIN32
#include <io.h>
#else
#include <unistd.h>
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -249,7 +249,7 @@ unsigned int FatSystem::nextCluster(unsigned int cluster, int fat)
}
}
}
#ifdef __WIN__
#ifdef _MSC_VER
}
__finally
{
Expand All @@ -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];
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -865,7 +865,7 @@ void FatSystem::rewriteUnallocated(bool random)
srand(time(NULL));
for (int cluster=0; cluster<totalClusters; cluster++) {
if (freeCluster(cluster)) {
#ifndef __WIN__
#ifndef _MSC_VER
char buffer[bytesPerCluster];
#else
char *buffer = new char[bytesPerCluster];
Expand All @@ -881,7 +881,7 @@ void FatSystem::rewriteUnallocated(bool random)
}
writeData(clusterAddress(cluster), buffer, sizeof(buffer));
total++;
#ifdef __WIN__
#ifdef _MSC_VER
}
__finally
{
Expand Down
9 changes: 5 additions & 4 deletions src/core/FatSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
#include "FatPath.h"
#include "OutputFormatType.h"

#ifdef __APPLE__
#if defined(__APPLE__) || defined(_WIN32)
#define O_LARGEFILE 0
#define lseek64 lseek
#endif
#ifdef __WIN__
#define O_LARGEFILE 0
#define lseek64 lseek

#ifndef O_BINARY
#define O_BINARY 0
#endif

using namespace std;

// Last cluster
Expand Down
18 changes: 11 additions & 7 deletions src/fatcat.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#include <stdlib.h>
#include<string.h>
#include <string.h>
#ifdef __APPLE__
#include <unistd.h>
#else
#ifdef __WIN__
#include <ctype.h>
#include "xgetopt/xgetopt.h"
#else
#include <argp.h>
#endif
#ifdef _WIN32
#include <ctype.h>
#ifndef _MSC_VER
#include <getopt.h>
#else
#include "xgetopt/xgetopt.h"
#endif
#else
#include <argp.h>
#endif
#endif

#include <stdio.h>
Expand Down
4 changes: 2 additions & 2 deletions src/table/FatBackup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions src/xgetopt/argcargv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -125,4 +125,4 @@ int _ConvertCommandLineToArgcArgv(LPCTSTR lpszSysCmdLine)
return argc;
}
}
#endif
#endif
4 changes: 2 additions & 2 deletions src/xgetopt/stdafx.cpp
Original file line number Diff line number Diff line change
@@ -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
#endif
4 changes: 2 additions & 2 deletions src/xgetopt/xgetopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -214,4 +214,4 @@ int getopt(int argc, TCHAR *argv[], TCHAR *optstring)

return c;
}
#endif
#endif