예제 #1
0
파일: main.c 프로젝트: gocario/tvds
int main(void)
{
	gfxInitDefault();
	consoleInitDefault();

	Result ret;
	state = STATE_START;

	ret = FS_Init();
	if (R_FAILED(ret))
	{
		consoleLog("\nCouldn't initialize the FS module!\n");
		consoleLog("Have you selected a title?\n");
		consoleLog("Error code: 0x%lx\n", ret);
		// state = STATE_ERROR; // TODO: Remove out of Citra
	}

	ret = saveInit();
	if (R_FAILED(ret))
	{
		consoleLog("\nCouldn't initialize the Save module!\n");
		consoleLog("Error code: 0x%lx\n", ret);
		// state = STATE_ERROR; // TODO: Remove out of Citra
	}

	ret = saveGetTitleId(&titleid);
	if (R_FAILED(ret))
	{
		consoleLog("\nCouldn't get the title id of the game!\n");
		consoleLog("Error code: 0x%lx\n", ret);
		// state = STATE_ERROR; // TODO: Remove out of Citra
	}

	fsDirInit();
	fsBackInit(titleid);
	switchState(&state);
	consoleSelectNew(&consoleLog);

	drawHelp();

	u64 heldUp = 0;
	u64 heldDown = 0;
	u32 kDown, kHeld;
	while (aptMainLoop())
	{
		gspWaitForVBlank();
		hidScanInput();

		kDown = hidKeysDown();
		kHeld = hidKeysHeld();

		switch (state)
		{
			case STATE_BROWSE:
			{
				if (kDown & (KEY_LEFT | KEY_RIGHT))
				{
					fsDirSwitch(NULL);
					fsDirPrintSave();
					fsDirPrintSdmc();
				}

				if (kDown & KEY_ZL)
				{
					fsDirSwitch(&saveDir);
					fsDirPrintSave();
					fsDirPrintSdmc();
				}

				if (kDown & KEY_ZR)
				{
					fsDirSwitch(&sdmcDir);
					fsDirPrintSave();
					fsDirPrintSdmc();
				}

				if (kDown & KEY_UP)
				{
					fsDirMove(-1);
					fsDirPrintCurrent();
					heldUp = svcGetSystemTick() + HELD_TICK * 2;
				}
#ifndef NO_HELD_TICK
				else if (kHeld & KEY_UP)
				{
					if (heldUp + HELD_TICK < svcGetSystemTick())
					{
						fsDirMove(-1);
						fsDirPrintCurrent();
						heldUp = svcGetSystemTick();
					}
				}
#endif

				if (kDown & KEY_DOWN)
				{
					fsDirMove(+1);
					fsDirPrintCurrent();
					heldDown = svcGetSystemTick() + HELD_TICK * 2;
				}
#ifndef NO_HELD_TICK
				else if (kHeld & KEY_DOWN)
				{
					if (heldDown + HELD_TICK < svcGetSystemTick())
					{
						fsDirMove(+1);
						fsDirPrintCurrent();
						heldDown = svcGetSystemTick();
					}
				}
#endif

				if (kDown & KEY_A)
				{
					ret = fsDirGotoSubDir();
					consoleLog("   > fsDirGotoSubDir: %lx\n", ret);
					fsDirPrintCurrent();
				}

				if (kDown & KEY_B)
				{
					ret = fsDirGotoParentDir();
					consoleLog("   > fsDirGotoParentDir: %lx\n", ret);
					fsDirPrintCurrent();
				}

				if (kDown & KEY_X)
				{
					ret = fsDirDeleteCurrentEntry();
					consoleLog("   > fsDirDeleteCurrentEntry: %lx\n", ret);
					fsDirPrintCurrent();
				}

				if (kDown & KEY_Y)
				{
					ret = fsDirCopyCurrentEntry(false);
					consoleLog("   > fsDirCopyCurrentEntry: %lx\n", ret);
					fsDirPrintDick();
				}

				break;
			}
			case STATE_BACKUP:
			{
				if (kDown & KEY_A)
				{
					ret = fsBackImport();
					consoleLog("  > fsBackImport: %lx\n", ret);
					fsBackPrintSave();
				}

				if (kDown & KEY_B)
				{
					state = STATE_BACKUP_KEY;

					// TODO: setKeyboardString

					consoleSelectNew(&logConsole);
				}

				if (kDown & KEY_X)
				{
					ret = fsBackDelete();
					consoleLog("  > fsBackDelete: %lx\n", ret);
					fsBackPrintBackup();
				}

				if (kDown & KEY_Y)
				{
					ret = fsBackExport();
					consoleLog("  > fsBackExport: %lx\n", ret);
					fsBackPrintBackup();
				}

				if (kDown & KEY_UP)
				{
					fsBackMove(-1);
					fsBackPrintBackup();
					heldUp = svcGetSystemTick() + HELD_TICK * 2;
				}
#ifndef NO_HELD_TICK
				else if (kHeld & KEY_UP)
				{
					if (heldUp + HELD_TICK < svcGetSystemTick())
					{
						fsBackMove(-1);
						fsBackPrintBackup();
						heldUp = svcGetSystemTick();
					}
				}
#endif

				if (kDown & KEY_DOWN)
				{
					fsBackMove(+1);
					fsBackPrintBackup();
					heldDown = svcGetSystemTick() + HELD_TICK * 2;
				}
#ifndef NO_HELD_TICK
				else if (kHeld & KEY_DOWN)
				{
					if (heldDown + HELD_TICK < svcGetSystemTick())
					{
						fsBackMove(+1);
						fsBackPrintBackup();
						heldDown = svcGetSystemTick();
					}
				}
#endif

				break;
			}
			case STATE_BACKUP_KEY:
			{
				// TODO: updateKeyboard

				if (kDown & KEY_A)
				{
					state = STATE_BACKUP;

					// TODO: getKeyboardString

					drawBackup();
				}

				if (kDown & KEY_B)
				{
					state = STATE_BACKUP;
					drawBackup();
				}

				break;
			}
			case STATE_ERROR:
			{
				consoleLog("\nAn error has occured...\n");
				consoleLog("Please check previous logs!\n");
				consoleLog("\nPress start to exit.\n");
				state = STATE_EOF;
				break;
			}
			default: break;
		}

		{
			if (kDown & KEY_L)
			{
				// TODO: Prev
				switchState(&state);
			}

			if (kDown & KEY_R)
			{
				// TODO: Next
				switchState(&state);
			}

			if (kDown & KEY_SELECT)
			{
				drawHelp();
			}
		}

		if (kDown & KEY_START)
			break;

		gfxFlushBuffers();
		gfxSwapBuffers();
	}

	fsDirExit();
	fsBackExit();
	FS_Exit();
	{
		hidScanInput();
		if (!(hidKeysHeld() & KEY_L) && !(hidKeysHeld() & KEY_R))
		{
			u8 out = 0;
			FS_MediaType mediaType = 3;
			FSUSER_GetMediaType(&mediaType);
			Result ret = saveRemoveSecureValue(titleid, mediaType, &out);
			if (R_FAILED(ret))
			{
				consoleSelect(&logConsole);
				printf("\nSecure value not removed.\n");
				printf("It might already be unitialized.\n");
				printf("Error code: 0x%lx (%i)\n", ret, out);
				printf("\n\nPress any key to exit.\n");
				waitKey(KEY_ANY);
			}
		}
	}
	gfxExit();
	return 0;
}
예제 #2
0
파일: main.cpp 프로젝트: Wheth/PHBank
int main(void)
{
	Result ret = 0, error = 0;

	sf2d_init();
	sftd_init();
	romfsInit();

	srand(osGetTime());

	// consoleInit(GFX_TOP, NULL); // TODO: Comment it!
	// consoleInit(GFX_BOTTOM, NULL); // TODO: Comment it!

	printf("> Loading texture manager\n");
	PHBanku::texture = new TextureManager();
	ret = PHBanku::texture->load();
	if (R_FAILED(ret))
	{
		// Graphics
		error |= ERR_GRAPHICS;
	}

	printf("> Loading font manager\n");
	PHBanku::font = new FontManager();
	ret = PHBanku::font->load();
	if (R_FAILED(ret))
	{
		// Font
		error |= ERR_FONT;
	}

	printf("> Loading data manager\n");
	PHBanku::data = new DataManager();
	ret = PHBanku::data->load();
	if (R_FAILED(ret))
	{
		// Data
		error |= ERR_DATA;
	}

#ifdef __cia
	printf("> Starting title selector\n");
	while (!error && TS_Loop())
	{

	// Draw the static loading screen again because of ts.h
	PHBanku::texture->drawStaticLoadingScreen();

	printf("> Loading filesystem services\n");
	ret = FSCIA_Init(titleEntry.titleid, titleEntry.mediatype);
	if (R_FAILED(ret))
	{
		// Filesystem
		error |= ERR_FILESYSTEM;
	}
#else // __3dsx
	printf("> Loading filesystem services\n");
	ret = FS_Init();
	if (R_FAILED(ret))
	{
		// Filesystem
		error |= ERR_FILESYSTEM;
	}
#endif

	printf("> Loading save manager\n");
	PHBanku::save = new SaveManager();
	ret = PHBanku::save->load();
	if (R_FAILED(ret))
	{
		// Save
		error |= ERR_SAVE;
	}

	if (!error)
	{
		printf("> Starting box viewer...\n");
		Viewer* viewer = new BoxViewer();

		ViewState state = Viewer::startMainLoop(viewer);

		if (state == ViewState::Saving)
		{
			// TODO Remove when better save display!
			consoleInit(GFX_TOP, NULL);
			printf("Saving...\n");
			// ^

			PHBanku::save->save();
		}
		else
		{
			// TODO Remove when better exit display!
			consoleInit(GFX_TOP, NULL);
			printf("Exiting...\n");
			// ^
		}

		delete viewer;
	}

	delete PHBanku::save;

#ifdef __cia
	FSCIA_Exit();
	consoleExit(GFX_TOP, NULL);
	break; // TODO Remove! The app crash itself after the 2nd ts, unknown cause.
	} // while (TS_LOOP())

	if (!error)
	{
		// TODO Remove when better exit display!
		consoleInit(GFX_BOTTOM, NULL);
		// ^

		printf("\nThe app execution ended!\n");
		printf("Thanks for being awesome!\n");
	}
#else
	FS_Exit();
#endif

	if (error)
	{
		// TODO Remove when better error display!
		consoleInit(GFX_TOP, NULL);
		// ^

		printf("\nProblem happened: 0x%lx\n", error);
		if (error & ERR_SAVE) printf(" \a Save\n");
		if (error & ERR_DATA) printf(" \a Data\n");
		if (error & ERR_FONT) printf(" \a Font\n");
		if (error & ERR_GRAPHICS) printf(" \a Graphics\n");
		if (error & ERR_FILESYSTEM) printf(" \a Filesystem\n");
		printf("PHBank version: %08x\n", VERSION);
		printf("Can't start the viewer.\n");
		printf("Press any key to exit\n");
		waitKey(KEY_ANY);
	}

	delete PHBanku::data;
	delete PHBanku::font;
	delete PHBanku::texture;

	romfsExit();
	sftd_fini();
	sf2d_fini();
	return 0;
}