[Change] Small amount of directory refactoring.
This commit is contained in:
parent
a329000a5b
commit
c26d5f2cf1
10
Bin/LibD.pro
10
Bin/LibD.pro
@ -37,7 +37,7 @@ HEADERS += ../src/Actor/Player.h \
|
|||||||
../src/Sprite/Sprite.h \
|
../src/Sprite/Sprite.h \
|
||||||
../src/System/Debug.h \
|
../src/System/Debug.h \
|
||||||
../src/System/ResourceManager.h \
|
../src/System/ResourceManager.h \
|
||||||
../src/System/ConvertType.h \
|
../src/System/Convert/ConvertType.h \
|
||||||
../src/System/Filesystem/InputStream.h \
|
../src/System/Filesystem/InputStream.h \
|
||||||
../src/System/Filesystem/OutputStream.h \
|
../src/System/Filesystem/OutputStream.h \
|
||||||
../src/System/Filesystem/EmptyBuffer.h \
|
../src/System/Filesystem/EmptyBuffer.h \
|
||||||
@ -48,8 +48,8 @@ HEADERS += ../src/Actor/Player.h \
|
|||||||
../src/System/Filesystem/FilePackageManager.h \
|
../src/System/Filesystem/FilePackageManager.h \
|
||||||
../src/System/Filesystem/InputStreamWrapper.h \
|
../src/System/Filesystem/InputStreamWrapper.h \
|
||||||
../src/System/Filesystem/MemoryStream.h \
|
../src/System/Filesystem/MemoryStream.h \
|
||||||
../src/System/SCCopyFile.cpp \
|
../src/System/Filesystem/SCCopyFile.cpp \
|
||||||
../src/System/Checksum.h \
|
../src/System/Filesystem/Checksum.h \
|
||||||
../src/Texture/Texture.h \
|
../src/Texture/Texture.h \
|
||||||
../src/Sound/Music.h \
|
../src/Sound/Music.h \
|
||||||
../src/TMXParser/base64.h \
|
../src/TMXParser/base64.h \
|
||||||
@ -107,8 +107,8 @@ SOURCES += ../src/Actor/Player.cpp \
|
|||||||
../src/System/Filesystem/FilePackageManager.cpp \
|
../src/System/Filesystem/FilePackageManager.cpp \
|
||||||
../src/System/Filesystem/InputStreamWrapper.cpp \
|
../src/System/Filesystem/InputStreamWrapper.cpp \
|
||||||
../src/System/Filesystem/MemoryStream.cpp \
|
../src/System/Filesystem/MemoryStream.cpp \
|
||||||
../src/System/SCCopyFile.cpp \
|
../src/System/Filesystem/SCCopyFile.cpp \
|
||||||
../src/System/Checksum.cpp \
|
../src/System/Filesystem/Checksum.cpp \
|
||||||
../src/Texture/Texture.cpp \
|
../src/Texture/Texture.cpp \
|
||||||
../src/Sound/Music.cpp \
|
../src/Sound/Music.cpp \
|
||||||
../src/Actor/NPC.cpp \
|
../src/Actor/NPC.cpp \
|
||||||
|
@ -1,68 +0,0 @@
|
|||||||
#include "Checksum.h"
|
|
||||||
#include "Filesystem/InputStreamWrapper.h"
|
|
||||||
#include <assert.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
using namespace saracraft;
|
|
||||||
|
|
||||||
unsigned int Checksum::CountChecksumForFile(const char* filename) {
|
|
||||||
unsigned int chksum = 0;
|
|
||||||
int filesize = 0;
|
|
||||||
bool success = CountChecksumForFileImpl(&chksum, &filesize, filename);
|
|
||||||
if(success) {
|
|
||||||
return chksum;
|
|
||||||
} else {
|
|
||||||
assert(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Checksum::DoesChecksumAndSizeMatchFile(unsigned int checksum, int filesize, const char* filename) {
|
|
||||||
unsigned int chksum = 0;
|
|
||||||
int size = 0;
|
|
||||||
bool success = CountChecksumForFileImpl(&chksum, &size, filename);
|
|
||||||
if(success) {
|
|
||||||
if(chksum == checksum && filesize == size)
|
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Checksum::CountChecksumForFileImpl(unsigned int* checksum, int* filesize, const char* filename) {
|
|
||||||
assert(filename != NULL);
|
|
||||||
|
|
||||||
filesystem::FB_FILE* f = filesystem::fb_fopen(filename, "rb");
|
|
||||||
if(f == NULL) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int size = filesystem::fb_fsize(f);
|
|
||||||
|
|
||||||
char* buf = new char[size];
|
|
||||||
|
|
||||||
bool success = true;
|
|
||||||
int got = filesystem::fb_fread(buf, size, 1, f);
|
|
||||||
if(got != 1) {
|
|
||||||
success = false;
|
|
||||||
} else {
|
|
||||||
success = true;
|
|
||||||
*filesize = size;
|
|
||||||
unsigned int hashCode = 1327341033;
|
|
||||||
int hashmult = 0;
|
|
||||||
for(int i = 0; i < size; i++) {
|
|
||||||
if((i % 73) == 0)
|
|
||||||
hashCode += (buf[i] << hashmult);
|
|
||||||
else
|
|
||||||
hashCode ^= (buf[i] << hashmult);
|
|
||||||
hashmult+=4;
|
|
||||||
if(hashmult > 23) hashmult -= 23;
|
|
||||||
}
|
|
||||||
delete [] buf;
|
|
||||||
filesystem::fb_fclose(f);
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
class Checksum {
|
|
||||||
public:
|
|
||||||
static unsigned int CountChecksumForFile(const char* filename);
|
|
||||||
static bool DoesChecksumAndSizeMatchFile(unsigned int checksum,
|
|
||||||
int filesize, const char* filename);
|
|
||||||
private:
|
|
||||||
static bool CountChecksumForFileImpl(unsigned int* checksum,
|
|
||||||
int* filesize, const char* filename);
|
|
||||||
};
|
|
||||||
|
|
@ -1,55 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef INCLUDED_CASSERT
|
|
||||||
#define INCLUSED_CASSERT
|
|
||||||
#include <cassert>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace saracraft {
|
|
||||||
namespace filesystem {
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
struct ConvertBase {
|
|
||||||
enum { charCount = sizeof(T) };
|
|
||||||
union Values {
|
|
||||||
unsigned char c[charCount];
|
|
||||||
T t;
|
|
||||||
};
|
|
||||||
|
|
||||||
Values value;
|
|
||||||
|
|
||||||
int GetSize(void) const { return charCount; }
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
struct ConvertFrom: private ConvertBase<T> {
|
|
||||||
explicit ConvertFrom(const T& t) {
|
|
||||||
this->value.t = t;
|
|
||||||
}
|
|
||||||
using ConvertBase<T>::GetSize;
|
|
||||||
|
|
||||||
unsigned char GetByte(int index) const {
|
|
||||||
assert((index >= 0) && (index < GetSize()));
|
|
||||||
return this->value.c[index];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
struct ConvertTo: private ConvertBase<T> {
|
|
||||||
using ConvertBase<T>::GetSize;
|
|
||||||
|
|
||||||
void SetByte(int index, unsigned char c) {
|
|
||||||
assert((index >= 0) && (index < GetSize()));
|
|
||||||
this->value.c[index] = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
const T& GetValue(void) const {
|
|
||||||
return this->value.t;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef unsigned short uint16_t;
|
|
||||||
|
|
||||||
} // Namespaces....
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
#include <boost/static_assert.hpp>
|
#include <boost/static_assert.hpp>
|
||||||
|
|
||||||
#include "../ConvertType.h"
|
#include "../Convert/ConvertType.h"
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include "InputStream.h"
|
#include "InputStream.h"
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include <boost/static_assert.hpp>
|
#include <boost/static_assert.hpp>
|
||||||
|
|
||||||
#include "../ConvertType.h"
|
#include "../Convert/ConvertType.h"
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include "OutputStream.h"
|
#include "OutputStream.h"
|
||||||
|
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
#include <fstream>
|
|
||||||
#include <string>
|
|
||||||
#include "Filesystem/InputStream.h"
|
|
||||||
#include "Filesystem/FilePackageManager.h"
|
|
||||||
|
|
||||||
#include "SCCopyFile.h"
|
|
||||||
|
|
||||||
namespace util {
|
|
||||||
|
|
||||||
void SCCopyFile::CopyFile(const std::string& from, const std::string& to) {
|
|
||||||
std::fstream out(to.c_str(), std::ios::out);
|
|
||||||
saracraft::filesystem::InputStream in = saracraft::filesystem::FilePackageManager::GetInstance().GetFile(from);
|
|
||||||
|
|
||||||
std::string temp;
|
|
||||||
temp.resize(in.GetSize());
|
|
||||||
in.Read((unsigned char*)&temp[0], in.GetSize());
|
|
||||||
out << temp << std::endl;
|
|
||||||
|
|
||||||
out.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // Namespace util.
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
namespace util {
|
|
||||||
|
|
||||||
class SCCopyFile {
|
|
||||||
public:
|
|
||||||
|
|
||||||
// TODO: This will currently only handle smallish text files
|
|
||||||
// propperly.
|
|
||||||
|
|
||||||
/*** DON'T USE FOR BINARY FILES!!!! ***/
|
|
||||||
static void CopyFile(const std::string& from, const std::string& to);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // Namespace util.
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user