setup.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. Haxe Setup
  3. Copyright (C) 2005-2016 Haxe Foundation
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  15. */
  16. // this is a small program that do basic Haxe setup on Windows
  17. #include <windows.h>
  18. static void Set( HKEY k, const char *name, DWORD t, const char *data ) {
  19. RegSetValueEx(k,name,0,t,(const BYTE*)data,(DWORD)strlen(data)+1);
  20. }
  21. int WINAPI WinMain( HINSTANCE inst, HINSTANCE prev, LPSTR lpCmdLine, int nCmdShow ) {
  22. char path[MAX_PATH];
  23. *path = '"';
  24. GetModuleFileName(NULL,path+1,MAX_PATH);
  25. // register .hxml extension
  26. char *s = strrchr(path,'\\') + 1;
  27. strcpy(s,"haxe.exe\" -prompt \"%1\"");
  28. HKEY k;
  29. RegCreateKey(HKEY_CLASSES_ROOT,".hxml\\shell\\Compile\\command",&k);
  30. RegSetValueEx(k,NULL,0,REG_SZ,(const BYTE*)path,(DWORD)(strlen(path)+1));
  31. *s = 0;
  32. // add %HAXEPATH% to PATH and set HAXEPATH to current path
  33. DWORD ktype;
  34. DWORD ksize = 16000;
  35. char *kdata = new char[16000];
  36. memset(kdata,0,ksize);
  37. RegOpenKey(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment",&k);
  38. RegQueryValueEx(k,"PATH",NULL,&ktype,(LPBYTE)kdata,&ksize);
  39. if( strstr(kdata,"%HAXEPATH%") == NULL ) {
  40. char *s = kdata + strlen(kdata);
  41. strcpy(s,";%HAXEPATH%");
  42. Set(k,"PATH",REG_EXPAND_SZ,kdata);
  43. }
  44. if( strstr(kdata,"%NEKO_INSTPATH%") == NULL ) {
  45. char *s = kdata + strlen(kdata);
  46. strcpy(s,";%NEKO_INSTPATH%");
  47. Set(k,"PATH",REG_EXPAND_SZ,kdata);
  48. }
  49. Set(k,"HAXEPATH",REG_SZ,path + 1);
  50. s[-1] = 0;
  51. strcpy(strrchr(path,'\\'),"\\neko");
  52. Set(k,"NEKO_INSTPATH",REG_SZ,path+1);
  53. RegCloseKey(k);
  54. // inform running apps of env changes (W2K/NT systems only ?)
  55. DWORD unused;
  56. SendMessageTimeout(HWND_BROADCAST,WM_SETTINGCHANGE, 0, (LPARAM)"Environment", SMTO_ABORTIFHUNG, 5000, &unused );
  57. // delete kdata;
  58. // // register
  59. // if( strcmp(lpCmdLine,"-silent") != 0 )
  60. // MessageBox(NULL,"Setup completed, you can start using Haxe now","haxesetup",MB_OK | MB_ICONINFORMATION);
  61. return 0;
  62. }