rhodes 2.0.0.beta1 → 2.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/CHANGELOG +5 -0
  2. data/LICENSE +19 -674
  3. data/Manifest.txt +21 -4
  4. data/README.textile +5 -36
  5. data/Rakefile +5 -0
  6. data/lib/build/jake.rb +3 -1
  7. data/lib/extensions/rexml/rexml/document.rb +2 -0
  8. data/lib/extensions/rexml/rexml/parsers/baseparser.rb +0 -6
  9. data/lib/extensions/rhoxml/rexml/child.rb +96 -0
  10. data/lib/extensions/rhoxml/rexml/document.rb +527 -0
  11. data/lib/extensions/rhoxml/rexml/element.rb +987 -0
  12. data/lib/extensions/rhoxml/rexml/encoding.rb +71 -0
  13. data/lib/extensions/rhoxml/rexml/encodings/US-ASCII.rb +30 -0
  14. data/lib/extensions/rhoxml/rexml/encodings/UTF-16.rb +35 -0
  15. data/lib/extensions/rhoxml/rexml/encodings/UTF-8.rb +18 -0
  16. data/lib/extensions/rhoxml/rexml/namespace.rb +47 -0
  17. data/lib/extensions/rhoxml/rexml/node.rb +76 -0
  18. data/lib/extensions/rhoxml/rexml/parent.rb +166 -0
  19. data/lib/extensions/rhoxml/rexml/parseexception.rb +51 -0
  20. data/lib/extensions/rhoxml/rexml/parsers/baseparser.rb +531 -0
  21. data/lib/extensions/rhoxml/rexml/parsers/treeparser.rb +100 -0
  22. data/lib/extensions/rhoxml/rexml/parsers/xpathparser.rb +698 -0
  23. data/lib/extensions/rhoxml/rexml/set.rb +1274 -0
  24. data/lib/extensions/rhoxml/rexml/source.rb +258 -0
  25. data/lib/extensions/rhoxml/rexml/xmltokens.rb +18 -0
  26. data/lib/extensions/rhoxml/rexml/xpath.rb +77 -0
  27. data/lib/extensions/rhoxml/rexml/xpath_parser.rb +806 -0
  28. data/lib/framework/builtinME.rb +2 -0
  29. data/lib/framework/dateME.rb +5 -1
  30. data/lib/framework/rho/render.rb +10 -2
  31. data/lib/framework/rhom/rhom_object_factory.rb +2 -1
  32. data/lib/framework/singleton.rb +1 -1
  33. data/platform/android/Rhodes/jni/src/rhodes.cpp +2 -4
  34. data/platform/android/Rhodes/src/com/rhomobile/rhodes/NativeBar.java +23 -18
  35. data/platform/android/Rhodes/src/com/rhomobile/rhodes/Rhodes.java +42 -69
  36. data/platform/android/Rhodes/src/com/rhomobile/rhodes/SplashScreen.java +59 -7
  37. data/platform/android/Rhodes/src/com/rhomobile/rhodes/camera/Camera.java +1 -1
  38. data/platform/android/Rhodes/src/com/rhomobile/rhodes/mapview/Annotation.java +1 -0
  39. data/platform/android/Rhodes/src/com/rhomobile/rhodes/mapview/MapView.java +97 -85
  40. data/platform/android/Rhodes/src/com/rhomobile/rhodes/uri/SmsUriHandler.java +52 -0
  41. data/platform/android/build/RhodesSRC_build.files +1 -0
  42. data/platform/android/build/android.rake +38 -14
  43. data/platform/bb/RubyVM/RubyVM.jdp +1 -0
  44. data/platform/bb/build/RubyVM_build.files +1 -0
  45. data/platform/bb/build/bb.rake +44 -2
  46. data/platform/bb/rhodes/platform/5.0/com/rho/BrowserAdapter5.java +1 -1
  47. data/platform/bb/rhodes/rhodes.jdp +4 -4
  48. data/platform/bb/rhodes/src/com/rho/BrowserAdapter.java +8 -4
  49. data/platform/bb/rhodes/src/com/rho/rubyext/Alert.java +149 -17
  50. data/platform/bb/rhodes/src/rhomobile/PushListeningThread.java +20 -17
  51. data/platform/bb/rhodes/src/rhomobile/RhodesApplication.java +54 -28
  52. data/platform/bb/rhodes/src/rhomobile/mapview/Annotation.java +1 -0
  53. data/platform/bb/rhodes/src/rhomobile/mapview/GoogleMapField.java +37 -11
  54. data/platform/bb/rhodes/src/rhomobile/mapview/MapView.java +49 -19
  55. data/platform/bb/rhodes/src/rhomobile/mapview/MapViewScreen.java +6 -0
  56. data/platform/iphone/Classes/MapView/GoogleGeocoder.h +6 -7
  57. data/platform/iphone/Classes/MapView/GoogleGeocoder.m +70 -70
  58. data/platform/iphone/Classes/MapView/MapAnnotation.h +5 -3
  59. data/platform/iphone/Classes/MapView/MapAnnotation.m +10 -8
  60. data/platform/iphone/Classes/MapView/MapViewController.h +13 -10
  61. data/platform/iphone/Classes/MapView/MapViewController.m +131 -72
  62. data/platform/iphone/Classes/Rhodes.h +2 -0
  63. data/platform/iphone/Classes/Rhodes.m +13 -1
  64. data/platform/iphone/Classes/SimpleMainView.m +0 -1
  65. data/platform/iphone/Classes/TabbedMainView.m +5 -6
  66. data/platform/shared/common/RhoTime.h +2 -2
  67. data/platform/shared/common/RhodesApp.cpp +1 -1
  68. data/platform/shared/db/DBAdapter.cpp +6 -0
  69. data/platform/shared/net/CURLNetRequest.cpp +23 -1
  70. data/platform/shared/ruby/thread_win32.c +9 -1
  71. data/platform/shared/rubyJVM/src/com/rho/Capabilities.java +6 -0
  72. data/platform/shared/rubyJVM/src/com/rho/RhodesApp.java +1 -1
  73. data/platform/shared/rubyJVM/src/com/rho/sync/ClientRegister.java +1 -1
  74. data/platform/shared/rubyJVM/src/com/xruby/GeneratedMethods/RubySymbol_Methods.java +6 -1
  75. data/platform/shared/rubyJVM/src/com/xruby/GeneratedMethods/RubyTime_Methods.java +3 -3
  76. data/platform/shared/rubyJVM/src/com/xruby/runtime/builtin/InputStreamExecutor.java +1 -1
  77. data/platform/shared/rubyJVM/src/com/xruby/runtime/builtin/RubyArray.java +15 -3
  78. data/platform/shared/rubyJVM/src/com/xruby/runtime/builtin/RubyString.java +10 -2
  79. data/platform/shared/rubyJVM/src/com/xruby/runtime/builtin/RubyTime.java +12 -1
  80. data/platform/shared/rubyJVM/src/com/xruby/runtime/lang/RubyKernelModule.java +18 -9
  81. data/platform/shared/rubyJVM/src/com/xruby/runtime/lang/RubySymbol.java +5 -0
  82. data/platform/shared/rubyJVM/src/org/json/me/JSONArray.java +2 -1
  83. data/platform/shared/unzip/unzip.cpp +1 -1
  84. data/platform/wm/build/wm.rake +27 -6
  85. data/platform/wm/rhodes/Alert.cpp +335 -5
  86. data/platform/wm/rhodes/Alert.h +84 -1
  87. data/platform/wm/rhodes/MainWindow.cpp +28 -6
  88. data/platform/wm/rhodes/MainWindow.h +7 -2
  89. data/platform/wm/rhodes/Rhodes.cpp +23 -0
  90. data/platform/wm/rhodes/rho/rubyext/SystemImpl.cpp +2 -1
  91. data/platform/wm/rhodes/stdafx.h +1 -0
  92. data/platform/wm/tools/detool/detool.cpp +405 -14
  93. data/rakefile.rb +5 -0
  94. data/res/build-tools/detool.exe +0 -0
  95. data/res/generators/rhogen.rb +2 -0
  96. data/rhodes.gemspec +1 -1
  97. data/spec/framework_spec/app/spec/fixtures/object_values.txt +1 -1
  98. data/spec/framework_spec/app/spec/pagination/fixtures/object_values.txt +1 -1
  99. data/spec/framework_spec/app/spec/rhom_object_spec.rb +12 -12
  100. metadata +23 -6
  101. data/LICENSING_OPTIONS +0 -1
  102. data/platform/bb/build/rhodesApp.rapc +0 -9
  103. data/res/generators/templates/source/source_adapter.rb +0 -48
  104. data/rhobuild.yml +0 -37
@@ -7,10 +7,93 @@
7
7
  using namespace rho;
8
8
  using namespace rho::common;
9
9
 
10
+ #define ID_ALERT_DLG_BUTTON_MAX (8)
11
+ #define ID_ALERT_DLG_BUTTON_FIRST (1)
12
+ #define ID_ALERT_DLG_BUTTON_LAST (ID_ALERT_DLG_BUTTON_FIRST + (ID_ALERT_DLG_BUTTON_MAX) - 1)
13
+
14
+ class CAlertDialog : public CIndirectDialogImpl<CAlertDialog, CMemDlgTemplate>
15
+ {
16
+ public:
17
+ /**
18
+ * Params is a container to pass parameters to UI thread.
19
+ */
20
+ class Params {
21
+ public:
22
+ enum {DLG_DEFAULT, DLG_CUSTOM};
23
+
24
+ Params (String &message)
25
+ {
26
+ m_dlgType = DLG_DEFAULT;
27
+ m_message = message;
28
+ }
29
+
30
+ Params (String &title, String &message, String &icon, String &callback, Hashtable<String, String> &buttons)
31
+ {
32
+ m_dlgType = DLG_CUSTOM;
33
+ m_title = title;
34
+ m_message = message;
35
+ m_icon = icon;
36
+ m_callback = callback;
37
+ m_buttons = buttons;
38
+ }
39
+
40
+ int m_dlgType;
41
+ String m_title;
42
+ String m_message;
43
+ String m_icon;
44
+ String m_callback;
45
+ Hashtable<String, String> m_buttons;
46
+ };
47
+
48
+ class CustomButton : public CButton {
49
+ public:
50
+ CustomButton () {}
51
+
52
+ CustomButton (String title, String strId, int numId)
53
+ {
54
+ m_title = title;
55
+ m_strId = strId;
56
+ m_numId = numId;
57
+ }
58
+ public:
59
+ String m_title;
60
+ String m_strId;
61
+ int m_numId;
62
+ };
63
+
64
+ public:
65
+ BEGIN_MSG_MAP(CAlertDialog)
66
+ MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
67
+ COMMAND_RANGE_HANDLER(ID_ALERT_DLG_BUTTON_FIRST, ID_ALERT_DLG_BUTTON_LAST, OnAlertDialogButton)
68
+ END_MSG_MAP()
69
+
70
+ CAlertDialog(Params *msg);
71
+ ~CAlertDialog();
72
+
73
+ void DoInitTemplate();
74
+ void DoInitControls();
75
+
76
+ bool findButton(int id, CustomButton &button);
77
+
78
+ public:
79
+ LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL&bHandled);
80
+ LRESULT OnAlertDialogButton (WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
81
+
82
+ private:
83
+ String m_title;
84
+ String m_message;
85
+ String m_callback;
86
+ String m_icon;
87
+
88
+ CStatic m_messageCtrl;
89
+ CStatic m_iconCtrl;
90
+ Vector<CustomButton> m_buttons;
91
+ };
92
+
10
93
  class CAlert {
11
94
  DEFINE_LOGCLASS;
12
95
  public:
13
- static void showPopup(String message);
96
+ static void showPopup(CAlertDialog::Params *params);
14
97
  static void vibrate();
15
98
  static void playFile(String fileName);
16
99
  };
@@ -25,6 +25,7 @@
25
25
  #include "sync/SyncThread.h"
26
26
  #include "common/RhoFilePath.h"
27
27
 
28
+
28
29
  #include <hash_map>
29
30
 
30
31
  IMPLEMENT_LOGCLASS(CMainWindow,"MainWindow");
@@ -430,7 +431,7 @@ LRESULT CMainWindow::OnTakePicture(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lPar
430
431
 
431
432
  RHODESAPP().callCameraCallback( (const char*)lParam, rho::common::convertToStringA(image_uri),
432
433
  (status!= S_OK && status != S_FALSE ? "Error" : ""), status == S_FALSE);
433
-
434
+
434
435
  free ((void *)lParam);
435
436
  #endif
436
437
  return 0;
@@ -478,16 +479,37 @@ LRESULT CMainWindow::OnSelectPicture(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lP
478
479
 
479
480
  LRESULT CMainWindow::OnAlertShowPopup (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/)
480
481
  {
482
+ LOG(INFO) + __FUNCTION__;
481
483
  StringW strAppName = getRhodesAppName();
484
+ CAlertDialog::Params *params = (CAlertDialog::Params *)lParam;
485
+
486
+ if (params->m_dlgType == CAlertDialog::Params::DLG_DEFAULT) {
487
+ MessageBox(convertToStringW(params->m_message).c_str(), strAppName.c_str(), MB_ICONWARNING | MB_OK);
488
+ } else if (params->m_dlgType == CAlertDialog::Params::DLG_CUSTOM) {
489
+ if (m_alertDialog == NULL) {
490
+ m_alertDialog = new CAlertDialog(params);
491
+ m_alertDialog->DoModal();
492
+ delete m_alertDialog;
493
+ m_alertDialog = NULL;
494
+ } else {
495
+ LOG(WARNING) + "Trying to show alert dialog while it exists.";
496
+ }
497
+ }
482
498
 
483
- USES_CONVERSION;
484
- MessageBox(A2T((const char*)lParam),
485
- strAppName.c_str(),
486
- MB_ICONWARNING | MB_OK);
487
- free ((void *)lParam);
499
+ delete params;
488
500
  return 0;
489
501
  }
490
502
 
503
+ LRESULT CMainWindow::OnAlertHidePopup (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/)
504
+ {
505
+ if (m_alertDialog != NULL) {
506
+ m_alertDialog->EndDialog(0);
507
+ m_alertDialog = NULL;
508
+ }
509
+
510
+ return 0;
511
+ }
512
+
491
513
  LRESULT CMainWindow::OnDateTimePicker (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/)
492
514
  {
493
515
  CDateTimeMessage *msg = (CDateTimeMessage *)lParam;
@@ -10,6 +10,7 @@
10
10
  #include "logging/RhoLog.h"
11
11
  #include "common/RhoConf.h"
12
12
  #include "common/RhodesApp.h"
13
+ #include "Alert.h"
13
14
 
14
15
  #if defined(OS_WINDOWS)
15
16
  #include "menubar.h"
@@ -24,7 +25,8 @@ static const UINT ID_BROWSER = 1;
24
25
  static UINT WM_TAKEPICTURE = ::RegisterWindowMessage(L"RHODES_WM_TAKEPICTURE");
25
26
  static UINT WM_SELECTPICTURE = ::RegisterWindowMessage(L"RHODES_WM_SELECTPICTURE");
26
27
  static UINT WM_CONNECTIONSNETWORKCOUNT = ::RegisterWindowMessage(L"RHODES_WM_CONNECTIONSNETWORKCOUNT");
27
- static UINT WM_ALERT_SHOWPOPUP = ::RegisterWindowMessage(L"RHODES_WM_ALERT_SHOWPOPUP");
28
+ static UINT WM_ALERT_SHOW_POPUP = ::RegisterWindowMessage(L"RHODES_WM_ALERT_SHOW_POPUP");
29
+ static UINT WM_ALERT_HIDE_POPUP = ::RegisterWindowMessage(L"RHODES_WM_ALERT_HIDE_POPUP");
28
30
  static UINT WM_DATETIME_PICKER = ::RegisterWindowMessage(L"RHODES_WM_DATETIME_PICKER");
29
31
 
30
32
 
@@ -87,7 +89,8 @@ public:
87
89
  MESSAGE_HANDLER(WM_TAKEPICTURE, OnTakePicture)
88
90
  MESSAGE_HANDLER(WM_SELECTPICTURE, OnSelectPicture)
89
91
  MESSAGE_HANDLER(WM_CONNECTIONSNETWORKCOUNT, OnConnectionsNetworkCount)
90
- MESSAGE_HANDLER(WM_ALERT_SHOWPOPUP, OnAlertShowPopup);
92
+ MESSAGE_HANDLER(WM_ALERT_SHOW_POPUP, OnAlertShowPopup)
93
+ MESSAGE_HANDLER(WM_ALERT_HIDE_POPUP, OnAlertHidePopup);
91
94
  MESSAGE_HANDLER(WM_DATETIME_PICKER, OnDateTimePicker);
92
95
  END_MSG_MAP()
93
96
 
@@ -118,6 +121,7 @@ private:
118
121
  LRESULT OnSelectPicture(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/);
119
122
  LRESULT OnConnectionsNetworkCount(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/);
120
123
  LRESULT OnAlertShowPopup (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/);
124
+ LRESULT OnAlertHidePopup (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/);
121
125
  LRESULT OnDateTimePicker (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/);
122
126
 
123
127
  public:
@@ -188,4 +192,5 @@ private:
188
192
  int m_pageCounter;
189
193
 
190
194
  rho::Vector<rho::common::CAppMenuItem> m_arAppMenuItems;
195
+ CAlertDialog *m_alertDialog;
191
196
  };
@@ -117,6 +117,29 @@ public :
117
117
 
118
118
  ::SetThreadPriority(GetCurrentThread(),10);
119
119
 
120
+ //Check for bundle directory is exists.
121
+ HANDLE hFind;
122
+ WIN32_FIND_DATA wfd;
123
+ hFind = FindFirstFile(convertToStringW(m_strRootPath.substr(0, m_strRootPath.find_last_of('/'))).c_str(), &wfd);
124
+
125
+ if (INVALID_HANDLE_VALUE == hFind || !(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
126
+ LOG(INFO) + "Bundle directory is missing\n";
127
+
128
+ int last = 0, pre_last = 0;
129
+ last = getRhoRootPath().find_last_of('\\');
130
+ pre_last = getRhoRootPath().substr(0, last).find_last_of('\\');
131
+ String appName = getRhoRootPath().substr(pre_last + 1, last - pre_last - 1);
132
+
133
+ int msgboxID = MessageBox(NULL,
134
+ _T("Bundle directory is missing."),
135
+ convertToStringW(appName).c_str(),
136
+ MB_ICONERROR | MB_OK);
137
+
138
+
139
+ return S_FALSE;
140
+ }
141
+
142
+
120
143
  // Create the main application window
121
144
  m_appWindow.Create(NULL, CWindow::rcDefault, TEXT("Rhodes"), WS_VISIBLE);
122
145
  if (NULL == m_appWindow.m_hWnd)
@@ -305,7 +305,8 @@ int rho_sysimpl_get_property(char* szPropName, VALUE* resValue)
305
305
  if (!GetVersionEx(&osv))
306
306
  return 0;
307
307
  char buf[50];
308
- snprintf(buf, sizeof(buf), "%u.%u.%u", (unsigned)osv.dwMajorVersion,
308
+ buf[sizeof(buf) - 1] = '\0';
309
+ snprintf(buf, sizeof(buf) - 1, "%u.%u.%u", (unsigned)osv.dwMajorVersion,
309
310
  (unsigned)osv.dwMinorVersion, (unsigned)osv.dwBuildNumber);
310
311
  *resValue = rho_ruby_create_string(&buf[0]);
311
312
  return 1;
@@ -89,6 +89,7 @@
89
89
  #include <atlframe.h>
90
90
  #include <atlmisc.h>
91
91
  #include <atlctrls.h>
92
+ #include <atldlgs.h>
92
93
  #define _WTL_CE_NO_ZOOMSCROLL
93
94
  #include <atlwince.h>
94
95
 
@@ -212,6 +212,7 @@ void wceDisconnect(void)
212
212
 
213
213
  #define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
214
214
 
215
+
215
216
  bool wcePutFile(const char *host_file, const char *wce_file)
216
217
  {
217
218
  TCHAR tszSrcFile[MAX_PATH];
@@ -299,6 +300,7 @@ bool wcePutFile(const char *host_file, const char *wce_file)
299
300
  _tprintf( TEXT("."));
300
301
  } while (dwNumRead);
301
302
  //_tprintf( TEXT("\n"));
303
+
302
304
  CeCloseHandle( hDest);
303
305
  CloseHandle (hSrc);
304
306
  }
@@ -338,7 +340,6 @@ bool wceRunProcess(const char *process, const char *args)
338
340
  _tprintf( TEXT("CreateProcess failed with Errorcode = %ld\n"), CeGetLastError());
339
341
  return false;
340
342
  }
341
- WaitForSingleObject(pi.hProcess, INFINITE);
342
343
  CeCloseHandle( pi.hProcess);
343
344
  CeCloseHandle( pi.hThread);
344
345
  }
@@ -381,47 +382,356 @@ bool wceInvokeCabSetup(const char *wceload_params)
381
382
  //#define EMU "USA Windows Mobile 6.5 Professional Portrait QVGA Emulator"
382
383
 
383
384
  /**
384
- * detool emu "<emu_name|vmid>" app.cab "app-name"
385
+ * detool emu "<emu_name|vmid>" "app-name" rhobundle_path exe_name
386
+ * or
387
+ * detool emucab "<emu_name|vmid>" app.cab "app-name"
385
388
  * or
386
- * detool dev app.cab "app-name"
389
+ detool dev "app-name" rhobundle_path exe_name
390
+ or
391
+ * detool devcab app.cab "app-name"
387
392
  */
388
393
  void usage(void)
389
394
  {
390
395
  printf
391
- ("Rhodes deployment tool for Windows Mobile: \n \
396
+ ("Rhodes deployment tool for Windows Mobile: \n \
392
397
  detool emu \"<emu_name|vmid>\" app.cab \"app-name\" \n \
393
- or \n \
394
- detool dev app.cab \"app-name\" \n"
398
+ or \n \
399
+ detool dev app.cab \"app-name\" \n"
395
400
  );
396
401
  }
397
402
  enum {
403
+ DEPLOY_EMUCAB,
404
+ DEPLOY_DEVCAB,
398
405
  DEPLOY_EMU,
399
406
  DEPLOY_DEV
400
407
  };
401
408
 
409
+ int copyExecutable (TCHAR *file_name, TCHAR *app_dir)
410
+ {
411
+ TCHAR exe_fullpath[MAX_PATH];
412
+ int retval = 0;
413
+ HANDLE hDest, hSrc;
414
+ BYTE buffer[5120];
415
+ DWORD dwNumRead, dwNumWritten;
416
+
417
+ USES_CONVERSION;
418
+
419
+ _tcscpy(exe_fullpath, app_dir);
420
+ _tcscat(exe_fullpath, _T("\\"));
421
+ _tcscat(exe_fullpath, _T("rhodes.exe"));
422
+
423
+
424
+ hSrc = CreateFile(file_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
425
+ if (INVALID_HANDLE_VALUE == hSrc) {
426
+ _tprintf( TEXT("Unable to open host file\n"));
427
+ return EXIT_FAILURE;
428
+ }
429
+
430
+ hDest = CeCreateFile(exe_fullpath, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
431
+ if (INVALID_HANDLE_VALUE == hDest ) {
432
+ _tprintf( TEXT("Unable to open target WinCE file\n"));
433
+ return CeGetLastError();
434
+ }
435
+
436
+ do {
437
+ if(ReadFile(hSrc, &buffer, sizeof(buffer), &dwNumRead, NULL)) {
438
+ if (!CeWriteFile(hDest, &buffer, dwNumRead, &dwNumWritten, NULL)) {
439
+ _tprintf( TEXT("Error !!! Writing WinCE file\n"));
440
+ goto copyFailure;
441
+ }
442
+ } else {
443
+ _tprintf( TEXT("Error !!! Reading host file\n"));
444
+ goto copyFailure;
445
+ }
446
+ _tprintf( TEXT("."));
447
+ } while (dwNumRead);
448
+ _tprintf( TEXT("\n"));
449
+
450
+ CeCloseHandle( hDest);
451
+ CloseHandle (hSrc);
452
+
453
+ return EXIT_SUCCESS;
454
+
455
+ copyFailure:
456
+ CeCloseHandle( hDest);
457
+ CloseHandle (hSrc);
458
+ /*
459
+
460
+ if (wcePutFile (T2A(file_name), T2A(exe_fullpath)))
461
+ return EXIT_SUCCESS;
462
+ */
463
+ return EXIT_FAILURE;
464
+ }
465
+
466
+ int copyBundle (TCHAR *parent_dir, TCHAR *file, TCHAR *app_dir)
467
+ {
468
+ HANDLE fileHandle;
469
+ WIN32_FIND_DATAW findData;
470
+ DWORD dwError;
471
+ TCHAR new_app_item[MAX_PATH];
472
+ TCHAR host_file[MAX_PATH];
473
+ HANDLE hFind;
474
+ CE_FIND_DATA wceFindData;
475
+
476
+ USES_CONVERSION;
477
+
478
+ TCHAR wildcard[MAX_PATH + 16];
479
+ TCHAR fullpath[MAX_PATH];
480
+
481
+ _tcscpy(fullpath, parent_dir);
482
+ _tcscat(fullpath, _T("\\"));
483
+ _tcscat(fullpath, file);
484
+
485
+ //TODO: check for fullpath is a dir
486
+
487
+ _tcscpy(wildcard, fullpath);
488
+ _tcscat(wildcard, _T("\\*.*"));
489
+
490
+ //wceConnect ();
491
+
492
+ fileHandle = FindFirstFile(wildcard, &findData);
493
+
494
+ if (fileHandle == INVALID_HANDLE_VALUE) {
495
+ printf ("Failed to open file\n");
496
+ wceDisconnect();
497
+ return EXIT_FAILURE;
498
+ }
499
+
500
+ /*
501
+ if (_tcscmp (_T("."), findData.cFileName) != 0 && _tcscmp (_T(".."), findData.cFileName) != 0) {
502
+ printf("-- %s\n", T2A(findData.cFileName));
503
+ if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
504
+ copyBundle (fullpath, findData.cFileName, NULL);
505
+ }
506
+ }
507
+ */
508
+
509
+ HANDLE hDest, hSrc;
510
+ BYTE buffer[5120];
511
+ DWORD dwNumRead, dwNumWritten;
512
+
513
+ while (FindNextFile(fileHandle, &findData)) {
514
+ if (_tcscmp (_T("."), findData.cFileName) == 0 || _tcscmp (_T(".."), findData.cFileName) == 0)
515
+ continue;
516
+
517
+ _tcscpy(new_app_item, app_dir);
518
+ _tcscat(new_app_item, _T("\\"));
519
+ _tcscat(new_app_item, findData.cFileName);
520
+
521
+ if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
522
+ {
523
+ //Check and create dir on device
524
+ hFind = CeFindFirstFile(new_app_item, &wceFindData);
525
+ if (INVALID_HANDLE_VALUE == hFind) {
526
+ if (!CeCreateDirectory(new_app_item, NULL)) {
527
+ _tprintf( TEXT("Create directory \"%s\" on device\n"), new_app_item);
528
+ printf ("Failed to create new directory on device\n");
529
+ return EXIT_FAILURE;
530
+ }
531
+ }
532
+ FindClose( hFind);
533
+
534
+ copyBundle (fullpath, findData.cFileName, new_app_item);
535
+ }
536
+ else
537
+ {
538
+ _tcscpy(host_file, fullpath);
539
+ _tcscat(host_file, _T("\\"));
540
+ _tcscat(host_file, findData.cFileName);
541
+
542
+ _tprintf( TEXT("Copy file \"%s\" to device"), new_app_item);
543
+
544
+ hSrc = CreateFile(host_file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
545
+ if (INVALID_HANDLE_VALUE == hSrc) {
546
+ _tprintf( TEXT("Unable to open host file\n"));
547
+ return false;
548
+ }
549
+
550
+ hDest = CeCreateFile(new_app_item, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
551
+ if (INVALID_HANDLE_VALUE == hDest ) {
552
+ _tprintf( TEXT("Unable to open target WinCE file\n"));
553
+ return false;
554
+ }
555
+
556
+ do {
557
+ if(ReadFile(hSrc, &buffer, sizeof(buffer), &dwNumRead, NULL)) {
558
+ if (!CeWriteFile(hDest, &buffer, dwNumRead, &dwNumWritten, NULL)) {
559
+ _tprintf( TEXT("Error !!! Writing WinCE file\n"));
560
+ goto copyBundleFailure;
561
+ }
562
+ } else {
563
+ _tprintf( TEXT("Error !!! Reading host file\n"));
564
+ goto copyBundleFailure;
565
+ }
566
+ _tprintf( TEXT("."));
567
+ } while (dwNumRead);
568
+ _tprintf( TEXT("\n"));
569
+
570
+ CeCloseHandle( hDest);
571
+ CloseHandle (hSrc);
572
+ /*
573
+ if(!wcePutFile (T2A(host_file), T2A(new_app_item))) {
574
+ printf("Failed to copy file.");
575
+ return EXIT_FAILURE;
576
+ }
577
+ */
578
+ }
579
+
580
+ }
581
+
582
+ return EXIT_SUCCESS;
583
+
584
+ copyBundleFailure:
585
+ CeCloseHandle( hDest);
586
+ CloseHandle (hSrc);
587
+ return EXIT_FAILURE;
588
+ }
589
+
402
590
  int _tmain(int argc, _TCHAR* argv[])
403
591
  {
404
592
  TCHAR *emu_name = NULL;
405
593
  TCHAR *cab_file = NULL;
406
594
  TCHAR *app_name = NULL;
595
+ TCHAR *bundle_path = NULL;
596
+ TCHAR *app_exe = NULL;
407
597
  TCHAR params_buf[MAX_PATH + 16];
598
+ WIN32_FIND_DATAW findData;
599
+ int new_copy = 0;
408
600
  int deploy_type;
409
601
 
410
- if (argc == 5) { //assuming that need to start emulator
411
- emu_name = argv[2];
412
- cab_file = argv[3];
413
- app_name = argv[4];
414
- deploy_type = DEPLOY_EMU;
602
+ USES_CONVERSION;
603
+
604
+ if (argc >= 5) { //assuming that need to start emulator
605
+ if (strcmp(T2A(argv[1]), "emu") == 0) {
606
+ emu_name = argv[2];
607
+ app_name = argv[3];
608
+ bundle_path = argv[4];
609
+ app_exe = argv[5];
610
+ deploy_type = DEPLOY_EMU;
611
+ }
612
+ if (strcmp(T2A(argv[1]), "emucab") == 0) {
613
+ emu_name = argv[2];
614
+ cab_file = argv[3];
615
+ app_name = argv[4];
616
+ deploy_type = DEPLOY_EMUCAB;
617
+ }
618
+
619
+ if (strcmp(T2A(argv[1]), "dev") == 0) {
620
+ app_name = argv[2];
621
+ bundle_path = argv[3];
622
+ app_exe = argv[4];
623
+ deploy_type = DEPLOY_DEV;
624
+ }
415
625
  } else if (argc == 4) { //assuming that need to deploy and start on device
416
626
  cab_file = argv[2];
417
627
  app_name = argv[3];
418
- deploy_type = DEPLOY_DEV;
628
+ deploy_type = DEPLOY_DEVCAB;
419
629
  } else {
420
630
  usage();
421
631
  return EXIT_FAILURE;
422
632
  }
423
633
 
634
+ TCHAR app_dir[MAX_PATH];
635
+ _tcscpy(app_dir, TEXT("\\Program Files\\"));
636
+ _tcscat(app_dir, app_name);
637
+ _tprintf( TEXT("%s\n"), app_dir);
638
+
424
639
  if (deploy_type == DEPLOY_EMU) {
640
+ if (SUCCEEDED(CoInitializeEx(NULL, COINIT_MULTITHREADED))) {
641
+ HANDLE hFind;
642
+ CE_FIND_DATA findData;
643
+
644
+ CreateThread(NULL, 0, startDEM, NULL, 0, NULL);
645
+
646
+ _tprintf( TEXT("Starting emulator... "));
647
+ if (!emuConnect (emu_name)) {
648
+ _tprintf( TEXT("FAILED\n"));
649
+ goto stop_emu_deploy;
650
+ }
651
+ _tprintf( TEXT("DONE\n"));
652
+
653
+ _tprintf( TEXT("Cradle emulator... "));
654
+ if(!emuCradle (emu_name)) {
655
+ _tprintf( TEXT("FAILED\n"));
656
+ goto stop_emu_deploy;
657
+ }
658
+ _tprintf( TEXT("DONE\n"));
659
+
660
+ if (!wceConnect ()) {
661
+ printf ("Failed to connect to remote device.\n");
662
+ goto stop_emu_deploy;
663
+ } else {
664
+
665
+ hFind = CeFindFirstFile(app_dir, &findData);
666
+ if (INVALID_HANDLE_VALUE == hFind) {
667
+ _tprintf( TEXT("Application directory on device was no found\n"));
668
+
669
+ new_copy = 1;
670
+
671
+ if (!CeCreateDirectory(app_dir, NULL)) {
672
+ printf ("Failed to create app directory\n");
673
+ goto stop_emu_deploy;
674
+ }
675
+ }
676
+ FindClose( hFind);
677
+
678
+ if (!findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
679
+ _tprintf( TEXT("Error: target directory is file\n"));
680
+ goto stop_emu_deploy;
681
+ }
682
+
683
+
684
+ TCHAR remote_bundle_path[MAX_PATH];
685
+
686
+ _tcscpy(remote_bundle_path, app_dir);
687
+ _tcscat(remote_bundle_path, _T("\\rho"));
688
+
689
+ hFind = CeFindFirstFile(remote_bundle_path, &findData);
690
+ if (INVALID_HANDLE_VALUE == hFind) {
691
+ _tprintf( TEXT("Bundle directory on device was no found\n"));
692
+
693
+ if (!CeCreateDirectory(remote_bundle_path, NULL)) {
694
+ printf ("Failed to create bundle directory\n");
695
+ goto stop_emu_deploy;
696
+ }
697
+ }
698
+ FindClose( hFind);
699
+
700
+ int retval = copyExecutable (app_exe, app_dir);
701
+ if (retval != EXIT_SUCCESS) {
702
+ printf ("Failed to copy application executable\n");
703
+ if (retval == 32) {
704
+ printf ("Please, stop application on device and try again.\n");
705
+ }
706
+ goto stop_emu_deploy;
707
+ }
708
+
709
+ if (copyBundle(bundle_path, _T("/"), remote_bundle_path) == EXIT_FAILURE) {
710
+ printf ("Failed to copy bundle\n");
711
+ goto stop_emu_deploy;
712
+ }
713
+
714
+ emuBringToFront(emu_name);
715
+
716
+ _tprintf( TEXT("Starting application..."));
717
+ _tcscpy(params_buf, TEXT("\\Program Files\\"));
718
+ _tcscat(params_buf, app_name);
719
+ _tcscat(params_buf, TEXT("\\rhodes.exe"));
720
+ if(!wceRunProcess(T2A(params_buf), NULL)) {
721
+ _tprintf( TEXT("FAILED\n"));
722
+ goto stop_emu_deploy;
723
+ }
724
+ _tprintf( TEXT("DONE\n"));
725
+
726
+ wceDisconnect();
727
+ }
728
+
729
+ CoUninitialize();
730
+
731
+ ExitProcess(EXIT_SUCCESS);
732
+ }
733
+ }
734
+ if (deploy_type == DEPLOY_EMUCAB) {
425
735
  if (SUCCEEDED(CoInitializeEx(NULL, COINIT_MULTITHREADED))) {
426
736
  CreateThread(NULL, 0, startDEM, NULL, 0, NULL);
427
737
 
@@ -440,7 +750,6 @@ int _tmain(int argc, _TCHAR* argv[])
440
750
  _tprintf( TEXT("DONE\n"));
441
751
 
442
752
  _tprintf( TEXT("Loading cab file..."));
443
- USES_CONVERSION;
444
753
  if (!wcePutFile (T2A(cab_file), "")) {
445
754
  _tprintf( TEXT("FAILED\n"));
446
755
  goto stop_emu_deploy;
@@ -484,14 +793,96 @@ int _tmain(int argc, _TCHAR* argv[])
484
793
 
485
794
 
486
795
  CoUninitialize();
487
-
488
796
  ExitProcess(EXIT_SUCCESS);
489
797
  stop_emu_deploy:
798
+ CoUninitialize();
490
799
  ExitProcess(EXIT_FAILURE);
491
800
  }
492
801
  }
493
802
 
494
803
  if (deploy_type == DEPLOY_DEV) {
804
+ HANDLE hFind;
805
+ CE_FIND_DATA findData;
806
+
807
+ _tprintf( TEXT("Searching for Windows CE device..."));
808
+
809
+ HRESULT hRapiResult;
810
+ hRapiResult = CeRapiInit();
811
+ if (FAILED(hRapiResult)) {
812
+ _tprintf( TEXT("FAILED\n"));
813
+ return false;
814
+ }
815
+ _tprintf( TEXT("DONE\n"));
816
+
817
+ hFind = CeFindFirstFile(app_dir, &findData);
818
+ if (INVALID_HANDLE_VALUE == hFind) {
819
+ _tprintf( TEXT("Application directory on device was no found\n"));
820
+
821
+ new_copy = 1;
822
+
823
+ if (!CeCreateDirectory(app_dir, NULL)) {
824
+ printf ("Failed to create app directory\n");
825
+ goto stop_emu_deploy;
826
+ }
827
+ }
828
+ FindClose( hFind);
829
+
830
+ if (!findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
831
+ _tprintf( TEXT("Error: target directory is file\n"));
832
+ goto stop_emu_deploy;
833
+ }
834
+
835
+
836
+ TCHAR remote_bundle_path[MAX_PATH];
837
+
838
+ _tcscpy(remote_bundle_path, app_dir);
839
+ _tcscat(remote_bundle_path, _T("\\rho"));
840
+
841
+ hFind = CeFindFirstFile(remote_bundle_path, &findData);
842
+ if (INVALID_HANDLE_VALUE == hFind) {
843
+ _tprintf( TEXT("Bundle directory on device was no found\n"));
844
+
845
+ if (!CeCreateDirectory(remote_bundle_path, NULL)) {
846
+ printf ("Failed to create bundle directory\n");
847
+ goto stop_emu_deploy;
848
+ }
849
+ }
850
+ FindClose( hFind);
851
+
852
+
853
+ int retval = copyExecutable (app_exe, app_dir);
854
+ if (retval != EXIT_SUCCESS) {
855
+ printf ("Failed to copy application executable\n");
856
+ if (retval == 32) {
857
+ printf ("Please, stop application on device and try again.\n");
858
+ }
859
+ goto stop_emu_deploy;
860
+ }
861
+
862
+ if (copyBundle(bundle_path, _T("/"), remote_bundle_path) == EXIT_FAILURE) {
863
+ printf ("Failed to copy bundle\n");
864
+ goto stop_emu_deploy;
865
+ }
866
+
867
+ Sleep(2 * 1000);
868
+
869
+ _tprintf( TEXT("Starting application..."));
870
+ _tcscpy(params_buf, TEXT("\\Program Files\\"));
871
+ _tcscat(params_buf, app_name);
872
+ _tcscat(params_buf, TEXT("\\rhodes.exe"));
873
+ _tprintf( TEXT("%s\n"), params_buf);
874
+
875
+
876
+ if(!wceRunProcess(T2A(params_buf), NULL)) {
877
+ _tprintf( TEXT("FAILED\n"));
878
+ goto stop_emu_deploy;
879
+ }
880
+ _tprintf( TEXT("DONE\n"));
881
+
882
+ ExitProcess(EXIT_SUCCESS);
883
+ }
884
+
885
+ if (deploy_type == DEPLOY_DEVCAB) {
495
886
  _tprintf( TEXT("Searching for Windows CE device..."));
496
887
 
497
888
  HRESULT hRapiResult;