Remove easy_file.cpp/h. Minor cleanups.

This commit is contained in:
Henrik Rydgard committed 2015-09-19 14:29:02 +02:00
1 parent 6cc7a85cde
commit ecbef7a2ff
13 files changed
+63 -247

No files matched your search

-1
View File
@@ -39,7 +39,6 @@ LOCAL_SRC_FILES :=\
ext/vjson/json.cpp \
ext/vjson/block_allocator.cpp \
file/fd_util.cpp \
file/easy_file.cpp \
file/chunk_file.cpp \
file/file_util.cpp \
file/path.cpp \
-1
View File
@@ -2,7 +2,6 @@
#include <stdio.h>
#include <string.h>
#include "json.h"
#include "file/easy_file.h"
#include "file/zip_read.h"
#include "file/vfs.h"
-1
View File
@@ -1,5 +1,4 @@
set(SRCS
easy_file.cpp
chunk_file.cpp
zip_read.cpp
file_util.cpp
+26 -30
View File
@@ -1,6 +1,7 @@
#include "base/logging.h"
#include "file/chunk_file.h"
#include "file/zip_read.h"
#include "file/file_util.h"
//#define CHUNKDEBUG
@@ -27,12 +28,12 @@ ChunkFile::ChunkFile(const char *filename, bool _read) {
return;
}
if (file.open(filename, FILE_WRITE)) {
didFail=false;
eof=file.fileSize();
file = openCFile(filename, "wb");
if (file) {
didFail = false;
eof = 0;
} else {
didFail=true;
return;
didFail = true;
}
}
@@ -48,42 +49,36 @@ ChunkFile::ChunkFile(const uint8_t *read_data, int data_size) {
}
ChunkFile::~ChunkFile() {
if (fastMode)
delete [] data;
else
file.close();
if (fastMode) {
delete[] data;
} else {
fclose(file);
}
}
int ChunkFile::readInt() {
if (data && pos<eof) {
/*
int temp = *(int *)(data+pos);
pos+=4;
*/
pos += 4;
if (fastMode)
return *(int *)(data + pos - 4);
else
return file.readInt();
else {
int i;
fread(&i, 1, 4, file);
return i;
}
} else {
return 0;
}
}
void ChunkFile::writeInt(int i) {
/*
*(int *)(data+pos) = i;
fwrite(&i, 1, 4, file);
pos+=4;
*/
#ifndef DEMO_VERSION //if this is missing.. heheh
file.writeInt(i);
pos+=4;
#endif
}
//let's get into the business
bool ChunkFile::descend(uint32_t id) {
id=flipID(id);
id = flipID(id);
if (read) {
bool found = false;
@@ -143,9 +138,10 @@ bool ChunkFile::descend(uint32_t id) {
}
void ChunkFile::seekTo(int _pos) {
if (!fastMode)
file.seekBeg(_pos);
pos=_pos;
if (!fastMode) {
fseek(file, 0, SEEK_SET);
}
pos = _pos;
}
//let's ascend out
@@ -174,7 +170,7 @@ void ChunkFile::readData(void *what, int count) {
if (fastMode)
memcpy(what, data + pos, count);
else
file.read(what,count);
fread(what, 1, count, file);
pos+=count;
char temp[4]; //discarded
@@ -182,21 +178,21 @@ void ChunkFile::readData(void *what, int count) {
if (count) {
count=4-count;
if (!fastMode)
file.read(temp,count);
fread(temp, 1, count, file); // could just as well seek
pos+=count;
}
}
//write a block
void ChunkFile::writeData(const void *what, int count) {
file.write(what, count);
fwrite(what, 1, count, file);
pos+=count;
char temp[5]={0,0,0,0,0};
count &= 3;
if (count)
{
count=4-count;
file.write(temp,count);
fwrite(temp, 1, count, file);
pos+=count;
}
}
+2 -3
View File
@@ -2,7 +2,6 @@
// RIFF file format reader/writer. Very old code, basically a total mess but it still works.
// Has nothing to do with the ChunkFile.h used in Dolphin or PPSSPP.
// LAMEFile should be removed.
// TO REMEMBER WHEN USING:
@@ -11,9 +10,9 @@
// otherwise the scheme breaks.
#include <string>
#include <stdio.h>
#include "base/basictypes.h"
#include "file/easy_file.h"
inline uint32_t flipID(uint32_t id) {
return ((id>>24)&0xFF) | ((id>>8)&0xFF00) | ((id<<8)&0xFF0000) | ((id<<24)&0xFF000000);
@@ -49,7 +48,7 @@ public:
private:
std::string fn;
LAMEFile file;
FILE *file;
struct ChunkInfo {
int startLocation;
int parentStartLocation;
-89
View File
@@ -1,89 +0,0 @@
#include <stdio.h>
#include "base/basictypes.h"
#include "file/easy_file.h"
LAMEFile::LAMEFile() : file_(NULL), isOpen(false), size_(0) {
}
LAMEFile::~LAMEFile() { }
bool LAMEFile::open(const char *filename, eFileMode mode) {
file_ = fopen(filename, mode == FILE_READ ? "rb" : "wb");
if (!file_) {
isOpen = false;
} else {
isOpen = true;
if (mode == FILE_READ) {
fseek(file_, 0, SEEK_END);
size_ = ftell(file_);
fseek(file_, 0, SEEK_SET);
}
}
return isOpen;
}
void LAMEFile::close() {
if (isOpen) {
//close the file and reset variables
fclose(file_);
file_ = NULL;
isOpen=false;
}
}
int LAMEFile::fileSize() {
if (!isOpen) //of course
return 0;
else
return size_;
}
std::string LAMEFile::readAll() {
std::string s;
size_t size = fileSize();
s.resize(size);
read(&s[0], size);
return s;
}
int LAMEFile::write(const void *data, size_t size) {
if (isOpen) {
return (int)fwrite(data, 1, size, file_); //we return the number of bytes that actually got written
} else {
return 0;
}
}
int LAMEFile::read(void *data, size_t size) {
if (isOpen) {
return (int)fread(data, 1, size, file_);
} else {
return 0;
}
}
int LAMEFile::readInt() {
int temp;
if (read(&temp, sizeof(int)))
return temp;
else
return 0;
}
void LAMEFile::writeInt(int i) {
write(&i, sizeof(int));
}
char LAMEFile::readChar() {
char temp;
if (read(&temp, sizeof(char)))
return temp;
else
return 0;
}
void LAMEFile::writeChar(char i) {
write(&i,sizeof(char));
}
-58
View File
@@ -1,58 +0,0 @@
#pragma once
// A dumb wrapper around stdio, for convenience. Very old.
#include <stdio.h>
#include <string>
#include "base/basictypes.h"
// Raw file paths, does not go through VFS.
enum eFileMode {
FILE_READ=5,
FILE_WRITE=6
};
// TODO: Rename.
class LAMEFile {
public:
LAMEFile();
virtual ~LAMEFile();
bool open(const char *filename, eFileMode mode);
bool open(std::string filename, eFileMode mode) {
return open(filename.c_str(), mode);
}
void close();
void writeInt(int i);
void writeChar(char i);
int write(const void *data, size_t size);
void write(const std::string &str) {
write((void *)str.data(), str.size());
}
int readInt();
char readChar();
int read(void *data, size_t size);
std::string readAll();
int fileSize();
void seekBeg(int pos) {
if (isOpen) fseek(file_,pos,SEEK_SET);
}
void seekEnd(int pos) {
if (isOpen) fseek(file_,pos,SEEK_END);
}
void seekCurrent(int pos) {
if (isOpen) fseek(file_,pos,SEEK_CUR);
}
private:
FILE *file_;
bool isOpen;
int size_;
};
+1
View File
@@ -29,6 +29,7 @@ std::string getFileExtension(const std::string &fn);
std::string getDir(const std::string &path);
std::string getFilename(std::string path);
bool getFileInfo(const char *path, FileInfo *fileInfo);
FILE *openCFile(const std::string &filename, const char *mode);
enum {
GETFILES_GETHIDDEN = 1
-2
View File
@@ -220,7 +220,6 @@
<ClInclude Include="ext\vjson\block_allocator.h" />
<ClInclude Include="ext\vjson\json.h" />
<ClInclude Include="file\chunk_file.h" />
<ClInclude Include="file\easy_file.h" />
<ClInclude Include="file\fd_util.h" />
<ClInclude Include="file\file_util.h" />
<ClInclude Include="file\path.h" />
@@ -676,7 +675,6 @@
<ClCompile Include="ext\vjson\block_allocator.cpp" />
<ClCompile Include="ext\vjson\json.cpp" />
<ClCompile Include="file\chunk_file.cpp" />
<ClCompile Include="file\easy_file.cpp" />
<ClCompile Include="file\fd_util.cpp" />
<ClCompile Include="file\file_util.cpp" />
<ClCompile Include="file\path.cpp" />
-6
View File
@@ -63,9 +63,6 @@
<ClInclude Include="file\chunk_file.h">
<Filter>file</Filter>
</ClInclude>
<ClInclude Include="file\easy_file.h">
<Filter>file</Filter>
</ClInclude>
<ClInclude Include="file\vfs.h">
<Filter>file</Filter>
</ClInclude>
@@ -341,9 +338,6 @@
<ClCompile Include="file\chunk_file.cpp">
<Filter>file</Filter>
</ClCompile>
<ClCompile Include="file\easy_file.cpp">
<Filter>file</Filter>
</ClCompile>
<ClCompile Include="file\zip_read.cpp">
<Filter>file</Filter>
</ClCompile>