2a2b05add59be3784d8216728e02e9e6aa4919bf
[reactos.git] / rosapps / packmgr / cmd-line / main.cpp
1 ////////////////////////////////////////////////////////
2 //
3 // main.cpp
4 //
5 // Implementation of a Commandlne Interface
6 // for the ReactOs Package Manager
7 //
8 // Maarten Bosma, 09.01.2004
9 // maarten.paul@bosma.de
10 //
11 ////////////////////////////////////////////////////////////////////
12
13 #include "main.h"
14
15
16 int main (int argc, char **argv)
17 {
18 cout << "ReactOs PackageManager " << PACKMGR_VERSION_MAJOR << "." << PACKMGR_VERSION_MINOR << "." << PACKMGR_VERSION_PATCH_LEVEL << " Commandline Interface \n\n";
19
20 int i;
21
22 if(argc<2)
23 return Help();
24
25 for (i=1; i<argc; i++)
26 cmdline.push_back(argv[i]);
27
28 // install a package
29 if (cmdline[0] == "install")
30 Install();
31
32 // install a package from source
33 else if (cmdline[0] == "src-inst")
34 {
35 cout << "Sorry but I can't do that yet. \n";
36 }
37
38 // update a package
39 else if (cmdline[0] == "update")
40 {
41 cout << "Sorry but I can't do that yet. \n";
42 }
43
44 // update everything
45 else if (cmdline[0] == "dist-upgrade")
46 {
47 cout << "Sorry but I can't do that yet. \n";
48 }
49
50 // remove a package
51 else if (cmdline[0] == "remove")
52 {
53 cout << "Sorry but I can't do that yet. \n";
54 }
55
56 // search for a package
57 else if (cmdline[0] == "show")
58 {
59 Show();
60 }
61
62 // search for a package
63 else if (cmdline[0] == "search")
64 {
65 cout << "Sorry but I can't do that yet. \n";
66 }
67
68 else
69 Help();
70
71 return 0;
72 }
73
74 int Help (void)
75 {
76 cout << "Usage: ros-get [command] \n\n";
77
78 cout << "Possible commands: \n";
79 cout << " install [package name] \t Installs a package \n\n";
80 cout << " show [package name] \t\t Shows you detailed information about a package \n";
81
82 cout << "Currently unimplemented commands: \n";
83 cout << " src-install [package name] \t Installs a package from source code \n";
84 cout << " update [package name] \t Updates a package \n";
85 cout << " dist-update [package name] \t Updates a package \n";
86 cout << " remove [package name] \t Uninstalls a package \n\n";
87
88 cout << " search [search agrument] \t Finds a package \n";
89 cout << " list \t\t\t\t Lists all installed programs \n\n";
90
91 return 0;
92 }
93
94 int Ask (const WCHAR* question)
95 {
96 char answer[255];
97
98 wprintf(question);
99
100 cout << " [y/n] ";
101 cin >> answer;
102 cout << endl;
103
104 if (answer[0]=='y')
105 return 1;
106
107 else if (answer[0]=='n')
108 return 0;
109
110 return Ask(question);
111 }
112
113 int SetStatus (int status1, int status2, WCHAR* text)
114 {
115 if(text)
116 wprintf(L"%s\n", text);
117
118 // If the Status is 1000 things are done
119 if(status1==1000)
120 {
121 wprintf(L"%s\n", PML_TransError(status2));
122 done = true;
123 }
124
125 return 0;
126 }
127
128 int Install (void)
129 {
130 pTree tree;
131 int i, error;
132
133 // load the tree
134 error = PML_LoadTree (&tree, "tree.xml", NULL);
135 if(error)
136 {
137 cout << PML_TransError(error);
138 return 0;
139 }
140
141 // look up the item
142 for (i=1; (UINT)i<cmdline.size(); i++)
143 {
144 int id = PML_FindItem(tree, cmdline[i].c_str());
145
146 if(id)
147 PML_SetAction(tree, id, 1, NULL, Ask);
148
149 else
150 cout << "Could not find the Package \"" << cmdline[i] << "\"\n";
151 }
152
153 // do it
154 error = PML_DoIt (tree, SetStatus, Ask);
155 if(error)
156 {
157 wprintf(L"%s\n", PML_TransError(error));
158 PML_CloseTree (tree);
159 return 0;
160 }
161
162 // wait
163 while (!done)
164 Sleep(1000);
165
166 // clean up
167 PML_CloseTree (tree);
168
169 return 0;
170 }
171
172 int Show (void)
173 {
174 pTree tree;
175 int i, error;
176
177 // load the tree
178 error = PML_LoadTree (&tree, "tree.xml", NULL);
179 if(error)
180 {
181 cout << PML_TransError(error);
182 return 0;
183 }
184
185 // look up the item
186 for (i=1; (UINT)i<cmdline.size(); i++)
187 {
188 int id = PML_FindItem(tree, cmdline[i].c_str());
189
190 if(id)
191 cout << PML_GetDescription (tree, id) << "\n";
192
193 else
194 cout << "Could not find the Package \"" << cmdline[i] << "\"\n";
195 }
196
197 // clean up
198 PML_CloseTree (tree);
199
200 return 0;
201 }