PackageManager
authorMaarten Bosma <maarten@bosma.de>
Fri, 8 Apr 2005 19:09:20 +0000 (19:09 +0000)
committerMaarten Bosma <maarten@bosma.de>
Fri, 8 Apr 2005 19:09:20 +0000 (19:09 +0000)
Created the commandline Interface
Deleated subcategries

svn path=/trunk/; revision=14553

rosapps/packmgr/cmd-line/main.cpp [new file with mode: 0644]
rosapps/packmgr/cmd-line/main.h [new file with mode: 0644]
rosapps/packmgr/cmd-line/makefile [new file with mode: 0644]
rosapps/packmgr/cmd-line/ros-get.rc [new file with mode: 0644]
rosapps/packmgr/gui/main.cpp
rosapps/packmgr/lib/package.cpp
rosapps/packmgr/lib/package.def
rosapps/packmgr/lib/package.hpp
rosapps/packmgr/lib/tree.cpp
rosapps/packmgr/tree/tree.xml
rosapps/packmgr/tree/tree_withsubs.xml [new file with mode: 0644]

diff --git a/rosapps/packmgr/cmd-line/main.cpp b/rosapps/packmgr/cmd-line/main.cpp
new file mode 100644 (file)
index 0000000..e37a4ed
--- /dev/null
@@ -0,0 +1,185 @@
+////////////////////////////////////////////////////////\r
+//\r
+// main.cpp\r
+// \r
+// Implementation of a Commandlne Interface\r
+// for the ReactOs Package Manager\r
+//\r
+// Maarten Bosma, 09.01.2004\r
+// maarten.paul@bosma.de\r
+//\r
+////////////////////////////////////////////////////////////////////\r
+\r
+#include "main.h"\r
+\r
+\r
+int main (int argc, char **argv) \r
+{\r
+       cout << "ReactOs PackageManager " << PACKMGR_VERSION_MAJOR << "." << PACKMGR_VERSION_MINOR << "." << PACKMGR_VERSION_PATCH_LEVEL << " Commandline Interface \n\n";\r
+\r
+       int i;\r
+\r
+       if(argc<2)\r
+               return Help();\r
+\r
+       for (i=1; i<argc; i++)\r
+               cmdline.push_back(argv[i]);\r
+\r
+       // install a package\r
+       if (cmdline[0] == "install") \r
+               Install();\r
+\r
+       // install a package from source\r
+       else if (cmdline[0] == "src-inst")\r
+       {\r
+               cout << "Sorry but I can't do that yet. \n";\r
+       }\r
+\r
+       // update a package\r
+       else if (cmdline[0] == "update")\r
+       {\r
+               cout << "Sorry but I can't do that yet. \n";\r
+       }\r
+\r
+       // update everything\r
+       else if (cmdline[0] == "dist-upgrade")\r
+       {\r
+               cout << "Sorry but I can't do that yet. \n";\r
+       }\r
+\r
+       // remove a package\r
+       else if (cmdline[0] == "remove")\r
+       {\r
+               cout << "Sorry but I can't do that yet. \n";\r
+       }\r
+\r
+       // search for a package\r
+       else if (cmdline[0] == "show")\r
+       {\r
+               Show();\r
+       }\r
+\r
+       // search for a package\r
+       else if (cmdline[0] == "search")\r
+       {\r
+               cout << "Sorry but I can't do that yet. \n";\r
+       }\r
+\r
+       else\r
+               Help();\r
+       \r
+       return 0;\r
+}\r
+\r
+int Help (void)\r
+{\r
+       cout << "Usage: ros-get [command] \n\n";\r
+\r
+       cout << "Possible commands: \n";\r
+       cout << "  install [package name] \t Installs a package \n\n";\r
+       cout << "  show [package name] \t\t Shows you detailed information about a package \n";\r
+\r
+       cout << "Currently unimplemented commands: \n";\r
+       cout << "  src-install [package name] \t Installs a package from source code \n";\r
+       cout << "  update [package name] \t Updates a package \n";\r
+       cout << "  dist-update [package name] \t Updates a package \n";\r
+       cout << "  remove [package name] \t Uninstalls a package \n\n";\r
+\r
+       cout << "  search [search agrument] \t Finds a package \n";\r
+       cout << "  list \t\t\t\t Lists all installed programs \n\n";\r
+\r
+       return 0;\r
+}\r
+       \r
+int SetStatus (int status1, int status2, WCHAR* text)\r
+{\r
+       if(text)\r
+               wprintf(L"%s\n", text);\r
+\r
+       // If the Status is 1000 things are done\r
+       if(status1==1000)\r
+       {\r
+               wprintf(L"%s\n", PML_TransError(status2));\r
+               done = true;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+int Install (void)\r
+{\r
+       pTree tree;\r
+       int i, error;\r
+\r
+       // load the tree\r
+       error = PML_LoadTree (&tree, "tree.xml", NULL);\r
+       if(error)\r
+       {\r
+               cout << PML_TransError(error);\r
+               return 0;\r
+       }\r
+               \r
+       // look up the item\r
+       for (i=1; (UINT)i<cmdline.size(); i++)\r
+       {\r
+               int id = PML_FindItem(tree, cmdline[i].c_str());\r
+\r
+               if(id)\r
+                       PML_SetAction(tree, id, 1, NULL);\r
+\r
+               else \r
+                       cout << "Could not find the Package \"" << cmdline[i] << "\"\n";\r
+       }\r
+\r
+       // do it\r
+       error = PML_DoIt (tree, SetStatus);\r
+       if(error)\r
+       {\r
+               wprintf(L"%s\n", PML_TransError(error));\r
+               PML_CloseTree (tree);\r
+               return 0;\r
+       }\r
+\r
+       // wait\r
+       while (!done)\r
+               Sleep(1000);\r
+\r
+       // clean up\r
+       PML_CloseTree (tree);\r
+\r
+       return 0;\r
+}\r
+\r
+int Show (void)\r
+{\r
+       pTree tree;\r
+       int i, error;\r
+\r
+       // load the tree\r
+       error = PML_LoadTree (&tree, "tree.xml", NULL);\r
+       if(error)\r
+       {\r
+               cout << PML_TransError(error);\r
+               return 0;\r
+       }\r
+\r
+       // look up the item\r
+       for (i=1; (UINT)i<cmdline.size(); i++)\r
+       {\r
+               int id = PML_FindItem(tree, cmdline[i].c_str());\r
+\r
+               cout << i << "<" << cmdline.size() << endl;\r
+\r
+               if(id)\r
+                       cout << PML_GetDescription (tree, id) << "\n";\r
+\r
+               else \r
+                       cout << "Could not find the Package \"" << cmdline[i] << "\"\n";\r
+       }\r
+               cout << i << "<" << cmdline.size() << endl;\r
+\r
+       // clean up\r
+       PML_CloseTree (tree);\r
+\r
+       return 0;\r
+}\r
diff --git a/rosapps/packmgr/cmd-line/main.h b/rosapps/packmgr/cmd-line/main.h
new file mode 100644 (file)
index 0000000..70b93a5
--- /dev/null
@@ -0,0 +1,19 @@
+///////////////////////////////////////////////////\r
+//\r
+// main.h\r
+//                             main.cpp's lumber room :)\r
+///////////////////////////////////////////////////\r
+\r
+#include "package.hpp"\r
+\r
+#include <iostream>\r
+\r
+\r
+vector<string> cmdline;\r
+bool done = false;\r
+\r
+int Help (void);\r
+int Install (void);\r
+int Show (void);\r
+\r
+int SetStatus (int status1, int status2, WCHAR* text);\r
diff --git a/rosapps/packmgr/cmd-line/makefile b/rosapps/packmgr/cmd-line/makefile
new file mode 100644 (file)
index 0000000..5ea81ea
--- /dev/null
@@ -0,0 +1,24 @@
+\r
+TARGET_NAME = ros-get\r
+TARGET_TYPE = program\r
+TARGET_APPTYPE = console\r
+PATH_TO_TOP = ../../../reactos\r
+\r
+TARGET_SDKLIBS = package.a\r
+\r
+TARGET_GCCLIBS = stdc++ uuid\r
+\r
+TARGET_OBJECTS = main.o\r
+\r
+TARGET_CFLAGS = \\r
+       -D__USE_W32API -DWIN32 -D_ROS_ \\r
+       -D_WIN32_IE=0x0501 -D_WIN32_WINNT=0x0501 \\r
+       -DUNICODE -Wall -I../lib\r
+\r
+TARGET_CPPFLAGS = $(TARGET_CFLAGS)\r
+\r
+TARGET_RCFLAGS =  -D__USE_W32API -DNDEBUG -DWIN32 -D_ROS_ -D__WINDRES__ -DUNICODE\r
+\r
+include $(PATH_TO_TOP)/rules.mak\r
+include $(TOOLS_PATH)/helper.mk\r
+include $(TOOLS_PATH)/depend.mk\r
diff --git a/rosapps/packmgr/cmd-line/ros-get.rc b/rosapps/packmgr/cmd-line/ros-get.rc
new file mode 100644 (file)
index 0000000..45f9cfb
--- /dev/null
@@ -0,0 +1,8 @@
+\r
+#define REACTOS_STR_FILE_DESCRIPTION   "ReactOS Package Manager - Cmdline Interface\0"\r
+#define REACTOS_STR_INTERNAL_NAME      "ros-get\0"\r
+#define REACTOS_STR_ORIGINAL_FILENAME  "ros-get.exe\0"\r
+\r
+#include <reactos/version.rc>\r
+\r
+/* EOF */\r
index 893cb7a..0fd151a 100644 (file)
@@ -204,12 +204,15 @@ int SetButton (DWORD id, BOOL state)
 \r
     SetMenuItemInfo(hPopup, id, FALSE, &mi);\r
 \r
-       return 1;\r
+       return 0;\r
 }\r
 \r
 // Set the text of the text box\r
 int SetText (const char* text) \r
 {\r
+       if(!text)\r
+               return 1;\r
+\r
        int i = 0;\r
        string source = text;\r
 \r
@@ -257,7 +260,8 @@ LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                        if(((LPNMHDR)lParam)->code == TVN_SELCHANGED) \r
                        {\r
                                selected = ((LPNMTREEVIEW)lParam)->itemNew.lParam; \r
-                               PML_LoadPackage (tree, selected, SetButton, SetText);\r
+                               PML_LoadPackage (tree, selected, SetButton);\r
+                               SetText(PML_GetDescription (tree, selected));\r
                        }\r
 \r
                        else if ((int)(((LPNMHDR)lParam)->code) == NM_RCLICK) // <= ahhh LISP\r
index 469cb4d..9608168 100644 (file)
@@ -84,16 +84,19 @@ void pack_text (void* usrdata, const char* data, int len)
 \r
 \r
 // The user clicks on a package\r
-extern "C" int PML_LoadPackage (TREE* tree, int id, PML_SetButton SetButton, PML_SetText SetText)\r
+extern "C" int PML_LoadPackage (TREE* tree, int id, PML_SetButton SetButton)\r
 {\r
        PACKAGE* pack = &tree->packages[id];\r
        tree->setButton = SetButton;\r
 \r
-       SetButton(1, pack->action);\r
-       SetButton(2, pack->inst); // && pack->action != 0\r
-       SetButton(3, pack->src_inst); \r
-       SetButton(4, pack->update);\r
-       SetButton(5, pack->uninstall); \r
+       if(SetButton)\r
+       {\r
+               SetButton(1, pack->action);\r
+               SetButton(2, pack->inst); // && pack->action != 0\r
+               SetButton(3, pack->src_inst); \r
+               SetButton(4, pack->update);\r
+               SetButton(5, pack->uninstall); \r
+       }\r
 \r
        // root notes (like network) return here\r
        if(!pack->path)\r
@@ -105,12 +108,35 @@ extern "C" int PML_LoadPackage (TREE* tree, int id, PML_SetButton SetButton, PML
                pack->loaded = TRUE;\r
        }\r
 \r
-       if(pack->description)\r
-               SetText(pack->description);\r
-\r
        return ERR_OK;\r
 }\r
 \r
+extern "C" int PML_FindItem (TREE* tree, const char* what)\r
+{\r
+       int i, j;\r
+       bool found;\r
+\r
+       // if we have children, same action for them\r
+       for (i=1; (UINT)i<tree->packages.size(); i++)\r
+       {\r
+               found = true;\r
+\r
+               for(j=0; (UINT)j<strlen(what); j++)\r
+               {\r
+                       if(tolower(what[j]) != tolower(tree->packages[i].name[j]))\r
+                       {\r
+                               found = false;\r
+                               break;\r
+                       }\r
+               }\r
+\r
+               if(found)\r
+                       return i;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
 // The user chooses a actions like Install\r
 extern "C" int PML_SetAction (TREE* tree, int id, int action, PML_SetIcon SetIcon)\r
 {\r
@@ -134,7 +160,8 @@ extern "C" int PML_SetAction (TREE* tree, int id, int action, PML_SetIcon SetIco
 \r
        // set the icon\r
        if(!pack->icon)\r
-               SetIcon(id, action);\r
+               if(SetIcon)\r
+                       SetIcon(id, action);\r
 \r
        // can't do src install yet\r
        if(action == 2)\r
@@ -147,7 +174,8 @@ extern "C" int PML_SetAction (TREE* tree, int id, int action, PML_SetIcon SetIco
        else if (action != 0)\r
        {\r
                // since we are setting a action we undo it again\r
-               tree->setButton(1, 1);\r
+               if(tree->setButton)\r
+                       tree->setButton(1, 1);\r
                //tree->setButton(action+1, 0);\r
                pack->action = action;\r
 \r
@@ -168,9 +196,10 @@ extern "C" int PML_SetAction (TREE* tree, int id, int action, PML_SetIcon SetIco
 \r
        // undoing\r
        else \r
-       {+\r
+       {\r
                // set other things back\r
-               tree->setButton(1, 0);\r
+               if(tree->setButton)\r
+                       tree->setButton(1, 0);\r
                //tree->setButton(pack->action+1, 1);\r
                pack->action = 0;\r
 \r
@@ -189,3 +218,11 @@ extern "C" int PML_SetAction (TREE* tree, int id, int action, PML_SetIcon SetIco
        return ret;\r
 }\r
 \r
+//\r
+extern "C" char* PML_GetDescription (TREE* tree, int id)\r
+{\r
+       PML_LoadPackage(tree, id, NULL);\r
+\r
+       return tree->packages[id].description;\r
+}\r
+\r
index 9154be9..9ec30fe 100644 (file)
@@ -5,7 +5,9 @@ EXPORTS
   PML_Abort\r
   PML_TransError\r
   PML_LoadTree\r
+  PML_FindItem\r
   PML_LoadPackage\r
+  PML_GetDescription\r
   PML_SetAction\r
   PML_DoIt\r
   PML_CloseTree\r
index ce6ee46..0b90065 100644 (file)
@@ -71,7 +71,9 @@ extern "C"
   WCHAR* PML_TransError (int code);\r
 \r
   int PML_LoadTree (pTree*, char* url, PML_AddItem);\r
-  int PML_LoadPackage (pTree, int id, PML_SetButton, PML_SetText);\r
+  int PML_FindItem (TREE* tree, const char* what);\r
+  int PML_LoadPackage (pTree, int id, PML_SetButton);\r
+  char* PML_GetDescription (TREE* tree, int id);\r
   int PML_SetAction (pTree, int package, int action, PML_SetIcon);\r
   int PML_DoIt (pTree, PML_SetStatus);\r
 \r
index 030e633..6cae038 100644 (file)
@@ -40,9 +40,8 @@ extern "C" int PML_LoadTree (TREE** tree, char* url, PML_AddItem AddItem)
 // expat callback for start of a "node" tag\r
 void tree_start (void* usrdata, const char* tag, const char** arg)\r
 {\r
-       int i, icon;\r
+       int i, icon = 0;\r
        static int id = 1;\r
-       const char* name = "\0";\r
 \r
        TREE* tree = (TREE*)usrdata;\r
 \r
@@ -58,12 +57,16 @@ void tree_start (void* usrdata, const char* tag, const char** arg)
        tree->packages[id].icon = FALSE;\r
        tree->packages[id].none = TRUE;\r
        tree->packages[id].path = NULL;\r
+       tree->packages[id].name = "\0";\r
 \r
        // read the arguments\r
        for (i=0; arg[i]; i+=2) \r
        {\r
                if(!strcmp(arg[i], "name"))\r
-                       name = arg[i+1];\r
+               {\r
+                       tree->packages[id].name = new char [strlen(arg[i+1])+1];\r
+                       strcpy(tree->packages[id].name, arg[i+1]);\r
+               }\r
 \r
                if(!strcmp(arg[i], "icon"))\r
                {\r
@@ -73,7 +76,7 @@ void tree_start (void* usrdata, const char* tag, const char** arg)
 \r
                if(!strcmp(arg[i], "file"))\r
                {\r
-                       tree->packages[id].path = new char [strlen(arg[i+1])];\r
+                       tree->packages[id].path = new char [strlen(arg[i+1])+1];\r
                        strcpy(tree->packages[id].path, arg[i+1]);\r
 \r
                        if(strcmp(tag, "bin"))\r
@@ -84,14 +87,19 @@ void tree_start (void* usrdata, const char* tag, const char** arg)
                }\r
        }\r
 \r
-       if(name[0]=='\0') return;\r
+       if(tree->packages[id].name[0] == '\0') return;\r
 \r
        // add it\r
        if(!parents.size())\r
-          tree->addItem(id, name, 0, icon);\r
+       {\r
+               if(tree->addItem)\r
+                       tree->addItem(id, tree->packages[id].name, 0, icon);\r
+       }\r
+\r
+       // do some manipulation at the parent\r
        else\r
        {\r
-          tree->addItem(id, name, parents.back(), icon);\r
+               tree->addItem(id, tree->packages[id].name, parents.back(), icon);\r
 \r
           // list as child in the parent node\r
           tree->packages[parents.back()].children.push_back(id);\r
index 0ebd185..7cf8f3d 100644 (file)
@@ -1,69 +1,15 @@
 <tree>\r
   <node name="Internet and Network" icon="5">\r
-    <node name="Browser" icon="5">\r
-      <node name="MozillaControl" file="mozcontrol.xml"/>\r
-    </node>\r
-    <node name="Email" icon="5"/>\r
-    <node name="Instant Messaging and IRC" icon="5">\r
-      <node name="VoIP" icon="5"/>\r
-    </node>\r
-    <node name="Filesharing" icon="5"/>\r
-    <node name="Remotecontrol" icon="5"/>\r
-    <node name="Server" icon="5">\r
-      <node name="File-Server" icon="5"/>\r
-      <node name="HTTP" icon="5"/>\r
-      <node name="IRC" icon="5"/>\r
-      <node name="FTP" icon="5"/>\r
-    </node>\r
-    <node name="Network monitoring" icon="5"/>\r
-    <node name="Security" icon="5"/>\r
-    <node name="Streaming" icon="5"/>\r
-    <node name="Other" icon="5"/>\r
+    <node name="Mozilla Control" file="mozcontrol.xml"/>\r
   </node>\r
   <node name="Office" icon="6">\r
-    <node name="Writing" icon="6">\r
-      <node name="PDF" icon="6"/>\r
-      <node name="AbiWord" file="abiword.xml"/>\r
-    </node>\r
-    <node name="Dictionaries" icon="6"/>\r
-  </node>\r
-  <node name="Graphics" icon="7">\r
-    <node name="Vector" icon="7"/>\r
-    <node name="Pixel" icon="7"/>\r
-    <node name="3D" icon="7"/>\r
-  </node>\r
-  <node name="Multimedia" icon="8">\r
-    <node name="Codecs" icon="8"/>\r
-    <node name="Editors" icon="8"/>\r
-    <node name="Players" icon="8"/>\r
-  </node>\r
-  <node name="Development" icon="9">\r
-    <node name="IDE" icon="9"/>\r
-    <node name="Compiler" icon="9"/>\r
-    <node name="Version Control" icon="9"/>\r
-    <node name="Web" icon="9"/>\r
-    <node name="Other" icon="9"/>\r
+    <node name="AbiWord" file="abiword.xml"/>\r
   </node>\r
+  <node name="Graphics" icon="7"/>\r
+  <node name="Multimedia" icon="8"/>\r
+  <node name="Development" icon="9"/>\r
   <node name="Games and Fun" icon="10"/>\r
-  <node name="Tools" icon="11">\r
-    <node name="Compression" icon="11"/>\r
-    <node name="Backup" icon="11"/>\r
-    <node name="Burning" icon="11">\r
-      <node name="CD" icon="11"/>\r
-      <node name="DVD" icon="11"/>\r
-    </node>\r
-  </node>\r
-  <node name="Others" icon="12">\r
-    <node name="Desktop Environments and Shellreplacements" icon="12"/>\r
-    <node name="Desktop" icon="12"/>\r
-    <node name="Antivirus" icon="12"/>\r
-    <node name="Emulators" icon="12">\r
-      <node name="Computers" icon="12"/>\r
-      <node name="Systems" icon="12"/>\r
-      <node name="Games" icon="12"/>\r
-    </node>\r
-    <node name="Drivers" icon="12"/>\r
-  </node>\r
-  <node name="Installed Programms" icon="13"/> \r
-</tree>\r
-\r
+  <node name="Tools" icon="11"/>\r
+  <node name="Others" icon="12"/>\r
+  <node name="Installed Programms" icon="13"/>\r
+</tree>
\ No newline at end of file
diff --git a/rosapps/packmgr/tree/tree_withsubs.xml b/rosapps/packmgr/tree/tree_withsubs.xml
new file mode 100644 (file)
index 0000000..0ebd185
--- /dev/null
@@ -0,0 +1,69 @@
+<tree>\r
+  <node name="Internet and Network" icon="5">\r
+    <node name="Browser" icon="5">\r
+      <node name="MozillaControl" file="mozcontrol.xml"/>\r
+    </node>\r
+    <node name="Email" icon="5"/>\r
+    <node name="Instant Messaging and IRC" icon="5">\r
+      <node name="VoIP" icon="5"/>\r
+    </node>\r
+    <node name="Filesharing" icon="5"/>\r
+    <node name="Remotecontrol" icon="5"/>\r
+    <node name="Server" icon="5">\r
+      <node name="File-Server" icon="5"/>\r
+      <node name="HTTP" icon="5"/>\r
+      <node name="IRC" icon="5"/>\r
+      <node name="FTP" icon="5"/>\r
+    </node>\r
+    <node name="Network monitoring" icon="5"/>\r
+    <node name="Security" icon="5"/>\r
+    <node name="Streaming" icon="5"/>\r
+    <node name="Other" icon="5"/>\r
+  </node>\r
+  <node name="Office" icon="6">\r
+    <node name="Writing" icon="6">\r
+      <node name="PDF" icon="6"/>\r
+      <node name="AbiWord" file="abiword.xml"/>\r
+    </node>\r
+    <node name="Dictionaries" icon="6"/>\r
+  </node>\r
+  <node name="Graphics" icon="7">\r
+    <node name="Vector" icon="7"/>\r
+    <node name="Pixel" icon="7"/>\r
+    <node name="3D" icon="7"/>\r
+  </node>\r
+  <node name="Multimedia" icon="8">\r
+    <node name="Codecs" icon="8"/>\r
+    <node name="Editors" icon="8"/>\r
+    <node name="Players" icon="8"/>\r
+  </node>\r
+  <node name="Development" icon="9">\r
+    <node name="IDE" icon="9"/>\r
+    <node name="Compiler" icon="9"/>\r
+    <node name="Version Control" icon="9"/>\r
+    <node name="Web" icon="9"/>\r
+    <node name="Other" icon="9"/>\r
+  </node>\r
+  <node name="Games and Fun" icon="10"/>\r
+  <node name="Tools" icon="11">\r
+    <node name="Compression" icon="11"/>\r
+    <node name="Backup" icon="11"/>\r
+    <node name="Burning" icon="11">\r
+      <node name="CD" icon="11"/>\r
+      <node name="DVD" icon="11"/>\r
+    </node>\r
+  </node>\r
+  <node name="Others" icon="12">\r
+    <node name="Desktop Environments and Shellreplacements" icon="12"/>\r
+    <node name="Desktop" icon="12"/>\r
+    <node name="Antivirus" icon="12"/>\r
+    <node name="Emulators" icon="12">\r
+      <node name="Computers" icon="12"/>\r
+      <node name="Systems" icon="12"/>\r
+      <node name="Games" icon="12"/>\r
+    </node>\r
+    <node name="Drivers" icon="12"/>\r
+  </node>\r
+  <node name="Installed Programms" icon="13"/> \r
+</tree>\r
+\r