| 1 | /** |
|---|
| 2 | * Padre Minimal Win32 Executable Launcher |
|---|
| 3 | * @author Olivier Mengué <dolmen@cpan.org> |
|---|
| 4 | */ |
|---|
| 5 | #define WIN32_LEAN_AND_MEAN |
|---|
| 6 | #define STRICT |
|---|
| 7 | #include <windows.h> |
|---|
| 8 | #include <tchar.h> |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | #include <EXTERN.h> /* from the Perl distribution */ |
|---|
| 12 | #include <perl.h> /* from the Perl distribution */ |
|---|
| 13 | |
|---|
| 14 | #include "padre-rc.h" |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | static void LocalizedMessageBox(LPCTSTR lpMessage, LPCTSTR lpTitle, DWORD dwFlags) |
|---|
| 18 | { |
|---|
| 19 | HMODULE hModule; |
|---|
| 20 | TCHAR szTitle[256]; |
|---|
| 21 | TCHAR szMessage[256]; |
|---|
| 22 | |
|---|
| 23 | hModule = GetModuleHandle(NULL); |
|---|
| 24 | if (IS_INTRESOURCE(lpMessage)) { |
|---|
| 25 | LoadString(hModule, (UINT)lpMessage, szMessage, sizeof(szMessage)/sizeof(szMessage[0])); |
|---|
| 26 | lpMessage = szMessage; |
|---|
| 27 | } |
|---|
| 28 | if (IS_INTRESOURCE(lpTitle)) { |
|---|
| 29 | LoadString(hModule, (UINT)lpTitle, szTitle, sizeof(szTitle)/sizeof(szTitle[0])); |
|---|
| 30 | lpTitle = szTitle; |
|---|
| 31 | } |
|---|
| 32 | MessageBox(NULL, lpMessage, lpTitle, dwFlags); |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | static BOOL FileExists(LPCTSTR lpFileName) |
|---|
| 36 | { |
|---|
| 37 | DWORD att = GetFileAttributes(lpFileName); |
|---|
| 38 | return (att != INVALID_FILE_ATTRIBUTES); //&& (att & (FILE_ATTRIBUTE_DEVICE|FILE_ATTRIBUTE_DIRECTORY) == 0); |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | /** |
|---|
| 43 | * When called by windows, we simply launch Padre from here |
|---|
| 44 | */ |
|---|
| 45 | int |
|---|
| 46 | main(int argc, char **argv, char **env) |
|---|
| 47 | { |
|---|
| 48 | // Padre.exe path |
|---|
| 49 | TCHAR szExePath[MAX_PATH]; |
|---|
| 50 | // Padre script path |
|---|
| 51 | static TCHAR szPadre[MAX_PATH]; |
|---|
| 52 | HMODULE hModule; |
|---|
| 53 | DWORD dwLength; |
|---|
| 54 | HANDLE hHeap; |
|---|
| 55 | char **new_argv; |
|---|
| 56 | int i; |
|---|
| 57 | int r; |
|---|
| 58 | |
|---|
| 59 | hModule = GetModuleHandle(NULL); |
|---|
| 60 | //Find the the executable's path |
|---|
| 61 | dwLength = GetModuleFileName(hModule, szExePath, sizeof(szExePath)/sizeof(szExePath[0])); |
|---|
| 62 | |
|---|
| 63 | // Build the 'padre' script path |
|---|
| 64 | if (dwLength) { |
|---|
| 65 | lstrcpy(szPadre, szExePath); |
|---|
| 66 | while (--dwLength) { |
|---|
| 67 | if (szPadre[ dwLength ] == _T('\\') || szPadre[ dwLength ] == _T('/')) { |
|---|
| 68 | dwLength++; |
|---|
| 69 | break; |
|---|
| 70 | } |
|---|
| 71 | } |
|---|
| 72 | } |
|---|
| 73 | lstrcpy(&szPadre[dwLength], _T("padre")); |
|---|
| 74 | //LocalizedMessageBox(szPadre, MAKEINTRESOURCE(IDS_APP_TITLE), MB_OK|MB_ICONINFORMATION); |
|---|
| 75 | |
|---|
| 76 | //At this point we should check if padre script exists or not |
|---|
| 77 | if (! FileExists(szPadre)) { |
|---|
| 78 | LocalizedMessageBox(MAKEINTRESOURCE(IDS_ERR_SCRIPT), MAKEINTRESOURCE(IDS_APP_TITLE), MB_OK|MB_ICONERROR); |
|---|
| 79 | ExitProcess(1); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | hHeap = GetProcessHeap(); |
|---|
| 83 | new_argv = HeapAlloc(hHeap, 0, (argc+2)*sizeof(new_argv[0])); |
|---|
| 84 | new_argv[0] = argv[0]; |
|---|
| 85 | new_argv[1] = "--"; |
|---|
| 86 | new_argv[2] = szPadre; |
|---|
| 87 | for(i=1; i<argc; i++) |
|---|
| 88 | new_argv[i+2] = argv[i]; |
|---|
| 89 | argc += 2; |
|---|
| 90 | |
|---|
| 91 | r = RunPerl(argc, new_argv, env); |
|---|
| 92 | |
|---|
| 93 | HeapFree(hHeap, 0, new_argv); |
|---|
| 94 | return r; |
|---|
| 95 | } |
|---|
| 96 | /** |
|---|
| 97 | # Copyright 2008-2009 The Padre development team as listed in Padre.pm. |
|---|
| 98 | # LICENSE |
|---|
| 99 | # This program is free software; you can redistribute it and/or |
|---|
| 100 | # modify it under the same terms as Perl 5 itself. |
|---|
| 101 | */ |
|---|
| 102 | /* vim:set ts=4 sts=4 sw=4: */ |
|---|