setup.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Haxe Setup
  3. * Copyright (c)2006 Nicolas Cannasse
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. // this is a small program that do basic haXe setup on Windows
  20. #include <windows.h>
  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. RegOpenKey(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment",&k);
  37. RegQueryValueEx(k,"PATH",NULL,&ktype,(LPBYTE)kdata,&ksize);
  38. if( strstr(kdata,"%HAXEPATH%") == NULL ) {
  39. s = kdata + strlen(kdata);
  40. strcpy(s,";%HAXEPATH%");
  41. RegSetValueEx(k,"PATH",0,REG_EXPAND_SZ,(const BYTE*)kdata,(DWORD)(strlen(kdata)+1));
  42. }
  43. RegSetValueEx(k,"HAXEPATH",0,REG_SZ,(const BYTE*)(path+1),(DWORD)strlen(path));
  44. RegCloseKey(k);
  45. // inform running apps of env changes
  46. SendMessage(HWND_BROADCAST,WM_SETTINGCHANGE, 0, (LPARAM)"Environment");
  47. delete kdata;
  48. // register
  49. MessageBox(NULL,"Setup completed, you can start using haXe now","haxesetup",MB_OK | MB_ICONINFORMATION);
  50. return 0;
  51. }