mirror of
https://github.com/izzy2lost/dolphin.git
synced 2026-06-19 01:16:48 -07:00
set svn:eol-style=native for **.cpp
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1442 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
@@ -1,103 +1,103 @@
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// 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, version 2.0.
|
||||
|
||||
// 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 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "BannerLoader.h"
|
||||
#include "BannerLoaderWii.h"
|
||||
#include "BannerLoaderGC.h"
|
||||
|
||||
#include "VolumeCreator.h"
|
||||
#include "FileUtil.h"
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
bool IBannerLoader::CopyToStringAndCheck(std::string& _rDestination, const char* _src)
|
||||
{
|
||||
static bool bValidChars[256];
|
||||
static bool bInitialized = false;
|
||||
|
||||
if (!bInitialized)
|
||||
{
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
bValidChars[i] = false;
|
||||
}
|
||||
|
||||
// generate valid chars
|
||||
for (unsigned char c = 0x20; c <= 0x80; c++)
|
||||
{
|
||||
bValidChars[c] = true;
|
||||
}
|
||||
|
||||
bValidChars[0x0a] = true;
|
||||
bValidChars[0xa9] = true;
|
||||
bValidChars[0xe9] = true;
|
||||
|
||||
bInitialized = true;
|
||||
}
|
||||
|
||||
bool bResult = true;
|
||||
char destBuffer[2048];
|
||||
char* dest = destBuffer;
|
||||
const char* src = _src;
|
||||
|
||||
// copy the string and check for "unknown" characters
|
||||
while (*src != 0x00)
|
||||
{
|
||||
u8 c = *src;
|
||||
|
||||
if (c == 0x0a){c = 0x20;}
|
||||
|
||||
if (bValidChars[c] == false)
|
||||
{
|
||||
bResult = false;
|
||||
break;
|
||||
}
|
||||
|
||||
*dest = c;
|
||||
dest++;
|
||||
src++;
|
||||
}
|
||||
|
||||
// finalize the string
|
||||
if (bResult)
|
||||
{
|
||||
*dest = 0x00;
|
||||
}
|
||||
else
|
||||
{
|
||||
dest[0] = ' ';
|
||||
dest[1] = 0x00;
|
||||
}
|
||||
|
||||
_rDestination = destBuffer;
|
||||
|
||||
return(bResult);
|
||||
}
|
||||
|
||||
|
||||
IBannerLoader* CreateBannerLoader(DiscIO::IFileSystem& _rFileSystem)
|
||||
{
|
||||
if (IsVolumeWiiDisc(_rFileSystem.GetVolume()))
|
||||
{
|
||||
return(new CBannerLoaderWii(_rFileSystem));
|
||||
}
|
||||
|
||||
return(new CBannerLoaderGC(_rFileSystem));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// 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, version 2.0.
|
||||
|
||||
// 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 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "BannerLoader.h"
|
||||
#include "BannerLoaderWii.h"
|
||||
#include "BannerLoaderGC.h"
|
||||
|
||||
#include "VolumeCreator.h"
|
||||
#include "FileUtil.h"
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
bool IBannerLoader::CopyToStringAndCheck(std::string& _rDestination, const char* _src)
|
||||
{
|
||||
static bool bValidChars[256];
|
||||
static bool bInitialized = false;
|
||||
|
||||
if (!bInitialized)
|
||||
{
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
bValidChars[i] = false;
|
||||
}
|
||||
|
||||
// generate valid chars
|
||||
for (unsigned char c = 0x20; c <= 0x80; c++)
|
||||
{
|
||||
bValidChars[c] = true;
|
||||
}
|
||||
|
||||
bValidChars[0x0a] = true;
|
||||
bValidChars[0xa9] = true;
|
||||
bValidChars[0xe9] = true;
|
||||
|
||||
bInitialized = true;
|
||||
}
|
||||
|
||||
bool bResult = true;
|
||||
char destBuffer[2048];
|
||||
char* dest = destBuffer;
|
||||
const char* src = _src;
|
||||
|
||||
// copy the string and check for "unknown" characters
|
||||
while (*src != 0x00)
|
||||
{
|
||||
u8 c = *src;
|
||||
|
||||
if (c == 0x0a){c = 0x20;}
|
||||
|
||||
if (bValidChars[c] == false)
|
||||
{
|
||||
bResult = false;
|
||||
break;
|
||||
}
|
||||
|
||||
*dest = c;
|
||||
dest++;
|
||||
src++;
|
||||
}
|
||||
|
||||
// finalize the string
|
||||
if (bResult)
|
||||
{
|
||||
*dest = 0x00;
|
||||
}
|
||||
else
|
||||
{
|
||||
dest[0] = ' ';
|
||||
dest[1] = 0x00;
|
||||
}
|
||||
|
||||
_rDestination = destBuffer;
|
||||
|
||||
return(bResult);
|
||||
}
|
||||
|
||||
|
||||
IBannerLoader* CreateBannerLoader(DiscIO::IFileSystem& _rFileSystem)
|
||||
{
|
||||
if (IsVolumeWiiDisc(_rFileSystem.GetVolume()))
|
||||
{
|
||||
return(new CBannerLoaderWii(_rFileSystem));
|
||||
}
|
||||
|
||||
return(new CBannerLoaderGC(_rFileSystem));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -1,193 +1,193 @@
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// 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, version 2.0.
|
||||
|
||||
// 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 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "BannerLoaderGC.h"
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
CBannerLoaderGC::CBannerLoaderGC(DiscIO::IFileSystem& _rFileSystem)
|
||||
: m_pBannerFile(NULL),
|
||||
m_IsValid(false)
|
||||
{
|
||||
// build LUT Table
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
lut3to8[i] = (i * 255) / 7;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
lut4to8[i] = (i * 255) / 15;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
lut5to8[i] = (i * 255) / 31;
|
||||
}
|
||||
|
||||
// load the opening.bnr
|
||||
size_t FileSize = _rFileSystem.GetFileSize("opening.bnr");
|
||||
|
||||
if (FileSize > 0)
|
||||
{
|
||||
m_pBannerFile = new u8[FileSize];
|
||||
_rFileSystem.ReadFile("opening.bnr", m_pBannerFile, FileSize);
|
||||
m_IsValid = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CBannerLoaderGC::~CBannerLoaderGC()
|
||||
{
|
||||
delete [] m_pBannerFile;
|
||||
m_pBannerFile = NULL;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CBannerLoaderGC::IsValid()
|
||||
{
|
||||
return(m_IsValid);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CBannerLoaderGC::GetBanner(u32* _pBannerImage)
|
||||
{
|
||||
if (!IsValid())
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
DVDBanner2* pBanner = (DVDBanner2*)m_pBannerFile;
|
||||
decode5A3image(_pBannerImage, pBanner->image, DVD_BANNER_WIDTH, DVD_BANNER_HEIGHT);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CBannerLoaderGC::GetName(std::string& _rName, int language)
|
||||
{
|
||||
_rName = "invalid image";
|
||||
|
||||
if (!IsValid())
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
DVDBanner2* pBanner = (DVDBanner2*)m_pBannerFile;
|
||||
|
||||
if (!CopyToStringAndCheck(_rName, language != 0 ? pBanner->comment[0].shortTitle : pBanner->comment[0].longTitle))
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CBannerLoaderGC::GetCompany(std::string& _rCompany)
|
||||
{
|
||||
_rCompany = "invalid images";
|
||||
|
||||
if (!IsValid())
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
DVDBanner2* pBanner = (DVDBanner2*)m_pBannerFile;
|
||||
|
||||
if (!CopyToStringAndCheck(_rCompany, pBanner->comment[0].shortMaker))
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CBannerLoaderGC::GetDescription(std::string& _rDescription)
|
||||
{
|
||||
_rDescription = "invalid images";
|
||||
|
||||
if (!IsValid())
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
DVDBanner2* pBanner = (DVDBanner2*)m_pBannerFile;
|
||||
|
||||
if (!CopyToStringAndCheck(_rDescription, pBanner->comment[0].comment))
|
||||
{
|
||||
_rDescription = "";
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
u32
|
||||
CBannerLoaderGC::decode5A3(u16 val)
|
||||
{
|
||||
u32 bannerBGColor = 0x00000000;
|
||||
|
||||
int r, g, b, a;
|
||||
|
||||
if ((val & 0x8000))
|
||||
{
|
||||
r = lut5to8[(val >> 10) & 0x1f];
|
||||
g = lut5to8[(val >> 5) & 0x1f];
|
||||
b = lut5to8[(val) & 0x1f];
|
||||
a = 0xFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
a = lut3to8[(val >> 12) & 0x7];
|
||||
r = (lut4to8[(val >> 8) & 0xf] * a + (bannerBGColor & 0xFF) * (255 - a)) / 255;
|
||||
g = (lut4to8[(val >> 4) & 0xf] * a + ((bannerBGColor >> 8) & 0xFF) * (255 - a)) / 255;
|
||||
b = (lut4to8[(val) & 0xf] * a + ((bannerBGColor >> 16) & 0xFF) * (255 - a)) / 255;
|
||||
a = 0xFF;
|
||||
}
|
||||
|
||||
return((a << 24) | (r << 16) | (g << 8) | b);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CBannerLoaderGC::decode5A3image(u32* dst, u16* src, int width, int height)
|
||||
{
|
||||
for (int y = 0; y < height; y += 4)
|
||||
{
|
||||
for (int x = 0; x < width; x += 4)
|
||||
{
|
||||
for (int iy = 0; iy < 4; iy++, src += 4)
|
||||
{
|
||||
for (int ix = 0; ix < 4; ix++)
|
||||
{
|
||||
u32 RGBA = decode5A3(Common::swap16(src[ix]));
|
||||
dst[(y + iy) * width + (x + ix)] = RGBA;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// 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, version 2.0.
|
||||
|
||||
// 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 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "BannerLoaderGC.h"
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
CBannerLoaderGC::CBannerLoaderGC(DiscIO::IFileSystem& _rFileSystem)
|
||||
: m_pBannerFile(NULL),
|
||||
m_IsValid(false)
|
||||
{
|
||||
// build LUT Table
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
lut3to8[i] = (i * 255) / 7;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
lut4to8[i] = (i * 255) / 15;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
lut5to8[i] = (i * 255) / 31;
|
||||
}
|
||||
|
||||
// load the opening.bnr
|
||||
size_t FileSize = _rFileSystem.GetFileSize("opening.bnr");
|
||||
|
||||
if (FileSize > 0)
|
||||
{
|
||||
m_pBannerFile = new u8[FileSize];
|
||||
_rFileSystem.ReadFile("opening.bnr", m_pBannerFile, FileSize);
|
||||
m_IsValid = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CBannerLoaderGC::~CBannerLoaderGC()
|
||||
{
|
||||
delete [] m_pBannerFile;
|
||||
m_pBannerFile = NULL;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CBannerLoaderGC::IsValid()
|
||||
{
|
||||
return(m_IsValid);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CBannerLoaderGC::GetBanner(u32* _pBannerImage)
|
||||
{
|
||||
if (!IsValid())
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
DVDBanner2* pBanner = (DVDBanner2*)m_pBannerFile;
|
||||
decode5A3image(_pBannerImage, pBanner->image, DVD_BANNER_WIDTH, DVD_BANNER_HEIGHT);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CBannerLoaderGC::GetName(std::string& _rName, int language)
|
||||
{
|
||||
_rName = "invalid image";
|
||||
|
||||
if (!IsValid())
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
DVDBanner2* pBanner = (DVDBanner2*)m_pBannerFile;
|
||||
|
||||
if (!CopyToStringAndCheck(_rName, language != 0 ? pBanner->comment[0].shortTitle : pBanner->comment[0].longTitle))
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CBannerLoaderGC::GetCompany(std::string& _rCompany)
|
||||
{
|
||||
_rCompany = "invalid images";
|
||||
|
||||
if (!IsValid())
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
DVDBanner2* pBanner = (DVDBanner2*)m_pBannerFile;
|
||||
|
||||
if (!CopyToStringAndCheck(_rCompany, pBanner->comment[0].shortMaker))
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CBannerLoaderGC::GetDescription(std::string& _rDescription)
|
||||
{
|
||||
_rDescription = "invalid images";
|
||||
|
||||
if (!IsValid())
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
DVDBanner2* pBanner = (DVDBanner2*)m_pBannerFile;
|
||||
|
||||
if (!CopyToStringAndCheck(_rDescription, pBanner->comment[0].comment))
|
||||
{
|
||||
_rDescription = "";
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
u32
|
||||
CBannerLoaderGC::decode5A3(u16 val)
|
||||
{
|
||||
u32 bannerBGColor = 0x00000000;
|
||||
|
||||
int r, g, b, a;
|
||||
|
||||
if ((val & 0x8000))
|
||||
{
|
||||
r = lut5to8[(val >> 10) & 0x1f];
|
||||
g = lut5to8[(val >> 5) & 0x1f];
|
||||
b = lut5to8[(val) & 0x1f];
|
||||
a = 0xFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
a = lut3to8[(val >> 12) & 0x7];
|
||||
r = (lut4to8[(val >> 8) & 0xf] * a + (bannerBGColor & 0xFF) * (255 - a)) / 255;
|
||||
g = (lut4to8[(val >> 4) & 0xf] * a + ((bannerBGColor >> 8) & 0xFF) * (255 - a)) / 255;
|
||||
b = (lut4to8[(val) & 0xf] * a + ((bannerBGColor >> 16) & 0xFF) * (255 - a)) / 255;
|
||||
a = 0xFF;
|
||||
}
|
||||
|
||||
return((a << 24) | (r << 16) | (g << 8) | b);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CBannerLoaderGC::decode5A3image(u32* dst, u16* src, int width, int height)
|
||||
{
|
||||
for (int y = 0; y < height; y += 4)
|
||||
{
|
||||
for (int x = 0; x < width; x += 4)
|
||||
{
|
||||
for (int iy = 0; iy < 4; iy++, src += 4)
|
||||
{
|
||||
for (int ix = 0; ix < 4; ix++)
|
||||
{
|
||||
u32 RGBA = decode5A3(Common::swap16(src[ix]));
|
||||
dst[(y + iy) * width + (x + ix)] = RGBA;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -1,224 +1,224 @@
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// 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, version 2.0.
|
||||
|
||||
// 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 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "Common.h"
|
||||
#include "BannerLoaderWii.h"
|
||||
#include "FileUtil.h"
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
CBannerLoaderWii::CBannerLoaderWii(DiscIO::IFileSystem& _rFileSystem)
|
||||
: m_pBannerFile(NULL)
|
||||
, m_IsValid(false)
|
||||
{
|
||||
InitLUTTable();
|
||||
|
||||
char Filename[260];
|
||||
char TitleID[4];
|
||||
|
||||
_rFileSystem.GetVolume()->Read(0, 4, (u8*)TitleID);
|
||||
sprintf(Filename, FULL_WII_USER_DIR "title/00010000/%02x%02x%02x%02x/data/banner.bin", (u8)TitleID[0], (u8)TitleID[1], (u8)TitleID[2], (u8)TitleID[3]);
|
||||
|
||||
// load the opening.bnr
|
||||
size_t FileSize = File::GetSize(Filename);
|
||||
|
||||
if (FileSize > 0)
|
||||
{
|
||||
m_pBannerFile = new u8[FileSize];
|
||||
FILE* pFile = fopen(Filename, "rb");
|
||||
if (pFile != NULL)
|
||||
{
|
||||
fread(m_pBannerFile, FileSize, 1, pFile);
|
||||
fclose(pFile);
|
||||
m_IsValid = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CBannerLoaderWii::~CBannerLoaderWii()
|
||||
{
|
||||
if (m_pBannerFile)
|
||||
{
|
||||
delete [] m_pBannerFile;
|
||||
m_pBannerFile = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CBannerLoaderWii::IsValid()
|
||||
{
|
||||
return (m_IsValid);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CBannerLoaderWii::GetBanner(u32* _pBannerImage)
|
||||
{
|
||||
if (!IsValid())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile;
|
||||
|
||||
static u32 Buffer[192 * 64];
|
||||
decode5A3image(Buffer, (u16*)pBanner->m_BannerTexture, 192, 64);
|
||||
|
||||
// ugly scaling :)
|
||||
for (int y=0; y<32; y++)
|
||||
{
|
||||
for (int x=0; x<96; x++)
|
||||
{
|
||||
_pBannerImage[y*96+x] = Buffer[(y*192*2)+(x*2)];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string
|
||||
CBannerLoaderWii::StupidWideCharToString(u16* _pSrc, size_t _max)
|
||||
{
|
||||
std::string temp;
|
||||
|
||||
u32 offset = 0;
|
||||
while (_pSrc[offset] != 0x0000)
|
||||
{
|
||||
temp += (char)(_pSrc[offset] >> 8);
|
||||
offset ++;
|
||||
|
||||
if (offset >= _max)
|
||||
break;
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
bool
|
||||
CBannerLoaderWii::GetName(std::string& _rName, int language)
|
||||
{
|
||||
if (IsValid())
|
||||
{
|
||||
SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile;
|
||||
|
||||
// very stupid
|
||||
_rName = StupidWideCharToString(pBanner->m_Comment[0], WII_BANNER_COMMENT_SIZE);
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CBannerLoaderWii::GetCompany(std::string& _rCompany)
|
||||
{
|
||||
_rCompany = "N/A";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CBannerLoaderWii::GetDescription(std::string& _rDescription)
|
||||
{
|
||||
if (IsValid())
|
||||
{
|
||||
SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile;
|
||||
|
||||
// very stupid
|
||||
_rDescription = StupidWideCharToString(pBanner->m_Comment[1], WII_BANNER_COMMENT_SIZE);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CBannerLoaderWii::InitLUTTable()
|
||||
{
|
||||
// build LUT Table
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
lut3to8[i] = (i * 255) / 7;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
lut4to8[i] = (i * 255) / 15;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
lut5to8[i] = (i * 255) / 31;
|
||||
}
|
||||
}
|
||||
|
||||
u32
|
||||
CBannerLoaderWii::decode5A3(u16 val)
|
||||
{
|
||||
u32 bannerBGColor = 0x00000000;
|
||||
|
||||
int r, g, b, a;
|
||||
|
||||
if ((val & 0x8000))
|
||||
{
|
||||
r = lut5to8[(val >> 10) & 0x1f];
|
||||
g = lut5to8[(val >> 5) & 0x1f];
|
||||
b = lut5to8[(val) & 0x1f];
|
||||
a = 0xFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
a = lut3to8[(val >> 12) & 0x7];
|
||||
r = (lut4to8[(val >> 8) & 0xf] * a + (bannerBGColor & 0xFF) * (255 - a)) / 255;
|
||||
g = (lut4to8[(val >> 4) & 0xf] * a + ((bannerBGColor >> 8) & 0xFF) * (255 - a)) / 255;
|
||||
b = (lut4to8[(val) & 0xf] * a + ((bannerBGColor >> 16) & 0xFF) * (255 - a)) / 255;
|
||||
a = 0xFF;
|
||||
}
|
||||
|
||||
return ((a << 24) | (r << 16) | (g << 8) | b);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CBannerLoaderWii::decode5A3image(u32* dst, u16* src, int width, int height)
|
||||
{
|
||||
for (int y = 0; y < height; y += 4)
|
||||
{
|
||||
for (int x = 0; x < width; x += 4)
|
||||
{
|
||||
for (int iy = 0; iy < 4; iy++, src += 4)
|
||||
{
|
||||
for (int ix = 0; ix < 4; ix++)
|
||||
{
|
||||
u32 RGBA = decode5A3(Common::swap16(src[ix]));
|
||||
dst[(y + iy) * width + (x + ix)] = RGBA;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// 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, version 2.0.
|
||||
|
||||
// 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 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "Common.h"
|
||||
#include "BannerLoaderWii.h"
|
||||
#include "FileUtil.h"
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
CBannerLoaderWii::CBannerLoaderWii(DiscIO::IFileSystem& _rFileSystem)
|
||||
: m_pBannerFile(NULL)
|
||||
, m_IsValid(false)
|
||||
{
|
||||
InitLUTTable();
|
||||
|
||||
char Filename[260];
|
||||
char TitleID[4];
|
||||
|
||||
_rFileSystem.GetVolume()->Read(0, 4, (u8*)TitleID);
|
||||
sprintf(Filename, FULL_WII_USER_DIR "title/00010000/%02x%02x%02x%02x/data/banner.bin", (u8)TitleID[0], (u8)TitleID[1], (u8)TitleID[2], (u8)TitleID[3]);
|
||||
|
||||
// load the opening.bnr
|
||||
size_t FileSize = File::GetSize(Filename);
|
||||
|
||||
if (FileSize > 0)
|
||||
{
|
||||
m_pBannerFile = new u8[FileSize];
|
||||
FILE* pFile = fopen(Filename, "rb");
|
||||
if (pFile != NULL)
|
||||
{
|
||||
fread(m_pBannerFile, FileSize, 1, pFile);
|
||||
fclose(pFile);
|
||||
m_IsValid = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CBannerLoaderWii::~CBannerLoaderWii()
|
||||
{
|
||||
if (m_pBannerFile)
|
||||
{
|
||||
delete [] m_pBannerFile;
|
||||
m_pBannerFile = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CBannerLoaderWii::IsValid()
|
||||
{
|
||||
return (m_IsValid);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CBannerLoaderWii::GetBanner(u32* _pBannerImage)
|
||||
{
|
||||
if (!IsValid())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile;
|
||||
|
||||
static u32 Buffer[192 * 64];
|
||||
decode5A3image(Buffer, (u16*)pBanner->m_BannerTexture, 192, 64);
|
||||
|
||||
// ugly scaling :)
|
||||
for (int y=0; y<32; y++)
|
||||
{
|
||||
for (int x=0; x<96; x++)
|
||||
{
|
||||
_pBannerImage[y*96+x] = Buffer[(y*192*2)+(x*2)];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string
|
||||
CBannerLoaderWii::StupidWideCharToString(u16* _pSrc, size_t _max)
|
||||
{
|
||||
std::string temp;
|
||||
|
||||
u32 offset = 0;
|
||||
while (_pSrc[offset] != 0x0000)
|
||||
{
|
||||
temp += (char)(_pSrc[offset] >> 8);
|
||||
offset ++;
|
||||
|
||||
if (offset >= _max)
|
||||
break;
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
bool
|
||||
CBannerLoaderWii::GetName(std::string& _rName, int language)
|
||||
{
|
||||
if (IsValid())
|
||||
{
|
||||
SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile;
|
||||
|
||||
// very stupid
|
||||
_rName = StupidWideCharToString(pBanner->m_Comment[0], WII_BANNER_COMMENT_SIZE);
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CBannerLoaderWii::GetCompany(std::string& _rCompany)
|
||||
{
|
||||
_rCompany = "N/A";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CBannerLoaderWii::GetDescription(std::string& _rDescription)
|
||||
{
|
||||
if (IsValid())
|
||||
{
|
||||
SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile;
|
||||
|
||||
// very stupid
|
||||
_rDescription = StupidWideCharToString(pBanner->m_Comment[1], WII_BANNER_COMMENT_SIZE);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CBannerLoaderWii::InitLUTTable()
|
||||
{
|
||||
// build LUT Table
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
lut3to8[i] = (i * 255) / 7;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
lut4to8[i] = (i * 255) / 15;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
lut5to8[i] = (i * 255) / 31;
|
||||
}
|
||||
}
|
||||
|
||||
u32
|
||||
CBannerLoaderWii::decode5A3(u16 val)
|
||||
{
|
||||
u32 bannerBGColor = 0x00000000;
|
||||
|
||||
int r, g, b, a;
|
||||
|
||||
if ((val & 0x8000))
|
||||
{
|
||||
r = lut5to8[(val >> 10) & 0x1f];
|
||||
g = lut5to8[(val >> 5) & 0x1f];
|
||||
b = lut5to8[(val) & 0x1f];
|
||||
a = 0xFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
a = lut3to8[(val >> 12) & 0x7];
|
||||
r = (lut4to8[(val >> 8) & 0xf] * a + (bannerBGColor & 0xFF) * (255 - a)) / 255;
|
||||
g = (lut4to8[(val >> 4) & 0xf] * a + ((bannerBGColor >> 8) & 0xFF) * (255 - a)) / 255;
|
||||
b = (lut4to8[(val) & 0xf] * a + ((bannerBGColor >> 16) & 0xFF) * (255 - a)) / 255;
|
||||
a = 0xFF;
|
||||
}
|
||||
|
||||
return ((a << 24) | (r << 16) | (g << 8) | b);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CBannerLoaderWii::decode5A3image(u32* dst, u16* src, int width, int height)
|
||||
{
|
||||
for (int y = 0; y < height; y += 4)
|
||||
{
|
||||
for (int x = 0; x < width; x += 4)
|
||||
{
|
||||
for (int iy = 0; iy < 4; iy++, src += 4)
|
||||
{
|
||||
for (int ix = 0; ix < 4; ix++)
|
||||
{
|
||||
u32 RGBA = decode5A3(Common::swap16(src[ix]));
|
||||
dst[(y + iy) * width + (x + ix)] = RGBA;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
+110
-110
@@ -1,110 +1,110 @@
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// 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, version 2.0.
|
||||
|
||||
// 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 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "Common.h"
|
||||
#include "FileUtil.h"
|
||||
#include "Blob.h"
|
||||
#include "CompressedBlob.h"
|
||||
#include "FileBlob.h"
|
||||
#include "DriveBlob.h"
|
||||
#include "MappedFile.h"
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
|
||||
// Provides caching and split-operation-to-block-operations facilities.
|
||||
// Used for compressed blob reading and direct drive reading.
|
||||
|
||||
void SectorReader::SetSectorSize(int blocksize)
|
||||
{
|
||||
for (int i = 0; i < CACHE_SIZE; i++)
|
||||
{
|
||||
cache[i] = new u8[blocksize];
|
||||
cache_tags[i] = (u64)(s64) - 1;
|
||||
}
|
||||
m_blocksize = blocksize;
|
||||
}
|
||||
|
||||
SectorReader::~SectorReader() {
|
||||
for (int i = 0; i < CACHE_SIZE; i++)
|
||||
delete[] cache[i];
|
||||
}
|
||||
|
||||
const u8 *SectorReader::GetBlockData(u64 block_num)
|
||||
{
|
||||
if (cache_tags[0] == block_num)
|
||||
{
|
||||
return cache[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
GetBlock(block_num, cache[0]);
|
||||
cache_tags[0] = block_num;
|
||||
return cache[0];
|
||||
}
|
||||
}
|
||||
|
||||
bool SectorReader::Read(u64 offset, u64 size, u8* out_ptr)
|
||||
{
|
||||
u64 startingBlock = offset / m_blocksize;
|
||||
u64 remain = size;
|
||||
|
||||
int positionInBlock = (int)(offset % m_blocksize);
|
||||
u64 block = startingBlock;
|
||||
|
||||
while (remain > 0)
|
||||
{
|
||||
const u8* data = GetBlockData(block);
|
||||
if (!data)
|
||||
return false;
|
||||
|
||||
u32 toCopy = m_blocksize - positionInBlock;
|
||||
if (toCopy >= remain)
|
||||
{
|
||||
// yay, we are done!
|
||||
memcpy(out_ptr, data + positionInBlock, (size_t)remain);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(out_ptr, data + positionInBlock, toCopy);
|
||||
out_ptr += toCopy;
|
||||
remain -= toCopy;
|
||||
positionInBlock = 0;
|
||||
block++;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
IBlobReader* CreateBlobReader(const char* filename)
|
||||
{
|
||||
//if (strlen(filename) < 4 && filename[1] == ':') // Drive, for sure.
|
||||
// return DriveReader::Create(filename);
|
||||
|
||||
if (!File::Exists(filename))
|
||||
return 0;
|
||||
|
||||
if (IsCompressedBlob(filename))
|
||||
return CompressedBlobReader::Create(filename);
|
||||
|
||||
// Still here? Assume plain file.
|
||||
return PlainFileReader::Create(filename);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// 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, version 2.0.
|
||||
|
||||
// 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 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "Common.h"
|
||||
#include "FileUtil.h"
|
||||
#include "Blob.h"
|
||||
#include "CompressedBlob.h"
|
||||
#include "FileBlob.h"
|
||||
#include "DriveBlob.h"
|
||||
#include "MappedFile.h"
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
|
||||
// Provides caching and split-operation-to-block-operations facilities.
|
||||
// Used for compressed blob reading and direct drive reading.
|
||||
|
||||
void SectorReader::SetSectorSize(int blocksize)
|
||||
{
|
||||
for (int i = 0; i < CACHE_SIZE; i++)
|
||||
{
|
||||
cache[i] = new u8[blocksize];
|
||||
cache_tags[i] = (u64)(s64) - 1;
|
||||
}
|
||||
m_blocksize = blocksize;
|
||||
}
|
||||
|
||||
SectorReader::~SectorReader() {
|
||||
for (int i = 0; i < CACHE_SIZE; i++)
|
||||
delete[] cache[i];
|
||||
}
|
||||
|
||||
const u8 *SectorReader::GetBlockData(u64 block_num)
|
||||
{
|
||||
if (cache_tags[0] == block_num)
|
||||
{
|
||||
return cache[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
GetBlock(block_num, cache[0]);
|
||||
cache_tags[0] = block_num;
|
||||
return cache[0];
|
||||
}
|
||||
}
|
||||
|
||||
bool SectorReader::Read(u64 offset, u64 size, u8* out_ptr)
|
||||
{
|
||||
u64 startingBlock = offset / m_blocksize;
|
||||
u64 remain = size;
|
||||
|
||||
int positionInBlock = (int)(offset % m_blocksize);
|
||||
u64 block = startingBlock;
|
||||
|
||||
while (remain > 0)
|
||||
{
|
||||
const u8* data = GetBlockData(block);
|
||||
if (!data)
|
||||
return false;
|
||||
|
||||
u32 toCopy = m_blocksize - positionInBlock;
|
||||
if (toCopy >= remain)
|
||||
{
|
||||
// yay, we are done!
|
||||
memcpy(out_ptr, data + positionInBlock, (size_t)remain);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(out_ptr, data + positionInBlock, toCopy);
|
||||
out_ptr += toCopy;
|
||||
remain -= toCopy;
|
||||
positionInBlock = 0;
|
||||
block++;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
IBlobReader* CreateBlobReader(const char* filename)
|
||||
{
|
||||
//if (strlen(filename) < 4 && filename[1] == ':') // Drive, for sure.
|
||||
// return DriveReader::Create(filename);
|
||||
|
||||
if (!File::Exists(filename))
|
||||
return 0;
|
||||
|
||||
if (IsCompressedBlob(filename))
|
||||
return CompressedBlobReader::Create(filename);
|
||||
|
||||
// Still here? Assume plain file.
|
||||
return PlainFileReader::Create(filename);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,25 +1,25 @@
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// 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, version 2.0.
|
||||
|
||||
// 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 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "DriveBlob.h"
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
|
||||
} // namespace
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// 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, version 2.0.
|
||||
|
||||
// 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 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "DriveBlob.h"
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
|
||||
} // namespace
|
||||
|
||||
+110
-110
@@ -1,110 +1,110 @@
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// 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, version 2.0.
|
||||
|
||||
// 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 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "Blob.h"
|
||||
#include "FileBlob.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
PlainFileReader::PlainFileReader(HANDLE hFile_)
|
||||
{
|
||||
hFile = hFile_;
|
||||
DWORD size_low, size_high;
|
||||
size_low = GetFileSize(hFile, &size_high);
|
||||
size = ((u64)size_low) | ((u64)size_high << 32);
|
||||
}
|
||||
|
||||
PlainFileReader* PlainFileReader::Create(const char* filename)
|
||||
{
|
||||
HANDLE hFile = CreateFile(
|
||||
filename, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL);
|
||||
if (hFile != INVALID_HANDLE_VALUE)
|
||||
return new PlainFileReader(hFile);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
PlainFileReader::~PlainFileReader()
|
||||
{
|
||||
CloseHandle(hFile);
|
||||
}
|
||||
|
||||
bool PlainFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr)
|
||||
{
|
||||
LONG offset_high = (LONG)(offset >> 32);
|
||||
SetFilePointer(hFile, (DWORD)(offset & 0xFFFFFFFF), &offset_high, FILE_BEGIN);
|
||||
|
||||
if (nbytes >= 0x100000000ULL)
|
||||
return false; // WTF, does windows really have this limitation?
|
||||
|
||||
DWORD unused = 0;
|
||||
if (!ReadFile(hFile, out_ptr, DWORD(nbytes & 0xFFFFFFFF), &unused, NULL))
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
#else // POSIX
|
||||
|
||||
PlainFileReader::PlainFileReader(FILE* file__)
|
||||
{
|
||||
file_ = file__;
|
||||
#if 0
|
||||
fseek64(file_, 0, SEEK_END);
|
||||
#else
|
||||
fseek(file_, 0, SEEK_END); // I don't have fseek64 with gcc 4.3
|
||||
#endif
|
||||
size = ftell(file_);
|
||||
fseek(file_, 0, SEEK_SET);
|
||||
}
|
||||
|
||||
PlainFileReader* PlainFileReader::Create(const char* filename)
|
||||
{
|
||||
FILE* file_ = fopen(filename, "rb");
|
||||
if (file_)
|
||||
return new PlainFileReader(file_);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
PlainFileReader::~PlainFileReader()
|
||||
{
|
||||
fclose(file_);
|
||||
}
|
||||
|
||||
bool PlainFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr)
|
||||
{
|
||||
int seekStatus = fseek(file_, offset, SEEK_SET);
|
||||
if (seekStatus != 0)
|
||||
return false;
|
||||
size_t bytesRead = fread(out_ptr, 1, nbytes, file_);
|
||||
return bytesRead == nbytes;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// 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, version 2.0.
|
||||
|
||||
// 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 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "Blob.h"
|
||||
#include "FileBlob.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
PlainFileReader::PlainFileReader(HANDLE hFile_)
|
||||
{
|
||||
hFile = hFile_;
|
||||
DWORD size_low, size_high;
|
||||
size_low = GetFileSize(hFile, &size_high);
|
||||
size = ((u64)size_low) | ((u64)size_high << 32);
|
||||
}
|
||||
|
||||
PlainFileReader* PlainFileReader::Create(const char* filename)
|
||||
{
|
||||
HANDLE hFile = CreateFile(
|
||||
filename, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL);
|
||||
if (hFile != INVALID_HANDLE_VALUE)
|
||||
return new PlainFileReader(hFile);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
PlainFileReader::~PlainFileReader()
|
||||
{
|
||||
CloseHandle(hFile);
|
||||
}
|
||||
|
||||
bool PlainFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr)
|
||||
{
|
||||
LONG offset_high = (LONG)(offset >> 32);
|
||||
SetFilePointer(hFile, (DWORD)(offset & 0xFFFFFFFF), &offset_high, FILE_BEGIN);
|
||||
|
||||
if (nbytes >= 0x100000000ULL)
|
||||
return false; // WTF, does windows really have this limitation?
|
||||
|
||||
DWORD unused = 0;
|
||||
if (!ReadFile(hFile, out_ptr, DWORD(nbytes & 0xFFFFFFFF), &unused, NULL))
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
#else // POSIX
|
||||
|
||||
PlainFileReader::PlainFileReader(FILE* file__)
|
||||
{
|
||||
file_ = file__;
|
||||
#if 0
|
||||
fseek64(file_, 0, SEEK_END);
|
||||
#else
|
||||
fseek(file_, 0, SEEK_END); // I don't have fseek64 with gcc 4.3
|
||||
#endif
|
||||
size = ftell(file_);
|
||||
fseek(file_, 0, SEEK_SET);
|
||||
}
|
||||
|
||||
PlainFileReader* PlainFileReader::Create(const char* filename)
|
||||
{
|
||||
FILE* file_ = fopen(filename, "rb");
|
||||
if (file_)
|
||||
return new PlainFileReader(file_);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
PlainFileReader::~PlainFileReader()
|
||||
{
|
||||
fclose(file_);
|
||||
}
|
||||
|
||||
bool PlainFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr)
|
||||
{
|
||||
int seekStatus = fseek(file_, offset, SEEK_SET);
|
||||
if (seekStatus != 0)
|
||||
return false;
|
||||
size_t bytesRead = fread(out_ptr, 1, nbytes, file_);
|
||||
return bytesRead == nbytes;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -1,237 +1,237 @@
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// 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, version 2.0.
|
||||
|
||||
// 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 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "Common.h"
|
||||
|
||||
#include "FileHandlerARC.h"
|
||||
#include "StringUtil.h"
|
||||
|
||||
|
||||
#define ARC_ID 0x55aa382d
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
CARCFile::CARCFile(const u8* _pBuffer, size_t _BufferSize)
|
||||
: m_pBuffer(NULL),
|
||||
m_Initialized(false)
|
||||
{
|
||||
m_pBuffer = new u8[_BufferSize];
|
||||
|
||||
if (m_pBuffer)
|
||||
{
|
||||
memcpy(m_pBuffer, _pBuffer, _BufferSize);
|
||||
m_Initialized = ParseBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CARCFile::~CARCFile()
|
||||
{
|
||||
delete [] m_pBuffer;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CARCFile::IsInitialized()
|
||||
{
|
||||
return(m_Initialized);
|
||||
}
|
||||
|
||||
|
||||
size_t
|
||||
CARCFile::GetFileSize(const std::string& _rFullPath)
|
||||
{
|
||||
if (!m_Initialized)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
const SFileInfo* pFileInfo = FindFileInfo(_rFullPath);
|
||||
|
||||
if (pFileInfo != NULL)
|
||||
{
|
||||
return(pFileInfo->m_FileSize);
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
size_t
|
||||
CARCFile::ReadFile(const std::string& _rFullPath, u8* _pBuffer, size_t _MaxBufferSize)
|
||||
{
|
||||
if (!m_Initialized)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
const SFileInfo* pFileInfo = FindFileInfo(_rFullPath);
|
||||
|
||||
if (pFileInfo == NULL)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
if (pFileInfo->m_FileSize > _MaxBufferSize)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
memcpy(_pBuffer, &m_pBuffer[pFileInfo->m_Offset], pFileInfo->m_FileSize);
|
||||
return(pFileInfo->m_FileSize);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CARCFile::ExportFile(const std::string& _rFullPath, const std::string& _rExportFilename)
|
||||
{
|
||||
if (!m_Initialized)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
const SFileInfo* pFileInfo = FindFileInfo(_rFullPath);
|
||||
|
||||
if (pFileInfo == NULL)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
FILE* pFile = fopen(_rExportFilename.c_str(), "wb");
|
||||
|
||||
if (pFile == NULL)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
fwrite(&m_pBuffer[pFileInfo->m_Offset], pFileInfo->m_FileSize, 1, pFile);
|
||||
fclose(pFile);
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CARCFile::ExportAllFiles(const std::string& _rFullPath)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CARCFile::ParseBuffer()
|
||||
{
|
||||
// check ID
|
||||
u32 ID = Common::swap32(*(u32*)(m_pBuffer));
|
||||
|
||||
if (ID != ARC_ID)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
// read header
|
||||
u32 FSTOffset = Common::swap32(*(u32*)(m_pBuffer + 0x4));
|
||||
//u32 FSTSize = Common::swap32(*(u32*)(m_pBuffer + 0x8));
|
||||
//u32 FileOffset = Common::swap32(*(u32*)(m_pBuffer + 0xC));
|
||||
|
||||
// read all file infos
|
||||
SFileInfo Root;
|
||||
Root.m_NameOffset = Common::swap32(*(u32*)(m_pBuffer + FSTOffset + 0x0));
|
||||
Root.m_Offset = Common::swap32(*(u32*)(m_pBuffer + FSTOffset + 0x4));
|
||||
Root.m_FileSize = Common::swap32(*(u32*)(m_pBuffer + FSTOffset + 0x8));
|
||||
|
||||
if (Root.IsDirectory())
|
||||
{
|
||||
m_FileInfoVector.resize(Root.m_FileSize);
|
||||
const char* szNameTable = (char*)(m_pBuffer + FSTOffset);
|
||||
|
||||
for (size_t i = 0; i < m_FileInfoVector.size(); i++)
|
||||
{
|
||||
u8* Offset = m_pBuffer + FSTOffset + (i * 0xC);
|
||||
m_FileInfoVector[i].m_NameOffset = Common::swap32(*(u32*)(Offset + 0x0));
|
||||
m_FileInfoVector[i].m_Offset = Common::swap32(*(u32*)(Offset + 0x4));
|
||||
m_FileInfoVector[i].m_FileSize = Common::swap32(*(u32*)(Offset + 0x8));
|
||||
|
||||
szNameTable += 0xC;
|
||||
}
|
||||
|
||||
BuildFilenames(1, m_FileInfoVector.size(), NULL, szNameTable);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
size_t
|
||||
CARCFile::BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const char* _szDirectory, const char* _szNameTable)
|
||||
{
|
||||
size_t CurrentIndex = _FirstIndex;
|
||||
|
||||
while (CurrentIndex < _LastIndex)
|
||||
{
|
||||
SFileInfo& rFileInfo = m_FileInfoVector[CurrentIndex];
|
||||
int uOffset = rFileInfo.m_NameOffset & 0xFFFFFF;
|
||||
|
||||
// check next index
|
||||
if (rFileInfo.IsDirectory())
|
||||
{
|
||||
// this is a directory, build up the new szDirectory
|
||||
if (_szDirectory != NULL)
|
||||
{
|
||||
sprintf(rFileInfo.m_FullPath, "%s%s\\", _szDirectory, &_szNameTable[uOffset]);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(rFileInfo.m_FullPath, "%s\\", &_szNameTable[uOffset]);
|
||||
}
|
||||
|
||||
CurrentIndex = BuildFilenames(CurrentIndex + 1, rFileInfo.m_FileSize, rFileInfo.m_FullPath, _szNameTable);
|
||||
}
|
||||
else
|
||||
{
|
||||
// this is a filename
|
||||
if (_szDirectory != NULL)
|
||||
{
|
||||
sprintf(rFileInfo.m_FullPath, "%s%s", _szDirectory, &_szNameTable[uOffset]);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(rFileInfo.m_FullPath, "%s", &_szNameTable[uOffset]);
|
||||
}
|
||||
|
||||
CurrentIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
return(CurrentIndex);
|
||||
}
|
||||
|
||||
|
||||
const SFileInfo*
|
||||
CARCFile::FindFileInfo(std::string _rFullPath) const
|
||||
{
|
||||
for (size_t i = 0; i < m_FileInfoVector.size(); i++)
|
||||
{
|
||||
if (!strcasecmp(m_FileInfoVector[i].m_FullPath, _rFullPath.c_str()))
|
||||
{
|
||||
return(&m_FileInfoVector[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
} // namespace
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// 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, version 2.0.
|
||||
|
||||
// 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 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "Common.h"
|
||||
|
||||
#include "FileHandlerARC.h"
|
||||
#include "StringUtil.h"
|
||||
|
||||
|
||||
#define ARC_ID 0x55aa382d
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
CARCFile::CARCFile(const u8* _pBuffer, size_t _BufferSize)
|
||||
: m_pBuffer(NULL),
|
||||
m_Initialized(false)
|
||||
{
|
||||
m_pBuffer = new u8[_BufferSize];
|
||||
|
||||
if (m_pBuffer)
|
||||
{
|
||||
memcpy(m_pBuffer, _pBuffer, _BufferSize);
|
||||
m_Initialized = ParseBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CARCFile::~CARCFile()
|
||||
{
|
||||
delete [] m_pBuffer;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CARCFile::IsInitialized()
|
||||
{
|
||||
return(m_Initialized);
|
||||
}
|
||||
|
||||
|
||||
size_t
|
||||
CARCFile::GetFileSize(const std::string& _rFullPath)
|
||||
{
|
||||
if (!m_Initialized)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
const SFileInfo* pFileInfo = FindFileInfo(_rFullPath);
|
||||
|
||||
if (pFileInfo != NULL)
|
||||
{
|
||||
return(pFileInfo->m_FileSize);
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
size_t
|
||||
CARCFile::ReadFile(const std::string& _rFullPath, u8* _pBuffer, size_t _MaxBufferSize)
|
||||
{
|
||||
if (!m_Initialized)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
const SFileInfo* pFileInfo = FindFileInfo(_rFullPath);
|
||||
|
||||
if (pFileInfo == NULL)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
if (pFileInfo->m_FileSize > _MaxBufferSize)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
memcpy(_pBuffer, &m_pBuffer[pFileInfo->m_Offset], pFileInfo->m_FileSize);
|
||||
return(pFileInfo->m_FileSize);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CARCFile::ExportFile(const std::string& _rFullPath, const std::string& _rExportFilename)
|
||||
{
|
||||
if (!m_Initialized)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
const SFileInfo* pFileInfo = FindFileInfo(_rFullPath);
|
||||
|
||||
if (pFileInfo == NULL)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
FILE* pFile = fopen(_rExportFilename.c_str(), "wb");
|
||||
|
||||
if (pFile == NULL)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
fwrite(&m_pBuffer[pFileInfo->m_Offset], pFileInfo->m_FileSize, 1, pFile);
|
||||
fclose(pFile);
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CARCFile::ExportAllFiles(const std::string& _rFullPath)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CARCFile::ParseBuffer()
|
||||
{
|
||||
// check ID
|
||||
u32 ID = Common::swap32(*(u32*)(m_pBuffer));
|
||||
|
||||
if (ID != ARC_ID)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
// read header
|
||||
u32 FSTOffset = Common::swap32(*(u32*)(m_pBuffer + 0x4));
|
||||
//u32 FSTSize = Common::swap32(*(u32*)(m_pBuffer + 0x8));
|
||||
//u32 FileOffset = Common::swap32(*(u32*)(m_pBuffer + 0xC));
|
||||
|
||||
// read all file infos
|
||||
SFileInfo Root;
|
||||
Root.m_NameOffset = Common::swap32(*(u32*)(m_pBuffer + FSTOffset + 0x0));
|
||||
Root.m_Offset = Common::swap32(*(u32*)(m_pBuffer + FSTOffset + 0x4));
|
||||
Root.m_FileSize = Common::swap32(*(u32*)(m_pBuffer + FSTOffset + 0x8));
|
||||
|
||||
if (Root.IsDirectory())
|
||||
{
|
||||
m_FileInfoVector.resize(Root.m_FileSize);
|
||||
const char* szNameTable = (char*)(m_pBuffer + FSTOffset);
|
||||
|
||||
for (size_t i = 0; i < m_FileInfoVector.size(); i++)
|
||||
{
|
||||
u8* Offset = m_pBuffer + FSTOffset + (i * 0xC);
|
||||
m_FileInfoVector[i].m_NameOffset = Common::swap32(*(u32*)(Offset + 0x0));
|
||||
m_FileInfoVector[i].m_Offset = Common::swap32(*(u32*)(Offset + 0x4));
|
||||
m_FileInfoVector[i].m_FileSize = Common::swap32(*(u32*)(Offset + 0x8));
|
||||
|
||||
szNameTable += 0xC;
|
||||
}
|
||||
|
||||
BuildFilenames(1, m_FileInfoVector.size(), NULL, szNameTable);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
size_t
|
||||
CARCFile::BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const char* _szDirectory, const char* _szNameTable)
|
||||
{
|
||||
size_t CurrentIndex = _FirstIndex;
|
||||
|
||||
while (CurrentIndex < _LastIndex)
|
||||
{
|
||||
SFileInfo& rFileInfo = m_FileInfoVector[CurrentIndex];
|
||||
int uOffset = rFileInfo.m_NameOffset & 0xFFFFFF;
|
||||
|
||||
// check next index
|
||||
if (rFileInfo.IsDirectory())
|
||||
{
|
||||
// this is a directory, build up the new szDirectory
|
||||
if (_szDirectory != NULL)
|
||||
{
|
||||
sprintf(rFileInfo.m_FullPath, "%s%s\\", _szDirectory, &_szNameTable[uOffset]);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(rFileInfo.m_FullPath, "%s\\", &_szNameTable[uOffset]);
|
||||
}
|
||||
|
||||
CurrentIndex = BuildFilenames(CurrentIndex + 1, rFileInfo.m_FileSize, rFileInfo.m_FullPath, _szNameTable);
|
||||
}
|
||||
else
|
||||
{
|
||||
// this is a filename
|
||||
if (_szDirectory != NULL)
|
||||
{
|
||||
sprintf(rFileInfo.m_FullPath, "%s%s", _szDirectory, &_szNameTable[uOffset]);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(rFileInfo.m_FullPath, "%s", &_szNameTable[uOffset]);
|
||||
}
|
||||
|
||||
CurrentIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
return(CurrentIndex);
|
||||
}
|
||||
|
||||
|
||||
const SFileInfo*
|
||||
CARCFile::FindFileInfo(std::string _rFullPath) const
|
||||
{
|
||||
for (size_t i = 0; i < m_FileInfoVector.size(); i++)
|
||||
{
|
||||
if (!strcasecmp(m_FileInfoVector[i].m_FullPath, _rFullPath.c_str()))
|
||||
{
|
||||
return(&m_FileInfoVector[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -1,249 +1,249 @@
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// 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, version 2.0.
|
||||
|
||||
// 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 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "Common.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "FileSystemGCWii.h"
|
||||
#include "StringUtil.h"
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
CFileSystemGCWii::CFileSystemGCWii(const IVolume *_rVolume)
|
||||
: IFileSystem(_rVolume),
|
||||
m_Initialized(false),
|
||||
m_OffsetShift(0)
|
||||
{
|
||||
m_Initialized = InitFileSystem();
|
||||
}
|
||||
|
||||
|
||||
CFileSystemGCWii::~CFileSystemGCWii()
|
||||
{
|
||||
}
|
||||
|
||||
bool CFileSystemGCWii::IsInitialized() const
|
||||
{
|
||||
return m_Initialized;
|
||||
}
|
||||
|
||||
u64 CFileSystemGCWii::GetFileSize(const char* _rFullPath) const
|
||||
{
|
||||
if (!m_Initialized)
|
||||
return 0;
|
||||
|
||||
const SFileInfo* pFileInfo = FindFileInfo(_rFullPath);
|
||||
|
||||
if (pFileInfo != NULL)
|
||||
return pFileInfo->m_FileSize;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char* CFileSystemGCWii::GetFileName(u64 _Address) const
|
||||
{
|
||||
for (size_t i = 0; i < m_FileInfoVector.size(); i++)
|
||||
{
|
||||
if ((m_FileInfoVector[i].m_Offset <= _Address) &&
|
||||
((m_FileInfoVector[i].m_Offset + m_FileInfoVector[i].m_FileSize) > _Address))
|
||||
{
|
||||
return m_FileInfoVector[i].m_FullPath;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
u64 CFileSystemGCWii::ReadFile(const char* _rFullPath, u8* _pBuffer, size_t _MaxBufferSize) const
|
||||
{
|
||||
if (!m_Initialized)
|
||||
return 0;
|
||||
|
||||
const SFileInfo* pFileInfo = FindFileInfo(_rFullPath);
|
||||
if (pFileInfo == NULL)
|
||||
return 0;
|
||||
|
||||
if (pFileInfo->m_FileSize > _MaxBufferSize)
|
||||
return 0;
|
||||
|
||||
m_rVolume->Read(pFileInfo->m_Offset, pFileInfo->m_FileSize, _pBuffer);
|
||||
return pFileInfo->m_FileSize;
|
||||
}
|
||||
|
||||
bool CFileSystemGCWii::ExportFile(const char* _rFullPath, const char* _rExportFilename) const
|
||||
{
|
||||
size_t filesize = GetFileSize(_rFullPath);
|
||||
|
||||
if (filesize == 0)
|
||||
return false;
|
||||
|
||||
u8* buffer = new u8[filesize];
|
||||
|
||||
if (!ReadFile(_rFullPath, buffer, filesize))
|
||||
{
|
||||
delete[] buffer;
|
||||
return false;
|
||||
}
|
||||
|
||||
FILE* f = fopen(_rExportFilename, "wb");
|
||||
|
||||
if (f)
|
||||
{
|
||||
fwrite(buffer, filesize, 1, f);
|
||||
fclose(f);
|
||||
delete[] buffer;
|
||||
return true;
|
||||
}
|
||||
|
||||
delete[] buffer;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CFileSystemGCWii::ExportAllFiles(const char* _rFullPath) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
u32 CFileSystemGCWii::Read32(u64 _Offset) const
|
||||
{
|
||||
u32 Temp = 0;
|
||||
m_rVolume->Read(_Offset, 4, (u8*)&Temp);
|
||||
return Common::swap32(Temp);
|
||||
}
|
||||
|
||||
void CFileSystemGCWii::GetStringFromOffset(u64 _Offset, char* Filename) const
|
||||
{
|
||||
m_rVolume->Read(_Offset, 255, (u8*)Filename);
|
||||
}
|
||||
|
||||
size_t CFileSystemGCWii::GetFileList(std::vector<const SFileInfo *> &_rFilenames) const
|
||||
{
|
||||
if (_rFilenames.size())
|
||||
PanicAlert("GetFileList : input list has contents?");
|
||||
_rFilenames.clear();
|
||||
_rFilenames.reserve(m_FileInfoVector.size());
|
||||
for (size_t i = 0; i < m_FileInfoVector.size(); i++)
|
||||
_rFilenames.push_back(&m_FileInfoVector[i]);
|
||||
return m_FileInfoVector.size();
|
||||
}
|
||||
|
||||
const SFileInfo* CFileSystemGCWii::FindFileInfo(const char* _rFullPath) const
|
||||
{
|
||||
for (size_t i = 0; i < m_FileInfoVector.size(); i++)
|
||||
{
|
||||
if (!strcasecmp(m_FileInfoVector[i].m_FullPath, _rFullPath))
|
||||
return &m_FileInfoVector[i];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool CFileSystemGCWii::InitFileSystem()
|
||||
{
|
||||
if (Read32(0x18) == 0x5D1C9EA3)
|
||||
{
|
||||
m_OffsetShift = 2; // Wii file system
|
||||
}
|
||||
else if (Read32(0x1c) == 0xC2339F3D)
|
||||
{
|
||||
m_OffsetShift = 0; // GC file system
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// read the whole FST
|
||||
u64 FSTOffset = (u64)Read32(0x424) << m_OffsetShift;
|
||||
// u32 FSTSize = Read32(0x428);
|
||||
// u32 FSTMaxSize = Read32(0x42C);
|
||||
|
||||
|
||||
// read all fileinfos
|
||||
SFileInfo Root;
|
||||
Root.m_NameOffset = Read32(FSTOffset + 0x0);
|
||||
Root.m_Offset = (u64)Read32(FSTOffset + 0x4) << m_OffsetShift;
|
||||
Root.m_FileSize = Read32(FSTOffset + 0x8);
|
||||
|
||||
if (Root.IsDirectory())
|
||||
{
|
||||
if (m_FileInfoVector.size())
|
||||
PanicAlert("Wtf?");
|
||||
u64 NameTableOffset = FSTOffset;
|
||||
|
||||
m_FileInfoVector.reserve(Root.m_FileSize);
|
||||
for (u32 i = 0; i < Root.m_FileSize; i++)
|
||||
{
|
||||
SFileInfo sfi;
|
||||
u64 Offset = FSTOffset + (i * 0xC);
|
||||
sfi.m_NameOffset = Read32(Offset + 0x0);
|
||||
sfi.m_Offset = (u64)Read32(Offset + 0x4) << m_OffsetShift;
|
||||
sfi.m_FileSize = Read32(Offset + 0x8);
|
||||
|
||||
m_FileInfoVector.push_back(sfi);
|
||||
NameTableOffset += 0xC;
|
||||
}
|
||||
|
||||
BuildFilenames(1, m_FileInfoVector.size(), NULL, NameTableOffset);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Changed this stuff from C++ string to C strings for speed in debug mode. Doesn't matter in release, but
|
||||
// std::string is SLOW in debug mode.
|
||||
size_t CFileSystemGCWii::BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const char* _szDirectory, u64 _NameTableOffset)
|
||||
{
|
||||
size_t CurrentIndex = _FirstIndex;
|
||||
|
||||
while (CurrentIndex < _LastIndex)
|
||||
{
|
||||
SFileInfo *rFileInfo = &m_FileInfoVector[CurrentIndex];
|
||||
u64 uOffset = _NameTableOffset + (rFileInfo->m_NameOffset & 0xFFFFFF);
|
||||
char filename[512];
|
||||
memset(filename, 0, sizeof(filename));
|
||||
GetStringFromOffset(uOffset, filename);
|
||||
|
||||
// check next index
|
||||
if (rFileInfo->IsDirectory())
|
||||
{
|
||||
// this is a directory, build up the new szDirectory
|
||||
if (_szDirectory != NULL)
|
||||
CharArrayFromFormat(rFileInfo->m_FullPath, "%s%s\\", _szDirectory, filename);
|
||||
else
|
||||
CharArrayFromFormat(rFileInfo->m_FullPath, "%s\\", filename);
|
||||
|
||||
CurrentIndex = BuildFilenames(CurrentIndex + 1, rFileInfo->m_FileSize, rFileInfo->m_FullPath, _NameTableOffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
// this is a filename
|
||||
if (_szDirectory != NULL)
|
||||
CharArrayFromFormat(rFileInfo->m_FullPath, "%s%s", _szDirectory, filename);
|
||||
else
|
||||
CharArrayFromFormat(rFileInfo->m_FullPath, "%s", filename);
|
||||
|
||||
CurrentIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
return CurrentIndex;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// 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, version 2.0.
|
||||
|
||||
// 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 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "Common.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "FileSystemGCWii.h"
|
||||
#include "StringUtil.h"
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
CFileSystemGCWii::CFileSystemGCWii(const IVolume *_rVolume)
|
||||
: IFileSystem(_rVolume),
|
||||
m_Initialized(false),
|
||||
m_OffsetShift(0)
|
||||
{
|
||||
m_Initialized = InitFileSystem();
|
||||
}
|
||||
|
||||
|
||||
CFileSystemGCWii::~CFileSystemGCWii()
|
||||
{
|
||||
}
|
||||
|
||||
bool CFileSystemGCWii::IsInitialized() const
|
||||
{
|
||||
return m_Initialized;
|
||||
}
|
||||
|
||||
u64 CFileSystemGCWii::GetFileSize(const char* _rFullPath) const
|
||||
{
|
||||
if (!m_Initialized)
|
||||
return 0;
|
||||
|
||||
const SFileInfo* pFileInfo = FindFileInfo(_rFullPath);
|
||||
|
||||
if (pFileInfo != NULL)
|
||||
return pFileInfo->m_FileSize;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char* CFileSystemGCWii::GetFileName(u64 _Address) const
|
||||
{
|
||||
for (size_t i = 0; i < m_FileInfoVector.size(); i++)
|
||||
{
|
||||
if ((m_FileInfoVector[i].m_Offset <= _Address) &&
|
||||
((m_FileInfoVector[i].m_Offset + m_FileInfoVector[i].m_FileSize) > _Address))
|
||||
{
|
||||
return m_FileInfoVector[i].m_FullPath;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
u64 CFileSystemGCWii::ReadFile(const char* _rFullPath, u8* _pBuffer, size_t _MaxBufferSize) const
|
||||
{
|
||||
if (!m_Initialized)
|
||||
return 0;
|
||||
|
||||
const SFileInfo* pFileInfo = FindFileInfo(_rFullPath);
|
||||
if (pFileInfo == NULL)
|
||||
return 0;
|
||||
|
||||
if (pFileInfo->m_FileSize > _MaxBufferSize)
|
||||
return 0;
|
||||
|
||||
m_rVolume->Read(pFileInfo->m_Offset, pFileInfo->m_FileSize, _pBuffer);
|
||||
return pFileInfo->m_FileSize;
|
||||
}
|
||||
|
||||
bool CFileSystemGCWii::ExportFile(const char* _rFullPath, const char* _rExportFilename) const
|
||||
{
|
||||
size_t filesize = GetFileSize(_rFullPath);
|
||||
|
||||
if (filesize == 0)
|
||||
return false;
|
||||
|
||||
u8* buffer = new u8[filesize];
|
||||
|
||||
if (!ReadFile(_rFullPath, buffer, filesize))
|
||||
{
|
||||
delete[] buffer;
|
||||
return false;
|
||||
}
|
||||
|
||||
FILE* f = fopen(_rExportFilename, "wb");
|
||||
|
||||
if (f)
|
||||
{
|
||||
fwrite(buffer, filesize, 1, f);
|
||||
fclose(f);
|
||||
delete[] buffer;
|
||||
return true;
|
||||
}
|
||||
|
||||
delete[] buffer;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CFileSystemGCWii::ExportAllFiles(const char* _rFullPath) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
u32 CFileSystemGCWii::Read32(u64 _Offset) const
|
||||
{
|
||||
u32 Temp = 0;
|
||||
m_rVolume->Read(_Offset, 4, (u8*)&Temp);
|
||||
return Common::swap32(Temp);
|
||||
}
|
||||
|
||||
void CFileSystemGCWii::GetStringFromOffset(u64 _Offset, char* Filename) const
|
||||
{
|
||||
m_rVolume->Read(_Offset, 255, (u8*)Filename);
|
||||
}
|
||||
|
||||
size_t CFileSystemGCWii::GetFileList(std::vector<const SFileInfo *> &_rFilenames) const
|
||||
{
|
||||
if (_rFilenames.size())
|
||||
PanicAlert("GetFileList : input list has contents?");
|
||||
_rFilenames.clear();
|
||||
_rFilenames.reserve(m_FileInfoVector.size());
|
||||
for (size_t i = 0; i < m_FileInfoVector.size(); i++)
|
||||
_rFilenames.push_back(&m_FileInfoVector[i]);
|
||||
return m_FileInfoVector.size();
|
||||
}
|
||||
|
||||
const SFileInfo* CFileSystemGCWii::FindFileInfo(const char* _rFullPath) const
|
||||
{
|
||||
for (size_t i = 0; i < m_FileInfoVector.size(); i++)
|
||||
{
|
||||
if (!strcasecmp(m_FileInfoVector[i].m_FullPath, _rFullPath))
|
||||
return &m_FileInfoVector[i];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool CFileSystemGCWii::InitFileSystem()
|
||||
{
|
||||
if (Read32(0x18) == 0x5D1C9EA3)
|
||||
{
|
||||
m_OffsetShift = 2; // Wii file system
|
||||
}
|
||||
else if (Read32(0x1c) == 0xC2339F3D)
|
||||
{
|
||||
m_OffsetShift = 0; // GC file system
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// read the whole FST
|
||||
u64 FSTOffset = (u64)Read32(0x424) << m_OffsetShift;
|
||||
// u32 FSTSize = Read32(0x428);
|
||||
// u32 FSTMaxSize = Read32(0x42C);
|
||||
|
||||
|
||||
// read all fileinfos
|
||||
SFileInfo Root;
|
||||
Root.m_NameOffset = Read32(FSTOffset + 0x0);
|
||||
Root.m_Offset = (u64)Read32(FSTOffset + 0x4) << m_OffsetShift;
|
||||
Root.m_FileSize = Read32(FSTOffset + 0x8);
|
||||
|
||||
if (Root.IsDirectory())
|
||||
{
|
||||
if (m_FileInfoVector.size())
|
||||
PanicAlert("Wtf?");
|
||||
u64 NameTableOffset = FSTOffset;
|
||||
|
||||
m_FileInfoVector.reserve(Root.m_FileSize);
|
||||
for (u32 i = 0; i < Root.m_FileSize; i++)
|
||||
{
|
||||
SFileInfo sfi;
|
||||
u64 Offset = FSTOffset + (i * 0xC);
|
||||
sfi.m_NameOffset = Read32(Offset + 0x0);
|
||||
sfi.m_Offset = (u64)Read32(Offset + 0x4) << m_OffsetShift;
|
||||
sfi.m_FileSize = Read32(Offset + 0x8);
|
||||
|
||||
m_FileInfoVector.push_back(sfi);
|
||||
NameTableOffset += 0xC;
|
||||
}
|
||||
|
||||
BuildFilenames(1, m_FileInfoVector.size(), NULL, NameTableOffset);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Changed this stuff from C++ string to C strings for speed in debug mode. Doesn't matter in release, but
|
||||
// std::string is SLOW in debug mode.
|
||||
size_t CFileSystemGCWii::BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const char* _szDirectory, u64 _NameTableOffset)
|
||||
{
|
||||
size_t CurrentIndex = _FirstIndex;
|
||||
|
||||
while (CurrentIndex < _LastIndex)
|
||||
{
|
||||
SFileInfo *rFileInfo = &m_FileInfoVector[CurrentIndex];
|
||||
u64 uOffset = _NameTableOffset + (rFileInfo->m_NameOffset & 0xFFFFFF);
|
||||
char filename[512];
|
||||
memset(filename, 0, sizeof(filename));
|
||||
GetStringFromOffset(uOffset, filename);
|
||||
|
||||
// check next index
|
||||
if (rFileInfo->IsDirectory())
|
||||
{
|
||||
// this is a directory, build up the new szDirectory
|
||||
if (_szDirectory != NULL)
|
||||
CharArrayFromFormat(rFileInfo->m_FullPath, "%s%s\\", _szDirectory, filename);
|
||||
else
|
||||
CharArrayFromFormat(rFileInfo->m_FullPath, "%s\\", filename);
|
||||
|
||||
CurrentIndex = BuildFilenames(CurrentIndex + 1, rFileInfo->m_FileSize, rFileInfo->m_FullPath, _NameTableOffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
// this is a filename
|
||||
if (_szDirectory != NULL)
|
||||
CharArrayFromFormat(rFileInfo->m_FullPath, "%s%s", _szDirectory, filename);
|
||||
else
|
||||
CharArrayFromFormat(rFileInfo->m_FullPath, "%s", filename);
|
||||
|
||||
CurrentIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
return CurrentIndex;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -1,50 +1,50 @@
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// 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, version 2.0.
|
||||
|
||||
// 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 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "Filesystem.h"
|
||||
|
||||
#include "VolumeCreator.h"
|
||||
#include "FileSystemGCWii.h"
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
IFileSystem::IFileSystem(const IVolume *_rVolume)
|
||||
: m_rVolume(_rVolume)
|
||||
{}
|
||||
|
||||
|
||||
IFileSystem::~IFileSystem()
|
||||
{}
|
||||
|
||||
|
||||
IFileSystem* CreateFileSystem(const IVolume* _rVolume)
|
||||
{
|
||||
IFileSystem* pFileSystem = new CFileSystemGCWii(_rVolume);
|
||||
|
||||
if (!pFileSystem)
|
||||
return 0;
|
||||
|
||||
if (!pFileSystem->IsInitialized())
|
||||
{
|
||||
delete pFileSystem;
|
||||
pFileSystem = NULL;
|
||||
}
|
||||
|
||||
return pFileSystem;
|
||||
}
|
||||
} // namespace
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// 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, version 2.0.
|
||||
|
||||
// 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 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "Filesystem.h"
|
||||
|
||||
#include "VolumeCreator.h"
|
||||
#include "FileSystemGCWii.h"
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
IFileSystem::IFileSystem(const IVolume *_rVolume)
|
||||
: m_rVolume(_rVolume)
|
||||
{}
|
||||
|
||||
|
||||
IFileSystem::~IFileSystem()
|
||||
{}
|
||||
|
||||
|
||||
IFileSystem* CreateFileSystem(const IVolume* _rVolume)
|
||||
{
|
||||
IFileSystem* pFileSystem = new CFileSystemGCWii(_rVolume);
|
||||
|
||||
if (!pFileSystem)
|
||||
return 0;
|
||||
|
||||
if (!pFileSystem->IsInitialized())
|
||||
{
|
||||
delete pFileSystem;
|
||||
pFileSystem = NULL;
|
||||
}
|
||||
|
||||
return pFileSystem;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+169
-169
@@ -1,169 +1,169 @@
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// 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, version 2.0.
|
||||
|
||||
// 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 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "VolumeGC.h"
|
||||
#include "StringUtil.h"
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
CVolumeGC::CVolumeGC(IBlobReader* _pReader)
|
||||
: m_pReader(_pReader)
|
||||
{}
|
||||
|
||||
CVolumeGC::~CVolumeGC()
|
||||
{
|
||||
delete m_pReader;
|
||||
}
|
||||
|
||||
bool CVolumeGC::Read(u64 _Offset, u64 _Length, u8* _pBuffer) const
|
||||
{
|
||||
if (m_pReader == NULL)
|
||||
return false;
|
||||
return m_pReader->Read(_Offset, _Length, _pBuffer);
|
||||
}
|
||||
|
||||
std::string CVolumeGC::GetUniqueID() const
|
||||
{
|
||||
static const std::string NO_UID("NO_UID");
|
||||
if (m_pReader == NULL)
|
||||
return NO_UID;
|
||||
|
||||
char id[6];
|
||||
if (!Read(0, sizeof(id), reinterpret_cast<u8*>(id)))
|
||||
{
|
||||
PanicAlert("Failed to read unique ID from disc image");
|
||||
return NO_UID;
|
||||
}
|
||||
|
||||
return std::string(id, sizeof(id));
|
||||
}
|
||||
|
||||
IVolume::ECountry CVolumeGC::GetCountry() const
|
||||
{
|
||||
if (!m_pReader)
|
||||
return COUNTRY_UNKNOWN;
|
||||
|
||||
u8 CountryCode;
|
||||
m_pReader->Read(3, 1, &CountryCode);
|
||||
|
||||
ECountry country = COUNTRY_UNKNOWN;
|
||||
|
||||
switch (CountryCode)
|
||||
{
|
||||
case 'S':
|
||||
country = COUNTRY_EUROPE;
|
||||
break; // PAL // <- that is shitty :) zelda demo disc
|
||||
|
||||
case 'P':
|
||||
country = COUNTRY_EUROPE;
|
||||
break; // PAL
|
||||
|
||||
case 'D':
|
||||
country = COUNTRY_EUROPE;
|
||||
break; // PAL
|
||||
|
||||
case 'F':
|
||||
country = COUNTRY_FRANCE;
|
||||
break; // PAL
|
||||
|
||||
case 'X':
|
||||
country = COUNTRY_EUROPE;
|
||||
break; // XIII <- uses X but is PAL
|
||||
|
||||
case 'E':
|
||||
country = COUNTRY_USA;
|
||||
break; // USA
|
||||
|
||||
case 'J':
|
||||
country = COUNTRY_JAP;
|
||||
break; // JAP
|
||||
|
||||
case 'O':
|
||||
country = COUNTRY_UNKNOWN;
|
||||
break; // SDK
|
||||
|
||||
default:
|
||||
// PanicAlert(StringFromFormat("Unknown Country Code!").c_str());
|
||||
country = COUNTRY_UNKNOWN;
|
||||
break;
|
||||
}
|
||||
|
||||
return(country);
|
||||
}
|
||||
|
||||
std::string CVolumeGC::GetMakerID() const
|
||||
{
|
||||
if (m_pReader == NULL)
|
||||
return false;
|
||||
|
||||
char makerID[3];
|
||||
if (!Read(0x4, 0x2, (u8*)&makerID))
|
||||
return false;
|
||||
makerID[2] = 0;
|
||||
|
||||
return makerID;
|
||||
}
|
||||
|
||||
std::string CVolumeGC::GetName() const
|
||||
{
|
||||
if (m_pReader == NULL)
|
||||
return false;
|
||||
|
||||
char name[128];
|
||||
if (!Read(0x20, 0x60, (u8*)&name))
|
||||
return false;
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
u32 CVolumeGC::GetFSTSize() const
|
||||
{
|
||||
if (m_pReader == NULL)
|
||||
return false;
|
||||
|
||||
u32 size;
|
||||
if (!Read(0x428, 0x4, (u8*)&size))
|
||||
return false;
|
||||
|
||||
return Common::swap32(size);
|
||||
}
|
||||
|
||||
std::string CVolumeGC::GetApploaderDate() const
|
||||
{
|
||||
if (m_pReader == NULL)
|
||||
return false;
|
||||
|
||||
char date[16];
|
||||
if (!Read(0x2440, 0x10, (u8*)&date))
|
||||
return false;
|
||||
// Should be 0 already, but just in case
|
||||
date[10] = 0;
|
||||
|
||||
return date;
|
||||
}
|
||||
|
||||
u64 CVolumeGC::GetSize() const
|
||||
{
|
||||
if (m_pReader)
|
||||
return (size_t)m_pReader->GetDataSize();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// 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, version 2.0.
|
||||
|
||||
// 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 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "VolumeGC.h"
|
||||
#include "StringUtil.h"
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
CVolumeGC::CVolumeGC(IBlobReader* _pReader)
|
||||
: m_pReader(_pReader)
|
||||
{}
|
||||
|
||||
CVolumeGC::~CVolumeGC()
|
||||
{
|
||||
delete m_pReader;
|
||||
}
|
||||
|
||||
bool CVolumeGC::Read(u64 _Offset, u64 _Length, u8* _pBuffer) const
|
||||
{
|
||||
if (m_pReader == NULL)
|
||||
return false;
|
||||
return m_pReader->Read(_Offset, _Length, _pBuffer);
|
||||
}
|
||||
|
||||
std::string CVolumeGC::GetUniqueID() const
|
||||
{
|
||||
static const std::string NO_UID("NO_UID");
|
||||
if (m_pReader == NULL)
|
||||
return NO_UID;
|
||||
|
||||
char id[6];
|
||||
if (!Read(0, sizeof(id), reinterpret_cast<u8*>(id)))
|
||||
{
|
||||
PanicAlert("Failed to read unique ID from disc image");
|
||||
return NO_UID;
|
||||
}
|
||||
|
||||
return std::string(id, sizeof(id));
|
||||
}
|
||||
|
||||
IVolume::ECountry CVolumeGC::GetCountry() const
|
||||
{
|
||||
if (!m_pReader)
|
||||
return COUNTRY_UNKNOWN;
|
||||
|
||||
u8 CountryCode;
|
||||
m_pReader->Read(3, 1, &CountryCode);
|
||||
|
||||
ECountry country = COUNTRY_UNKNOWN;
|
||||
|
||||
switch (CountryCode)
|
||||
{
|
||||
case 'S':
|
||||
country = COUNTRY_EUROPE;
|
||||
break; // PAL // <- that is shitty :) zelda demo disc
|
||||
|
||||
case 'P':
|
||||
country = COUNTRY_EUROPE;
|
||||
break; // PAL
|
||||
|
||||
case 'D':
|
||||
country = COUNTRY_EUROPE;
|
||||
break; // PAL
|
||||
|
||||
case 'F':
|
||||
country = COUNTRY_FRANCE;
|
||||
break; // PAL
|
||||
|
||||
case 'X':
|
||||
country = COUNTRY_EUROPE;
|
||||
break; // XIII <- uses X but is PAL
|
||||
|
||||
case 'E':
|
||||
country = COUNTRY_USA;
|
||||
break; // USA
|
||||
|
||||
case 'J':
|
||||
country = COUNTRY_JAP;
|
||||
break; // JAP
|
||||
|
||||
case 'O':
|
||||
country = COUNTRY_UNKNOWN;
|
||||
break; // SDK
|
||||
|
||||
default:
|
||||
// PanicAlert(StringFromFormat("Unknown Country Code!").c_str());
|
||||
country = COUNTRY_UNKNOWN;
|
||||
break;
|
||||
}
|
||||
|
||||
return(country);
|
||||
}
|
||||
|
||||
std::string CVolumeGC::GetMakerID() const
|
||||
{
|
||||
if (m_pReader == NULL)
|
||||
return false;
|
||||
|
||||
char makerID[3];
|
||||
if (!Read(0x4, 0x2, (u8*)&makerID))
|
||||
return false;
|
||||
makerID[2] = 0;
|
||||
|
||||
return makerID;
|
||||
}
|
||||
|
||||
std::string CVolumeGC::GetName() const
|
||||
{
|
||||
if (m_pReader == NULL)
|
||||
return false;
|
||||
|
||||
char name[128];
|
||||
if (!Read(0x20, 0x60, (u8*)&name))
|
||||
return false;
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
u32 CVolumeGC::GetFSTSize() const
|
||||
{
|
||||
if (m_pReader == NULL)
|
||||
return false;
|
||||
|
||||
u32 size;
|
||||
if (!Read(0x428, 0x4, (u8*)&size))
|
||||
return false;
|
||||
|
||||
return Common::swap32(size);
|
||||
}
|
||||
|
||||
std::string CVolumeGC::GetApploaderDate() const
|
||||
{
|
||||
if (m_pReader == NULL)
|
||||
return false;
|
||||
|
||||
char date[16];
|
||||
if (!Read(0x2440, 0x10, (u8*)&date))
|
||||
return false;
|
||||
// Should be 0 already, but just in case
|
||||
date[10] = 0;
|
||||
|
||||
return date;
|
||||
}
|
||||
|
||||
u64 CVolumeGC::GetSize() const
|
||||
{
|
||||
if (m_pReader)
|
||||
return (size_t)m_pReader->GetDataSize();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,21 +1,21 @@
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// 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, version 2.0.
|
||||
|
||||
// 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 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// TODO: reference any additional headers you need in STDAFX.H
|
||||
// and not in this file
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// 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, version 2.0.
|
||||
|
||||
// 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 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// TODO: reference any additional headers you need in STDAFX.H
|
||||
// and not in this file
|
||||
|
||||
Reference in New Issue
Block a user