Simple File Viewer by Timidon18th Oct 2010 20:13
|
---|
Summary This is a simple file viewer. This program gives a quick example of how to view a file in a directory. The program will display all the files of the current working directory to th Description Note: This works well for a XP OS, I have heard of some Windows 7 OS issues when dealing with permissions to read directories. Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com // Dark GDK - The Game Creators - www.thegamecreators.com // By: Timidon // Date: 10/18/2010 // ------------------------------------------------------------------------------------------------ // Example of a simple File Reader for Dark DGK - bare bones // Enjoy and Modify to your hearts desire. // ------------------------------------------------------------------------------------------------ #include "DarkGDK.h" // the main entry point for the application is this function void DarkGDK ( void ) { // Varibles char sTextOut[64]; bool bPass = false; int nFileType = -1; int nNumberOfEntries = 0; int nYpos, nXpos; // turn on sync rate and set maximum rate to 60 fps dbSetDisplayMode(640,480,32); dbSyncOn ( ); dbSyncRate ( 60 ); // Clear & Set Varibles nXpos = 0;nYpos = 16; strcpy (sTextOut,""); nNumberOfEntries=0; // Send Up First File & Directory dbFindFirst(); dbFindNext(); //because the first one is allways "." // If you want to get rid of the "source directory" the ".." at slot 0 use another dbFindNext() // I find it usefull for file detection. dbFindNext(); // comment this out and see what I am talking about.. // Clear Screen and set Opening dbCLS(); dbText(0,0,"Generatring List, this will take a few moments..."); dbSync(); // Main System Loop while ( LoopGDK ( ) || bPass == false) { // Loop False Condition - you can happy replace this with your While Loop if (bPass == false) { // Get Currently stored file type from dbFineNext() nFileType = dbGetFileType(); // If the nFileType does not return a a void (-1) then continue if (nFileType != -1) { // Update Entires nNumberOfEntries++; // Display To Screen dbText(nXpos,nYpos,dbStr(nNumberOfEntries)); dbText(nXpos+16,nYpos,dbGetFileName()); // You can also "copy" the to a string the "dbGetFileName();" // example: strcpy (sString,dbGetFileName()); // Increase Y position for screen and do a simple check nYpos+=16; if (nYpos>400) {nYpos = 16; nXpos += 200;}; // Set up next file to read dbFindNext(); } else { // No More Files, stop reading bPass = true; } } // End of Pass Give final reading instructions if (bPass == true) { strcpy(sTextOut,"Number of Entries. "); strcat(sTextOut,dbStr(nNumberOfEntries)); dbText(0,416,sTextOut); dbText(0,432,"<<Press ''Escape'' to Exit>>"); } // Snyc dbSync(); } // return back to windows return; } |