OLD | NEW |
1 #include <functional> | 1 #include <functional> |
2 #include <memory> | 2 #include <memory> |
3 #include <sstream> | 3 #include <sstream> |
4 #include <AdblockPlus/FileSystem.h> | 4 #include <AdblockPlus/FileSystem.h> |
5 #include <AdblockPlus/WebRequest.h> | 5 #include <AdblockPlus/WebRequest.h> |
6 | 6 |
| 7 #include "../shared/Dictionary.h" |
7 #include "../shared/Utils.h" | 8 #include "../shared/Utils.h" |
8 #include "Debug.h" | 9 #include "Debug.h" |
9 #include "Resource.h" | 10 #include "Resource.h" |
10 #include "Updater.h" | 11 #include "Updater.h" |
11 | 12 |
12 namespace | 13 namespace |
13 { | 14 { |
14 typedef std::function<void()> ThreadCallbackType; | 15 typedef std::function<void()> ThreadCallbackType; |
15 typedef std::function<void(HWND)> DialogCallbackType; | 16 typedef std::function<void(HWND)> DialogCallbackType; |
16 | 17 |
17 const int DOWNLOAD_FAILED = 101; | 18 const int DOWNLOAD_FAILED = 101; |
18 | 19 |
19 LRESULT CALLBACK UpdateDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPar
am) | 20 LRESULT CALLBACK UpdateDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPar
am) |
20 { | 21 { |
21 switch (msg) | 22 switch (msg) |
22 { | 23 { |
23 case WM_INITDIALOG: | 24 case WM_INITDIALOG: |
24 { | 25 { |
25 // TODO: Localize dialog strings | 26 Dictionary* dict = Dictionary::GetInstance(); |
| 27 SetWindowTextW(hWnd, dict->Lookup("updater", "update-title").c_str()); |
| 28 SetDlgItemTextW(hWnd, IDC_UPDATETEXT, dict->Lookup("updater", "update-te
xt").c_str()); |
| 29 SetDlgItemTextW(hWnd, IDC_DOYOU, dict->Lookup("updater", "update-questio
n").c_str()); |
| 30 SetDlgItemTextW(hWnd, IDOK, dict->Lookup("general", "button-yes").c_str(
)); |
| 31 SetDlgItemTextW(hWnd, IDCANCEL, dict->Lookup("general", "button-no").c_s
tr()); |
26 return TRUE; | 32 return TRUE; |
27 } | 33 } |
28 case WM_COMMAND: | 34 case WM_COMMAND: |
29 { | 35 { |
30 if (wParam == IDOK || wParam == IDCANCEL) | 36 if (wParam == IDOK || wParam == IDCANCEL) |
31 { | 37 { |
32 EndDialog(hWnd, wParam); | 38 EndDialog(hWnd, wParam); |
33 return TRUE; | 39 return TRUE; |
34 } | 40 } |
35 break; | 41 break; |
36 } | 42 } |
37 } | 43 } |
38 | 44 |
39 return FALSE; | 45 return FALSE; |
40 } | 46 } |
41 | 47 |
42 LRESULT CALLBACK DownloadDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lP
aram) | 48 LRESULT CALLBACK DownloadDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lP
aram) |
43 { | 49 { |
44 // TODO: Indicate progress | 50 // TODO: Indicate progress |
45 | 51 |
46 switch (msg) | 52 switch (msg) |
47 { | 53 { |
48 case WM_INITDIALOG: | 54 case WM_INITDIALOG: |
49 { | 55 { |
50 // TODO: Localize dialog strings | 56 Dictionary* dict = Dictionary::GetInstance(); |
| 57 SetWindowTextW(hWnd, dict->Lookup("updater", "download-title").c_str()); |
| 58 SetDlgItemTextW(hWnd, IDC_INSTALLMSG, dict->Lookup("updater", "download-
progress-text").c_str()); |
| 59 SetDlgItemTextW(hWnd, IDCANCEL, dict->Lookup("general", "button-cancel")
.c_str()); |
| 60 |
51 std::auto_ptr<DialogCallbackType> callback(reinterpret_cast<DialogCallba
ckType*>(lParam)); | 61 std::auto_ptr<DialogCallbackType> callback(reinterpret_cast<DialogCallba
ckType*>(lParam)); |
52 (*callback)(hWnd); | 62 (*callback)(hWnd); |
53 return TRUE; | 63 return TRUE; |
54 } | 64 } |
55 case WM_COMMAND: | 65 case WM_COMMAND: |
56 { | 66 { |
57 if (wParam == IDCANCEL) | 67 if (wParam == IDCANCEL) |
58 { | 68 { |
59 EndDialog(hWnd, wParam); | 69 EndDialog(hWnd, wParam); |
60 return TRUE; | 70 return TRUE; |
(...skipping 26 matching lines...) Expand all Loading... |
87 { | 97 { |
88 Debug("User accepted update"); | 98 Debug("User accepted update"); |
89 | 99 |
90 DialogCallbackType* callback = new DialogCallbackType(std::bind(&Updater::St
artDownload, | 100 DialogCallbackType* callback = new DialogCallbackType(std::bind(&Updater::St
artDownload, |
91 this, std::placeholders::_1)); | 101 this, std::placeholders::_1)); |
92 int result = DialogBoxParam(NULL, MAKEINTRESOURCE(IDD_DOWNLOADDIALOG), GetDe
sktopWindow(), | 102 int result = DialogBoxParam(NULL, MAKEINTRESOURCE(IDD_DOWNLOADDIALOG), GetDe
sktopWindow(), |
93 reinterpret_cast<DLGPROC>(&DownloadDlgProc), | 103 reinterpret_cast<DLGPROC>(&DownloadDlgProc), |
94 reinterpret_cast<LPARAM>(callback)); | 104 reinterpret_cast<LPARAM>(callback)); |
95 if (result == DOWNLOAD_FAILED) | 105 if (result == DOWNLOAD_FAILED) |
96 { | 106 { |
97 // TODO: Localize | 107 Dictionary* dict = Dictionary::GetInstance(); |
98 MessageBoxW(NULL, L"Download failed", L"Downloading update", 0); | 108 MessageBoxW(NULL, |
| 109 dict->Lookup("updater", "download-error-neterror").c_str(), |
| 110 dict->Lookup("updater", "download-error-title").c_str(), |
| 111 0); |
99 } | 112 } |
100 if (result != IDOK) | 113 if (result != IDOK) |
101 return; | 114 return; |
102 | 115 |
103 PROCESS_INFORMATION pi; | 116 PROCESS_INFORMATION pi; |
104 STARTUPINFO si; | 117 STARTUPINFO si; |
105 ::ZeroMemory(&si, sizeof(si)); | 118 ::ZeroMemory(&si, sizeof(si)); |
106 si.cb = sizeof(si); | 119 si.cb = sizeof(si); |
107 si.wShowWindow = FALSE; | 120 si.wShowWindow = FALSE; |
108 | 121 |
109 if (!::CreateProcessW(tempFile.c_str(), NULL, NULL, NULL, FALSE, CREATE_BREA
KAWAY_FROM_JOB, NULL, NULL, &si, &pi)) | 122 if (!::CreateProcessW(tempFile.c_str(), NULL, NULL, NULL, FALSE, CREATE_BREA
KAWAY_FROM_JOB, NULL, NULL, &si, &pi)) |
110 { | 123 { |
111 // TODO: Localize | 124 Dictionary* dict = Dictionary::GetInstance(); |
112 MessageBoxW(NULL, L"Failed to run updater", L"Downloading update", 0); | 125 MessageBoxW(NULL, |
| 126 dict->Lookup("updater", "download-error-runerror").c_str(), |
| 127 dict->Lookup("updater", "download-error-title").c_str(), |
| 128 0); |
113 DebugLastError("Creating updater process failed"); | 129 DebugLastError("Creating updater process failed"); |
114 return; | 130 return; |
115 } | 131 } |
116 ::CloseHandle(pi.hProcess); | 132 ::CloseHandle(pi.hProcess); |
117 ::CloseHandle(pi.hThread); | 133 ::CloseHandle(pi.hThread); |
118 } | 134 } |
119 } | 135 } |
120 | 136 |
121 void Updater::StartDownload(HWND dialog) | 137 void Updater::StartDownload(HWND dialog) |
122 { | 138 { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 } | 175 } |
160 catch (const std::exception& e) | 176 catch (const std::exception& e) |
161 { | 177 { |
162 DebugException(e); | 178 DebugException(e); |
163 EndDialog(dialog, DOWNLOAD_FAILED); | 179 EndDialog(dialog, DOWNLOAD_FAILED); |
164 return; | 180 return; |
165 } | 181 } |
166 | 182 |
167 EndDialog(dialog, IDOK); | 183 EndDialog(dialog, IDOK); |
168 } | 184 } |
OLD | NEW |