main.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "PolycodeWindowsPlayer.h"
  2. #include <Polycode.h>
  3. #include "PolycodePlayerView.h"
  4. #include "windows.h"
  5. #include "resource.h"
  6. using namespace Polycode;
  7. extern Win32Core *core;
  8. void wtoc(char* Dest, TCHAR* Source, int SourceSize)
  9. {
  10. for(int i = 0; i < SourceSize; ++i)
  11. Dest[i] = (char)Source[i];
  12. }
  13. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  14. {
  15. String args = String(GetCommandLineW());
  16. String fileName;
  17. for(int i=0; i < args.length(); i++) {
  18. if(args[i] != '\"')
  19. fileName += args.substr(i, 1);
  20. if(args[i] == '\"' && i != args.length()-1)
  21. fileName = "";
  22. }
  23. if(fileName == " ")
  24. fileName = "";
  25. if(fileName.length() > 1) {
  26. fileName = fileName.replace(":", "");
  27. fileName = fileName.replace("\\", "/");
  28. fileName = fileName.substr(1, fileName.length() - 1);
  29. }
  30. char path[2049];
  31. TCHAR tpath[2049];
  32. GetModuleFileName(NULL, (LPWSTR)tpath, 2048);
  33. wtoc(path, tpath, 2048);
  34. String basePath = path;
  35. vector<String> cpts = basePath.split("\\");
  36. String installPath = "";
  37. for(int i=0; i < cpts.size() - 1; i++) {
  38. installPath = installPath + cpts[i];
  39. installPath += String("\\");
  40. }
  41. SetCurrentDirectory(installPath.getWDataWithEncoding(String::ENCODING_UTF8));
  42. PolycodePlayerView *view = new PolycodePlayerView(true, hInstance, nCmdShow, L"");
  43. PolycodeWindowsPlayer *player = new PolycodeWindowsPlayer(view, "main.polyapp", false);
  44. player->addEventListener(view, PolycodeDebugEvent::EVENT_ERROR);
  45. player->addEventListener(view, PolycodeDebugEvent::EVENT_PRINT);
  46. player->runPlayer();
  47. core = (Win32Core*)player->getCore();
  48. MSG Msg;
  49. do {
  50. if(PeekMessage(&Msg, NULL, 0,0,PM_REMOVE)) {
  51. TranslateMessage(&Msg);
  52. DispatchMessage(&Msg);
  53. }
  54. } while(player->Update());
  55. return Msg.wParam;
  56. }