Ya no es necesario parchearlo, nos ahorramos un paso, para estar haciendo pruebas.
Publico mi ultima modificacion con la opcion de copiar, cortar, pegar y borrar (pero solo ficheros, no directorios). Estoy haciendo pruebas con la extraccion de la imagen de fondo de los juegos, pero no consigo crear el fichero correctamente. El fichero nxeart es un PIRS y por lo tanto tiene que existir una funcion para abrir su contenido y acceder a los ficheros que contiene. Pero sin debug y con mis escasos conocimientos no lo he conseguido todabia.
//--------------------------------------------------------------------------------------
// Loader Beta
// by SPlNeTe
//
// Thanks to Ski-lleR for your code
//--------------------------------------------------------------------------------------
#include <xtl.h>
#include <xui.h>
#include <xuiapp.h>
#include <stdio.h>
#include <xtl.h>
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
/*
List of physical drive
"\\Device\\Flash"
"\\Device\\Mu1"
"\\Device\\Mu0"
"\\Device\\Cdrom0"
"\\Device\\Harddisk0\\Partition0"
"\\Device\\Harddisk0\\Partition1"
"\\Device\\Harddisk0\\Partition2"
"\\Device\\Harddisk0\\Partition3"
"\\Device\\Mass0"
"\\Device\\Mass1"
"\\Device\\Mass2"
*/
#define DEVICE_NAND_FLASH 0
#define DEVICE_MEMORY_UNIT0 1
#define DEVICE_MEMORY_UNIT1 2
#define DEVICE_CDROM0 3
#define DEVICE_HARDISK0_PART0 4
#define DEVICE_HARDISK0_PART1 5
#define DEVICE_HARDISK0_PART2 6
#define DEVICE_HARDISK0_PART3 7
#define DEVICE_USB0 8
#define DEVICE_USB1 9
#define DEVICE_USB2 10
typedef struct _STRING {
USHORT Length;
USHORT MaximumLength;
PCHAR Buffer;
} STRING;
// Follow the white rabbit ^^
extern "C" int __stdcall ObCreateSymbolicLink( STRING*, STRING*);
extern "C" int __stdcall ObDeleteSymbolicLink( STRING* );
HRESULT Monter( int periphPhys, char* lettreLecteur )
{
char lecteurCible[16];
sprintf_s(lecteurCible,"\\??\\%s", lettreLecteur );
char * periphOriginal;
switch( periphPhys )
{
case DEVICE_NAND_FLASH:
periphOriginal = "\\Device\\Flash";
break;
case DEVICE_MEMORY_UNIT0:
periphOriginal = "\\Device\\Mu0";
break;
case DEVICE_MEMORY_UNIT1:
periphOriginal = "\\Device\\Mu1";
break;
case DEVICE_CDROM0:
periphOriginal = "\\Device\\Cdrom0";
break;
case DEVICE_HARDISK0_PART0:
periphOriginal = "\\Device\\Harddisk0\\Partition0";
break;
case DEVICE_HARDISK0_PART1:
periphOriginal = "\\Device\\Harddisk0\\Partition1";
break;
case DEVICE_HARDISK0_PART2:
periphOriginal = "\\Device\\Harddisk0\\Partition2";
break;
case DEVICE_HARDISK0_PART3:
periphOriginal = "\\Device\\Harddisk0\\Partition3";
break;
case DEVICE_USB0:
periphOriginal = "\\Device\\Mass0";
break;
case DEVICE_USB1:
periphOriginal = "\\Device\\Mass1";
break;
case DEVICE_USB2:
periphOriginal = "\\Device\\Mass2";
break;
}
STRING PeriphOriginal = { strlen( periphOriginal ), strlen( periphOriginal ) + 1, periphOriginal };
STRING LienSymbolique = { strlen( lecteurCible ), strlen( lecteurCible ) + 1, lecteurCible };
return ( HRESULT )ObCreateSymbolicLink( &LienSymbolique, &PeriphOriginal );
}
HRESULT Demonter( char* lettreLecteur )
{
char lecteurCible[16];
sprintf_s( lecteurCible,"\\??\\%s", lettreLecteur );
STRING LienSymbolique = { strlen(lecteurCible), strlen(lecteurCible) + 1, lecteurCible };
return ( HRESULT )ObDeleteSymbolicLink( &LienSymbolique );
}
//--------------------------------------------------------------------------------------
// Scene implementation class.
//--------------------------------------------------------------------------------------
class CMyMainScene : public CXuiSceneImpl
{
protected:
// Control and Element wrapper objects.
CXuiTextElement m_text1;
CXuiTextElement m_text2;
CXuiList m_list1;
CXuiList m_list2;
CXuiList m_list3;
CXuiImageElement m_image1;
CXuiScrollBar m_scrollBar1;
CXuiProgressBar m_progressBar1;
CXuiElement m_button1;
string sDirAct;
string sSelectedFiles[1000];
#define COPY 0
#define CUT 1
#define DEL 2
int iManagerOption;
// Message map.
XUI_BEGIN_MSG_MAP()
XUI_ON_XM_INIT( OnInit )
XUI_ON_XM_NOTIFY_PRESS( OnNotifyPress )
XUI_ON_XM_KEYDOWN( OnKeyDown )
XUI_END_MSG_MAP()
//----------------------------------------------------------------------------------
// Performs initialization tasks - retreives controls.
//----------------------------------------------------------------------------------
HRESULT OnInit( XUIMessageInit* pInitData, BOOL& bHandled )
{
// Retrieve controls for later use.
GetChildById( L"XuiText1", &m_text1 );
GetChildById( L"XuiText2", &m_text2 );
GetChildById( L"XuiCommonList1", &m_list1 );
GetChildById( L"XuiCommonList2", &m_list2 );
GetChildById( L"XuiCommonList3", &m_list3 );
GetChildById( L"XuiImage1", &m_image1 );
GetChildById( L"XuiScrollBar1", &m_scrollBar1 );
GetChildById( L"XuiProgressBar1", &m_progressBar1 );
GetChildById( L"XuiButton1", &m_button1 );
// Montamos los dispositivos
// if (ERROR_SUCCESS == Monter(DEVICE_CDROM0, "dvd0:"))
// m_list1.DeleteItems(3, 1);
Monter(DEVICE_CDROM0, "dvd0:");
Monter(DEVICE_USB0, "usb0:");
Monter(DEVICE_HARDISK0_PART1, "hdd1:");
Monter(DEVICE_NAND_FLASH, "flash:");
//Oculta los elementos inecesarios
m_list3.SetOpacity(0);
m_text2.SetOpacity(0);
m_progressBar1.SetOpacity(0);
m_button1.SetOpacity(0);
//Enfoca la lista de dispositivos
m_list1.SetFocus(XUSER_INDEX_ANY);
return S_OK;
}
//----------------------------------------------------------------------------------
// Handler for the button press message.
//----------------------------------------------------------------------------------
HRESULT OnNotifyPress( HXUIOBJ hObjPressed, BOOL& bHandled )
{
LPSTR fileName = new char[MAX_PATH];
LPSTR fullPath = new char[MAX_PATH];
LPSTR device = new char[MAX_PATH];
// Si se ha pulsado un boton de la lista de dispositivos
if( hObjPressed == m_list1 )
{
bHandled = TRUE;
//Se convierte el nombre del dispositivo a caracteres anchos
::WideCharToMultiByte( CP_ACP, NULL,m_list1.GetText(m_list1.GetCurSel()), -1, device,MAX_PATH,NULL,NULL );
//Se ocualta la lista de dispositivos
m_list1.SetOpacity(0);
//Se muestra el dispositivo seleccionado
OpenDevice(device);
}
// Si se ha pulsado un boton de la lista de ficheros
else if( hObjPressed == m_list2 )
{
bHandled = TRUE;
//Añade una barra al directorio actual
sDirAct+="\\";
//Convierte el nombre del fichero a caracteres
::WideCharToMultiByte(CP_ACP,NULL,m_list2.GetText(m_list2.GetCurSel()),-1,fileName,MAX_PATH,NULL,NULL);
//Añade el nombre del fichero al directorio Actual
sDirAct+= fileName;
//Copia el sDirAct al puntero directorio
sDirAct._Copy_s(fullPath, sDirAct.length(),sDirAct.length());
//Añade el final del fichero
fullPath[sDirAct.length()]='\0';
//Si el fichero seleccionado es un directorio
if(FILE_ATTRIBUTE_DIRECTORY == GetFileAttributes(fullPath))
{
//Abre el directorio
OpenDevice(fullPath);
}
else
//Si es un fichero
{
//Se comprueba si es un ejecutable
string str = fileName;
if (str.find(".xex")!=string::npos)
{
//Se lanza el ejecutable
XLaunchNewImage(fullPath, NULL);
}
}
}
// Si se ha pulsado un boton de la lista de opciones de ficheros
else if( hObjPressed == m_list3 )
{
bHandled = TRUE;
//Si se ha seccionado "Copiar"
if (m_list3.GetCurSel()==0)
{
iManagerOption = COPY;
SelectCheckedFiles();
}
//Si se ha seccionado "Cortar"
else if (m_list3.GetCurSel()==1)
{
iManagerOption = CUT;
SelectCheckedFiles();
}
//Si se ha seccionado "Pegar"
else if (m_list3.GetCurSel()==2)
{
PasteFiles();
}
//Si se ha seccionado "Borrar"
else if (m_list3.GetCurSel()==3)
{
iManagerOption = DEL;
SelectCheckedFiles();
DeleteFiles();
}
//Si se ha seccionado "Crear"
else if (m_list3.GetCurSel()==4)
{
m_text1.SetText(L"Crear");
CreateDir();
}
//Se oculta la lista de opciones
m_list3.SetOpacity(0);
//Se enfoca la lista de ficheros
m_list2.SetFocus(XUSER_INDEX_ANY);
}
return S_OK;
}
//----------------------------------------------------------------------------------
// Handler for the button press message.
//----------------------------------------------------------------------------------
HRESULT OnKeyDown(XUIMessageInput *pInputData, BOOL& bHandled)
{
string str;
CXuiControl ItemCtrl1;
CXuiControl ItemCtrl2;
CXuiControl ItemCtrl3;
// Recuperamos los botones seleccionado de todas las listas
// para comprobar en que lista esta enfocada
m_list1.GetCurSel(&ItemCtrl1);
m_list2.GetCurSel(&ItemCtrl2);
m_list3.GetCurSel(&ItemCtrl3);
// Si se pulsa sobre la lista de dispositivos
if ( ItemCtrl1 == ItemCtrl1.GetFocus(XUSER_INDEX_ANY))
{
// Si se pulsa el boton B
if ( pInputData->dwKeyCode == VK_PAD_B )
{
//Se ocualta la lista de dispositivos
m_list1.SetOpacity(0);
//Enfoca la lista de archivos
m_list2.SetFocus(XUSER_INDEX_ANY);
bHandled = TRUE;
}
}
// Si se pulsa sobre la lista de ficheros
else if ( ItemCtrl2 == ItemCtrl2.GetFocus(XUSER_INDEX_ANY))
{
// Si se pulsa el boton B
if ( pInputData->dwKeyCode == VK_PAD_B )
{
//Se obtiene la posicion de la ultima barra del directorio actual
size_t pos = sDirAct.find_last_of("\\");
if (pos!=string::npos)
{
//Se extrae el subdirectorio
sDirAct = sDirAct.substr(0,pos);
//Se abre el subdirectorio
OpenDevice(sDirAct);
}
bHandled = TRUE;
}
// Si se pulsa el boton BACK
else if ( pInputData->dwKeyCode == VK_PAD_BACK )
{
//Se muestra la lista de dispositivos
m_list1.SetOpacity(1);
//Se enfoca la lista de dispositivos
m_list1.SetFocus(XUSER_INDEX_ANY);
bHandled = TRUE;
}
// Si se pulsa el boton X
else if ( pInputData->dwKeyCode == VK_PAD_X )
{
// Si el boton seleccionado esta marcado
if ( TRUE == m_list2.GetItemCheck(m_list2.GetCurSel()))
{
// Se quita la marca y se habilita
m_list2.SetItemCheck(m_list2.GetCurSel(), FALSE);
m_list2.SetItemEnable(m_list2.GetCurSel(), TRUE);
}
// Si el boton seleccionado no esta marcado
else
{
// Se marca y se deshabilita
m_list2.SetItemCheck(m_list2.GetCurSel(), TRUE);
m_list2.SetItemEnable(m_list2.GetCurSel(), FALSE);
}
bHandled = TRUE;
}
// Si se pulsa el boton Y
else if ( pInputData->dwKeyCode == VK_PAD_Y )
{
// Se muestra la lista de opciones
m_list3.SetOpacity(1);
// Se enfoca la lista de opciones
m_list3.SetFocus(XUSER_INDEX_ANY);
bHandled = TRUE;
}
// Si se pulsa arriba en el pad
else if ( pInputData->dwKeyCode == VK_PAD_DPAD_UP )
{
XuiScrollBarSetItemData( m_scrollBar1, m_list2.GetItemCount(), m_list2.GetCurSel(), 7 );
}
// Si se pulsa abajo en el pad
else if ( pInputData->dwKeyCode == VK_PAD_DPAD_DOWN )
{
XuiScrollBarSetItemData( m_scrollBar1, m_list2.GetItemCount(), m_list2.GetCurSel(), 7 );
}
// Si se pulsa sobre la lista de opciones de ficheros
}
else if( ItemCtrl3 == ItemCtrl2.GetFocus(XUSER_INDEX_ANY))
{
// Si se pulsa el boton B
if ( pInputData->dwKeyCode == VK_PAD_B )
{
//Se ocualta la lista de dispositivos
m_list3.SetOpacity(0);
//Enfoca la lista de archivos
m_list2.SetFocus(XUSER_INDEX_ANY);
bHandled = TRUE;
}
}
return S_OK;
}
//----------------------------------------------------------------------------------
// Abre un dispositivo y rellena la lista con los nombres.
//----------------------------------------------------------------------------------
HRESULT OpenDevice(string strFind)
{
HANDLE hFind; //Manejador de ficheros
WIN32_FIND_DATA wfd; //Informacion de los ficheros
LPSTR lpPath = new char[MAX_PATH]; //Directorio
LPWSTR lpPathW = new wchar_t[MAX_PATH]; //Directorio en caracteres anchos
LPSTR lpFileName = new char[MAX_PATH]; //Nombre del fichero
LPWSTR lpFileNameW = new wchar_t[MAX_PATH]; //Nombre del fichero en caracteres anchos
string sFileName;
// Elimino todos los Items de la lista
m_list2.DeleteItems(0, m_list2.GetItemCount());
//Guarda el directorio actual
sDirAct = strFind;
//Enfoca la lista de archivos
m_list2.SetFocus(XUSER_INDEX_ANY);
//Añado \* al directorio para buscar todos los archivos
strFind+= "\\*";
//Copia el directorio al puntero directorio
strFind._Copy_s(lpPath, strFind.length(),strFind.length());
//Añade el final del fichero
lpPath[strFind.length()]='\0';
//Convierte el directorio a caracteres anchos directorioW
::MultiByteToWideChar( CP_ACP, NULL,lpPath, -1, lpPathW, MAX_PATH);
// Muestro el nombre del directorio explorado
m_text1.SetText(lpPathW);
// Empieza la busqueda de ficheros
hFind = FindFirstFile( lpPath, &wfd );
if( INVALID_HANDLE_VALUE == hFind )
{
//Si falla la busqueda
}
else
{
int nIndex = 0;
// Se trata el fichero y se obtiene el siguiente
do
{
// Inserto un Item en la lista y le paso el nombre del fichero convirtiendolo en caracteres anchos
m_list2.InsertItems(nIndex,1);
sFileName = wfd.cFileName;
//Copia el fichero al puntero
sFileName._Copy_s(lpFileName, sFileName.length(), sFileName.length());
//Añade el final del fichero
lpFileName[sFileName.length()]='\0';
::MultiByteToWideChar( CP_ACP, NULL,lpFileName, -1, lpFileNameW, MAX_PATH);
m_list2.SetText(nIndex,lpFileNameW);
//Segun el tipo de fichero se asigna un icono
if(FILE_ATTRIBUTE_DIRECTORY == wfd.dwFileAttributes)
{
m_list2.SetImage(nIndex,L"file://game:/media/icons/folder.png");
}
else if ((sFileName.find(".xex"))!=string::npos)
{
m_list2.SetImage(nIndex,L"file://game:/media/icons/xex.png");
}
else
m_list2.SetImage(nIndex,L"file://game:/media/icons/file.png");
if (sFileName.find("nxeart")!=string::npos)
{
// CargarFondo2();
}
nIndex++;
} while( FindNextFile( hFind, &wfd ));
// Cierra el manejador de la busqueda
FindClose( hFind );
}
return S_OK;
}
//----------------------------------------------------------------------------------
// Selecciona los directorios y ficheros seleccionados
//----------------------------------------------------------------------------------
VOID SelectCheckedFiles()
{
LPSTR lpFileName = new char[MAX_PATH]; //Nombre del fichero
int nCount = 0;
for (int i=0; i<m_list2.GetItemCount(); i++)
{
if (m_list2.GetItemCheck(i))
{
//Convierte el nombre del fichero a caracteres
::WideCharToMultiByte(CP_ACP,NULL,m_list2.GetText(i),-1,lpFileName,MAX_PATH,NULL,NULL);
//Añade el nombre del fichero al directorio Actual
sSelectedFiles[nCount]= sDirAct;
sSelectedFiles[nCount]+= "\\";
sSelectedFiles[nCount]+= lpFileName;
nCount++;
}
}
sSelectedFiles[nCount].clear();
}
//----------------------------------------------------------------------------------
// Copya los ficheros y directorios del directorio pasado al sDirAct
//----------------------------------------------------------------------------------
VOID CopyDirectory(string sDestino, string sOrigen)
{
HANDLE hFind; //Manejador de ficheros
WIN32_FIND_DATA wfd; //Informacion de los ficheros
LPSTR lpOrigen = new char[MAX_PATH]; //Directorio
LPSTR lpDestino = new char[MAX_PATH];
string sPathOrig;
string sPathDest;
sPathOrig = sOrigen;
//Añado \* al directorio para buscar todos los archivos
sPathOrig+= "\\*";
//Copia el directorio al puntero directorio
sPathOrig._Copy_s(lpOrigen, sPathOrig.length(), sPathOrig.length());
//Añade el final del fichero
lpOrigen[sPathOrig.length()]='\0';
// Empieza la busqueda de ficheros
hFind = FindFirstFile( lpOrigen, &wfd );
if( INVALID_HANDLE_VALUE == hFind )
{
//Si falla la busqueda
}
else
{
// Se trata el fichero y se obtiene el siguiente
do
{
sPathOrig = sOrigen;
sPathOrig+="\\";
sPathOrig+= wfd.cFileName;
sPathOrig._Copy_s(lpOrigen, sPathOrig.length(), sPathOrig.length());
lpOrigen[sPathOrig.length()]='\0';
sPathDest = sDestino;
sPathDest+= "\\";
sPathDest+= wfd.cFileName;
sPathDest._Copy_s(lpDestino, sPathDest.length(), sPathDest.length());
lpDestino[sPathDest.length()]='\0';
//Si el fichero a copia es un directorio
if (wfd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
{
//Se crea el directorio
CreateDirectory(
lpDestino, // directory name
NULL // SD
);
CopyDirectory(sPathDest, sPathOrig);
if (iManagerOption == CUT)
RemoveDirectory(lpOrigen);
}
else
{
if (iManagerOption == COPY)
{
CopyFileEx(
lpOrigen, // name of existing file
lpDestino, // name of new file
NULL,//CopyProgressRoutine, // callback function
NULL, // callback parameter
NULL, // cancel status
NULL
// COPY_FILE_FAIL_IF_EXISTS // copy iManagerOptions
);
}
else if (iManagerOption == CUT)
{
MoveFileWithProgress(
lpOrigen, // name of existing file
lpDestino, // name of new file
NULL, //CopyProgressRoutine, // callback function
NULL, // callback parameter
MOVEFILE_REPLACE_EXISTING
// COPY_FILE_FAIL_IF_EXISTS // copy iManagerOptions
);
}
}
} while( FindNextFile( hFind, &wfd ));
// Cierra el manejador de la busqueda
FindClose( hFind );
}
}
//----------------------------------------------------------------------------------
// Elimina los ficheros y directorios del directorio pasado
//----------------------------------------------------------------------------------
VOID DeleteDirectory(string sPath)
{
HANDLE hFind; //Manejador de ficheros
WIN32_FIND_DATA wfd; //Informacion de los ficheros
LPSTR lpPath = new char[MAX_PATH]; //Directorio
string sDirPath;
sDirPath = sPath;
//Añado \* al directorio para buscar todos los archivos
sDirPath+= "\\*";
//Copia el directorio al puntero directorio
sDirPath._Copy_s(lpPath, sDirPath.length(), sDirPath.length());
//Añade el final del fichero
lpPath[sDirPath.length()]='\0';
// Empieza la busqueda de ficheros
hFind = FindFirstFile( lpPath, &wfd );
if( INVALID_HANDLE_VALUE == hFind )
{
//Si falla la busqueda
}
else
{
// Se trata el fichero y se obtiene el siguiente
do
{
sDirPath = sPath;
sDirPath+= "\\";
sDirPath+= wfd.cFileName;
sDirPath._Copy_s(lpPath, sDirPath.length(), sDirPath.length());
lpPath[sDirPath.length()] = '\0';
//Si el fichero a copia es un directorio
if(FILE_ATTRIBUTE_DIRECTORY == wfd.dwFileAttributes)
{
DeleteDirectory(sDirPath);
//Se crea el directorio
RemoveDirectory(
lpPath // directory name
);
}
else
{
DeleteFile(
lpPath // file name
);
}
} while( FindNextFile( hFind, &wfd ));
// Cierra el manejador de la busqueda
FindClose( hFind );
}
}
//----------------------------------------------------------------------------------
// Indica el progreso en la copia de ficheros
//----------------------------------------------------------------------------------
/* static DWORD CopyProgressRoutine(
LARGE_INTEGER TotalFileSize, // file size
LARGE_INTEGER TotalBytesTransferred, // bytes transferred
LARGE_INTEGER StreamSize, // bytes in stream
LARGE_INTEGER StreamBytesTransferred, // bytes transferred for stream
DWORD dwStreamNumber, // current stream
DWORD dwCallbackReason, // callback reason
HANDLE hSourceFile, // handle to source file
HANDLE hDestinationFile, // handle to destination file
LPVOID lpData )// from CopyFileEx
{
int nValue = (TotalFileSize.QuadPart / TotalBytesTransferred.QuadPart) * 100;
m_progressBar1.std.SetValue(nValue);
return 0;
}
*/ //----------------------------------------------------------------------------------
// Pega los ficheros
//----------------------------------------------------------------------------------
VOID PasteFiles()
{
LPSTR lpFileName = new char[MAX_PATH]; //Nombre del fichero
LPWSTR lpFileNameW = new wchar_t[MAX_PATH]; //Nombre del fichero caracteres anchos
string sFileName;
LPSTR lpOrigen = new char[MAX_PATH] ;
LPSTR lpDestino = new char[MAX_PATH];
string sDestino;
m_text2.SetOpacity(1);
m_button1.SetOpacity(1);
m_progressBar1.SetOpacity(1);
int i = 0;
if (sSelectedFiles[i] != "\0")
{
do{
//Inicializa la barra de progreso
// m_progressBar1.SetRange(0,100);
// m_progressBar1.SetValue(0);
//Copia el nombre del directorio actual
sDestino = sDirAct;
//Se obtiene la posicion de la ultima barra del directorio actual
size_t pos = sSelectedFiles[i].find_last_of("\\");
//Extrae el nombre del fichero con la barra
sFileName = sSelectedFiles[i].substr(pos+1);
//Copiar el nombre del fichero a un puntero
sFileName._Copy_s(lpFileName, sFileName.length(),sFileName.length());
//Añade el final del fichero
lpFileName[sFileName.length()]='\0';
//Convierte el nombre del fichero a caracteres anchos
::MultiByteToWideChar( CP_ACP, NULL, lpFileName, -1, lpFileNameW, MAX_PATH);
//Se muestra el nombre en el boton de la barra de progreso
m_text2.SetText(lpFileNameW);
//Añade el nombre del fichero al directorio destino
sDestino+="\\";
sDestino+=sFileName;
sSelectedFiles[i]._Copy_s(lpOrigen, sSelectedFiles[i].length(), sSelectedFiles[i].length());
lpOrigen[sSelectedFiles[i].length()]='\0';
//Copia el directorio al puntero directorio
sDestino._Copy_s(lpDestino, sDestino.length(), sDestino.length());
lpDestino[sDestino.length()]='\0';
//Si el fichero a copia es un directorio
if(FILE_ATTRIBUTE_DIRECTORY == GetFileAttributes(lpOrigen))
{
//Se crea el directorio
CreateDirectory(
lpDestino, // directory name
NULL // SD
);
CopyDirectory(sDestino, sSelectedFiles[i]);
if (iManagerOption == CUT)
RemoveDirectory(lpOrigen);
}
else
{
if (iManagerOption == COPY)
{
CopyFileEx(
lpOrigen, // name of existing file
lpDestino, // name of new file
NULL,//CopyProgressRoutine, // callback function
NULL, // callback parameter
NULL, // cancel status
NULL
// COPY_FILE_FAIL_IF_EXISTS // copy iManagerOptions
);
}
else if (iManagerOption == CUT)
{
MoveFileWithProgress(
lpOrigen, // name of existing file
lpDestino, // name of new file
NULL, //CopyProgressRoutine, // callback function
NULL, // callback parameter
MOVEFILE_REPLACE_EXISTING
// COPY_FILE_FAIL_IF_EXISTS // copy iManagerOptions
);
}
}
i++;
}while (sSelectedFiles[i] != "\0");
OpenDevice(sDirAct);
}
m_button1.SetOpacity(0);
m_text2.SetOpacity(0);
m_progressBar1.SetOpacity(0);
}
//----------------------------------------------------------------------------------
// Borra los ficheros
//----------------------------------------------------------------------------------
VOID DeleteFiles()
{
LPSTR lpFileName = new char[MAX_PATH]; //Nombre del fichero
LPWSTR lpFileNameW = new wchar_t[MAX_PATH]; //Nombre del fichero caracteres anchos
string sFileName;
for (int i=0; i<m_list2.GetItemCount(); i++)
{
if (m_list2.GetItemCheck(i))
{
//Inicializa la barra de progreso
// m_progressBar1.SetRange(0,100);
// m_progressBar1.SetValue(0);
//Convierte el nombre del fichero a caracteres
::WideCharToMultiByte(CP_ACP,NULL,m_list2.GetText(i),-1,lpFileName,MAX_PATH,NULL,NULL);
//Añade el nombre del fichero al directorio Actual
sFileName = sDirAct;
sFileName+= "\\";
sFileName+= lpFileName;
//Copiar el nombre del fichero a un puntero
sFileName._Copy_s(lpFileName, sFileName.length(),sFileName.length());
//Añade el final del fichero
lpFileName[sFileName.length()]='\0';
//Convierte el nombre del fichero a caracteres anchos
::MultiByteToWideChar( CP_ACP, NULL, lpFileName, -1, lpFileNameW, MAX_PATH);
//Se muestra el nombre en el boton de la barra de progreso
m_text2.SetText(lpFileNameW);
//Si el fichero a copia es un directorio
if(FILE_ATTRIBUTE_DIRECTORY == GetFileAttributes(lpFileName))
{
DeleteDirectory(sFileName);
//Se crea el directorio
RemoveDirectory(
lpFileName // directory name
);
}
else
{
DeleteFile(
lpFileName // file name
);
}
i++;
}
}
OpenDevice(sDirAct);
}
//----------------------------------------------------------------------------------
// Crea un directorio
//----------------------------------------------------------------------------------
VOID CreateDir()
{
}
//----------------------------------------------------------------------------------
// Carga el fondo de pantalla
//----------------------------------------------------------------------------------
VOID CargarFondo()
{
// Create event for asynchronous writing
/* HANDLE hEventComplete = CreateEvent( NULL, FALSE, FALSE, NULL );
if( hEventComplete == NULL )
XOVERLAPPED xov = {0};
xov.hEvent = hEventComplete;
CHAR szFileName[XCONTENT_MAX_FILENAME_LENGTH];
WCHAR szDisplayName[XCONTENT_MAX_DISPLAYNAME_LENGTH];
XCONTENT_DATA contentData = {0};
strcpy_s( contentData.szFileName, "nxeart" );
wcscpy_s( contentData.szDisplayName, L"nxeart" );
contentData.dwContentType = XCONTENTTYPE_PUBLISHER;
contentData.DeviceID = XCONTENTDEVICE_ANY;
// Mount the device associated with the display name for writing
DWORD dwErr = XContentCreate( 0, "usb0:\\Assassins Creed 2", &contentData,
XCONTENTFLAG_OPENEXISTING, NULL, NULL, &xov );
if( dwErr != ERROR_IO_PENDING )
{
CloseHandle( hEventComplete );
// ATG::DebugSpew( "WriteSaveGame: XContentCreate failed.\n" );
// return dwErr;
}
// Wait on hEventComplete handle
if( XGetOverlappedResult( &xov, NULL, TRUE ) == ERROR_SUCCESS )
{
HANDLE hFile = CreateFile( "usb0:\\Assassins Creed 2\nxeart\", GENERIC_READ, 0,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
if( hFile != INVALID_HANDLE_VALUE )
{
// Write dummy data to the file
CHAR szBuffer[] = "Test save game data.\n";
DWORD dwWritten;
if( WriteFile( hFile, ( VOID* )szBuffer, strlen( szBuffer ), &dwWritten, NULL ) == 0 )
{
CloseHandle( hFile );
XContentClose( g_szSaveRoot, &xov );
XGetOverlappedResult( &xov, NULL, TRUE );
CloseHandle( hEventComplete );
ATG::DebugSpew( "WriteSaveGame: WriteFile failed. Error = %08x\n", GetLastError() );
return GetLastError();
}
CloseHandle( hFile );
}
else
{
ATG::DebugSpew( "WriteSaveGame: CreateFile failed. Error = %08x\n", GetLastError() );
return GetLastError();
}
}
XContentClose( g_szSaveRoot, &xov );
// Wait for XCloseContent to complete
XGetOverlappedResult( &xov, NULL, TRUE );
CloseHandle( hEventComplete );
*/ }
VOID CargarFondo2()
{
ifstream in;
stringstream buffer;
string content;
string wallpaperHD;
size_t start, end, length;
in.open("usb0:\\Assassins Creed 2\\nxeart", ios::in | ios::binary);
buffer << in.rdbuf();
content=buffer.str();
// We search for JFIF signature
start = content.find("ÖExif");
// Header of JPEG is 6 caracter & JFIF string, so back to 6 in file
start -= 5;
// Because first part of the hd wallpaper is 688144
end = start + 688144;
// Calculate the size of the first part
length = end - start;
// Extract the first part
wallpaperHD = content.substr( start, end );
// The second part start after 8176 dummy, ALWAYS
start = end + 8176;
// We search for the end of the JPEG, it's a signature
end = content.find("ÿÙ", start );
// Calculate the size of the second part
length = end - start;
// Add the second part at the end of the first
wallpaperHD.append( content.substr( start, end+2 ) );
ofstream out("file://game:/media/nxebg.jpg");
out << wallpaperHD;
out.close();
m_image1.SetImagePath(L"usb0:\\media\\nxebg.jpg");
}
string ByteToString(byte b[]){
string t="";
int size = sizeof(b);
for(int i=0;size;i++) t+=(char)b[i];
return t;
}
byte* StringToByte(string b){
int size = b.length();
byte* t = new byte[size];
for(int i=0;size;i++) t[i]=(char)b[i];
return t;
}
public:
// Define the class. The class name must match the ClassOverride property
// set for the scene in the UI Authoring tool.
XUI_IMPLEMENT_CLASS( CMyMainScene, L"MyMainScene", XUI_CLASS_SCENE )
};
//--------------------------------------------------------------------------------------
// Main XUI host class. It is responsible for registering scene classes and provide
// basic initialization, scene loading and rendering capability.
//--------------------------------------------------------------------------------------
class CMyApp : public CXuiModule
{
protected:
// Override RegisterXuiClasses so that CMyApp can register classes.
virtual HRESULT RegisterXuiClasses();
// Override UnregisterXuiClasses so that CMyApp can unregister classes.
virtual HRESULT UnregisterXuiClasses();
};
//--------------------------------------------------------------------------------------
// Name: RegisterXuiClasses
// Desc: Registers all the scene classes.
//--------------------------------------------------------------------------------------
HRESULT CMyApp::RegisterXuiClasses()
{
return CMyMainScene::Register();
}
//--------------------------------------------------------------------------------------
// Name: UnregisterXuiClasses
// Desc: Unregisters all the scene classes.
//--------------------------------------------------------------------------------------
HRESULT CMyApp::UnregisterXuiClasses()
{
CMyMainScene::Unregister();
return S_OK;
}
//--------------------------------------------------------------------------------------
// Name: main
// Desc: Application entry point.
//--------------------------------------------------------------------------------------
VOID __cdecl main()
{
// Declare an instance of the XUI framework application.
CMyApp app;
// Initialize the application.
HRESULT hr = app.Init( XuiD3DXTextureLoader );
if( FAILED( hr ) )
{
OutputDebugString( "Failed intializing application.\n" );
return;
}
// Register a default typeface
hr = app.RegisterDefaultTypeface( L"Arial Unicode MS", L"file://game:/media/xarialuni.ttf" );
if( FAILED( hr ) )
{
OutputDebugString( "Failed to register default typeface.\n" );
return;
}
// Load the skin file used for the scene.
app.LoadSkin( L"file://game:/media/simplescene.xzp#Media\\xui\\simple_scene_skin.xur" );
// Load the scene.
app.LoadFirstScene( L"file://game:/media/simplescene.xzp#Media\\xui\\", L"simple_scene.xur", NULL );
// Run the scene.
app.Run();
// Free resources, unregister custom classes, and exit.
app.Uninit();
}
Saludos.
P.D.: He actualizado el codigo con mis ultimas modificaciones para copiar, cortar, pegar y borrar archivos y directorios.
He cambiado la ruta de los iconos de "media" a "media/icons".
He añadido iconos a las opciones de gestion de archivos.
He modificado la posicion de los iconos, ahora estan a la izquierda del nombre del fichero, para ello hay que modificar el fichero simple_scene_skin.xui. El objeto XuiButton, tiene otro objeto llamado image_presenter, solo hay que cambiarlo a la izquierda del texto y modificar la propiedad "Anchor X" de Right a Left.
Ahora voy a intentar acceder a las imagenes que existen dentro del fichero nxeart, no solo los dos fondos, sino los iconos y el nombre del juego. Si consigo acceder a esto se podria crear una lista de juegos automatica con el icono y fondo de cada juego. Estoy ojeando el ejemplo XContent que parece que estrae el ThumbnailImage de un savegame.
Tengo creada una rutina para mostrar la barra de progreso cuando se copian ficheros, pero necesito crear la funcion delegada, para pasarla como parametro. En el codigo esta comentada "CopyProgressRoutine". Alguien se anima?
Saludos.
ACTUALIZACION:
Gracias a Ski-lleR, he montado el codigo de cargar el fondo, pero tambien extrae el icono y la imagen pequeña. El problema es que no funciona, aunque deveria hacerlo, ya que he comprobado directamente con los ficheros que los datos para su extraccion son correctos y no he modificado el algoritmo que me paso Ski-lleR. Haber si alguien le puede echar un vistazo y ver que puede fallar.
//----------------------------------------------------------------------------------
// Carga el fondo de pantalla
//----------------------------------------------------------------------------------
VOID CargarFondo()
{
LPWSTR lpGameNameW = new wchar_t[MAX_PATH]; //Nombre del fichero caracteres anchos
string sNxeartFile;
char cNxeartFile[MAX_PATH];
char cGameImagesFile[MAX_PATH];
sNxeartFile= sDirAct;
sNxeartFile+= "\\nxeart";
sNxeartFile._Copy_s(cNxeartFile, sNxeartFile.length(), sNxeartFile.length());
cNxeartFile[sNxeartFile.length()]='\0';
// Ouverture du fichier nxeart pour traitement
ifstream in;
stringstream out;
string content;
size_t start, end, length;
in.open(cNxeartFile, ios::in | ios::binary);
out << in.rdbuf();
// On stock le fichier entier en mémoire
content=out.str();
// On extrait le nom
string gameName = content.substr( 5778, 40 );
for (size_t i = 0; i < gameName.length(); i++)
{
if (gameName.at(i) == 0x00)
gameName.erase(i, 1);
}
char *cGameName = new char[gameName.length()+1];
gameName._Copy_s(cGameName, gameName.length(), gameName.length());
cGameName[gameName.length()] = '/0';
// On extrait l'icone du jeu
start = content.find("PNG");
start -= 1;
end = content.find("IEND");
end += 7;
length = end - start;
string icon = content.substr( start, length );
start = content.find("JFIF");
start -= 6;
end = start + 688128;
length = end - start;
string wallpaperHD = content.substr( start, length );
// Deuxième partie de l'image
start = end + 8192;
end = content.find("ÿÙ", start );
length = end - start;
// On colle les 2 bouts
wallpaperHD.append( content.substr( start, length+2 ) );
/* // On extrait l'image utiliser pour le preview
start = content.find("JFIF", end);
start -= 6;
end = content.find("ÿÙ", start );
end += 5;
end = content.find("ÿÙ", end );
end += 5;
end = content.find("ÿÙ", end );
length = end - start;
string logo = content.substr( start, length+2 );
*/
//Se crea el directorio
CreateDirectory(
"file://game:/media/gameimages", // directory name
NULL // SD
);
ofstream out2;
// sprintf_s( cGameImagesFile,"file://game:/media/gameimages/%s_icon.jpg", cGameName );
sprintf_s( cGameImagesFile,"usb0:\\media\\gameimages\\%s_icon.jpg", cGameName );
out2.open(cGameImagesFile, ios::out | ios::binary);
out2.write(icon.c_str(), icon.length());
out2.close();
/*
sprintf_s( cGameImagesFile,"file://game:/media/gameimages/%s_logo.jpg", cGameName );
sprintf_s( cGameImagesFile,"usb0:\\media\\gameimages\\%s_logo.jpg", cGameName );
out2.open(cGameImagesFile, ios::out | ios::binary);
out2.write(logo.c_str(), logo.length());
out2.close();
*/
// sprintf_s( cGameImagesFile,"file://game:/media/gameimages/%s_wallpaperHD.jpg", cGameName );
sprintf_s( cGameImagesFile,"usb0:\\media\\gameimages\\%s_wallpaperHD.jpg", cGameName );
out2.open(cGameImagesFile, ios::out | ios::binary);
out2.write(wallpaperHD.c_str(), wallpaperHD.length());
out2.close();
::MultiByteToWideChar( CP_ACP, NULL, cGameName, -1, lpGameNameW, MAX_PATH);
m_image1.SetImagePath(lpGameNameW);
}