Remove easy_file.cpp/h. Minor cleanups.

This commit is contained in:
Henrik Rydgard 2015-09-19 14:28:43 +02:00
parent 6cc7a85cde
commit ecbef7a2ff
13 changed files with 63 additions and 247 deletions

View file

@ -894,8 +894,6 @@ add_library(native STATIC
ext/native/ext/vjson/block_allocator.h
ext/native/file/chunk_file.cpp
ext/native/file/chunk_file.h
ext/native/file/easy_file.cpp
ext/native/file/easy_file.h
ext/native/file/fd_util.cpp
ext/native/file/fd_util.h
ext/native/file/file_util.cpp

View file

@ -33,8 +33,7 @@ inline struct tm* localtime_r(const time_t *clock, struct tm *result) {
}
#endif
namespace File
{
namespace File {
// FileSystem tree node/
struct FSTEntry
@ -107,8 +106,7 @@ const std::string &GetExeDirectory();
// simple wrapper for cstdlib file functions to
// hopefully will make error checking easier
// and make forgetting an fclose() harder
class IOFile : NonCopyable
{
class IOFile : NonCopyable {
public:
IOFile();
IOFile(std::FILE* file);

View file

@ -88,6 +88,22 @@ WindowsHost::WindowsHost(HWND mainWindow, HWND displayWindow)
SetConsolePosition();
}
void WindowsHost::SetConsolePosition() {
HWND console = GetConsoleWindow();
if (console != NULL && g_Config.iConsoleWindowX != -1 && g_Config.iConsoleWindowY != -1)
SetWindowPos(console, NULL, g_Config.iConsoleWindowX, g_Config.iConsoleWindowY, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
}
void WindowsHost::UpdateConsolePosition() {
RECT rc;
HWND console = GetConsoleWindow();
if (console != NULL && GetWindowRect(console, &rc) && !IsIconic(console))
{
g_Config.iConsoleWindowX = rc.left;
g_Config.iConsoleWindowY = rc.top;
}
}
bool WindowsHost::InitGraphics(std::string *error_message) {
switch (g_Config.iGPUBackend) {
case GPU_BACKEND_OPENGL:
@ -111,8 +127,7 @@ void WindowsHost::ShutdownGraphics() {
PostMessage(mainWindow_, WM_CLOSE, 0, 0);
}
void WindowsHost::SetWindowTitle(const char *message)
{
void WindowsHost::SetWindowTitle(const char *message) {
std::wstring winTitle = ConvertUTF8ToWString(std::string("PPSSPP ") + PPSSPP_GIT_VERSION);
if (message != nullptr) {
winTitle.append(ConvertUTF8ToWString(" - "));
@ -123,56 +138,47 @@ void WindowsHost::SetWindowTitle(const char *message)
PostMessage(mainWindow_, MainWindow::WM_USER_WINDOW_TITLE_CHANGED, 0, 0);
}
void WindowsHost::InitSound()
{
void WindowsHost::InitSound() {
}
// UGLY!
extern WindowsAudioBackend *winAudioBackend;
void WindowsHost::UpdateSound()
{
void WindowsHost::UpdateSound() {
if (winAudioBackend)
winAudioBackend->Update();
}
void WindowsHost::ShutdownSound()
{
void WindowsHost::ShutdownSound() {
}
void WindowsHost::UpdateUI()
{
void WindowsHost::UpdateUI() {
PostMessage(mainWindow_, MainWindow::WM_USER_UPDATE_UI, 0, 0);
}
void WindowsHost::UpdateScreen()
{
void WindowsHost::UpdateScreen() {
PostMessage(mainWindow_, MainWindow::WM_USER_UPDATE_SCREEN, 0, 0);
}
void WindowsHost::UpdateMemView()
{
void WindowsHost::UpdateMemView() {
for (int i = 0; i < numCPUs; i++)
if (memoryWindow[i])
PostDialogMessage(memoryWindow[i], WM_DEB_UPDATE);
}
void WindowsHost::UpdateDisassembly()
{
void WindowsHost::UpdateDisassembly() {
for (int i = 0; i < numCPUs; i++)
if (disasmWindow[i])
PostDialogMessage(disasmWindow[i], WM_DEB_UPDATE);
}
void WindowsHost::SetDebugMode(bool mode)
{
void WindowsHost::SetDebugMode(bool mode) {
for (int i = 0; i < numCPUs; i++)
if (disasmWindow[i])
PostDialogMessage(disasmWindow[i], WM_DEB_SETDEBUGLPARAM, 0, (LPARAM)mode);
}
void WindowsHost::PollControllers(InputState &input_state)
{
void WindowsHost::PollControllers(InputState &input_state) {
bool doPad = true;
for (auto iter = this->input.begin(); iter != this->input.end(); iter++)
{
@ -202,8 +208,7 @@ void WindowsHost::PollControllers(InputState &input_state)
//if (fabsf(my) > 0.1f) NativeAxis(axisY);
}
void WindowsHost::BootDone()
{
void WindowsHost::BootDone() {
symbolMap.SortSymbols();
SendMessage(mainWindow_, WM_USER + 1, 0, 0);
@ -211,16 +216,14 @@ void WindowsHost::BootDone()
Core_EnableStepping(!g_Config.bAutoRun);
}
static std::string SymbolMapFilename(const char *currentFilename, char* ext)
{
static std::string SymbolMapFilename(const char *currentFilename, char* ext) {
FileInfo info;
std::string result = currentFilename;
// can't fail, definitely exists if it gets this far
getFileInfo(currentFilename, &info);
if (info.isDirectory)
{
if (info.isDirectory) {
#ifdef _WIN32
char* slash = "\\";
#else
@ -240,8 +243,7 @@ static std::string SymbolMapFilename(const char *currentFilename, char* ext)
}
}
bool WindowsHost::AttemptLoadSymbolMap()
{
bool WindowsHost::AttemptLoadSymbolMap() {
bool result1 = symbolMap.LoadSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart.c_str(),".ppmap").c_str());
// Load the old-style map file.
if (!result1)
@ -250,13 +252,11 @@ bool WindowsHost::AttemptLoadSymbolMap()
return result1 || result2;
}
void WindowsHost::SaveSymbolMap()
{
void WindowsHost::SaveSymbolMap() {
symbolMap.SaveSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart.c_str(),".ppmap").c_str());
}
bool WindowsHost::IsDebuggingEnabled()
{
bool WindowsHost::IsDebuggingEnabled() {
#ifdef _DEBUG
return true;
#else
@ -264,24 +264,6 @@ bool WindowsHost::IsDebuggingEnabled()
#endif
}
void WindowsHost::SetConsolePosition()
{
HWND console = GetConsoleWindow();
if (console != NULL && g_Config.iConsoleWindowX != -1 && g_Config.iConsoleWindowY != -1)
SetWindowPos(console, NULL, g_Config.iConsoleWindowX, g_Config.iConsoleWindowY, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
}
void WindowsHost::UpdateConsolePosition()
{
RECT rc;
HWND console = GetConsoleWindow();
if (console != NULL && GetWindowRect(console, &rc) && !IsIconic(console))
{
g_Config.iConsoleWindowX = rc.left;
g_Config.iConsoleWindowY = rc.top;
}
}
// http://msdn.microsoft.com/en-us/library/aa969393.aspx
HRESULT CreateLink(LPCWSTR lpszPathObj, LPCWSTR lpszArguments, LPCWSTR lpszPathLink, LPCWSTR lpszDesc) {
HRESULT hres;

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 \

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"

View file

@ -1,5 +1,4 @@
set(SRCS
easy_file.cpp
chunk_file.cpp
zip_read.cpp
file_util.cpp

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;
}
}

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;

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));
}

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_;
};

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

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" />

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>