disable defining ntstatus codes in windows.h/winnt.h when using ndk
[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 if(text)
118 wprintf(L"%s\n", text);
119
120 // If the Status is 1000 things are done
121 if(status1==1000)
122 {
123 wprintf(L"%s\n", PML_TransError(status2));
124 done = TRUE;
125 }
126
127 return 0;
128 }
129
130 int Install (void)
131 {
132 pTree tree;
133 int i, error;
134
135 // load the tree
136 error = PML_LoadTree (&tree, "tree.xml", NULL);
137 if(error)
138 {
139 wprintf(PML_TransError(error));
140 return 0;
141 }
142
143 // look up the item
144 for (i=2; i<Argc; i++)
145 {
146 int id = PML_FindItem(tree, Argv[i]);
147
148 if(id)
149 {
150 PML_LoadPackage(tree, id, NULL);
151 PML_SetAction(tree, id, 1, NULL, Ask);
152 }
153
154 else
155 printf("Could not find the Package \"%s\"\n", Argv[i]);
156 }
157
158 // do it
159 error = PML_DoIt (tree, SetStatus, Ask);
160 if(error)
161 {
162 wprintf(PML_TransError(error));
163 PML_CloseTree (tree);
164 return 0;
165 }
166
167 // wait
168 while (!done)
169 Sleep(1000);
170
171 // clean up
172 PML_CloseTree (tree);
173
174 return 0;
175 }
176
177 int Show (void)
178 {
179 pTree tree;
180 int i, error;
181
182 // load the tree
183 error = PML_LoadTree (&tree, "tree.xml", NULL);
184 if(error)
185 {
186 wprintf(PML_TransError(error));
187 return 0;
188 }
189
190 // look up the item
191 for (i=2; i<Argc; i++)
192 {
193 int id = PML_FindItem(tree, Argv[i]);
194
195 if(id)
196 printf(PML_GetDescription(tree, id));
197
198 else
199 printf("Could not find the Package \"%s\"\n", Argv[i]);
200 }
201
202 // clean up
203 PML_CloseTree (tree);
204
205 return 0;
206 }