main.cpp 4.1 KB

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