示例#1
0
void Menu_WadList(void)
{
	char str [100];
	fatFile *fileList = NULL;
	u32      fileCnt;
	s32 ret, selected = 0, start = 0;
    char *tmpPath = malloc (MAX_FILE_PATH_LEN);

    // wiiNinja: check for malloc error
    if (tmpPath == NULL)
    {
        ret = -999; // What am I gonna use here?
		printf(" ERROR! Out of memory (ret = %d)\n", ret);
        return;
    }

	printf("[+] Retrieving file list...");
	fflush(stdout);
	
	gDirLevel = 0;

    // wiiNinja: The root is always the primary folder
    // But if the user has a /wad directory, just go there. This makes
    // both sides of the argument win
	sprintf(tmpPath, "%s:" WAD_DIRECTORY, fdev->mount);
    PushCurrentDir(tmpPath,0,0);
	//if (strcmp (WAD_DIRECTORY, WAD_ROOT_DIRECTORY) != 0)
	if (strcmp (WAD_DIRECTORY, gConfig.startupPath) != 0)
	{
        // If the directory can be successfully opened, it must exists
        //DIR_ITER *tmpDirPtr = NULL;
        //tmpDirPtr = diropen(WAD_ROOT_DIRECTORY);
        //if (tmpDirPtr)
        //{
		//	dirclose (tmpDirPtr);

            // Now push the /wad directory as the current operating folder
            //sprintf(tmpPath, "%s:" WAD_ROOT_DIRECTORY, fdev->mount);
			sprintf(tmpPath, "%s:%s", fdev->mount, gConfig.startupPath);
			//printf ("\nThe final startupPath is: %s\n", tmpPath);
			//WaitButtons ();
            PushCurrentDir(tmpPath,0,0); // wiiNinja
        //}
	}

	/* Retrieve filelist */
getList:
    if (fileList)
    {
        free (fileList);
        fileList = NULL;
    }

	ret = __Menu_RetrieveList(tmpPath, &fileList, &fileCnt);
	if (ret < 0) {
		printf(" ERROR! (ret = %d)\n", ret);
		goto err;
	}

	/* No files */
	if (!fileCnt) {
		printf(" No files found!\n");
		goto err;
	}

	for (;;) 
	{
		u32 cnt;
		s32 index;

		/* Clear console */
		Con_Clear();

		/** Print entries **/
		cnt = strlen(tmpPath);
		if(cnt>30)
			index = cnt-30;
		else
			index = 0;

		printf("[+] WAD files on [%s]:\n\n", tmpPath+index);

		/* Print entries */
		for (cnt = start; cnt < fileCnt; cnt++) 
		{
			fatFile *file     = &fileList[cnt];
			f32      filesize = file->filestat.st_size / MB_SIZE;

			/* Entries per page limit */
			if ((cnt - start) >= ENTRIES_PER_PAGE)
				break;

			strncpy(str, file->filename, 48);
			str[48]=0;

			/* Print filename */
			//printf("\t%2s %s (%.2f MB)\n", (cnt == selected) ? ">>" : "  ", file->filename, filesize);
            if (file->filestat.st_mode & S_IFDIR) // wiiNinja
				printf("\t%2s [%s]\n", (cnt == selected) ? ">>" : "  ", str);
            else
                printf("\t%2s %s (%.2f MB)\n", (cnt == selected) ? ">>" : "  ", str, filesize);

		}

		printf("\n");

		printf("[+] Press A button to (un)install a WAD file.\n");
		if(gDirLevel>1)
			printf("    Press B button to go up-level DIR");
		else
			printf("    Press B button to select a storage device");

		/** Controls **/
		u32 buttons = WaitButtons();

		/* DPAD buttons */
		if (buttons & (WPAD_BUTTON_UP | WPAD_BUTTON_LEFT)) {
			selected -= (buttons & WPAD_BUTTON_LEFT) ? ENTRIES_PER_PAGE : 1;

			if (selected <= -1)
				selected = (fileCnt - 1);
		}
		if (buttons & (WPAD_BUTTON_DOWN | WPAD_BUTTON_RIGHT)) {
			selected += (buttons & WPAD_BUTTON_RIGHT) ? ENTRIES_PER_PAGE : 1;

			if (selected >= fileCnt)
				selected = 0;
		}

		/* HOME button */
		if (buttons & WPAD_BUTTON_HOME)
			Restart();

		/* A button */
		if (buttons & WPAD_BUTTON_A)
		{
			fatFile *tmpFile = &fileList[selected];
            char *tmpCurPath;
            if (tmpFile->filestat.st_mode & S_IFDIR) // wiiNinja
            {
                if (strcmp (tmpFile->filename, "..") == 0)
                {
					selected = 0;
					start = 0;

					// Previous dir
                    tmpCurPath = PopCurrentDir(&selected, &start);
                    if (tmpCurPath != NULL)
                        sprintf(tmpPath, "%s", tmpCurPath);
						
                    goto getList;
                }
                else if (IsListFull () == true)
                {
                    WaitPrompt ("Maximum number of directory levels is reached.\n");
                }
                else
                {
                    tmpCurPath = PeekCurrentDir ();
                    if (tmpCurPath != NULL)
                    {
						if(gDirLevel>1)
							sprintf(tmpPath, "%s/%s", tmpCurPath, tmpFile->filename);
						else
							sprintf(tmpPath, "%s%s", tmpCurPath, tmpFile->filename);
                    }
                    // wiiNinja: Need to PopCurrentDir
                    PushCurrentDir (tmpPath, selected, start);
					selected = 0;
					start = 0;
                    goto getList;
                }
            }
            else
            {
                tmpCurPath = PeekCurrentDir ();
                if (tmpCurPath != NULL)
                    Menu_WadManage(tmpFile, tmpCurPath);
            }
		}

		/* B button */
		if (buttons & WPAD_BUTTON_B)
		{
			if(gDirLevel<=1)
			{
				return;
			}

			char *tmpCurPath;
			selected = 0;
			start = 0;
			// Previous dir
			tmpCurPath = PopCurrentDir(&selected, &start);
			if (tmpCurPath != NULL)
				sprintf(tmpPath, "%s", tmpCurPath);
			goto getList;
			//return;
		}

		/** Scrolling **/
		/* List scrolling */
		index = (selected - start);

		if (index >= ENTRIES_PER_PAGE)
			start += index - (ENTRIES_PER_PAGE - 1);
		if (index <= -1)
			start += index;
	}

err:
	printf("\n");
	printf("    Press any button to continue...\n");

	free (tmpPath);
	
	/* Wait for button */
	WaitButtons();
}
示例#2
0
void Menu_WadList(void)
{
	char str [100];
	fatFile *fileList = NULL;
	u32      fileCnt;
	s32 ret, selected = 0, start = 0;
    char *tmpPath = malloc (MAX_FILE_PATH_LEN);
	int installCnt = 0;
	int uninstallCnt = 0;

	//fatFile *installFiles = malloc(sizeof(fatFile) * 50);
	//int installCount = 0;

    // wiiNinja: check for malloc error
    if (tmpPath == NULL)
    {
        ret = -997; // What am I gonna use here?
		printf(" ERROR! Out of memory (ret = %d)\n", ret);
        return;
    }

	printf("[+] Retrieving file list...");
	fflush(stdout);

	gDirLevel = 0;

    // wiiNinja: The root is always the primary folder
    // But if the user has a /wad directory, just go there. This makes
    // both sides of the argument win
	sprintf(tmpPath, "%s:" WAD_DIRECTORY, fdev->mount);
    PushCurrentDir(tmpPath,0,0);
	//if (strcmp (WAD_DIRECTORY, WAD_ROOT_DIRECTORY) != 0)
	if (strcmp (WAD_DIRECTORY, gConfig.startupPath) != 0)
	{
        // If the directory can be successfully opened, it must exists
        //DIR_ITER *tmpDirPtr = NULL;
        //tmpDirPtr = diropen(WAD_ROOT_DIRECTORY);
        //if (tmpDirPtr)
        //{
		//	dirclose (tmpDirPtr);

            // Now push the /wad directory as the current operating folder
            //sprintf(tmpPath, "%s:" WAD_ROOT_DIRECTORY, fdev->mount);
			sprintf(tmpPath, "%s:%s", fdev->mount, gConfig.startupPath);
			//printf ("\nThe final startupPath is: %s\n", tmpPath);
			//WaitButtons ();
            PushCurrentDir(tmpPath,0,0); // wiiNinja
        //}
	}

	/* Retrieve filelist */
getList:
    if (fileList)
    {
        free (fileList);
        fileList = NULL;
    }

	ret = __Menu_RetrieveList(tmpPath, &fileList, &fileCnt);
	if (ret < 0) {
		printf(" ERROR! (ret = %d)\n", ret);
		goto err;
	}

	/* No files */
	if (!fileCnt) {
		printf(" No files found!\n");
		goto err;
	}

	/* Set install-values to 0 - Leathl */
	int counter;
	for (counter = 0; counter < fileCnt; counter++) {
		fatFile *file = &fileList[counter];
		file->install = 0;
	}

	for (;;)
	{
		u32 cnt;
		s32 index;

		/* Clear console */
		Con_Clear();

		/** Print entries **/
		cnt = strlen(tmpPath);
		if(cnt>30)
			index = cnt-30;
		else
			index = 0;

		printf("[+] WAD files on [%s]:\n\n", tmpPath+index);

		/* Print entries */
		for (cnt = start; cnt < fileCnt; cnt++)
		{
			fatFile *file     = &fileList[cnt];
			f32      filesize = file->filestat.st_size / MB_SIZE;

			/* Entries per page limit */
			if ((cnt - start) >= ENTRIES_PER_PAGE)
				break;

			strncpy(str, file->filename, 40); //Only 40 chars to fit the screen
			str[40]=0;

			/* Print filename */
			//printf("\t%2s %s (%.2f MB)\n", (cnt == selected) ? ">>" : "  ", file->filename, filesize);
            if (file->filestat.st_mode & S_IFDIR) // wiiNinja
				printf("\t%2s [%s]\n", (cnt == selected) ? ">>" : "  ", str);
            else
                printf("\t%2s%s%s (%.2f MB)\n", (cnt == selected) ? ">>" : "  ", (file->install == 1) ? "+" : ((file->install == 2) ? "-" : " "), str, filesize);

		}

		printf("\n");

		printf("[+] Press A to (un)install.");
		if(gDirLevel>1)
			printf(" Press B to go up-level DIR.\n");
		else
			printf(" Press B to select a device.\n");
		printf("    Use + and - to (un)mark. Press 1 for file operations.");

			/** Controls **/
		u32 buttons = WaitButtons();

		/* DPAD buttons */
		if (buttons & WPAD_BUTTON_UP) {
			selected--;

			if (selected <= -1)
				selected = (fileCnt - 1);
		}
		if (buttons & WPAD_BUTTON_LEFT) {
			selected = selected + ENTRIES_PER_PAGE;

			if (selected >= fileCnt)
				selected = 0;
		}
		if (buttons & WPAD_BUTTON_DOWN) {
			selected ++;

			if (selected >= fileCnt)
				selected = 0;
		}
			if (buttons & WPAD_BUTTON_RIGHT) {
				selected = selected - ENTRIES_PER_PAGE;

			if (selected <= -1)
				selected = (fileCnt - 1);
		}

		/* HOME button */
		if (buttons & WPAD_BUTTON_HOME)
			Restart();

		/* Plus Button - Leathl */
		if (buttons & WPAD_BUTTON_PLUS)
		{
			if(Wpad_TimeButton())
			{
			  installCnt = 0;
			  int i = 0;
			  while( i < fileCnt)
			  {
			  fatFile *file = &fileList[i];
			  if (((file->filestat.st_mode & S_IFDIR) == false) & (file->install == 0)) {
				  file->install = 1;

				  installCnt += 1;
			  }
			  else if (((file->filestat.st_mode & S_IFDIR) == false) & (file->install == 1)) {
				  file->install = 0;

				  installCnt -= 1;
			  }
			  else if (((file->filestat.st_mode & S_IFDIR) == false) & (file->install == 2)) {
				  file->install = 1;

				  installCnt += 1;
				  uninstallCnt -= 1;
			  }
			  i++;
			  }

			}
			else
			{
			  fatFile *file = &fileList[selected];
			  if (((file->filestat.st_mode & S_IFDIR) == false) & (file->install == 0)) {
				  file->install = 1;

				  installCnt += 1;
			  }
			  else if (((file->filestat.st_mode & S_IFDIR) == false) & (file->install == 1)) {
				  file->install = 0;

				  installCnt -= 1;
			  }
			  else if (((file->filestat.st_mode & S_IFDIR) == false) & (file->install == 2)) {
				  file->install = 1;

				  installCnt += 1;
				  uninstallCnt -= 1;
			  }
			  selected++;

			  if (selected >= fileCnt)
				selected = 0;
			}
		}

		/* Minus Button - Leathl */
		if (buttons & WPAD_BUTTON_MINUS)
		{

			if(Wpad_TimeButton())
			{
			  installCnt = 0;
			  int i = 0;
			  while( i < fileCnt)
			  {
			  fatFile *file = &fileList[i];
			  if (((file->filestat.st_mode & S_IFDIR) == false) & (file->install == 0)) {
				file->install = 2;

				uninstallCnt += 1;
			  }
			  else if (((file->filestat.st_mode & S_IFDIR) == false) & (file->install == 1)) {
				file->install = 2;

				uninstallCnt += 1;
				installCnt -= 1;
			  }
			  else if (((file->filestat.st_mode & S_IFDIR) == false) & (file->install == 2)) {
				file->install = 0;

				uninstallCnt -= 1;
			  }
			  i++;
			  }

			}
			else
			{
			fatFile *file = &fileList[selected];
			if (((file->filestat.st_mode & S_IFDIR) == false) & (file->install == 0)) {
				file->install = 2;

				uninstallCnt += 1;
			}
			else if (((file->filestat.st_mode & S_IFDIR) == false) & (file->install == 1)) {
				file->install = 2;

				uninstallCnt += 1;
				installCnt -= 1;
			}
			else if (((file->filestat.st_mode & S_IFDIR) == false) & (file->install == 2)) {
				file->install = 0;

				uninstallCnt -= 1;
			}
			 selected++;

			  if (selected >= fileCnt)
				selected = 0;
			}
		}

		/* 1 Button - Leathl */
		if (buttons & WPAD_BUTTON_1)
		{
			fatFile *tmpFile = &fileList[selected];
			char *tmpCurPath = PeekCurrentDir ();
            if (tmpCurPath != NULL) {
				int res = Menu_FileOperations(tmpFile, tmpCurPath);
                if (res != 0)
					goto getList;
			}
		}


		/* A button */
		if (buttons & WPAD_BUTTON_A)
		{
				fatFile *tmpFile = &fileList[selected];
				char *tmpCurPath;
				if (tmpFile->filestat.st_mode & S_IFDIR) // wiiNinja
				{
					if (strcmp (tmpFile->filename, "..") == 0)
					{
						selected = 0;
						start = 0;

						// Previous dir
						tmpCurPath = PopCurrentDir(&selected, &start);
						if (tmpCurPath != NULL)
							sprintf(tmpPath, "%s", tmpCurPath);

						installCnt = 0;
						uninstallCnt = 0;

						goto getList;
					}
					else if (IsListFull () == true)
					{
						WaitPrompt ("Maximum number of directory levels is reached.\n");
					}
					else
					{
						tmpCurPath = PeekCurrentDir ();
						if (tmpCurPath != NULL)
						{
							if(gDirLevel>1)
								sprintf(tmpPath, "%s/%s", tmpCurPath, tmpFile->filename);
							else
								sprintf(tmpPath, "%s%s", tmpCurPath, tmpFile->filename);
						}
						// wiiNinja: Need to PopCurrentDir
						PushCurrentDir (tmpPath, selected, start);
						selected = 0;
						start = 0;

						installCnt = 0;
						uninstallCnt = 0;

						goto getList;
					}
				}
				else
				{
					//If at least one WAD is marked, goto batch screen - Leathl
					if ((installCnt > 0) | (uninstallCnt > 0)) {
						char *thisCurPath = PeekCurrentDir ();
						if (thisCurPath != NULL) {
							int res = Menu_BatchProcessWads(fileList, fileCnt, thisCurPath, installCnt, uninstallCnt);

							if (res == 1) {
								int counter;
								for (counter = 0; counter < fileCnt; counter++) {
									fatFile *temp = &fileList[counter];
									temp->install = 0;
								}

								installCnt = 0;
								uninstallCnt = 0;
							}
						}
					}
					//else use standard wadmanage menu - Leathl
					else {
						tmpCurPath = PeekCurrentDir ();
						if (tmpCurPath != NULL)
							Menu_WadManage(tmpFile, tmpCurPath);
					}
				}
		}

		/* B button */
		if (buttons & WPAD_BUTTON_B)
		{
			if(gDirLevel<=1)
			{
				return;
			}

			char *tmpCurPath;
			selected = 0;
			start = 0;
			// Previous dir
			tmpCurPath = PopCurrentDir(&selected, &start);
			if (tmpCurPath != NULL)
				sprintf(tmpPath, "%s", tmpCurPath);
			goto getList;
			//return;
		}

		/** Scrolling **/
		/* List scrolling */
		index = (selected - start);

		if (index >= ENTRIES_PER_PAGE)
			start += index - (ENTRIES_PER_PAGE - 1);
		if (index <= -1)
			start += index;
	}

err:
	printf("\n");
	printf("    Press any button to continue...\n");

	free (tmpPath);

	/* Wait for button */
	WaitButtons();
}