Added support to read game information from xml. The first draft of the xml is in the downloads section of googlecode. Put the file (still zipped) in your titles.txt path. then highlite a game and press 2 to view stuff about the game. If a synopsis exists for that game in the file, you can see it by pressing a. Currently only 1 game has a synopsis.
There are lots of fields that are wrong/missing on the xml but don't tell us about it. Somebody else (Lustar) will be in charge of keeping up with it.
4
Makefile
@ -17,7 +17,7 @@ include $(DEVKITPPC)/wii_rules
|
|||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
TARGET := boot
|
TARGET := boot
|
||||||
BUILD := build
|
BUILD := build
|
||||||
SOURCES := source source/libwiigui source/images source/fonts source/sounds source/libwbfs
|
SOURCES := source source/libwiigui source/images source/fonts source/sounds source/libwbfs source/unzip source/mxml
|
||||||
INCLUDES := source
|
INCLUDES := source
|
||||||
SVNDEV := -D'SVN_REV="$(shell svnversion -n ..)"'
|
SVNDEV := -D'SVN_REV="$(shell svnversion -n ..)"'
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map,--section-start,.init=0x80a00
|
|||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# any extra libraries we wish to link with the project
|
# any extra libraries we wish to link with the project
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
LIBS := -lfat -lpngu -lpng -lmetaphrasis -lm -lz -lwiiuse -lmad -lbte -lasnd -logc -ltremor -lfreetype
|
LIBS := -lfat -lpngu -lpng -lmetaphrasis -lm -lz -lwiiuse -lmad -lbte -lasnd -logc -ltremor -lfreetype -lmxml
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# list of directories containing libraries, this must be the top level containing
|
# list of directories containing libraries, this must be the top level containing
|
||||||
# include and lib
|
# include and lib
|
||||||
|
2
gui.pnps
@ -1 +1 @@
|
|||||||
<pd><ViewState><e p="gui" x="true"></e><e p="gui\source" x="true"></e><e p="gui\source\fonts" x="false"></e><e p="gui\source\images" x="false"></e><e p="gui\source\libwbfs" x="false"></e><e p="gui\source\libwiigui" x="true"></e><e p="gui\source\sounds" x="false"></e></ViewState></pd>
|
<pd><ViewState><e p="gui" x="true"></e><e p="gui\source\mxml" x="false"></e><e p="gui\source" x="true"></e><e p="gui\source\fonts" x="false"></e><e p="gui\source\images" x="false"></e><e p="gui\source\libwbfs" x="false"></e><e p="gui\source\libwiigui" x="true"></e><e p="gui\source\sounds" x="false"></e><e p="gui\source\unzip" x="false"></e></ViewState></pd>
|
1541
source/Settings.cpp
@ -7,6 +7,8 @@
|
|||||||
#include <ogcsys.h>
|
#include <ogcsys.h>
|
||||||
#include "cfg.h"
|
#include "cfg.h"
|
||||||
#include "language.h"
|
#include "language.h"
|
||||||
|
#include "xml.h" /* XML - Lustar*/
|
||||||
|
#include "mxml/mxml.h"
|
||||||
|
|
||||||
struct SSettings Settings;
|
struct SSettings Settings;
|
||||||
|
|
||||||
@ -1555,6 +1557,11 @@ void CFG_Load(void)
|
|||||||
cfg_load_games();
|
cfg_load_games();
|
||||||
cfg_load_game_num();
|
cfg_load_game_num();
|
||||||
|
|
||||||
|
/* load renamed titles from proper names and game info XML, needs to be after cfg_load_games - Lustar */
|
||||||
|
//snprintf(pathname, sizeof(pathname), "%s%s", Settings.titlestxt_path, "wiitdb.zip");
|
||||||
|
//OpenXMLFile(pathname);
|
||||||
|
//LoadTitlesFromXML("English", false); // options can be added to set force title language to any language and force Japanese title to English
|
||||||
|
|
||||||
Global_Default(); //global default depends on theme information
|
Global_Default(); //global default depends on theme information
|
||||||
CFG_LoadGlobal();
|
CFG_LoadGlobal();
|
||||||
|
|
||||||
|
@ -32,6 +32,18 @@ extern const u32 bg_music_ogg_size;
|
|||||||
extern const u8 credits_music_ogg[];
|
extern const u8 credits_music_ogg[];
|
||||||
extern const u32 credits_music_ogg_size;
|
extern const u32 credits_music_ogg_size;
|
||||||
|
|
||||||
|
extern const u8 gameinfo1_png[];
|
||||||
|
extern const u32 gameinfo1_png_size;
|
||||||
|
|
||||||
|
extern const u8 gameinfo2_png[];
|
||||||
|
extern const u32 gameinfo2_png_size;
|
||||||
|
|
||||||
|
extern const u8 gameinfo1a_png[];
|
||||||
|
extern const u32 gameinfo1a_png_size;
|
||||||
|
|
||||||
|
extern const u8 gameinfo2a_png[];
|
||||||
|
extern const u32 gameinfo2a_png_size;
|
||||||
|
|
||||||
extern const u8 menuin_ogg[];
|
extern const u8 menuin_ogg[];
|
||||||
extern const u32 menuin_ogg_size;
|
extern const u32 menuin_ogg_size;
|
||||||
|
|
||||||
@ -290,4 +302,141 @@ extern const u32 settings_title_over_png_size;
|
|||||||
extern const u8 pageindicator_png[];
|
extern const u8 pageindicator_png[];
|
||||||
extern const u32 pageindicator_png_size;
|
extern const u32 pageindicator_png_size;
|
||||||
|
|
||||||
|
extern const u8 Wiimote1_png[];
|
||||||
|
extern const u32 Wiimote1_png_size;
|
||||||
|
|
||||||
|
extern const u8 Wiimote2_png[];
|
||||||
|
extern const u32 Wiimote2_png_size;
|
||||||
|
|
||||||
|
extern const u8 wifi1_png[];
|
||||||
|
extern const u32 wifi1_png_size;
|
||||||
|
|
||||||
|
extern const u8 wifi2_png[];
|
||||||
|
extern const u32 wifi2png_size;
|
||||||
|
|
||||||
|
extern const u8 wifi3_png[];
|
||||||
|
extern const u32 wifi3_png_size;
|
||||||
|
|
||||||
|
extern const u8 wifi4_png[];
|
||||||
|
extern const u32 wifi4_png_size;
|
||||||
|
|
||||||
|
extern const u8 wifi8_png[];
|
||||||
|
extern const u32 wifi8_png_size;
|
||||||
|
|
||||||
|
extern const u8 Wiimote4_png[];
|
||||||
|
extern const u32 Wiimote4_png_size;
|
||||||
|
|
||||||
|
extern const u8 norating_png[];
|
||||||
|
extern const u32 norating_png_size;
|
||||||
|
|
||||||
|
extern const u8 guitar_png[];
|
||||||
|
extern const u32 guitar_png_size;
|
||||||
|
|
||||||
|
extern const u8 microphone_png[];
|
||||||
|
extern const u32 microphone_png_size;
|
||||||
|
|
||||||
|
extern const u8 gcncontroller_png[];
|
||||||
|
extern const u32 gcncontroller_png_size;
|
||||||
|
|
||||||
|
extern const u8 classiccontroller_png[];
|
||||||
|
extern const u32 classiccontroller_png_size;
|
||||||
|
|
||||||
|
extern const u8 nunchuck_png[];
|
||||||
|
extern const u32 nunchuck_png_size;
|
||||||
|
|
||||||
|
extern const u8 guitarR_png[];
|
||||||
|
extern const u32 guitarR_png_size;
|
||||||
|
|
||||||
|
extern const u8 microphoneR_png[];
|
||||||
|
extern const u32 microphoneR_png_size;
|
||||||
|
|
||||||
|
extern const u8 gcncontrollerR_png[];
|
||||||
|
extern const u32 gcncontrollerR_png_size;
|
||||||
|
|
||||||
|
extern const u8 classiccontrollerR_png[];
|
||||||
|
extern const u32 classiccontrollerR_png_size;
|
||||||
|
|
||||||
|
extern const u8 nunchuckR_png[];
|
||||||
|
extern const u32 nunchuckR_png_size;
|
||||||
|
|
||||||
|
extern const u8 dancepadR_png[];
|
||||||
|
extern const u32 dancepadR_size;
|
||||||
|
|
||||||
|
extern const u8 balanceboard_png[];
|
||||||
|
extern const u32 balanceboard_png_size;
|
||||||
|
|
||||||
|
extern const u8 balanceboardR_png[];
|
||||||
|
extern const u32 balanceboardR_png_size;
|
||||||
|
|
||||||
|
extern const u8 dancepad_png[];
|
||||||
|
extern const u32 dancepad_png_size;
|
||||||
|
|
||||||
|
extern const u8 drumsR_png[];
|
||||||
|
extern const u32 drumsR_png_size;
|
||||||
|
|
||||||
|
extern const u8 drums_png[];
|
||||||
|
extern const u32 drums_png_size;
|
||||||
|
|
||||||
|
extern const u8 motionplusR_png[];
|
||||||
|
extern const u32 motionplusR_png_size;
|
||||||
|
|
||||||
|
extern const u8 motionplus_png[];
|
||||||
|
extern const u32 motionplus_png_size;
|
||||||
|
|
||||||
|
extern const u8 wheelR_png[];
|
||||||
|
extern const u32 wheelR_png_size;
|
||||||
|
|
||||||
|
extern const u8 wheel_png[];
|
||||||
|
extern const u32 wheel_png_size;
|
||||||
|
|
||||||
|
extern const u8 esrb_ec_png[];
|
||||||
|
extern const u32 esrb_ec_png_size;
|
||||||
|
|
||||||
|
extern const u8 esrb_e_png[];
|
||||||
|
extern const u32 esrb_e_png_size;
|
||||||
|
|
||||||
|
extern const u8 esrb_eten_png[];
|
||||||
|
extern const u32 esrb_eten_png_size;
|
||||||
|
|
||||||
|
extern const u8 esrb_t_png[];
|
||||||
|
extern const u32 esrb_t_png_size;
|
||||||
|
|
||||||
|
extern const u8 esrb_m_png[];
|
||||||
|
extern const u32 esrb_m_png_size;
|
||||||
|
|
||||||
|
extern const u8 esrb_ao_png[];
|
||||||
|
extern const u32 esrb_ao_png_size;
|
||||||
|
|
||||||
|
extern const u8 cero_a_png[];
|
||||||
|
extern const u32 cero_a_png_size;
|
||||||
|
|
||||||
|
extern const u8 cero_b_png[];
|
||||||
|
extern const u32 cero_b_png_size;
|
||||||
|
|
||||||
|
extern const u8 cero_c_png[];
|
||||||
|
extern const u32 cero_c_png_size;
|
||||||
|
|
||||||
|
extern const u8 cero_d_png[];
|
||||||
|
extern const u32 cero_d_png_size;
|
||||||
|
|
||||||
|
extern const u8 cero_z_png[];
|
||||||
|
extern const u32 cero_z_png_size;
|
||||||
|
|
||||||
|
extern const u8 pegi_3_png[];
|
||||||
|
extern const u32 pegi_3_png_size;
|
||||||
|
|
||||||
|
extern const u8 pegi_7_png[];
|
||||||
|
extern const u32 pegi_7_png_size;
|
||||||
|
|
||||||
|
extern const u8 pegi_12_png[];
|
||||||
|
extern const u32 pegi_12_png_size;
|
||||||
|
|
||||||
|
extern const u8 pegi_16_png[];
|
||||||
|
extern const u32 pegi_16_png_size;
|
||||||
|
|
||||||
|
extern const u8 pegi_18_png[];
|
||||||
|
extern const u32 pegi_18_png_size;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
781
source/gameinfo.cpp
Normal file
@ -0,0 +1,781 @@
|
|||||||
|
#include <gccore.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "gameinfo.h"
|
||||||
|
|
||||||
|
#include "menu.h"
|
||||||
|
#include "filelist.h"
|
||||||
|
#include "sys.h"
|
||||||
|
#include "wpad.h"
|
||||||
|
#include "wbfs.h"
|
||||||
|
#include "language.h"
|
||||||
|
#include "libwiigui/gui.h"
|
||||||
|
#include "fatmounter.h"
|
||||||
|
#include "listfiles.h"
|
||||||
|
|
||||||
|
#include "xml.h"
|
||||||
|
|
||||||
|
GuiText * debugTxt = NULL;
|
||||||
|
|
||||||
|
int cnt;
|
||||||
|
GuiImageData * playersImgData = NULL;
|
||||||
|
GuiImage * playersImg = NULL;
|
||||||
|
|
||||||
|
GuiImageData * wifiplayersImgData = NULL;
|
||||||
|
GuiImage * wifiplayersImg = NULL;
|
||||||
|
GuiImage * ratingImg = NULL;
|
||||||
|
|
||||||
|
GuiImage * classiccontrollerImg;
|
||||||
|
GuiImage * nunchuckImg;
|
||||||
|
GuiImage * guitarImg;
|
||||||
|
GuiImage * drumsImg;
|
||||||
|
GuiImage * dancepadImg;
|
||||||
|
GuiImage * motionplusImg;
|
||||||
|
GuiImage * wheelImg;
|
||||||
|
GuiImage * balanceboardImg;
|
||||||
|
GuiImage * microphoneImg;
|
||||||
|
GuiImage * gcImg;
|
||||||
|
GuiImage * dialogBoxImg1;
|
||||||
|
GuiImage * dialogBoxImg2;
|
||||||
|
GuiImage * dialogBoxImg3;
|
||||||
|
GuiImage * dialogBoxImg4;
|
||||||
|
GuiImage * dialogBoxImg11;
|
||||||
|
GuiImage * dialogBoxImg22;
|
||||||
|
GuiImage * dialogBoxImg33;
|
||||||
|
GuiImage * dialogBoxImg44;
|
||||||
|
GuiImage * coverImg;
|
||||||
|
GuiImage * coverImg2;
|
||||||
|
|
||||||
|
GuiImageData * classiccontrollerImgData = NULL;
|
||||||
|
GuiImageData * nunchuckImgData = NULL;
|
||||||
|
GuiImageData * guitarImgData = NULL;
|
||||||
|
GuiImageData * drumsImgData = NULL;
|
||||||
|
GuiImageData * motionplusImgData = NULL;
|
||||||
|
GuiImageData * wheelImgData = NULL;
|
||||||
|
GuiImageData * balanceboardImgData = NULL;
|
||||||
|
GuiImageData * dancepadImgData = NULL;
|
||||||
|
GuiImageData * microphoneImgData = NULL;
|
||||||
|
GuiImageData * gamecubeImgData = NULL;
|
||||||
|
GuiImageData * ratingImgData = NULL;
|
||||||
|
GuiImageData * cover = NULL;
|
||||||
|
|
||||||
|
GuiText * releasedTxt = NULL;
|
||||||
|
GuiText * publisherTxt = NULL;
|
||||||
|
GuiText * developerTxt = NULL;
|
||||||
|
GuiText * titleTxt = NULL;
|
||||||
|
GuiText * synopsisTxt = NULL;
|
||||||
|
GuiText * genreTxt = NULL;
|
||||||
|
GuiText * betaTxt = NULL;
|
||||||
|
GuiText * beta1Txt = NULL;
|
||||||
|
GuiText ** wifiTxt = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
/*** Extern variables ***/
|
||||||
|
extern GuiWindow * mainWindow;
|
||||||
|
extern GuiSound * bgMusic;
|
||||||
|
extern u8 shutdown;
|
||||||
|
extern u8 reset;
|
||||||
|
|
||||||
|
/*** Extern functions ***/
|
||||||
|
extern void ResumeGui();
|
||||||
|
extern void HaltGui();
|
||||||
|
|
||||||
|
void eatADick()
|
||||||
|
{
|
||||||
|
// use this to display variables on the window GuiText * debugTxt = NULL;
|
||||||
|
|
||||||
|
playersImgData = NULL;
|
||||||
|
playersImg = NULL;
|
||||||
|
|
||||||
|
wifiplayersImgData = NULL;
|
||||||
|
wifiplayersImg = NULL;
|
||||||
|
ratingImg = NULL;
|
||||||
|
|
||||||
|
classiccontrollerImg = NULL;
|
||||||
|
nunchuckImg = NULL;
|
||||||
|
guitarImg = NULL;
|
||||||
|
drumsImg = NULL;
|
||||||
|
dancepadImg = NULL;
|
||||||
|
motionplusImg = NULL;
|
||||||
|
wheelImg = NULL;
|
||||||
|
balanceboardImg = NULL;
|
||||||
|
microphoneImg = NULL;
|
||||||
|
gcImg = NULL;
|
||||||
|
dialogBoxImg1 = NULL;
|
||||||
|
dialogBoxImg2 = NULL;
|
||||||
|
dialogBoxImg3 = NULL;
|
||||||
|
dialogBoxImg4 = NULL;
|
||||||
|
dialogBoxImg11 = NULL;
|
||||||
|
dialogBoxImg22 = NULL;
|
||||||
|
dialogBoxImg33 = NULL;
|
||||||
|
dialogBoxImg44 = NULL;
|
||||||
|
coverImg = NULL;
|
||||||
|
coverImg2 = NULL;
|
||||||
|
|
||||||
|
classiccontrollerImgData = NULL;
|
||||||
|
nunchuckImgData = NULL;
|
||||||
|
guitarImgData = NULL;
|
||||||
|
drumsImgData = NULL;
|
||||||
|
motionplusImgData = NULL;
|
||||||
|
wheelImgData = NULL;
|
||||||
|
balanceboardImgData = NULL;
|
||||||
|
dancepadImgData = NULL;
|
||||||
|
microphoneImgData = NULL;
|
||||||
|
gamecubeImgData = NULL;
|
||||||
|
ratingImgData = NULL;
|
||||||
|
cover = NULL;
|
||||||
|
|
||||||
|
releasedTxt = NULL;
|
||||||
|
publisherTxt = NULL;
|
||||||
|
developerTxt = NULL;
|
||||||
|
titleTxt = NULL;
|
||||||
|
synopsisTxt = NULL;
|
||||||
|
genreTxt = NULL;
|
||||||
|
betaTxt = NULL;
|
||||||
|
beta1Txt = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* gameinfo
|
||||||
|
***************************************************************************/
|
||||||
|
int
|
||||||
|
showGameInfo(char *ID, u8 *headerID)
|
||||||
|
{
|
||||||
|
int choice = -1;
|
||||||
|
//int i = 0;
|
||||||
|
int y = 0, y1 = 32;
|
||||||
|
int intputX =200, inputY=-30, txtXOffset = 90;
|
||||||
|
u8 nunchuk=0,
|
||||||
|
classiccontroller=0,
|
||||||
|
balanceboard=0,
|
||||||
|
dancepad=0,
|
||||||
|
guitar=0,
|
||||||
|
gamecube=0,
|
||||||
|
wheel=0,
|
||||||
|
motionplus=0,
|
||||||
|
drums=0,
|
||||||
|
microphone=0;
|
||||||
|
int newline=1;
|
||||||
|
u8 page =1;
|
||||||
|
|
||||||
|
GuiWindow gameinfoWindow(600,308);
|
||||||
|
gameinfoWindow.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
|
||||||
|
gameinfoWindow.SetPosition(0, -50);
|
||||||
|
|
||||||
|
GuiWindow gameinfoWindow2(600,308);
|
||||||
|
gameinfoWindow2.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
|
||||||
|
gameinfoWindow2.SetPosition(0, -50);
|
||||||
|
|
||||||
|
GuiWindow txtWindow(350,270);
|
||||||
|
txtWindow.SetAlignment(ALIGN_CENTRE, ALIGN_RIGHT);
|
||||||
|
txtWindow.SetPosition(85, 50);
|
||||||
|
|
||||||
|
|
||||||
|
GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, SOUND_PCM, Settings.sfxvolume);
|
||||||
|
GuiSound btnClick(button_click2_pcm, button_click2_pcm_size, SOUND_PCM, Settings.sfxvolume);
|
||||||
|
char imgPath[50];
|
||||||
|
snprintf(imgPath, sizeof(imgPath), "%sbutton_dialogue_box.png", CFG.theme_path);
|
||||||
|
GuiImageData btnOutline(imgPath, button_dialogue_box_png);
|
||||||
|
snprintf(imgPath, sizeof(imgPath), "%sgameinfo1_png.png", CFG.theme_path);
|
||||||
|
GuiImageData dialogBox1(imgPath, gameinfo1_png);
|
||||||
|
snprintf(imgPath, sizeof(imgPath), "%sgameinfo1a_png.png", CFG.theme_path);
|
||||||
|
GuiImageData dialogBox2(imgPath, gameinfo1a_png);
|
||||||
|
snprintf(imgPath, sizeof(imgPath), "%sgameinfo2_png.png", CFG.theme_path);
|
||||||
|
GuiImageData dialogBox3(imgPath, gameinfo2_png);
|
||||||
|
snprintf(imgPath, sizeof(imgPath), "%sgameinfo2a_png.png", CFG.theme_path);
|
||||||
|
GuiImageData dialogBox4(imgPath, gameinfo2a_png);
|
||||||
|
|
||||||
|
GuiTrigger trigA;
|
||||||
|
trigA.SetButtonOnlyTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||||
|
GuiTrigger trigB;
|
||||||
|
trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B);
|
||||||
|
|
||||||
|
|
||||||
|
GuiButton backBtn(0,0);
|
||||||
|
backBtn.SetPosition(-20,-20);
|
||||||
|
backBtn.SetTrigger(&trigB);
|
||||||
|
gameinfoWindow.Append(&backBtn);
|
||||||
|
|
||||||
|
GuiButton nextBtn(0,0);
|
||||||
|
nextBtn.SetPosition(20,20);
|
||||||
|
nextBtn.SetTrigger(&trigA);
|
||||||
|
gameinfoWindow.Append(&nextBtn);
|
||||||
|
|
||||||
|
//load the xml shit
|
||||||
|
char pathname[100];
|
||||||
|
snprintf(pathname, sizeof(pathname), "%s%s", Settings.titlestxt_path, "wiitdb.zip");
|
||||||
|
OpenXMLFile(pathname);
|
||||||
|
snprintf(pathname, sizeof(pathname), "English");
|
||||||
|
LoadTitlesFromXML(pathname, false); // options can be added to set force title language to any language and force Japanese title to English
|
||||||
|
|
||||||
|
|
||||||
|
/*struct Game_CFG *game_cfg = NULL;
|
||||||
|
int opt_lang;
|
||||||
|
char langtexttmp[11][22] =
|
||||||
|
{{"Console Default"},
|
||||||
|
{"Japanese"},
|
||||||
|
{"English"},
|
||||||
|
{"German"},
|
||||||
|
{"French"},
|
||||||
|
{"Spanish"},
|
||||||
|
{"Italian"},
|
||||||
|
{"Dutch"},
|
||||||
|
{"S. Chinese"},
|
||||||
|
{"T. Chinese"},
|
||||||
|
{"Korean"}};
|
||||||
|
game_cfg = CFG_get_game_opt(headerID);
|
||||||
|
if (game_cfg) {
|
||||||
|
opt_lang = game_cfg->language;
|
||||||
|
} else {
|
||||||
|
opt_lang = Settings.language;
|
||||||
|
}*/
|
||||||
|
LoadGameInfoFromXML(ID,pathname);
|
||||||
|
//LoadGameInfoFromXML(ID,langtexttmp[opt_lang]);
|
||||||
|
char linebuf[1000] = "";
|
||||||
|
char linebuf2[100] = "";
|
||||||
|
|
||||||
|
// set images for required input
|
||||||
|
for (int i=0;strcmp(gameinfo.accessories_required[i+1],"") != 0;i++)
|
||||||
|
{
|
||||||
|
if (strcmp(gameinfo.accessories_required[i+1],"nunchuk")==0)
|
||||||
|
{nunchuckImgData = new GuiImageData(nunchuckR_png);nunchuk=1;}
|
||||||
|
else
|
||||||
|
nunchuckImgData = new GuiImageData(nunchuck_png);
|
||||||
|
|
||||||
|
if (strcmp(gameinfo.accessories_required[i+1],"classiccontroller")==0)
|
||||||
|
{classiccontrollerImgData = new GuiImageData(classiccontrollerR_png);classiccontroller=1;}
|
||||||
|
else
|
||||||
|
classiccontrollerImgData = new GuiImageData(classiccontroller_png);
|
||||||
|
|
||||||
|
if (strcmp(gameinfo.accessories_required[i+1],"guitar")==0)
|
||||||
|
{guitarImgData = new GuiImageData(guitarR_png);guitar=1;}
|
||||||
|
else
|
||||||
|
guitarImgData = new GuiImageData(guitar_png);
|
||||||
|
|
||||||
|
if (strcmp(gameinfo.accessories_required[i+1],"gamecube")==0)
|
||||||
|
{gamecubeImgData = new GuiImageData(gcncontrollerR_png);gamecube=1;}
|
||||||
|
else
|
||||||
|
gamecubeImgData = new GuiImageData(gcncontroller_png);
|
||||||
|
|
||||||
|
if (strcmp(gameinfo.accessories_required[i+1],"wheel")==0)
|
||||||
|
{wheelImgData = new GuiImageData(wheelR_png);wheel=1;}
|
||||||
|
else
|
||||||
|
wheelImgData = new GuiImageData(wheel_png);
|
||||||
|
|
||||||
|
if (strcmp(gameinfo.accessories_required[i+1],"motionplus")==0)
|
||||||
|
{motionplusImgData = new GuiImageData(motionplusR_png);motionplus=1;}
|
||||||
|
else
|
||||||
|
motionplusImgData = new GuiImageData(motionplus_png);
|
||||||
|
|
||||||
|
if (strcmp(gameinfo.accessories_required[i+1],"drums")==0)
|
||||||
|
{drumsImgData = new GuiImageData(drumsR_png);drums=1;}
|
||||||
|
else
|
||||||
|
drumsImgData = new GuiImageData(drums_png);
|
||||||
|
|
||||||
|
if (strcmp(gameinfo.accessories_required[i+1],"microphone")==0)
|
||||||
|
{microphoneImgData = new GuiImageData(microphoneR_png);microphone=1;}
|
||||||
|
else
|
||||||
|
microphoneImgData = new GuiImageData(microphone_png);
|
||||||
|
|
||||||
|
if (strcmp(gameinfo.accessories_required[i+1],"balanceboard")==0)
|
||||||
|
{balanceboardImgData = new GuiImageData(balanceboardR_png);balanceboard=1;}
|
||||||
|
else
|
||||||
|
balanceboardImgData = new GuiImageData(balanceboard_png);
|
||||||
|
|
||||||
|
if (strcmp(gameinfo.accessories_required[i+1],"dancepad")==0)
|
||||||
|
{dancepadImgData = new GuiImageData(dancepadR_png);dancepad=1;}
|
||||||
|
else
|
||||||
|
dancepadImgData = new GuiImageData(dancepad_png);
|
||||||
|
|
||||||
|
}
|
||||||
|
for (int i=0;strcmp(gameinfo.accessories[i+1],"") != 0;i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (strcmp(gameinfo.accessories_required[i],"classiccontroller")==0)
|
||||||
|
classiccontroller=1;
|
||||||
|
|
||||||
|
if (strcmp(gameinfo.accessories[i+1],"nunchuk")==0)
|
||||||
|
{nunchuk=1;}
|
||||||
|
|
||||||
|
if (strcmp(gameinfo.accessories[i+1],"guitar")==0)
|
||||||
|
guitar=1;
|
||||||
|
|
||||||
|
if (strcmp(gameinfo.accessories_required[i],"drums")==0)
|
||||||
|
drums=1;
|
||||||
|
|
||||||
|
if (strcmp(gameinfo.accessories_required[i],"dancepad")==0)
|
||||||
|
dancepad=1;
|
||||||
|
|
||||||
|
if (strcmp(gameinfo.accessories_required[i],"motionplus")==0)
|
||||||
|
motionplus=1;
|
||||||
|
|
||||||
|
if (strcmp(gameinfo.accessories_required[i],"wheel")==0)
|
||||||
|
wheel=1;
|
||||||
|
|
||||||
|
if (strcmp(gameinfo.accessories_required[i],"balanceboard")==0)
|
||||||
|
balanceboard=1;
|
||||||
|
|
||||||
|
if (strcmp(gameinfo.accessories_required[i],"microphone")==0)
|
||||||
|
microphone=1;
|
||||||
|
|
||||||
|
if (strcmp(gameinfo.accessories_required[i],"gamecube")==0)
|
||||||
|
gamecube=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
dialogBoxImg1 = new GuiImage(&dialogBox1);
|
||||||
|
dialogBoxImg1->SetAlignment(0,3);
|
||||||
|
dialogBoxImg1->SetPosition(0,0);
|
||||||
|
|
||||||
|
dialogBoxImg2 = new GuiImage(&dialogBox2);
|
||||||
|
dialogBoxImg2->SetAlignment(0,3);
|
||||||
|
dialogBoxImg2->SetPosition(150,0);
|
||||||
|
|
||||||
|
dialogBoxImg3 = new GuiImage(&dialogBox3);
|
||||||
|
dialogBoxImg3->SetAlignment(0,3);
|
||||||
|
dialogBoxImg3->SetPosition(300,0);
|
||||||
|
|
||||||
|
dialogBoxImg4 = new GuiImage(&dialogBox4);
|
||||||
|
dialogBoxImg4->SetAlignment(0,3);
|
||||||
|
dialogBoxImg4->SetPosition(450,0);
|
||||||
|
|
||||||
|
|
||||||
|
gameinfoWindow.Append(dialogBoxImg1);
|
||||||
|
gameinfoWindow.Append(dialogBoxImg2);
|
||||||
|
gameinfoWindow.Append(dialogBoxImg3);
|
||||||
|
gameinfoWindow.Append(dialogBoxImg4);
|
||||||
|
// gameinfoWindow.Append(&titleTxt);
|
||||||
|
|
||||||
|
//coverart
|
||||||
|
//snprintf(imgPath, sizeof(imgPath), "%s%s.png", Settings.covers_path, IDfull);
|
||||||
|
// cover = new GuiImageData(imgPath,0); //load short id
|
||||||
|
// if (!cover->GetImage()) //if could not load the short id image
|
||||||
|
// {
|
||||||
|
// delete cover;
|
||||||
|
snprintf(imgPath, sizeof(imgPath), "%s%s.png", Settings.covers_path, ID);
|
||||||
|
cover = new GuiImageData(imgPath, 0); //load full id image
|
||||||
|
if (!cover->GetImage())
|
||||||
|
{
|
||||||
|
delete cover;
|
||||||
|
snprintf(imgPath, sizeof(imgPath), "%snoimage.png", Settings.covers_path);
|
||||||
|
cover = new GuiImageData(imgPath, nocover_png); //load no image
|
||||||
|
}
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (coverImg)
|
||||||
|
// {
|
||||||
|
delete coverImg;
|
||||||
|
coverImg = NULL;
|
||||||
|
// }
|
||||||
|
coverImg = new GuiImage(cover);
|
||||||
|
coverImg->SetWidescreen(CFG.widescreen);
|
||||||
|
coverImg->SetPosition(15,30);
|
||||||
|
gameinfoWindow.Append(coverImg);
|
||||||
|
|
||||||
|
// # of players
|
||||||
|
if (strcmp(gameinfo.players,"") != 0) {
|
||||||
|
playersImgData = new GuiImageData(Wiimote1_png);
|
||||||
|
if (atoi(gameinfo.players)>1){
|
||||||
|
playersImgData= new GuiImageData(Wiimote2_png);}
|
||||||
|
if (atoi(gameinfo.players)>2){
|
||||||
|
playersImgData= new GuiImageData(Wiimote4_png);}
|
||||||
|
|
||||||
|
playersImg = new GuiImage(playersImgData);
|
||||||
|
playersImg->SetWidescreen(CFG.widescreen);
|
||||||
|
playersImg->SetPosition(intputX , inputY);
|
||||||
|
playersImg->SetAlignment(0,4);
|
||||||
|
gameinfoWindow.Append(playersImg);
|
||||||
|
intputX += (CFG.widescreen ? playersImg->GetWidth() * .8 : playersImg->GetWidth());
|
||||||
|
}
|
||||||
|
|
||||||
|
//draw the inupt types for this game
|
||||||
|
if (nunchuk==1){
|
||||||
|
nunchuckImg = new GuiImage(nunchuckImgData);
|
||||||
|
nunchuckImg->SetWidescreen(CFG.widescreen);
|
||||||
|
nunchuckImg->SetPosition(intputX , inputY);
|
||||||
|
nunchuckImg->SetAlignment(0,4);
|
||||||
|
gameinfoWindow.Append(nunchuckImg);
|
||||||
|
intputX += (CFG.widescreen ? nunchuckImg->GetWidth() * .8 : nunchuckImg->GetWidth());}
|
||||||
|
|
||||||
|
if (classiccontroller==1){
|
||||||
|
classiccontrollerImg = new GuiImage(classiccontrollerImgData);
|
||||||
|
classiccontrollerImg->SetWidescreen(CFG.widescreen);
|
||||||
|
classiccontrollerImg->SetPosition(intputX , inputY);
|
||||||
|
classiccontrollerImg->SetAlignment(0,4);
|
||||||
|
gameinfoWindow.Append(classiccontrollerImg);
|
||||||
|
intputX += (CFG.widescreen ? classiccontrollerImg->GetWidth() * .8 : classiccontrollerImg->GetWidth());}
|
||||||
|
|
||||||
|
if (gamecube==1){
|
||||||
|
gcImg = new GuiImage(gamecubeImgData);
|
||||||
|
gcImg->SetWidescreen(CFG.widescreen);
|
||||||
|
gcImg->SetPosition(intputX , inputY);
|
||||||
|
gcImg->SetAlignment(0,4);
|
||||||
|
gameinfoWindow.Append(gcImg);
|
||||||
|
intputX += (CFG.widescreen ? gcImg->GetWidth() * .8 : gcImg->GetWidth());}
|
||||||
|
|
||||||
|
if (wheel==1){
|
||||||
|
wheelImg = new GuiImage(wheelImgData);
|
||||||
|
wheelImg->SetWidescreen(CFG.widescreen);
|
||||||
|
wheelImg->SetPosition(intputX , inputY);
|
||||||
|
wheelImg->SetAlignment(0,4);
|
||||||
|
gameinfoWindow.Append(wheelImg);
|
||||||
|
intputX += (CFG.widescreen ? wheelImg->GetWidth() * .8 : wheelImg->GetWidth());}
|
||||||
|
|
||||||
|
if (guitar==1){
|
||||||
|
guitarImg = new GuiImage(guitarImgData);
|
||||||
|
guitarImg->SetWidescreen(CFG.widescreen);
|
||||||
|
guitarImg->SetPosition(intputX , inputY);
|
||||||
|
guitarImg->SetAlignment(0,4);
|
||||||
|
gameinfoWindow.Append(guitarImg);
|
||||||
|
intputX += (CFG.widescreen ? guitarImg->GetWidth() * .8 : guitarImg->GetWidth());}
|
||||||
|
|
||||||
|
if (drums==1){
|
||||||
|
drumsImg = new GuiImage(drumsImgData);
|
||||||
|
drumsImg->SetWidescreen(CFG.widescreen);
|
||||||
|
drumsImg->SetPosition(intputX , inputY);
|
||||||
|
drumsImg->SetAlignment(0,4);
|
||||||
|
gameinfoWindow.Append(drumsImg);
|
||||||
|
intputX += (CFG.widescreen ? drumsImg->GetWidth() * .8 : drumsImg->GetWidth());}
|
||||||
|
|
||||||
|
if (microphone==1){
|
||||||
|
microphoneImg = new GuiImage(microphoneImgData);
|
||||||
|
microphoneImg->SetWidescreen(CFG.widescreen);
|
||||||
|
microphoneImg->SetPosition(intputX , inputY);
|
||||||
|
microphoneImg->SetAlignment(0,4);
|
||||||
|
gameinfoWindow.Append(microphoneImg);
|
||||||
|
intputX += (CFG.widescreen ? microphoneImg->GetWidth() * .8 : microphoneImg->GetWidth());}
|
||||||
|
|
||||||
|
if (dancepad==1){
|
||||||
|
dancepadImg = new GuiImage(dancepadImgData);
|
||||||
|
dancepadImg->SetWidescreen(CFG.widescreen);
|
||||||
|
dancepadImg->SetPosition(intputX , inputY);
|
||||||
|
dancepadImg->SetAlignment(0,4);
|
||||||
|
gameinfoWindow.Append(dancepadImg);
|
||||||
|
intputX += (CFG.widescreen ? dancepadImg->GetWidth() * .8 : dancepadImg->GetWidth());}
|
||||||
|
|
||||||
|
if (motionplus==1){
|
||||||
|
motionplusImg = new GuiImage(motionplusImgData);
|
||||||
|
motionplusImg->SetWidescreen(CFG.widescreen);
|
||||||
|
motionplusImg->SetPosition(intputX , inputY);
|
||||||
|
motionplusImg->SetAlignment(0,4);
|
||||||
|
gameinfoWindow.Append(motionplusImg);
|
||||||
|
intputX += (CFG.widescreen ? motionplusImg->GetWidth() * .8 : motionplusImg->GetWidth());}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// # online players
|
||||||
|
if (strcmp(gameinfo.wifiplayers,"") != 0) {
|
||||||
|
wifiplayersImgData = new GuiImageData(wifi1_png);
|
||||||
|
if (atoi(gameinfo.wifiplayers)>1){
|
||||||
|
wifiplayersImgData= new GuiImageData(wifi2_png);}
|
||||||
|
if (atoi(gameinfo.wifiplayers)>2){
|
||||||
|
wifiplayersImgData= new GuiImageData(wifi4_png);}
|
||||||
|
|
||||||
|
if (atoi(gameinfo.wifiplayers)>4){
|
||||||
|
wifiplayersImgData= new GuiImageData(wifi8_png);}
|
||||||
|
|
||||||
|
wifiplayersImg = new GuiImage(wifiplayersImgData);
|
||||||
|
wifiplayersImg->SetWidescreen(CFG.widescreen);
|
||||||
|
wifiplayersImg->SetPosition(intputX , inputY);
|
||||||
|
wifiplayersImg->SetAlignment(0,4);
|
||||||
|
gameinfoWindow.Append(wifiplayersImg);
|
||||||
|
intputX += (CFG.widescreen ? wifiplayersImg->GetWidth() * .8 : wifiplayersImg->GetWidth());
|
||||||
|
}
|
||||||
|
|
||||||
|
// ratings
|
||||||
|
if (strcmp(gameinfo.ratingtype,"") !=0){
|
||||||
|
if (strcmp(gameinfo.ratingtype,"ESRB")==0) {
|
||||||
|
if (strcmp(gameinfo.ratingvalueESRB,"EC")==0)
|
||||||
|
ratingImgData = new GuiImageData(esrb_ec_png);
|
||||||
|
else if (strcmp(gameinfo.ratingvalueESRB,"E")==0)
|
||||||
|
ratingImgData = new GuiImageData(esrb_e_png);
|
||||||
|
else if (strcmp(gameinfo.ratingvalueESRB,"E10+")==0)
|
||||||
|
ratingImgData = new GuiImageData(esrb_eten_png);
|
||||||
|
else if (strcmp(gameinfo.ratingvalueESRB,"T")==0)
|
||||||
|
ratingImgData = new GuiImageData(esrb_t_png);
|
||||||
|
else if (strcmp(gameinfo.ratingvalueESRB,"M")==0)
|
||||||
|
ratingImgData = new GuiImageData(esrb_m_png);
|
||||||
|
else if (strcmp(gameinfo.ratingvalueESRB,"AO")==0)
|
||||||
|
ratingImgData = new GuiImageData(esrb_ao_png);
|
||||||
|
else {ratingImgData = new GuiImageData(norating_png);}
|
||||||
|
} //there are 2 values here cause some countries are stupid and
|
||||||
|
else if (strcmp(gameinfo.ratingtype,"PEGI")==0) {//can't use the same as everybody else
|
||||||
|
if ((strcmp(gameinfo.ratingvaluePEGI,"3")==0)||(strcmp(gameinfo.ratingvaluePEGI,"4")==0))
|
||||||
|
ratingImgData = new GuiImageData(pegi_3_png);
|
||||||
|
else if ((strcmp(gameinfo.ratingvaluePEGI,"7")==0)||(strcmp(gameinfo.ratingvaluePEGI,"7")==0))
|
||||||
|
ratingImgData = new GuiImageData(pegi_7_png);
|
||||||
|
else if (strcmp(gameinfo.ratingvaluePEGI,"12")==0)
|
||||||
|
ratingImgData = new GuiImageData(pegi_12_png);
|
||||||
|
else if ((strcmp(gameinfo.ratingvaluePEGI,"16")==0)||(strcmp(gameinfo.ratingvaluePEGI,"15")==0))
|
||||||
|
ratingImgData = new GuiImageData(pegi_16_png);
|
||||||
|
else if (strcmp(gameinfo.ratingvaluePEGI,"18")==0)
|
||||||
|
ratingImgData = new GuiImageData(pegi_18_png);
|
||||||
|
else {ratingImgData = new GuiImageData(norating_png);}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (strcmp(gameinfo.ratingtype,"CERO")==0) {
|
||||||
|
if (strcmp(gameinfo.ratingvalueCERO,"A")==0)
|
||||||
|
ratingImgData = new GuiImageData(cero_a_png);
|
||||||
|
//ratingImgData = new GuiImageData(cero_b_png);
|
||||||
|
else if (strcmp(gameinfo.ratingvalueCERO,"B")==0)
|
||||||
|
ratingImgData = new GuiImageData(cero_b_png);
|
||||||
|
else if (strcmp(gameinfo.ratingvalueCERO,"C")==0)
|
||||||
|
ratingImgData = new GuiImageData(cero_c_png);
|
||||||
|
else if (strcmp(gameinfo.ratingvalueCERO,"D")==0)
|
||||||
|
ratingImgData = new GuiImageData(cero_d_png);
|
||||||
|
else if (strcmp(gameinfo.ratingvalueCERO,"Z")==0)
|
||||||
|
ratingImgData = new GuiImageData(cero_z_png);
|
||||||
|
else {ratingImgData = new GuiImageData(norating_png);}
|
||||||
|
}
|
||||||
|
|
||||||
|
else {ratingImgData = new GuiImageData(norating_png);}
|
||||||
|
ratingImg = new GuiImage(ratingImgData);
|
||||||
|
ratingImg->SetWidescreen(CFG.widescreen);
|
||||||
|
ratingImg->SetPosition(-25 , inputY);
|
||||||
|
ratingImg->SetAlignment(1,4);
|
||||||
|
gameinfoWindow.Append(ratingImg);
|
||||||
|
intputX += (CFG.widescreen ? ratingImg->GetWidth() * .8 : ratingImg->GetWidth());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////debugging line
|
||||||
|
/* snprintf(linebuf, sizeof(linebuf), "%s %s %s %s %i %s",gameinfo.ratingtype ,gameinfo.ratingvalueESRB,gameinfo.ratingvaluePEGI,gameinfo.ratingvalueCERO, ass,LANGUAGE.released);
|
||||||
|
|
||||||
|
for (int i=0;strcmp(gameinfo.accessories_required[i+1],"") != 0;i++)
|
||||||
|
{
|
||||||
|
snprintf(linebuf, sizeof(linebuf), "%s %s",linebuf, gameinfo.accessories_required[i+1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
debugTxt = new GuiText(linebuf, 18, (GXColor){0,0,0, 255});
|
||||||
|
debugTxt->SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); debugTxt->SetPosition(0,0);
|
||||||
|
gameinfoWindow.Append(debugTxt);*/
|
||||||
|
|
||||||
|
if (strcmp(gameinfo.title,"") != 0)
|
||||||
|
{snprintf(linebuf, sizeof(linebuf), "%s",gameinfo.title);
|
||||||
|
titleTxt = new GuiText(linebuf, 22, (GXColor){0,0,0, 255});
|
||||||
|
if (titleTxt->GetWidth()>300)titleTxt->SetFontSize(18);
|
||||||
|
titleTxt->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); titleTxt->SetPosition(txtXOffset,12+y); y+=24;
|
||||||
|
gameinfoWindow.Append(titleTxt);}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//date
|
||||||
|
snprintf(linebuf2, sizeof(linebuf2), " ");
|
||||||
|
if (strcmp(gameinfo.day,"") != 0)
|
||||||
|
{snprintf(linebuf2, sizeof(linebuf2), "%s ", gameinfo.day);}
|
||||||
|
if (strcmp(gameinfo.month,"") != 0){
|
||||||
|
switch (atoi(gameinfo.month))
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, LANGUAGE.january);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, LANGUAGE.february);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, LANGUAGE.march);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, LANGUAGE.april);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, LANGUAGE.may);
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, LANGUAGE.june);
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, LANGUAGE.july);
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, LANGUAGE.august);
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, LANGUAGE.september);
|
||||||
|
break;
|
||||||
|
case 10:
|
||||||
|
snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, LANGUAGE.october);
|
||||||
|
break;
|
||||||
|
case 11:
|
||||||
|
snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, LANGUAGE.november);
|
||||||
|
break;
|
||||||
|
case 12:
|
||||||
|
snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, LANGUAGE.december);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (strcmp(gameinfo.year,"") != 0)newline=1;
|
||||||
|
{snprintf(linebuf, sizeof(linebuf), "%s : %s%s", LANGUAGE.released, linebuf2, gameinfo.year);
|
||||||
|
releasedTxt = new GuiText(linebuf, 16, (GXColor){0,0,0, 255});
|
||||||
|
if (releasedTxt->GetWidth()>300) newline=2;
|
||||||
|
releasedTxt->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); releasedTxt->SetPosition(-17,12+y); y+=(20 * newline);newline=1;
|
||||||
|
gameinfoWindow.Append(releasedTxt);}
|
||||||
|
//genre
|
||||||
|
if (strcmp(gameinfo.genre,"") != 0)
|
||||||
|
{snprintf(linebuf, sizeof(linebuf), "%s", gameinfo.genre);
|
||||||
|
genreTxt = new GuiText(linebuf, 16, (GXColor){0,0,0, 255});
|
||||||
|
if (genreTxt->GetWidth()>300) newline=2;
|
||||||
|
genreTxt->SetAlignment(ALIGN_LEFT, ALIGN_TOP); genreTxt->SetPosition(205,12+y1); y1+=(25 * newline);newline=1;
|
||||||
|
gameinfoWindow.Append(genreTxt);}
|
||||||
|
|
||||||
|
//developer
|
||||||
|
if (strcmp(gameinfo.developer,"") != 0 && strcmp(gameinfo.developer,gameinfo.publisher) != 0)
|
||||||
|
{snprintf(linebuf, sizeof(linebuf), "%s %s", LANGUAGE.developedby, gameinfo.developer);
|
||||||
|
developerTxt = new GuiText(linebuf, 16, (GXColor){0,0,0, 255});
|
||||||
|
if (developerTxt->GetWidth()>250) newline=2;
|
||||||
|
developerTxt->SetMaxWidth(250,GuiText::WRAP);
|
||||||
|
developerTxt->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); developerTxt->SetPosition(-17,12+y); y+=(40 * newline);newline=1;
|
||||||
|
gameinfoWindow.Append(developerTxt);}
|
||||||
|
|
||||||
|
//publisher
|
||||||
|
if (strcmp(gameinfo.publisher,"") != 0)
|
||||||
|
{snprintf(linebuf, sizeof(linebuf), "%s %s", LANGUAGE.publishedby, gameinfo.publisher);
|
||||||
|
publisherTxt = new GuiText(linebuf, 16, (GXColor){0,0,0, 255});
|
||||||
|
if (publisherTxt->GetWidth()>250) newline=2;
|
||||||
|
publisherTxt->SetMaxWidth(250,GuiText::WRAP);
|
||||||
|
publisherTxt->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); publisherTxt->SetPosition(-17,12+y); y+=(20 * newline);newline=1;
|
||||||
|
gameinfoWindow.Append(publisherTxt);}
|
||||||
|
|
||||||
|
//don't bother us txt
|
||||||
|
snprintf(linebuf, sizeof(linebuf), "Don't bother the USB Loader QX Team about errors in this file.");
|
||||||
|
betaTxt = new GuiText(linebuf, 14, (GXColor){0,0,0, 255});
|
||||||
|
betaTxt->SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); betaTxt->SetPosition(-17,-20);//
|
||||||
|
gameinfoWindow.Append(betaTxt);
|
||||||
|
snprintf(linebuf, sizeof(linebuf), "A site will be available in the near nuture to submit changes.");
|
||||||
|
beta1Txt = new GuiText(linebuf, 14, (GXColor){0,0,0, 255});
|
||||||
|
beta1Txt->SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); beta1Txt->SetPosition(-17,-10);
|
||||||
|
gameinfoWindow.Append(beta1Txt);
|
||||||
|
|
||||||
|
// WiFi Shit commented out cause it has a code dump in it still
|
||||||
|
/*if (strcmp(gameinfo.wififeatures[0],"") != 0){
|
||||||
|
snprintf(linebuf, sizeof(linebuf), "%s:",LANGUAGE.wififeatures);
|
||||||
|
wifiTxt[0] = new GuiText(linebuf, 16, (GXColor){0,0,0, 255});
|
||||||
|
wifiTxt[0]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); wifiTxt[0]->SetPosition(205,12+y); y+=(20 * newline);
|
||||||
|
gameinfoWindow.Append(wifiTxt[0]);}
|
||||||
|
for (int i=1;strcmp(gameinfo.wififeatures[i],"") != 0;i++)
|
||||||
|
{
|
||||||
|
snprintf(linebuf, sizeof(linebuf), "%s",gameinfo.wififeatures[i]);
|
||||||
|
wifiTxt[i] = new GuiText(linebuf, 16, (GXColor){0,0,0, 255});
|
||||||
|
wifiTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); wifiTxt[i]->SetPosition(210,12+y); y+=(20 * newline);
|
||||||
|
gameinfoWindow.Append(wifiTxt[i]);}*/
|
||||||
|
|
||||||
|
//synopsis
|
||||||
|
if (strcmp(gameinfo.synopsis,"") != 0)
|
||||||
|
{snprintf(linebuf, sizeof(linebuf), "%s", gameinfo.synopsis);
|
||||||
|
synopsisTxt = new GuiText(linebuf, 16, (GXColor){0,0,0, 255});
|
||||||
|
synopsisTxt->SetMaxWidth(350,GuiText::WRAP);
|
||||||
|
synopsisTxt->SetAlignment(ALIGN_LEFT, ALIGN_TOP); synopsisTxt->SetPosition(0,0);
|
||||||
|
dialogBoxImg11 = new GuiImage(&dialogBox1);
|
||||||
|
dialogBoxImg11->SetAlignment(0,3);
|
||||||
|
dialogBoxImg11->SetPosition(0,0);
|
||||||
|
|
||||||
|
dialogBoxImg22 = new GuiImage(&dialogBox2);
|
||||||
|
dialogBoxImg22->SetAlignment(0,3);
|
||||||
|
dialogBoxImg22->SetPosition(150,0);
|
||||||
|
|
||||||
|
dialogBoxImg33 = new GuiImage(&dialogBox3);
|
||||||
|
dialogBoxImg33->SetAlignment(0,3);
|
||||||
|
dialogBoxImg33->SetPosition(300,0);
|
||||||
|
|
||||||
|
dialogBoxImg44 = new GuiImage(&dialogBox4);
|
||||||
|
dialogBoxImg44->SetAlignment(0,3);
|
||||||
|
dialogBoxImg44->SetPosition(450,0);
|
||||||
|
|
||||||
|
|
||||||
|
gameinfoWindow2.Append(dialogBoxImg11);
|
||||||
|
gameinfoWindow2.Append(dialogBoxImg22);
|
||||||
|
gameinfoWindow2.Append(dialogBoxImg33);
|
||||||
|
gameinfoWindow2.Append(dialogBoxImg44);
|
||||||
|
|
||||||
|
txtWindow.Append(synopsisTxt);
|
||||||
|
coverImg2 = new GuiImage(cover);
|
||||||
|
coverImg2->SetWidescreen(CFG.widescreen);
|
||||||
|
coverImg2->SetPosition(15,30);
|
||||||
|
gameinfoWindow2.Append(coverImg2);
|
||||||
|
gameinfoWindow2.Append(&txtWindow);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
gameinfoWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_IN, 50);
|
||||||
|
HaltGui();
|
||||||
|
mainWindow->SetState(STATE_DISABLED);
|
||||||
|
mainWindow->Append(&gameinfoWindow);
|
||||||
|
mainWindow->ChangeFocus(&gameinfoWindow);
|
||||||
|
ResumeGui();
|
||||||
|
|
||||||
|
while(choice == -1)
|
||||||
|
{
|
||||||
|
VIDEO_WaitVSync();
|
||||||
|
if(shutdown == 1)
|
||||||
|
{
|
||||||
|
wiilight(0);
|
||||||
|
Sys_Shutdown();
|
||||||
|
}
|
||||||
|
if(reset == 1)
|
||||||
|
Sys_Reboot();
|
||||||
|
|
||||||
|
|
||||||
|
if ((backBtn.GetState()==STATE_CLICKED)||(backBtn.GetState()==STATE_HELD)){
|
||||||
|
choice=1;
|
||||||
|
eatADick();
|
||||||
|
synopsisTxt = NULL;
|
||||||
|
break;}
|
||||||
|
|
||||||
|
else if (((nextBtn.GetState()==STATE_CLICKED)||(nextBtn.GetState()==STATE_HELD))&&
|
||||||
|
(strcmp(gameinfo.synopsis,"") != 0)){
|
||||||
|
|
||||||
|
if (page==1){
|
||||||
|
nextBtn.ResetState();
|
||||||
|
HaltGui();
|
||||||
|
gameinfoWindow.SetVisible(false);
|
||||||
|
gameinfoWindow2.SetVisible(true);
|
||||||
|
coverImg->SetPosition(15,30);
|
||||||
|
|
||||||
|
backBtn.SetClickable(false);
|
||||||
|
gameinfoWindow2.Append(&nextBtn);
|
||||||
|
mainWindow->Append(&gameinfoWindow2);
|
||||||
|
ResumeGui();
|
||||||
|
page=2;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
nextBtn.ResetState();
|
||||||
|
HaltGui();
|
||||||
|
backBtn.SetClickable(true);
|
||||||
|
gameinfoWindow2.SetVisible(false);
|
||||||
|
gameinfoWindow.SetVisible(true);
|
||||||
|
gameinfoWindow.Append(&backBtn);
|
||||||
|
gameinfoWindow.Append(&nextBtn);
|
||||||
|
mainWindow->Remove(&gameinfoWindow2);
|
||||||
|
ResumeGui();
|
||||||
|
page=1;
|
||||||
|
}
|
||||||
|
nextBtn.ResetState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (page==1){
|
||||||
|
gameinfoWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50);
|
||||||
|
while(gameinfoWindow.GetEffect() > 0) usleep(50);
|
||||||
|
HaltGui();
|
||||||
|
mainWindow->Remove(&gameinfoWindow);
|
||||||
|
mainWindow->SetState(STATE_DEFAULT);
|
||||||
|
ResumeGui();}
|
||||||
|
else {
|
||||||
|
gameinfoWindow2.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50);
|
||||||
|
while(gameinfoWindow2.GetEffect() > 0) usleep(50);
|
||||||
|
HaltGui();
|
||||||
|
mainWindow->Remove(&gameinfoWindow2);
|
||||||
|
mainWindow->SetState(STATE_DEFAULT);
|
||||||
|
ResumeGui();}
|
||||||
|
return choice;
|
||||||
|
}
|
||||||
|
|
14
source/gameinfo.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* PromptWindows
|
||||||
|
* USB Loader GX 2009
|
||||||
|
*
|
||||||
|
* PromptWindows.h
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#ifndef _GAMEINFO_H_
|
||||||
|
#define _GAMEINFO_H_
|
||||||
|
|
||||||
|
|
||||||
|
int showGameInfo(char *ID, u8 *headerID);
|
||||||
|
void eatADick();
|
||||||
|
#endif
|
BIN
source/images/Wiimote1.png
Normal file
After Width: | Height: | Size: 849 B |
BIN
source/images/Wiimote2.png
Normal file
After Width: | Height: | Size: 900 B |
BIN
source/images/Wiimote3.png
Normal file
After Width: | Height: | Size: 923 B |
BIN
source/images/Wiimote4.png
Normal file
After Width: | Height: | Size: 911 B |
BIN
source/images/balanceboard.png
Normal file
After Width: | Height: | Size: 3.6 KiB |
BIN
source/images/balanceboardR.png
Normal file
After Width: | Height: | Size: 3.1 KiB |
BIN
source/images/cero_a.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
source/images/cero_b.png
Normal file
After Width: | Height: | Size: 4.0 KiB |
BIN
source/images/cero_c.png
Normal file
After Width: | Height: | Size: 4.2 KiB |
BIN
source/images/cero_d.png
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
source/images/cero_z.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
source/images/classiccontroller.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
source/images/classiccontrollerR.png
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
source/images/dancepad.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
source/images/dancepadR.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
source/images/drums.png
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
source/images/drumsR.png
Normal file
After Width: | Height: | Size: 3.1 KiB |
BIN
source/images/esrb_ao.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
source/images/esrb_e.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
source/images/esrb_ec.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
source/images/esrb_eten.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
source/images/esrb_m.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
source/images/esrb_t.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
source/images/gameinfo1.png
Normal file
After Width: | Height: | Size: 8.3 KiB |
BIN
source/images/gameinfo1a.png
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
source/images/gameinfo2.png
Normal file
After Width: | Height: | Size: 7.7 KiB |
BIN
source/images/gameinfo2a.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
source/images/gcncontroller.png
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
source/images/gcncontrollerR.png
Normal file
After Width: | Height: | Size: 3.1 KiB |
BIN
source/images/guitar.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
source/images/guitarR.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
source/images/microphone.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
source/images/microphoneR.png
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
source/images/motionplus.png
Normal file
After Width: | Height: | Size: 530 B |
BIN
source/images/motionplusR.png
Normal file
After Width: | Height: | Size: 533 B |
BIN
source/images/norating.png
Normal file
After Width: | Height: | Size: 5.6 KiB |
BIN
source/images/nunchuck.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
source/images/nunchuckR.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
source/images/pegi_12.png
Normal file
After Width: | Height: | Size: 8.4 KiB |
BIN
source/images/pegi_16.png
Normal file
After Width: | Height: | Size: 8.2 KiB |
BIN
source/images/pegi_18.png
Normal file
After Width: | Height: | Size: 8.2 KiB |
BIN
source/images/pegi_3.png
Normal file
After Width: | Height: | Size: 8.7 KiB |
BIN
source/images/pegi_7.png
Normal file
After Width: | Height: | Size: 8.9 KiB |
BIN
source/images/wheel.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
source/images/wheelR.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
source/images/wifi1.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
source/images/wifi2.png
Normal file
After Width: | Height: | Size: 4.6 KiB |
BIN
source/images/wifi3.png
Normal file
After Width: | Height: | Size: 4.6 KiB |
BIN
source/images/wifi4.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
source/images/wifi8.png
Normal file
After Width: | Height: | Size: 4.4 KiB |
@ -185,6 +185,7 @@ snprintf(LANGUAGE.RenameGameonWBFS, sizeof(LANGUAGE.RenameGameonWBFS), "Rename G
|
|||||||
snprintf(LANGUAGE.Restart, sizeof(LANGUAGE.Restart), "Restart");
|
snprintf(LANGUAGE.Restart, sizeof(LANGUAGE.Restart), "Restart");
|
||||||
snprintf(LANGUAGE.Restarting, sizeof(LANGUAGE.Restarting), "Restarting...");
|
snprintf(LANGUAGE.Restarting, sizeof(LANGUAGE.Restarting), "Restarting...");
|
||||||
snprintf(LANGUAGE.Return, sizeof(LANGUAGE.Return), "Return");
|
snprintf(LANGUAGE.Return, sizeof(LANGUAGE.Return), "Return");
|
||||||
|
snprintf(LANGUAGE.released, sizeof(LANGUAGE.released), "Released");
|
||||||
snprintf(LANGUAGE.ReturntoWiiMenu, sizeof(LANGUAGE.ReturntoWiiMenu), "Return to Wii Menu");
|
snprintf(LANGUAGE.ReturntoWiiMenu, sizeof(LANGUAGE.ReturntoWiiMenu), "Return to Wii Menu");
|
||||||
snprintf(LANGUAGE.Right, sizeof(LANGUAGE.Right), "Right");
|
snprintf(LANGUAGE.Right, sizeof(LANGUAGE.Right), "Right");
|
||||||
snprintf(LANGUAGE.Rumble, sizeof(LANGUAGE.Rumble), "Rumble");
|
snprintf(LANGUAGE.Rumble, sizeof(LANGUAGE.Rumble), "Rumble");
|
||||||
@ -255,6 +256,21 @@ snprintf(LANGUAGE.Dutch, sizeof(LANGUAGE.Dutch), "Dutch");
|
|||||||
snprintf(LANGUAGE.SChinese, sizeof(LANGUAGE.SChinese), "SChinese");
|
snprintf(LANGUAGE.SChinese, sizeof(LANGUAGE.SChinese), "SChinese");
|
||||||
snprintf(LANGUAGE.TChinese, sizeof(LANGUAGE.TChinese), "TChinese");
|
snprintf(LANGUAGE.TChinese, sizeof(LANGUAGE.TChinese), "TChinese");
|
||||||
snprintf(LANGUAGE.Korean, sizeof(LANGUAGE.Korean), "Korean");
|
snprintf(LANGUAGE.Korean, sizeof(LANGUAGE.Korean), "Korean");
|
||||||
|
snprintf(LANGUAGE.january, sizeof(LANGUAGE.january), "Jan");
|
||||||
|
snprintf(LANGUAGE.february, sizeof(LANGUAGE.february), "Feb");
|
||||||
|
snprintf(LANGUAGE.march, sizeof(LANGUAGE.march), "Mar");
|
||||||
|
snprintf(LANGUAGE.april, sizeof(LANGUAGE.april), "Apr");
|
||||||
|
snprintf(LANGUAGE.may, sizeof(LANGUAGE.may), "May");
|
||||||
|
snprintf(LANGUAGE.june, sizeof(LANGUAGE.june), "June");
|
||||||
|
snprintf(LANGUAGE.july, sizeof(LANGUAGE.july), "July");
|
||||||
|
snprintf(LANGUAGE.august, sizeof(LANGUAGE.august), "Aug");
|
||||||
|
snprintf(LANGUAGE.september, sizeof(LANGUAGE.september), "Sept");
|
||||||
|
snprintf(LANGUAGE.october, sizeof(LANGUAGE.october), "Oct");
|
||||||
|
snprintf(LANGUAGE.november, sizeof(LANGUAGE.november), "Nov");
|
||||||
|
snprintf(LANGUAGE.december, sizeof(LANGUAGE.december), "Dec");
|
||||||
|
snprintf(LANGUAGE.developedby, sizeof(LANGUAGE.developedby), "Developed by");
|
||||||
|
snprintf(LANGUAGE.publishedby, sizeof(LANGUAGE.publishedby), "Published by");
|
||||||
|
snprintf(LANGUAGE.wififeatures, sizeof(LANGUAGE.wififeatures), "WiFi Features");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,7 +10,25 @@ extern "C"
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct LANGUAGE
|
struct LANGUAGE
|
||||||
{
|
{
|
||||||
|
char released[15];
|
||||||
|
char publishedby[25];
|
||||||
|
char developedby[25];
|
||||||
|
char january[15];
|
||||||
|
char february[15];
|
||||||
|
char march[15];
|
||||||
|
char april[15];
|
||||||
|
char may[15];
|
||||||
|
char june[15];
|
||||||
|
char july[15];
|
||||||
|
char august[15];
|
||||||
|
char september[15];
|
||||||
|
char october[15];
|
||||||
|
char november[15];
|
||||||
|
char december[15];
|
||||||
|
char wififeatures[20];
|
||||||
|
|
||||||
|
|
||||||
char t3Covers[50];
|
char t3Covers[50];
|
||||||
char addToFavorite[50];
|
char addToFavorite[50];
|
||||||
char all[30];
|
char all[30];
|
||||||
|
2107
source/menu.cpp
305
source/mxml/mxml.h
Normal file
@ -0,0 +1,305 @@
|
|||||||
|
/*
|
||||||
|
* "$Id: mxml.h 307 2007-09-15 20:03:15Z mike $"
|
||||||
|
*
|
||||||
|
* Header file for Mini-XML, a small XML-like file parsing library.
|
||||||
|
*
|
||||||
|
* Copyright 2003-2007 by Michael Sweet.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2, 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Prevent multiple inclusion...
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _mxml_h_
|
||||||
|
# define _mxml_h_
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Include necessary headers...
|
||||||
|
*/
|
||||||
|
|
||||||
|
# include <stdio.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
# include <string.h>
|
||||||
|
# include <ctype.h>
|
||||||
|
# include <errno.h>
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Constants...
|
||||||
|
*/
|
||||||
|
|
||||||
|
# define MXML_TAB 8 /* Tabs every N columns */
|
||||||
|
|
||||||
|
# define MXML_NO_CALLBACK 0 /* Don't use a type callback */
|
||||||
|
# define MXML_INTEGER_CALLBACK mxml_integer_cb
|
||||||
|
/* Treat all data as integers */
|
||||||
|
# define MXML_OPAQUE_CALLBACK mxml_opaque_cb
|
||||||
|
/* Treat all data as opaque */
|
||||||
|
# define MXML_REAL_CALLBACK mxml_real_cb
|
||||||
|
/* Treat all data as real numbers */
|
||||||
|
# define MXML_TEXT_CALLBACK 0 /* Treat all data as text */
|
||||||
|
# define MXML_IGNORE_CALLBACK mxml_ignore_cb
|
||||||
|
/* Ignore all non-element content */
|
||||||
|
|
||||||
|
# define MXML_NO_PARENT 0 /* No parent for the node */
|
||||||
|
|
||||||
|
# define MXML_DESCEND 1 /* Descend when finding/walking */
|
||||||
|
# define MXML_NO_DESCEND 0 /* Don't descend when finding/walking */
|
||||||
|
# define MXML_DESCEND_FIRST -1 /* Descend for first find */
|
||||||
|
|
||||||
|
# define MXML_WS_BEFORE_OPEN 0 /* Callback for before open tag */
|
||||||
|
# define MXML_WS_AFTER_OPEN 1 /* Callback for after open tag */
|
||||||
|
# define MXML_WS_BEFORE_CLOSE 2 /* Callback for before close tag */
|
||||||
|
# define MXML_WS_AFTER_CLOSE 3 /* Callback for after close tag */
|
||||||
|
|
||||||
|
# define MXML_ADD_BEFORE 0 /* Add node before specified node */
|
||||||
|
# define MXML_ADD_AFTER 1 /* Add node after specified node */
|
||||||
|
# define MXML_ADD_TO_PARENT NULL /* Add node relative to parent */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Data types...
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef enum mxml_sax_event_e /**** SAX event type. ****/
|
||||||
|
{
|
||||||
|
MXML_SAX_CDATA, /* CDATA node */
|
||||||
|
MXML_SAX_COMMENT, /* Comment node */
|
||||||
|
MXML_SAX_DATA, /* Data node */
|
||||||
|
MXML_SAX_DIRECTIVE, /* Processing directive node */
|
||||||
|
MXML_SAX_ELEMENT_CLOSE, /* Element closed */
|
||||||
|
MXML_SAX_ELEMENT_OPEN /* Element opened */
|
||||||
|
} mxml_sax_event_t;
|
||||||
|
|
||||||
|
typedef enum mxml_type_e /**** The XML node type. ****/
|
||||||
|
{
|
||||||
|
MXML_IGNORE = -1, /* Ignore/throw away node @since Mini-XML 2.3@ */
|
||||||
|
MXML_ELEMENT, /* XML element with attributes */
|
||||||
|
MXML_INTEGER, /* Integer value */
|
||||||
|
MXML_OPAQUE, /* Opaque string */
|
||||||
|
MXML_REAL, /* Real value */
|
||||||
|
MXML_TEXT, /* Text fragment */
|
||||||
|
MXML_CUSTOM /* Custom data @since Mini-XML 2.1@ */
|
||||||
|
} mxml_type_t;
|
||||||
|
|
||||||
|
typedef void (*mxml_custom_destroy_cb_t)(void *);
|
||||||
|
/**** Custom data destructor ****/
|
||||||
|
|
||||||
|
typedef void (*mxml_error_cb_t)(const char *);
|
||||||
|
/**** Error callback function ****/
|
||||||
|
|
||||||
|
typedef struct mxml_attr_s /**** An XML element attribute value. ****/
|
||||||
|
{
|
||||||
|
char *name; /* Attribute name */
|
||||||
|
char *value; /* Attribute value */
|
||||||
|
} mxml_attr_t;
|
||||||
|
|
||||||
|
typedef struct mxml_element_s /**** An XML element value. ****/
|
||||||
|
{
|
||||||
|
char *name; /* Name of element */
|
||||||
|
int num_attrs; /* Number of attributes */
|
||||||
|
mxml_attr_t *attrs; /* Attributes */
|
||||||
|
} mxml_element_t;
|
||||||
|
|
||||||
|
typedef struct mxml_text_s /**** An XML text value. ****/
|
||||||
|
{
|
||||||
|
int whitespace; /* Leading whitespace? */
|
||||||
|
char *string; /* Fragment string */
|
||||||
|
} mxml_text_t;
|
||||||
|
|
||||||
|
typedef struct mxml_custom_s /**** An XML custom value. @since Mini-XML 2.1@ ****/
|
||||||
|
{
|
||||||
|
void *data; /* Pointer to (allocated) custom data */
|
||||||
|
mxml_custom_destroy_cb_t destroy; /* Pointer to destructor function */
|
||||||
|
} mxml_custom_t;
|
||||||
|
|
||||||
|
typedef union mxml_value_u /**** An XML node value. ****/
|
||||||
|
{
|
||||||
|
mxml_element_t element; /* Element */
|
||||||
|
int integer; /* Integer number */
|
||||||
|
char *opaque; /* Opaque string */
|
||||||
|
double real; /* Real number */
|
||||||
|
mxml_text_t text; /* Text fragment */
|
||||||
|
mxml_custom_t custom; /* Custom data @since Mini-XML 2.1@ */
|
||||||
|
} mxml_value_t;
|
||||||
|
|
||||||
|
typedef struct mxml_node_s /**** An XML node. ****/
|
||||||
|
{
|
||||||
|
mxml_type_t type; /* Node type */
|
||||||
|
struct mxml_node_s *next; /* Next node under same parent */
|
||||||
|
struct mxml_node_s *prev; /* Previous node under same parent */
|
||||||
|
struct mxml_node_s *parent; /* Parent node */
|
||||||
|
struct mxml_node_s *child; /* First child node */
|
||||||
|
struct mxml_node_s *last_child; /* Last child node */
|
||||||
|
mxml_value_t value; /* Node value */
|
||||||
|
int ref_count; /* Use count */
|
||||||
|
void *user_data; /* User data */
|
||||||
|
} mxml_node_t;
|
||||||
|
|
||||||
|
typedef struct mxml_index_s /**** An XML node index. ****/
|
||||||
|
{
|
||||||
|
char *attr; /* Attribute used for indexing or NULL */
|
||||||
|
int num_nodes; /* Number of nodes in index */
|
||||||
|
int alloc_nodes; /* Allocated nodes in index */
|
||||||
|
int cur_node; /* Current node */
|
||||||
|
mxml_node_t **nodes; /* Node array */
|
||||||
|
} mxml_index_t;
|
||||||
|
|
||||||
|
typedef int (*mxml_custom_load_cb_t)(mxml_node_t *, const char *);
|
||||||
|
/**** Custom data load callback function ****/
|
||||||
|
|
||||||
|
typedef char *(*mxml_custom_save_cb_t)(mxml_node_t *);
|
||||||
|
/**** Custom data save callback function ****/
|
||||||
|
|
||||||
|
typedef mxml_type_t (*mxml_load_cb_t)(mxml_node_t *);
|
||||||
|
/**** Load callback function ****/
|
||||||
|
|
||||||
|
typedef const char *(*mxml_save_cb_t)(mxml_node_t *, int);
|
||||||
|
/**** Save callback function ****/
|
||||||
|
|
||||||
|
typedef void (*mxml_sax_cb_t)(mxml_node_t *, mxml_sax_event_t, void *);
|
||||||
|
/**** SAX callback function ****/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* C++ support...
|
||||||
|
*/
|
||||||
|
|
||||||
|
# ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
# endif /* __cplusplus */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Prototypes...
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern void mxmlAdd(mxml_node_t *parent, int where,
|
||||||
|
mxml_node_t *child, mxml_node_t *node);
|
||||||
|
extern void mxmlDelete(mxml_node_t *node);
|
||||||
|
extern void mxmlElementDeleteAttr(mxml_node_t *node,
|
||||||
|
const char *name);
|
||||||
|
extern const char *mxmlElementGetAttr(mxml_node_t *node, const char *name);
|
||||||
|
extern void mxmlElementSetAttr(mxml_node_t *node, const char *name,
|
||||||
|
const char *value);
|
||||||
|
extern void mxmlElementSetAttrf(mxml_node_t *node, const char *name,
|
||||||
|
const char *format, ...)
|
||||||
|
# ifdef __GNUC__
|
||||||
|
__attribute__ ((__format__ (__printf__, 3, 4)))
|
||||||
|
# endif /* __GNUC__ */
|
||||||
|
;
|
||||||
|
extern int mxmlEntityAddCallback(int (*cb)(const char *name));
|
||||||
|
extern const char *mxmlEntityGetName(int val);
|
||||||
|
extern int mxmlEntityGetValue(const char *name);
|
||||||
|
extern void mxmlEntityRemoveCallback(int (*cb)(const char *name));
|
||||||
|
extern mxml_node_t *mxmlFindElement(mxml_node_t *node, mxml_node_t *top,
|
||||||
|
const char *name, const char *attr,
|
||||||
|
const char *value, int descend);
|
||||||
|
extern void mxmlIndexDelete(mxml_index_t *ind);
|
||||||
|
extern mxml_node_t *mxmlIndexEnum(mxml_index_t *ind);
|
||||||
|
extern mxml_node_t *mxmlIndexFind(mxml_index_t *ind,
|
||||||
|
const char *element,
|
||||||
|
const char *value);
|
||||||
|
extern mxml_index_t *mxmlIndexNew(mxml_node_t *node, const char *element,
|
||||||
|
const char *attr);
|
||||||
|
extern mxml_node_t *mxmlIndexReset(mxml_index_t *ind);
|
||||||
|
extern mxml_node_t *mxmlLoadFd(mxml_node_t *top, int fd,
|
||||||
|
mxml_type_t (*cb)(mxml_node_t *));
|
||||||
|
extern mxml_node_t *mxmlLoadFile(mxml_node_t *top, FILE *fp,
|
||||||
|
mxml_type_t (*cb)(mxml_node_t *));
|
||||||
|
extern mxml_node_t *mxmlLoadString(mxml_node_t *top, const char *s,
|
||||||
|
mxml_type_t (*cb)(mxml_node_t *));
|
||||||
|
extern mxml_node_t *mxmlNewCDATA(mxml_node_t *parent, const char *string);
|
||||||
|
extern mxml_node_t *mxmlNewCustom(mxml_node_t *parent, void *data,
|
||||||
|
mxml_custom_destroy_cb_t destroy);
|
||||||
|
extern mxml_node_t *mxmlNewElement(mxml_node_t *parent, const char *name);
|
||||||
|
extern mxml_node_t *mxmlNewInteger(mxml_node_t *parent, int integer);
|
||||||
|
extern mxml_node_t *mxmlNewOpaque(mxml_node_t *parent, const char *opaque);
|
||||||
|
extern mxml_node_t *mxmlNewReal(mxml_node_t *parent, double real);
|
||||||
|
extern mxml_node_t *mxmlNewText(mxml_node_t *parent, int whitespace,
|
||||||
|
const char *string);
|
||||||
|
extern mxml_node_t *mxmlNewTextf(mxml_node_t *parent, int whitespace,
|
||||||
|
const char *format, ...)
|
||||||
|
# ifdef __GNUC__
|
||||||
|
__attribute__ ((__format__ (__printf__, 3, 4)))
|
||||||
|
# endif /* __GNUC__ */
|
||||||
|
;
|
||||||
|
extern mxml_node_t *mxmlNewXML(const char *version);
|
||||||
|
extern int mxmlRelease(mxml_node_t *node);
|
||||||
|
extern void mxmlRemove(mxml_node_t *node);
|
||||||
|
extern int mxmlRetain(mxml_node_t *node);
|
||||||
|
extern char *mxmlSaveAllocString(mxml_node_t *node,
|
||||||
|
mxml_save_cb_t cb);
|
||||||
|
extern int mxmlSaveFd(mxml_node_t *node, int fd,
|
||||||
|
mxml_save_cb_t cb);
|
||||||
|
extern int mxmlSaveFile(mxml_node_t *node, FILE *fp,
|
||||||
|
mxml_save_cb_t cb);
|
||||||
|
extern int mxmlSaveString(mxml_node_t *node, char *buffer,
|
||||||
|
int bufsize, mxml_save_cb_t cb);
|
||||||
|
extern mxml_node_t *mxmlSAXLoadFd(mxml_node_t *top, int fd,
|
||||||
|
mxml_type_t (*cb)(mxml_node_t *),
|
||||||
|
mxml_sax_cb_t sax, void *sax_data);
|
||||||
|
extern mxml_node_t *mxmlSAXLoadFile(mxml_node_t *top, FILE *fp,
|
||||||
|
mxml_type_t (*cb)(mxml_node_t *),
|
||||||
|
mxml_sax_cb_t sax, void *sax_data);
|
||||||
|
extern mxml_node_t *mxmlSAXLoadString(mxml_node_t *top, const char *s,
|
||||||
|
mxml_type_t (*cb)(mxml_node_t *),
|
||||||
|
mxml_sax_cb_t sax, void *sax_data);
|
||||||
|
extern int mxmlSetCDATA(mxml_node_t *node, const char *data);
|
||||||
|
extern int mxmlSetCustom(mxml_node_t *node, void *data,
|
||||||
|
mxml_custom_destroy_cb_t destroy);
|
||||||
|
extern void mxmlSetCustomHandlers(mxml_custom_load_cb_t load,
|
||||||
|
mxml_custom_save_cb_t save);
|
||||||
|
extern int mxmlSetElement(mxml_node_t *node, const char *name);
|
||||||
|
extern void mxmlSetErrorCallback(mxml_error_cb_t cb);
|
||||||
|
extern int mxmlSetInteger(mxml_node_t *node, int integer);
|
||||||
|
extern int mxmlSetOpaque(mxml_node_t *node, const char *opaque);
|
||||||
|
extern int mxmlSetReal(mxml_node_t *node, double real);
|
||||||
|
extern int mxmlSetText(mxml_node_t *node, int whitespace,
|
||||||
|
const char *string);
|
||||||
|
extern int mxmlSetTextf(mxml_node_t *node, int whitespace,
|
||||||
|
const char *format, ...)
|
||||||
|
# ifdef __GNUC__
|
||||||
|
__attribute__ ((__format__ (__printf__, 3, 4)))
|
||||||
|
# endif /* __GNUC__ */
|
||||||
|
;
|
||||||
|
extern void mxmlSetWrapMargin(int column);
|
||||||
|
extern mxml_node_t *mxmlWalkNext(mxml_node_t *node, mxml_node_t *top,
|
||||||
|
int descend);
|
||||||
|
extern mxml_node_t *mxmlWalkPrev(mxml_node_t *node, mxml_node_t *top,
|
||||||
|
int descend);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Semi-private functions...
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern void mxml_error(const char *format, ...);
|
||||||
|
extern mxml_type_t mxml_ignore_cb(mxml_node_t *node);
|
||||||
|
extern mxml_type_t mxml_integer_cb(mxml_node_t *node);
|
||||||
|
extern mxml_type_t mxml_opaque_cb(mxml_node_t *node);
|
||||||
|
extern mxml_type_t mxml_real_cb(mxml_node_t *node);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* C++ support...
|
||||||
|
*/
|
||||||
|
|
||||||
|
# ifdef __cplusplus
|
||||||
|
}
|
||||||
|
# endif /* __cplusplus */
|
||||||
|
#endif /* !_mxml_h_ */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* End of "$Id: mxml.h 307 2007-09-15 20:03:15Z mike $".
|
||||||
|
*/
|
132
source/unzip/crypt.h
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
/* crypt.h -- base code for crypt/uncrypt ZIPfile
|
||||||
|
|
||||||
|
|
||||||
|
Version 1.01e, February 12th, 2005
|
||||||
|
|
||||||
|
Copyright (C) 1998-2005 Gilles Vollant
|
||||||
|
|
||||||
|
This code is a modified version of crypting code in Infozip distribution
|
||||||
|
|
||||||
|
The encryption/decryption parts of this source code (as opposed to the
|
||||||
|
non-echoing password parts) were originally written in Europe. The
|
||||||
|
whole source package can be freely distributed, including from the USA.
|
||||||
|
(Prior to January 2000, re-export from the US was a violation of US law.)
|
||||||
|
|
||||||
|
This encryption code is a direct transcription of the algorithm from
|
||||||
|
Roger Schlafly, described by Phil Katz in the file appnote.txt. This
|
||||||
|
file (appnote.txt) is distributed with the PKZIP program (even in the
|
||||||
|
version without encryption capabilities).
|
||||||
|
|
||||||
|
If you don't need crypting in your application, just define symbols
|
||||||
|
NOCRYPT and NOUNCRYPT.
|
||||||
|
|
||||||
|
This code support the "Traditional PKWARE Encryption".
|
||||||
|
|
||||||
|
The new AES encryption added on Zip format by Winzip (see the page
|
||||||
|
http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong
|
||||||
|
Encryption is not supported.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* Return the next byte in the pseudo-random sequence
|
||||||
|
*/
|
||||||
|
static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
|
||||||
|
{
|
||||||
|
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
|
||||||
|
* unpredictable manner on 16-bit systems; not a problem
|
||||||
|
* with any known compiler so far, though */
|
||||||
|
|
||||||
|
temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
|
||||||
|
return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* Update the encryption keys with the next byte of plain text
|
||||||
|
*/
|
||||||
|
static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c)
|
||||||
|
{
|
||||||
|
(*(pkeys+0)) = CRC32((*(pkeys+0)), c);
|
||||||
|
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
|
||||||
|
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
|
||||||
|
{
|
||||||
|
register int keyshift = (int)((*(pkeys+1)) >> 24);
|
||||||
|
(*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* Initialize the encryption keys and the random header according to
|
||||||
|
* the given password.
|
||||||
|
*/
|
||||||
|
static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab)
|
||||||
|
{
|
||||||
|
*(pkeys+0) = 305419896L;
|
||||||
|
*(pkeys+1) = 591751049L;
|
||||||
|
*(pkeys+2) = 878082192L;
|
||||||
|
while (*passwd != '\0') {
|
||||||
|
update_keys(pkeys,pcrc_32_tab,(int)*passwd);
|
||||||
|
passwd++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#define zdecode(pkeys,pcrc_32_tab,c) \
|
||||||
|
(update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
|
||||||
|
|
||||||
|
#define zencode(pkeys,pcrc_32_tab,c,t) \
|
||||||
|
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
|
||||||
|
|
||||||
|
#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
|
||||||
|
|
||||||
|
#define RAND_HEAD_LEN 12
|
||||||
|
/* "last resort" source for second part of crypt seed pattern */
|
||||||
|
# ifndef ZCR_SEED2
|
||||||
|
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
|
||||||
|
# endif
|
||||||
|
|
||||||
|
static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
|
||||||
|
const char *passwd; /* password string */
|
||||||
|
unsigned char *buf; /* where to write header */
|
||||||
|
int bufSize;
|
||||||
|
unsigned long* pkeys;
|
||||||
|
const unsigned long* pcrc_32_tab;
|
||||||
|
unsigned long crcForCrypting;
|
||||||
|
{
|
||||||
|
int n; /* index in random header */
|
||||||
|
int t; /* temporary */
|
||||||
|
int c; /* random byte */
|
||||||
|
unsigned char header[RAND_HEAD_LEN-2]; /* random header */
|
||||||
|
static unsigned calls = 0; /* ensure different random header each time */
|
||||||
|
|
||||||
|
if (bufSize<RAND_HEAD_LEN)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
|
||||||
|
* output of rand() to get less predictability, since rand() is
|
||||||
|
* often poorly implemented.
|
||||||
|
*/
|
||||||
|
if (++calls == 1)
|
||||||
|
{
|
||||||
|
srand((unsigned)(time(NULL) ^ ZCR_SEED2));
|
||||||
|
}
|
||||||
|
init_keys(passwd, pkeys, pcrc_32_tab);
|
||||||
|
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
||||||
|
{
|
||||||
|
c = (rand() >> 7) & 0xff;
|
||||||
|
header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
|
||||||
|
}
|
||||||
|
/* Encrypt random header (last two bytes is high word of crc) */
|
||||||
|
init_keys(passwd, pkeys, pcrc_32_tab);
|
||||||
|
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
||||||
|
{
|
||||||
|
buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
|
||||||
|
}
|
||||||
|
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
|
||||||
|
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
177
source/unzip/ioapi.c
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
/* ioapi.c -- IO base function header for compress/uncompress .zip
|
||||||
|
files using zlib + zip or unzip API
|
||||||
|
|
||||||
|
Version 1.01e, February 12th, 2005
|
||||||
|
|
||||||
|
Copyright (C) 1998-2005 Gilles Vollant
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "zlib.h"
|
||||||
|
#include "ioapi.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
|
||||||
|
|
||||||
|
#ifndef SEEK_CUR
|
||||||
|
#define SEEK_CUR 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SEEK_END
|
||||||
|
#define SEEK_END 2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SEEK_SET
|
||||||
|
#define SEEK_SET 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
voidpf ZCALLBACK fopen_file_func OF((
|
||||||
|
voidpf opaque,
|
||||||
|
const char* filename,
|
||||||
|
int mode));
|
||||||
|
|
||||||
|
uLong ZCALLBACK fread_file_func OF((
|
||||||
|
voidpf opaque,
|
||||||
|
voidpf stream,
|
||||||
|
void* buf,
|
||||||
|
uLong size));
|
||||||
|
|
||||||
|
uLong ZCALLBACK fwrite_file_func OF((
|
||||||
|
voidpf opaque,
|
||||||
|
voidpf stream,
|
||||||
|
const void* buf,
|
||||||
|
uLong size));
|
||||||
|
|
||||||
|
long ZCALLBACK ftell_file_func OF((
|
||||||
|
voidpf opaque,
|
||||||
|
voidpf stream));
|
||||||
|
|
||||||
|
long ZCALLBACK fseek_file_func OF((
|
||||||
|
voidpf opaque,
|
||||||
|
voidpf stream,
|
||||||
|
uLong offset,
|
||||||
|
int origin));
|
||||||
|
|
||||||
|
int ZCALLBACK fclose_file_func OF((
|
||||||
|
voidpf opaque,
|
||||||
|
voidpf stream));
|
||||||
|
|
||||||
|
int ZCALLBACK ferror_file_func OF((
|
||||||
|
voidpf opaque,
|
||||||
|
voidpf stream));
|
||||||
|
|
||||||
|
|
||||||
|
voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
|
||||||
|
voidpf opaque;
|
||||||
|
const char* filename;
|
||||||
|
int mode;
|
||||||
|
{
|
||||||
|
FILE* file = NULL;
|
||||||
|
const char* mode_fopen = NULL;
|
||||||
|
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
|
||||||
|
mode_fopen = "rb";
|
||||||
|
else
|
||||||
|
if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
||||||
|
mode_fopen = "r+b";
|
||||||
|
else
|
||||||
|
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
||||||
|
mode_fopen = "wb";
|
||||||
|
|
||||||
|
if ((filename!=NULL) && (mode_fopen != NULL))
|
||||||
|
file = fopen(filename, mode_fopen);
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uLong ZCALLBACK fread_file_func (opaque, stream, buf, size)
|
||||||
|
voidpf opaque;
|
||||||
|
voidpf stream;
|
||||||
|
void* buf;
|
||||||
|
uLong size;
|
||||||
|
{
|
||||||
|
uLong ret;
|
||||||
|
ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)
|
||||||
|
voidpf opaque;
|
||||||
|
voidpf stream;
|
||||||
|
const void* buf;
|
||||||
|
uLong size;
|
||||||
|
{
|
||||||
|
uLong ret;
|
||||||
|
ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
long ZCALLBACK ftell_file_func (opaque, stream)
|
||||||
|
voidpf opaque;
|
||||||
|
voidpf stream;
|
||||||
|
{
|
||||||
|
long ret;
|
||||||
|
ret = ftell((FILE *)stream);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
|
||||||
|
voidpf opaque;
|
||||||
|
voidpf stream;
|
||||||
|
uLong offset;
|
||||||
|
int origin;
|
||||||
|
{
|
||||||
|
int fseek_origin=0;
|
||||||
|
long ret;
|
||||||
|
switch (origin)
|
||||||
|
{
|
||||||
|
case ZLIB_FILEFUNC_SEEK_CUR :
|
||||||
|
fseek_origin = SEEK_CUR;
|
||||||
|
break;
|
||||||
|
case ZLIB_FILEFUNC_SEEK_END :
|
||||||
|
fseek_origin = SEEK_END;
|
||||||
|
break;
|
||||||
|
case ZLIB_FILEFUNC_SEEK_SET :
|
||||||
|
fseek_origin = SEEK_SET;
|
||||||
|
break;
|
||||||
|
default: return -1;
|
||||||
|
}
|
||||||
|
ret = 0;
|
||||||
|
fseek((FILE *)stream, offset, fseek_origin);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ZCALLBACK fclose_file_func (opaque, stream)
|
||||||
|
voidpf opaque;
|
||||||
|
voidpf stream;
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
ret = fclose((FILE *)stream);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ZCALLBACK ferror_file_func (opaque, stream)
|
||||||
|
voidpf opaque;
|
||||||
|
voidpf stream;
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
ret = ferror((FILE *)stream);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fill_fopen_filefunc (pzlib_filefunc_def)
|
||||||
|
zlib_filefunc_def* pzlib_filefunc_def;
|
||||||
|
{
|
||||||
|
pzlib_filefunc_def->zopen_file = fopen_file_func;
|
||||||
|
pzlib_filefunc_def->zread_file = fread_file_func;
|
||||||
|
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
|
||||||
|
pzlib_filefunc_def->ztell_file = ftell_file_func;
|
||||||
|
pzlib_filefunc_def->zseek_file = fseek_file_func;
|
||||||
|
pzlib_filefunc_def->zclose_file = fclose_file_func;
|
||||||
|
pzlib_filefunc_def->zerror_file = ferror_file_func;
|
||||||
|
pzlib_filefunc_def->opaque = NULL;
|
||||||
|
}
|
75
source/unzip/ioapi.h
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/* ioapi.h -- IO base function header for compress/uncompress .zip
|
||||||
|
files using zlib + zip or unzip API
|
||||||
|
|
||||||
|
Version 1.01e, February 12th, 2005
|
||||||
|
|
||||||
|
Copyright (C) 1998-2005 Gilles Vollant
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _ZLIBIOAPI_H
|
||||||
|
#define _ZLIBIOAPI_H
|
||||||
|
|
||||||
|
|
||||||
|
#define ZLIB_FILEFUNC_SEEK_CUR (1)
|
||||||
|
#define ZLIB_FILEFUNC_SEEK_END (2)
|
||||||
|
#define ZLIB_FILEFUNC_SEEK_SET (0)
|
||||||
|
|
||||||
|
#define ZLIB_FILEFUNC_MODE_READ (1)
|
||||||
|
#define ZLIB_FILEFUNC_MODE_WRITE (2)
|
||||||
|
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
|
||||||
|
|
||||||
|
#define ZLIB_FILEFUNC_MODE_EXISTING (4)
|
||||||
|
#define ZLIB_FILEFUNC_MODE_CREATE (8)
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef ZCALLBACK
|
||||||
|
|
||||||
|
#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
|
||||||
|
#define ZCALLBACK CALLBACK
|
||||||
|
#else
|
||||||
|
#define ZCALLBACK
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
|
||||||
|
typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
|
||||||
|
typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
|
||||||
|
typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
|
||||||
|
typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
|
||||||
|
typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
|
||||||
|
typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
|
||||||
|
|
||||||
|
typedef struct zlib_filefunc_def_s
|
||||||
|
{
|
||||||
|
open_file_func zopen_file;
|
||||||
|
read_file_func zread_file;
|
||||||
|
write_file_func zwrite_file;
|
||||||
|
tell_file_func ztell_file;
|
||||||
|
seek_file_func zseek_file;
|
||||||
|
close_file_func zclose_file;
|
||||||
|
testerror_file_func zerror_file;
|
||||||
|
voidpf opaque;
|
||||||
|
} zlib_filefunc_def;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
|
||||||
|
|
||||||
|
#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size))
|
||||||
|
#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size))
|
||||||
|
#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream))
|
||||||
|
#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode))
|
||||||
|
#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream))
|
||||||
|
#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream))
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
276
source/unzip/miniunz.c
Normal file
@ -0,0 +1,276 @@
|
|||||||
|
/*
|
||||||
|
miniunz.c
|
||||||
|
Version 1.01e, February 12th, 2005
|
||||||
|
|
||||||
|
Copyright (C) 1998-2005 Gilles Vollant
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
# include <unistd.h>
|
||||||
|
# include <utime.h>
|
||||||
|
|
||||||
|
#include "unzip.h"
|
||||||
|
|
||||||
|
#define CASESENSITIVITY (0)
|
||||||
|
#define WRITEBUFFERSIZE (8192)
|
||||||
|
#define MAXFILENAME (256)
|
||||||
|
|
||||||
|
static int mymkdir(const char* dirname)
|
||||||
|
{
|
||||||
|
int ret=0;
|
||||||
|
ret = mkdir (dirname,0775);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int makedir (char *newdir)
|
||||||
|
{
|
||||||
|
char *buffer ;
|
||||||
|
char *p;
|
||||||
|
int len = (int)strlen(newdir);
|
||||||
|
|
||||||
|
if (len <= 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
buffer = (char*)malloc(len+1);
|
||||||
|
strcpy(buffer,newdir);
|
||||||
|
|
||||||
|
if (buffer[len-1] == '/') {
|
||||||
|
buffer[len-1] = '\0';
|
||||||
|
}
|
||||||
|
if (mymkdir(buffer) == 0)
|
||||||
|
{
|
||||||
|
free(buffer);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
p = buffer+1;
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
char hold;
|
||||||
|
|
||||||
|
while(*p && *p != '\\' && *p != '/')
|
||||||
|
p++;
|
||||||
|
hold = *p;
|
||||||
|
*p = 0;
|
||||||
|
if ((mymkdir(buffer) == -1) && (errno == ENOENT))
|
||||||
|
{
|
||||||
|
printf("couldn't create directory %s\n",buffer);
|
||||||
|
free(buffer);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (hold == 0)
|
||||||
|
break;
|
||||||
|
*p++ = hold;
|
||||||
|
}
|
||||||
|
free(buffer);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int do_extract_currentfile(unzFile uf,const int* popt_extract_without_path,int* popt_overwrite,const char* password)
|
||||||
|
{
|
||||||
|
char filename_inzip[256];
|
||||||
|
char* filename_withoutpath;
|
||||||
|
char* p;
|
||||||
|
int err=UNZ_OK;
|
||||||
|
FILE *fout=NULL;
|
||||||
|
void* buf;
|
||||||
|
uInt size_buf;
|
||||||
|
|
||||||
|
unz_file_info file_info;
|
||||||
|
err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
|
||||||
|
|
||||||
|
if (err!=UNZ_OK)
|
||||||
|
{
|
||||||
|
printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_buf = WRITEBUFFERSIZE;
|
||||||
|
buf = (void*)malloc(size_buf);
|
||||||
|
if (buf==NULL)
|
||||||
|
{
|
||||||
|
printf("Error allocating memory\n");
|
||||||
|
return UNZ_INTERNALERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
p = filename_withoutpath = filename_inzip;
|
||||||
|
while ((*p) != '\0')
|
||||||
|
{
|
||||||
|
if (((*p)=='/') || ((*p)=='\\'))
|
||||||
|
filename_withoutpath = p+1;
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((*filename_withoutpath)=='\0')
|
||||||
|
{
|
||||||
|
if ((*popt_extract_without_path)==0)
|
||||||
|
{
|
||||||
|
printf("creating directory: %s\n",filename_inzip);
|
||||||
|
mymkdir(filename_inzip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char* write_filename;
|
||||||
|
int skip=0;
|
||||||
|
|
||||||
|
if ((*popt_extract_without_path)==0)
|
||||||
|
write_filename = filename_inzip;
|
||||||
|
else
|
||||||
|
write_filename = filename_withoutpath;
|
||||||
|
|
||||||
|
err = unzOpenCurrentFilePassword(uf,password);
|
||||||
|
if (err!=UNZ_OK)
|
||||||
|
{
|
||||||
|
printf("error %d with zipfile in unzOpenCurrentFilePassword\n",err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (((*popt_overwrite)==0) && (err==UNZ_OK))
|
||||||
|
{
|
||||||
|
char rep=0;
|
||||||
|
FILE* ftestexist;
|
||||||
|
ftestexist = fopen(write_filename,"rb");
|
||||||
|
if (ftestexist!=NULL)
|
||||||
|
{
|
||||||
|
fclose(ftestexist);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
char answer[128];
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
printf("The file %s exists. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename);
|
||||||
|
ret = scanf("%1s",answer);
|
||||||
|
if (ret != 1)
|
||||||
|
{
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
rep = answer[0] ;
|
||||||
|
if ((rep>='a') && (rep<='z'))
|
||||||
|
rep -= 0x20;
|
||||||
|
}
|
||||||
|
while ((rep!='Y') && (rep!='N') && (rep!='A'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rep == 'N')
|
||||||
|
skip = 1;
|
||||||
|
|
||||||
|
if (rep == 'A')
|
||||||
|
*popt_overwrite=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((skip==0) && (err==UNZ_OK))
|
||||||
|
{
|
||||||
|
fout=fopen(write_filename,"wb");
|
||||||
|
|
||||||
|
/* some zipfile don't contain directory alone before file */
|
||||||
|
if ((fout==NULL) && ((*popt_extract_without_path)==0) &&
|
||||||
|
(filename_withoutpath!=(char*)filename_inzip))
|
||||||
|
{
|
||||||
|
char c=*(filename_withoutpath-1);
|
||||||
|
*(filename_withoutpath-1)='\0';
|
||||||
|
makedir(write_filename);
|
||||||
|
*(filename_withoutpath-1)=c;
|
||||||
|
fout=fopen(write_filename,"wb");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fout==NULL)
|
||||||
|
{
|
||||||
|
printf("error opening %s\n",write_filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fout!=NULL)
|
||||||
|
{
|
||||||
|
printf(" extracting: %s\n",write_filename);
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
err = unzReadCurrentFile(uf,buf,size_buf);
|
||||||
|
if (err<0)
|
||||||
|
{
|
||||||
|
printf("error %d with zipfile in unzReadCurrentFile\n",err);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (err>0)
|
||||||
|
if (fwrite(buf,err,1,fout)!=1)
|
||||||
|
{
|
||||||
|
printf("error in writing extracted file\n");
|
||||||
|
err=UNZ_ERRNO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (err>0);
|
||||||
|
if (fout)
|
||||||
|
fclose(fout);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err==UNZ_OK)
|
||||||
|
{
|
||||||
|
err = unzCloseCurrentFile (uf);
|
||||||
|
if (err!=UNZ_OK)
|
||||||
|
{
|
||||||
|
printf("error %d with zipfile in unzCloseCurrentFile\n",err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
unzCloseCurrentFile(uf); /* don't lose the error */
|
||||||
|
}
|
||||||
|
|
||||||
|
free(buf);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int extractZip(unzFile uf,int opt_extract_without_path,int opt_overwrite,const char* password)
|
||||||
|
{
|
||||||
|
uLong i;
|
||||||
|
unz_global_info gi;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
err = unzGetGlobalInfo (uf,&gi);
|
||||||
|
if (err!=UNZ_OK)
|
||||||
|
printf("error %d with zipfile in unzGetGlobalInfo \n",err);
|
||||||
|
|
||||||
|
for (i=0;i<gi.number_entry;i++)
|
||||||
|
{
|
||||||
|
if (do_extract_currentfile(uf,&opt_extract_without_path,
|
||||||
|
&opt_overwrite,
|
||||||
|
password) != UNZ_OK)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if ((i+1)<gi.number_entry)
|
||||||
|
{
|
||||||
|
err = unzGoToNextFile(uf);
|
||||||
|
if (err!=UNZ_OK)
|
||||||
|
{
|
||||||
|
printf("error %d with zipfile in unzGoToNextFile\n",err);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int extractZipOnefile(unzFile uf,const char* filename,int opt_extract_without_path,int opt_overwrite,const char* password)
|
||||||
|
{
|
||||||
|
if (unzLocateFile(uf,filename,CASESENSITIVITY)!=UNZ_OK)
|
||||||
|
{
|
||||||
|
printf("file %s not found in the zipfile\n",filename);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (do_extract_currentfile(uf,&opt_extract_without_path,
|
||||||
|
&opt_overwrite,
|
||||||
|
password) == UNZ_OK)
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
17
source/unzip/miniunz.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
#ifndef _miniunz_H
|
||||||
|
#define _miniunz_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int extractZip(unzFile uf,int opt_extract_without_path,int opt_overwrite,const char* password);
|
||||||
|
int extractZipOnefile(unzFile uf,const char* filename,int opt_extract_without_path,int opt_overwrite,const char* password);
|
||||||
|
int makedir(char *newdir);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
281
source/unzip/mztools.c
Normal file
@ -0,0 +1,281 @@
|
|||||||
|
/*
|
||||||
|
Additional tools for Minizip
|
||||||
|
Code: Xavier Roche '2004
|
||||||
|
License: Same as ZLIB (www.gzip.org)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Code */
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "zlib.h"
|
||||||
|
#include "unzip.h"
|
||||||
|
|
||||||
|
#define READ_8(adr) ((unsigned char)*(adr))
|
||||||
|
#define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) )
|
||||||
|
#define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) )
|
||||||
|
|
||||||
|
#define WRITE_8(buff, n) do { \
|
||||||
|
*((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \
|
||||||
|
} while(0)
|
||||||
|
#define WRITE_16(buff, n) do { \
|
||||||
|
WRITE_8((unsigned char*)(buff), n); \
|
||||||
|
WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \
|
||||||
|
} while(0)
|
||||||
|
#define WRITE_32(buff, n) do { \
|
||||||
|
WRITE_16((unsigned char*)(buff), (n) & 0xffff); \
|
||||||
|
WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
|
extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered)
|
||||||
|
const char* file;
|
||||||
|
const char* fileOut;
|
||||||
|
const char* fileOutTmp;
|
||||||
|
uLong* nRecovered;
|
||||||
|
uLong* bytesRecovered;
|
||||||
|
{
|
||||||
|
int err = Z_OK;
|
||||||
|
FILE* fpZip = fopen(file, "rb");
|
||||||
|
FILE* fpOut = fopen(fileOut, "wb");
|
||||||
|
FILE* fpOutCD = fopen(fileOutTmp, "wb");
|
||||||
|
if (fpZip != NULL && fpOut != NULL) {
|
||||||
|
int entries = 0;
|
||||||
|
uLong totalBytes = 0;
|
||||||
|
char header[30];
|
||||||
|
char filename[256];
|
||||||
|
char extra[1024];
|
||||||
|
int offset = 0;
|
||||||
|
int offsetCD = 0;
|
||||||
|
while ( fread(header, 1, 30, fpZip) == 30 ) {
|
||||||
|
int currentOffset = offset;
|
||||||
|
|
||||||
|
/* File entry */
|
||||||
|
if (READ_32(header) == 0x04034b50) {
|
||||||
|
unsigned int version = READ_16(header + 4);
|
||||||
|
unsigned int gpflag = READ_16(header + 6);
|
||||||
|
unsigned int method = READ_16(header + 8);
|
||||||
|
unsigned int filetime = READ_16(header + 10);
|
||||||
|
unsigned int filedate = READ_16(header + 12);
|
||||||
|
unsigned int crc = READ_32(header + 14); /* crc */
|
||||||
|
unsigned int cpsize = READ_32(header + 18); /* compressed size */
|
||||||
|
unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */
|
||||||
|
unsigned int fnsize = READ_16(header + 26); /* file name length */
|
||||||
|
unsigned int extsize = READ_16(header + 28); /* extra field length */
|
||||||
|
filename[0] = extra[0] = '\0';
|
||||||
|
|
||||||
|
/* Header */
|
||||||
|
if (fwrite(header, 1, 30, fpOut) == 30) {
|
||||||
|
offset += 30;
|
||||||
|
} else {
|
||||||
|
err = Z_ERRNO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Filename */
|
||||||
|
if (fnsize > 0) {
|
||||||
|
if (fread(filename, 1, fnsize, fpZip) == fnsize) {
|
||||||
|
if (fwrite(filename, 1, fnsize, fpOut) == fnsize) {
|
||||||
|
offset += fnsize;
|
||||||
|
} else {
|
||||||
|
err = Z_ERRNO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = Z_ERRNO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = Z_STREAM_ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Extra field */
|
||||||
|
if (extsize > 0) {
|
||||||
|
if (fread(extra, 1, extsize, fpZip) == extsize) {
|
||||||
|
if (fwrite(extra, 1, extsize, fpOut) == extsize) {
|
||||||
|
offset += extsize;
|
||||||
|
} else {
|
||||||
|
err = Z_ERRNO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = Z_ERRNO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Data */
|
||||||
|
{
|
||||||
|
int dataSize = cpsize;
|
||||||
|
if (dataSize == 0) {
|
||||||
|
dataSize = uncpsize;
|
||||||
|
}
|
||||||
|
if (dataSize > 0) {
|
||||||
|
char* data = malloc(dataSize);
|
||||||
|
if (data != NULL) {
|
||||||
|
if ((int)fread(data, 1, dataSize, fpZip) == dataSize) {
|
||||||
|
if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) {
|
||||||
|
offset += dataSize;
|
||||||
|
totalBytes += dataSize;
|
||||||
|
} else {
|
||||||
|
err = Z_ERRNO;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = Z_ERRNO;
|
||||||
|
}
|
||||||
|
free(data);
|
||||||
|
if (err != Z_OK) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = Z_MEM_ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Central directory entry */
|
||||||
|
{
|
||||||
|
char header[46];
|
||||||
|
char* comment = "";
|
||||||
|
int comsize = (int) strlen(comment);
|
||||||
|
WRITE_32(header, 0x02014b50);
|
||||||
|
WRITE_16(header + 4, version);
|
||||||
|
WRITE_16(header + 6, version);
|
||||||
|
WRITE_16(header + 8, gpflag);
|
||||||
|
WRITE_16(header + 10, method);
|
||||||
|
WRITE_16(header + 12, filetime);
|
||||||
|
WRITE_16(header + 14, filedate);
|
||||||
|
WRITE_32(header + 16, crc);
|
||||||
|
WRITE_32(header + 20, cpsize);
|
||||||
|
WRITE_32(header + 24, uncpsize);
|
||||||
|
WRITE_16(header + 28, fnsize);
|
||||||
|
WRITE_16(header + 30, extsize);
|
||||||
|
WRITE_16(header + 32, comsize);
|
||||||
|
WRITE_16(header + 34, 0); /* disk # */
|
||||||
|
WRITE_16(header + 36, 0); /* int attrb */
|
||||||
|
WRITE_32(header + 38, 0); /* ext attrb */
|
||||||
|
WRITE_32(header + 42, currentOffset);
|
||||||
|
/* Header */
|
||||||
|
if (fwrite(header, 1, 46, fpOutCD) == 46) {
|
||||||
|
offsetCD += 46;
|
||||||
|
|
||||||
|
/* Filename */
|
||||||
|
if (fnsize > 0) {
|
||||||
|
if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) {
|
||||||
|
offsetCD += fnsize;
|
||||||
|
} else {
|
||||||
|
err = Z_ERRNO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = Z_STREAM_ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Extra field */
|
||||||
|
if (extsize > 0) {
|
||||||
|
if (fwrite(extra, 1, extsize, fpOutCD) == extsize) {
|
||||||
|
offsetCD += extsize;
|
||||||
|
} else {
|
||||||
|
err = Z_ERRNO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Comment field */
|
||||||
|
if (comsize > 0) {
|
||||||
|
if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) {
|
||||||
|
offsetCD += comsize;
|
||||||
|
} else {
|
||||||
|
err = Z_ERRNO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
err = Z_ERRNO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Success */
|
||||||
|
entries++;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Final central directory */
|
||||||
|
{
|
||||||
|
int entriesZip = entries;
|
||||||
|
char header[22];
|
||||||
|
char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools";
|
||||||
|
int comsize = (int) strlen(comment);
|
||||||
|
if (entriesZip > 0xffff) {
|
||||||
|
entriesZip = 0xffff;
|
||||||
|
}
|
||||||
|
WRITE_32(header, 0x06054b50);
|
||||||
|
WRITE_16(header + 4, 0); /* disk # */
|
||||||
|
WRITE_16(header + 6, 0); /* disk # */
|
||||||
|
WRITE_16(header + 8, entriesZip); /* hack */
|
||||||
|
WRITE_16(header + 10, entriesZip); /* hack */
|
||||||
|
WRITE_32(header + 12, offsetCD); /* size of CD */
|
||||||
|
WRITE_32(header + 16, offset); /* offset to CD */
|
||||||
|
WRITE_16(header + 20, comsize); /* comment */
|
||||||
|
|
||||||
|
/* Header */
|
||||||
|
if (fwrite(header, 1, 22, fpOutCD) == 22) {
|
||||||
|
|
||||||
|
/* Comment field */
|
||||||
|
if (comsize > 0) {
|
||||||
|
if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) {
|
||||||
|
err = Z_ERRNO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
err = Z_ERRNO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Final merge (file + central directory) */
|
||||||
|
fclose(fpOutCD);
|
||||||
|
if (err == Z_OK) {
|
||||||
|
fpOutCD = fopen(fileOutTmp, "rb");
|
||||||
|
if (fpOutCD != NULL) {
|
||||||
|
int nRead;
|
||||||
|
char buffer[8192];
|
||||||
|
while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) {
|
||||||
|
if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) {
|
||||||
|
err = Z_ERRNO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(fpOutCD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Close */
|
||||||
|
fclose(fpZip);
|
||||||
|
fclose(fpOut);
|
||||||
|
|
||||||
|
/* Wipe temporary file */
|
||||||
|
(void)remove(fileOutTmp);
|
||||||
|
|
||||||
|
/* Number of recovered entries */
|
||||||
|
if (err == Z_OK) {
|
||||||
|
if (nRecovered != NULL) {
|
||||||
|
*nRecovered = entries;
|
||||||
|
}
|
||||||
|
if (bytesRecovered != NULL) {
|
||||||
|
*bytesRecovered = totalBytes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = Z_STREAM_ERROR;
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
}
|
31
source/unzip/mztools.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
Additional tools for Minizip
|
||||||
|
Code: Xavier Roche '2004
|
||||||
|
License: Same as ZLIB (www.gzip.org)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _zip_tools_H
|
||||||
|
#define _zip_tools_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef _ZLIB_H
|
||||||
|
#include "zlib.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "unzip.h"
|
||||||
|
|
||||||
|
/* Repair a ZIP file (missing central directory)
|
||||||
|
file: file to recover
|
||||||
|
fileOut: output file after recovery
|
||||||
|
fileOutTmp: temporary file name used for recovery
|
||||||
|
*/
|
||||||
|
extern int ZEXPORT unzRepair(const char* file,
|
||||||
|
const char* fileOut,
|
||||||
|
const char* fileOutTmp,
|
||||||
|
uLong* nRecovered,
|
||||||
|
uLong* bytesRecovered);
|
||||||
|
|
||||||
|
#endif
|
1607
source/unzip/unzip.c
Normal file
354
source/unzip/unzip.h
Normal file
@ -0,0 +1,354 @@
|
|||||||
|
/* unzip.h -- IO for uncompress .zip files using zlib
|
||||||
|
Version 1.01e, February 12th, 2005
|
||||||
|
|
||||||
|
Copyright (C) 1998-2005 Gilles Vollant
|
||||||
|
|
||||||
|
This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
|
||||||
|
WinZip, InfoZip tools and compatible.
|
||||||
|
|
||||||
|
Multi volume ZipFile (span) are not supported.
|
||||||
|
Encryption compatible with pkzip 2.04g only supported
|
||||||
|
Old compressions used by old PKZip 1.x are not supported
|
||||||
|
|
||||||
|
|
||||||
|
I WAIT FEEDBACK at mail info@winimage.com
|
||||||
|
Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
|
||||||
|
|
||||||
|
Condition of use and distribution are the same than zlib :
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* for more info about .ZIP format, see
|
||||||
|
http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
|
||||||
|
http://www.info-zip.org/pub/infozip/doc/
|
||||||
|
PkWare has also a specification at :
|
||||||
|
ftp://ftp.pkware.com/probdesc.zip
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _unz_H
|
||||||
|
#define _unz_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef _ZLIB_H
|
||||||
|
#include "zlib.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef _ZLIBIOAPI_H
|
||||||
|
#include "ioapi.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
|
||||||
|
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||||
|
from (void*) without cast */
|
||||||
|
typedef struct TagunzFile__ { int unused; } unzFile__;
|
||||||
|
typedef unzFile__ *unzFile;
|
||||||
|
#else
|
||||||
|
typedef voidp unzFile;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define UNZ_OK (0)
|
||||||
|
#define UNZ_END_OF_LIST_OF_FILE (-100)
|
||||||
|
#define UNZ_ERRNO (Z_ERRNO)
|
||||||
|
#define UNZ_EOF (0)
|
||||||
|
#define UNZ_PARAMERROR (-102)
|
||||||
|
#define UNZ_BADZIPFILE (-103)
|
||||||
|
#define UNZ_INTERNALERROR (-104)
|
||||||
|
#define UNZ_CRCERROR (-105)
|
||||||
|
|
||||||
|
/* tm_unz contain date/time info */
|
||||||
|
typedef struct tm_unz_s
|
||||||
|
{
|
||||||
|
uInt tm_sec; /* seconds after the minute - [0,59] */
|
||||||
|
uInt tm_min; /* minutes after the hour - [0,59] */
|
||||||
|
uInt tm_hour; /* hours since midnight - [0,23] */
|
||||||
|
uInt tm_mday; /* day of the month - [1,31] */
|
||||||
|
uInt tm_mon; /* months since January - [0,11] */
|
||||||
|
uInt tm_year; /* years - [1980..2044] */
|
||||||
|
} tm_unz;
|
||||||
|
|
||||||
|
/* unz_global_info structure contain global data about the ZIPfile
|
||||||
|
These data comes from the end of central dir */
|
||||||
|
typedef struct unz_global_info_s
|
||||||
|
{
|
||||||
|
uLong number_entry; /* total number of entries in
|
||||||
|
the central dir on this disk */
|
||||||
|
uLong size_comment; /* size of the global comment of the zipfile */
|
||||||
|
} unz_global_info;
|
||||||
|
|
||||||
|
|
||||||
|
/* unz_file_info contain information about a file in the zipfile */
|
||||||
|
typedef struct unz_file_info_s
|
||||||
|
{
|
||||||
|
uLong version; /* version made by 2 bytes */
|
||||||
|
uLong version_needed; /* version needed to extract 2 bytes */
|
||||||
|
uLong flag; /* general purpose bit flag 2 bytes */
|
||||||
|
uLong compression_method; /* compression method 2 bytes */
|
||||||
|
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
|
||||||
|
uLong crc; /* crc-32 4 bytes */
|
||||||
|
uLong compressed_size; /* compressed size 4 bytes */
|
||||||
|
uLong uncompressed_size; /* uncompressed size 4 bytes */
|
||||||
|
uLong size_filename; /* filename length 2 bytes */
|
||||||
|
uLong size_file_extra; /* extra field length 2 bytes */
|
||||||
|
uLong size_file_comment; /* file comment length 2 bytes */
|
||||||
|
|
||||||
|
uLong disk_num_start; /* disk number start 2 bytes */
|
||||||
|
uLong internal_fa; /* internal file attributes 2 bytes */
|
||||||
|
uLong external_fa; /* external file attributes 4 bytes */
|
||||||
|
|
||||||
|
tm_unz tmu_date;
|
||||||
|
} unz_file_info;
|
||||||
|
|
||||||
|
extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
|
||||||
|
const char* fileName2,
|
||||||
|
int iCaseSensitivity));
|
||||||
|
/*
|
||||||
|
Compare two filename (fileName1,fileName2).
|
||||||
|
If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
|
||||||
|
If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
|
||||||
|
or strcasecmp)
|
||||||
|
If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
|
||||||
|
(like 1 on Unix, 2 on Windows)
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
extern unzFile ZEXPORT unzOpen OF((const char *path));
|
||||||
|
/*
|
||||||
|
Open a Zip file. path contain the full pathname (by example,
|
||||||
|
on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
|
||||||
|
"zlib/zlib113.zip".
|
||||||
|
If the zipfile cannot be opened (file don't exist or in not valid), the
|
||||||
|
return value is NULL.
|
||||||
|
Else, the return value is a unzFile Handle, usable with other function
|
||||||
|
of this unzip package.
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern unzFile ZEXPORT unzOpen2 OF((const char *path,
|
||||||
|
zlib_filefunc_def* pzlib_filefunc_def));
|
||||||
|
/*
|
||||||
|
Open a Zip file, like unzOpen, but provide a set of file low level API
|
||||||
|
for read/write the zip file (see ioapi.h)
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern int ZEXPORT unzClose OF((unzFile file));
|
||||||
|
/*
|
||||||
|
Close a ZipFile opened with unzipOpen.
|
||||||
|
If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
|
||||||
|
these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
|
||||||
|
return UNZ_OK if there is no problem. */
|
||||||
|
|
||||||
|
extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
|
||||||
|
unz_global_info *pglobal_info));
|
||||||
|
/*
|
||||||
|
Write info about the ZipFile in the *pglobal_info structure.
|
||||||
|
No preparation of the structure is needed
|
||||||
|
return UNZ_OK if there is no problem. */
|
||||||
|
|
||||||
|
|
||||||
|
extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
|
||||||
|
char *szComment,
|
||||||
|
uLong uSizeBuf));
|
||||||
|
/*
|
||||||
|
Get the global comment string of the ZipFile, in the szComment buffer.
|
||||||
|
uSizeBuf is the size of the szComment buffer.
|
||||||
|
return the number of byte copied or an error code <0
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
|
/* Unzip package allow you browse the directory of the zipfile */
|
||||||
|
|
||||||
|
extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
|
||||||
|
/*
|
||||||
|
Set the current file of the zipfile to the first file.
|
||||||
|
return UNZ_OK if there is no problem
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern int ZEXPORT unzGoToNextFile OF((unzFile file));
|
||||||
|
/*
|
||||||
|
Set the current file of the zipfile to the next file.
|
||||||
|
return UNZ_OK if there is no problem
|
||||||
|
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern int ZEXPORT unzLocateFile OF((unzFile file,
|
||||||
|
const char *szFileName,
|
||||||
|
int iCaseSensitivity));
|
||||||
|
/*
|
||||||
|
Try locate the file szFileName in the zipfile.
|
||||||
|
For the iCaseSensitivity signification, see unzStringFileNameCompare
|
||||||
|
|
||||||
|
return value :
|
||||||
|
UNZ_OK if the file is found. It becomes the current file.
|
||||||
|
UNZ_END_OF_LIST_OF_FILE if the file is not found
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* ****************************************** */
|
||||||
|
/* Ryan supplied functions */
|
||||||
|
/* unz_file_info contain information about a file in the zipfile */
|
||||||
|
typedef struct unz_file_pos_s
|
||||||
|
{
|
||||||
|
uLong pos_in_zip_directory; /* offset in zip file directory */
|
||||||
|
uLong num_of_file; /* # of file */
|
||||||
|
} unz_file_pos;
|
||||||
|
|
||||||
|
extern int ZEXPORT unzGetFilePos(
|
||||||
|
unzFile file,
|
||||||
|
unz_file_pos* file_pos);
|
||||||
|
|
||||||
|
extern int ZEXPORT unzGoToFilePos(
|
||||||
|
unzFile file,
|
||||||
|
unz_file_pos* file_pos);
|
||||||
|
|
||||||
|
/* ****************************************** */
|
||||||
|
|
||||||
|
extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
|
||||||
|
unz_file_info *pfile_info,
|
||||||
|
char *szFileName,
|
||||||
|
uLong fileNameBufferSize,
|
||||||
|
void *extraField,
|
||||||
|
uLong extraFieldBufferSize,
|
||||||
|
char *szComment,
|
||||||
|
uLong commentBufferSize));
|
||||||
|
/*
|
||||||
|
Get Info about the current file
|
||||||
|
if pfile_info!=NULL, the *pfile_info structure will contain somes info about
|
||||||
|
the current file
|
||||||
|
if szFileName!=NULL, the filemane string will be copied in szFileName
|
||||||
|
(fileNameBufferSize is the size of the buffer)
|
||||||
|
if extraField!=NULL, the extra field information will be copied in extraField
|
||||||
|
(extraFieldBufferSize is the size of the buffer).
|
||||||
|
This is the Central-header version of the extra field
|
||||||
|
if szComment!=NULL, the comment string of the file will be copied in szComment
|
||||||
|
(commentBufferSize is the size of the buffer)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
|
/* for reading the content of the current zipfile, you can open it, read data
|
||||||
|
from it, and close it (you can close it before reading all the file)
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
|
||||||
|
/*
|
||||||
|
Open for reading data the current file in the zipfile.
|
||||||
|
If there is no error, the return value is UNZ_OK.
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
|
||||||
|
const char* password));
|
||||||
|
/*
|
||||||
|
Open for reading data the current file in the zipfile.
|
||||||
|
password is a crypting password
|
||||||
|
If there is no error, the return value is UNZ_OK.
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
|
||||||
|
int* method,
|
||||||
|
int* level,
|
||||||
|
int raw));
|
||||||
|
/*
|
||||||
|
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
|
||||||
|
if raw==1
|
||||||
|
*method will receive method of compression, *level will receive level of
|
||||||
|
compression
|
||||||
|
note : you can set level parameter as NULL (if you did not want known level,
|
||||||
|
but you CANNOT set method parameter as NULL
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
|
||||||
|
int* method,
|
||||||
|
int* level,
|
||||||
|
int raw,
|
||||||
|
const char* password));
|
||||||
|
/*
|
||||||
|
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
|
||||||
|
if raw==1
|
||||||
|
*method will receive method of compression, *level will receive level of
|
||||||
|
compression
|
||||||
|
note : you can set level parameter as NULL (if you did not want known level,
|
||||||
|
but you CANNOT set method parameter as NULL
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
|
||||||
|
/*
|
||||||
|
Close the file in zip opened with unzOpenCurrentFile
|
||||||
|
Return UNZ_CRCERROR if all the file was read but the CRC is not good
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
|
||||||
|
voidp buf,
|
||||||
|
unsigned len));
|
||||||
|
/*
|
||||||
|
Read bytes from the current file (opened by unzOpenCurrentFile)
|
||||||
|
buf contain buffer where data must be copied
|
||||||
|
len the size of buf.
|
||||||
|
|
||||||
|
return the number of byte copied if somes bytes are copied
|
||||||
|
return 0 if the end of file was reached
|
||||||
|
return <0 with error code if there is an error
|
||||||
|
(UNZ_ERRNO for IO error, or zLib error for uncompress error)
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern z_off_t ZEXPORT unztell OF((unzFile file));
|
||||||
|
/*
|
||||||
|
Give the current position in uncompressed data
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern int ZEXPORT unzeof OF((unzFile file));
|
||||||
|
/*
|
||||||
|
return 1 if the end of file was reached, 0 elsewhere
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
|
||||||
|
voidp buf,
|
||||||
|
unsigned len));
|
||||||
|
/*
|
||||||
|
Read extra field from the current file (opened by unzOpenCurrentFile)
|
||||||
|
This is the local-header version of the extra field (sometimes, there is
|
||||||
|
more info in the local-header version than in the central-header)
|
||||||
|
|
||||||
|
if buf==NULL, it return the size of the local extra field
|
||||||
|
|
||||||
|
if buf!=NULL, len is the size of the buffer, the extra header is copied in
|
||||||
|
buf.
|
||||||
|
the return value is the number of bytes copied in buf, or (if <0)
|
||||||
|
the error code
|
||||||
|
*/
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
|
/* Get the current file offset */
|
||||||
|
extern uLong ZEXPORT unzGetOffset (unzFile file);
|
||||||
|
|
||||||
|
/* Set the current file offset */
|
||||||
|
extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _unz_H */
|
622
source/xml.c
Normal file
@ -0,0 +1,622 @@
|
|||||||
|
/*
|
||||||
|
Load game information from XML - Lustar
|
||||||
|
- Mini-XML ported by Beardface
|
||||||
|
- MiniZip adapted by Tantric
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "cfg.h"
|
||||||
|
|
||||||
|
#include "mxml/mxml.h"
|
||||||
|
#include "xml.h"
|
||||||
|
#include "unzip/unzip.h"
|
||||||
|
|
||||||
|
|
||||||
|
bool xmldebug = false;
|
||||||
|
|
||||||
|
extern struct SSettings Settings; // for loader GX
|
||||||
|
|
||||||
|
|
||||||
|
char langlist[11][22] =
|
||||||
|
{{"Console Default"},
|
||||||
|
{"Japanese"},
|
||||||
|
{"English"},
|
||||||
|
{"German"},
|
||||||
|
{"French"},
|
||||||
|
{"Spanish"},
|
||||||
|
{"Italian"},
|
||||||
|
{"Dutch"},
|
||||||
|
{"S. Chinese"},
|
||||||
|
{"T. Chinese"},
|
||||||
|
{"Korean"}};
|
||||||
|
|
||||||
|
char langcodes[11][22] =
|
||||||
|
{{""},
|
||||||
|
{"JA"},
|
||||||
|
{"EN"},
|
||||||
|
{"DE"},
|
||||||
|
{"FR"},
|
||||||
|
{"ES"},
|
||||||
|
{"IT"},
|
||||||
|
{"NL"},
|
||||||
|
{"ZH"},
|
||||||
|
{"ZH"},
|
||||||
|
{"KO"}};
|
||||||
|
|
||||||
|
char element_text[5000];
|
||||||
|
|
||||||
|
mxml_node_t *nodetree;
|
||||||
|
mxml_node_t *nodedata;
|
||||||
|
mxml_node_t *nodeid;
|
||||||
|
mxml_node_t *nodeidtmp;
|
||||||
|
mxml_node_t *nodefound;
|
||||||
|
mxml_index_t *nodeindex;
|
||||||
|
mxml_index_t *nodeindextmp;
|
||||||
|
|
||||||
|
int xmlloadtime = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/* get_text() taken as is from mini-mxml example mxmldoc.c */
|
||||||
|
/* get_text() - Get the text for a node. */
|
||||||
|
static char *get_text(mxml_node_t *node, char *buffer, int buflen);
|
||||||
|
static char * /* O - Text in node */
|
||||||
|
get_text(mxml_node_t *node, /* I - Node to get */
|
||||||
|
char *buffer, /* I - Buffer */
|
||||||
|
int buflen) /* I - Size of buffer */
|
||||||
|
{
|
||||||
|
char *ptr, /* Pointer into buffer */
|
||||||
|
*end; /* End of buffer */
|
||||||
|
int len; /* Length of node */
|
||||||
|
mxml_node_t *current; /* Current node */
|
||||||
|
ptr = buffer;
|
||||||
|
end = buffer + buflen - 1;
|
||||||
|
for (current = node->child; current && ptr < end; current = current->next)
|
||||||
|
{
|
||||||
|
if (current->type == MXML_TEXT) {
|
||||||
|
if (current->value.text.whitespace)
|
||||||
|
*ptr++ = ' ';
|
||||||
|
len = (int)strlen(current->value.text.string);
|
||||||
|
if (len > (int)(end - ptr))
|
||||||
|
len = (int)(end - ptr);
|
||||||
|
memcpy(ptr, current->value.text.string, len);
|
||||||
|
ptr += len;
|
||||||
|
} else if (current->type == MXML_OPAQUE) {
|
||||||
|
len = (int)strlen(current->value.opaque);
|
||||||
|
if (len > (int)(end - ptr))
|
||||||
|
len = (int)(end - ptr);
|
||||||
|
memcpy(ptr, current->value.opaque, len);
|
||||||
|
ptr += len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*ptr = '\0';
|
||||||
|
return (buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GetTextFromNode(mxml_node_t *currentnode, mxml_node_t *topnode, char *nodename, char *attributename, char *value, int descend, char *dest)
|
||||||
|
{
|
||||||
|
*element_text = 0; // reset text
|
||||||
|
|
||||||
|
nodefound = mxmlFindElement(currentnode, topnode, nodename, attributename, value, descend);
|
||||||
|
if (nodefound != NULL) {
|
||||||
|
if (attributename != NULL) {
|
||||||
|
strcpy(dest,mxmlElementGetAttr(nodefound, attributename));
|
||||||
|
} else {
|
||||||
|
get_text(nodefound, element_text, sizeof(element_text));
|
||||||
|
strcpy(dest,element_text);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
strcpy(dest,"");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool OpenXMLFile(char *filename)
|
||||||
|
{
|
||||||
|
mxml_node_t *nodetree;
|
||||||
|
|
||||||
|
// if (xmldebug)
|
||||||
|
// dbg_time1();
|
||||||
|
|
||||||
|
char* strresult = strstr(filename,".zip");
|
||||||
|
if (strresult == NULL) {
|
||||||
|
/* Load XML file */
|
||||||
|
FILE *filexml;
|
||||||
|
filexml = fopen(filename, "rb");
|
||||||
|
if (!filexml)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
nodetree = mxmlLoadFile(NULL, filexml, MXML_NO_CALLBACK);
|
||||||
|
fclose(filexml);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
/* load zipped XML file */
|
||||||
|
unzFile unzfile = unzOpen(filename);
|
||||||
|
if (unzfile == NULL)
|
||||||
|
return false;
|
||||||
|
unzOpenCurrentFile(unzfile);
|
||||||
|
|
||||||
|
unz_file_info zipfileinfo;
|
||||||
|
unzGetCurrentFileInfo(unzfile, &zipfileinfo, NULL, 0, NULL, 0, NULL, 0);
|
||||||
|
int zipfilebuffersize = zipfileinfo.uncompressed_size;
|
||||||
|
char * zipfilebuffer = (char *) calloc(1,zipfilebuffersize);
|
||||||
|
if (zipfilebuffer == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
unzReadCurrentFile(unzfile, zipfilebuffer, zipfilebuffersize);
|
||||||
|
unzCloseCurrentFile(unzfile);
|
||||||
|
unzClose(unzfile);
|
||||||
|
|
||||||
|
nodetree = mxmlLoadString(NULL, zipfilebuffer, MXML_NO_CALLBACK);
|
||||||
|
free(zipfilebuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nodetree == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
nodedata = mxmlFindElement(nodetree, nodetree, "datafile", NULL, NULL, MXML_DESCEND);
|
||||||
|
if (nodedata == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* create index of <id> elements */
|
||||||
|
nodeindex = mxmlIndexNew(nodetree,"id", NULL);
|
||||||
|
if (nodedata == NULL) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
//if (xmldebug);
|
||||||
|
// xmlloadtime = dbg_time2(NULL);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FreeXMLMemory()
|
||||||
|
{
|
||||||
|
/* free memory */
|
||||||
|
mxmlIndexDelete(nodeindex);
|
||||||
|
mxmlIndexDelete(nodeindextmp);
|
||||||
|
mxmlDelete(nodeid);
|
||||||
|
mxmlDelete(nodeidtmp);
|
||||||
|
mxmlDelete(nodefound);
|
||||||
|
mxmlDelete(nodedata);
|
||||||
|
mxmlDelete(nodetree);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* convert language text into ISO 639 two-letter language code */
|
||||||
|
char *ConvertLangTextToCode(char *languagetxt)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i=0;i<=10;i++)
|
||||||
|
{
|
||||||
|
if (!strcasecmp(languagetxt,langlist[i])) // case insensitive comparison
|
||||||
|
return langcodes[i];
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char ConvertRatingToIndex(char *ratingtext)
|
||||||
|
{
|
||||||
|
int type = -1;
|
||||||
|
if (strcmp(ratingtext,"CERO") == 0) { type = 0; }
|
||||||
|
if (strcmp(ratingtext,"ESRB") == 0) { type = 1; }
|
||||||
|
if (strcmp(ratingtext,"PEGI") == 0) { type = 2; }
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ConvertRating(char *ratingvalue, char *fromrating, char *torating, char *destvalue)
|
||||||
|
{
|
||||||
|
if(strcmp(fromrating,torating) == 0) {
|
||||||
|
strcpy(destvalue,ratingvalue);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
strcpy(destvalue,"");
|
||||||
|
int type = -1;
|
||||||
|
int desttype = -1;
|
||||||
|
|
||||||
|
type = ConvertRatingToIndex(fromrating);
|
||||||
|
desttype = ConvertRatingToIndex(torating);
|
||||||
|
if (type == -1 || desttype == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* rating conversion table */
|
||||||
|
/* the list is ordered to pick the most likely value first: */
|
||||||
|
/* EC and AO are less likely to be used so they are moved down to only be picked up when converting ESRB to PEGI or CERO */
|
||||||
|
/* the conversion can never be perfect because ratings can differ between regions for the same game */
|
||||||
|
char ratingtable[12][3][4] =
|
||||||
|
{
|
||||||
|
{{"A"},{"E"},{"3"}},
|
||||||
|
{{"A"},{"E"},{"4"}},
|
||||||
|
{{"A"},{"E"},{"6"}},
|
||||||
|
{{"A"},{"E"},{"7"}},
|
||||||
|
{{"A"},{"EC"},{"3"}},
|
||||||
|
{{"A"},{"E10+"},{"7"}},
|
||||||
|
{{"B"},{"T"},{"12"}},
|
||||||
|
{{"D"},{"M"},{"18"}},
|
||||||
|
{{"D"},{"M"},{"16"}},
|
||||||
|
{{"C"},{"T"},{"16"}},
|
||||||
|
{{"C"},{"T"},{"15"}},
|
||||||
|
{{"Z"},{"AO"},{"18"}},
|
||||||
|
};
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for (i=0;i<=11;i++)
|
||||||
|
{
|
||||||
|
if (strcmp(ratingtable[i][type],ratingvalue) == 0) {
|
||||||
|
strcpy(destvalue,ratingtable[i][desttype]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LoadTitlesFromXML(char *langtxt, bool forcejptoen)
|
||||||
|
/* langtxt: set to "English","French","German", to force language for all titles, or "" to load title depending on each game's setting */
|
||||||
|
/* forcejptoen: set to true to load English title instead of Japanese title when game is set to Japanese */
|
||||||
|
{
|
||||||
|
if (nodeindex == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
bool forcelang = false;
|
||||||
|
if (strcmp(langtxt,""))
|
||||||
|
forcelang = true;
|
||||||
|
|
||||||
|
char langcode[100] = "";
|
||||||
|
if (forcelang)
|
||||||
|
strcpy(langcode,ConvertLangTextToCode(langtxt)); /* convert language text into ISO 639 two-letter language code */
|
||||||
|
|
||||||
|
/* reset index before new search */
|
||||||
|
nodeid = mxmlIndexReset(nodeindex);
|
||||||
|
*element_text = 0;
|
||||||
|
char id_text[10];
|
||||||
|
char title_text[500] = "";
|
||||||
|
char title_text_EN[500] = "";
|
||||||
|
|
||||||
|
/* search index of id elements, load all id/titles text */
|
||||||
|
while (nodeid != NULL)
|
||||||
|
{
|
||||||
|
nodeid = mxmlIndexFind(nodeindex,"id", NULL);
|
||||||
|
if (nodeid != NULL) {
|
||||||
|
strcpy(title_text,"");
|
||||||
|
strcpy(title_text_EN,"");
|
||||||
|
|
||||||
|
get_text(nodeid, element_text, sizeof(element_text));
|
||||||
|
snprintf(id_text, 7, "%s",element_text);
|
||||||
|
|
||||||
|
// if language is not forced, use game language setting from config
|
||||||
|
if (!forcelang) {
|
||||||
|
struct Game_CFG *game_cfg = NULL;
|
||||||
|
int opt_lang;
|
||||||
|
game_cfg = CFG_get_game_opt((u8*)id_text);
|
||||||
|
if (game_cfg) {
|
||||||
|
opt_lang = game_cfg->language;
|
||||||
|
} else {
|
||||||
|
// opt_lang = CFG.language; // for config loader
|
||||||
|
opt_lang = Settings.language; // for loader GX
|
||||||
|
}
|
||||||
|
strcpy(langcode,ConvertLangTextToCode(langlist[opt_lang]));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if enabled, force English title for all games set to Japanese */
|
||||||
|
if (forcejptoen && strcmp(langcode,"JA") == 0)
|
||||||
|
strcpy(langcode,"EN");
|
||||||
|
|
||||||
|
/* load title from nodes */
|
||||||
|
nodefound = mxmlFindElement(nodeid, nodedata, "locale", "lang", "EN", MXML_NO_DESCEND);
|
||||||
|
if (nodefound != NULL) {
|
||||||
|
GetTextFromNode(nodefound, nodedata, "title", NULL, NULL, MXML_DESCEND, title_text_EN);
|
||||||
|
}
|
||||||
|
nodefound = mxmlFindElement(nodeid, nodedata, "locale", "lang", langcode, MXML_NO_DESCEND);
|
||||||
|
if (nodefound != NULL) {
|
||||||
|
GetTextFromNode(nodefound, nodedata, "title", NULL, NULL, MXML_DESCEND, title_text);
|
||||||
|
}
|
||||||
|
/* fall back to English title if prefered language was not found */
|
||||||
|
if (strcmp(title_text,"") == 0) {
|
||||||
|
strcpy(title_text,title_text_EN);
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(id_text, 5, "%s",id_text);
|
||||||
|
//printf("%s %s\n",id_text,title_text);
|
||||||
|
title_set(id_text, title_text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//if (xmldebug);
|
||||||
|
//xmlloadtime = dbg_time2(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GetPublisherFromGameid(char *idtxt, char *dest)
|
||||||
|
{
|
||||||
|
/* guess publisher from company list using last two characters from game id */
|
||||||
|
|
||||||
|
nodeindextmp = mxmlIndexNew(nodedata,"company", NULL);
|
||||||
|
nodeidtmp = mxmlIndexReset(nodeindextmp);
|
||||||
|
|
||||||
|
*element_text = 0;
|
||||||
|
char publishercode[3];
|
||||||
|
sprintf(publishercode,"%c%c", idtxt[4],idtxt[5]);
|
||||||
|
|
||||||
|
while (strcmp(element_text,publishercode) != 0)
|
||||||
|
{
|
||||||
|
nodeidtmp = mxmlIndexFind(nodeindextmp,"company", NULL);
|
||||||
|
if (nodeidtmp != NULL) {
|
||||||
|
strcpy(element_text,mxmlElementGetAttr(nodeidtmp, "code"));
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (strcmp(element_text,publishercode) == 0) {
|
||||||
|
strcpy(dest,mxmlElementGetAttr(nodeidtmp, "name"));
|
||||||
|
} else {
|
||||||
|
strcpy(dest,"");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LoadGameInfoFromXML(char* gameid, char* langtxt)
|
||||||
|
/* gameid: full game id */
|
||||||
|
/* langcode: "English","French","German" */
|
||||||
|
{
|
||||||
|
if (nodeindex == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* convert language text into ISO 639 two-letter language codes */
|
||||||
|
char langcode[100] = "";
|
||||||
|
strcpy(langcode,ConvertLangTextToCode(langtxt));
|
||||||
|
|
||||||
|
/* reset all game info */
|
||||||
|
gameinfo = gameinfo_reset;
|
||||||
|
|
||||||
|
/* reset index before new search */
|
||||||
|
nodeid = mxmlIndexReset(nodeindex);
|
||||||
|
*element_text = 0;
|
||||||
|
|
||||||
|
/* search for game matching gameid */
|
||||||
|
while (strcmp(element_text,gameid) != 0)
|
||||||
|
{
|
||||||
|
nodeid = mxmlIndexFind(nodeindex,"id", NULL);
|
||||||
|
if (nodeid != NULL) {
|
||||||
|
get_text(nodeid, element_text, sizeof(element_text));
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp(element_text,gameid) == 0) {
|
||||||
|
/* text from elements */
|
||||||
|
strcpy(gameinfo.id,element_text);
|
||||||
|
GetTextFromNode(nodeid, nodedata, "region", NULL, NULL, MXML_NO_DESCEND, gameinfo.region);
|
||||||
|
GetTextFromNode(nodeid, nodedata, "version", NULL, NULL, MXML_NO_DESCEND, gameinfo.version);
|
||||||
|
GetTextFromNode(nodeid, nodedata, "genre", NULL, NULL, MXML_NO_DESCEND, gameinfo.genre);
|
||||||
|
GetTextFromNode(nodeid, nodedata, "developer", NULL, NULL, MXML_NO_DESCEND, gameinfo.developer);
|
||||||
|
GetTextFromNode(nodeid, nodedata, "publisher", NULL, NULL, MXML_NO_DESCEND, gameinfo.publisher);
|
||||||
|
// try to guess publisher from game id in case it is missing
|
||||||
|
if (strcmp(gameinfo.publisher,"") == 0) {
|
||||||
|
GetPublisherFromGameid(gameid,gameinfo.publisher);
|
||||||
|
}
|
||||||
|
GetPublisherFromGameid(gameid,gameinfo.publisherfromid);
|
||||||
|
|
||||||
|
/* text from attributes */
|
||||||
|
GetTextFromNode(nodeid, nodedata, "date", "year", NULL, MXML_NO_DESCEND, gameinfo.year);
|
||||||
|
GetTextFromNode(nodeid, nodedata, "date", "month", NULL,MXML_NO_DESCEND, gameinfo.month);
|
||||||
|
GetTextFromNode(nodeid, nodedata, "date", "day", NULL, MXML_NO_DESCEND, gameinfo.day);
|
||||||
|
GetTextFromNode(nodeid, nodedata, "rating", "type", NULL, MXML_NO_DESCEND, gameinfo.ratingtype);
|
||||||
|
GetTextFromNode(nodeid, nodedata, "rating", "value", NULL, MXML_NO_DESCEND, gameinfo.ratingvalue);
|
||||||
|
GetTextFromNode(nodeid, nodedata, "rom", "crc", NULL, MXML_NO_DESCEND, gameinfo.iso_crc);
|
||||||
|
GetTextFromNode(nodeid, nodedata, "rom", "md5", NULL, MXML_NO_DESCEND, gameinfo.iso_md5);
|
||||||
|
GetTextFromNode(nodeid, nodedata, "rom", "sha1", NULL, MXML_NO_DESCEND, gameinfo.iso_sha1);
|
||||||
|
|
||||||
|
/* text from child elements */
|
||||||
|
nodefound = mxmlFindElement(nodeid, nodedata, "locale", "lang", "EN", MXML_NO_DESCEND);
|
||||||
|
if (nodefound != NULL) {
|
||||||
|
GetTextFromNode(nodefound, nodedata, "title", NULL, NULL, MXML_DESCEND, gameinfo.title_EN);
|
||||||
|
GetTextFromNode(nodefound, nodedata, "synopsis", NULL, NULL, MXML_DESCEND, gameinfo.synopsis_EN);
|
||||||
|
}
|
||||||
|
nodefound = mxmlFindElement(nodeid, nodedata, "locale", "lang", langcode, MXML_NO_DESCEND);
|
||||||
|
if (nodefound != NULL) {
|
||||||
|
GetTextFromNode(nodefound, nodedata, "title", NULL, NULL, MXML_DESCEND, gameinfo.title);
|
||||||
|
GetTextFromNode(nodefound, nodedata, "synopsis", NULL, NULL, MXML_DESCEND, gameinfo.synopsis);
|
||||||
|
}
|
||||||
|
// fall back to English title and synopsis if prefered language was not found
|
||||||
|
if (strcmp(gameinfo.title,"") == 0) {
|
||||||
|
strcpy(gameinfo.title,gameinfo.title_EN);
|
||||||
|
}
|
||||||
|
if (strcmp(gameinfo.synopsis,"") == 0) {
|
||||||
|
strcpy(gameinfo.synopsis,gameinfo.synopsis_EN);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* list locale lang attributes */
|
||||||
|
nodefound = mxmlFindElement(nodeid, nodedata, "locale", "lang", NULL, MXML_NO_DESCEND);
|
||||||
|
if (nodefound != NULL) {
|
||||||
|
int incr = 0;
|
||||||
|
while (nodefound != NULL)
|
||||||
|
{
|
||||||
|
++incr;
|
||||||
|
strcpy(gameinfo.locales[incr],mxmlElementGetAttr(nodefound, "lang"));
|
||||||
|
nodefound = mxmlWalkNext(nodefound, nodedata, MXML_NO_DESCEND);
|
||||||
|
if (nodefound != NULL) {
|
||||||
|
nodefound = mxmlFindElement(nodefound, nodedata, "locale", "lang", NULL, MXML_NO_DESCEND);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* unbounded child elements */
|
||||||
|
GetTextFromNode(nodeid, nodedata, "wi-fi", "players", NULL, MXML_NO_DESCEND, gameinfo.wifiplayers);
|
||||||
|
nodefound = mxmlFindElement(nodeid, nodedata, "wi-fi", NULL, NULL, MXML_NO_DESCEND);
|
||||||
|
if (nodefound != NULL) {
|
||||||
|
int incr = 0;
|
||||||
|
nodeindextmp = mxmlIndexNew(nodefound,"feature", NULL);
|
||||||
|
nodeidtmp = mxmlIndexReset(nodeindextmp);
|
||||||
|
|
||||||
|
while (nodeidtmp != NULL)
|
||||||
|
{
|
||||||
|
nodeidtmp = mxmlIndexFind(nodeindextmp,"feature", NULL);
|
||||||
|
if (nodeidtmp != NULL) {
|
||||||
|
++incr;
|
||||||
|
GetTextFromNode(nodeidtmp, nodedata, "feature", NULL, NULL, MXML_DESCEND, gameinfo.wififeatures[incr]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nodefound = mxmlFindElement(nodeid, nodedata, "rating", NULL, NULL, MXML_NO_DESCEND);
|
||||||
|
if (nodefound != NULL) {
|
||||||
|
int incr = 0;
|
||||||
|
nodeindextmp = mxmlIndexNew(nodefound,"descriptor", NULL);
|
||||||
|
nodeidtmp = mxmlIndexReset(nodeindextmp);
|
||||||
|
|
||||||
|
while (nodeidtmp != NULL)
|
||||||
|
{
|
||||||
|
nodeidtmp = mxmlIndexFind(nodeindextmp,"descriptor", NULL);
|
||||||
|
if (nodeidtmp != NULL) {
|
||||||
|
++incr;
|
||||||
|
GetTextFromNode(nodeidtmp, nodedata, "descriptor", NULL, NULL, MXML_DESCEND, gameinfo.ratingdescriptors[incr]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GetTextFromNode(nodeid, nodedata, "input", "players", NULL, MXML_NO_DESCEND, gameinfo.players);
|
||||||
|
nodefound = mxmlFindElement(nodeid, nodedata, "input", NULL, NULL, MXML_NO_DESCEND);
|
||||||
|
if (nodefound != NULL) {
|
||||||
|
//int incr = 0;
|
||||||
|
//int incrreq = 0;
|
||||||
|
gameinfo.accessoryCnt=0;
|
||||||
|
gameinfo.accessoryReqCnt=0;
|
||||||
|
|
||||||
|
nodeindextmp = mxmlIndexNew(nodefound,"control", NULL);
|
||||||
|
nodeidtmp = mxmlIndexReset(nodeindextmp);
|
||||||
|
|
||||||
|
while (nodeidtmp != NULL)
|
||||||
|
{
|
||||||
|
nodeidtmp = mxmlIndexFind(nodeindextmp,"control", NULL);
|
||||||
|
if (nodeidtmp != NULL) {
|
||||||
|
if (strcmp(mxmlElementGetAttr(nodeidtmp, "required"),"true") == 0) {
|
||||||
|
++gameinfo.accessoryReqCnt;
|
||||||
|
strcpy(gameinfo.accessories_required[gameinfo.accessoryReqCnt],mxmlElementGetAttr(nodeidtmp, "type"));
|
||||||
|
} else {
|
||||||
|
//++incr;
|
||||||
|
++gameinfo.accessoryCnt;
|
||||||
|
strcpy(gameinfo.accessories[gameinfo.accessoryCnt],mxmlElementGetAttr(nodeidtmp, "type"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* convert rating value */
|
||||||
|
ConvertRating(gameinfo.ratingvalue, gameinfo.ratingtype, "CERO",gameinfo.ratingvalueCERO);
|
||||||
|
ConvertRating(gameinfo.ratingvalue, gameinfo.ratingtype, "ESRB",gameinfo.ratingvalueESRB);
|
||||||
|
ConvertRating(gameinfo.ratingvalue, gameinfo.ratingtype, "PEGI",gameinfo.ratingvaluePEGI);
|
||||||
|
|
||||||
|
//PrintGameInfo();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
/*game not found */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PrintGameInfo(bool showfullinfo)
|
||||||
|
{
|
||||||
|
if (showfullinfo) {
|
||||||
|
|
||||||
|
//Con_Clear();
|
||||||
|
|
||||||
|
//printf("id: %s version: %s region: %s",gameinfo.id, gameinfo.version, gameinfo.region);
|
||||||
|
printf("title: %s\n",gameinfo.title);
|
||||||
|
int i;
|
||||||
|
printf("locales:");
|
||||||
|
for (i=1;strcmp(gameinfo.locales[i],"") != 0;i++)
|
||||||
|
{
|
||||||
|
printf(" %s",gameinfo.locales[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
printf("developer: %s\n",gameinfo.developer);
|
||||||
|
printf("publisher: %s\n",gameinfo.publisher);
|
||||||
|
printf("publisher from ID: %s\n",gameinfo.publisherfromid);
|
||||||
|
printf("year:%s month:%s day:%s\n",gameinfo.year,gameinfo.month,gameinfo.day);
|
||||||
|
printf("genre: %s\n",gameinfo.genre);
|
||||||
|
printf("rating: %s %s (CERO: %s ESRB: %s PEGI: %s)\n",gameinfo.ratingtype, gameinfo.ratingvalue,
|
||||||
|
gameinfo.ratingvalueCERO,gameinfo.ratingvalueESRB,gameinfo.ratingvaluePEGI);
|
||||||
|
printf("content descriptor:");
|
||||||
|
for (i=1;strcmp(gameinfo.wififeatures[i],"") != 0;i++)
|
||||||
|
{
|
||||||
|
printf(" %s",gameinfo.ratingdescriptors[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
printf("players: %s wi-fi: %s\n",gameinfo.players,gameinfo.wifiplayers);
|
||||||
|
printf("wi-fi features:");
|
||||||
|
for (i=1;strcmp(gameinfo.wififeatures[i],"") != 0;i++)
|
||||||
|
{
|
||||||
|
printf(" %s",gameinfo.wififeatures[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
printf("accessory required:");
|
||||||
|
for (i=1;strcmp(gameinfo.accessories_required[i],"") != 0;i++)
|
||||||
|
{
|
||||||
|
printf(" %s",gameinfo.accessories_required[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
printf("accessory:");
|
||||||
|
for (i=1;strcmp(gameinfo.accessories[i],"") != 0;i++)
|
||||||
|
{
|
||||||
|
printf(" %s",gameinfo.accessories[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
//printf("iso_crc: %s iso_md5: %s\n",gameinfo.iso_crc,gameinfo.iso_md5);
|
||||||
|
//printf("iso_sha1: %s\n",gameinfo.iso_sha1);
|
||||||
|
printf("synopsis: %s\n",gameinfo.synopsis);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
char linebuf[1000] = "";
|
||||||
|
|
||||||
|
if (xmldebug) {
|
||||||
|
char xmltime[100];
|
||||||
|
sprintf(xmltime,"%d",xmlloadtime);
|
||||||
|
printf("xml load time: %s\n",xmltime);
|
||||||
|
/*
|
||||||
|
printf("xml forcelang: %s\n",CFG.db_lang);
|
||||||
|
printf("xml url: %s\n",CFG.db_url);
|
||||||
|
printf("xml file: %s\n",CFG.db_filename);
|
||||||
|
char xmljptoen[100];
|
||||||
|
sprintf(xmljptoen,"%d",CFG.db_JPtoEN);
|
||||||
|
printf("xml JPtoEN: %s\n",xmljptoen);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
//printf("%s: ",gameidfull);
|
||||||
|
//printf("%s\n",gameinfo.title);
|
||||||
|
if (strcmp(gameinfo.year,"") != 0)
|
||||||
|
snprintf(linebuf, sizeof(linebuf), "%s ", gameinfo.year);
|
||||||
|
if (strcmp(gameinfo.publisher,"") != 0)
|
||||||
|
snprintf(linebuf, sizeof(linebuf), "%s%s", linebuf, gameinfo.publisher);
|
||||||
|
if (strcmp(gameinfo.developer,"") != 0 && strcmp(gameinfo.developer,gameinfo.publisher) != 0)
|
||||||
|
snprintf(linebuf, sizeof(linebuf), "%s / %s", linebuf, gameinfo.developer);
|
||||||
|
if (strlen(linebuf) >= 100) {
|
||||||
|
char buffer[200] = "";
|
||||||
|
strncpy(buffer, linebuf, 100);
|
||||||
|
strncat(buffer, "...", 3);
|
||||||
|
snprintf(linebuf, sizeof(linebuf), "%s", buffer);
|
||||||
|
}
|
||||||
|
printf("%s\n",linebuf);
|
||||||
|
strcpy(linebuf,"");
|
||||||
|
|
||||||
|
if (strcmp(gameinfo.ratingvalue,"") != 0) {
|
||||||
|
snprintf(linebuf, sizeof(linebuf), "rated %s", gameinfo.ratingvalue);
|
||||||
|
if (strcmp(gameinfo.ratingtype,"PEGI") == 0)
|
||||||
|
snprintf(linebuf, sizeof(linebuf), "%s+ ", linebuf);
|
||||||
|
snprintf(linebuf, sizeof(linebuf), "%s ", linebuf);
|
||||||
|
}
|
||||||
|
if (strcmp(gameinfo.players,"") != 0) {
|
||||||
|
snprintf(linebuf, sizeof(linebuf), "%sfor %s player", linebuf, gameinfo.players);
|
||||||
|
if (atoi(gameinfo.players) > 1)
|
||||||
|
snprintf(linebuf, sizeof(linebuf), "%ss", linebuf);
|
||||||
|
if (atoi(gameinfo.wifiplayers) > 1)
|
||||||
|
snprintf(linebuf, sizeof(linebuf), "%s (%s online)", linebuf, gameinfo.wifiplayers);
|
||||||
|
}
|
||||||
|
printf("%s\n",linebuf);
|
||||||
|
strcpy(linebuf,"");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
70
source/xml.h
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
|
||||||
|
#ifndef _XML_H_
|
||||||
|
#define _XML_H_
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct gameXMLinfo
|
||||||
|
{
|
||||||
|
char id[10];
|
||||||
|
char version[500];
|
||||||
|
char region[10];
|
||||||
|
char title[500];
|
||||||
|
char synopsis[2000];
|
||||||
|
char title_EN[500];
|
||||||
|
char synopsis_EN[2000];
|
||||||
|
char locales[100][500];
|
||||||
|
char developer[500];
|
||||||
|
char publisher[500];
|
||||||
|
char publisherfromid[500];
|
||||||
|
char year[10];
|
||||||
|
char month[10];
|
||||||
|
char day[10];
|
||||||
|
char genre[500];
|
||||||
|
char ratingtype[10];
|
||||||
|
char ratingvalue[10];
|
||||||
|
char ratingdescriptors[100][500];
|
||||||
|
char ratingvalueCERO[10];
|
||||||
|
char ratingvalueESRB[10];
|
||||||
|
char ratingvaluePEGI[10];
|
||||||
|
char wifiplayers[10];
|
||||||
|
char wififeatures[100][500];
|
||||||
|
char players[10];
|
||||||
|
char accessories[100][500];
|
||||||
|
char accessories_required[100][500];
|
||||||
|
char iso_crc[10];
|
||||||
|
char iso_md5[50];
|
||||||
|
char iso_sha1[50];
|
||||||
|
int accessoryCnt;
|
||||||
|
int accessoryReqCnt;
|
||||||
|
|
||||||
|
} ;
|
||||||
|
|
||||||
|
struct gameXMLinfo gameinfo;
|
||||||
|
struct gameXMLinfo gameinfo_reset;
|
||||||
|
|
||||||
|
bool OpenXMLFile(char* filename);
|
||||||
|
void LoadGameInfoFromXML(char* gameid, char* langcode);
|
||||||
|
void LoadTitlesFromXML(char *langcode, bool forcejptoen);
|
||||||
|
void GetPublisherFromGameid(char *idtxt, char *dest);
|
||||||
|
char *ConvertLangTextToCode(char *langtext);
|
||||||
|
void ConvertRating(char *ratingvalue, char *fromrating, char *torating, char *destvalue);
|
||||||
|
void PrintGameInfo(bool showfullinfo);
|
||||||
|
void FreeXMLMemory();
|
||||||
|
|
||||||
|
void title_set(char *id, char *title);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|