PackageManager: Depencies
Modified: trunk/rosapps/packmgr/gui/main.cpp
Modified: trunk/rosapps/packmgr/gui/main.h
Modified: trunk/rosapps/packmgr/lib/download.cpp
Modified: trunk/rosapps/packmgr/lib/en.rc
Modified: trunk/rosapps/packmgr/lib/error.h
Modified: trunk/rosapps/packmgr/lib/main.cpp
Modified: trunk/rosapps/packmgr/lib/package.cpp
Modified: trunk/rosapps/packmgr/lib/package.hpp

Modified: trunk/rosapps/packmgr/gui/main.cpp
--- trunk/rosapps/packmgr/gui/main.cpp	2005-04-10 14:32:30 UTC (rev 14575)
+++ trunk/rosapps/packmgr/gui/main.cpp	2005-04-10 15:34:15 UTC (rev 14576)
@@ -174,6 +174,17 @@
     return 1;
 }
 
+// Set the Icons
+int Ask (const WCHAR* message) 
+{	
+	int ans = MessageBox (0,message,0,MB_YESNO);
+
+	if(ans == IDYES)
+		return 1;
+
+    return 0;
+}
+
 // En- or Disable a Button inside of the toolbar and the Context Menu
 int SetButton (DWORD id, BOOL state) 
 {
@@ -182,7 +193,12 @@
 
     ti.cbSize = sizeof (ti);
     ti.dwMask = TBIF_STATE;
-
+/*
+	if(state&&id==1)
+		MessageBox(0,L"on",0,0);
+	else if(!state&&id==1)
+		MessageBox(0,L"off",0,0);
+*/
 	if(state)
 		ti.fsState = TBSTATE_ENABLED;
 	else
@@ -294,7 +310,7 @@
 			if(LOWORD(wParam) <= 5 && LOWORD(wParam) >= 1)
 			{
 				if(selected)
-					if(PML_SetAction(tree, selected, LOWORD(wParam)-1, SetIcon) == ERR_OK)
+					if(PML_SetAction(tree, selected, LOWORD(wParam)-1, SetIcon, Ask) == ERR_OK)
 						break;
 
 				MessageBeep(MB_ICONHAND);
@@ -303,7 +319,7 @@
 			// DoIt
 			else if(LOWORD(wParam)==6)
 			{
-				if(PML_DoIt(tree, SetStatus) == ERR_OK)
+				if(PML_DoIt(tree, SetStatus, Ask) == ERR_OK)
 					DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DOIT), hwnd, StatusProc);
 				else
 					MessageBeep(MB_ICONHAND);
@@ -325,7 +341,7 @@
 		// prozess hotkeys
 		case WM_HOTKEY:
 		{
-			if(PML_SetAction(tree, selected, wParam, SetIcon) != ERR_OK)
+			if(PML_SetAction(tree, selected, wParam, SetIcon, Ask) != ERR_OK)
 				MessageBeep(MB_ICONHAND);
 		}
 		break;

Modified: trunk/rosapps/packmgr/gui/main.h
--- trunk/rosapps/packmgr/gui/main.h	2005-04-10 14:32:30 UTC (rev 14575)
+++ trunk/rosapps/packmgr/gui/main.h	2005-04-10 15:34:15 UTC (rev 14576)
@@ -35,6 +35,7 @@
 int AddItem (int id, const char* name, int parent, int icon);
 int SetText (const char* text);
 int SetStatus (int status1, int status2, WCHAR* text);
+int Ask (const WCHAR* message);
 
 /* Toolbar Releated */
 

Modified: trunk/rosapps/packmgr/lib/download.cpp
--- trunk/rosapps/packmgr/lib/download.cpp	2005-04-10 14:32:30 UTC (rev 14575)
+++ trunk/rosapps/packmgr/lib/download.cpp	2005-04-10 15:34:15 UTC (rev 14576)
@@ -16,7 +16,7 @@
 #include <wine/urlmon.h>
 
 // Server there all the files lie
-const char* tree_server = "http://svn.reactos.com/viewcvs/*checkout*/trunk/rosapps/packmgr/tree/"; 
+const char* tree_server = "http://maarten-online.de/xml/"; 
 
 HRESULT WINAPI URLDownloadToFileA(      
     LPUNKNOWN pCaller,

Modified: trunk/rosapps/packmgr/lib/en.rc
--- trunk/rosapps/packmgr/lib/en.rc	2005-04-10 14:32:30 UTC (rev 14575)
+++ trunk/rosapps/packmgr/lib/en.rc	2005-04-10 15:34:15 UTC (rev 14576)
@@ -14,6 +14,10 @@
   ERR_SYNATX       "Error while Script Execution.\nWrong Synatx."
   ERR_CALL         "Error while Script Execution.\nCould not find function."
   ERR_PARAMETER    "Error while Script Execution.\nWrong Parameter(s)."
+
+  ERR_DEP1	   "To install this package you have to install the following package(s) as well:\n\n"
+  ERR_DEP2	   "\nDo you want this ?"
+  ERR_READY	   "You choosen to install %d package(s). To install them you have to read and agree with each of thier licences.\n\n Do you want still want to ?"
 END
 
 /* EOF */

Modified: trunk/rosapps/packmgr/lib/error.h
--- trunk/rosapps/packmgr/lib/error.h	2005-04-10 14:32:30 UTC (rev 14575)
+++ trunk/rosapps/packmgr/lib/error.h	2005-04-10 15:34:15 UTC (rev 14576)
@@ -6,6 +6,10 @@
 #define ERR_NOTODO	   0x003 // without text yet
 #define ERR_PACK	   0x004
 
+#define ERR_DEP1	   0x005
+#define ERR_DEP2	   0x006
+#define ERR_READY	   0x007
+
 // Script
 #define ERR_SYNATX     0x011
 #define ERR_CALL       0x012

Modified: trunk/rosapps/packmgr/lib/main.cpp
--- trunk/rosapps/packmgr/lib/main.cpp	2005-04-10 14:32:30 UTC (rev 14575)
+++ trunk/rosapps/packmgr/lib/main.cpp	2005-04-10 15:34:15 UTC (rev 14576)
@@ -102,7 +102,7 @@
 
 	// set all actions to none
 	for(i=0; i<tree->packages.size(); i++)
-		PML_SetAction (tree, i, 0, tree->setIcon);
+		PML_SetAction (tree, i, 0, tree->setIcon, NULL);
 
 	tree->setStatus(1000, ret, NULL);
 
@@ -110,7 +110,7 @@
 } 
 
 // Do the actions the user wants us to do
-extern "C" int PML_DoIt (TREE* tree, PML_SetStatus SetStatus)
+extern "C" int PML_DoIt (TREE* tree, PML_SetStatus SetStatus, PML_Ask Ask)
 { 
     DWORD dummy; 
 	tree->setStatus = SetStatus;
@@ -118,6 +118,14 @@
 	if(!tree->todo.size())
 		return ERR_NOTODO;
 
+	//ask
+	WCHAR buffer [2000];
+	wsprintf(buffer, PML_TransError(ERR_READY), tree->todo.size());
+
+	if(!Ask(buffer))
+		return ERR_GENERIC;
+	
+
 	hThread = CreateThread(NULL, 0, DoitThread, tree, 0, &dummy);
 
 	if(!hThread)

Modified: trunk/rosapps/packmgr/lib/package.cpp
--- trunk/rosapps/packmgr/lib/package.cpp	2005-04-10 14:32:30 UTC (rev 14575)
+++ trunk/rosapps/packmgr/lib/package.cpp	2005-04-10 15:34:15 UTC (rev 14576)
@@ -58,6 +58,12 @@
 
 		else if(!strcmp(tag, "description"))
 			pack->field = &pack->description;
+
+		else if (!strcmp(tag, "depent"))
+		{
+			pack->depencies.push_back((char*)NULL);
+			pack->field = &pack->depencies.back();
+		}
 	}
 }
 
@@ -82,7 +88,6 @@
 	(*pack->field)[len] = '\0';
 }
 
-
 // The user clicks on a package
 extern "C" int PML_LoadPackage (TREE* tree, int id, PML_SetButton SetButton)
 {
@@ -138,7 +143,7 @@
 }
 
 // The user chooses a actions like Install
-extern "C" int PML_SetAction (TREE* tree, int id, int action, PML_SetIcon SetIcon)
+extern "C" int PML_SetAction (TREE* tree, int id, int action, PML_SetIcon SetIcon, PML_Ask Ask)
 {
 	UINT i;
 	int ret = ERR_OK;
@@ -148,7 +153,7 @@
 
 	// if we have children, same action for them
 	for (i=0; i<pack->children.size(); i++)
-		ret = ret || PML_SetAction(tree, pack->children[i], action, SetIcon);
+		ret = ret || PML_SetAction(tree, pack->children[i], action, SetIcon, Ask);
 
 	// is the action possible ? 
 	if(!pack->actions[action])
@@ -158,11 +163,66 @@
 	if(pack->action == action)
 		return ERR_OK;
 
+	//
+	if(pack->depencies.size() && action)
+	{
+		UINT count = pack->depencies.size();
+		WCHAR buffer[2000], buffer2[200];
+		wcscpy(buffer, PML_TransError(ERR_DEP1));
+		
+		for (i=0; i<pack->depencies.size(); i++)
+		{
+			int item = PML_FindItem(tree, pack->depencies[i]);
+
+			if(!item)
+				return ERR_GENERIC;
+
+			if(action == tree->packages[item].action)// || tree->packages[item].installed
+			{
+				count--;
+				continue;
+			}
+
+			MultiByteToWideChar (CP_ACP, 0, pack->depencies[i], strlen(pack->depencies[i])+1, buffer2, 200);
+			wsprintf(buffer, L"%s - %s\n", buffer, buffer2);//
+		}
+
+		wcscat(buffer, PML_TransError(ERR_DEP2));
+
+		if(count)
+			if(!Ask(buffer))
+				return ERR_GENERIC;
+
+		for (i=0; i<pack->depencies.size(); i++)
+		{
+			int item = PML_FindItem(tree, pack->depencies[i]);
+
+			tree->packages[item].neededBy.push_back(id);
+
+			PML_SetAction(tree, item, action, SetIcon, Ask);
+		}
+	}
+
+	// load it if it's not loaded yet
+	else if (!pack->loaded && pack->path)
+	{
+		PML_XmlDownload (pack->path, (void*)pack, pack_start, pack_end, pack_text);
+		pack->loaded = TRUE;
+
+		return PML_SetAction(tree, id, action, SetIcon, Ask);
+	}
+
 	// set the icon
-	if(!pack->icon)
-		if(SetIcon)
+	if(SetIcon && !pack->icon)
 			SetIcon(id, action);
 
+	// set the button(s)
+	if(tree->setButton && action != 2)
+	{
+		tree->setButton(1, action);
+		//tree->setButton(pack->action+1, action);
+	}
+
 	// can't do src install yet
 	if(action == 2)
 	{
@@ -177,19 +237,13 @@
 		if(tree->setButton)
 			tree->setButton(1, 1);
 		//tree->setButton(action+1, 0);
+
 		pack->action = action;
 
 		// root notes (like network) return here
 		if(!pack->path)
 			return ret; 
 
-		// load it if it's not loaded yet
-		if(!pack->loaded)
-		{
-			PML_XmlDownload (pack->path, (void*)pack, pack_start, pack_end, pack_text);
-			pack->loaded = TRUE;
-		}
-
 		// save the name of the corresponding script in a vector
 		tree->todo.push_back(pack->files[action-1]);
 	}
@@ -197,10 +251,16 @@
 	// undoing
 	else 
 	{
-		// set other things back
-		if(tree->setButton)
-			tree->setButton(1, 0);
-		//tree->setButton(pack->action+1, 1);
+		for(i=0; i<pack->neededBy.size(); i++)
+		{
+			if(tree->packages[pack->neededBy[i]].action)
+			{
+				SetIcon(id, pack->action);
+				return ERR_GENERIC;
+			}
+		}
+
+		// set action back
 		pack->action = 0;
 
 		// root notes (like network) return here
@@ -211,8 +271,6 @@
 		for(i=0; i<tree->todo.size(); i++)
 			if(!strcmp(tree->todo[i], pack->files[pack->action-1])) // look for right entry
 				tree->todo.erase(tree->todo.begin()+i); // delete it
-
-		return ERR_OK;
 	}
 
 	return ret;

Modified: trunk/rosapps/packmgr/lib/package.hpp
--- trunk/rosapps/packmgr/lib/package.hpp	2005-04-10 14:32:30 UTC (rev 14575)
+++ trunk/rosapps/packmgr/lib/package.hpp	2005-04-10 15:34:15 UTC (rev 14576)
@@ -18,6 +18,7 @@
 typedef int (*PML_SetButton)	(DWORD dwID, BOOL state);
 typedef int (*PML_SetIcon)		(int id, int icon);
 typedef int (*PML_SetText)		(const char* text);
+typedef int (*PML_Ask)			(const WCHAR* text);
 
 
 /* Structs */
@@ -32,6 +33,8 @@
   char**		field;
   char*			name;
   char*			description;
+  vector<char*>	depencies;
+  vector<int>	neededBy;
   
   int			action;
   char*			files [4];
@@ -74,8 +77,8 @@
   int PML_FindItem (TREE* tree, const char* what);
   int PML_LoadPackage (pTree, int id, PML_SetButton);
   char* PML_GetDescription (TREE* tree, int id);
-  int PML_SetAction (pTree, int package, int action, PML_SetIcon);
-  int PML_DoIt (pTree, PML_SetStatus);
+  int PML_SetAction (pTree, int package, int action, PML_SetIcon, PML_Ask);
+  int PML_DoIt (pTree, PML_SetStatus, PML_Ask);
 
   void PML_CloseTree (pTree);
 }