source: AE/Installer/trunk/source/methods.h@ 317

Last change on this file since 317 was 314, checked in by gumby, 16 years ago
File size: 4.4 KB
Line 
1/* AE/Mod Installer header file */
2
3#include <string>
4#include <vector>
5#include <fstream>
6
7using namespace std;
8
9static string SLASHSLASH = "//";
10static string DIRSLASH = "\\";
11
12#define STRUCT_DEFS
13struct 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
49ModPackage::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
69int mainMenu(void);
70int globalizeData(void);
71int installPackages(void);
72int uninstallPackages(void);
73int listInstalledPackages(void);
74int printInstallerInfo(void);
75vector<ModPackage> getPackages(void);
76ModPackage fileToModPackage(fstream&);
77void recompileAll(vector<string>);
78vector<string> getInstallString(void);
79void tokenize(const string&, vector<string>&, const string& delimiters = " ");
80//bool getDirectoryContents(char , char &);
81
82
83//New copy(path, path) function. Too lazy to implement my own, this is basically how I would have done it though.
84//No, really. :)
85//Move to utilities.cpp when the time comes.
86using namespace boost::filesystem;
87using namespace std;
88
89void copy_directory( const path & from_dir_ph,
90 const path & to_dir_ph );
91
92 void copy( const path & from_file_ph,
93 const path & to_file_ph );
94
95
96// this function copies files and directories. If copying a
97// directory to a directory, it copies recursively.
98
99 //pardon the mess, I did this at midnight, and had to fix a bug
100void copy( const path & from_ph,
101 const path & to_ph )
102{
103 cout << to_ph.string() << "\n";
104 // Make sure that the destination, if it exists, is a directory
105 if((exists(to_ph) && !is_directory(to_ph)) || (!exists(from_ph))) cout << "error";
106 if(!is_directory(from_ph))
107 {
108
109 if(exists(to_ph))
110 {
111 copy_file(from_ph,to_ph/from_ph.filename());
112 }
113 else
114 {
115 try{
116
117 copy_file(from_ph,to_ph);
118 }
119 catch (exception ex){
120 cout << from_ph.string() << " to " << to_ph.string() << "\n";
121 }
122 }
123
124 }
125 else if(from_ph.filename() != ".svn")
126 {
127 path destination;
128 if(!exists(to_ph))
129 {
130 destination=to_ph;
131 }
132 else
133 {
134 destination=to_ph/from_ph.filename();
135 }
136 //not sure what this did, its going away though. probably error checking ;)
137 //copy_directory(from_ph,destination);
138
139 for(directory_iterator i(from_ph); i!=directory_iterator(); ++i)
140 {
141 //the idiot who coded this in the first place (not me)
142 //forgot to make a new directory. Exception city. x_x
143 create_directory(destination);
144 copy(*i,destination/i->filename());
145 }
146 }
147}
148
149void copy_directory( const path &from_dir_ph,
150 const path &to_dir_ph)
151{
152 if(!exists(from_dir_ph) || !is_directory(from_dir_ph)
153 || exists(to_dir_ph))
154 cout << !exists(from_dir_ph) << " " << !is_directory(from_dir_ph)
155 << " " << exists(to_dir_ph);
156 //boost::throw_exception( filesystem_error(
157 //"boost::filesystem::copy_directory",
158 //from_dir_ph, to_dir_ph, boost::system::error_code() ));
159
160# ifdef BOOST_POSIX
161 struct stat from_stat;
162 if ( (::stat( from_dir_ph.string().c_str(), &from_stat ) != 0)
163 || ::mkdir(to_dir_ph.native_directory_string().c_str(),
164 from_stat.st_mode)!=0)
165# endif
166 // boost::throw_exception( filesystem_error(
167 // //"boost::filesystem::copy_directory",
168 // from_dir_ph, to_dir_ph, boost::system::error_code()));
169}
170
Note: See TracBrowser for help on using the repository browser.