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

Last change on this file since 320 was 319, checked in by gumby, 16 years ago

Added uninstall options.
Added PC Demo\Mac detection.
Added installed_something detection.

File size: 4.5 KB
RevLine 
[314]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 &);
[319]81void clearOldDats(void);
82void writeInstalledMods( vector<string> );
[314]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.
87using namespace boost::filesystem;
88using namespace std;
89
90void 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
101void 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
150void 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
Note: See TracBrowser for help on using the repository browser.