Skip to content

Commit

Permalink
Option for Wii/GC covers. DevkitPPC 30 compatible.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wiimpathy committed May 25, 2018
1 parent f295837 commit 0105935
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 55 deletions.
87 changes: 47 additions & 40 deletions source/main.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <algorithm>
#include <new>
#include <gccore.h>
#include <sys/param.h> // MAXPATHLEN devkit r29+
#include <wiiuse/wpad.h>
#include <dirent.h>
#include <fat.h>
Expand Down Expand Up @@ -96,19 +97,19 @@ bool DirExist(const char *path)
return false;
}

void CreateCache(const char *name, int indent, bool compress, bool usb)
void CreateCache(const char *name, int indent, bool compress, bool skip, bool usb)
{
int i = 0, count = 0;
u8 textureFmt = compress ? GX_TF_CMPR : GX_TF_RGB565;

DIR *dir = NULL;
struct dirent *entry = NULL;
DIR *dir = NULL;
struct dirent *entry = NULL;

if (!(dir = opendir(name)))
if (!(dir = opendir(name)))
{
printf("\nError opening %s", name);
sleep(5);
return;
return;
}

while ((entry = readdir(dir)) != NULL) {
Expand Down Expand Up @@ -149,11 +150,11 @@ void CreateCache(const char *name, int indent, bool compress, bool usb)

free(cachepath);

CreateCache(path, indent + 2, compress, usb);
CreateCache(path, indent + 2, compress, skip, usb);
}
else // Files : create cache files.
{
snprintf(path, sizeof(path), "%s/%s", name, entry->d_name);
snprintf(path, sizeof(path), "%s/%s", name, entry->d_name);

// Checks for /wiiflow/boxcovers root folder (Wii covers). Count > 1 means subdirectory ie. plugins'covers
count = 0;
Expand All @@ -164,7 +165,7 @@ void CreateCache(const char *name, int indent, bool compress, bool usb)
}

// Skips cache creation if we're in /wiiflow/boxcovers only
if(count <= 1)
if(skip && count <= 1)
{
continue;
//printf("Root, Wii cover : skip it!\n");
Expand Down Expand Up @@ -236,23 +237,23 @@ void CreateCache(const char *name, int indent, bool compress, bool usb)
free(fullpath);
}
}
}
}
closedir(dir);
}
}
closedir(dir);
}

void format_elapsed_time(char *time_str, double elapsed) {
int h, m, s, ms;

h = m = s = ms = 0;
ms = elapsed * 1000; // promote the fractional part to milliseconds
h = ms / 3600000;
ms -= (h * 3600000);
m = ms / 60000;
ms -= (m * 60000);
s = ms / 1000;
ms -= (s * 1000);
sprintf(time_str, "%02ih:%02im:%02is", h, m, s);
int h, m, s, ms;

h = m = s = ms = 0;
ms = elapsed * 1000; // promote the fractional part to milliseconds
h = ms / 3600000;
ms -= (h * 3600000);
m = ms / 60000;
ms -= (m * 60000);
s = ms / 1000;
ms -= (s * 1000);
sprintf(time_str, "%02ih:%02im:%02is", h, m, s);
}

//---------------------------------------------------------------------------------
Expand Down Expand Up @@ -302,6 +303,7 @@ int main(int argc, char **argv) {
int i = 0;
bool compressTex = true;
bool isUSB = false;
bool skipWii = true;

while(!done)
{
Expand All @@ -310,9 +312,10 @@ int main(int argc, char **argv) {
printf("\x1b[5;1HThis homebrew creates .wfc files for WiiFlow. (plugins only!)\n");
printf("\x1b[6;1HScanning the boxcovers and converting them take a long time.\n");

printf("\x1b[12;1H");
printf("\n %sCompress Textures : << %s >>\n", i ? " " : ">", compressTex ? "Yes" : "No");
printf("\n %sCovers directory : << %s >>\n", i ? ">" : " ", isUSB ? "USB" : "SD");
printf("\x1b[11;1H");
printf("\n%s Compress Textures : << %s >>\n", i ? " " : ">", compressTex ? "YES" : "NO");
printf("\n%s Covers directory : << %s >>\n", (i == 1) ? ">" : " ", isUSB ? "USB" : "SD");
printf("\n%s Skip Wii/GC covers : << %s >>\n", (i == 2) ? ">" : " ", skipWii ? "YES" : "NO");

printf("\x1b[24;0HUp/Down : Select option.\n");
printf("\x1b[25;0HLeft/Right : Modify option.\n");
Expand Down Expand Up @@ -344,6 +347,10 @@ int main(int argc, char **argv) {
{
isUSB = !isUSB;
}
else if(i==2)
{
skipWii = !skipWii;
}
}
else if(btnsGC & PAD_BUTTON_START || btnsWii & WPAD_BUTTON_PLUS)
{
Expand All @@ -358,7 +365,7 @@ int main(int argc, char **argv) {
Quit();
}

if(i>1 || i<0)
if(i>2 || i<0)
i=0;
}

Expand Down Expand Up @@ -393,27 +400,27 @@ int main(int argc, char **argv) {
// Clear screen
ClearScreen();

printf("The cache creation will begin shortly. Press Home/Start to cancel at any time.\n");
printf("The cache creation will begin shortly. Press Home/Start to cancel at any time.\n");
sleep(6);

// Create log file
sprintf(logfile, "%s:/log_cachecreate.txt", isUSB ? "usb" : "sd");
FILE *log;
log = fopen(logfile, "wb");
if (log == NULL)
{
log = fopen(logfile, "wb");
if (log == NULL)
{
ClearScreen();
printf("Error! can't open log file %s\n", logfile);
printf("Error! can't open log file %s\n", logfile);
sleep(3);
}
}
fclose(log);

// Timer to estimate duration
time_t t0, t1;
t0 = time(NULL);

// Start browsing boxcovers and creating cache files
CreateCache(".", 0, compressTex, isUSB);
CreateCache(".", 0, compressTex, skipWii, isUSB);

// Get and Display elapsed time
t1 = time(NULL);
Expand All @@ -426,16 +433,16 @@ int main(int argc, char **argv) {
printf("It took about %s\n", Timetxt);

// Append elapsed time to log file
log = fopen(logfile, "a");
if (log == NULL)
{
log = fopen(logfile, "a");
if (log == NULL)
{
ClearScreen();
printf("Error! can't open log file %s\n", logfile);
printf("Error! can't open log file %s\n", logfile);
sleep(3);
}
}
else
{
fprintf(log, "Cache generated in %s\n", Timetxt);
fprintf(log, "Cache generated in %s\n", Timetxt);
}
fclose(log);

Expand Down
6 changes: 6 additions & 0 deletions source/pngu.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ More info : http://frontier-dev.net
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include "pngu.h"
#include <png.h>

Expand Down Expand Up @@ -1020,6 +1021,11 @@ int pngu_info (IMGCTX ctx)
png_set_sig_bytes (ctx->png_ptr, 8); // We have read 8 bytes already to check PNG authenticity
}

// Silence 'incorrect sRGB profile' warning with libpng 1.6 +
#if defined(PNG_SKIP_sRGB_CHECK_PROFILE) && defined(PNG_SET_OPTION_SUPPORTED)
png_set_option(ctx->png_ptr, PNG_SKIP_sRGB_CHECK_PROFILE, PNG_OPTION_ON);
#endif

// Read png header
png_read_info (ctx->png_ptr, ctx->info_ptr);

Expand Down
26 changes: 11 additions & 15 deletions source/texture.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <ogcsys.h>
#include <sys/param.h> // MAXPATHLEN devkit r29+
#include <algorithm>
#include <malloc.h>
#include <cmath>

#include "texture.hpp"
#include <string.h>
#include <stdio.h>
#include <ogcsys.h>
#include <unistd.h>

#include "texture.hpp"
#include "pngu.h"

Expand Down Expand Up @@ -54,7 +49,8 @@ void fsop_ReadFileLoc(const char *path, const u32 size, void *loc)
u8 *fsop_ReadFile(const char *path, u32 *size)
{
*(size) = 0;
u32 filesize = 0;
size_t filesize = 0;

u8 *mem = NULL;
fsop_GetFileSizeBytes(path, &filesize);
if(filesize > 0)
Expand Down Expand Up @@ -260,13 +256,13 @@ TexErr STexture::fromImageFile(TexData &dest, const char *filename, u8 f, u32 mi

// Open log file and append any errors
FILE *log = NULL;
log = fopen(logfile, "a");
log = fopen(logfile, "a");

if (log == NULL)
{
if (log == NULL)
{
printf("fromImageFile Error! can't open log file %s.\n", logfile);
fclose(log);
}
}

u32 fileSize = 0;
u8 *Image = NULL;
Expand All @@ -282,7 +278,7 @@ TexErr STexture::fromImageFile(TexData &dest, const char *filename, u8 f, u32 mi
if(Image == NULL)
{
printf("Error opening %s!\n", filename);
fprintf(log, "Error opening %s!\n", filename);
fprintf(log, "Error opening %s!\n", filename);
fclose(log);
return TE_ERROR;
}
Expand All @@ -298,8 +294,8 @@ TexErr STexture::fromImageFile(TexData &dest, const char *filename, u8 f, u32 mi
// error : Write our log file
if(result)
{
fprintf(log, "Error converting %s\n", filename);
fprintf(log, "%s\n", buferror);
fprintf(log, "Error converting %s\n", filename);
fprintf(log, "%s\n", buferror);
}
fclose(log);

Expand Down

0 comments on commit 0105935

Please sign in to comment.