source: AE/Installer/trunk/source/subs.cpp@ 296

Last change on this file since 296 was 294, checked in by gumby, 16 years ago

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

File size: 8.1 KB
RevLine 
[294]1/*
2AE\Mod Installer.
3
4Needs getPackages() now!
5*/
6
7#include <string>
8//#include <string.h>
9#include <cctype>
10#include <iostream>
11#include "methods.h"
12#include <vector>
13#include <fstream>
14
[290]15#include <errno.h>
[293]16#ifdef WIN32
[294]17#include "Include\dirent.h"
[293]18#else
[294]19#include <dirent.h> //??? is this included for Macs?
[293]20#endif
[290]21#include <stdio.h>
[294]22#include <stdlib.h>
23
24
25using namespace std;
26bool FALSE = 0;
27bool TRUE = 0;
28
29
30int main(void)
31{
32
33 // SetConsoleTitle("AE Installer"); windows junk, convert to SDL
34 // system("color 0A");
35
36 cout << "\nWelcome to the AE installer!\n";
37
38 cout << "\nWhat would you like to do?\n";
39
40 return mainMenu();
41}
42
43vector<ModPackage> getPackages(void) {
44 vector<ModPackage> packages;
45 packages.reserve(256); //thats 63 or 64 pointers to packages...i think. :P Reserving this improves performance when we add new pointers
46
47 fstream file;
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
54
55 string filename = "\0";
56 string MODINFO_CFG = "\\Mod_Info.cfg";
57
58
59
[290]60 DIR *pdir;
61 struct dirent *pent;
62
63 pdir = opendir( path.c_str() ); //"." refers to the current dir
64 if (!pdir){
65 printf ("opendir() failure; terminating");
66 exit(1);
67 }
[292]68 errno=0;
69
70 while (( pent = readdir(pdir) )){
[294]71
[290]72 filename = path + '\\' + pent->d_name + MODINFO_CFG;
[292]73 file.open(filename.c_str());
74
[290]75 //cout << filename << "\n";
76
[292]77 if(!file.fail() )
[290]78 {
[292]79 //file.open(filename.c_str(), fstream::out);
[294]80
[290]81 //do stuff like adding to vector :P
[293]82
[292]83 //would prefer to push a pointer to a package, but this will do for now
[293]84 packages.push_back( fileToModPackage(file) );
[294]85
[292]86 }
87 file.close();
88 file.clear();
[294]89
[290]90 }
91
[294]92
[290]93 if (errno){
94 printf ("readdir() failure; terminating");
[294]95 exit(1);
[290]96 }
[294]97 closedir(pdir);
98
99
100 return packages;
101}
102
103ModPackage fileToModPackage(fstream &file) {
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;
112 string line;
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 + " ";
[293]144 }
145 }
[294]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();
210 return package;
211}
212
213int mainMenu(void) {
214 int choice = '0';
215 bool ok = FALSE;
216 cout << "1. Install new packages\n";
217 cout << "2. Uninstall packages\n";
218 cout << "3. See what is installed\n";
219 cout << "4. About AE\n";
220 cout << "5. Quit\n\n";
221
222 do {
223 ok = TRUE;
224 choice = cin.get();
225 cin.ignore(1);
226 switch(choice) {
227 case '1':
228 installPackages();
229 break;
230 case '2':
231 uninstallPackages();
232 break;
233 case '3':
234 //listInstalledPackages();
235 break;
236 case '5':
237 return 0;
238 default:
239 ok = FALSE;
240 }
241 } while(ok == FALSE);
242 return 0;
243}
244
245
246void installPackages() {
247 ModPackage package;
248 vector<string> installed_packages;
249 vector<ModPackage> packages; // = getPackages()
250 vector<ModPackage>::iterator iter;
251 iter = packages.begin();
252
253 getPackages();
254
255 if (packages.empty()) {
256 cout << "Error: You have no packages!\n";
257 return;
258 }
259
260 cout << "Detecting installed packages...\n";
261
262 for(int i = 0; i < packages.size();) {
263 package = *iter;
264 if(!package.isInstalled){
265 packages.erase(iter);
266 }
267 else {
268 i++;
269 iter++;
270 }
271
272 }
273
274 if (packages.empty()) {
275 cout << "Error: You have no installed packages!\n";
276 return;
277 }
278
279 //listInstalledPackages(packages);
280
281}
282void uninstallPackages() {
283 ;
284}
285
286void getInstalledPackages() {
287 ;
288}
Note: See TracBrowser for help on using the repository browser.