setup.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. static void Set( HKEY k, const char *name, DWORD t, const char *data ) {
  22. RegSetValueEx(k,name,0,t,(const BYTE*)data,(DWORD)strlen(data)+1);
  23. }
  24. int WINAPI WinMain( HINSTANCE inst, HINSTANCE prev, LPSTR lpCmdLine, int nCmdShow ) {
  25. char path[MAX_PATH];
  26. *path = '"';
  27. GetModuleFileName(NULL,path+1,MAX_PATH);
  28. // register .hxml extension
  29. char *s = strrchr(path,'\\') + 1;
  30. strcpy(s,"haxe.exe\" -prompt \"%1\"");
  31. HKEY k;
  32. RegCreateKey(HKEY_CLASSES_ROOT,".hxml\\shell\\Compile\\command",&k);
  33. RegSetValueEx(k,NULL,0,REG_SZ,(const BYTE*)path,(DWORD)(strlen(path)+1));
  34. *s = 0;
  35. // add %HAXEPATH% to PATH and set HAXEPATH to current path
  36. DWORD ktype;
  37. DWORD ksize = 16000;
  38. char *kdata = new char[16000];
  39. memset(kdata,0,ksize);
  40. RegOpenKey(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment",&k);
  41. RegQueryValueEx(k,"PATH",NULL,&ktype,(LPBYTE)kdata,&ksize);
  42. if( strstr(kdata,"%HAXEPATH%") == NULL ) {
  43. char *s = kdata + strlen(kdata);
  44. strcpy(s,";%HAXEPATH%");
  45. Set(k,"PATH",REG_EXPAND_SZ,kdata);
  46. }
  47. if( strstr(kdata,"%NEKO_INSTPATH%") == NULL ) {
  48. char *s = kdata + strlen(kdata);
  49. strcpy(s,";%NEKO_INSTPATH%");
  50. Set(k,"PATH",REG_EXPAND_SZ,kdata);
  51. }
  52. Set(k,"HAXEPATH",REG_SZ,path + 1);
  53. s[-1] = 0;
  54. strcpy(strrchr(path,'\\'),"\\neko");
  55. Set(k,"NEKO_INSTPATH",REG_SZ,path+1);
  56. RegCloseKey(k);
  57. // inform running apps of env changes (W2K/NT systems only ?)
  58. DWORD unused;
  59. SendMessageTimeout(HWND_BROADCAST,WM_SETTINGCHANGE, 0, (LPARAM)"Environment", SMTO_ABORTIFHUNG, 5000, &unused );
  60. // delete kdata;
  61. // // register
  62. // if( strcmp(lpCmdLine,"-silent") != 0 )
  63. // MessageBox(NULL,"Setup completed, you can start using Haxe now","haxesetup",MB_OK | MB_ICONINFORMATION);
  64. return 0;
  65. }