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