Converted a few of the file paths to strings, and moved the generic file manipulation functions in IsoFileFormats to their own file.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1562 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
arcum42 2009-07-24 03:08:14 +00:00
parent 90c2f8ebc6
commit 56a98ca922
11 changed files with 234 additions and 181 deletions

View File

@ -148,17 +148,17 @@ struct PluginNames
// This may end up being moved to Paths.h. It may also be converted to strings.
struct FilePaths
{
char Working[g_MaxPath];
string Working;
char Plugins[g_MaxPath];
char Bios[g_MaxPath];
// These are mainly placeholders for later.
char Isos[g_MaxPath];
char Dumps[g_MaxPath];
string Isos;
string Dumps;
// This is intended for the program to populate, and the plugins to read.
// Obviously can't be saved in the config file. :)
char Inis[g_MaxPath];
string Inis;
};
struct Hacks_t

View File

@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "PrecompiledHeader.h"
#include "IopCommon.h"
#include "IsoFStools.h"
@ -26,134 +26,6 @@
#include <fcntl.h>
#include <errno.h>
#ifdef _WIN32
#include <windows.h>
void *_openfile(const char *filename, int flags)
{
HANDLE handle;
// Console::WriteLn("_openfile %s, %d", params filename, flags & O_RDONLY);
if (flags & O_WRONLY)
{
int _flags = CREATE_NEW;
if (flags & O_CREAT) _flags = CREATE_ALWAYS;
handle = CreateFile(filename, GENERIC_WRITE, 0, NULL, _flags, 0, NULL);
}
else
{
handle = CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
}
return handle == INVALID_HANDLE_VALUE ? NULL : handle;
}
u64 _tellfile(void *handle)
{
u64 ofs;
PLONG _ofs = (LONG*) & ofs;
_ofs[1] = 0;
_ofs[0] = SetFilePointer(handle, 0, &_ofs[1], FILE_CURRENT);
return ofs;
}
int _seekfile(void *handle, u64 offset, int whence)
{
u64 ofs = (u64)offset;
PLONG _ofs = (LONG*) & ofs;
// Console::WriteLn("_seekfile %p, %d_%d", params handle, _ofs[1], _ofs[0]);
if (whence == SEEK_SET)
{
SetFilePointer(handle, _ofs[0], &_ofs[1], FILE_BEGIN);
}
else
{
SetFilePointer(handle, _ofs[0], &_ofs[1], FILE_END);
}
return 0;
}
int _readfile(void *handle, void *dst, int size)
{
DWORD ret;
// Console::WriteLn("_readfile %p %d", params handle, size);
ReadFile(handle, dst, size, &ret, NULL);
// Console::WriteLn("_readfile ret %d; %d", params ret, GetLastError());
return ret;
}
int _writefile(void *handle, void *src, int size)
{
DWORD ret;
// Console::WriteLn("_writefile %p, %d", params handle, size);
// _seekfile(handle, _tellfile(handle));
WriteFile(handle, src, size, &ret, NULL);
// Console::WriteLn("_writefile ret %d", params ret);
return ret;
}
void _closefile(void *handle)
{
CloseHandle(handle);
}
#else
void *_openfile(const char *filename, int flags)
{
// Console::WriteLn("_openfile %s %x", params filename, flags);
if (flags & O_WRONLY)
return fopen64(filename, "wb");
else
return fopen64(filename, "rb");
}
u64 _tellfile(void *handle)
{
s64 cursize = ftell(handle);
if (cursize == -1)
{
// try 64bit
cursize = ftello64(handle);
if (cursize < -1)
{
// zero top 32 bits
cursize &= 0xffffffff;
}
}
return cursize;
}
int _seekfile(void *handle, u64 offset, int whence)
{
int seekerr = fseeko64(handle, offset, whence);
if (seekerr == -1) Console::Error("Failed to seek.");
return seekerr;
}
int _readfile(void *handle, void *dst, int size)
{
return fread(dst, 1, size, handle);
}
int _writefile(void *handle, void *src, int size)
{
return fwrite(src, 1, size, handle);
}
void _closefile(void *handle)
{
fclose(handle);
}
#endif
int detect(isoFile *iso)
{
u8 buf[2448];

View File

@ -19,26 +19,8 @@
#ifndef __LIBISO_H__
#define __LIBISO_H__
#ifndef __USE_LARGEFILE64
#define __USE_LARGEFILE64
#endif
#ifndef _LARGEFILE64_SOURCE
#define _LARGEFILE_SOURCE
#endif
#ifndef _LARGEFILE64_SOURCE
#define _LARGEFILE64_SOURCE
#endif
#define __USE_FILE_OFFSET64
#define _FILE_OFFSET_BITS 64
#ifdef _MSC_VER
#pragma warning(disable:4018)
#endif
#include "CDVD.h"
#include "IsoFileTools.h"
enum isoType
{
@ -99,11 +81,4 @@ int isoReadBlock(isoFile *iso, u8 *dst, int lsn);
int isoWriteBlock(isoFile *iso, u8 *src, int lsn);
void isoClose(isoFile *iso);
void *_openfile(const char *filename, int flags);
u64 _tellfile(void *handle);
int _seekfile(void *handle, u64 offset, int whence);
int _readfile(void *handle, void *dst, int size);
int _writefile(void *handle, void *src, int size);
void _closefile(void *handle);
#endif /* __LIBISO_H__ */

148
pcsx2/CDVD/IsoFileTools.cpp Normal file
View File

@ -0,0 +1,148 @@
/* Pcsx2 - Pc Ps2 Emulator
* Copyright (C) 2002-2009 Pcsx2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "PrecompiledHeader.h"
#include "IsoFileTools.h"
#ifdef _WIN32
#include <windows.h>
void *_openfile(const char *filename, int flags)
{
HANDLE handle;
// Console::WriteLn("_openfile %s, %d", params filename, flags & O_RDONLY);
if (flags & O_WRONLY)
{
int _flags = CREATE_NEW;
if (flags & O_CREAT) _flags = CREATE_ALWAYS;
handle = CreateFile(filename, GENERIC_WRITE, 0, NULL, _flags, 0, NULL);
}
else
{
handle = CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
}
return handle == INVALID_HANDLE_VALUE ? NULL : handle;
}
u64 _tellfile(void *handle)
{
u64 ofs;
PLONG _ofs = (LONG*) & ofs;
_ofs[1] = 0;
_ofs[0] = SetFilePointer(handle, 0, &_ofs[1], FILE_CURRENT);
return ofs;
}
int _seekfile(void *handle, u64 offset, int whence)
{
u64 ofs = (u64)offset;
PLONG _ofs = (LONG*) & ofs;
// Console::WriteLn("_seekfile %p, %d_%d", params handle, _ofs[1], _ofs[0]);
if (whence == SEEK_SET)
{
SetFilePointer(handle, _ofs[0], &_ofs[1], FILE_BEGIN);
}
else
{
SetFilePointer(handle, _ofs[0], &_ofs[1], FILE_END);
}
return 0;
}
int _readfile(void *handle, void *dst, int size)
{
DWORD ret;
// Console::WriteLn("_readfile %p %d", params handle, size);
ReadFile(handle, dst, size, &ret, NULL);
// Console::WriteLn("_readfile ret %d; %d", params ret, GetLastError());
return ret;
}
int _writefile(void *handle, void *src, int size)
{
DWORD ret;
// Console::WriteLn("_writefile %p, %d", params handle, size);
// _seekfile(handle, _tellfile(handle));
WriteFile(handle, src, size, &ret, NULL);
// Console::WriteLn("_writefile ret %d", params ret);
return ret;
}
void _closefile(void *handle)
{
CloseHandle(handle);
}
#else
void *_openfile(const char *filename, int flags)
{
// Console::WriteLn("_openfile %s %x", params filename, flags);
if (flags & O_WRONLY)
return fopen64(filename, "wb");
else
return fopen64(filename, "rb");
}
u64 _tellfile(void *handle)
{
s64 cursize = ftell(handle);
if (cursize == -1)
{
// try 64bit
cursize = ftello64(handle);
if (cursize < -1)
{
// zero top 32 bits
cursize &= 0xffffffff;
}
}
return cursize;
}
int _seekfile(void *handle, u64 offset, int whence)
{
int seekerr = fseeko64(handle, offset, whence);
if (seekerr == -1) Console::Error("Failed to seek.");
return seekerr;
}
int _readfile(void *handle, void *dst, int size)
{
return fread(dst, 1, size, handle);
}
int _writefile(void *handle, void *src, int size)
{
return fwrite(src, 1, size, handle);
}
void _closefile(void *handle)
{
fclose(handle);
}
#endif

50
pcsx2/CDVD/IsoFileTools.h Normal file
View File

@ -0,0 +1,50 @@
/* Pcsx2 - Pc Ps2 Emulator
* Copyright (C) 2002-2009 Pcsx2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __ISO_FILE_TOOLS_H__
#define __ISO_FILE_TOOLS_H__
#ifndef _LARGEFILE_SOURCE
#define _LARGEFILE_SOURCE
#endif
#ifndef _LARGEFILE64_SOURCE
#define _LARGEFILE64_SOURCE
#endif
#define __USE_FILE_OFFSET64
#define _FILE_OFFSET_BITS 64
#ifdef _MSC_VER
#pragma warning(disable:4018)
#endif
#include "IopCommon.h"
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
void *_openfile(const char *filename, int flags);
u64 _tellfile(void *handle);
int _seekfile(void *handle, u64 offset, int whence);
int _readfile(void *handle, void *dst, int size);
int _writefile(void *handle, void *src, int size);
void _closefile(void *handle);
#endif

View File

@ -15,6 +15,6 @@ libps2_cdvd_a_SOURCES = \
CDVD.cpp IsoFStools.cpp IsoFSdrv.cpp CdRom.cpp \
CDVD.h CDVD_internal.h IsoFStools.h IsoFSdrv.h IsoFScdvd.h CdRom.h \
CDVDisoReader.cpp CDVDisoReader.h CDVDaccess.cpp CDVDaccess.h \
IsoFileFormats.cpp IsoFileFormats.h
IsoFileFormats.cpp IsoFileFormats.h IsoFileTools.cpp IsoFileTools.h
#SUBDIRS =

View File

@ -37,8 +37,8 @@ int main(int argc, char *argv[])
efile = 0;
/* store main dir */
strcpy(Config.Paths.Working, Path::GetWorkingDirectory().c_str());
Console::Notice("Config.Paths.Working is %s", params Config.Paths.Working);
Config.Paths.Working = Path::GetWorkingDirectory();
Console::Notice("Config.Paths.Working is %s", params Config.Paths.Working.c_str());
#ifdef ENABLE_NLS
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, "Langs");
@ -48,15 +48,15 @@ int main(int argc, char *argv[])
// Note: Config.Paths.Inis won't do anything till we set up windows and the plugins to use it.
#ifndef LOCAL_PLUGIN_INIS
mkdir(DEFAULT_INIS_DIR, 0755);
sprintf(Config.Paths.Inis, "%s/%s/", Config.Paths.Working, DEFAULT_INIS_DIR);
sprintf(cfgfile, "%s/pcsx2.cfg", Config.Paths.Inis);
Config.Paths.Inis = Config.Paths.Working + "/" + string(DEFAULT_INIS_DIR) + "/";
sprintf(cfgfile, "%s/pcsx2.cfg", Config.Paths.Inis.c_str());
#else
Path::CreateDirectory(string("~/.pcsx2"));
Path::ChangeDirectory(string("~/.pcsx2"));
Path::CreateDirectory(string(DEFAULT_INIS_DIR));
sprintf(Config.Paths.Inis, "~/.pcsx2/%s/", DEFAULT_INIS_DIR);
sprintf(cfgfile, "%s/pcsx2.cfg", Config.Paths.Inis);
Path::ChangeDirectory(string(Config.Paths.Working));
Path::CreateDirectory("~/.pcsx2");
Path::ChangeDirectory("~/.pcsx2");
Path::CreateDirectory(DEFAULT_INIS_DIR);
Config.Paths.Inis = "~/.pcsx2/" + DEFAULT_INIS_DIR + "/";
sprintf(cfgfile, "%s/pcsx2.cfg", Config.Paths.Inis.c_str());
Path::ChangeDirectory(Config.Paths.Working);
#endif
#ifdef PCSX2_DEVBUILD
@ -81,10 +81,10 @@ int main(int argc, char *argv[])
{
memset(&Config, 0, sizeof(Config));
sprintf(Config.Paths.Bios, "%s/%s/", Config.Paths.Working, DEFAULT_BIOS_DIR);
sprintf(Config.Paths.Plugins, "%s/%s/", Config.Paths.Working, DEFAULT_PLUGINS_DIR);
sprintf(Config.Mcd[0].Filename, "%s/%s/%s", Config.Paths.Working, MEMCARDS_DIR, DEFAULT_MEMCARD1);
sprintf(Config.Mcd[1].Filename, "%s/%s/%s", Config.Paths.Working, MEMCARDS_DIR, DEFAULT_MEMCARD2);
sprintf(Config.Paths.Bios, "%s/%s/", Config.Paths.Working.c_str(), DEFAULT_BIOS_DIR);
sprintf(Config.Paths.Plugins, "%s/%s/", Config.Paths.Working.c_str(), DEFAULT_PLUGINS_DIR);
sprintf(Config.Mcd[0].Filename, "%s/%s/%s", Config.Paths.Working.c_str(), MEMCARDS_DIR, DEFAULT_MEMCARD1);
sprintf(Config.Mcd[1].Filename, "%s/%s/%s", Config.Paths.Working.c_str(), MEMCARDS_DIR, DEFAULT_MEMCARD2);
Config.Mcd[0].Enabled = 1;
Config.Mcd[1].Enabled = 1;
Config.McdEnableEject = 1;

View File

@ -56,7 +56,7 @@ void OnConf_Memcards(GtkMenuItem *menuitem, gpointer user_data)
{
char path[g_MaxPath];
sprintf(path, "%s/%s/%s", Config.Paths.Working, MEMCARDS_DIR, entry->d_name);
sprintf(path, "%s/%s/%s", Config.Paths.Working.c_str(), MEMCARDS_DIR, entry->d_name);
for (j = 0; j < 2; j++)
{
@ -83,17 +83,17 @@ void OnConf_Memcards(GtkMenuItem *menuitem, gpointer user_data)
void OnMemcards_Ok(GtkButton *button, gpointer user_data)
{
if (gtk_combo_box_get_active(GTK_COMBO_BOX(lookup_widget(MemDlg, "memcard1combo"))) != -1)
sprintf(Config.Mcd[0].Filename, "%s/%s/%s", Config.Paths.Working, MEMCARDS_DIR,
sprintf(Config.Mcd[0].Filename, "%s/%s/%s", Config.Paths.Working.c_str(), MEMCARDS_DIR,
gtk_combo_box_get_active_text(GTK_COMBO_BOX(lookup_widget(MemDlg, "memcard1combo"))));
else
sprintf(Config.Mcd[0].Filename, "%s/%s/%s", Config.Paths.Working, MEMCARDS_DIR, DEFAULT_MEMCARD1);
sprintf(Config.Mcd[0].Filename, "%s/%s/%s", Config.Paths.Working.c_str(), MEMCARDS_DIR, DEFAULT_MEMCARD1);
if (gtk_combo_box_get_active(GTK_COMBO_BOX(lookup_widget(MemDlg, "memcard2combo"))) != -1)
sprintf(Config.Mcd[1].Filename, "%s/%s/%s", Config.Paths.Working, MEMCARDS_DIR,
sprintf(Config.Mcd[1].Filename, "%s/%s/%s", Config.Paths.Working.c_str(), MEMCARDS_DIR,
gtk_combo_box_get_active_text(GTK_COMBO_BOX(lookup_widget(MemDlg, "memcard2combo"))));
else
sprintf(Config.Mcd[1].Filename, "%s/%s/%s", Config.Paths.Working, MEMCARDS_DIR, DEFAULT_MEMCARD2);
sprintf(Config.Mcd[1].Filename, "%s/%s/%s", Config.Paths.Working.c_str(), MEMCARDS_DIR, DEFAULT_MEMCARD2);
Config.Mcd[0].Enabled = is_checked(MemDlg, "check_enable_mcd1");
Config.Mcd[1].Enabled = is_checked(MemDlg, "check_enable_mcd2");

View File

@ -59,7 +59,7 @@ void DlgItem_GetText( HWND hwnd, int dlgId, string& dest )
static const char* _stripPathInfo( const char* src )
{
const char* retval = src;
const char* workingfold = Config.Paths.Working;
const char* workingfold = Config.Paths.Working.c_str();
while( (*retval != 0) && (*workingfold != 0) && (tolower(*retval) == tolower(*workingfold)) )
{

View File

@ -2487,6 +2487,14 @@
RelativePath="..\..\CDVD\IsoFileFormats.h"
>
</File>
<File
RelativePath="..\..\CDVD\IsoFileTools.cpp"
>
</File>
<File
RelativePath="..\..\CDVD\IsoFileTools.h"
>
</File>
<File
RelativePath="..\..\CDVD\IsoFScdvd.h"
>

View File

@ -269,7 +269,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
#endif
//strcpy(g_WorkingFolder, Path::GetWorkingDirectory().c_str());
strcpy(Config.Paths.Working, Path::GetWorkingDirectory().c_str());
Config.Paths.Working = Path::GetWorkingDirectory();
int argc;
TCHAR *const *const argv = _CommandLineToArgv( lpCmdLine, &argc );