source: AE/Installer/trunk/source/installer.h@ 467

Last change on this file since 467 was 462, checked in by gumby, 15 years ago

Fixed buggy BSL stuff

File size: 7.0 KB
Line 
1 #pragma once
2/* AE/Mod Installer header file */
3#ifndef DOUBLE_HEADER
4#define DOUBLE_HEADER
5
6
7#include <string>
8#include <vector>
9#include <fstream>
10
11using namespace std;
12
13static string SLASHSLASH = "//";
14static string DIRSLASH = "\\";
15string strInstallCfg = "../GameDataFolder/Add.cfg";
16static string strInstallerVersion = "1.0";
17
18#define STRUCT_DEFS
19struct ModPackage
20{
21 bool isInstalled; //replace with function
22 string name;
23 string modStringName;
24 int modStringVersion;
25 bool hasOnis;
26 bool hasDeltas;
27 bool hasBSL;
28 bool hasAddon;
29 bool hasDats;
30 string category;
31 string creator;
32 bool isEngine;
33 string readme;
34 bool globalNeeded;
35 ModPackage();
36
37 void doOutput()
38 {
39 cout << "Mod: " << name; cout << "\n"; // remove this when done
40 cout << " String: " << modStringName << " v." << modStringVersion << "\n";
41 cout << " Category: " << category << "\n";
42 cout << " Creator: " << creator << "\n";
43 cout << " HasOnis: " << hasOnis << "\n";
44 cout << " HasBSL: " << hasBSL << "\n";
45 cout << " HasDeltas: " << hasDeltas << "\n";
46 cout << " HasDats: " << hasDats << "\n";
47 cout << " IsEngine: " << isEngine << "\n";
48 cout << " GlobalNeeded: " << globalNeeded << "\n";
49 cout << " Readme: " << readme << "\n";
50 cout << "\n";
51 }
52
53 bool operator < (const ModPackage &fs) const
54 { return (name < fs.name);}
55
56 bool operator > (const ModPackage &fs) const
57 { return (name > fs.name);}
58
59 bool operator == (const ModPackage &fs) const
60 { return (name == fs.name);}
61};
62
63#define METHOD_DEFS
64// Initialization to default values
65ModPackage::ModPackage()
66{
67 isInstalled = true; // replace with function
68 name = "";
69 modStringName = "";
70 modStringVersion = 0;
71 hasOnis = false;
72 hasDeltas = false;
73 hasBSL = false;
74 hasAddon = false;
75 hasDats = false;
76 category = "";
77 creator = "";
78 isEngine = false;
79 readme = "";
80 globalNeeded = true;
81 // void doOutput() const
82 // { };
83}
84
85#define FUNCTION_PROTOTYPES
86int mainMenu(void);
87int globalizeData(void);
88int installPackages(void);
89int uninstallPackages(void);
90int listInstalledPackages(void);
91int printInstallerInfo(void);
92vector<ModPackage> getPackages(void);
93ModPackage fileToModPackage(fstream&);
94void recompileAll(vector<string>);
95vector<string> getInstallString(string = strInstallCfg);
96void tokenize(const string&, vector<string>&, const string& delimiters = " ");
97//bool getDirectoryContents(char , char &);
98void clearOldDats(void);
99void writeInstalledMods( vector<string> );
100void setStatusArea( string );
101void setProgressBar( int );
102
103void copyBSL( string, vector<string>&, ModPackage );
104
105//New copy(path, path) function. Too lazy to implement my own, this is basically how I would have done it though.
106//No, really. :)
107//Move to utilities.cpp when the time comes.
108using namespace boost::filesystem;
109using namespace std;
110
111void copy_directory( const path & from_dir_ph,
112 const path & to_dir_ph );
113
114void copy( const path & from_file_ph,
115 const path & to_file_ph );
116
117
118// this function copies files and directories. If copying a
119// directory to a directory, it copies recursively.
120
121//pardon the mess, I did this at midnight, and had to fix a bug
122void copy( const path & from_ph,
123 const path & to_ph )
124{
125 cout << to_ph.string() << "\n";
126 // Make sure that the destination, if it exists, is a directory
127 if((exists(to_ph) && !is_directory(to_ph)) || (!exists(from_ph))) cout << "error";
128 if(!is_directory(from_ph))
129 {
130
131 if(exists(to_ph))
132 {
133 copy_file(from_ph,to_ph/from_ph.filename());
134 }
135 else
136 {
137 try{
138
139 copy_file(from_ph,to_ph);
140 }
141 catch (exception ex){
142 cout << from_ph.string() << " to " << to_ph.string() << "\n";
143 }
144 }
145
146 }
147 else if(from_ph.filename() != ".svn")
148 {
149 path destination;
150 if(!exists(to_ph))
151 {
152 destination=to_ph;
153 }
154 else
155 {
156 destination=to_ph/from_ph.filename();
157 }
158 //not sure what this did, its going away though. probably error checking ;)
159 //copy_directory(from_ph,destination);
160
161 for(directory_iterator i(from_ph); i!=directory_iterator(); ++i)
162 {
163 //the idiot who coded this in the first place (not me)
164 //forgot to make a new directory. Exception city. x_x
165 create_directory(destination);
166 copy(*i,destination/i->filename());
167 }
168 }
169}
170
171void copy_directory( const path &from_dir_ph,
172 const path &to_dir_ph)
173{
174 if(!exists(from_dir_ph) || !is_directory(from_dir_ph)
175 || exists(to_dir_ph))
176 cout << !exists(from_dir_ph) << " " << !is_directory(from_dir_ph)
177 << " " << exists(to_dir_ph);
178 //boost::throw_exception( filesystem_error(
179 //"boost::filesystem::copy_directory",
180 //from_dir_ph, to_dir_ph, boost::system::error_code() ));
181
182# ifdef BOOST_POSIX
183 struct stat from_stat;
184 if ( (::stat( from_dir_ph.string().c_str(), &from_stat ) != 0)
185 || ::mkdir(to_dir_ph.native_directory_string().c_str(),
186 from_stat.st_mode)!=0)
187# endif
188 // boost::throw_exception( filesystem_error(
189 // //"boost::filesystem::copy_directory",
190 // from_dir_ph, to_dir_ph, boost::system::error_code()));
191 }
192
193#endif
194
195#ifdef WIN32
196
197#ifndef __GUICON_H__
198
199#define __GUICON_H__
200
201
202
203void RedirectIOToConsole();
204
205
206
207#endif
208
209/* End of File */
210
211
212#include <windows.h>
213
214#include <stdio.h>
215
216#include <fcntl.h>
217
218#include <io.h>
219
220#include <iostream>
221
222#include <fstream>
223
224#ifndef _USE_OLD_IOSTREAMS
225
226using namespace std;
227
228#endif
229
230// maximum mumber of lines the output console should have
231
232static const WORD MAX_CONSOLE_LINES = 500;
233
234
235void RedirectIOToConsole()
236
237{
238
239 int hConHandle;
240
241 long lStdHandle;
242
243 CONSOLE_SCREEN_BUFFER_INFO coninfo;
244
245 FILE *fp;
246
247 // allocate a console for this app
248
249 AllocConsole();
250
251 // set the screen buffer to be big enough to let us scroll text
252
253 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE),
254
255 &coninfo);
256
257 coninfo.dwSize.Y = MAX_CONSOLE_LINES;
258
259 SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE),
260
261 coninfo.dwSize);
262
263 // redirect unbuffered STDOUT to the console
264
265 lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
266
267 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
268
269 fp = _fdopen( hConHandle, "w" );
270
271 *stdout = *fp;
272
273 setvbuf( stdout, NULL, _IONBF, 0 );
274
275 // redirect unbuffered STDIN to the console
276
277 lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE);
278
279 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
280
281 fp = _fdopen( hConHandle, "r" );
282
283 *stdin = *fp;
284
285 setvbuf( stdin, NULL, _IONBF, 0 );
286
287 // redirect unbuffered STDERR to the console
288
289 lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE);
290
291 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
292
293 fp = _fdopen( hConHandle, "w" );
294
295 *stderr = *fp;
296
297 setvbuf( stderr, NULL, _IONBF, 0 );
298
299
300 // make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog
301
302 // point to console as well
303
304 ios::sync_with_stdio();
305
306}
307
308
309
310//End of File
311
312
313
314
315
316
317#endif
Note: See TracBrowser for help on using the repository browser.