Better error handling
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3138 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
ccef537676
commit
ed8c349736
3 changed files with 60 additions and 42 deletions
|
@ -57,9 +57,10 @@ unsigned int uWndWidth, uWndHeight;
|
||||||
|
|
||||||
void *oldProc;
|
void *oldProc;
|
||||||
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
|
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
|
||||||
int myatoi(char *s);
|
HBITMAP __stdcall LoadBitmapFile(long right, long bottom, BITMAP *bBitmap);
|
||||||
|
int __stdcall myatoi(char *s);
|
||||||
COLORREF GetColor();
|
COLORREF GetColor();
|
||||||
void GetXY(LPPOINT lpPoint);
|
void __stdcall GetXY(LPPOINT lpPoint);
|
||||||
|
|
||||||
BOOL bReturn;
|
BOOL bReturn;
|
||||||
|
|
||||||
|
@ -70,7 +71,7 @@ NSISFunc(SetReturn) {
|
||||||
bReturn = !lstrcmpi(szTemp, "on");
|
bReturn = !lstrcmpi(szTemp, "on");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void my_pushstring(char *str)
|
static void __stdcall my_pushstring(char *str)
|
||||||
{
|
{
|
||||||
stack_t *th;
|
stack_t *th;
|
||||||
if (!g_stacktop || !bReturn) return;
|
if (!g_stacktop || !bReturn) return;
|
||||||
|
@ -90,6 +91,7 @@ NSISFunc(SetBg) {
|
||||||
|
|
||||||
if (!hwndParent) {
|
if (!hwndParent) {
|
||||||
my_pushstring("can't find parent window");
|
my_pushstring("can't find parent window");
|
||||||
|
LCS();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,13 +131,17 @@ NSISFunc(SetBg) {
|
||||||
);
|
);
|
||||||
if (!hWndImage) {
|
if (!hWndImage) {
|
||||||
my_pushstring("can't create window");
|
my_pushstring("can't create window");
|
||||||
|
LCS();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
oldProc = (void *)SetWindowLong(hwndParent, GWL_WNDPROC, (long)WndProc);
|
oldProc = (void *)SetWindowLong(hwndParent, GWL_WNDPROC, (long)WndProc);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bgBitmap.iType == MIL_BITMAP) DeleteObject(bgBitmap.hBitmap);
|
bgBitmap.bReady = FALSE;
|
||||||
|
|
||||||
|
if (bgBitmap.iType == MIL_BITMAP)
|
||||||
|
DeleteObject(bgBitmap.hBitmap);
|
||||||
|
|
||||||
unsigned int uScrWidth = GetSystemMetrics(SM_CXSCREEN);
|
unsigned int uScrWidth = GetSystemMetrics(SM_CXSCREEN);
|
||||||
unsigned int uScrHeight = GetSystemMetrics(SM_CYSCREEN);
|
unsigned int uScrHeight = GetSystemMetrics(SM_CYSCREEN);
|
||||||
|
@ -146,8 +152,12 @@ NSISFunc(SetBg) {
|
||||||
uWndWidth = uScrWidth;
|
uWndWidth = uScrWidth;
|
||||||
uWndHeight = uScrHeight;
|
uWndHeight = uScrHeight;
|
||||||
|
|
||||||
|
char szGradient[] = {'/', 'G', 'R', 'A', 'D', 'I', 'E', 'N', 'T', 0};
|
||||||
|
char szFillScreen[] = {'/', 'F', 'I' ,'L', 'L', 'S', 'C', 'R', 'E', 'E', 'N', 0};
|
||||||
|
char szTiled[] = {'/', 'T', 'I', 'L', 'E', 'D', 0};
|
||||||
|
|
||||||
popstring(szTemp);
|
popstring(szTemp);
|
||||||
if (!lstrcmpi(szTemp, "/GRADIENT")) {
|
if (!lstrcmpi(szTemp, szGradient)) {
|
||||||
bgBitmap.cGradientFrom = GetColor();
|
bgBitmap.cGradientFrom = GetColor();
|
||||||
bgBitmap.cGradientTo = GetColor();
|
bgBitmap.cGradientTo = GetColor();
|
||||||
|
|
||||||
|
@ -155,12 +165,12 @@ NSISFunc(SetBg) {
|
||||||
|
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (!lstrcmpi(szTemp, "/FILLSCREEN")) {
|
if (!lstrcmpi(szTemp, szFillScreen)) {
|
||||||
bgBitmap.rPos.right = uScrWidth;
|
bgBitmap.rPos.right = uScrWidth;
|
||||||
bgBitmap.rPos.bottom = uScrHeight;
|
bgBitmap.rPos.bottom = uScrHeight;
|
||||||
popstring(szTemp);
|
popstring(szTemp);
|
||||||
}
|
}
|
||||||
else if (!lstrcmpi(szTemp, "/TILED")) {
|
else if (!lstrcmpi(szTemp, szTiled)) {
|
||||||
popstring(szTemp);
|
popstring(szTemp);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -170,16 +180,10 @@ NSISFunc(SetBg) {
|
||||||
|
|
||||||
BITMAP bBitmap;
|
BITMAP bBitmap;
|
||||||
|
|
||||||
bgBitmap.hBitmap = (HBITMAP)LoadImage(0, szTemp, IMAGE_BITMAP, bgBitmap.rPos.right, bgBitmap.rPos.bottom, LR_LOADFROMFILE);
|
bgBitmap.hBitmap = LoadBitmapFile(bgBitmap.rPos.right, bgBitmap.rPos.bottom, &bBitmap);
|
||||||
if (!bgBitmap.hBitmap) {
|
if (!bgBitmap.hBitmap)
|
||||||
my_pushstring("can't load bitmap");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (!GetObject(bgBitmap.hBitmap, sizeof(bBitmap), (void *)&bBitmap)) {
|
|
||||||
my_pushstring("can't load bitmap");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!bgBitmap.rPos.right) {
|
if (!bgBitmap.rPos.right) {
|
||||||
bgBitmap.rPos.right = bBitmap.bmWidth;
|
bgBitmap.rPos.right = bBitmap.bmWidth;
|
||||||
bgBitmap.rPos.bottom = bBitmap.bmHeight;
|
bgBitmap.rPos.bottom = bBitmap.bmHeight;
|
||||||
|
@ -216,6 +220,7 @@ NSISFunc(AddImage) {
|
||||||
myImageList *newImg = (myImageList *)GlobalAlloc(GPTR, sizeof(myImageList));
|
myImageList *newImg = (myImageList *)GlobalAlloc(GPTR, sizeof(myImageList));
|
||||||
if (!newImg) {
|
if (!newImg) {
|
||||||
my_pushstring("memory allocation error");
|
my_pushstring("memory allocation error");
|
||||||
|
LCS();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,20 +234,16 @@ NSISFunc(AddImage) {
|
||||||
popstring(szTemp);
|
popstring(szTemp);
|
||||||
}
|
}
|
||||||
|
|
||||||
newImg->hBitmap = (HBITMAP)LoadImage(0, szTemp, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
|
BITMAP bBitmap;
|
||||||
|
|
||||||
|
newImg->hBitmap = LoadBitmapFile(0, 0, &bBitmap);
|
||||||
if (!newImg->hBitmap) {
|
if (!newImg->hBitmap) {
|
||||||
my_pushstring("can't load bitmap");
|
GlobalFree(newImg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetXY(LPPOINT(&newImg->rPos));
|
GetXY(LPPOINT(&newImg->rPos));
|
||||||
|
|
||||||
BITMAP bBitmap;
|
|
||||||
|
|
||||||
if (!GetObject(newImg->hBitmap, sizeof(bBitmap), (void *)&bBitmap)) {
|
|
||||||
my_pushstring("can't load bitmap");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
newImg->rPos.right = newImg->rPos.left + bBitmap.bmWidth;
|
newImg->rPos.right = newImg->rPos.left + bBitmap.bmWidth;
|
||||||
newImg->rPos.bottom = newImg->rPos.top + bBitmap.bmHeight;
|
newImg->rPos.bottom = newImg->rPos.top + bBitmap.bmHeight;
|
||||||
|
|
||||||
|
@ -261,6 +262,7 @@ NSISFunc(AddText) {
|
||||||
myImageList *newImg = (myImageList *)GlobalAlloc(GPTR, sizeof(myImageList));
|
myImageList *newImg = (myImageList *)GlobalAlloc(GPTR, sizeof(myImageList));
|
||||||
if (!newImg) {
|
if (!newImg) {
|
||||||
my_pushstring("memory allocation error");
|
my_pushstring("memory allocation error");
|
||||||
|
LCS();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,6 +272,8 @@ NSISFunc(AddText) {
|
||||||
newImg->szText = (char *)GlobalAlloc(GPTR, lstrlen(szTemp)+1);
|
newImg->szText = (char *)GlobalAlloc(GPTR, lstrlen(szTemp)+1);
|
||||||
if (!newImg->szText) {
|
if (!newImg->szText) {
|
||||||
my_pushstring("memory allocation error");
|
my_pushstring("memory allocation error");
|
||||||
|
GlobalFree(newImg);
|
||||||
|
LCS();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
lstrcpy(newImg->szText, szTemp);
|
lstrcpy(newImg->szText, szTemp);
|
||||||
|
@ -356,13 +360,14 @@ NSISFunc(Sound) {
|
||||||
|
|
||||||
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
|
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
|
||||||
HWND hwndParent = hWndParent;
|
HWND hwndParent = hWndParent;
|
||||||
|
HWND hwndImage = hWndImage;
|
||||||
|
|
||||||
if (hwnd == hwndParent) {
|
if (hwnd == hwndParent) {
|
||||||
if (message == WM_SIZE) {
|
if (message == WM_SIZE) {
|
||||||
ShowWindow(hWndImage, wParam == SIZE_MINIMIZED ? SW_HIDE : SW_SHOW);
|
ShowWindow(hwndImage, wParam == SIZE_MINIMIZED ? SW_HIDE : SW_SHOW);
|
||||||
}
|
}
|
||||||
if (message == WM_WINDOWPOSCHANGED) {
|
if (message == WM_WINDOWPOSCHANGED) {
|
||||||
SetWindowPos(hWndImage, hwndParent, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
|
SetWindowPos(hwndImage, hwndParent, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
|
||||||
}
|
}
|
||||||
return CallWindowProc(
|
return CallWindowProc(
|
||||||
(long (__stdcall *)(HWND,unsigned int,unsigned int,long))oldProc,
|
(long (__stdcall *)(HWND,unsigned int,unsigned int,long))oldProc,
|
||||||
|
@ -551,18 +556,31 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
COLORREF GetColor() {
|
HBITMAP __stdcall LoadBitmapFile(long right, long bottom, BITMAP *bBitmap)
|
||||||
int iRed, iGreen, iBlue;
|
{
|
||||||
popstring(szTemp);
|
HBITMAP hBitmap = (HBITMAP)LoadImage(0, szTemp, IMAGE_BITMAP, right, bottom, LR_LOADFROMFILE);
|
||||||
iRed = myatoi(szTemp);
|
if (!hBitmap || !GetObject(hBitmap, sizeof(BITMAP), (void *)bBitmap)) {
|
||||||
popstring(szTemp);
|
my_pushstring("can't load bitmap");
|
||||||
iGreen = myatoi(szTemp);
|
if (hBitmap)
|
||||||
popstring(szTemp);
|
DeleteObject(hBitmap);
|
||||||
iBlue = myatoi(szTemp);
|
LCS();
|
||||||
return RGB(iRed, iGreen, iBlue);
|
return 0;
|
||||||
|
}
|
||||||
|
return hBitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetXY(LPPOINT lpPoint) {
|
COLORREF GetColor() {
|
||||||
|
COLORREF cColor = 0;
|
||||||
|
popstring(szTemp);
|
||||||
|
cColor |= (BYTE) myatoi(szTemp);
|
||||||
|
popstring(szTemp);
|
||||||
|
cColor |= ((BYTE) myatoi(szTemp)) << 8;
|
||||||
|
popstring(szTemp);
|
||||||
|
cColor |= ((BYTE) myatoi(szTemp)) << 16;
|
||||||
|
return cColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void __stdcall GetXY(LPPOINT lpPoint) {
|
||||||
popstring(szTemp);
|
popstring(szTemp);
|
||||||
int iPosTemp = myatoi(szTemp);
|
int iPosTemp = myatoi(szTemp);
|
||||||
if (iPosTemp < 0) iPosTemp = iPosTemp + (int)uWndWidth;
|
if (iPosTemp < 0) iPosTemp = iPosTemp + (int)uWndWidth;
|
||||||
|
@ -574,7 +592,7 @@ void GetXY(LPPOINT lpPoint) {
|
||||||
lpPoint->y = (unsigned int)iPosTemp;
|
lpPoint->y = (unsigned int)iPosTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
int myatoi(char *s)
|
int __stdcall myatoi(char *s)
|
||||||
{
|
{
|
||||||
unsigned int v=0;
|
unsigned int v=0;
|
||||||
if (*s == '0' && (s[1] == 'x' || s[1] == 'X'))
|
if (*s == '0' && (s[1] == 'x' || s[1] == 'X'))
|
||||||
|
|
|
@ -24,8 +24,8 @@ static unsigned int g_stringsize;
|
||||||
static stack_t **g_stacktop;
|
static stack_t **g_stacktop;
|
||||||
static char *g_variables;
|
static char *g_variables;
|
||||||
|
|
||||||
static int popstring(char *str); // 0 on success, 1 on empty stack
|
static int __stdcall popstring(char *str); // 0 on success, 1 on empty stack
|
||||||
static void pushstring(char *str);
|
static void __stdcall pushstring(char *str);
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
|
@ -59,7 +59,7 @@ __INST_LAST
|
||||||
|
|
||||||
|
|
||||||
// utility functions (not required but often useful)
|
// utility functions (not required but often useful)
|
||||||
static int popstring(char *str)
|
static int __stdcall popstring(char *str)
|
||||||
{
|
{
|
||||||
stack_t *th;
|
stack_t *th;
|
||||||
if (!g_stacktop || !*g_stacktop) return 1;
|
if (!g_stacktop || !*g_stacktop) return 1;
|
||||||
|
@ -70,7 +70,7 @@ static int popstring(char *str)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pushstring(char *str)
|
static void __stdcall pushstring(char *str)
|
||||||
{
|
{
|
||||||
stack_t *th;
|
stack_t *th;
|
||||||
if (!g_stacktop) return;
|
if (!g_stacktop) return;
|
||||||
|
@ -80,13 +80,13 @@ static void pushstring(char *str)
|
||||||
*g_stacktop=th;
|
*g_stacktop=th;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *getuservariable(int varnum)
|
static char * __stdcall getuservariable(int varnum)
|
||||||
{
|
{
|
||||||
if (varnum < 0 || varnum >= __INST_LAST) return NULL;
|
if (varnum < 0 || varnum >= __INST_LAST) return NULL;
|
||||||
return g_variables+varnum*g_stringsize;
|
return g_variables+varnum*g_stringsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setuservariable(int varnum, char *var)
|
static void __stdcall setuservariable(int varnum, char *var)
|
||||||
{
|
{
|
||||||
if (var != NULL && varnum >= 0 && varnum < __INST_LAST)
|
if (var != NULL && varnum >= 0 && varnum < __INST_LAST)
|
||||||
lstrcpy(g_variables + varnum*g_stringsize, var);
|
lstrcpy(g_variables + varnum*g_stringsize, var);
|
||||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue