Ignore:
Timestamp:
Apr 6, 2009, 5:13:01 AM (16 years ago)
Author:
gumby
Message:

Reader is pretty much finished. What to work on now?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • AE/Installer/trunk/source/subs.cpp

    r293 r294  
    66
    77#include <string>
     8//#include <string.h>
     9#include <cctype>
    810#include <iostream>
    911#include "methods.h"
     
    1315#include <errno.h>
    1416#ifdef WIN32
    15         #include "Include\dirent.h"
     17#include "Include\dirent.h"
    1618#else
    17         #include <dirent.h> //??? is this included for Macs?
     19#include <dirent.h> //??? is this included for Macs?
    1820#endif
    1921#include <stdio.h>
     
    3133        //      SetConsoleTitle("AE Installer"); windows junk, convert to SDL
    3234        //      system("color 0A");
    33        
     35
    3436        cout << "\nWelcome to the AE installer!\n";
    3537
    3638        cout << "\nWhat would you like to do?\n";
    37        
     39
    3840        return mainMenu();
    3941}
    40  
     42
    4143vector<ModPackage> getPackages(void) {
    4244        vector<ModPackage> packages;
    4345        packages.reserve(256); //thats 63 or 64 pointers to packages...i think. :P Reserving this improves performance when we add new pointers
    44        
     46
    4547        fstream file;
    46        
    47         #ifdef WIN32
    48                 string path = "K:\\Oni\\edition\\install\\packages"; //only for my build. :P
    49         #else
    50                 string path = "K:\\Oni\\edition\\install\\packages"; //change this, 'scen.
    51         #endif
     48
     49#ifdef WIN32
     50        string path = "K:\\Oni\\edition\\install\\packages"; //only for my build. :P
     51#else
     52        string path = "K:\\Oni\\edition\\install\\packages"; //change this, 'scen.
     53#endif
    5254
    5355        string filename = "\0";
    5456        string MODINFO_CFG = "\\Mod_Info.cfg";
    5557
    56        
     58
    5759
    5860        DIR *pdir;
     
    6769
    6870        while (( pent = readdir(pdir) )){
    69                
     71
    7072                filename = path + '\\' + pent->d_name + MODINFO_CFG;
    7173                file.open(filename.c_str());
     
    7678                {
    7779                        //file.open(filename.c_str(), fstream::out);
    78                                
     80
    7981                        //do stuff like adding to vector :P
    8082
    8183                        //would prefer to push a pointer to a package, but this will do for now
    8284                        packages.push_back( fileToModPackage(file) );
    83                        
     85
    8486                }       
    8587                file.close();
    8688                file.clear();
    87                
    88         }
    89 
    90        
     89
     90        }
     91
     92
    9193        if (errno){
    9294                printf ("readdir() failure; terminating");
    93         exit(1);
     95                exit(1);
    9496        }
    9597        closedir(pdir);
    96        
    97        
     98
     99
    98100        return packages;
    99101}
    100102
    101103ModPackage fileToModPackage(fstream &file) {
    102         ModPackage package = {0, ""};
     104        /*
     105                This converts a file to a ModPackage struct.
     106
     107                A few notes...
     108                        "iter" is the current word we are on. I should have named it "token" or something, but I don't have multiple iterators, so its ok.
     109                        I refer to (*iter) at the beginning of each if statement block. I could probably store it as a variable, but I'm pretty sure that dereferencing a pointer\iterator isn't much slower than reading a variable.
     110        */
     111        ModPackage package;
    103112        string line;
    104         static string NameOfMod = "NameOfMod"; //used for comparing to the current token
    105         static string SLASHSLASH = "//";
    106         static string ARROW = "->";
    107                         while (! file.eof() )
    108                         {
    109                                 getline (file,line);
    110                                      vector<string> tokens;
    111                                          vector<string>::iterator iter;
    112                                 Tokenize(line, tokens);                                 //string to vector of "words"
    113                                 if (tokens.capacity() >= 2) {                   //make sure they are using enough stuff
    114                                         iter = tokens.begin();                          //what word we are on, starts at first word
    115                                                                                 /*
    116                                         if (!AEInstallVersion.compare(*iter))
    117                                                 If mod is too old, skip this mod.
    118                                         */
    119                                         /*else*/if (!NameOfMod.compare(*iter))  {       //if it contains the name
    120                                                 for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) {     //interates through the words, ends if it reaches the end of the line or a "//" comment
    121                                                         if (ARROW.compare(*iter) && NameOfMod.compare(*iter)) {                 //ignores "->" and "NameOfMod"
    122                                                                 //cout << *iter;
    123                                                                 //cout << " ";
    124                                                                 package.name += *iter + " ";
    125                                                         }
    126                                                 }
    127                                                 cout << package.name; cout << "\n"; //remove this when done
    128                                         /*
    129                                         else if (!ModString.compare(*iter)
    130                                         else if (!HasOnis.compare(*iter)
    131                                         else if (!HasDeltas.compare(*iter)
    132                                         else if (!HasBSL.compare(*iter)
    133                                         else if (!HasDats.compare(*iter)
    134                                         else if (!Category.compare(*iter)
    135                                         else if (!Creator.compare(*iter)
    136                                         else if (!IsEngine.compare(*iter)
    137                                         else if (!Readme.compare(*iter)
    138                                         else if (!GlobalNeeded.compare(*iter)
    139                                         */
    140                                         }
    141                                         //cout << *iter;
    142                                 }
    143                        
    144                         }
    145                        
     113        static string NameOfMod = "NameOfMod";  //used for comparing to the current token...
     114        static string SLASHSLASH = "//";                //I could have done it in reverse (*iter).compare("ModString") or 
     115        static string ARROW = "->";                             //did something like "ModString".compare(*iter), and it would have been
     116        static string ModString = "ModString";  //functionably the same.
     117        static string HasOnis = "HasOnis";
     118        static string HasDeltas = "HasDeltas";
     119        static string HasBSL = "HasBSL";
     120        static string HasDats = "HasDats";
     121        static string IsEngine = "IsEngine";
     122        static string Readme = "Readme";
     123        static string GlobalNeeded = "GlobalNeeded";
     124        static string Category = "Category";
     125        static string Creator = "Creator";
     126        while (! file.eof() )
     127        {
     128                getline (file,line);
     129                vector<string> tokens;
     130                vector<string>::iterator iter;
     131                Tokenize(line, tokens);                                 //string to vector of "words"
     132                if (tokens.capacity() >= 2) {                   //make sure they are using enough stuff
     133                        iter = tokens.begin();                          //what word we are on, starts at first word
     134                        /*
     135                        if (!AEInstallVersion.compare(*iter))
     136                        If mod is too old, skip this mod.
     137                        */
     138                        /*else*/if (!NameOfMod.compare(*iter))  {       //if it contains the name
     139                                for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) {     //interates through the words, ends if it reaches the end of the line or a "//" comment
     140                                        if (ARROW.compare(*iter) && NameOfMod.compare(*iter)) {                 //ignores "->" and "NameOfMod"
     141                                                //cout << *iter;
     142                                                //cout << " ";
     143                                                package.name += *iter + " ";
     144                                        }
     145                                }
     146                               
     147                        }
     148                        else if (!ModString.compare(*iter)) {
     149                                iter++; iter++;
     150                                package.modStringName = *iter;
     151                                iter++;
     152                                package.modStringVersion = atoi((*iter).c_str());
     153                        }
     154                        else if (!HasOnis.compare(*iter)) {
     155                                iter++; iter++; 
     156                                if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasOnis = 1; //Gotta love c++'s lack of a standard case-insensitive string comparer...I know my implementation here sucks. I need to change it to check each character one by one. At the moment, using "YFR" would probably set it off. :<
     157                        }
     158                        else if (!HasBSL.compare(*iter)) {
     159                                iter++; iter++; 
     160                                if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasBSL = 1;
     161                        }
     162                        else if (!HasDeltas.compare(*iter)) {
     163                                iter++; iter++; 
     164                                if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasDeltas = 1;
     165                        }
     166                        else if (!HasDats.compare(*iter)) {
     167                                iter++; iter++; 
     168                                if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasDats = 1;
     169                        }
     170                        else if (!IsEngine.compare(*iter)) {
     171                                iter++; iter++; 
     172                                if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.isEngine = 1;
     173                        }
     174                        else if (!GlobalNeeded.compare(*iter)) {
     175                                iter++; iter++; 
     176                                if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.globalNeeded = 1;
     177                                else if (toupper((*iter)[0]) + toupper((*iter)[1]) == 'N' + 'O') package.globalNeeded = 1; //Really the only place where checking for "No" is important atm.
     178                        }
     179                        else if (!Category.compare(*iter))  {   
     180                                for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) {     //interates through the words, ends if it reaches the end of the line or a "//" comment
     181                                        if (ARROW.compare(*iter) && Category.compare(*iter)) {                  //ignores "->" and "Category"
     182                                                //cout << *iter;
     183                                                //cout << " ";
     184                                                package.category += *iter + " ";
     185                                        }
     186                                }
     187                        }
     188                        else if (!Creator.compare(*iter))  {    //if it contains the name
     189                                for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) {     //interates through the words, ends if it reaches the end of the line or a "//" comment
     190                                        if (ARROW.compare(*iter) && Creator.compare(*iter)) {                   //ignores "->" and "Category"
     191                                                //cout << *iter;
     192                                                //cout << " ";
     193                                                package.creator += *iter + " ";
     194                                        }
     195                                }
     196                        }
     197                        else if (!Readme.compare(*iter))  {     //if it contains the name
     198                                for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) {     //interates through the words, ends if it reaches the end of the line or a "//" comment
     199                                        if (ARROW.compare(*iter) && Readme.compare(*iter)) {                    //ignores "->" and "Category"
     200                                                //cout << *iter;
     201                                                //cout << " ";
     202                                                package.readme += *iter + " ";
     203                                        }
     204                                }
     205                        }
     206                }
     207
     208        }
     209        package.doOutput();
    146210        return package;
    147211}
     
    155219        cout << "4. About AE\n";
    156220        cout << "5. Quit\n\n";
    157        
     221
    158222        do {
    159223                ok = TRUE;
     
    186250        vector<ModPackage>::iterator iter;
    187251        iter = packages.begin();
    188        
     252
    189253        getPackages();
    190254
     
    193257                return;
    194258        }
    195                        
     259
    196260        cout << "Detecting installed packages...\n";
    197        
    198                 for(int i = 0; i < packages.size();) {
     261
     262        for(int i = 0; i < packages.size();) {
    199263                package = *iter;
    200264                if(!package.isInstalled){
     
    205269                        iter++;
    206270                }
    207                
    208         }
    209        
     271
     272        }
     273
    210274        if (packages.empty()) {
    211275                cout << "Error: You have no installed packages!\n";
    212276                return;
    213277        }
    214        
     278
    215279        //listInstalledPackages(packages);
    216        
     280
    217281}
    218282void uninstallPackages() {
    219 ;
     283        ;
    220284}
    221285
    222286void getInstalledPackages() {
    223 ;
    224 }
     287        ;
     288}
Note: See TracChangeset for help on using the changeset viewer.