main.cpp 3.9 KB

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