1 | /* AE/Mod Installer header file */
|
---|
2 |
|
---|
3 | #include <string>
|
---|
4 | #include <vector>
|
---|
5 | #include <fstream>
|
---|
6 |
|
---|
7 | using namespace std;
|
---|
8 |
|
---|
9 | static string SLASHSLASH = "//";
|
---|
10 | static string DIRSLASH = "\\";
|
---|
11 |
|
---|
12 | #define STRUCT_DEFS
|
---|
13 | struct ModPackage
|
---|
14 | {
|
---|
15 | bool isInstalled; //replace with function
|
---|
16 | string name;
|
---|
17 | string modStringName;
|
---|
18 | int modStringVersion;
|
---|
19 | bool hasOnis;
|
---|
20 | bool hasDeltas;
|
---|
21 | bool hasBSL;
|
---|
22 | bool hasDats;
|
---|
23 | string category;
|
---|
24 | string creator;
|
---|
25 | bool isEngine;
|
---|
26 | string readme;
|
---|
27 | bool globalNeeded;
|
---|
28 | ModPackage();
|
---|
29 | void doOutput()
|
---|
30 | {
|
---|
31 | cout << "Mod: " << name; cout << "\n"; // remove this when done
|
---|
32 | cout << " String: " << modStringName << " v." << modStringVersion << "\n";
|
---|
33 | cout << " Category: " << category << "\n";
|
---|
34 | cout << " Creator: " << creator << "\n";
|
---|
35 | cout << " HasOnis: " << hasOnis << "\n";
|
---|
36 | cout << " HasBSL: " << hasBSL << "\n";
|
---|
37 | cout << " HasDeltas: " << hasDeltas << "\n";
|
---|
38 | cout << " HasDats: " << hasDats << "\n";
|
---|
39 | cout << " IsEngine: " << isEngine << "\n";
|
---|
40 | cout << " GlobalNeeded: " << globalNeeded << "\n";
|
---|
41 | cout << " Readme: " << readme << "\n";
|
---|
42 | cout << "\n";
|
---|
43 | }
|
---|
44 |
|
---|
45 | };
|
---|
46 |
|
---|
47 | #define METHOD_DEFS
|
---|
48 | // Initialization to default values
|
---|
49 | ModPackage::ModPackage()
|
---|
50 | {
|
---|
51 | isInstalled = true; // replace with function
|
---|
52 | name = "";
|
---|
53 | modStringName = "";
|
---|
54 | modStringVersion = 0;
|
---|
55 | hasOnis = false;
|
---|
56 | hasDeltas = false;
|
---|
57 | hasBSL = false;
|
---|
58 | hasDats = false;
|
---|
59 | category = "";
|
---|
60 | creator = "";
|
---|
61 | isEngine = false;
|
---|
62 | readme = "";
|
---|
63 | globalNeeded = true;
|
---|
64 | // void doOutput() const
|
---|
65 | // { };
|
---|
66 | }
|
---|
67 |
|
---|
68 | #define FUNCTION_PROTOTYPES
|
---|
69 | int mainMenu(void);
|
---|
70 | int globalizeData(void);
|
---|
71 | int installPackages(void);
|
---|
72 | int uninstallPackages(void);
|
---|
73 | int listInstalledPackages(void);
|
---|
74 | int printInstallerInfo(void);
|
---|
75 | vector<ModPackage> getPackages(void);
|
---|
76 | ModPackage fileToModPackage(fstream&);
|
---|
77 | void recompileAll(vector<string>);
|
---|
78 | vector<string> getInstallString(void);
|
---|
79 | void tokenize(const string&, vector<string>&, const string& delimiters = " ");
|
---|
80 | //bool getDirectoryContents(char , char &);
|
---|
81 | void clearOldDats(void);
|
---|
82 | void writeInstalledMods( vector<string> );
|
---|
83 |
|
---|
84 | //New copy(path, path) function. Too lazy to implement my own, this is basically how I would have done it though.
|
---|
85 | //No, really. :)
|
---|
86 | //Move to utilities.cpp when the time comes.
|
---|
87 | using namespace boost::filesystem;
|
---|
88 | using namespace std;
|
---|
89 |
|
---|
90 | void copy_directory( const path & from_dir_ph,
|
---|
91 | const path & to_dir_ph );
|
---|
92 |
|
---|
93 | void copy( const path & from_file_ph,
|
---|
94 | const path & to_file_ph );
|
---|
95 |
|
---|
96 |
|
---|
97 | // this function copies files and directories. If copying a
|
---|
98 | // directory to a directory, it copies recursively.
|
---|
99 |
|
---|
100 | //pardon the mess, I did this at midnight, and had to fix a bug
|
---|
101 | void copy( const path & from_ph,
|
---|
102 | const path & to_ph )
|
---|
103 | {
|
---|
104 | cout << to_ph.string() << "\n";
|
---|
105 | // Make sure that the destination, if it exists, is a directory
|
---|
106 | if((exists(to_ph) && !is_directory(to_ph)) || (!exists(from_ph))) cout << "error";
|
---|
107 | if(!is_directory(from_ph))
|
---|
108 | {
|
---|
109 |
|
---|
110 | if(exists(to_ph))
|
---|
111 | {
|
---|
112 | copy_file(from_ph,to_ph/from_ph.filename());
|
---|
113 | }
|
---|
114 | else
|
---|
115 | {
|
---|
116 | try{
|
---|
117 |
|
---|
118 | copy_file(from_ph,to_ph);
|
---|
119 | }
|
---|
120 | catch (exception ex){
|
---|
121 | cout << from_ph.string() << " to " << to_ph.string() << "\n";
|
---|
122 | }
|
---|
123 | }
|
---|
124 |
|
---|
125 | }
|
---|
126 | else if(from_ph.filename() != ".svn")
|
---|
127 | {
|
---|
128 | path destination;
|
---|
129 | if(!exists(to_ph))
|
---|
130 | {
|
---|
131 | destination=to_ph;
|
---|
132 | }
|
---|
133 | else
|
---|
134 | {
|
---|
135 | destination=to_ph/from_ph.filename();
|
---|
136 | }
|
---|
137 | //not sure what this did, its going away though. probably error checking ;)
|
---|
138 | //copy_directory(from_ph,destination);
|
---|
139 |
|
---|
140 | for(directory_iterator i(from_ph); i!=directory_iterator(); ++i)
|
---|
141 | {
|
---|
142 | //the idiot who coded this in the first place (not me)
|
---|
143 | //forgot to make a new directory. Exception city. x_x
|
---|
144 | create_directory(destination);
|
---|
145 | copy(*i,destination/i->filename());
|
---|
146 | }
|
---|
147 | }
|
---|
148 | }
|
---|
149 |
|
---|
150 | void copy_directory( const path &from_dir_ph,
|
---|
151 | const path &to_dir_ph)
|
---|
152 | {
|
---|
153 | if(!exists(from_dir_ph) || !is_directory(from_dir_ph)
|
---|
154 | || exists(to_dir_ph))
|
---|
155 | cout << !exists(from_dir_ph) << " " << !is_directory(from_dir_ph)
|
---|
156 | << " " << exists(to_dir_ph);
|
---|
157 | //boost::throw_exception( filesystem_error(
|
---|
158 | //"boost::filesystem::copy_directory",
|
---|
159 | //from_dir_ph, to_dir_ph, boost::system::error_code() ));
|
---|
160 |
|
---|
161 | # ifdef BOOST_POSIX
|
---|
162 | struct stat from_stat;
|
---|
163 | if ( (::stat( from_dir_ph.string().c_str(), &from_stat ) != 0)
|
---|
164 | || ::mkdir(to_dir_ph.native_directory_string().c_str(),
|
---|
165 | from_stat.st_mode)!=0)
|
---|
166 | # endif
|
---|
167 | // boost::throw_exception( filesystem_error(
|
---|
168 | // //"boost::filesystem::copy_directory",
|
---|
169 | // from_dir_ph, to_dir_ph, boost::system::error_code()));
|
---|
170 | }
|
---|
171 |
|
---|