From e45867b698ea039938d9b124007c88806b53fcc2 Mon Sep 17 00:00:00 2001 From: Maarten Bosma Date: Sun, 10 Apr 2005 15:34:15 +0000 Subject: [PATCH] PackageManager: Depencies svn path=/trunk/; revision=14576 --- rosapps/packmgr/gui/main.cpp | 24 ++++++-- rosapps/packmgr/gui/main.h | 1 + rosapps/packmgr/lib/download.cpp | 2 +- rosapps/packmgr/lib/en.rc | 4 ++ rosapps/packmgr/lib/error.h | 4 ++ rosapps/packmgr/lib/main.cpp | 12 +++- rosapps/packmgr/lib/package.cpp | 94 ++++++++++++++++++++++++++------ rosapps/packmgr/lib/package.hpp | 7 ++- 8 files changed, 121 insertions(+), 27 deletions(-) diff --git a/rosapps/packmgr/gui/main.cpp b/rosapps/packmgr/gui/main.cpp index 0fd151a4c06..eb06779f069 100644 --- a/rosapps/packmgr/gui/main.cpp +++ b/rosapps/packmgr/gui/main.cpp @@ -174,6 +174,17 @@ int SetIcon (int id, int icon) 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 @@ int SetButton (DWORD id, BOOL state) 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 @@ LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) 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 @@ LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) // 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 @@ LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) // 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; diff --git a/rosapps/packmgr/gui/main.h b/rosapps/packmgr/gui/main.h index 63cd4cc50f9..93451f91118 100644 --- a/rosapps/packmgr/gui/main.h +++ b/rosapps/packmgr/gui/main.h @@ -35,6 +35,7 @@ void Help (void); 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 */ diff --git a/rosapps/packmgr/lib/download.cpp b/rosapps/packmgr/lib/download.cpp index 6528ae5da0a..f0d2f6bd974 100644 --- a/rosapps/packmgr/lib/download.cpp +++ b/rosapps/packmgr/lib/download.cpp @@ -16,7 +16,7 @@ #include // 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, diff --git a/rosapps/packmgr/lib/en.rc b/rosapps/packmgr/lib/en.rc index 386b5bbbaa3..c7484abb9f0 100644 --- a/rosapps/packmgr/lib/en.rc +++ b/rosapps/packmgr/lib/en.rc @@ -14,6 +14,10 @@ BEGIN 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 */ diff --git a/rosapps/packmgr/lib/error.h b/rosapps/packmgr/lib/error.h index 847c6999a9d..ec63a7a763d 100644 --- a/rosapps/packmgr/lib/error.h +++ b/rosapps/packmgr/lib/error.h @@ -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 diff --git a/rosapps/packmgr/lib/main.cpp b/rosapps/packmgr/lib/main.cpp index f5812fe6176..db126ca9f06 100644 --- a/rosapps/packmgr/lib/main.cpp +++ b/rosapps/packmgr/lib/main.cpp @@ -102,7 +102,7 @@ DWORD WINAPI DoitThread (void* lpParam) // set all actions to none for(i=0; ipackages.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 @@ DWORD WINAPI DoitThread (void* lpParam) } // 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 @@ extern "C" int PML_DoIt (TREE* tree, PML_SetStatus SetStatus) 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) diff --git a/rosapps/packmgr/lib/package.cpp b/rosapps/packmgr/lib/package.cpp index 9608168ec04..7610d009800 100644 --- a/rosapps/packmgr/lib/package.cpp +++ b/rosapps/packmgr/lib/package.cpp @@ -58,6 +58,12 @@ void pack_start (void* usrdata, const char* tag, const char** arg) 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 @@ void pack_text (void* usrdata, const char* data, int len) (*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 @@ extern "C" int PML_FindItem (TREE* tree, const char* what) } // 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 @@ extern "C" int PML_SetAction (TREE* tree, int id, int action, PML_SetIcon SetIco // if we have children, same action for them for (i=0; ichildren.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 @@ extern "C" int PML_SetAction (TREE* tree, int id, int action, PML_SetIcon SetIco 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; idepencies.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; idepencies.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 @@ extern "C" int PML_SetAction (TREE* tree, int id, int action, PML_SetIcon SetIco 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 @@ extern "C" int PML_SetAction (TREE* tree, int id, int action, PML_SetIcon SetIco // undoing else { - // set other things back - if(tree->setButton) - tree->setButton(1, 0); - //tree->setButton(pack->action+1, 1); + for(i=0; ineededBy.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 @@ extern "C" int PML_SetAction (TREE* tree, int id, int action, PML_SetIcon SetIco for(i=0; itodo.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; diff --git a/rosapps/packmgr/lib/package.hpp b/rosapps/packmgr/lib/package.hpp index 0b900658cff..1170ba4790d 100644 --- a/rosapps/packmgr/lib/package.hpp +++ b/rosapps/packmgr/lib/package.hpp @@ -18,6 +18,7 @@ typedef int (*PML_SetStatus) (int status1, int status2, WCHAR* text); 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 @@ typedef struct char** field; char* name; char* description; + vector depencies; + vector neededBy; int action; char* files [4]; @@ -74,8 +77,8 @@ extern "C" 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); }