main.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include <Polycode.h>
  2. #include "PolycodeIDEApp.h"
  3. #include "PolycodeWinIDEView.h"
  4. #include "windows.h"
  5. #include "resource.h"
  6. #include <Shlobj.h>
  7. #include <Shlwapi.h>
  8. #include <shellapi.h>
  9. extern PolycodeIDEApp *globalApp;
  10. using namespace Polycode;
  11. void registerFileType(String extension, String progId, String app, String defaultIcon, String desc) {
  12. HKEY hkey;
  13. RegCreateKeyEx(HKEY_CLASSES_ROOT,extension.getWDataWithEncoding(String::ENCODING_UTF8),0,0,0,KEY_ALL_ACCESS,0,&hkey,0);
  14. RegSetValueEx(hkey,L"",0,REG_SZ,(BYTE*)progId.getWDataWithEncoding(String::ENCODING_UTF8),progId.length() * sizeof(wchar_t));
  15. RegCloseKey(hkey);
  16. RegCreateKeyEx(HKEY_CLASSES_ROOT,L".polyproject\\OpenWithProgIds\\",0,0,0,KEY_ALL_ACCESS,0,&hkey,0);
  17. RegSetValueEx(hkey,progId.getWDataWithEncoding(String::ENCODING_UTF8),0,REG_NONE,0,0);
  18. RegCloseKey(hkey);
  19. RegCreateKeyEx(HKEY_CLASSES_ROOT,progId.getWDataWithEncoding(String::ENCODING_UTF8),0,0,0,KEY_ALL_ACCESS,0,&hkey,0);
  20. RegSetValueEx(hkey,L"",0,REG_SZ,(BYTE*)desc.getWDataWithEncoding(String::ENCODING_UTF8),desc.length() * sizeof(wchar_t));
  21. RegCloseKey(hkey);
  22. String path = progId + "\\shell\\open\\command\\";
  23. RegCreateKeyEx(HKEY_CLASSES_ROOT,path.getWDataWithEncoding(String::ENCODING_UTF8),0,0,0,KEY_ALL_ACCESS,0,&hkey,0);
  24. RegSetValueEx(hkey,L"",0,REG_SZ,(BYTE*)app.getWDataWithEncoding(String::ENCODING_UTF8),app.length() * sizeof(wchar_t));
  25. RegCloseKey(hkey);
  26. path = progId + "\\DefaultIcon\\";
  27. RegCreateKeyEx(HKEY_CLASSES_ROOT,path.getWDataWithEncoding(String::ENCODING_UTF8),0,0,0,KEY_ALL_ACCESS,0,&hkey,0);
  28. RegSetValueEx(hkey,L"",0,REG_SZ,(BYTE*)defaultIcon.getWDataWithEncoding(String::ENCODING_UTF8),defaultIcon.length() * sizeof(wchar_t));
  29. RegCloseKey(hkey);
  30. SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST,0,0);
  31. }
  32. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  33. {
  34. ChangeWindowMessageFilter(WM_COPYDATA,MSGFLT_ADD);
  35. int nArgs;
  36. LPWSTR *szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
  37. String fileName = "";
  38. if(nArgs > 1) {
  39. fileName = String(szArglist[1]);
  40. }
  41. fileName = fileName.replace("\\", "/");
  42. // check if an instance of Polycode is running and bring it up and open file if needed
  43. HWND runningHwnd = FindWindow(L"POLYCODEAPPLICATION", L"Polycode");
  44. if(runningHwnd) {
  45. SwitchToThisWindow(runningHwnd, FALSE);
  46. ShowWindow(runningHwnd,SW_NORMAL);
  47. if(fileName != "") {
  48. COPYDATASTRUCT cds;
  49. cds.cbData = (fileName.length() * sizeof(wchar_t)) + 1;
  50. cds.lpData = fileName.getWDataWithEncoding(String::ENCODING_UTF8);
  51. SendMessage(runningHwnd, WM_COPYDATA, 0, (LPARAM)&cds);
  52. }
  53. return 1;
  54. }
  55. TCHAR FilePath[MAX_PATH] = { 0 };
  56. GetModuleFileName( 0, FilePath, MAX_PATH );
  57. PathRemoveFileSpec( FilePath );
  58. SetCurrentDirectory( FilePath );
  59. PolycodeWinIDEView *view = new PolycodeWinIDEView(hInstance, nCmdShow, L"Polycode", true, false);
  60. PolycodeIDEApp *app = new PolycodeIDEApp(view);
  61. globalApp = app;
  62. if(fileName != "") {
  63. app->openProject(fileName);
  64. }
  65. HICON mainIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
  66. SendMessage(view->hwnd, WM_SETICON, ICON_SMALL, (LPARAM) mainIcon );
  67. registerFileType(".polyproject", "Polycode.ProjectFile.1", CoreServices::getInstance()->getCore()->getDefaultWorkingDirectory()+"\\Polycode.exe \"%1\"", CoreServices::getInstance()->getCore()->getDefaultWorkingDirectory()+"\\Polycode.exe,-103", "Polycode Project");
  68. registerFileType(".polyapp", "Polycode.Applicaton.1", CoreServices::getInstance()->getCore()->getDefaultWorkingDirectory()+"\\Standalone\\Player\\PolycodePlayer.exe \"%1\"", CoreServices::getInstance()->getCore()->getDefaultWorkingDirectory()+"\\Polycode.exe,-104", "Polycode Application");
  69. MSG Msg;
  70. do {
  71. while (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) {
  72. if (!TranslateAccelerator(view->hwnd, view->haccel, &Msg)) {
  73. TranslateMessage(&Msg);
  74. DispatchMessage(&Msg);
  75. }
  76. }
  77. if(((Win32Core*)app->core)->hasCopyDataString) {
  78. app->openProject(((Win32Core*)app->core)->copyDataString);
  79. ((Win32Core*)app->core)->hasCopyDataString = false;
  80. }
  81. } while(app->Update());
  82. app->saveConfigFile();
  83. return Msg.wParam;
  84. }