Joshtech

PondLewder

Sep 30th, 2016
594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 34.51 KB | None | 0 0
  1. # MakeFile #
  2. BIN = Pond
  3. CC = arm-buildroot-linux-uclibcgnueabi-gcc
  4. SRC = main.c
  5. OBJ = main.o
  6. CFLAGS = -Wall -g -02 -fomit-frampointer -lSDL -lSDL_ttf -lSDL_image -ldl -lstdc++ -lm -lgcc_s -lc
  7.  
  8. $(BIN): $(OBJ)
  9.         $(CC) -o $@ $^ $(CFLAGS)
  10.  
  11. clean: $(SRC)
  12.         rm -f $(BIN) $(OBJ)
  13.  
  14.  
  15. # main.c #
  16.  
  17. #include <SDL/SDL.h>      // Main SDL Header
  18. #include <SDL/SDL_ttf.h>  // True Type Font Header
  19. #include <SDL/SDL_image.h>
  20. #include <dirent.h>
  21. #include <dlfcn.h>
  22. #include "Defines.h"  // Header with defines
  23. #include <string.h>
  24. #include <unistd.h>
  25. #include <sys/statvfs.h>
  26. #include <fcntl.h>
  27. #include <errno.h>
  28. #include <stdio.h>
  29.  
  30. typedef int boolean;
  31. enum { false, true };
  32.  
  33.  
  34. char* BASE_DIR = "PondLewder/";
  35. char* SPLASH_PATH="Assets/Images/splash.png";
  36. char* BACKGROUND_PATH = "Assets/Images/background.png";
  37. char* RING_PATH = "Assets/Images/ring.png";
  38. char* RING_SELECTED_PATH = "Assets/Images/ring_s.png";
  39. char* MAIN_TITLE_PATH = "Assets/Images/main_menu.png";
  40. char* BACKUP_DIR = "LF/Bulk/PondLewderBackups";
  41.  
  42.  
  43. char* DISNEY_FONT_PATH = "Assets/Fonts/disney_font.ttf";
  44. char* DOOM_FONT_PATH = "Assets/Fonts/doom_font.ttf";
  45.  
  46. char* CURRENT_DIR_PATH = "";
  47. char* CART_PRODUCT_ID; // We will set this on start up
  48.  
  49. char* currentCopy;
  50.  
  51.  
  52. unsigned long DISK_TOTAL;
  53. unsigned long DISK_AVALIABLE;
  54. unsigned long DISK_FREE;
  55.  
  56.  
  57. // Option Settings
  58. boolean isShowingHidden = false;
  59.  
  60. struct ImageStruct {
  61.     SDL_Surface* screen;
  62.     float x;
  63.     float y;
  64.     float orgX;
  65.     float orgY;
  66.     int dir;
  67. };
  68.  
  69.  struct AppStruct{
  70.     char name[100];
  71.     char category[20];
  72.     char type[20];
  73.     char productID[20];
  74.     char packageID[40];
  75.     char version[20];
  76.     char locale[10];
  77.     char developer[30];
  78.     char publisher[30];
  79.     char appSo[40];
  80.     char path[200];
  81.     char icon[200];
  82.     char hidden[10];
  83.     // Should we push memory lulz??
  84.     SDL_Surface* screen;
  85.     int x;
  86.     int y;
  87. };
  88.  
  89. struct ImageStruct g_DropLet;
  90. struct AppStruct Apps[300];
  91.  
  92. /* DECLARES FOR BTIO */
  93. typedef int* (*tdBTIO_SendCommand)(void*,int,void*, int);
  94. typedef int* (*tdBTIO_Init)(void (*)(void*));
  95. typedef int* (*RunApp)();
  96. struct LFController {char AButton; char BButton; char HomeButton; char HintButton; char WandPos; char VPos;
  97.                       char JoyX; char JoyY; char AccelX; char unknown; char AccelY; char unknown1; char AccelZ;
  98.                       char Counter; char Batt; char unknown2;};
  99. typedef void* (*arbitrary)();
  100.  
  101.  
  102. SDL_Surface* g_SplashScreen;  // Splash Image
  103. SDL_Surface* g_Background;    // Background Image
  104. SDL_Surface* g_Screen;        // Back buffer
  105. SDL_Surface* g_AppRingSel;
  106. SDL_Surface* g_AppRingUnSel;
  107. SDL_Surface* g_MainMenuTitle;
  108. SDL_Surface* g_OptionsTitle;
  109. SDL_Surface* g_OptionsBg;
  110.  
  111. SDL_Event g_Event;            // SDL event struct for input
  112. SDL_Surface* tempIcon;
  113. int g_Timer;                  // Timer
  114.  
  115. char* BUILD_DATE = "BUILD: v1.02-10/01/2016";
  116.  
  117. // Functions to handle different states of app
  118. void Menu();
  119. void Game();
  120. void Exit();
  121.  
  122. // Init and Shutdown functions
  123. void Init();
  124. void Shutdown();
  125.  
  126. // Helper functions for app states
  127. void DrawScreen(SDL_Surface*);
  128. void DrawImage(SDL_Surface*, int, int);
  129. SDL_Surface* LoadImage(char*);
  130. void ClearScreen();
  131. void DisplayText(char*, char*, int, int, int, int, int, int, int);
  132. void HandleMenuInput();
  133. void HandleGameInput();
  134. void HandleExitInput();
  135. void LaunchApp(char*);
  136. void MountApp(char* path);
  137. void RemoveMount();
  138. void PrintText(char*);
  139. void BackupCart();
  140. void GetAppsInDir(char*);
  141. void ReadMetaToApp(char*);
  142. char* getcwd(char*, size_t);
  143. void removeChar(char *, char);
  144. int CopyFile(char*, char*);
  145. void CopyCart();
  146. void CopyDir(char*, char*);
  147. boolean isCopying = false;
  148. int menuState = 0;
  149. //0 Init, 1 Splash, 2 Menu
  150. int appLoc = 0; // Location of where app should be
  151. int textLoc = 1; // Location of PrintText on screen
  152. int appCounter = 0; // Count for apps in array
  153. int running = 1; // Main loop
  154. int selected = 0; // App Selected in menu
  155. int page = 0; // Menu App Page
  156. void* handle; // Handle for bt
  157.  
  158.  
  159.  
  160. void PrintText( char* text){
  161.     char tempString[500];
  162.     char tempText[400];
  163.     strcpy(tempString, "drawtext-fb /dev/fb0 /var/fonts/monotext8x16.rgb \"");
  164.     strcat(tempString, text);
  165.     strcat(tempString, "\" ");
  166.     sprintf(tempText, "%d", textLoc);
  167.     strcat(tempString, tempText);
  168.     strcat(tempString, " 5 0\n");
  169.     system(tempString);
  170.     //printf(tempString);
  171.     textLoc++;
  172. }
  173.  
  174.  
  175. void CallbackFunction()
  176. {
  177.   printf("This is our callback!");
  178. }
  179.  
  180. boolean aPressed = false;
  181. boolean bPressed = false;
  182. boolean homePressed = false;
  183. boolean hintPressed = false;
  184. boolean leftPressed = false;
  185. boolean rightPressed = false;
  186. boolean upPressed = false;
  187. boolean downPressed = false;
  188.  
  189.  
  190.  
  191.  
  192. void GetCurrentDir(){
  193.     char cwd[1024];
  194.     if (getcwd(cwd, sizeof(cwd)) != NULL){
  195.         printf("Current working dir: %s\n", cwd);
  196.     } else {
  197.         printf("Failed to get current dir!");
  198.     }
  199. }
  200.  
  201. void LoaderCallBackFunction(void* callback, struct LFController* LFC, int length)
  202. {
  203.     if (LFC->JoyY > 0xC0 && upPressed == false)
  204.     {
  205.         // Joy Up
  206.         upPressed = true;
  207.         if(selected - 4 < 0){
  208.             selected = 0;
  209.         } else {
  210.             selected = selected - 4;
  211.         }
  212.     } else if(LFC->JoyY < 0xC0){
  213.         upPressed = false;
  214.     }
  215.  
  216.     if (LFC->JoyY < 0x3F && downPressed == false)
  217.     {
  218.         // Joy Down
  219.         downPressed = true;
  220.         if(selected + 4 > appCounter){
  221.             selected = appCounter - 1;
  222.         } else {
  223.             selected = selected + 4;
  224.         }
  225.     } else if (LFC->JoyY > 0x3F){
  226.         downPressed = false;
  227.     }
  228.     if (LFC->JoyX > 0xC0 && rightPressed == false)
  229.     {
  230.         // Joy Right
  231.         rightPressed = true;
  232.         if(selected + 1 > appCounter){
  233.             selected = appCounter - 1;
  234.         } else {
  235.             selected++;
  236.         }
  237.     } else if (LFC->JoyX < 0xC0){
  238.         rightPressed = false;  
  239.     }
  240.     if (LFC->JoyX < 0x3F && leftPressed == false)
  241.     {
  242.         // Joy Left
  243.         leftPressed = true;
  244.         if(selected - 1 < 0){
  245.             selected = 0;
  246.         } else {
  247.             selected--;
  248.         }
  249.     } else if (LFC->JoyX > 0x3F){
  250.         leftPressed = false;
  251.     }
  252.    
  253.     if (LFC->AButton == 0x01 && aPressed == false)
  254.     {
  255.         // A Pressed
  256.         aPressed = true;
  257.         char tempString[100];
  258.         sprintf(tempString, "%s", Apps[selected].path);
  259.         removeChar(tempString, '.');
  260.         printf("Mounting %s: %s\n", Apps[selected].name, tempString);
  261.         MountApp(tempString);
  262.     } else if (LFC->AButton == 0x00) {
  263.         aPressed = false;
  264.     }
  265.  
  266.     if (LFC->BButton == 0x01 && bPressed == false)
  267.     {
  268.         // B Pressed
  269.         bPressed = true;
  270.         BackupCart();
  271.         /*char tempString[100];
  272.         sprintf(tempString, "%s/%s", Apps[selected].path, Apps[selected].appSo);
  273.         printf("Launching %s: %s\n", Apps[selected].name, tempString);
  274.         LaunchApp(tempString);*/
  275.     } else if (LFC->BButton == 0x00){
  276.         bPressed = false;  
  277.     }
  278.     if (LFC->HomeButton == 0x01 && homePressed == false)
  279.     {
  280.         // Home Pressed
  281.         homePressed = true;
  282.         running = 0;
  283.     } else {
  284.         homePressed = false;
  285.     }
  286.     if (LFC->HintButton == 0x01 && hintPressed == false)
  287.     {
  288.         // Hint Pressed
  289.         hintPressed = true;
  290.         if(menuState){
  291.             menuState = 0;
  292.         } else {
  293.             menuState = 1;
  294.         }
  295.     } else if (LFC->HintButton == 0x00){
  296.         hintPressed = false;
  297.     }
  298.     if(selected > (page * 12) + 11){
  299.         page++;
  300.     } else if (selected < page * 12) {
  301.         page--;
  302.     }
  303. }
  304. void LaunchApp(char* path){
  305.     char* error;
  306.     void* appHandle = dlopen (path, RTLD_LAZY);
  307.     if (!appHandle) {
  308.         fputs (dlerror(), stderr);
  309.     } else {
  310.         printf("IT LOADED!");
  311.         RunApp RunCreateApp = (RunApp)dlsym(appHandle, "CreateApp");
  312.         if ((error = dlerror()) != NULL)  {
  313.             fputs(error, stderr);
  314.             fputs(" @ RunApp\n", stderr);
  315.             dlclose(appHandle);
  316.         } else {
  317.             printf("CREATED SYMBOL!"); 
  318.         }
  319.         appLoc = 3;
  320.         RunCreateApp();
  321.         //appLoc = 0;
  322.     }
  323. }
  324.  
  325. void MountApp(char* path){
  326.     // Remove symlink
  327.     RemoveMount();
  328.     // Create symlink to current path!
  329.     char tempString[1024];
  330.     sprintf(tempString, "ln -s %s /LF/Cart/0x99999999", path);
  331.     system(tempString);
  332.     //printf(tempString);
  333.     running = 0;
  334. }
  335.  
  336. void RemoveMount(){
  337.     // Remove symlink
  338.     system("rm -f /LF/Cart/0x99999999");   
  339. }
  340.  
  341. void InitControls(){
  342.     char *error;
  343.     // Open libBRIO.so
  344.     handle = dlopen ("/usr/lib/libBTIO.so", RTLD_LAZY);
  345.     if (!handle) {
  346.         fputs (dlerror(), stderr);
  347.         exit(1);
  348.     }
  349.     tdBTIO_SendCommand BTIO_SendCommand = (tdBTIO_SendCommand)dlsym(handle, "BTIO_SendCommand");
  350.     if ((error = dlerror()) != NULL)  {
  351.         fputs(error, stderr);
  352.         fputs(" @ BTIO_QueryForDevices\n", stderr);
  353.         exit(1);
  354.     }
  355.     tdBTIO_Init BTIO_Init = (tdBTIO_Init)dlsym(handle, "BTIO_Init");
  356.     if ((error = dlerror()) != NULL)  {
  357.         fputs(error, stderr);
  358.         fputs(" @ BTIO_QueryForDevices\n", stderr);
  359.         exit(1);
  360.     }
  361.     /* Init BTIO */
  362.     int* ControllerNum = BTIO_Init((void*)&CallbackFunction);//param seems to be *void callback pointer?
  363.     printf("BTIO_Init returned val of %d \n", ControllerNum);
  364.    
  365.     int* SendComRet = 0;
  366.     SendComRet = BTIO_SendCommand(ControllerNum,1,(void*)&LoaderCallBackFunction,4);
  367.     //printf("Send Command returned val of %d \n", SendComRet);
  368.     SendComRet = BTIO_SendCommand(ControllerNum,2,(void*)&LoaderCallBackFunction,4);
  369.     //printf("Send Command returned val of %d \n", SendComRet);
  370.     SendComRet = BTIO_SendCommand(ControllerNum,0,(void*)&LoaderCallBackFunction,4);
  371.     //printf("Send Command returned val of %d \n", SendComRet);
  372.     SendComRet = BTIO_SendCommand(ControllerNum,9,(void*)&LoaderCallBackFunction,4);
  373.     //printf("Send Command returned val of %d \n", SendComRet);
  374. }
  375.  
  376.  
  377. void Init()
  378. {
  379.     // We should probs also read config here aswell...
  380.     char tempString[200];
  381.     // Call this to fix frame buffer offset
  382.     system("drawrect-fb /dev/fb0 0 0 1 1 50 0x802020");
  383.     system("led-control --beat 2");
  384.     PrintText(BUILD_DATE);
  385.     PrintText("THIS SOFTWARE IS FREE! IF YOU PAID FOR IT DEMAND A REFUND!");
  386.     PrintText("**********************************");
  387.     PrintText("*  PondLewder Homebrew Launcher  *");
  388.     PrintText("*             v1.02              *");
  389.     PrintText("*      Written by Joshtech       *");
  390.     PrintText("**********************************");
  391.     PrintText("   Special Thanks to is0-mick");
  392.     PrintText("  Keep your Safety Googles on!");
  393.     PrintText("");
  394.     PrintText("       WWW.SPIFFYHACKS.COM        ");
  395.     GetCurrentDir();
  396.     //PrintText("WE WILL PUT A DEPENDANCY CHECK HERE! - TODO");
  397.     //PrintText("IF SOMETHING IS NOT FOUND IT WILL DOWNLOAD THEM");
  398.     PrintText("UNMOUNTING ANY EMULATED CARTS!");
  399.     RemoveMount();
  400.     PrintText("");
  401.     PrintText("*Initalize SDL*");
  402.     // Initilize SDL Video
  403.     if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ){
  404.         sprintf(tempString," SDL Init: FAILED! Reason: %s\n", SDL_GetError());
  405.         PrintText(tempString);
  406.         PrintText(" TERMINATING APP!");
  407.         sleep(10);
  408.         exit(1);
  409.     } else {
  410.         PrintText(" SDL_Init: OK!");
  411.     }
  412.     PrintText("*Initialize TTF*");
  413.     // Initialize the true type font library
  414.     if( TTF_Init() < 0)
  415.     {
  416.         sprintf(tempString, " TTF_Init: FAILED! Reason: %s\n", TTF_GetError());
  417.         PrintText(tempString);
  418.         PrintText(" TERMINATING APP!");
  419.         sleep(10);
  420.         exit(1);
  421.     } else {
  422.         PrintText(" TTF_Init: OK!");
  423.     }
  424.     PrintText("*Initialize SDL_Image*");
  425.     // Initialize the SDL_Image library with png support
  426.     int imgFlags = IMG_INIT_PNG;
  427.     if ( !(IMG_Init( imgFlags ) & imgFlags) ){
  428.         sprintf(tempString, " IMG_Init: FAILED! Reason: %s\n", SDL_GetError());
  429.         PrintText(tempString);
  430.         PrintText(" TERMINATING APP!");
  431.         sleep(10);
  432.         exit(1);
  433.     } else {
  434.         PrintText(" IMG_Init: OK!");
  435.     }
  436.     PrintText("*Remove Cursor*");
  437.     if ( SDL_ShowCursor(SDL_DISABLE) < 0 ) // Stupid cursor on the screen
  438.     {
  439.         sprintf(tempString, " SDL_ShowCursor: FAILED! Reason: %s\n", SDL_GetError());
  440.         PrintText(tempString);
  441.         PrintText(" TERMINATING APP!");
  442.         sleep(10);
  443.         exit(1);
  444.     } else {
  445.         PrintText(" SDL_ShowCursor(SDL_DISABLE): OK!");
  446.     }
  447.     PrintText("*Initialize SDL_TIMER*");
  448.     // Get the number of ticks since SDL was initialized
  449.     g_Timer = SDL_GetTicks();
  450.     if ( g_Timer < 0 ){
  451.         sprintf(tempString," SDL_Timer: FAILED! Reason: %s\n", SDL_GetError());
  452.         PrintText(tempString);
  453.         PrintText(" TERMINATING APP!");
  454.         sleep(10);
  455.         exit(1);
  456.     } else {
  457.         PrintText(" SDL_Timer: OK!");
  458.     }
  459.     PrintText("*Load Image Assets*");
  460.     // We will start by loading Splash screen
  461.     g_SplashScreen = LoadImage("/PondLewder/Assets/Images/splash.png");
  462.     g_Background = LoadImage("/PondLewder/Assets/Images/background.png");;
  463.     g_AppRingSel = LoadImage("/PondLewder/Assets/Images/ring_s.png");
  464.     g_AppRingUnSel = LoadImage("/PondLewder/Assets/Images/ring.png");
  465.     g_MainMenuTitle = LoadImage("/PondLewder/Assets/Images/main_menu.png");
  466.     g_OptionsTitle = LoadImage("/PondLewder/Assets/Images/options.png");
  467.     g_OptionsBg = LoadImage("/PondLewder/Assets/Images/options_bg.png");
  468.     if ( g_SplashScreen == NULL || g_Background == NULL || g_AppRingSel == NULL || g_AppRingUnSel == NULL || g_MainMenuTitle == NULL || g_OptionsTitle == NULL || g_OptionsBg == NULL){
  469.         sprintf(tempString, " IMG_Load: FAILED! Reason: %s\n", SDL_GetError());
  470.         PrintText(tempString);
  471.         PrintText(" TERMINATING APP!");
  472.         sleep(10);
  473.         exit(1);
  474.     } else {
  475.         PrintText(" IMG_Load: LOADED ALL ASSETS OK!");
  476.     }
  477.     PrintText("*Setting Video Mode*");
  478.     sprintf(tempString, " SDL_SetVideoMode: Width:%d x Height:%d", WIDTH, HEIGHT);
  479.     PrintText(tempString);
  480.     PrintText("");
  481.     PrintText(" Get ready for 88 m/ph Marty! OK! Doc!");
  482.     sleep(4);
  483.     g_Screen = SDL_SetVideoMode( WIDTH, HEIGHT, 32, SDL_SWSURFACE | SDL_FULLSCREEN | SDL_PREALLOC );
  484.     //g_Screen = SDL_SetVideoMode( 1024, 600, 32, SDL_SWSURFACE | SDL_FULLSCREEN | SDL_PREALLOC ); // For LeapPad Ultra
  485.     // Now we will check if g_Screen was set
  486.     if ( g_Screen == NULL ){
  487.         sprintf(tempString, "SDL_SetVideoMode: FAILED! Reason: %s\n", SDL_GetError());
  488.         PrintText(tempString);
  489.         PrintText("TERMINATING APP!");
  490.         sleep(10);
  491.         exit(1);
  492.     } else {
  493.         printf("SDL_SetVideoMode: Width:%d x Height:%d\n", WIDTH, HEIGHT);
  494.     }
  495.     textLoc = 1;
  496. }
  497.  
  498.                                            
  499. SDL_Surface* LoadImage(char* file)
  500. {
  501.  
  502.     // Load Image at specified path
  503.     SDL_Surface* loadedImage = IMG_Load(file);
  504.     //printf("imageLoaded good");
  505.     if(loadedImage == NULL)
  506.     {
  507.         // Dispose of old surface
  508.         SDL_FreeSurface(loadedImage);
  509.     }
  510.     return loadedImage;
  511.    
  512. }
  513.  
  514. // Lets scan ALL folders from given directory!
  515. int CheckIfCart(){
  516.     DIR           *d;
  517.     struct dirent *dir;
  518.     d = opendir("/LF/Cart");
  519.     int isCart = 0; // 0 is no cart, 1 cart inserted, 2 emulated cart (This can happen if a cart is in when startup unmount is called)
  520.     if(d)
  521.     {
  522.         while ((dir = readdir(d)) != 0)
  523.         {
  524.             // If folder has 0x99999999 then a emulated cart is already loaded
  525.             if(strcmp(dir->d_name,"0x99999999") == 1 ){
  526.                 isCart = 2;
  527.             } else if(strcmp(dir->d_name,".") && strcmp(dir->d_name,"..") && strcmp(dir->d_name,"lost+found") && strcmp(dir->d_name,".Trash-1000")){
  528.                 // This should be the cart prouctID
  529.                 isCart = 1;
  530.                 CART_PRODUCT_ID = dir->d_name; // We will set it here!
  531.             }
  532.         }
  533.         closedir(d);
  534.     }  
  535.     return isCart;
  536. }
  537.  
  538. int CopyFile(char *from, char *to)
  539. {
  540.     int fd_to, fd_from;
  541.     char buf[4096];
  542.     ssize_t nread;
  543.     int saved_errno;
  544.  
  545.     fd_from = open(from, O_RDONLY);
  546.     if (fd_from < 0)
  547.         return -1;
  548.  
  549.     fd_to = open(to, O_WRONLY | O_CREAT | O_EXCL, 0666);
  550.     if (fd_to < 0)
  551.         goto out_error;
  552.  
  553.     while (nread = read(fd_from, buf, sizeof buf), nread > 0)
  554.     {
  555.         char *out_ptr = buf;
  556.         ssize_t nwritten;
  557.  
  558.         do {
  559.             nwritten = write(fd_to, out_ptr, nread);
  560.             if (nwritten >= 0)
  561.             {
  562.                 nread -= nwritten;
  563.                 out_ptr += nwritten;
  564.             }
  565.             else if (errno != EINTR)
  566.             {
  567.                 goto out_error;
  568.             }
  569.         } while (nread > 0);
  570.     }
  571.  
  572.     if (nread == 0)
  573.     {
  574.         if (close(fd_to) < 0)
  575.         {
  576.             fd_to = -1;
  577.             goto out_error;
  578.         }
  579.         close(fd_from);
  580.  
  581.         /* Success! */
  582.         return 0;
  583.     }
  584.  
  585.   out_error:
  586.     saved_errno = errno;
  587.  
  588.     close(fd_from);
  589.     if (fd_to >= 0)
  590.         close(fd_to);
  591.  
  592.     errno = saved_errno;
  593.     return -1;
  594. }
  595.  
  596. void LoadCart(){
  597.     // First thing we must do is check if a cart is in
  598.     if(CheckIfCart()){
  599.         // There is a cart, now lets read meta.inf from cart... Should know the product id from checking cart...
  600.         printf("Cart Product ID is: %s\n",CART_PRODUCT_ID);
  601.         // We will create a tempString for formating!
  602.         char tempString[300];
  603.         sprintf(tempString, "/LF/Cart/%s/meta.inf", CART_PRODUCT_ID);
  604.         ReadMetaToApp(tempString); // Read the carts meta.inf
  605.         sprintf(tempString, "/LF/Cart/%s", Apps[appCounter].productID); // We will read the productid from the app from now on
  606.         strcpy(Apps[appCounter].path, tempString); // We have to manually add path since it's a cart
  607.         // Now the res of the image on the cart is actually larger than normal... instead of resizeing we can "load" it from the systems cache!
  608.         // System stores cart cache in /LF/Bulk/Data/Local/All/CartIconCache with the packageID.png so lets set that as the icon path :D
  609.         sprintf(tempString, "/LF/Bulk/Data/Local/All/CartIconCache/%s.png", Apps[appCounter].packageID);
  610.         printf(tempString);
  611.         // Since splash screen loads icons programatically we will do it manually here to bypass cart icon
  612.         Apps[appCounter].screen = LoadImage(tempString);
  613.         if(Apps[appCounter].screen == NULL){
  614.                     //printf("DIDN'T LOAD IMAGE! TRYING MISSING ICON");
  615.                     Apps[appCounter].screen = LoadImage("/PondLewder/Assets/Images/missing_cache.png");
  616.                     if(Apps[appCounter].screen == NULL){
  617.                         printf("FAILED TO LOAD MISSINGICON! I GIVE UP!");
  618.                     }
  619.                 }
  620.          // Increase app count so we can continue to load other apps for the list!
  621.         appCounter++;
  622.     } else if(CheckIfCart() == 2) {
  623.         printf("There is no cart inserted and a cart is being emulated!\n");
  624.     } else {
  625.         printf("There is no cart or emulated cart!\n");
  626.     }
  627. }
  628.  
  629.  
  630. void BackupCart(){
  631.     // First thing we must do is check if a cart is in
  632.     if(CheckIfCart()){
  633.         menuState = 2;
  634.         CopyCart();
  635.         menuState = 0;
  636.     } else if(CheckIfCart() == 2) {
  637.         printf("There is no cart inserted and a cart is being emulated!\n");
  638.     } else {
  639.         printf("There is no cart or emulated cart!\n");
  640.     }
  641. }
  642. void CopyCart(){
  643. // We will hard code copy for the time being
  644.     DIR           *d;
  645.     struct dirent *dir;
  646.     char temp[200];
  647.     sprintf(temp, "mkdir /%s", BACKUP_DIR); // We should probs put checks if they exist create them but meh for now
  648.     system(temp);
  649.     d = opendir("/LF/Cart");
  650.     if(d)
  651.     {
  652.         while ((dir = readdir(d)) != 0)
  653.         {
  654.             // If there is a directory on the cart...
  655.             if(dir->d_type == 4 && strcmp(dir->d_name,".") && strcmp(dir->d_name,"..") && strcmp(dir->d_name,"lost+found") && strcmp(dir->d_name,".Trash-1000") ){
  656.                 // Well this will obviously be the productID dir of the cart!
  657.                 // So lets create it in /LF/Bulk/PondLewderBackups
  658.                 // We need to make sure the dir is create first
  659.                 sprintf(temp, "mkdir /%s/%s", BACKUP_DIR, dir->d_name); // To lazy will use system call
  660.                 system(temp);
  661.                 sprintf(temp, "touch /%s/%s/.PondLewder", BACKUP_DIR, dir->d_name); // To lazy will use system call
  662.                 system(temp);
  663.                 currentCopy = dir->d_name;
  664.                 CopyDir("/LF/Cart", dir->d_name);
  665.             } else { // Then it's a file   
  666.                 //printf("%s\n", dir->d_name);
  667.             }
  668.         }
  669.         closedir(d);
  670.     }  
  671. }
  672.  
  673. void CopyDir(char* base, char* path){
  674.     DIR           *d;
  675.     struct dirent *dir;
  676.     char temp[200];
  677.     sprintf(temp, "%s/%s", base, path);
  678.     d = opendir(temp);
  679.     if(d)
  680.     {
  681.         while ((dir = readdir(d)) != 0)
  682.         {
  683.            
  684.             // If there is a directory on the cart...
  685.             if(dir->d_type == 4 && strcmp(dir->d_name,".") && strcmp(dir->d_name,"..") && strcmp(dir->d_name,"lost+found") && strcmp(dir->d_name,".Trash-1000") ){
  686.                 sprintf(temp, "%s/%s", path, dir->d_name);
  687.                 char tempSystem[200];
  688.                 // We will create this new folder in the game dir
  689.                 sprintf(tempSystem, "mkdir /%s/%s", BACKUP_DIR, temp); // To lazy will use system call
  690.                 system(tempSystem);
  691.                 CopyDir(base, temp);
  692.             } else if (strcmp(dir->d_name,".") && strcmp(dir->d_name,"..") && strcmp(dir->d_name,"lost+found") && strcmp(dir->d_name,".Trash-1000")) { // Then it's a file
  693.                 char from[300];
  694.                 char to[300];
  695.                 sprintf(from, "%s/%s/%s", base, path, dir->d_name);
  696.                 sprintf(to, "/%s/%s/%s", BACKUP_DIR, path, dir->d_name);
  697.                 //printf("%s\n", to);
  698.                 currentCopy = to;
  699.                 CopyFile(from, to);
  700.             }
  701.         }
  702.         closedir(d);
  703.     }  
  704. }
  705.  
  706. void ReadVolume(){
  707.     struct statvfs fiData;
  708.     if((statvfs("/LF/Bulk", &fiData)) < 0) {
  709.         printf("Failed to get drive info!\n");
  710.     } else {
  711.         DISK_TOTAL = fiData.f_blocks * fiData.f_frsize / 1024;
  712.         DISK_AVALIABLE = fiData.f_bavail * fiData.f_frsize / 1024;
  713.         DISK_FREE = fiData.f_bfree * fiData.f_frsize / 1024;
  714.         printf("Location: %s\n", ".");
  715.         printf("Total: %lu\n", DISK_TOTAL);
  716.         printf("Avaliable: %lu\n", DISK_AVALIABLE);
  717.         printf("Free: %lu\n", DISK_FREE);
  718.         printf("Used: %lu\n", (DISK_TOTAL - DISK_FREE));
  719.     }
  720. }
  721.  
  722.  
  723.  
  724.  
  725.  
  726. void Shutdown()
  727. {
  728.     ClearScreen();
  729.     // Shutdown the true type font library.
  730.     TTF_Quit();
  731.  
  732.     // Free our surfaces.
  733.     SDL_FreeSurface(g_Background);
  734.     SDL_FreeSurface(g_DropLet.screen);
  735.     SDL_FreeSurface(g_Screen);
  736.    
  737.     // Tell SDL to shutdown and free and resources it was using.
  738.     SDL_Quit();
  739. }
  740.  
  741.  
  742. void Menu()
  743. {
  744.  
  745.     DrawScreen(g_Background);
  746.     DisplayText("/PondLewder/Assets/Fonts/disney_font.ttf", BUILD_DATE, 1, 1, 12, 255, 255, 255, 255);
  747.     DisplayText("/PondLewder/Assets/Fonts/disney_font.ttf", "Pre-Alpha Build - WWW.SPIFFYHACKS.COM", 1, 30, 12, 0, 0, 0, 255);
  748.     char tempString[300];
  749.     sprintf(tempString, "FREE SPACE: %lu  USED SPACE: %lu  TOTAL SPACE: %lu <- THIS IS TO BE FIXED, SORRY PEOPLE!", DISK_FREE, DISK_TOTAL - DISK_FREE, DISK_TOTAL);
  750.     DisplayText("/PondLewder/Assets/Fonts/disney_font.ttf", tempString, 250, 1, 12, 255, 0, 100, 255);
  751.     switch(menuState){
  752.         case 0: // Displaying apps
  753.             DrawImage(g_MainMenuTitle, 470, 16);
  754.             int disp;
  755.             for(disp = 12 * page; disp < (12 * page) + 12 && disp < appCounter; disp++){
  756.                 if(Apps[disp].screen != NULL){
  757.                     DrawImage(Apps[disp].screen, Apps[disp].x, Apps[disp].y); //256x256
  758.                     //printf("Selected:%d & Disp:%d & Page:%d\n", selected, disp, page); // For debug
  759.                     if(disp == selected){
  760.                         DrawImage(g_AppRingSel, Apps[disp].x, Apps[disp].y); //256x256
  761.                     } else {
  762.                         DrawImage(g_AppRingUnSel, Apps[disp].x, Apps[disp].y); //256x256
  763.                     }
  764.                     DisplayText("/PondLewder/Assets/Fonts/doom_font.ttf", Apps[disp].name, Apps[disp].x + (256 / 2) - (strlen(Apps[disp].name) * 3) , Apps[disp].y + (256 - 65), 15, 0, 0, 0, 255);
  765.                 }
  766.             }
  767.             break;
  768.         case 1: // Options
  769.             // Need to write more of options... later tho will keep current code... tho since this code is in release we will put text to explain that options are still to come
  770.             DrawImage(g_OptionsBg, 22, 102);
  771.             DrawImage(g_OptionsTitle, 470, 16);
  772.             DisplayText("/PondLewder/Assets/Fonts/disney_font.ttf", "Pre-Alpha Build - WWW.SPIFFYHACKS.COM", 0, 30, 12, 0, 0, 0, 255);
  773.             break;
  774.         case 2: // Copying File
  775.             DisplayText("/PondLewder/Assets/Fonts/disney_font.ttf", "Pre-Alpha Build - WWW.SPIFFYHACKS.COM", 0, 30, 12, 0, 0, 0, 255);
  776.             DisplayText("/PondLewder/Assets/Fonts/disney_font.ttf", "COPYING... PLEASE WAIT!", 0, 360, 100, 255, 0, 0, 255);
  777.             //DisplayText("/PondLewder/Assets/Fonts/disney_font.ttf", currentCopy, 0, 500, 20, 255, 0, 0, 255);
  778.     }
  779.     SDL_UpdateRect(g_Screen, 0, 0, 0, 0);
  780. }
  781.  
  782. void SplashScreen(){
  783.     // Update screen to show splash
  784.     GetAppsInDir(".."); // This is to check whole system KEK
  785.     //GetAppsInDir("/LF/Bulk/ProgramFiles");
  786.     printf("Found %d apps\n", appCounter);
  787.     // This might push memory limits... will see
  788.     int i;
  789.     int x = 0;
  790.     int y = 0;
  791.     for (i =0; i < appCounter; i++){
  792.         // We will set "Page" locations here!!
  793.             switch (x){
  794.                 case 0:
  795.                     Apps[i].x = 10;
  796.                     break;
  797.                 case 1:
  798.                     Apps[i].x = 10 + (256 * x);
  799.                     break;
  800.                 case 2:
  801.                     Apps[i].x = 10 + (256 * x);
  802.                     break;
  803.                 case 3:
  804.                     Apps[i].x = 10 + (256 * x);
  805.                     break;
  806.             }
  807.             switch (y){
  808.                 case 0:
  809.                     Apps[i].y = 65;
  810.                     break;
  811.                 case 1:
  812.                     Apps[i].y = 20 + (256 * y);
  813.                     break;
  814.                 case 2:
  815.                     Apps[i].y = (256 * y) - 23;        
  816.             }
  817.             if(x < 3){
  818.                 x++;
  819.             } else {
  820.                 x = 0;
  821.                 if(y < 2){
  822.                     y++;
  823.                 } else {
  824.                     y = 0;
  825.                 }
  826.             }
  827.             char tempChar[150];
  828.             sprintf(tempChar, "%s/%s", Apps[i].path, Apps[i].icon);
  829.             //printf("%s\n", tempChar);
  830.             if(Apps[i].screen == NULL){
  831.                 Apps[i].screen = LoadImage(tempChar);
  832.                 if(Apps[i].screen == NULL){
  833.                     //printf("DIDN'T LOAD IMAGE! TRYING MISSING ICON");
  834.                     Apps[i].screen = LoadImage("/PondLewder/Assets/Images/missing_icon.png");
  835.                     if(Apps[i].screen == NULL){
  836.                         printf("FAILED TO LOAD MISSINGICON! I GIVE UP!");
  837.                     }
  838.                 }
  839.             } else {
  840.                 printf("App already has icon... Cache Cart Icon?\n");
  841.             }
  842.     }
  843.     // For debuging kek
  844.     /*for (i =0; i< appCounter; i++){
  845.         printf("\nApp Details:\n");
  846.         printf("%s\n", Apps[i].name);
  847.         printf("%s\n", Apps[i].type);
  848.         printf("%s\n", Apps[i].category);
  849.         printf("%s\n", Apps[i].productID);
  850.         printf("%s\n", Apps[i].packageID);
  851.         printf("%s\n", Apps[i].appSo);
  852.         printf("%s\n", Apps[i].version);
  853.         printf("%s\n", Apps[i].locale);
  854.         printf("%s\n", Apps[i].developer);
  855.         printf("%s\n", Apps[i].publisher);
  856.         printf("%s\n", Apps[i].icon);
  857.         printf("%s\n", Apps[i].hidden);
  858.         printf("%s\n", Apps[i].path);
  859.     }*/
  860.     appLoc = 2;
  861.     // We don't need this anymore maybe!
  862.     SDL_FreeSurface(g_SplashScreen);
  863.    
  864. }
  865.  
  866. char* ReturnType(int type){
  867.     switch (type){
  868.         case 8:
  869.             return "FILE";
  870.             break;
  871.         case 4:
  872.             return "DIR";
  873.             break;
  874.         case 3:
  875.             return "SYM";
  876.             break;
  877.     }
  878.     return NULL;
  879. }
  880.  
  881. void removeChar(char *str, char garbage) {
  882.  
  883.     char *src, *dst;
  884.     for (src = dst = str; *src != '\0'; src++) {
  885.         *dst = *src;
  886.         if (*dst != garbage) dst++;
  887.     }
  888.     *dst = '\0';
  889. }
  890.  
  891.  
  892. char *trim(char *str)
  893. {
  894.   char *end;
  895.  
  896.   // Trim leading space
  897.   while(isspace(*str)) str++;
  898.  
  899.   if(*str == 0)  // All spaces?
  900.     return str;
  901.  
  902.   // Trim trailing space
  903.   end = str + strlen(str) - 1;
  904.   while(end > str && isspace(*end)) end--;
  905.  
  906.   // Write new null terminator
  907.   *(end+1) = 0;
  908.  
  909.   return str;
  910. }
  911. // Function to parse meta.infs ONLY! kek
  912. void ReadMetaToApp(char* path){
  913.     //printf("Reading %s\n", path);
  914.     FILE *fr;
  915.     char line[100];
  916.     // Open meta.inf
  917.     fr = fopen (path, "rt");  
  918.  
  919.     // Lets read line for line yeh?
  920.     while(fgets(line, 100, fr) != NULL)
  921.     {
  922.         // Parse line for line
  923.         char* tempVar;
  924.         tempVar = strtok(line, "=");
  925.         if(tempVar){
  926.             // For name
  927.             if(!strcmp(tempVar, "Name")){
  928.                 tempVar = strtok(NULL, "=");
  929.                 if(tempVar){
  930.                     // Do stuff with data
  931.                     removeChar(tempVar, '"');
  932.                     strcpy(Apps[appCounter].name, trim(tempVar));
  933.                 }
  934.             }
  935.             // For Type
  936.             if(!strcmp(tempVar, "Type")){
  937.                 tempVar = strtok(NULL, "=");
  938.                 if(tempVar){
  939.                     // Do stuff with data
  940.                     removeChar(tempVar, '"');
  941.                     strcpy(Apps[appCounter].type, trim(tempVar));
  942.                 }
  943.             }
  944.             // For ProductID
  945.             if(!strcmp(tempVar, "ProductID")){
  946.                 tempVar = strtok(NULL, "=");
  947.                 if(tempVar){
  948.                     // Do stuff with data
  949.                     removeChar(tempVar, '"');
  950.                     strcpy(Apps[appCounter].productID, trim(tempVar));
  951.                 }
  952.             }
  953.             // For PackageID
  954.             if(!strcmp(tempVar, "PackageID")){
  955.                 tempVar = strtok(NULL, "=");
  956.                 if(tempVar){
  957.                     // Do stuff with data
  958.                     removeChar(tempVar, '"');
  959.                     strcpy(Apps[appCounter].packageID, trim(tempVar));
  960.                 }
  961.             }
  962.             // For Version
  963.             if(!strcmp(tempVar, "Version")){
  964.                 tempVar = strtok(NULL, "=");
  965.                 if(tempVar){
  966.                     // Do stuff with data
  967.                     removeChar(tempVar, '"');
  968.                     strcpy(Apps[appCounter].version, trim(tempVar));
  969.                 }
  970.             }
  971.             // For Locale
  972.             if(!strcmp(tempVar, "Locale")){
  973.                 tempVar = strtok(NULL, "=");
  974.                 if(tempVar){
  975.                     // Do stuff with data
  976.                     removeChar(tempVar, '"');
  977.                     strcpy(Apps[appCounter].locale, trim(tempVar));
  978.                 }
  979.             }
  980.             // For Publisher
  981.             if(!strcmp(tempVar, "Publisher")){
  982.                 tempVar = strtok(NULL, "=");
  983.                 if(tempVar){
  984.                     // Do stuff with data
  985.                     removeChar(tempVar, '"');
  986.                     strcpy(Apps[appCounter].publisher, trim(tempVar));
  987.                 }
  988.             }
  989.             // For Developer
  990.             if(!strcmp(tempVar, "Developer")){
  991.                 tempVar = strtok(NULL, "=");
  992.                 if(tempVar){
  993.                     // Do stuff with data
  994.                     removeChar(tempVar, '"');
  995.                     strcpy(Apps[appCounter].developer, trim(tempVar));
  996.                 }
  997.             }
  998.             // For AppSo
  999.             if(!strcmp(tempVar, "AppSo")){
  1000.                 tempVar = strtok(NULL, "=");
  1001.                 if(tempVar){
  1002.                     // Do stuff with data
  1003.                     removeChar(tempVar, '"');
  1004.                     strcpy(Apps[appCounter].appSo, trim(tempVar));
  1005.                 }
  1006.             }
  1007.             // For Icon
  1008.             if(!strcmp(tempVar, "Icon")){
  1009.                 tempVar = strtok(NULL, "=");
  1010.                 if(tempVar){
  1011.                     // Do stuff with data
  1012.                     removeChar(tempVar, '"');
  1013.                     strcpy(Apps[appCounter].icon, trim(tempVar));
  1014.                 }
  1015.             }
  1016.             // For Category
  1017.             if(!strcmp(tempVar, "Category")){
  1018.                 tempVar = strtok(NULL, "=");
  1019.                 if(tempVar){
  1020.                     // Do stuff with data
  1021.                     removeChar(tempVar, '"');
  1022.                     strcpy(Apps[appCounter].category, trim(tempVar));
  1023.                 }
  1024.             }
  1025.             // For Hidden
  1026.             if(!strcmp(tempVar, "Hidden")){
  1027.                 tempVar = strtok(NULL, "=");
  1028.                 if(tempVar){
  1029.                     // Do stuff with data
  1030.                     removeChar(tempVar, '"');
  1031.                     strcpy(Apps[appCounter].hidden, trim(tempVar));
  1032.                 }
  1033.             }
  1034.            
  1035.            
  1036.         }
  1037.         /*tempVar = strtok(NULL, "=");
  1038.         if(tempVar){
  1039.             printf("Second: %s\n", tempVar);
  1040.         }
  1041.         printf ("%s", line);*/
  1042.     }
  1043.     fclose(fr);  /* close the file prior to exiting the routine */
  1044. }
  1045.  
  1046.  
  1047.  
  1048. // Lets scan ALL folders from given directory!
  1049. void GetAppsInDir(char* path){
  1050.     DIR           *d;
  1051.     struct dirent *dir;
  1052.     d = opendir(path);
  1053.     if(d)
  1054.     {
  1055.         while ((dir = readdir(d)) != 0)
  1056.         {
  1057.             char temp[150];
  1058.             if(dir->d_type == 4 && strcmp(dir->d_name,".") && strcmp(dir->d_name,"..") && strcmp(dir->d_name,"Cart") ){
  1059.                 //printf("%s\n", dir->d_name); // For debug
  1060.                 sprintf(temp, "%s/%s", path, dir->d_name);
  1061.                 GetAppsInDir(temp);
  1062.             }
  1063.             if(strcmp(dir->d_name,"meta.inf") == 0){ // If folder has a meta.inf it might be an app
  1064.                 //Add to app Counter
  1065.                
  1066.                 //This is where we will read the inf   
  1067.                 sprintf(temp, "%s/%s", path, dir->d_name);
  1068.                 //printf("%s\n", temp); // Debug to be removed
  1069.                 ReadMetaToApp(temp);
  1070.                 //Assign path to APP
  1071.                 strcpy(Apps[appCounter].path, path);
  1072.                 //printf("Read %s without issues\n", temp);
  1073.                 // Display Findings for visual awesomeness
  1074.                 sprintf(temp, "SCANNING:%s/", path);
  1075.                 DrawScreen(g_SplashScreen);
  1076.                 DisplayText("/PondLewder/Assets/Fonts/disney_font.ttf", BUILD_DATE, 1, 1, 12, 0, 0, 0, 255);
  1077.                 DisplayText("/PondLewder/Assets/Fonts/doom_font.ttf",temp, 1280 / 2 -  (strlen(temp) * 3), 720-25, 20, 0, 0, 0, 255);
  1078.                 DisplayText("/PondLewder/Assets/Fonts/doom_font.ttf",Apps[appCounter].name, 1280 / 2 - (strlen(Apps[appCounter].name) * 4), 720-55, 30, 0, 0, 0, 255);
  1079.                 SDL_UpdateRect(g_Screen, 0, 0, 0, 0);
  1080.                 appCounter++; // Add 1 to app counter, for total count + array indexing
  1081.             }
  1082.            
  1083.         }
  1084.         closedir(d);
  1085.     }
  1086. }
  1087.  
  1088. // This function draws a "screen" fullscreen
  1089. void DrawScreen(SDL_Surface* screen)
  1090. {
  1091.     // These structures tell SDL_BlitSurface() the location of what
  1092.     // we want to blit and the destination we want it blitted to.
  1093.     // Presently, we blit the entire surface to the entire screen.
  1094.     SDL_Rect destination = { 0, 0, 0, 0 };
  1095.     // This just 'block-image transfers' our bitmap to our window.
  1096.     SDL_BlitSurface(screen, NULL, g_Screen, &destination);
  1097. }
  1098.  
  1099. // This function draws and image at a set location <- Since SDL 1.2 doesn't have scaleing we must have
  1100. // set image sizes already
  1101. void DrawImage(SDL_Surface* screen, int x, int y)
  1102. {
  1103.  
  1104.     SDL_Rect destination = { x, y, 0, 0 }; // <- Doesn't matter kek
  1105.  
  1106.     // This just 'block-image transfers' our bitmap to our window.
  1107.     SDL_BlitSurface(screen, NULL, g_Screen, &destination);
  1108. }
  1109.  
  1110.  
  1111. // This function simply clears the back buffer to black.
  1112. void ClearScreen()
  1113. {
  1114.     // This function just fills a surface with a given color. The
  1115.     // first 0 tells SDL to fill the whole surface. The second 0
  1116.     // is for black.
  1117.     SDL_FillRect(g_Screen, 0, 0);
  1118. }
  1119.  
  1120.  
  1121. // Changes a surface's alpha value, by altering per-pixel alpha if necessary.
  1122. void SetSurfaceAlpha (SDL_Surface *surface, Uint8 alpha)
  1123. {
  1124.     SDL_PixelFormat* fmt = surface->format;
  1125.  
  1126.     // If surface has no alpha channel, just set the surface alpha.
  1127.     if( fmt->Amask == 0 ) {
  1128.         SDL_SetAlpha( surface, SDL_SRCALPHA, alpha );
  1129.     }
  1130.     // Else change the alpha of each pixel.
  1131.     else {
  1132.         unsigned bpp = fmt->BytesPerPixel;
  1133.         // Scaling factor to clamp alpha to [0, alpha].
  1134.         float scale = alpha / 255.0f;
  1135.  
  1136.         SDL_LockSurface(surface);
  1137.         int y, x;
  1138.         for (y = 0; y < surface->h; ++y)
  1139.         for (x = 0; x < surface->w; ++x) {
  1140.             // Get a pointer to the current pixel.
  1141.             Uint32* pixel_ptr = (Uint32 *)(
  1142.                     (Uint8 *)surface->pixels
  1143.                     + y * surface->pitch
  1144.                     + x * bpp
  1145.                     );
  1146.  
  1147.             // Get the old pixel components.
  1148.             Uint8 r, g, b, a;
  1149.             SDL_GetRGBA( *pixel_ptr, fmt, &r, &g, &b, &a );
  1150.  
  1151.             // Set the pixel with the new alpha.
  1152.             *pixel_ptr = SDL_MapRGBA( fmt, r, g, b, scale * a );
  1153.         }  
  1154.  
  1155.         SDL_UnlockSurface(surface);
  1156.     }      
  1157. }  
  1158.  
  1159. // Modified Display text to set background transparent XD
  1160. void DisplayText(char* fontFile, char* text, int x, int y, int size, int fR,
  1161.                  int fG, int fB, int alpha)
  1162. {
  1163.     // Open our font and set its size to the given parameter.
  1164.     TTF_Font* font = TTF_OpenFont(fontFile, size);
  1165.     if ( font == NULL )
  1166.     {
  1167.         printf("TTF_OpenFont: FAILED! Reason: %s\n", TTF_GetError());  
  1168.     }
  1169.     SDL_Color foreground = { fR, fG, fB};   // Text color.
  1170.     //SDL_Color background = { bR, bG, bB };  // Color of what's behind the text. <- No need for this
  1171.  
  1172.     // This renders our text to a temporary surface. There
  1173.     // are other text functions, but this one looks nice.
  1174.     SDL_Surface* temp = TTF_RenderText_Blended(font, text, foreground);
  1175.     SetSurfaceAlpha( temp, alpha );
  1176.     // A structure storing the destination of our text.
  1177.     SDL_Rect destination = { x, y, 0, 0 };
  1178.  
  1179.     // Blit the text surface to our window surface, the NULL specifies the whole surface.
  1180.     SDL_BlitSurface(temp, NULL, g_Screen, &destination);
  1181.  
  1182.     // Always free memory!
  1183.     SDL_FreeSurface(temp);
  1184.  
  1185.     // Close the font.
  1186.     TTF_CloseFont(font);
  1187. }
  1188.        
  1189.  
  1190. int CreateApp()
  1191. {
  1192.     //char tempString[100];
  1193.     // Main loop
  1194.     while(running){
  1195.         switch (appLoc)
  1196.         {
  1197.             case 0:
  1198.                 Init();
  1199.                 InitControls();
  1200.                 ReadVolume();
  1201.                 LoadCart();
  1202.                 appLoc = 1;
  1203.                 break;
  1204.             case 1:
  1205.                 SplashScreen();
  1206.                 break;
  1207.             case 2:
  1208.                 Menu();
  1209.                 break;
  1210.             case 3: //Launched app
  1211.                 break;
  1212.         }
  1213.        
  1214.     }
  1215.     // We should dispose everything
  1216.     Shutdown();
  1217.     exit(0);
  1218.     return 0;
  1219. }
  1220.  
  1221. int main(int argc, char **argv){
  1222.     CreateApp();
  1223.     exit(0);
  1224.     return 0;
  1225. }
Advertisement
Add Comment
Please, Sign In to add comment