Beispiel #1
0
int FileMkdir( const char *path )
{
	char *ptr;
	int c;

	if( (ptr = strchr( path, ':' )) == NULL ) {
#ifdef _DEBUG
		printf("FileMkdir : Invalid Path (ptr = NULL)\n");
#endif
		return -1;
	}

	c = ptr - path;

	if( !strncmp( path, "pfs", 3 ) ) {
		return fileXioMkdir( path, O_RDWR | O_CREAT );
	}
	else if( !strncmp( path, "mc0:", c ) || !strncmp( path, "mc1:", c ) ) {
		return fioMkdir( path );
	}
	else if( !strncmp( path, "mass:", c ) ) {
		return fioMkdir( path );
	}
	else if( !strncmp( path, "smb:", c ) ) {
		return smbc_mkdir( path, 0666 );
	}

	return -1;
}
Beispiel #2
0
/** Browser Menu
        Display:         PAL/NTSC
        Emulated System: PAL/NTSC
        Center Screen
        Configure Save Path: (browse to path)
        Configure Elf Path: (browse to path)
        Exit to Elf Path
        Exit to PS2Browser
**/
int Browser_Menu(void)
{
    char *temp;
    char cnfpath[2048];
    int i,selection = 0;
    oldselect = -1;
    int option_changed = 0;

    int menu_x1 = gsGlobal->Width*0.25;
    int menu_y1 = gsGlobal->Height*0.15;
    int menu_x2 = gsGlobal->Width*0.75;
    int menu_y2 = gsGlobal->Height*0.85+FONT_HEIGHT;
    int text_line = menu_y1 + 4;

    char options[12][39] = {
        { "Display: " },
        { "Interlacing: " },
        { "Emulated System: " },
        { "Center Screen" },
        { "Configure Save Path: " },
        { "" },
        { "Configure ELF Path:  " },
        { "" },
        { "Save FCEUltra.cnf"},
        { "Power Off" },
        { "Exit to ELF" },
        { "Exit Options Menu" }
    };

    //fill lines with values
    for(i=0;i<12;i++) {
        switch(i) {
            case 0:
                if(!Settings.display) {
                    sprintf(options[i],"%s%s",options[i],"NTSC");
                }
                else {
                    sprintf(options[i],"%s%s",options[i],"PAL");
                }
                break;
            case 1:
                if(Settings.interlace) {
                    sprintf(options[i],"%s%s",options[i],"On");
                }
                else {
                    sprintf(options[i],"%s%s",options[i],"Off");
                }
                break;
            case 2:
                if(!Settings.emulation) {
                    sprintf(options[i],"%s%s",options[i],"NTSC");
                }
                else {
                    sprintf(options[i],"%s%s",options[i],"PAL");
                }
                break;
            case 5:
                strzncpy(options[5],Settings.savepath,38);
                break;
            case 7:
                strzncpy(options[7],Settings.elfpath,38);
                break;
        }
    }



    while(1) {
        selected = 0; //clear selected flag
        selection += menu_input(0,0);

        if(selection > 11) { selection = 0; }
        if(selection < 0) { selection = 11; }
        if(selection == 5 && oldselect == 4) { selection++; } //5 is savepath
        if(selection == 5 && oldselect == 6) { selection--; }
        if(selection == 7 && oldselect == 6) { selection++; } //7 is elfpath
        if(selection == 7 && oldselect == 8) { selection--; }


        if((oldselect != selection) || option_changed) {

            gsKit_clear(gsGlobal,GS_SETREG_RGBAQ(0x00,0x00,0x00,0x80,0x00));

            menu_primitive("Options", &MENU_TEX, menu_x1, menu_y1, menu_x2, menu_y2);

            for(i=0;i<12;i++) {
                if(selection == i) {
                    //font_print(gsGlobal, menu_x1+10.0f, text_line + i*FONT_HEIGHT, 2, DarkYellowFont, options[i]);
                    printXY(options[i],menu_x1+10,text_line+i*FONT_HEIGHT, 4, FCEUSkin.highlight, 1, 0);
                }
                else {
                    //font_print(gsGlobal, menu_x1+10.0f, text_line + i*FONT_HEIGHT, 2, WhiteFont, options[i]);
                    printXY(options[i],menu_x1+10,text_line + i*FONT_HEIGHT, 4, FCEUSkin.textcolor, 1, 0);
                }
            }

            DrawScreen(gsGlobal);

            if(power_off)
                option_changed = 1;
                power_off--;
                if(!power_off) {
                    strcpy(cnfpath,"xyz:/imaginary/hypothetical/doesn't.exist");
                    FILE *File;
                    File = fopen(cnfpath,"r");
                    if(File != NULL)
                        fclose(File);
                }
        }

        oldselect = selection;
        option_changed = 0;

        if(selected) {
            if(selected == 2) {
                selection = 11;
            }
            i = selection;
            switch(i) {
                case 0: //Display PAL/NTSC
                    Settings.display ^= 1;
                    if(Settings.display) {
                        gsGlobal->Mode = GS_MODE_PAL;
                        gsGlobal->Height = 512;
                        defaulty = 72;
                        temp = strstr(options[i],"NTSC");
                        *temp = 0;
                        strcat(options[i],"PAL");
                    }
                    else {
                        gsGlobal->Mode = GS_MODE_NTSC;
                        gsGlobal->Height = 448;
                        defaulty = 50;
                        temp = strstr(options[i],"PAL");
                        *temp = 0;
                        strcat(options[i],"NTSC");
                    }
					gsGlobal->Width = 640;
					gsGlobal->Field = GS_FIELD;
					if (gsGlobal->Interlace == GS_NONINTERLACED) {
						gsGlobal->Height = gsGlobal->Height/2;
						gsGlobal->StartY = gsGlobal->StartY/2 -1 ;
					}

                    gsGlobal->StartY = gsGlobal->StartY + Settings.offset_y;
                    //if(Settings.interlace && (gsGlobal->Mode == GS_MODE_NTSC))
                        //gsGlobal->StartY = gsGlobal->StartY + 22;
                    //else
                        //gsGlobal->StartY = gsGlobal->StartY + 11;
                    //normalize_screen();
					gsKit_init_screen(gsGlobal);	/* Apply settings. */
					gsKit_mode_switch(gsGlobal, GS_ONESHOT);

                    menu_x1 = gsGlobal->Width*0.25;
                    menu_y1 = gsGlobal->Height*0.15;
                    menu_x2 = gsGlobal->Width*0.75;
                    menu_y2 = gsGlobal->Height*0.85+FONT_HEIGHT;
					text_line = menu_y1 + 4;
					    
                    option_changed = 1;
                    //SetGsCrt(gsGlobal->Interlace,gsGlobal->Mode,gsGlobal->Field);
                    break;
                case 1: //Interlacing Off/On
                    Settings.interlace ^= 1;
                    if (gsGlobal->Mode == GS_MODE_PAL)
						gsGlobal->Height = 512;
					else
						gsGlobal->Height = 448;
                    if(Settings.interlace) {
                        gsGlobal->Interlace = GS_INTERLACED;
                        //gsGlobal->StartY = (gsGlobal->StartY-1)*2;
                        temp = strstr(options[i],"Off");
                        *temp = 0;
                        strcat(options[i],"On");
                    }
                    else {
                        gsGlobal->Interlace = GS_NONINTERLACED;
                        gsGlobal->StartY = gsGlobal->StartY/2 + 1;
						gsGlobal->Height = gsGlobal->Height/2;
                        temp = strstr(options[i],"On");
                        *temp = 0;
                        strcat(options[i],"Off");
                    }
					gsGlobal->Width = 640;
					gsGlobal->Field = GS_FIELD;
                    //normalize_screen();
					gsKit_init_screen(gsGlobal);	/* Apply settings. */
					gsKit_mode_switch(gsGlobal, GS_ONESHOT);
					
                    menu_x1 = gsGlobal->Width*0.25;
                    menu_y1 = gsGlobal->Height*0.15;
                    menu_x2 = gsGlobal->Width*0.75;
                    menu_y2 = gsGlobal->Height*0.85+FONT_HEIGHT;
					text_line = menu_y1 + 4;
                    option_changed = 1;
                    //SetGsCrt(gsGlobal->Interlace,gsGlobal->Mode,gsGlobal->Field);
                    break;
                case 2: //Emulated System
                    Settings.emulation ^= 1;
                    if(Settings.emulation) {
                        temp = strstr(options[i],"NTSC");
                        *temp = 0;
                        strcat(options[i],"PAL");
                    }
                    else {
                        temp = strstr(options[i],"PAL");
                        *temp = 0;
                        strcat(options[i],"NTSC");
                    }
                    FCEUI_SetVidSystem(Settings.emulation);
                    option_changed = 1;
                    break;
                case 3: //Center Screen
                    while(menu_input(0,2) != 2) {}
                    i = 0x10000;
                    while(i--) asm("nop\nnop\nnop\nnop");
                    option_changed = 1;
                    break;
                case 4: //Configure Save Path
                    h = 0; //reset browser
                    selection = 0;
                    oldselect = -1;
                    selected = 0;
                    strcpy(path,"path"); //end reset browser
                    strcpy(Settings.savepath,Browser(0,1));
                    printf("%s",Settings.savepath);
                    strzncpy(options[5],Settings.savepath,38);
                    selected_dir = 0;
                    h = 0;
                    selection = 0;
                    oldselect = -1;
                    strcpy(path,"path");
                    option_changed = 1;
                    selected = 0;
                    break;
                case 6: //Configure ELF Path
                    h = 0;
                    selection = 0;
                    oldselect = -1;
                    selected = 0;
                    strcpy(path,"path");
                    strcpy(Settings.elfpath,Browser(1,2));
                    strzncpy(options[7],Settings.elfpath,38);
                    h = 0;
                    selection = 0;
                    oldselect = -1;
                    strcpy(path,"path");
                    option_changed = 1;
                    selected = 0;
                    break;
                case 8: //Save CNF
                    fioMkdir("mc0:FCEUMM");
                    Save_Global_CNF("mc0:/FCEUMM/FCEUltra.cnf");
                    break;
                case 9: //Power Off
                    poweroffShutdown();
                    if(Settings.display)
                        power_off = 50/4;
                    else
                        power_off = 60/4;
                    option_changed = 1;
                    break;
                case 10: //Exit to ELF
                    return 2;
                case 11: //Exit Options Menu
                    selected = 0;
                    return 1;

            }
        }
    }
}
Beispiel #3
0
int CreateSave(void)
{
	int mc_fd;
	int icon_fd,icon_size;
	char* icon_buffer;
	mcIcon icon_sys;

	static iconIVECTOR bgcolor[4] = {
		{  68,  23, 116,  0 }, // top left
		{ 255, 255, 255,  0 }, // top right
		{ 255, 255, 255,  0 }, // bottom left
		{  68,  23, 116,  0 }, // bottom right
	};

	static iconFVECTOR lightdir[3] = {
		{ 0.5, 0.5, 0.5, 0.0 },
		{ 0.0,-0.4,-0.1, 0.0 },
		{-0.5,-0.5, 0.5, 0.0 },
	};

	static iconFVECTOR lightcol[3] = {
		{ 0.3, 0.3, 0.3, 0.00 },
		{ 0.4, 0.4, 0.4, 0.00 },
		{ 0.5, 0.5, 0.5, 0.00 },
	};

	static iconFVECTOR ambient = { 0.50, 0.50, 0.50, 0.00 };


	if(fioMkdir("mc0:PS2DEV") < 0) return -1;

	// Set up icon.sys. This is the file which controls how our memory card save looks
	// in the PS2 browser screen. It contains info on the bg colour, lighting, save name
	// and icon filenames. Please note that the save name is sjis encoded.

	memset(&icon_sys, 0, sizeof(mcIcon));
	strcpy(icon_sys.head, "PS2D");
	strcpy_sjis((short *)&icon_sys.title, "Memcard Example\nPS2Dev r0x0rs");
	icon_sys.nlOffset = 16;
	icon_sys.trans = 0x60;
	memcpy(icon_sys.bgCol, bgcolor, sizeof(bgcolor));
	memcpy(icon_sys.lightDir, lightdir, sizeof(lightdir));
	memcpy(icon_sys.lightCol, lightcol, sizeof(lightcol));
	memcpy(icon_sys.lightAmbient, ambient, sizeof(ambient));
	strcpy(icon_sys.view, "ps2dev.icn"); // these filenames are relative to the directory
	strcpy(icon_sys.copy, "ps2dev.icn"); // in which icon.sys resides.
	strcpy(icon_sys.del, "ps2dev.icn");

	// Write icon.sys to the memory card (Note that this filename is fixed)
	mc_fd = fioOpen("mc0:PS2DEV/icon.sys",O_WRONLY | O_CREAT);
	if(mc_fd < 0) return -2;

	fioWrite(mc_fd, &icon_sys, sizeof(icon_sys));
	fioClose(mc_fd);
	printf("icon.sys written sucessfully.\n");

	// Write icon file to the memory card.
	// Note: The icon file was created with my bmp2icon tool, available for download at
	//       http://www.ps2dev.org
	icon_fd = fioOpen("host:ps2dev.icn",O_RDONLY);
	if(icon_fd < 0) return -3;

	icon_size = fioLseek(icon_fd,0,SEEK_END);
	fioLseek(icon_fd,0,SEEK_SET);

	icon_buffer = malloc(icon_size);
	if(icon_buffer == NULL) return -4;
	if(fioRead(icon_fd, icon_buffer, icon_size) != icon_size) return -5;
	fioClose(icon_fd);

	icon_fd = fioOpen("mc0:PS2DEV/ps2dev.icn",O_WRONLY | O_CREAT);
	if(icon_fd < 0) return -6;

	fioWrite(icon_fd,icon_buffer,icon_size);
	fioClose(icon_fd);
	printf("ps2dev.icn written sucessfully.\n");

	return 0;
}
Beispiel #4
0
void Sys_mkdir (char *path)
{
	fioMkdir(path);
}
Beispiel #5
0
int extractZIP(gameSave_t *save, device_t dst)
{
    FILE *dstFile;
    unzFile zf;
    unz_file_info fileInfo;
    unz_global_info info;
    char fileName[100];
    char dirNameTemp[100];
    int numFiles;
    char *dirName;
    char dstName[100];
    u8 *data;
    float progress = 0.0;
    
    if(!save || !(dst & (MC_SLOT_1|MC_SLOT_2)))
        return 0;
    
    zf = unzOpen(save->path);
    if(!zf)
        return 0;

    unzGetGlobalInfo(zf, &info);
    numFiles = info.number_entry;

    // Get directory name
    if(unzGoToFirstFile(zf) != UNZ_OK)
    {
        unzClose(zf);
        return 0;
    }

    unzGetCurrentFileInfo(zf, &fileInfo, fileName, 100, NULL, 0, NULL, 0);
    printf("Filename: %s\n", fileName);

    strcpy(dirNameTemp, fileName);

    dirNameTemp[(unsigned int)(strstr(dirNameTemp, "/") - dirNameTemp)] = 0;

    printf("Directory name: %s\n", dirNameTemp);

    dirName = savesGetDevicePath(dirNameTemp, dst);
    int ret = fioMkdir(dirName);
    
    // Prompt user to overwrite save if it already exists
    if(ret == -4)
    {
        const char *items[] = {"Yes", "No"};
        int choice = displayPromptMenu(items, 2, "Save already exists. Do you want to overwrite it?");
        if(choice == 1)
        {
            unzClose(zf);
            free(dirName);
            return 0;
        }
    }
    
    // Copy each file entry
    do
    {
        progress += (float)1/numFiles;
        drawCopyProgress(progress);

        unzGetCurrentFileInfo(zf, &fileInfo, fileName, 100, NULL, 0, NULL, 0);
        
        data = malloc(fileInfo.uncompressed_size);
        unzOpenCurrentFile(zf);
        unzReadCurrentFile(zf, data, fileInfo.uncompressed_size);
        unzCloseCurrentFile(zf);
        
        snprintf(dstName, 100, "%s/%s", dirName, strstr(fileName, "/") + 1);

        printf("Writing %s...", dstName);

        dstFile = fopen(dstName, "wb");
        if(!dstFile)
        {
            printf(" failed!!!\n");
            unzClose(zf);
            free(dirName);
            free(data);
            return 0;
        }
        fwrite(data, 1, fileInfo.uncompressed_size, dstFile);
        fclose(dstFile);
        free(data);

        printf(" done!\n");
    } while(unzGoToNextFile(zf) != UNZ_END_OF_LIST_OF_FILE);

    free(dirName);
    unzClose(zf);
    
    return 1;
}
int main(int argc, char *argv[])
#endif
{


#ifdef PSP
    SetupCallbacks();
    scePowerSetClockFrequency(333, 333, 166);
#endif

    for (int i=0; i<FLAG_COUNT; i++) {
		GAME_FLAGS[i] = false;
	}
	UNUSED(argc);

    string argvString = "";
#ifndef WII
    argvString = string(argv[0]);
#else
    if (!fatInitDefault()) {
        printf("fatInitDefault ERROR #1");
        std::fflush(stdout);
        timer.delay(500);
        exit(-1);
    }
#endif


    get_filepath();
    // fallback in case getcwd returns null
    if (FILEPATH.size() == 0) {
        std::cout << "Could not read path, fallback to using argv" << std::endl;
        FILEPATH = argvString.substr(0, argvString.size()-EXEC_NAME.size());
    }
    std::cout << "main - argvString: '" << argvString << "', FILEPATH: '" << FILEPATH << "'" << std::endl; std::fflush(stdout);



#ifdef PLAYSTATION2
    std::cout << "PS2.DEBUG #1" << std::endl; std::fflush(stdout);

    #ifndef PS2LINK
    SifIopReset(NULL, 0); // clean previous loading of irx by apps like ulaunchElf. Comment this line to get cout on ps2link
    #endif

    printf("DEBUG.PS2 #1.1\n");

	/* SP193: Being creative (Do something while waiting for the slow IOP to be reset). =D */
	int main_id = GetThreadId();
    ChangeThreadPriority(main_id, 72);
    std::cout << "PS2.DEBUG #1.1" << std::endl; std::fflush(stdout);
    printf("DEBUG.PS2 #1.2\n");

    #ifndef PS2LINK
    while(SifIopSync()) {
        std::cout << "PS2.SifIopSync()" << std::endl;
    }
    #endif
	/* Initialize and connect to all SIF services on the IOP. */
	SifInitRpc(0);
	SifInitIopHeap();
	SifLoadFileInit();
	fioInit();
    printf("DEBUG.PS2 #1.3\n");

	/* Apply the SBV LMB patch to allow modules to be loaded from a buffer in EE RAM. */
	sbv_patch_enable_lmb();

    // --- DEBUG --- //
    //FILEPATH = "cdfs:/";
    // --- DEBUG --- //

    std::cout << "PS2.DEBUG #2" << std::endl; std::fflush(stdout);

    if (FILEPATH.find("mass:") != std::string::npos) {
        printf("DEBUG.PS2 #1.4\n");
        std::cout << "PS2.DEBUG Load USB" << std::endl; std::fflush(stdout);
        PS2_load_USB();
    }

    if (FILEPATH.find("cdfs") != std::string::npos || FILEPATH.find("cdrom") != std::string::npos) {
        printf("DEBUG.PS2 #1.5\n");
        std::cout << "PS2.DEBUG Load CDROM" << std::endl; std::fflush(stdout);
        FILEPATH = "cdfs:";
        PS2_load_CDROM();
    }
    printf("DEBUG.PS2 #2\n");




    std::cout << "PS2.DEBUG #3" << std::endl; std::fflush(stdout);
#endif




	// check command-line paramethers
	if (argc > 1) {
		for (int i=1; i<argc; i++) {
			std::string temp_argv(argv[i]);
			if (temp_argv == "--fullscreen") {

			} else if (temp_argv == "--quickload") {
				GAME_FLAGS[FLAG_QUICKLOAD] = true;
			} else if (temp_argv == "--invencible") { // player have infinite HP
				GAME_FLAGS[FLAG_INVENCIBLE] = true;
			} else if (temp_argv == "--allweapons") { // player have all weapons available even if
				GAME_FLAGS[FLAG_ALLWEAPONS] = true;
			} else if (temp_argv == "--infinitejump") { // player can jump again and again
				GAME_FLAGS[FLAG_INFINITE_JUMP] = true;
			}
		}
	}

    std::cout << "PS2.DEBUG #7" << std::endl; std::fflush(stdout);

    //fio.check_conversion();
	fio.read_game(game_data);


    //GAME_FLAGS[FLAG_INFINITE_HP] = true; // DEBUG


    gameControl.get_drop_item_ids();
	soundManager.init_audio_system();

// PS2 version have to load config AFTER SDL_Init due to SDK issues
#ifdef LINUX
    SAVEPATH = std::string(getenv("HOME")) + "/.rockbot/";
    mkdir(SAVEPATH.c_str(), 0777);
    //std::cout << "SAVEPATH: " << SAVEPATH << ", mkdir-res: " << res << ", errno: " << errno << std::endl;
#elif WIN32
    SAVEPATH =  std::string(getenv("APPDATA")) + "/rockbot";
    std::cout << "SAVEPATH: " << SAVEPATH << std::endl;
    _mkdir(SAVEPATH.c_str());
#else
    SAVEPATH = FILEPATH;
#endif

#ifndef PLAYSTATION2
    fio.load_config(game_config);
#endif

	// INIT GRAPHICS
	if (graphLib.initGraphics() != true) {
        printf("ERROR intializing graphic\n");
		return -1;
	}

    // define SAVEPATH
    #ifdef PLAYSTATION2
        PS2_load_MC();
        SAVEPATH = "mc0:Rockbot/";

        if (fioMkdir(SAVEPATH.c_str()) < 0) {
            std::cout << "main - warning: could not create '" << SAVEPATH << "' folder" << std::endl; std::fflush(stdout);
            /// @TODO - check if directory exists
        } else {
            std::cout << "Folder '" << SAVEPATH << "' created" << std::endl; std::fflush(stdout);
        }

    #endif
    have_save = fio.save_exists();

    #ifndef DEBUG_OUTPUT // redirect output to null
        std::string cout_file = "/dev/null";
        std::ofstream out(cout_file.c_str());
        std::cout.rdbuf(out.rdbuf());
    #else
        // --- REDIRECT STDOUT TO A FILE --- //
        #if defined(PSP) || defined(WII) || defined(ANDROID) || defined(DINGUX) || defined(PLAYSTATION2)
            //std::string cout_file = SAVEPATH + "/stdout.txt";
            std::string cout_file = FILEPATH + "/stdout.txt";
            std::streambuf *coutbuf = std::cout.rdbuf();
            std::ofstream out(cout_file.c_str());
            std::cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt!
        #endif
    #endif


    graphLib.preload();
#ifdef PLAYSTATION2
    fio.load_config(game_config);
    PS2_create_save_icons();
#endif
    draw_lib.preload();

    gameControl.currentStage = APEBOT;





	// INIT GAME
	if (GAME_FLAGS[FLAG_QUICKLOAD] == false) {
		if (gameControl.showIntro() == false) {
            std::cout << "ERROR SHOWING INTRO" << std::endl;
			return 0;
		}
	} else {
        gameControl.quick_load_game();
        //ending end_obj;
        //end_obj.start();
        //return 1;
    }

	input.clean();
	input.p1_input[BTN_START] = 0;
	input.waitTime(200);
	input.clean();

    bool run_game = true;



    while (run_game) {
        #if !defined(PSP) && !defined(DINGUX)
            timer.start_ticker();
        #endif


		#ifdef PLAYSTATION2
			RotateThreadReadyQueue(_MIXER_THREAD_PRIORITY);
        #endif


		gameControl.showGame();
#ifdef DEBUG_SHOW_FPS
        gameControl.fps_count();
#endif
        draw_lib.update_screen();
        if (input.p1_input[BTN_QUIT] == 1) {
            //std::cout << "LEAVE #3" << std::endl;
            std::fflush(stdout);
            gameControl.leave_game();
        }
        unsigned int now_ticks = timer.get_ticks();
        if (now_ticks < (1000 / FRAMES_PER_SECOND)) {
            timer.delay((1000 / FRAMES_PER_SECOND) - now_ticks);
        }

    }
	/// @TODO: sdl quit sub-systems


	
#ifdef PSP
    sceKernelExitGame();
    return 0;
#else
    SDL_Quit();
#endif
	
	return 1;
}
Beispiel #7
0
int extractPSU(gameSave_t *save, device_t dst)
{
    FILE *psuFile, *dstFile;
    int numFiles, next, i;
    char *dirName;
    char dstName[100];
    u8 *data;
    McFsEntry entry;
    float progress = 0.0;
    
    if(!save || !(dst & (MC_SLOT_1|MC_SLOT_2)))
        return 0;
    
    psuFile = fopen(save->path, "rb");
    if(!psuFile)
        return 0;
    
    // Read main directory entry
    fread(&entry, 1, 512, psuFile);
    numFiles = entry.length - 2;
    
    dirName = savesGetDevicePath(entry.name, dst);
    int ret = fioMkdir(dirName);
    
    // Prompt user to overwrite save if it already exists
    if(ret == -4)
    {
        const char *items[] = {"Yes", "No"};
        int choice = displayPromptMenu(items, 2, "Save already exists. Do you want to overwrite it?");
        if(choice == 1)
        {
            fclose(psuFile);
            free(dirName);
            return 0;
        }
    }
    
    // Skip "." and ".."
    fseek(psuFile, 1024, SEEK_CUR);
    
    // Copy each file entry
    for(i = 0; i < numFiles; i++)
    {
        progress += (float)1/numFiles;
        drawCopyProgress(progress);
        
        fread(&entry, 1, 512, psuFile);
        
        data = malloc(entry.length);
        fread(data, 1, entry.length, psuFile);
        
        snprintf(dstName, 100, "%s/%s", dirName, entry.name);
        dstFile = fopen(dstName, "wb");
        if(!dstFile)
        {
            fclose(psuFile);
            free(dirName);
            free(data);
            return 0;
        }
        fwrite(data, 1, entry.length, dstFile);
        fclose(dstFile);
        free(data);
        
        next = 1024 - (entry.length % 1024);
        if(next < 1024)
            fseek(psuFile, next, SEEK_CUR);
    }

    free(dirName);
    fclose(psuFile);
    
    return 1;
}
Beispiel #8
0
int SMS_SaveConfig ( void ) {

 int retVal = 0;
 int lRes;

 MC_GetInfo ( 0, 0, &lRes, &lRes, &lRes );
 MC_Sync ( &lRes );

 if ( lRes > -2 ) {

  SMS_MCTable lDir __attribute__(   (  aligned( 64 )  )   );

  MC_GetDir ( 0, 0, s_pSMS, 0, 1, &lDir );
  MC_Sync ( &lRes );

  if (  lRes || !fioMkdir ( s_pMC0SMS )  ) {

   int lFD = fioOpen ( s_pIcoSys, O_RDONLY );

   if ( lFD < 0 ) {

    static int lBgClr[ 4 ][ 4 ] __attribute__(   (  section( ".data" )  )    ) = {
     {  68,  23, 116,  0 },
     { 255, 255, 255,  0 },
     { 255, 255, 255,  0 },
     {  68,  23, 116,  0 }
	};
    static float lLightDir[ 3 ][ 4 ] __attribute__(   (  section( ".data" )  )    ) = {
     {  0.5F,  0.5F,  0.5F, 0.0F },
     {  0.0F, -0.4F, -0.1F, 0.0F },
     { -0.5F, -0.5F,  0.5F, 0.0F }
	};
	static float lLightCol[ 3 ][ 4 ] __attribute__(   (  section( ".data" )  )    ) = {
     { 0.3F, 0.3F, 0.3F, 0.0F },
     { 0.4F, 0.4F, 0.4F, 0.0F },
     { 0.5F, 0.5F, 0.5F, 0.0F }
	};
	static float lAmb[ 4 ] __attribute__(   (  section( ".data" )  )    ) = { 0.5F, 0.5F, 0.5F, 0.0F };

    SMS_MCIcon lIcon; memset ( &lIcon, 0, sizeof ( SMS_MCIcon )  );

	strcpy ( lIcon.m_Header, s_pPS2D );
	strcpy_sjis (  ( short* )&lIcon.m_Title, s_pSMS + 1  );

	lIcon.m_Offset =   16;
	lIcon.m_Trans  = 0x60;

    memcpy ( lIcon.m_ClrBg,    lBgClr,    sizeof ( lBgClr    )  );
    memcpy ( lIcon.m_LightDir, lLightDir, sizeof ( lLightDir )  );
    memcpy ( lIcon.m_LightCol, lLightCol, sizeof ( lLightCol )  );
    memcpy ( lIcon.m_LightAmb, lAmb,      sizeof ( lAmb      )  );

    strcpy ( lIcon.m_View, s_pSMSICN );
    strcpy ( lIcon.m_Copy, s_pSMSICN );
    strcpy ( lIcon.m_Del,  s_pSMSICN );

 	lFD = fioOpen ( s_pIcoSys, O_WRONLY | O_CREAT );

	if ( lFD >= 0 ) {

     fioWrite (  lFD, &lIcon, sizeof ( lIcon )  );
     fioClose ( lFD );

     lFD = fioOpen ( s_pSMSIcn, O_WRONLY | O_CREAT );

     if ( lFD >= 0 ) {

      fioWrite (  lFD, g_IconSMS, sizeof ( g_IconSMS )  );
      fioClose ( lFD );

     }  /* end if */

    }  /* end if */

   } else fioClose ( lFD );