Threads safer
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@2574 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
6c1d0b6e73
commit
4cb488964d
2 changed files with 81 additions and 42 deletions
|
@ -2,6 +2,12 @@
|
||||||
#include <Mmsystem.h>
|
#include <Mmsystem.h>
|
||||||
#include "../exdll/exdll.h"
|
#include "../exdll/exdll.h"
|
||||||
|
|
||||||
|
#undef EXDLL_INIT
|
||||||
|
|
||||||
|
#define EXDLL_INIT() { \
|
||||||
|
g_stringsize=string_size; \
|
||||||
|
g_stacktop=stacktop; }
|
||||||
|
|
||||||
#define NSISFunc(name) extern "C" void __declspec(dllexport) name(HWND hwndParent, int string_size, char *variables, stack_t **stacktop)
|
#define NSISFunc(name) extern "C" void __declspec(dllexport) name(HWND hwndParent, int string_size, char *variables, stack_t **stacktop)
|
||||||
|
|
||||||
char szTemp[2048];
|
char szTemp[2048];
|
||||||
|
@ -9,6 +15,16 @@ HWND hWndImage, hWndParent;
|
||||||
|
|
||||||
HINSTANCE g_hInstance;
|
HINSTANCE g_hInstance;
|
||||||
|
|
||||||
|
CRITICAL_SECTION CriticalSection;
|
||||||
|
|
||||||
|
void ECS() {
|
||||||
|
EnterCriticalSection(&CriticalSection);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LCS() {
|
||||||
|
LeaveCriticalSection(&CriticalSection);
|
||||||
|
}
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
MIL_DUMMY,
|
MIL_DUMMY,
|
||||||
MIL_GRADIENT,
|
MIL_GRADIENT,
|
||||||
|
@ -43,6 +59,7 @@ 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);
|
int myatoi(char *s);
|
||||||
COLORREF GetColor();
|
COLORREF GetColor();
|
||||||
|
void GetXY(LPPOINT lpPoint);
|
||||||
|
|
||||||
BOOL bReturn;
|
BOOL bReturn;
|
||||||
|
|
||||||
|
@ -66,7 +83,7 @@ static void my_pushstring(char *str)
|
||||||
NSISFunc(SetBg) {
|
NSISFunc(SetBg) {
|
||||||
EXDLL_INIT();
|
EXDLL_INIT();
|
||||||
|
|
||||||
bgBitmap.bReady = FALSE;
|
ECS();
|
||||||
|
|
||||||
if (!hWndImage) {
|
if (!hWndImage) {
|
||||||
hWndParent = hwndParent;
|
hWndParent = hwndParent;
|
||||||
|
@ -90,14 +107,15 @@ NSISFunc(SetBg) {
|
||||||
"NSISBGImage",
|
"NSISBGImage",
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
if (!RegisterClassEx(&wc)) {
|
ATOM atomClass = RegisterClassEx(&wc);
|
||||||
my_pushstring("can't register class");
|
if (!atomClass) {
|
||||||
|
my_pushstring("can't create window");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
hWndImage = CreateWindowEx(
|
hWndImage = CreateWindowEx(
|
||||||
WS_EX_TOOLWINDOW,
|
WS_EX_TOOLWINDOW,
|
||||||
"NSISBGImage",
|
(LPSTR)atomClass,
|
||||||
0,
|
0,
|
||||||
WS_CLIPSIBLINGS|WS_POPUP,
|
WS_CLIPSIBLINGS|WS_POPUP,
|
||||||
0,
|
0,
|
||||||
|
@ -159,7 +177,7 @@ NSISFunc(SetBg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!GetObject(bgBitmap.hBitmap, sizeof(bBitmap), (void *)&bBitmap)) {
|
if (!GetObject(bgBitmap.hBitmap, sizeof(bBitmap), (void *)&bBitmap)) {
|
||||||
my_pushstring("can't query bitmap size");
|
my_pushstring("can't load bitmap");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!bgBitmap.rPos.right) {
|
if (!bgBitmap.rPos.right) {
|
||||||
|
@ -175,6 +193,8 @@ done:
|
||||||
|
|
||||||
bgBitmap.bReady = TRUE;
|
bgBitmap.bReady = TRUE;
|
||||||
|
|
||||||
|
LCS();
|
||||||
|
|
||||||
if (hWndImage) {
|
if (hWndImage) {
|
||||||
SetWindowPos(
|
SetWindowPos(
|
||||||
hWndImage,
|
hWndImage,
|
||||||
|
@ -191,6 +211,8 @@ done:
|
||||||
}
|
}
|
||||||
|
|
||||||
NSISFunc(AddImage) {
|
NSISFunc(AddImage) {
|
||||||
|
ECS();
|
||||||
|
|
||||||
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");
|
||||||
|
@ -213,34 +235,29 @@ NSISFunc(AddImage) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
popstring(szTemp);
|
GetXY(LPPOINT(&newImg->rPos));
|
||||||
int iPosTemp = myatoi(szTemp);
|
|
||||||
if (iPosTemp < 0) iPosTemp = iPosTemp + (int)uWndWidth;
|
|
||||||
newImg->rPos.left = newImg->rPos.right = (unsigned int)iPosTemp;
|
|
||||||
popstring(szTemp);
|
|
||||||
iPosTemp = myatoi(szTemp);
|
|
||||||
if (iPosTemp < 0) iPosTemp = iPosTemp + (int)uWndHeight;
|
|
||||||
newImg->rPos.top = newImg->rPos.bottom = (unsigned int)iPosTemp;
|
|
||||||
|
|
||||||
BITMAP bBitmap;
|
BITMAP bBitmap;
|
||||||
|
|
||||||
if (!GetObject(newImg->hBitmap, sizeof(bBitmap), (void *)&bBitmap)) {
|
if (!GetObject(newImg->hBitmap, sizeof(bBitmap), (void *)&bBitmap)) {
|
||||||
my_pushstring("can't query bitmap size");
|
my_pushstring("can't load bitmap");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
newImg->rPos.right += bBitmap.bmWidth;
|
newImg->rPos.right = newImg->rPos.left + bBitmap.bmWidth;
|
||||||
newImg->rPos.bottom += bBitmap.bmHeight;
|
newImg->rPos.bottom = newImg->rPos.top + bBitmap.bmHeight;
|
||||||
|
|
||||||
newImg->bReady = TRUE;
|
|
||||||
|
|
||||||
myImageList *img = &bgBitmap;
|
myImageList *img = &bgBitmap;
|
||||||
while (img->next) img = img->next;
|
while (img->next) img = img->next;
|
||||||
img->next = newImg;
|
img->next = newImg;
|
||||||
|
|
||||||
my_pushstring("success");
|
my_pushstring("success");
|
||||||
|
|
||||||
|
LCS();
|
||||||
}
|
}
|
||||||
|
|
||||||
NSISFunc(AddText) {
|
NSISFunc(AddText) {
|
||||||
|
ECS();
|
||||||
|
|
||||||
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");
|
||||||
|
@ -260,30 +277,17 @@ NSISFunc(AddText) {
|
||||||
popstring(szTemp);
|
popstring(szTemp);
|
||||||
newImg->hFont = (HFONT)myatoi(szTemp);
|
newImg->hFont = (HFONT)myatoi(szTemp);
|
||||||
newImg->cTextColor = GetColor();
|
newImg->cTextColor = GetColor();
|
||||||
popstring(szTemp);
|
|
||||||
int iPosTemp = myatoi(szTemp);
|
GetXY(LPPOINT(&newImg->rPos));
|
||||||
if (iPosTemp < 0) iPosTemp = iPosTemp + (int)uWndWidth;
|
GetXY(LPPOINT(&newImg->rPos) + 1);
|
||||||
newImg->rPos.left = (unsigned int)iPosTemp;
|
|
||||||
popstring(szTemp);
|
|
||||||
iPosTemp = myatoi(szTemp);
|
|
||||||
if (iPosTemp < 0) iPosTemp = iPosTemp + (int)uWndHeight;
|
|
||||||
newImg->rPos.top = (unsigned int)iPosTemp;
|
|
||||||
popstring(szTemp);
|
|
||||||
iPosTemp = myatoi(szTemp);
|
|
||||||
if (iPosTemp < 0) iPosTemp = iPosTemp + (int)uWndWidth;
|
|
||||||
newImg->rPos.right = (unsigned int)iPosTemp;
|
|
||||||
popstring(szTemp);
|
|
||||||
iPosTemp = myatoi(szTemp);
|
|
||||||
if (iPosTemp < 0) iPosTemp = iPosTemp + (int)uWndHeight;
|
|
||||||
newImg->rPos.bottom = (unsigned int)iPosTemp;
|
|
||||||
|
|
||||||
newImg->bReady = TRUE;
|
|
||||||
|
|
||||||
myImageList *img = &bgBitmap;
|
myImageList *img = &bgBitmap;
|
||||||
while (img->next) img = img->next;
|
while (img->next) img = img->next;
|
||||||
img->next = newImg;
|
img->next = newImg;
|
||||||
|
|
||||||
my_pushstring("success");
|
my_pushstring("success");
|
||||||
|
|
||||||
|
LCS();
|
||||||
}
|
}
|
||||||
|
|
||||||
NSISFunc(Redraw) {
|
NSISFunc(Redraw) {
|
||||||
|
@ -292,7 +296,9 @@ NSISFunc(Redraw) {
|
||||||
}
|
}
|
||||||
|
|
||||||
NSISFunc(Clear) {
|
NSISFunc(Clear) {
|
||||||
bgBitmap.bReady = FALSE;
|
ECS();
|
||||||
|
|
||||||
|
BOOL bIsFirst = TRUE;
|
||||||
|
|
||||||
myImageList *img = &bgBitmap;
|
myImageList *img = &bgBitmap;
|
||||||
while (img) {
|
while (img) {
|
||||||
|
@ -306,12 +312,20 @@ NSISFunc(Clear) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
myImageList *thisImg = img;
|
||||||
|
|
||||||
img = img->next;
|
img = img->next;
|
||||||
|
|
||||||
if (img) GlobalFree(img);
|
if (!bIsFirst)
|
||||||
|
GlobalFree(thisImg);
|
||||||
|
else
|
||||||
|
bIsFirst = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bgBitmap.next = 0;
|
bgBitmap.next = 0;
|
||||||
|
bgBitmap.bReady = FALSE;
|
||||||
|
|
||||||
|
LCS();
|
||||||
}
|
}
|
||||||
|
|
||||||
NSISFunc(Destroy) {
|
NSISFunc(Destroy) {
|
||||||
|
@ -324,11 +338,13 @@ NSISFunc(Destroy) {
|
||||||
|
|
||||||
NSISFunc(Sound) {
|
NSISFunc(Sound) {
|
||||||
char szLoop[] = {'/', 'L', 'O', 'O', 'P', 0};
|
char szLoop[] = {'/', 'L', 'O', 'O', 'P', 0};
|
||||||
|
char szWait[] = {'/', 'W', 'A', 'I', 'T', 0};
|
||||||
|
char szStop[] = {'/', 'S', 'T', 'O', 'P', 0};
|
||||||
|
|
||||||
DWORD flags = SND_FILENAME | SND_NODEFAULT;
|
DWORD flags = SND_FILENAME | SND_NODEFAULT;
|
||||||
g_stacktop=stacktop;
|
g_stacktop=stacktop;
|
||||||
popstring(szTemp);
|
popstring(szTemp);
|
||||||
if (lstrcmpi(szTemp, "/WAIT"))
|
if (lstrcmpi(szTemp, szWait))
|
||||||
flags |= SND_ASYNC;
|
flags |= SND_ASYNC;
|
||||||
else
|
else
|
||||||
popstring(szTemp);
|
popstring(szTemp);
|
||||||
|
@ -336,7 +352,7 @@ NSISFunc(Sound) {
|
||||||
flags |= SND_LOOP;
|
flags |= SND_LOOP;
|
||||||
popstring(szTemp);
|
popstring(szTemp);
|
||||||
}
|
}
|
||||||
PlaySound(lstrcmpi(szTemp, "/STOP") ? szTemp : 0, 0, flags);
|
PlaySound(lstrcmpi(szTemp, szStop) ? szTemp : 0, 0, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
|
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
|
||||||
|
@ -358,6 +374,8 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
switch (message) {
|
switch (message) {
|
||||||
case WM_PAINT:
|
case WM_PAINT:
|
||||||
if (bgBitmap.bReady) {
|
if (bgBitmap.bReady) {
|
||||||
|
ECS();
|
||||||
|
|
||||||
PAINTSTRUCT ps;
|
PAINTSTRUCT ps;
|
||||||
HDC hdc = BeginPaint(hwnd, &ps);
|
HDC hdc = BeginPaint(hwnd, &ps);
|
||||||
|
|
||||||
|
@ -398,7 +416,6 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
|
|
||||||
myImageList *img = bgBitmap.next;
|
myImageList *img = bgBitmap.next;
|
||||||
while (img) {
|
while (img) {
|
||||||
if (!img->bReady) break;
|
|
||||||
if (img->iType == MIL_TEXT) {
|
if (img->iType == MIL_TEXT) {
|
||||||
SetBkMode(hdc, TRANSPARENT);
|
SetBkMode(hdc, TRANSPARENT);
|
||||||
|
|
||||||
|
@ -511,6 +528,8 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
img = img->next;
|
img = img->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LCS();
|
||||||
|
|
||||||
EndPaint(hwnd, &ps);
|
EndPaint(hwnd, &ps);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -522,7 +541,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_CLOSE:
|
case WM_CLOSE:
|
||||||
DestroyWindow(hWndImage);
|
DestroyWindow(hwnd);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return DefWindowProc(hwnd, message, wParam, lParam);
|
return DefWindowProc(hwnd, message, wParam, lParam);
|
||||||
|
@ -541,6 +560,18 @@ COLORREF GetColor() {
|
||||||
return RGB(iRed, iGreen, iBlue);
|
return RGB(iRed, iGreen, iBlue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GetXY(LPPOINT lpPoint) {
|
||||||
|
popstring(szTemp);
|
||||||
|
int iPosTemp = myatoi(szTemp);
|
||||||
|
if (iPosTemp < 0) iPosTemp = iPosTemp + (int)uWndWidth;
|
||||||
|
lpPoint->x = (unsigned int)iPosTemp;
|
||||||
|
|
||||||
|
popstring(szTemp);
|
||||||
|
iPosTemp = myatoi(szTemp);
|
||||||
|
if (iPosTemp < 0) iPosTemp = iPosTemp + (int)uWndHeight;
|
||||||
|
lpPoint->y = (unsigned int)iPosTemp;
|
||||||
|
}
|
||||||
|
|
||||||
int myatoi(char *s)
|
int myatoi(char *s)
|
||||||
{
|
{
|
||||||
unsigned int v=0;
|
unsigned int v=0;
|
||||||
|
@ -588,5 +619,13 @@ int myatoi(char *s)
|
||||||
|
|
||||||
BOOL WINAPI _DllMainCRTStartup(HINSTANCE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) {
|
BOOL WINAPI _DllMainCRTStartup(HINSTANCE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) {
|
||||||
g_hInstance=hInst;
|
g_hInstance=hInst;
|
||||||
|
switch (ul_reason_for_call) {
|
||||||
|
case DLL_PROCESS_ATTACH:
|
||||||
|
InitializeCriticalSection(&CriticalSection);
|
||||||
|
break;
|
||||||
|
case DLL_PROCESS_DETACH:
|
||||||
|
DeleteCriticalSection(&CriticalSection);
|
||||||
|
break;
|
||||||
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue