2005-08-07 07:33:14 +00:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// main.cpp
|
2007-10-19 23:05:02 +00:00
|
|
|
//
|
2005-08-07 07:33:14 +00:00
|
|
|
// Implementation of a Commandlne Interface
|
|
|
|
// for the ReactOs Package Manager
|
|
|
|
//
|
|
|
|
// Maarten Bosma, 09.01.2004
|
|
|
|
// maarten.paul@bosma.de
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
2007-10-19 23:05:02 +00:00
|
|
|
int main (int argc, char **argv)
|
2005-08-07 07:33:14 +00:00
|
|
|
{
|
|
|
|
wprintf(L"ReactOs PackageManager %d.%d.%d Commandline Interface \n\n", PACKMGR_VERSION_MAJOR, PACKMGR_VERSION_MINOR, PACKMGR_VERSION_PATCH_LEVEL);
|
|
|
|
Argv = argv; Argc = argc;
|
|
|
|
|
|
|
|
if(argc<2)
|
|
|
|
return Help();
|
|
|
|
|
|
|
|
// install a package
|
2007-10-19 23:05:02 +00:00
|
|
|
if (!strcmp(argv[1], "install"))
|
2005-08-07 07:33:14 +00:00
|
|
|
Install();
|
|
|
|
|
|
|
|
// install a package from source
|
|
|
|
else if (!strcmp(argv[1], "src-inst"))
|
|
|
|
{
|
|
|
|
wprintf(L"Sorry but I can't do that yet. \n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// update a package
|
|
|
|
else if (!strcmp(argv[1], "update"))
|
|
|
|
{
|
|
|
|
wprintf(L"Sorry but I can't do that yet. \n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// update everything
|
|
|
|
else if (!strcmp(argv[1], "dist-upgrade"))
|
|
|
|
{
|
|
|
|
wprintf(L"Sorry but I can't do that yet. \n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove a package
|
|
|
|
else if (!strcmp(argv[1], "remove"))
|
|
|
|
{
|
|
|
|
wprintf(L"Sorry but I can't do that yet. \n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// search for a package
|
|
|
|
else if (!strcmp(argv[1], "show"))
|
|
|
|
{
|
|
|
|
Show();
|
|
|
|
}
|
|
|
|
|
|
|
|
// search for a package
|
|
|
|
else if (!strcmp(argv[1], "search"))
|
|
|
|
{
|
|
|
|
wprintf(L"Sorry but I can't do that yet. \n");
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
Help();
|
|
|
|
|
|
|
|
//
|
|
|
|
wprintf(L"\n");
|
2007-10-19 23:05:02 +00:00
|
|
|
|
2005-08-07 07:33:14 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Help (void)
|
|
|
|
{
|
|
|
|
wprintf(L"Usage: ros-get [command] \n\n");
|
|
|
|
|
|
|
|
wprintf(L"Possible commands: \n");
|
|
|
|
wprintf(L" install [package name] \t Installs a package \n\n");
|
|
|
|
wprintf(L" show [package name] \t\t Shows you detailed information about a package \n");
|
|
|
|
|
|
|
|
wprintf(L"Currently unimplemented commands: \n");
|
|
|
|
wprintf(L" src-install [package name] \t Installs a package from source code \n");
|
|
|
|
wprintf(L" update [package name] \t Updates a package \n");
|
|
|
|
wprintf(L" dist-update [package name] \t Updates a package \n");
|
|
|
|
wprintf(L" remove [package name] \t Uninstalls a package \n\n");
|
|
|
|
|
|
|
|
wprintf(L" search [search agrument] \t Finds a package \n");
|
|
|
|
wprintf(L" list \t\t\t\t Lists all installed programs \n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Ask (const WCHAR* question)
|
|
|
|
{
|
|
|
|
// ask the user
|
|
|
|
wprintf(L"%s [y/n] ", question);
|
|
|
|
char answer = getchar();
|
|
|
|
|
|
|
|
// clear keybuffer
|
|
|
|
while(getchar()!='\n');
|
|
|
|
wprintf(L"\n");
|
|
|
|
|
|
|
|
// prozess answer
|
|
|
|
if (answer == 'y')
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
else if (answer == 'n')
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return Ask(question);
|
|
|
|
}
|
2007-10-19 23:05:02 +00:00
|
|
|
|
2005-08-07 07:33:14 +00:00
|
|
|
int SetStatus (int status1, int status2, WCHAR* text)
|
|
|
|
{
|
2005-11-26 10:20:35 +00:00
|
|
|
WCHAR errbuf[2000];
|
2005-08-07 07:33:14 +00:00
|
|
|
if(text)
|
|
|
|
wprintf(L"%s\n", text);
|
|
|
|
|
|
|
|
// If the Status is 1000 things are done
|
|
|
|
if(status1==1000)
|
|
|
|
{
|
2005-11-26 10:40:21 +00:00
|
|
|
wprintf(L"%s\n", PML_TransError(status2, errbuf, sizeof(errbuf)/sizeof(WCHAR)));
|
2005-08-07 07:33:14 +00:00
|
|
|
done = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Install (void)
|
|
|
|
{
|
|
|
|
pTree tree;
|
|
|
|
int i, error;
|
2005-11-26 10:20:35 +00:00
|
|
|
WCHAR errbuf[2000];
|
2005-08-07 07:33:14 +00:00
|
|
|
|
|
|
|
// load the tree
|
|
|
|
error = PML_LoadTree (&tree, "tree.xml", NULL);
|
|
|
|
if(error)
|
|
|
|
{
|
2005-11-26 10:20:35 +00:00
|
|
|
|
2005-11-26 10:40:21 +00:00
|
|
|
wprintf(PML_TransError(error, errbuf, sizeof(errbuf)/sizeof(WCHAR)));
|
2005-08-07 07:33:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2007-10-19 23:05:02 +00:00
|
|
|
|
2005-08-07 07:33:14 +00:00
|
|
|
// look up the item
|
|
|
|
for (i=2; i<Argc; i++)
|
|
|
|
{
|
|
|
|
int id = PML_FindItem(tree, Argv[i]);
|
|
|
|
|
|
|
|
if(id)
|
|
|
|
{
|
|
|
|
PML_LoadPackage(tree, id, NULL);
|
|
|
|
PML_SetAction(tree, id, 1, NULL, Ask);
|
|
|
|
}
|
|
|
|
|
2007-10-19 23:05:02 +00:00
|
|
|
else
|
2005-08-07 07:33:14 +00:00
|
|
|
printf("Could not find the Package \"%s\"\n", Argv[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// do it
|
|
|
|
error = PML_DoIt (tree, SetStatus, Ask);
|
|
|
|
if(error)
|
|
|
|
{
|
2005-11-26 10:20:35 +00:00
|
|
|
|
2005-11-26 10:40:21 +00:00
|
|
|
wprintf(PML_TransError(error, errbuf, sizeof(errbuf)/sizeof(WCHAR)));
|
2005-08-07 07:33:14 +00:00
|
|
|
PML_CloseTree (tree);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// wait
|
|
|
|
while (!done)
|
|
|
|
Sleep(1000);
|
|
|
|
|
|
|
|
// clean up
|
|
|
|
PML_CloseTree (tree);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Show (void)
|
|
|
|
{
|
|
|
|
pTree tree;
|
|
|
|
int i, error;
|
2005-11-26 10:20:35 +00:00
|
|
|
WCHAR errbuf[2000];
|
2005-08-07 07:33:14 +00:00
|
|
|
|
|
|
|
// load the tree
|
2006-01-03 00:12:35 +00:00
|
|
|
error = PML_LoadTree (&tree, "tree_bare.xml", NULL);
|
2005-08-07 07:33:14 +00:00
|
|
|
if(error)
|
|
|
|
{
|
2005-11-26 10:40:21 +00:00
|
|
|
wprintf(PML_TransError(error, errbuf, sizeof(errbuf)/sizeof(WCHAR)));
|
2005-08-07 07:33:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// look up the item
|
|
|
|
for (i=2; i<Argc; i++)
|
|
|
|
{
|
|
|
|
int id = PML_FindItem(tree, Argv[i]);
|
|
|
|
|
|
|
|
if(id)
|
|
|
|
printf(PML_GetDescription(tree, id));
|
|
|
|
|
2007-10-19 23:05:02 +00:00
|
|
|
else
|
2005-08-07 07:33:14 +00:00
|
|
|
printf("Could not find the Package \"%s\"\n", Argv[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// clean up
|
|
|
|
PML_CloseTree (tree);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|