PackageManager: Options.xml
[reactos.git] / rosapps / packmgr / lib / functions.cpp
1 ////////////////////////////////////////////////////////
2 //
3 // functions.cpp
4 //
5 // Script Functions
6 //
7 //
8 // Klemens Friedl, 19.03.2005
9 // frik85@hotmail.com
10 //
11 ////////////////////////////////////////////////////////////////////
12
13 #include "package.hpp"
14 #include "script.h"
15 #include "log.h"
16
17 extern const char* tree_server;
18 char* PML_Download (pTree, const char* url, const char* server, const char* filename);
19
20
21 int debuglog (int argc, char* argv[])
22 {
23 Log("! SCRIPT DEBUG: ");
24 LogAdd(argv[1]);
25
26 return ERR_OK;
27 }
28
29 int download (int argc, char* argv[])
30 {
31 char* result;
32
33 if (argc==3)
34 result = PML_Download(NULL, argv[1], argv[3], argv[2]);
35
36 else if (argc==2)
37 result = PML_Download(NULL, argv[1], NULL, argv[2]);
38
39 else
40 return ERR_GENERIC;
41
42 if(!result)
43 return ERR_GENERIC;
44
45 return ERR_OK;
46
47 }
48
49 int extract (int argc, char* argv[])
50 {
51 return ERR_OK;
52 }
53
54 int msgbox (int argc, char* argv[])
55 {
56 if (argc==1)
57 MessageBoxA(0,argv[1],0,0);
58
59 else if (argc==2)
60 MessageBoxA(0,argv[1],argv[2],0);
61
62 else
63 return ERR_GENERIC;
64
65 return ERR_OK;
66 }
67
68 int shell (int argc, char* argv[])
69 {
70 // Get the temp dir
71 char tmp [MAX_PATH];
72 GetTempPathA (MAX_PATH, tmp);
73
74 SHELLEXECUTEINFOA info = {0};
75 info.cbSize = sizeof(SHELLEXECUTEINFO);
76 info.fMask = SEE_MASK_NOCLOSEPROCESS;
77 info.lpVerb = "open";
78 info.lpFile = argv[1];
79 info.lpDirectory = tmp;
80 info.nShow = SW_SHOW;
81
82 if(argc >= 2)
83 info.lpParameters = "";
84
85 if(!ShellExecuteExA (&info))
86 return ERR_GENERIC;
87
88 WaitForSingleObject (info.hProcess, INFINITE);
89
90 return ERR_OK;
91 }
92
93 const FUNC_TABLE FuncTable[] =
94 {
95 /* Name */ /* Function */
96 {"download", download},
97 {"extract", extract},
98 {"shell", shell},
99 {"msgbox", msgbox},
100 {"debug", debuglog}
101 };