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

Last change on this file since 291 was 290, checked in by gumby, 16 years ago
File size: 2.9 KB
RevLine 
[286]1/*
2AE\Mod Installer.
3
4Needs getPackages() now!
5*/
6
7#include <string>
8#include <iostream>
9#include "methods.h"
10#include <vector>
11
[290]12#include <errno.h>
13#include "Include\dirent.h"
14#include <stdio.h>
15#include <stdlib.h>
16
17
[286]18using namespace std;
19bool FALSE = 0;
20bool TRUE = 0;
21
22
23int main(void)
24{
25
26 // SetConsoleTitle("AE Installer"); windows junk, convert to SDL
[290]27 // system("color 0A");
28
[286]29 cout << "\nWelcome to the AE installer!\n";
30
31 cout << "\nWhat would you like to do?\n";
32
33 return mainMenu();
[290]34}
35
36vector<ModPackage> getPackages(void) {
37 vector<ModPackage> packages;
38 packages.reserve(256); //thats 63 or 64 pointers to packages...i think. :P Reserving this improves performance when we add new pointers
39
40 #ifdef WIN32
41 string path = "K:\\Oni\\edition\\install\\packages"; //only for my build. :P
42 #else
43 string path = "K:\\Oni\\edition\\install\\packages"; //change this, 'scen.
44 #endif
[286]45
[290]46 string filename = "\0";
47 string MODINFO_CFG = "\\Mod_Info.cfg";
48 DIR *pdir;
49 struct dirent *pent;
50
51 pdir = opendir( path.c_str() ); //"." refers to the current dir
52 if (!pdir){
53 printf ("opendir() failure; terminating");
54 exit(1);
55 }
56 errno=0;
57 while ((pent=readdir(pdir))){
58
59
60 filename = path + '\\' + pent->d_name + MODINFO_CFG;
61
62 //cout << filename << "\n";
63
64 if (FILE * file = fopen( filename.c_str(), "r"))
65 {
66 //do stuff like adding to vector :P
67
68 cout << pent->d_name << "\n";
69
70 //would prefer to push a pointer to a package, but this will do for now
71 //packages.push_back(modelfileToModPackage(file *))
72 fclose(file);
73 }
74
75 }
76
77
78 if (errno){
79 printf ("readdir() failure; terminating");
80 exit(1);
81 }
82 closedir(pdir);
[286]83
[290]84
85 return packages;
[286]86}
87
88int mainMenu(void) {
89 int choice = '0';
90 bool ok = FALSE;
91 cout << "1. Install new packages\n";
92 cout << "2. Uninstall packages\n";
93 cout << "3. See what is installed\n";
94 cout << "4. About AE\n";
95 cout << "5. Quit\n\n";
96
97 do {
98 ok = TRUE;
99 choice = cin.get();
100 cin.ignore(1);
101 switch(choice) {
102 case '1':
103 installPackages();
104 break;
105 case '2':
106 uninstallPackages();
107 break;
108 case '3':
109 //listInstalledPackages();
110 break;
111 case '5':
112 return 0;
113 default:
114 ok = FALSE;
115 }
116 } while(ok == FALSE);
117 return 0;
118}
119
120
121void installPackages() {
122 ModPackage package;
123 vector<string> installed_packages;
124 vector<ModPackage> packages; // = getPackages()
125 vector<ModPackage>::iterator iter;
126 iter = packages.begin();
127
[290]128 getPackages();
129
[286]130 if (packages.empty()) {
131 cout << "Error: You have no packages!\n";
132 return;
133 }
134
135 cout << "Detecting installed packages...\n";
136
137 for(int i = 0; i < packages.size();) {
138 package = *iter;
139 if(!package.isInstalled){
140 packages.erase(iter);
141 }
142 else {
143 i++;
144 iter++;
145 }
146
147 }
148
149 if (packages.empty()) {
150 cout << "Error: You have no installed packages!\n";
151 return;
152 }
153
154 //listInstalledPackages(packages);
155
156}
157void uninstallPackages() {
158;
159}
160
161void getInstalledPackages() {
162;
163}
Note: See TracBrowser for help on using the repository browser.