1 /* PROJECT: ReactOS Downloader
2 * LICENSE: GPL - See COPYING in the top level directory
3 * FILE: base/applications/downloader/xml.c
4 * PURPOSE: Main program
5 * PROGRAMMERS: Maarten Bosma, Lester Kortenhoeven, Dmitry Chapyshev
15 #include "resources.h"
16 #include "structures.h"
18 HWND hwnd
, hCategories
, hApps
, hDownloadButton
, hUninstallButton
, hUpdateButton
, hHelpButton
, hProfButton
;
19 HBITMAP hLogo
, hUnderline
;
20 WCHAR
* DescriptionHeadline
= L
"";
21 WCHAR
* DescriptionText
= L
"";
22 WCHAR ApplicationText
[700];
25 struct Application
* SelectedApplication
;
27 INT_PTR CALLBACK
DownloadProc (HWND
, UINT
, WPARAM
, LPARAM
);
28 BOOL
ProcessXML (const char* filename
, struct Category
* Root
);
29 VOID
FreeTree (struct Category
* Node
);
30 WCHAR Strings
[STRING_COUNT
][MAX_STRING_LENGHT
];
34 getUninstaller(WCHAR
* RegName
, WCHAR
* Uninstaller
) {
36 const DWORD ArraySize
= 200;
41 DWORD Size
= ArraySize
;
42 WCHAR Value
[ArraySize
];
43 WCHAR KeyName
[ArraySize
];
46 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall",0,KEY_READ
,&hKey1
) == ERROR_SUCCESS
) {
47 while (RegEnumKeyExW(hKey1
,i
,KeyName
,&Size
,NULL
,NULL
,NULL
,NULL
) == ERROR_SUCCESS
) {
49 RegOpenKeyExW(hKey1
,KeyName
,0,KEY_READ
,&hKey2
);
51 if (RegQueryValueExW(hKey2
,L
"DisplayName",0,&Type
,(LPBYTE
)Value
,&Size
) == ERROR_SUCCESS
) {
53 if (StrCmpW(Value
,RegName
) == 0) {
54 if (RegQueryValueExW(hKey2
,L
"UninstallString",0,&Type
,(LPBYTE
)Uninstaller
,&Size
) == ERROR_SUCCESS
) {
74 ShowMessage (WCHAR
* title
, WCHAR
* message
)
76 DescriptionHeadline
= title
;
77 DescriptionText
= message
;
78 InvalidateRect(hwnd
,NULL
,TRUE
);
83 AddItems(HWND hwnd
, struct Category
* Category
, struct Category
* Parent
)
85 TV_INSERTSTRUCTW Insert
;
87 Insert
.item
.lParam
= (UINT
)Category
;
88 Insert
.item
.mask
= TVIF_TEXT
|TVIF_PARAM
|TVIF_IMAGE
|TVIF_SELECTEDIMAGE
;;
89 Insert
.item
.pszText
= Category
->Name
;
90 Insert
.item
.cchTextMax
= lstrlenW(Category
->Name
);
91 Insert
.item
.iImage
= Category
->Icon
;
92 Insert
.item
.iSelectedImage
= Category
->Icon
;
93 Insert
.hInsertAfter
= TVI_LAST
;
94 Insert
.hParent
= Category
->Parent
? Category
->Parent
->TreeviewItem
: TVI_ROOT
;
96 Category
->TreeviewItem
= (HTREEITEM
)SendMessage(hwnd
, TVM_INSERTITEM
, 0, (LPARAM
)&Insert
);
99 AddItems (hwnd
,Category
->Next
,Parent
);
101 if(Category
->Children
)
102 AddItems (hwnd
,Category
->Children
,Category
);
106 CategoryChoosen(HWND hwnd
, struct Category
* Category
)
108 struct Application
* CurrentApplication
;
109 TV_INSERTSTRUCTW Insert
;
110 SelectedApplication
= NULL
;
112 if(Category
->Children
&& !Category
->Apps
)
113 ShowMessage(Category
->Name
, Strings
[IDS_CHOOSE_SUB
]);
114 else if(!Category
->Children
&& Category
->Apps
)
115 ShowMessage(Category
->Name
, Strings
[IDS_CHOOSE_APP
]);
116 else if(Category
->Children
&& Category
->Apps
)
117 ShowMessage(Category
->Name
, Strings
[IDS_CHOOSE_BOTH
]);
119 ShowMessage(Category
->Name
, Strings
[IDS_NO_APPS
]);
121 (void)TreeView_DeleteItem(hwnd
, TVI_ROOT
);
122 (void)TreeView_DeleteItem(hwnd
, TVI_ROOT
); // Delete twice to bypass bug in windows
124 Insert
.item
.mask
= TVIF_TEXT
|TVIF_PARAM
|TVIF_IMAGE
;
125 Insert
.hInsertAfter
= TVI_LAST
;
126 Insert
.hParent
= TVI_ROOT
;
128 CurrentApplication
= Category
->Apps
;
130 WCHAR Uninstaller
[200];
131 while(CurrentApplication
)
133 Insert
.item
.lParam
= (UINT
)CurrentApplication
;
134 Insert
.item
.pszText
= CurrentApplication
->Name
;
135 Insert
.item
.cchTextMax
= lstrlenW(CurrentApplication
->Name
);
136 Insert
.item
.iImage
= 10;
137 if(StrCmpW(CurrentApplication
->RegName
,L
"")) {
138 if(getUninstaller(CurrentApplication
->RegName
, Uninstaller
))
139 Insert
.item
.iImage
= 9;
141 SendMessage(hwnd
, TVM_INSERTITEM
, 0, (LPARAM
)&Insert
);
142 CurrentApplication
= CurrentApplication
->Next
;
146 BOOL
CreateToolTip(HWND hwndTool
, HWND hDlg
, WCHAR
* pText
)
148 if (!hwndTool
|| !hDlg
|| !pText
)
151 HWND hwndTip
= CreateWindowExW(0, TOOLTIPS_CLASS
, NULL
,
152 WS_POPUP
|TTS_ALWAYSTIP
| TTS_BALLOON
,
153 CW_USEDEFAULT
, CW_USEDEFAULT
,
154 CW_USEDEFAULT
, CW_USEDEFAULT
,
156 GetModuleHandle(NULL
), NULL
);
160 TOOLINFO toolInfo
= {0};
161 toolInfo
.cbSize
= sizeof(toolInfo
);
162 toolInfo
.hwnd
= hDlg
;
163 toolInfo
.uFlags
= TTF_IDISHWND
| TTF_SUBCLASS
;
164 toolInfo
.uId
= (UINT_PTR
)hwndTool
;
165 toolInfo
.lpszText
= pText
;
166 SendMessage(hwndTip
, TTM_ADDTOOL
, 0, (LPARAM
)&toolInfo
);
172 SetupControls (HWND hwnd
)
174 TV_INSERTSTRUCTW Insert
= {0};
175 HIMAGELIST hImageList
;
176 HINSTANCE hInstance
= GetModuleHandle(NULL
);
177 WCHAR Cats
[MAX_STRING_LENGHT
], Apps
[MAX_STRING_LENGHT
];
178 WCHAR Tooltip1
[MAX_STRING_LENGHT
], Tooltip2
[MAX_STRING_LENGHT
], Tooltip3
[MAX_STRING_LENGHT
];
183 // Getting downloader.xml path
184 if(!GetSystemDirectory(Buf
,sizeof(Buf
)/sizeof(char))) return FALSE
;
185 lstrcat((LPTSTR
)Buf
, L
"\\downloader.xml");
186 for (i
= 0; i
< _tcslen(Buf
) + 1; i
++) Tmp
[i
] = Buf
[i
];
188 // Parse the XML file
189 if (!ProcessXML(Tmp
, &Root
))
192 LoadStringW(hInstance
, IDS_CATS_TITLE
, Cats
, MAX_STRING_LENGHT
);
193 LoadStringW(hInstance
, IDS_APPS_TITLE
, Apps
, MAX_STRING_LENGHT
);
195 // Set up the controls
196 hCategories
= CreateWindowExW(0, WC_TREEVIEWW
, Cats
,
197 WS_CHILD
|WS_VISIBLE
|WS_BORDER
|TVS_HASLINES
|TVS_LINESATROOT
|TVS_HASBUTTONS
|TVS_SHOWSELALWAYS
,
198 0, 0, 0, 0, hwnd
, NULL
, hInstance
, NULL
);
200 hApps
= CreateWindowExW(0, WC_TREEVIEWW
, Apps
,
201 WS_CHILD
|WS_VISIBLE
|WS_BORDER
|TVS_HASLINES
|TVS_LINESATROOT
|TVS_HASBUTTONS
|TVS_SHOWSELALWAYS
,
202 0, 0, 0, 0, hwnd
, NULL
, hInstance
, NULL
);
204 hLogo
= LoadBitmap(GetModuleHandle(NULL
),
205 MAKEINTRESOURCE(IDB_LOGO
));
206 hUnderline
= LoadBitmap(GetModuleHandle(NULL
),
207 MAKEINTRESOURCE(IDB_UNDERLINE
));
209 hHelpButton
= CreateWindowW(L
"Button", L
"",
210 WS_CHILD
| WS_VISIBLE
| BS_ICON
,
212 hwnd
, 0, hInstance
, NULL
);
213 LoadString(hInstance
, TTT_HELPBUTTON
, Tooltip1
, MAX_STRING_LENGHT
);
214 CreateToolTip(hHelpButton
, hwnd
, Tooltip1
);
216 hUpdateButton
= CreateWindowW(L
"Button", L
"",
217 WS_CHILD
| WS_VISIBLE
| BS_ICON
,
219 hwnd
, 0, hInstance
, NULL
);
220 LoadString(hInstance
, TTT_UPDATEBUTTON
, Tooltip2
, MAX_STRING_LENGHT
);
221 CreateToolTip(hUpdateButton
, hwnd
, Tooltip2
);
223 hProfButton
= CreateWindowW(L
"Button", L
"",
224 WS_CHILD
| WS_VISIBLE
| BS_ICON
,
226 hwnd
, 0, hInstance
, NULL
);
227 LoadString(hInstance
, TTT_PROFBUTTON
, Tooltip3
, MAX_STRING_LENGHT
);
228 CreateToolTip(hProfButton
, hwnd
, Tooltip3
);
230 hDownloadButton
= CreateWindowW(L
"Button", L
"",
231 WS_CHILD
| WS_VISIBLE
| BS_BITMAP
,
233 hwnd
, 0, hInstance
, NULL
);
235 hUninstallButton
= CreateWindowW(L
"Button", L
"",
236 WS_CHILD
| WS_VISIBLE
| BS_BITMAP
,
238 hwnd
, 0, hInstance
, NULL
);
240 SendMessageW(hProfButton
,
243 (LPARAM
)(HANDLE
)LoadIcon(hInstance
,MAKEINTRESOURCE(IDI_PROF
)));
244 SendMessageW(hHelpButton
,
247 (LPARAM
)(HANDLE
)LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_HELP
)));
248 SendMessageW(hUpdateButton
,
251 (LPARAM
)(HANDLE
)LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_UPDATE
)));
252 SendMessageW(hDownloadButton
,
254 (WPARAM
)IMAGE_BITMAP
,
255 (LPARAM
)(HANDLE
)LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_DOWNLOAD
)));
256 SendMessageW(hUninstallButton
,
258 (WPARAM
)IMAGE_BITMAP
,
259 (LPARAM
)(HANDLE
)LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_UNINSTALL
)));
260 ShowWindow(hUninstallButton
, SW_HIDE
);
262 // Set deflaut entry for hApps
263 Insert
.item
.mask
= TVIF_TEXT
|TVIF_IMAGE
;
264 Insert
.item
.pszText
= Strings
[IDS_CHOOSE_CATEGORY
];
265 Insert
.item
.cchTextMax
= lstrlenW(Strings
[IDS_CHOOSE_CATEGORY
]);
266 Insert
.item
.iImage
= 0;
267 SendMessage(hApps
, TVM_INSERTITEM
, 0, (LPARAM
)&Insert
);
270 hImageList
= ImageList_Create(16, 16, ILC_COLORDDB
, 1, 1);
271 SendMessageW(hCategories
, TVM_SETIMAGELIST
, TVSIL_NORMAL
, (LPARAM
)(HIMAGELIST
)hImageList
);
272 SendMessageW(hApps
, TVM_SETIMAGELIST
, TVSIL_NORMAL
, (LPARAM
)(HIMAGELIST
)hImageList
);
274 ImageList_Add(hImageList
,
275 LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_TREEVIEW_ICON_0
)), NULL
);
276 ImageList_Add(hImageList
,
277 LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_TREEVIEW_ICON_1
)), NULL
);
278 ImageList_Add(hImageList
,
279 LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_TREEVIEW_ICON_2
)), NULL
);
280 ImageList_Add(hImageList
,
281 LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_TREEVIEW_ICON_3
)), NULL
);
282 ImageList_Add(hImageList
,
283 LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_TREEVIEW_ICON_4
)), NULL
);
284 ImageList_Add(hImageList
,
285 LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_TREEVIEW_ICON_5
)), NULL
);
286 ImageList_Add(hImageList
,
287 LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_TREEVIEW_ICON_6
)), NULL
);
288 ImageList_Add(hImageList
,
289 LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_TREEVIEW_ICON_7
)), NULL
);
290 ImageList_Add(hImageList
,
291 LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_TREEVIEW_ICON_8
)), NULL
);
292 ImageList_Add(hImageList
,
293 LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_TREEVIEW_ICON_9
)), NULL
);
294 ImageList_Add(hImageList
,
295 LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_TREEVIEW_ICON_10
)), NULL
);
296 ImageList_Add(hImageList
,
297 LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_TREEVIEW_ICON_11
)), NULL
);
298 ImageList_Add(hImageList
,
299 LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_TREEVIEW_ICON_12
)), NULL
);
300 ImageList_Add(hImageList
,
301 LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_TREEVIEW_ICON_13
)), NULL
);
303 // Fill the TreeViews
304 AddItems (hCategories
, Root
.Children
, NULL
);
310 ResizeControl (HWND hwnd
, int x1
, int y1
, int x2
, int y2
)
312 // Make resizing a little easier
313 MoveWindow(hwnd
, x1
, y1
, x2
-x1
, y2
-y1
, TRUE
);
317 DrawBitmap (HDC hdc
, int x
, int y
, HBITMAP hBmp
)
320 HDC hdcMem
= CreateCompatibleDC(hdc
);
322 SelectObject(hdcMem
, hBmp
);
323 GetObject(hBmp
, sizeof(bm
), &bm
);
324 TransparentBlt(hdc
, x
, y
, bm
.bmWidth
, bm
.bmHeight
, hdcMem
, 0, 0, bm
.bmWidth
, bm
.bmHeight
, 0xFFFFFF);
330 DrawDescription (HDC hdc
, RECT DescriptionRect
)
334 RECT Rect
= {DescriptionRect
.left
+5, DescriptionRect
.top
+3, DescriptionRect
.right
-2, DescriptionRect
.top
+22};
337 Rectangle(hdc
, DescriptionRect
.left
, DescriptionRect
.top
, DescriptionRect
.right
, DescriptionRect
.bottom
);
340 for (i
=DescriptionRect
.left
+1;i
<DescriptionRect
.right
-1;i
++)
341 DrawBitmap(hdc
, i
, DescriptionRect
.top
+22, hUnderline
); // less code then stretching ;)
344 Font
= CreateFont(-16 , 0, 0, 0, FW_EXTRABOLD
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
345 OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
, DEFAULT_QUALITY
, FF_DONTCARE
, L
"Arial");
346 SelectObject(hdc
, Font
);
347 DrawTextW(hdc
, DescriptionHeadline
, lstrlenW(DescriptionHeadline
), &Rect
, DT_SINGLELINE
|DT_NOPREFIX
);
351 Font
= CreateFont(-13 , 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
352 OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
, DEFAULT_QUALITY
, FF_DONTCARE
, L
"Arial");
353 SelectObject(hdc
, Font
);
355 Rect
.bottom
= DescriptionRect
.bottom
-2;
356 DrawTextW(hdc
, DescriptionText
, lstrlenW(DescriptionText
), &Rect
, DT_WORDBREAK
|DT_NOPREFIX
); // ToDo: Call TabbedTextOut to draw a nice table
361 void showUninstaller() {
362 int Split_Vertical
= 200;
365 GetClientRect(hwnd
,&Rect
);
366 ShowWindow(hUninstallButton
,SW_SHOW
);
367 MoveWindow(hDownloadButton
,(Split_Vertical
+Rect
.right
-Rect
.left
)/2,Rect
.bottom
-Rect
.top
-45,140,35,TRUE
);;
370 void hideUninstaller() {
371 int Split_Vertical
= 200;
374 GetClientRect(hwnd
,&Rect
);
375 ShowWindow(hUninstallButton
,SW_HIDE
);
376 MoveWindow(hDownloadButton
,(Split_Vertical
+Rect
.right
-Rect
.left
)/2-70,Rect
.bottom
-Rect
.top
-45,140,35,TRUE
);
379 void startUninstaller(WCHAR
* Uninstaller
) {
381 PROCESS_INFORMATION pi
;
383 memset(&si
, 0, sizeof(si
));
385 CreateProcessW(NULL
,Uninstaller
,NULL
,NULL
,FALSE
,0,NULL
,NULL
,&si
,&pi
);
386 CloseHandle(pi
.hThread
);
387 // WaitForSingleObject(pi.hProcess, INFINITE); // If you want to wait for the Unistaller
388 CloseHandle(pi
.hProcess
);
393 SaveSettings(HWND hwnd
)
396 TCHAR szBuf
[MAX_PATH
];
398 if (RegOpenKey(HKEY_LOCAL_MACHINE
,
399 TEXT("Software\\ReactOS\\Downloader"),
400 &hKey
) != ERROR_SUCCESS
)
403 GetDlgItemText(hwnd
, IDC_DOWNLOAD_FOLDER_EDIT
, szBuf
, sizeof(szBuf
) / sizeof(TCHAR
));
404 if (GetFileAttributes(szBuf
) == 0xFFFFFFFF)
405 if (!CreateDirectory((LPCTSTR
)szBuf
,NULL
))
407 LoadString(GetModuleHandle(NULL
), IDS_UNABLECREATE_FOLDER
, szBuf
, sizeof(szBuf
) / sizeof(TCHAR
));
408 MessageBox(hwnd
, (LPCTSTR
)szBuf
, NULL
, MB_ICONSTOP
);
411 if (RegSetValueEx(hKey
,
416 (DWORD
)(sizeof(szBuf
) / sizeof(TCHAR
))))
419 GetDlgItemText(hwnd
, IDC_UPDATE_SERVER_EDIT
, szBuf
, sizeof(szBuf
) / sizeof(TCHAR
));
420 if (RegSetValueEx(hKey
,
425 (DWORD
)(sizeof(szBuf
) / sizeof(TCHAR
))))
429 if (SendDlgItemMessage(hwnd
, IDC_DELINST_FILES_CHECKBOX
, BM_GETCHECK
, 0, 0) == BST_CHECKED
)
433 if (RegSetValueEx(hKey
,
447 InitProfDlg(HWND hwnd
)
451 DWORD dwDisp
, dwSize
;
453 if (RegOpenKey(HKEY_LOCAL_MACHINE
,
454 TEXT("Software\\ReactOS\\Downloader"),
455 &hKey
) != ERROR_SUCCESS
)
457 if (RegCreateKeyEx(HKEY_LOCAL_MACHINE
, L
"Software\\ReactOS\\Downloader",
458 0, NULL
, REG_OPTION_NON_VOLATILE
,
459 KEY_WRITE
, NULL
, &hKey
, &dwDisp
))
461 LoadString(GetModuleHandle(NULL
), IDS_NOTCREATE_REGKEY
, Buf
, sizeof(Buf
) / sizeof(TCHAR
));
462 MessageBox(hwnd
, (LPCTSTR
)Buf
, NULL
, MB_ICONSTOP
);
468 if (RegQueryValueEx(hKey
,
473 &dwSize
) == ERROR_SUCCESS
)
475 SetDlgItemText(hwnd
, IDC_DOWNLOAD_FOLDER_EDIT
, Buf
);
479 if (!GetWindowsDirectory(Buf
, sizeof(Buf
) / sizeof(TCHAR
))) return FALSE
;
483 for (i
= 0; i
< 4; i
++)
492 LoadString(GetModuleHandle(NULL
), IDS_DOWNLOAD_FOLDER
, Buf
, sizeof(Buf
) / sizeof(TCHAR
));
493 lstrcat((LPTSTR
)DPath
, Buf
);
494 if (RegSetValueEx(hKey
,
499 (DWORD
)(sizeof(DPath
) / sizeof(TCHAR
))))
503 if (GetFileAttributes(DPath
) == 0xFFFFFFFF)
504 if (!CreateDirectory((LPCTSTR
)DPath
,NULL
)) return FALSE
;
505 SetDlgItemText(hwnd
, IDC_DOWNLOAD_FOLDER_EDIT
, DPath
);
510 if (RegQueryValueEx(hKey
,
515 &dwSize
) == ERROR_SUCCESS
)
517 SetDlgItemText(hwnd
, IDC_UPDATE_SERVER_EDIT
, Buf
);
521 LoadString(GetModuleHandle(NULL
), IDS_UPDATE_URL
, Buf
, sizeof(Buf
) / sizeof(TCHAR
));
522 if (RegSetValueEx(hKey
,
527 (DWORD
)(sizeof(Buf
) / sizeof(TCHAR
))))
531 SetDlgItemText(hwnd
, IDC_UPDATE_SERVER_EDIT
, Buf
);
535 DWORD dwValue
, dwType
= REG_DWORD
;
536 dwSize
= sizeof(DWORD
);
537 if (RegQueryValueEx(hKey
,
542 &dwSize
) == ERROR_SUCCESS
)
545 SendDlgItemMessage(hwnd
, IDC_DELINST_FILES_CHECKBOX
, BM_SETCHECK
, 1, 1);
550 if (RegSetValueEx(hKey
,
565 ChooseFolder(HWND hwnd
)
568 LPCITEMIDLIST lpItemList
;
569 TCHAR szPath
[MAX_PATH
],Buf
[256];
571 ZeroMemory(&fi
, sizeof(BROWSEINFO
));
573 LoadString(GetModuleHandle(NULL
), IDS_CHOOSE_FOLDER
, Buf
, sizeof(Buf
) / sizeof(TCHAR
));
574 fi
.lpszTitle
= (LPCTSTR
)Buf
;
575 fi
.ulFlags
= BIF_DONTGOBELOWDOMAIN
| BIF_RETURNONLYFSDIRS
| BIF_BROWSEFORCOMPUTER
| BIF_NEWDIALOGSTYLE
;
580 if(!(lpItemList
= SHBrowseForFolder(&fi
))) return FALSE
;
581 SHGetPathFromIDList(lpItemList
, szPath
);
583 if (_tcslen(szPath
) == 0) return FALSE
;
584 SetDlgItemText(hwnd
, IDC_DOWNLOAD_FOLDER_EDIT
, szPath
);
590 ProfDlgProc(HWND hDlg
,
596 UNREFERENCED_PARAMETER(lParam
);
602 hIcon
= LoadImage(GetModuleHandle(NULL
),MAKEINTRESOURCE(IDI_MAIN
),IMAGE_ICON
,16,16,0);
603 SendMessage(hDlg
,WM_SETICON
,ICON_SMALL
,(LPARAM
)hIcon
);
612 case IDC_CHOOSE_BUTTON
:
619 EndDialog(hDlg
,LOWORD(wParam
));
626 EndDialog(hDlg
,LOWORD(wParam
));
638 BOOL
IsApplicationInstalled(struct Application
* App
)
640 WCHAR Uninstaller
[200];
641 if(StrCmpW(App
->RegName
, L
"")) {
642 if(getUninstaller(App
->RegName
, Uninstaller
)) {
649 struct Application
* GetDependency(const WCHAR
* Dependency
)
651 struct Category
* Category
= Root
.Children
;
653 while (Category
->Next
)
655 while (Category
->Apps
)
657 if(StrCmpW(Category
->Apps
->RegName
, Dependency
) == 0)
658 return Category
->Apps
;
659 Category
->Apps
= Category
->Apps
->Next
;
661 Category
= Category
->Next
;
667 WndProc (HWND hwnd
, UINT Message
, WPARAM wParam
, LPARAM lParam
)
669 static RECT DescriptionRect
;
670 struct Application
* AppToInstall
;
671 WCHAR InstallDep
[260];
672 WCHAR InstallDepBuffer
[260];
679 if(!SetupControls(hwnd
))
681 ShowMessage(Strings
[IDS_WELCOME_TITLE
], Strings
[IDS_WELCOME
]);
688 HDC hdc
= BeginPaint(hwnd
, &ps
);
689 HDC BackbufferHdc
= CreateCompatibleDC(hdc
);
690 HBITMAP BackbufferBmp
= CreateCompatibleBitmap(hdc
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
691 SelectObject(BackbufferHdc
, BackbufferBmp
);
693 FillRect(BackbufferHdc
, &ps
.rcPaint
, CreateSolidBrush(RGB(235,235,235)));
694 DrawBitmap(BackbufferHdc
, 10, 12, hLogo
);
695 DrawDescription(BackbufferHdc
, DescriptionRect
);
697 BitBlt(hdc
, 0, 0, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
, BackbufferHdc
, 0, 0, SRCCOPY
);
698 DeleteObject(BackbufferBmp
);
699 DeleteDC(BackbufferHdc
);
706 if(HIWORD(wParam
) == BN_CLICKED
)
708 if (lParam
== (LPARAM
)hProfButton
)
710 DialogBox(GetModuleHandle(NULL
),
711 MAKEINTRESOURCE(IDD_PROF
),
715 if (lParam
== (LPARAM
)hDownloadButton
)
717 if(SelectedApplication
)
719 /* install dependencies */
720 if(StrCmpW(SelectedApplication
->Depends
, L
""))
722 AppToInstall
= SelectedApplication
;
723 SelectedApplication
= GetDependency(SelectedApplication
->Depends
);
724 if (SelectedApplication
)
725 if (!IsApplicationInstalled(SelectedApplication
))
727 LoadString(GetModuleHandle(NULL
), IDS_INSTALL_DEP
, InstallDep
, sizeof(InstallDep
) / sizeof(WCHAR
));
728 LoadString(GetModuleHandle(NULL
), IDS_WINDOW_TITLE
, Title
, sizeof(Title
) / sizeof(WCHAR
));
729 _snwprintf(InstallDepBuffer
, sizeof(InstallDepBuffer
) / sizeof(WCHAR
), InstallDep
, SelectedApplication
->Name
, AppToInstall
->Name
, SelectedApplication
->Name
);
730 if (MessageBox(hwnd
, InstallDepBuffer
, Title
, MB_YESNO
| MB_ICONINFORMATION
) == IDYES
)
732 DialogBoxW(GetModuleHandle(NULL
), MAKEINTRESOURCEW(IDD_DOWNLOAD
), 0, DownloadProc
);
735 SelectedApplication
= AppToInstall
;
738 /* download and install the app */
739 DialogBoxW(GetModuleHandle(NULL
), MAKEINTRESOURCEW(IDD_DOWNLOAD
), 0, DownloadProc
);
741 /* install req. hacks to get it working */
742 if(StrCmpW(SelectedApplication
->PostInstallAction
, L
""))
744 AppToInstall
= SelectedApplication
;
745 CopyMemory(SelectedApplication
->Location
, SelectedApplication
->PostInstallAction
, sizeof(SelectedApplication
->Location
));
746 DialogBoxW(GetModuleHandle(NULL
), MAKEINTRESOURCEW(IDD_DOWNLOAD
), 0, DownloadProc
);
747 SelectedApplication
= AppToInstall
;
751 ShowMessage(Strings
[IDS_NO_APP_TITLE
], Strings
[IDS_NO_APP
]);
753 else if (lParam
== (LPARAM
)hUninstallButton
)
755 if(SelectedApplication
)
757 WCHAR Uninstaller
[200];
758 if(StrCmpW(SelectedApplication
->RegName
, L
"")) {
759 if(getUninstaller(SelectedApplication
->RegName
, Uninstaller
))
760 startUninstaller(Uninstaller
);
764 else if (lParam
== (LPARAM
)hUpdateButton
)
766 ShowMessage(Strings
[IDS_UPDATE_TITLE
], Strings
[IDS_UPDATE
]);
768 else if (lParam
== (LPARAM
)hHelpButton
)
770 ShowMessage(Strings
[IDS_HELP_TITLE
], Strings
[IDS_HELP
]);
778 LPNMHDR data
= (LPNMHDR
)lParam
;
779 if(data
->code
== TVN_SELCHANGED
)
781 BOOL bShowUninstaller
= FALSE
;
782 if(data
->hwndFrom
== hCategories
)
784 struct Category
* Category
= (struct Category
*) ((LPNMTREEVIEW
)lParam
)->itemNew
.lParam
;
785 CategoryChoosen (hApps
, Category
);
787 else if(data
->hwndFrom
== hApps
)
789 SelectedApplication
= (struct Application
*) ((LPNMTREEVIEW
)lParam
)->itemNew
.lParam
;
790 if(SelectedApplication
)
792 ApplicationText
[0]=L
'\0';
793 if(StrCmpW(SelectedApplication
->Version
, L
"")) {
794 StrCatW(ApplicationText
, Strings
[IDS_VERSION
]);
795 StrCatW(ApplicationText
, SelectedApplication
->Version
);
796 StrCatW(ApplicationText
, L
"\n");
798 if(StrCmpW(SelectedApplication
->Licence
, L
"")) {
799 StrCatW(ApplicationText
, Strings
[IDS_LICENCE
]);
800 StrCatW(ApplicationText
, SelectedApplication
->Licence
);
801 StrCatW(ApplicationText
, L
"\n");
803 if(StrCmpW(SelectedApplication
->Maintainer
, L
"")) {
804 StrCatW(ApplicationText
, Strings
[IDS_MAINTAINER
]);
805 StrCatW(ApplicationText
, SelectedApplication
->Maintainer
);
806 StrCatW(ApplicationText
, L
"\n");
808 if(StrCmpW(SelectedApplication
->Licence
, L
"") || StrCmpW(SelectedApplication
->Version
, L
"") || StrCmpW(SelectedApplication
->Maintainer
, L
""))
809 StrCatW(ApplicationText
, L
"\n");
810 StrCatW(ApplicationText
, SelectedApplication
->Description
);
811 ShowMessage(SelectedApplication
->Name
, ApplicationText
);
812 WCHAR Uninstaller
[200];
813 if(StrCmpW(SelectedApplication
->RegName
, L
"")) {
814 if(getUninstaller(SelectedApplication
->RegName
, Uninstaller
)) {
815 bShowUninstaller
= TRUE
;
820 if (bShowUninstaller
)
830 LPRECT pRect
= (LPRECT
)lParam
;
831 if (pRect
->right
-pRect
->left
< 520)
832 pRect
->right
= pRect
->left
+ 520;
834 if (pRect
->bottom
-pRect
->top
< 300)
835 pRect
->bottom
= pRect
->top
+ 300;
841 int Split_Hozizontal
= (HIWORD(lParam
)-(45+60))/2 + 60;
842 int Split_Vertical
= 200;
844 ResizeControl(hCategories
, 10, 60, Split_Vertical
, HIWORD(lParam
)-10);
845 ResizeControl(hApps
, Split_Vertical
+5, 60, LOWORD(lParam
)-10, Split_Hozizontal
);
846 RECT Rect
= {Split_Vertical
+5, Split_Hozizontal
+5, LOWORD(lParam
)-10, HIWORD(lParam
)-50};
847 DescriptionRect
= Rect
;
849 MoveWindow(hHelpButton
, LOWORD(lParam
)-50, 10, 40, 40, TRUE
);
850 MoveWindow(hUpdateButton
, LOWORD(lParam
)-150, 10, 40, 40, TRUE
);
851 MoveWindow(hProfButton
, LOWORD(lParam
)-100, 10, 40, 40, TRUE
);
852 if(IsWindowVisible(hUninstallButton
))
853 MoveWindow(hDownloadButton
, (Split_Vertical
+LOWORD(lParam
))/2, HIWORD(lParam
)-45, 140, 35, TRUE
);
855 MoveWindow(hDownloadButton
, (Split_Vertical
+LOWORD(lParam
))/2-70, HIWORD(lParam
)-45, 140, 35, TRUE
);
856 MoveWindow(hUninstallButton
, (Split_Vertical
+LOWORD(lParam
))/2-140, HIWORD(lParam
)-45, 140, 35, TRUE
);
864 FreeTree(Root
.Children
);
871 return DefWindowProc (hwnd
, Message
, wParam
, lParam
);
875 wWinMain (HINSTANCE hInstance
,
881 WNDCLASSEXW WndClass
= {0};
884 InitCommonControls();
887 for(i
=0; i
<STRING_COUNT
; i
++)
888 LoadStringW(hInstance
, i
, Strings
[i
], MAX_STRING_LENGHT
); // if you know a better method please tell me.
891 WndClass
.cbSize
= sizeof(WNDCLASSEX
);
892 WndClass
.lpszClassName
= L
"Downloader";
893 WndClass
.lpfnWndProc
= WndProc
;
894 WndClass
.hInstance
= hInstance
;
895 WndClass
.style
= CS_HREDRAW
| CS_VREDRAW
;
896 WndClass
.hIcon
= LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_MAIN
));
897 WndClass
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
899 RegisterClassExW(&WndClass
);
901 hwnd
= CreateWindowW(L
"Downloader",
902 Strings
[IDS_WINDOW_TITLE
],
903 WS_OVERLAPPEDWINDOW
|WS_CLIPCHILDREN
,
912 ShowWindow(hwnd
, SW_SHOW
);
916 while(GetMessage(&msg
,NULL
,0,0))
918 TranslateMessage(&msg
);
919 DispatchMessage(&msg
);