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