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