From b99ac66530f7cc44e481fe0d69958bd3a08a1d67 Mon Sep 17 00:00:00 2001 From: Scott Harrison Date: Wed, 1 Mar 2023 17:36:52 -0600 Subject: [PATCH 1/6] First Build --- .../Corona.Simulator/BuildAndroidDlg.cpp | 76 +++++-------------- .../Corona.Simulator/BuildAndroidDlg.h | 7 +- platform/windows/Corona.Simulator/Resource.h | 5 ++ .../windows/Corona.Simulator/Simulator.cpp | 3 + .../windows/Corona.Simulator/Simulator.rc | 10 ++- 5 files changed, 35 insertions(+), 66 deletions(-) mode change 100755 => 100644 platform/windows/Corona.Simulator/BuildAndroidDlg.cpp mode change 100755 => 100644 platform/windows/Corona.Simulator/Simulator.rc diff --git a/platform/windows/Corona.Simulator/BuildAndroidDlg.cpp b/platform/windows/Corona.Simulator/BuildAndroidDlg.cpp old mode 100755 new mode 100644 index 8fb8e020d..537b50d61 --- a/platform/windows/Corona.Simulator/BuildAndroidDlg.cpp +++ b/platform/windows/Corona.Simulator/BuildAndroidDlg.cpp @@ -67,9 +67,6 @@ BEGIN_MESSAGE_MAP(CBuildAndroidDlg, CDialog) ON_EN_KILLFOCUS(IDC_BUILD_KEYSTORE, &CBuildAndroidDlg::OnKillFocusKeystorePath) ON_CBN_SELCHANGE(IDC_BUILD_KEYALIAS, &CBuildAndroidDlg::OnChangeAliasList) ON_CBN_SETFOCUS(IDC_BUILD_KEYALIAS, &CBuildAndroidDlg::OnSetFocusAliasList) -#ifdef AUTO_INCLUDE_MONETIZATION_PLUGIN - ON_BN_CLICKED(IDC_ENABLE_MONETIZATION, &CBuildAndroidDlg::OnBnClickedEnableMonetization) -#endif ON_WM_HELPINFO() ON_WM_SYSCOMMAND() ON_BN_CLICKED(IDC_CREATE_LIVE_BUILD, &CBuildAndroidDlg::OnBnClickedCreateLiveBuild) @@ -250,32 +247,7 @@ BOOL CBuildAndroidDlg::OnInitDialog() // Set up the "Live Build" checkbox. CheckDlgButton(IDC_CREATE_LIVE_BUILD, m_pProject->GetCreateLiveBuild() ? BST_CHECKED : BST_UNCHECKED); -#ifdef AUTO_INCLUDE_MONETIZATION_PLUGIN - // Initialize the "Enable Monetization" checkbox - CButton *enableMonetizationBtn = (CButton *)GetDlgItem(IDC_ENABLE_MONETIZATION); - bool debugMonetizationPlugin = AfxGetApp()->GetProfileInt(REGISTRY_SECTION, REGISTRY_DEBUG_MONETIZATION_PLUGIN, - REGISTRY_DEBUG_MONETIZATION_PLUGIN_DEFAULT) ? true : false; - if (debugMonetizationPlugin) - { - // Load setting from project - enableMonetizationBtn->SetCheck((m_pProject->GetEnableMonetization() ? BST_CHECKED : BST_UNCHECKED)); - } - else - { - // Hide and disable "Enable Monetization" checkbox - enableMonetizationBtn->ShowWindow(SW_HIDE); - enableMonetizationBtn->SetCheck(BST_UNCHECKED); - m_pProject->SetEnableMonetization(false); - } - -#else - // Disable dialog control - CButton *enableMonetizationBtn = (CButton *)GetDlgItem(IDC_ENABLE_MONETIZATION); - enableMonetizationBtn->ShowWindow(SW_HIDE); - enableMonetizationBtn->SetCheck(BST_UNCHECKED); - -#endif // AUTO_INCLUDE_MONETIZATION_PLUGIN return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE @@ -932,36 +904,6 @@ UINT CBuildAndroidDlg::DisplayWarningMessageWithHelp(UINT nTitleID, UINT nMessag return ::MessageBoxIndirect(&mbp); } -#ifdef AUTO_INCLUDE_MONETIZATION_PLUGIN -// Called when the user changes the "Enable Monetization" checkbox -void CBuildAndroidDlg::OnBnClickedEnableMonetization() -{ - CButton *enableMonetizationBtn = (CButton *) GetDlgItem(IDC_ENABLE_MONETIZATION); - - // If they uncheck the box, ask them if they are sure - if (enableMonetizationBtn->GetCheck() == BST_UNCHECKED) - { - CString title; - CString message; - DWORD answer = IDNO; - - title.LoadString(IDS_ENABLE_MONETIZATION); - message.LoadString(IDS_MONETIZATION_WARNING); - //answer = MessageBox(message, title, MB_YESNO | MB_ICONWARNING | MB_HELP); - answer = DisplayWarningMessageWithHelp(IDS_ENABLE_MONETIZATION, IDS_MONETIZATION_WARNING, L"https://fusepowered.com/corona"); - - // The dialog asks whether they really want to disable monetization so - // if they answer "No" we need to re-check the checkbox - if (answer == IDNO) - { - enableMonetizationBtn->SetCheck(BST_CHECKED); - } - } - - m_pProject->SetEnableMonetization((enableMonetizationBtn->GetCheck() == BST_CHECKED)); -} -#endif // AUTO_INCLUDE_MONETIZATION_PLUGIN - void CBuildAndroidDlg::OnBnClickedCreateLiveBuild() @@ -992,6 +934,24 @@ void CBuildAndroidDlg::OnBnClickedCreateLiveBuild() } } +void CBuildAndroidDlg::OnRadioClickedCopyToDevice() +{ + + +} + +void CBuildAndroidDlg::OnRadioClickedShowInFiles() +{ + + +} + +void CBuildAndroidDlg::OnRadioClickedDoNothing() +{ + + +} + void CBuildAndroidDlg::LogAnalytics(const char *eventName, const char *key, const char *value) { Rtt_ASSERT(GetWinProperties()->GetAnalytics() != NULL); diff --git a/platform/windows/Corona.Simulator/BuildAndroidDlg.h b/platform/windows/Corona.Simulator/BuildAndroidDlg.h index dde2db719..51d5f2d3a 100644 --- a/platform/windows/Corona.Simulator/BuildAndroidDlg.h +++ b/platform/windows/Corona.Simulator/BuildAndroidDlg.h @@ -87,11 +87,10 @@ class CBuildAndroidDlg : public CDialog void DisplayWarningMessage(UINT nMessageID, CString filename); // override with additional info UINT DisplayWarningMessageWithHelp(UINT nTitleID, UINT nMessageID, CString helpURL); static void CALLBACK CBuildAndroidDlg::HelpCallback(LPHELPINFO lpHelpInfo); -#ifdef AUTO_INCLUDE_MONETIZATION_PLUGIN -public: - afx_msg void OnBnClickedEnableMonetization(); -#endif afx_msg void OnBnClickedCreateLiveBuild(); + afx_msg void OnRadioClickedCopyToDevice(); + afx_msg void OnRadioClickedShowInFiles(); + afx_msg void OnRadioClickedDoNothing(); void LogAnalytics(const char *eventName, const char *key = NULL, const char *value = NULL); }; diff --git a/platform/windows/Corona.Simulator/Resource.h b/platform/windows/Corona.Simulator/Resource.h index d19b79285..b77b13828 100644 --- a/platform/windows/Corona.Simulator/Resource.h +++ b/platform/windows/Corona.Simulator/Resource.h @@ -320,6 +320,9 @@ #define IDC_INCLUDE_STANDART_RESOURCES 1104 #define IDC_CREATE_FB_INSTANT_ARCHIVE 1105 #define IDC_BUILD_NMETA_PATH 1106 +#define IDC_COPY_TO_DEVICE 1107 +#define IDC_SHOW_IN_FILES 1108 +#define IDC_DO_NOTHING 1109 #define ID_Menu 32771 #define ID_FILE_OPENFORBUILD 32772 #define ID_FILE_RELAUNCH 32774 @@ -362,6 +365,8 @@ #define ID_VIEWAS_CUSTOMDEVICE 32998 #define ID_VIEWAS_END 32999 + + // Next default values for new objects // #ifdef APSTUDIO_INVOKED diff --git a/platform/windows/Corona.Simulator/Simulator.cpp b/platform/windows/Corona.Simulator/Simulator.cpp index f23cc6feb..2b9aa715c 100644 --- a/platform/windows/Corona.Simulator/Simulator.cpp +++ b/platform/windows/Corona.Simulator/Simulator.cpp @@ -12,6 +12,9 @@ #include #include #include +#include +#include +#include #include "Simulator.h" #include "MainFrm.h" diff --git a/platform/windows/Corona.Simulator/Simulator.rc b/platform/windows/Corona.Simulator/Simulator.rc old mode 100755 new mode 100644 index 3bf66cef3..bb5dfd885 --- a/platform/windows/Corona.Simulator/Simulator.rc +++ b/platform/windows/Corona.Simulator/Simulator.rc @@ -277,7 +277,7 @@ BEGIN LTEXT "",IDC_ABOUT_VERSION,39,26,160,8 END -IDD_BUILD_DROID DIALOGEX 0, 0, 313, 218 +IDD_BUILD_DROID DIALOGEX 0, 0, 313, 280 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_CONTEXTHELP CAPTION "Android Build Setup" @@ -305,9 +305,11 @@ BEGIN EDITTEXT IDC_BUILD_SAVETO,90,170,156,14,ES_AUTOHSCROLL PUSHBUTTON "Browse...",IDC_BUILD_BROWSE_SAVETO,252,170,54,14 CONTROL "Create &Live Build",IDC_CREATE_LIVE_BUILD,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,90,187,81,10 - CONTROL "Enable Monetization",IDC_ENABLE_MONETIZATION,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,90,199,81,10 - DEFPUSHBUTTON "Build",IDOK,204,197,48,14 - PUSHBUTTON "Cancel",IDCANCEL,258,197,48,14 + AUTORADIOBUTTON "Copy to device",IDC_COPY_TO_DEVICE,90,210,81,10, WS_GROUP | WS_TABSTOP + AUTORADIOBUTTON "Show in File Explorer", IDC_SHOW_IN_FILES, 90, 230, 81, 10, WS_GROUP | WS_TABSTOP + AUTORADIOBUTTON "Do nothing", IDC_SHOW_IN_FILES, 90, 250, 81, 10, WS_GROUP | WS_TABSTOP + DEFPUSHBUTTON "Build",IDOK,204,260,48,14 + PUSHBUTTON "Cancel",IDCANCEL,258,260,48,14 END IDD_PASSWORD DIALOGEX 0, 0, 169, 106 From 6f8dc5edaa9a7866e8690ebf36309191e2373215 Mon Sep 17 00:00:00 2001 From: Scott Harrison Date: Thu, 2 Mar 2023 10:02:47 -0600 Subject: [PATCH 2/6] Updates --- .../Corona.Simulator/BuildAndroidDlg.cpp | 47 +++++++++++-------- .../Corona.Simulator/BuildAndroidDlg.h | 3 -- .../Corona.Simulator/CoronaProject.cpp | 30 ++++++++---- .../windows/Corona.Simulator/CoronaProject.h | 10 ++-- platform/windows/Corona.Simulator/Resource.h | 7 +-- .../windows/Corona.Simulator/Simulator.rc | 7 +-- 6 files changed, 64 insertions(+), 40 deletions(-) diff --git a/platform/windows/Corona.Simulator/BuildAndroidDlg.cpp b/platform/windows/Corona.Simulator/BuildAndroidDlg.cpp index 537b50d61..7eafc8045 100644 --- a/platform/windows/Corona.Simulator/BuildAndroidDlg.cpp +++ b/platform/windows/Corona.Simulator/BuildAndroidDlg.cpp @@ -247,7 +247,14 @@ BOOL CBuildAndroidDlg::OnInitDialog() // Set up the "Live Build" checkbox. CheckDlgButton(IDC_CREATE_LIVE_BUILD, m_pProject->GetCreateLiveBuild() ? BST_CHECKED : BST_UNCHECKED); - + // Set up the "Build to Device" Radio Group + CButton* pCopyToDevice = (CButton*)GetDlgItem(IDC_COPY_TO_DEVICE); + CButton* pShowInFiles = (CButton*)GetDlgItem(IDC_SHOW_IN_FILES); + CButton* pDoNothing = (CButton*)GetDlgItem(IDC_DO_NOTHING); + pCopyToDevice->SetCheck((m_pProject->GetAfterBuild() == "2") ? BST_CHECKED : BST_UNCHECKED); + pShowInFiles->SetCheck((m_pProject->GetAfterBuild() == "1") ? BST_CHECKED : BST_UNCHECKED); + pDoNothing->SetCheck((m_pProject->GetAfterBuild() == "0") ? BST_CHECKED : BST_UNCHECKED); + return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE @@ -698,6 +705,14 @@ void CBuildAndroidDlg::OnOK() // OnBuild() } isLiveBuild = (IsDlgButtonChecked(IDC_CREATE_LIVE_BUILD) == BST_CHECKED); + CString afterBuild = _T("0"); + CButton* pCopyToDevice = (CButton*)GetDlgItem(IDC_COPY_TO_DEVICE); + CButton* pShowInFiles = (CButton*)GetDlgItem(IDC_SHOW_IN_FILES); + if (pCopyToDevice->GetCheck() == BST_CHECKED) + afterBuild = _T("2"); + else if (pShowInFiles->GetCheck() == BST_CHECKED) + afterBuild = _T("1"); + // Store field settings to project. m_pProject->SetName(sAppName); m_pProject->SetAndroidVersionCode(iVersionCode); @@ -708,6 +723,7 @@ void CBuildAndroidDlg::OnOK() // OnBuild() m_pProject->SetSaveDir(sBuildDir); m_pProject->SetTargetOS(_T("Android 2.3.3")); // <- This string is only used by logging/analytics. m_pProject->SetCreateLiveBuild(isLiveBuild); + m_pProject->SetAfterBuild(afterBuild); // Update global build settings in registry. stringBuffer.SetUTF8(pTargetStore->GetStringId()); @@ -805,6 +821,17 @@ void CBuildAndroidDlg::OnOK() // OnBuild() catch (...) {} } + //After Build Options + if (afterBuild == "2") // Copy to Device + { + CString sAppPath = m_pProject->GetPath(); + } + else if (afterBuild == "1") // Show in Files + { + CString sAppPath = m_pProject->GetPath(); + ::ShellExecute(nullptr, nullptr, _T("explorer"), sAppPath, nullptr, SW_SHOWNORMAL); + }//else do nothing + // Close this window. CDialog::OnOK(); } @@ -934,24 +961,6 @@ void CBuildAndroidDlg::OnBnClickedCreateLiveBuild() } } -void CBuildAndroidDlg::OnRadioClickedCopyToDevice() -{ - - -} - -void CBuildAndroidDlg::OnRadioClickedShowInFiles() -{ - - -} - -void CBuildAndroidDlg::OnRadioClickedDoNothing() -{ - - -} - void CBuildAndroidDlg::LogAnalytics(const char *eventName, const char *key, const char *value) { Rtt_ASSERT(GetWinProperties()->GetAnalytics() != NULL); diff --git a/platform/windows/Corona.Simulator/BuildAndroidDlg.h b/platform/windows/Corona.Simulator/BuildAndroidDlg.h index 51d5f2d3a..87354c94f 100644 --- a/platform/windows/Corona.Simulator/BuildAndroidDlg.h +++ b/platform/windows/Corona.Simulator/BuildAndroidDlg.h @@ -88,9 +88,6 @@ class CBuildAndroidDlg : public CDialog UINT DisplayWarningMessageWithHelp(UINT nTitleID, UINT nMessageID, CString helpURL); static void CALLBACK CBuildAndroidDlg::HelpCallback(LPHELPINFO lpHelpInfo); afx_msg void OnBnClickedCreateLiveBuild(); - afx_msg void OnRadioClickedCopyToDevice(); - afx_msg void OnRadioClickedShowInFiles(); - afx_msg void OnRadioClickedDoNothing(); void LogAnalytics(const char *eventName, const char *key = NULL, const char *value = NULL); }; diff --git a/platform/windows/Corona.Simulator/CoronaProject.cpp b/platform/windows/Corona.Simulator/CoronaProject.cpp index 449ea4477..aff13b20a 100644 --- a/platform/windows/Corona.Simulator/CoronaProject.cpp +++ b/platform/windows/Corona.Simulator/CoronaProject.cpp @@ -1,7 +1,7 @@ ////////////////////////////////////////////////////////////////////////////// // // This file is part of the Corona game engine. -// For overview and more information on licensing please refer to README.md +// For overview and more information on licensing please refer to README.md // Home page: https://github.com/coronalabs/corona // Contact: support@coronalabs.com // @@ -224,9 +224,10 @@ CCoronaProject::RegistryGet( CString sSection ) // Third argument is what this is a password for, not value of password m_KeystorePassword.RegistryGet( sSection, REGISTRY_KEYSTOREPWD, GetKeystorePath() ); - m_AliasPassword.RegistryGet( sSection, REGISTRY_ALIASPWD, GetAlias() ); + m_AliasPassword.RegistryGet( sSection, REGISTRY_ALIASPWD, GetAlias() ); stringBuffer = pApp->GetProfileString(sSection, REGISTRY_CREATE_LIVE_BUILD, REGISTRY_CREATE_LIVE_BUILD_DEFAULT); m_CreateLiveBuild = _ttoi(stringBuffer) ? true : false; + m_sAfterBuild = pApp->GetProfileString( sSection, REGISTRY_AFTER_BUILD ); #ifdef AUTO_INCLUDE_MONETIZATION_PLUGIN stringBuffer = pApp->GetProfileString(sSection, REGISTRY_ENABLE_MONETIZATION, REGISTRY_ENABLE_MONETIZATION_DEFAULT); m_EnableMonetization = _ttoi(stringBuffer) ? true : false; @@ -262,6 +263,8 @@ CCoronaProject::RegistryPut( CString sSection ) m_AliasPassword.RegistryPut(sSection, REGISTRY_ALIASPWD, GetAlias()); stringBuffer.Format(_T("%d"), m_CreateLiveBuild); pApp->WriteProfileString(sSection, REGISTRY_CREATE_LIVE_BUILD, stringBuffer); + + pApp->WriteProfileString( sSection, REGISTRY_AFTER_BUILD, m_sAfterBuild ); #ifdef AUTO_INCLUDE_MONETIZATION_PLUGIN stringBuffer.Format(_T("%d"), m_EnableMonetization); pApp->WriteProfileString(sSection, REGISTRY_ENABLE_MONETIZATION, stringBuffer); @@ -356,7 +359,7 @@ CCoronaProject::ValidatePackage( CString sPackage ) if( (nextPeriod == 0) // starting with period || (nextPeriod == length - 1) // ending with period || (nextPeriod == prevPeriod + 1 ) // two periods in a row - || ! allalphanum( sPackage, prevPeriod + 1, nextPeriod - 1) + || ! allalphanum( sPackage, prevPeriod + 1, nextPeriod - 1) || isJavaReservedWord( sPackage, prevPeriod + 1, nextPeriod - 1) ) { bCorrect = false; @@ -396,7 +399,7 @@ CCoronaProject::allalphanum( CString string, int start, int end ) return true; } -// isJavaReservedWord - return true if all the characters between start and end, inclusive, +// isJavaReservedWord - return true if all the characters between start and end, inclusive, // form a Java reserved word. http://www.javacamp.org/javaI/reservedWords.html // Note that case matters: "interface" is reserved, but "Interface" isn't. bool @@ -566,6 +569,15 @@ void CCoronaProject::SetCreateLiveBuild(bool createLiveBuild) m_CreateLiveBuild = createLiveBuild; } +CString CCoronaProject::GetAfterBuild() +{ + return m_sAfterBuild; +} +void CCoronaProject::SetAfterBuild(CString afterBuild) +{ + m_sAfterBuild = afterBuild; +} + #ifdef AUTO_INCLUDE_MONETIZATION_PLUGIN bool CCoronaProject::GetEnableMonetization() { @@ -681,7 +693,7 @@ CEncryptedKeeper::RegistryPut( CString sSection, CString sKey, CString sMatch ) ClearCurrent(); } // Re-save of same data, could be to different registry location - else if( m_aSavedData != NULL && m_nSavedData > 0 ) + else if( m_aSavedData != NULL && m_nSavedData > 0 ) { pApp->WriteProfileBinary( sSection, sKey, m_aSavedData, m_nSavedData ); } @@ -716,7 +728,7 @@ CEncryptedKeeper::ClearSaved() } // ClearAll - clear both current and saved data -void +void CEncryptedKeeper::ClearAll() { ClearCurrent(); @@ -738,7 +750,7 @@ void CEncryptedKeeper::EncryptString( CString sSecret, BYTE **paBytes, UINT *pnB // byte character sets. unencryptedData.cbData = (sSecret.GetLength() + 1) * sizeof( sSecret[0] ); if (!CryptProtectData( - &unencryptedData, + &unencryptedData, _T("Marker"), NULL, NULL, @@ -763,7 +775,7 @@ void CEncryptedKeeper::EncryptString( CString sSecret, BYTE **paBytes, UINT *pnB CString CEncryptedKeeper::DecryptString( BYTE *aBytes, UINT nBytes ) { DATA_BLOB encryptedData, unencryptedData; - + encryptedData.pbData = aBytes; encryptedData.cbData = nBytes; LPWSTR dataDescription; // Receives the description saved with data @@ -784,7 +796,7 @@ CString CEncryptedKeeper::DecryptString( BYTE *aBytes, UINT nBytes ) // NOTE: Contains NULL terminator CString sSecret( (LPCTSTR) unencryptedData.pbData, unencryptedData.cbData ); - + // Cleanup LocalFree(unencryptedData.pbData); diff --git a/platform/windows/Corona.Simulator/CoronaProject.h b/platform/windows/Corona.Simulator/CoronaProject.h index 3fc8e08f0..242712d92 100644 --- a/platform/windows/Corona.Simulator/CoronaProject.h +++ b/platform/windows/Corona.Simulator/CoronaProject.h @@ -1,7 +1,7 @@ ////////////////////////////////////////////////////////////////////////////// // // This file is part of the Corona game engine. -// For overview and more information on licensing please refer to README.md +// For overview and more information on licensing please refer to README.md // Home page: https://github.com/coronalabs/corona // Contact: support@coronalabs.com // @@ -45,6 +45,7 @@ #define REGISTRY_ALIAS_DEFAULT _T("") #define REGISTRY_SAVEDIR_DEFAULT _T("") #define REGISTRY_CREATE_LIVE_BUILD_DEFAULT _T("0") +#define REGISTRY_AFTER_BUILD _T("0") #define REGISTRY_ENABLE_MONETIZATION_DEFAULT _T("1") /////////////////////////////////////////////////////////////////////////////// @@ -66,7 +67,7 @@ class CEncryptedKeeper : public CObject void SetSave( bool bSave ) { m_bSaveToRegistry = bSave; } void RegistryGet( CString sSection, CString sKey, CString sMatch ); - void RegistryPut( CString sSection, CString sKey, CString sMatch ); + void RegistryPut( CString sSection, CString sKey, CString sMatch ); void ClearCurrent(); void ClearSaved(); @@ -163,6 +164,8 @@ class CCoronaProject : bool GetCreateLiveBuild(); void SetCreateLiveBuild(bool createLiveBuild); + CString GetAfterBuild(); + void SetAfterBuild(CString afterBuild); #ifdef AUTO_INCLUDE_MONETIZATION_PLUGIN bool GetEnableMonetization(); @@ -219,10 +222,11 @@ class CCoronaProject : bool m_CreateLiveBuild; + CString m_sAfterBuild; + #ifdef AUTO_INCLUDE_MONETIZATION_PLUGIN bool m_EnableMonetization; #endif bool m_sCreateFBInstantArchive; }; - diff --git a/platform/windows/Corona.Simulator/Resource.h b/platform/windows/Corona.Simulator/Resource.h index b77b13828..8efed1f7e 100644 --- a/platform/windows/Corona.Simulator/Resource.h +++ b/platform/windows/Corona.Simulator/Resource.h @@ -320,9 +320,10 @@ #define IDC_INCLUDE_STANDART_RESOURCES 1104 #define IDC_CREATE_FB_INSTANT_ARCHIVE 1105 #define IDC_BUILD_NMETA_PATH 1106 -#define IDC_COPY_TO_DEVICE 1107 -#define IDC_SHOW_IN_FILES 1108 -#define IDC_DO_NOTHING 1109 +#define IDC_ON_COMPLETE_OPTIONS 1107 +#define IDC_COPY_TO_DEVICE 1108 +#define IDC_SHOW_IN_FILES 1109 +#define IDC_DO_NOTHING 1110 #define ID_Menu 32771 #define ID_FILE_OPENFORBUILD 32772 #define ID_FILE_RELAUNCH 32774 diff --git a/platform/windows/Corona.Simulator/Simulator.rc b/platform/windows/Corona.Simulator/Simulator.rc index bb5dfd885..4fbed963e 100644 --- a/platform/windows/Corona.Simulator/Simulator.rc +++ b/platform/windows/Corona.Simulator/Simulator.rc @@ -305,9 +305,10 @@ BEGIN EDITTEXT IDC_BUILD_SAVETO,90,170,156,14,ES_AUTOHSCROLL PUSHBUTTON "Browse...",IDC_BUILD_BROWSE_SAVETO,252,170,54,14 CONTROL "Create &Live Build",IDC_CREATE_LIVE_BUILD,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,90,187,81,10 - AUTORADIOBUTTON "Copy to device",IDC_COPY_TO_DEVICE,90,210,81,10, WS_GROUP | WS_TABSTOP - AUTORADIOBUTTON "Show in File Explorer", IDC_SHOW_IN_FILES, 90, 230, 81, 10, WS_GROUP | WS_TABSTOP - AUTORADIOBUTTON "Do nothing", IDC_SHOW_IN_FILES, 90, 250, 81, 10, WS_GROUP | WS_TABSTOP + GROUPBOX "After Build:", IDC_ON_COMPLETE_OPTIONS, 90, 205, 90, 70 + CONTROL "Copy to device",IDC_COPY_TO_DEVICE,"BUTTON", BS_AUTORADIOBUTTON, 94, 220, 81, 10 + CONTROL "Show in File Explorer", IDC_SHOW_IN_FILES,"BUTTON", BS_AUTORADIOBUTTON, 94, 240, 81, 10 + CONTROL "Do nothing", IDC_DO_NOTHING,"BUTTON", BS_AUTORADIOBUTTON, 94, 260, 81, 10 DEFPUSHBUTTON "Build",IDOK,204,260,48,14 PUSHBUTTON "Cancel",IDCANCEL,258,260,48,14 END From 5183d57b1846940dd5e962dc68738d8e4df6f3d6 Mon Sep 17 00:00:00 2001 From: Scott Harrison Date: Fri, 3 Mar 2023 11:12:19 -0600 Subject: [PATCH 3/6] Final Version --- .../Corona.Simulator/BuildAndroidDlg.cpp | 79 +- .../Corona.Simulator/BuildAndroidDlg.h | 2 +- platform/windows/Corona.Simulator/Resource.h | 2 + platform/windows/Corona.Simulator/Simulator.h | 5 + .../windows/Corona.Simulator/Simulator.rc | 2 + .../BuildAndroidDlg.cpp | 1029 +++++++++++++++++ 6 files changed, 1092 insertions(+), 27 deletions(-) create mode 100644 platform/windows/enc_temp_folder/7c24e61fe51de841fc62ed235c2cf3b/BuildAndroidDlg.cpp diff --git a/platform/windows/Corona.Simulator/BuildAndroidDlg.cpp b/platform/windows/Corona.Simulator/BuildAndroidDlg.cpp index 7eafc8045..9cb971d5f 100644 --- a/platform/windows/Corona.Simulator/BuildAndroidDlg.cpp +++ b/platform/windows/Corona.Simulator/BuildAndroidDlg.cpp @@ -29,7 +29,9 @@ #include "Rtt_TargetDevice.h" #include "Rtt_TargetAndroidAppStore.h" #include - +#include +#include +#include // CBuildAndroidDlg dialog @@ -251,10 +253,10 @@ BOOL CBuildAndroidDlg::OnInitDialog() CButton* pCopyToDevice = (CButton*)GetDlgItem(IDC_COPY_TO_DEVICE); CButton* pShowInFiles = (CButton*)GetDlgItem(IDC_SHOW_IN_FILES); CButton* pDoNothing = (CButton*)GetDlgItem(IDC_DO_NOTHING); - pCopyToDevice->SetCheck((m_pProject->GetAfterBuild() == "2") ? BST_CHECKED : BST_UNCHECKED); - pShowInFiles->SetCheck((m_pProject->GetAfterBuild() == "1") ? BST_CHECKED : BST_UNCHECKED); - pDoNothing->SetCheck((m_pProject->GetAfterBuild() == "0") ? BST_CHECKED : BST_UNCHECKED); - + + pCopyToDevice->SetCheck((m_pProject->GetAfterBuild() == AB_COPY_TO_DEVICE) ? BST_CHECKED : BST_UNCHECKED); + pShowInFiles->SetCheck((m_pProject->GetAfterBuild() == AB_SHOW_IN_FILES) ? BST_CHECKED : BST_UNCHECKED); + pDoNothing->SetCheck((m_pProject->GetAfterBuild() == AB_DO_NOTHING || m_pProject->GetAfterBuild() == "") ? BST_CHECKED : BST_UNCHECKED); //Default option return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE @@ -554,6 +556,19 @@ void CBuildAndroidDlg::OnSysCommand(UINT nID, LPARAM lParam) } } + +//This will open and run a command promot window +void Exec(CString command) { + ::ShellExecute( + nullptr, + _T("open"), + _T("cmd"), + _T(" /K \"")+command+_T("\""), // params + nullptr, + SW_SHOW); +} + + // OnOK - build project // Retrieve values from dialog, save to registry, // get key alias password if necessary @@ -582,7 +597,7 @@ void CBuildAndroidDlg::OnOK() // OnBuild() if (ret != IDYES) return; AfxGetApp()->WriteProfileString( REGISTRY_BUILD_ANDROID, _T("AcceptedSDKLicense"), _T("YES") ); } - + // Fetch and validate field values. GetDlgItemText(IDC_BUILD_APPNAME, sAppName); sAppName.Trim(); @@ -800,14 +815,30 @@ void CBuildAndroidDlg::OnOK() // OnBuild() return; } + //After Build Options + if (afterBuild == AB_COPY_TO_DEVICE) // Copy to Device + { + if (PathFileExists(_T("C:\\Program Files (x86)\\Android\\android-sdk\\platform-tools\\adb.exe"))) { // this should be where adb is installed + CString apkPath = m_pProject->GetSaveDir() + _T("\\") + m_pProject->GetName() + _T(".apk"); // apk path + Exec(_T("cd C:\\Program Files (x86)\\Android\\android-sdk\\platform-tools & adb install -r \"") + apkPath + _T("\" & adb logcat Corona:v *:s")); // install apk and print logs + } + else { // adb is not installed + DisplayWarningMessageWithHelp(IDS_ADB_NOT_INSTALLED, IDS_ADB_NOT_INSTALLED_WARNING, _T("https://docs.coronalabs.com/guide/basics/debugging/index.html#device-debugging-android"), false); + } + + } + else if (afterBuild == AB_SHOW_IN_FILES) + { + ShellExecute(NULL, _T("open"), m_pProject->GetSaveDir(), NULL, NULL, SW_SHOWNORMAL); + } // The build has succeeded. Inform the user. - CMessageDlg messageDlg(this); - messageDlg.SetText( IDS_BUILD_SUCCEEDED ); - messageDlg.SetDefaultText( IDS_DONE ); - messageDlg.SetAltText( IDS_VIEW_EXPLORER ); - messageDlg.SetFolder( m_pProject->GetSaveDir() ); - messageDlg.SetIconStyle( MB_ICONINFORMATION ); - messageDlg.DoModal(); + CMessageDlg messageDlg(this); + messageDlg.SetText(IDS_BUILD_SUCCEEDED); + messageDlg.SetDefaultText(IDS_DONE); + //messageDlg.SetAltText( IDS_VIEW_EXPLORER ); //Remove because we give user a choice already + //messageDlg.SetFolder( m_pProject->GetSaveDir() ); + messageDlg.SetIconStyle(MB_ICONINFORMATION); + messageDlg.DoModal(); // Add the project to the Corona Live Server list, if enabled. if (isLiveBuild) @@ -821,16 +852,7 @@ void CBuildAndroidDlg::OnOK() // OnBuild() catch (...) {} } - //After Build Options - if (afterBuild == "2") // Copy to Device - { - CString sAppPath = m_pProject->GetPath(); - } - else if (afterBuild == "1") // Show in Files - { - CString sAppPath = m_pProject->GetPath(); - ::ShellExecute(nullptr, nullptr, _T("explorer"), sAppPath, nullptr, SW_SHOWNORMAL); - }//else do nothing + // Close this window. CDialog::OnOK(); @@ -899,7 +921,7 @@ void CALLBACK CBuildAndroidDlg::HelpCallback(LPHELPINFO lpHelpInfo) catch (...) {} } -UINT CBuildAndroidDlg::DisplayWarningMessageWithHelp(UINT nTitleID, UINT nMessageID, CString helpURL) +UINT CBuildAndroidDlg::DisplayWarningMessageWithHelp(UINT nTitleID, UINT nMessageID, CString helpURL, bool isYesNo) { MSGBOXPARAMS mbp; CString title; @@ -919,8 +941,13 @@ UINT CBuildAndroidDlg::DisplayWarningMessageWithHelp(UINT nTitleID, UINT nMessag // if you wanted to specify a different caption, here is where you do it mbp.lpszCaption = title; - - mbp.dwStyle = MB_YESNO | MB_ICONWARNING | MB_HELP; + if (isYesNo) { //default YES NO + mbp.dwStyle = MB_YESNO | MB_ICONWARNING | MB_HELP; + } + else { + mbp.dwStyle = MB_ICONWARNING | MB_HELP; + } + // mbp.lpszIcon = ; // note, you could provide your own custom ICON here! diff --git a/platform/windows/Corona.Simulator/BuildAndroidDlg.h b/platform/windows/Corona.Simulator/BuildAndroidDlg.h index 87354c94f..24b0a24c4 100644 --- a/platform/windows/Corona.Simulator/BuildAndroidDlg.h +++ b/platform/windows/Corona.Simulator/BuildAndroidDlg.h @@ -85,7 +85,7 @@ class CBuildAndroidDlg : public CDialog CString GetTrialKeyAliasPassword(); void DisplayWarningMessage(UINT nMessageID); void DisplayWarningMessage(UINT nMessageID, CString filename); // override with additional info - UINT DisplayWarningMessageWithHelp(UINT nTitleID, UINT nMessageID, CString helpURL); + UINT DisplayWarningMessageWithHelp(UINT nTitleID, UINT nMessageID, CString helpURL, bool isYesNo = true); static void CALLBACK CBuildAndroidDlg::HelpCallback(LPHELPINFO lpHelpInfo); afx_msg void OnBnClickedCreateLiveBuild(); void LogAnalytics(const char *eventName, const char *key = NULL, const char *value = NULL); diff --git a/platform/windows/Corona.Simulator/Resource.h b/platform/windows/Corona.Simulator/Resource.h index 8efed1f7e..9bd8e1ed1 100644 --- a/platform/windows/Corona.Simulator/Resource.h +++ b/platform/windows/Corona.Simulator/Resource.h @@ -232,6 +232,8 @@ #define IDS_ANDROID_BUILD 675 #define IDS_ANDROID_SDK_LICENSE 676 #define IDS_BUILD_NMETA_NAME_NOT_PROVIDED 677 +#define IDS_ADB_NOT_INSTALLED 678 +#define IDS_ADB_NOT_INSTALLED_WARNING 679 #define IDC_LINK_ANSCAMOBILE 1000 #define IDC_BUILD_APPNAME 1001 #define IDC_BUILD_VERSION_CODE 1002 diff --git a/platform/windows/Corona.Simulator/Simulator.h b/platform/windows/Corona.Simulator/Simulator.h index 46dc47ae2..389432b74 100644 --- a/platform/windows/Corona.Simulator/Simulator.h +++ b/platform/windows/Corona.Simulator/Simulator.h @@ -37,6 +37,11 @@ #define SIM_SHAKE_REPS 7 #define SIM_SHAKE_PERIOD 80 // msec +// After Build Types +#define AB_DO_NOTHING "0" +#define AB_SHOW_IN_FILES "1" +#define AB_COPY_TO_DEVICE "2" + // Define all registry items here #define REGISTRY_SECTION _T("Preferences") #define REGISTRY_WORKINGDIR _T("WorkingDir") diff --git a/platform/windows/Corona.Simulator/Simulator.rc b/platform/windows/Corona.Simulator/Simulator.rc index 4fbed963e..dbabcc32f 100644 --- a/platform/windows/Corona.Simulator/Simulator.rc +++ b/platform/windows/Corona.Simulator/Simulator.rc @@ -859,6 +859,8 @@ BEGIN IDS_ANDROID_BUILD "Building Android App" IDS_ANDROID_SDK_LICENSE """You are about to build an Android app for the first time with this build system.\nIt uses the Android SDK and you must read and accept its license agreement in order to proceed.\nNote, the first time it will download about 250Mb which can take several minutes.\nPress 'Yes' to accept, 'No' to decline or 'Help' to read the license agreement.""" IDS_BUILD_NMETA_NAME_NOT_PROVIDED "You must provide path to .nmeta file." + IDS_ADB_NOT_INSTALLED "ADB Not Installed" + IDS_ADB_NOT_INSTALLED_WARNING "You must have Android Device Bridge Installed to Copy App to Device" END STRINGTABLE diff --git a/platform/windows/enc_temp_folder/7c24e61fe51de841fc62ed235c2cf3b/BuildAndroidDlg.cpp b/platform/windows/enc_temp_folder/7c24e61fe51de841fc62ed235c2cf3b/BuildAndroidDlg.cpp new file mode 100644 index 000000000..8231bac61 --- /dev/null +++ b/platform/windows/enc_temp_folder/7c24e61fe51de841fc62ed235c2cf3b/BuildAndroidDlg.cpp @@ -0,0 +1,1029 @@ +////////////////////////////////////////////////////////////////////////////// +// +// This file is part of the Corona game engine. +// For overview and more information on licensing please refer to README.md +// Home page: https://github.com/coronalabs/corona +// Contact: support@coronalabs.com +// +////////////////////////////////////////////////////////////////////////////// + +#include "stdafx.h" +#include "Simulator.h" +#include "SimulatorView.h" +#include "Resource.h" +#include "CoronaProject.h" +#include "PasswordDlg.h" +#include "BuildAndroidDlg.h" +#include "BuildProgressDlg.h" +#include "BuildResult.h" +#include "WinGlobalProperties.h" +#include "WinString.h" +#include "BrowseDirDialog.h" +#include "HtmlMessageDlg.h" +#include "MessageDlg.h" +#include "ListKeyStore.h" +#include "CoronaInterface.h" +#include "Core/Rtt_Build.h" +#include "Rtt_AndroidSupportTools.h" +#include "Rtt_SimulatorAnalytics.h" +#include "Rtt_TargetDevice.h" +#include "Rtt_TargetAndroidAppStore.h" +#include +#include +#include +#include + +// CBuildAndroidDlg dialog + +CString CBuildAndroidDlg::m_sHelpURL; + +IMPLEMENT_DYNAMIC(CBuildAndroidDlg, CDialog) + +CBuildAndroidDlg::CBuildAndroidDlg(CWnd* pParent /*=NULL*/) + : CDialog(CBuildAndroidDlg::IDD, pParent), + m_pProject( NULL ), + m_sPrevKeystorePath( "" ), + m_sKeystoreDir( "" ), + m_nValidFields( 0 ), + m_androidValidatorLuaState( NULL ) +{ +} + +CBuildAndroidDlg::~CBuildAndroidDlg() +{ + if (m_androidValidatorLuaState) + { + Rtt_AndroidSupportTools_CloseLuaState(m_androidValidatorLuaState); + } +} + +void CBuildAndroidDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); +} + + +BEGIN_MESSAGE_MAP(CBuildAndroidDlg, CDialog) + ON_BN_CLICKED(IDC_BUILD_BROWSE_KEYSTORE, &CBuildAndroidDlg::OnBrowseKeystore) + ON_BN_CLICKED(IDC_BUILD_BROWSE_SAVETO, &CBuildAndroidDlg::OnBrowseSaveto) + ON_EN_KILLFOCUS(IDC_BUILD_KEYSTORE, &CBuildAndroidDlg::OnKillFocusKeystorePath) + ON_CBN_SELCHANGE(IDC_BUILD_KEYALIAS, &CBuildAndroidDlg::OnChangeAliasList) + ON_CBN_SETFOCUS(IDC_BUILD_KEYALIAS, &CBuildAndroidDlg::OnSetFocusAliasList) + ON_WM_HELPINFO() + ON_WM_SYSCOMMAND() + ON_BN_CLICKED(IDC_CREATE_LIVE_BUILD, &CBuildAndroidDlg::OnBnClickedCreateLiveBuild) +END_MESSAGE_MAP() + +// OnInitDialog - restore settings from m_pProject if available. +// Choose likely defaults for non-saved settings. +// Check for trial users, who can only use installed debug.keystore +BOOL CBuildAndroidDlg::OnInitDialog() +{ + WinString stringConverter; + CString stringBuffer; + + // Initialize base class first. + CDialog::OnInitDialog(); + + // Do not display this window if not given a project settings object. + if (!m_pProject) + { + CDialog::OnCancel(); + return TRUE; + } + + //Set inital project type now that we have Android/Web (used by the BuildProgressDlg - does not indicate target app store) + m_pProject->SetTargetPlatform(Rtt::TargetDevice::kAndroidPlatform); + + // Initialize the Android validator. + WinString androidValidatorFilePath; + androidValidatorFilePath.SetUTF8(GetWinProperties()->GetResourcesDir()); + if ((androidValidatorFilePath.GetLength() > 0) && !androidValidatorFilePath.EndsWith("\\")) + { + androidValidatorFilePath.Append("\\"); + } + androidValidatorFilePath.Append("AndroidValidation.lua"); + m_androidValidatorLuaState = Rtt_AndroidSupportTools_NewLuaState(androidValidatorFilePath.GetUTF8()); + + // Limit the text length of CEdit boxes. + ((CEdit*)GetDlgItem(IDC_BUILD_APPNAME))->SetLimitText(128); + ((CEdit*)GetDlgItem(IDC_BUILD_VERSION_CODE))->SetLimitText(9); + ((CEdit*)GetDlgItem(IDC_BUILD_VERSION_NAME))->SetLimitText(16); + ((CEdit*)GetDlgItem(IDC_BUILD_PACKAGE))->SetLimitText(128); + ((CEdit*)GetDlgItem(IDC_BUILD_KEYSTORE))->SetLimitText(MAX_PATH - 1); + ((CEdit*)GetDlgItem(IDC_BUILD_SAVETO))->SetLimitText(MAX_PATH - 1); + + // Fetch the last selected app store. + stringConverter.SetUTF8(Rtt::TargetAndroidAppStore::kGoogle.GetStringId()); + stringBuffer = AfxGetApp()->GetProfileString( + REGISTRY_BUILD_ANDROID, REGISTRY_TARGET_APP_STORE, stringConverter.GetTCHAR()); + stringConverter.SetTCHAR(stringBuffer); + Rtt::TargetAndroidAppStore *pLastSelectedStore = + Rtt::TargetAndroidAppStore::GetByStringId(stringConverter.GetUTF8()); + + // Set up the app store combo box. + CComboBox *pStoreComboBox = (CComboBox*)GetDlgItem(IDC_BUILD_TARGET_APP_STORE); + int iStoreCount = Rtt::TargetAndroidAppStore::GetCount(); + for (int iStoreIndex = 0; iStoreIndex < iStoreCount; iStoreIndex++) + { + Rtt::TargetAndroidAppStore *pNextStore = Rtt::TargetAndroidAppStore::GetByIndex(iStoreIndex); + if (pNextStore != NULL) + { + stringConverter.SetUTF8(pNextStore->GetName()); + int iComboBoxIndex = pStoreComboBox->AddString(stringConverter.GetTCHAR()); + if (iComboBoxIndex >= 0) + { + pStoreComboBox->SetItemDataPtr(iComboBoxIndex, (void*)pNextStore); + if (pNextStore == pLastSelectedStore) + { + pStoreComboBox->SetCurSel(iComboBoxIndex); + } + if ((pStoreComboBox->GetCurSel() < 0) && + (pNextStore == &Rtt::TargetAndroidAppStore::kGoogle)) + { + pStoreComboBox->SetCurSel(iComboBoxIndex); + } + } + } + } + + m_sKeystoreDir = AfxGetApp()->GetProfileString( REGISTRY_BUILD_ANDROID, REGISTRY_KEYSTOREDIR, + ((CSimulatorApp *)AfxGetApp())->GetResourceDir() ); // default to resource dir (where debug.keystore is) + CString sLastKeystore = AfxGetApp()->GetProfileString( REGISTRY_BUILD_ANDROID, REGISTRY_LASTKEYSTORE, _T("") ); + + m_sPrevKeystorePath = _T(""); + m_nValidFields = 0; + + // If there isn't a package name, create one by reversing the user's email address and adding the app name + if (m_pProject->GetPackage().IsEmpty()) + { + CString package("com.solar2d.app."); + package.Append(m_pProject->GetName()); + + for (int c = 0; c < package.GetLength(); c++) + { + if (package[c] > 255 || (!isalnum(package[c]) && package[c] != '.' && package[c] != '_')) + { + package.SetAt(c, _T('_')); + } + } + + package.Trim(_T("._")); + + m_pProject->SetPackage(package); + } + + stringBuffer.Format(_T("%d"), m_pProject->GetAndroidVersionCode()); + SetDlgItemText( IDC_BUILD_APPNAME, m_pProject->GetName() ); + SetDlgItemText( IDC_BUILD_VERSION_CODE, stringBuffer ); + SetDlgItemText( IDC_BUILD_VERSION_NAME, m_pProject->GetAndroidVersionName() ); + SetDlgItemText( IDC_BUILD_PACKAGE, m_pProject->GetPackage() ); + SetDlgItemText( IDC_BUILD_PROJECTPATH, m_pProject->GetDir() ); + + CSimulatorApp *pApp = (CSimulatorApp *)AfxGetApp(); + + // Initialize keystore path from, in order available + // 1. saved keystore path for this project + // 2. last used keystore path (also get last-used password) + // (if neither are available, there is also a saved keystore directory for browsing) + { + if( m_pProject->GetKeystorePath().IsEmpty() ) // none saved for project, get last-used path + { + if (sLastKeystore.IsEmpty()) + { + SetDlgItemText( IDC_BUILD_KEYSTORE, CCoronaProject::GetTrialKeystorePath() ); + m_pProject->SetKeystorePassword( GetTrialKeystorePassword() ); + } + else + { + if ( ! pApp->CheckPathExists( sLastKeystore ) ) + { + DisplayWarningMessage(IDS_ANDROID_KEYSTORE_FILE_NOT_FOUND, sLastKeystore); + } + else + { + SetDlgItemText( IDC_BUILD_KEYSTORE, sLastKeystore ); + // Third argument tells what this password is for + m_pProject->RegistryGetKeystorePassword( REGISTRY_BUILD_ANDROID, REGISTRY_LASTKEYSTOREPWD, sLastKeystore ); + } + } + } + else // use the one saved with this project + { + if ( ! pApp->CheckPathExists( m_pProject->GetKeystorePath() ) ) + { + DisplayWarningMessage(IDS_ANDROID_KEYSTORE_FILE_NOT_FOUND, m_pProject->GetKeystorePath()); + } + else + { + SetDlgItemText( IDC_BUILD_KEYSTORE, m_pProject->GetKeystorePath() ); + } + } + } + + // After all that, get the values for keystore and password and try to initialize alias list + CString sKeystore, sKeystorePassword; + GetDlgItemText( IDC_BUILD_KEYSTORE, sKeystore ); + + // Non-trial user with our installed keystore + if( sKeystore.CompareNoCase( CCoronaProject::GetTrialKeystorePath() ) == 0 ) + { + m_pProject->SetKeystorePassword( GetTrialKeystorePassword() ); + } + // For all cases, set variable to pass in to ReadKeystore + sKeystorePassword = m_pProject->GetKeystorePassword( sKeystore ); // argument has to match what pwd is for + + ReadKeystore( sKeystore, sKeystorePassword, false ); // bShowErrors=false, dialog not visible yet + + // Choose the saved key alias in the key alias dropdown + CComboBox *pAlias = (CComboBox *)GetDlgItem( IDC_BUILD_KEYALIAS ); + if( ! m_pProject->GetAlias().IsEmpty() ) + { + pAlias->SelectString( -1, m_pProject->GetAlias() ); + OnChangeAliasList(); + } + + // Initialize build destination directory. + SetDlgItemText(IDC_BUILD_SAVETO, m_pProject->GetSaveDir()); + + // Set up the "Live Build" checkbox. + CheckDlgButton(IDC_CREATE_LIVE_BUILD, m_pProject->GetCreateLiveBuild() ? BST_CHECKED : BST_UNCHECKED); + + // Set up the "Build to Device" Radio Group + CButton* pCopyToDevice = (CButton*)GetDlgItem(IDC_COPY_TO_DEVICE); + CButton* pShowInFiles = (CButton*)GetDlgItem(IDC_SHOW_IN_FILES); + CButton* pDoNothing = (CButton*)GetDlgItem(IDC_DO_NOTHING); + + pCopyToDevice->SetCheck((m_pProject->GetAfterBuild() == AB_COPY_TO_DEVICE) ? BST_CHECKED : BST_UNCHECKED); + pShowInFiles->SetCheck((m_pProject->GetAfterBuild() == AB_SHOW_IN_FILES) ? BST_CHECKED : BST_UNCHECKED); + pDoNothing->SetCheck((m_pProject->GetAfterBuild() == AB_DO_NOTHING || m_pProject->GetAfterBuild() == "") ? BST_CHECKED : BST_UNCHECKED); + OutputDebugString(_T("Run123/")); + OutputDebugString(m_pProject->GetAfterBuild()); + + return TRUE; // return TRUE unless you set the focus to a control + // EXCEPTION: OCX Property Pages should return FALSE +} + +// SetProject - called before DoModal to set the associated project. +void CBuildAndroidDlg::SetProject( const std::shared_ptr& pProject ) +{ + m_pProject = pProject; // leave unchanged until OnOK() +} + +// BuildAndroidDlg message handlers + +// OnBrowseKeystore - check authorization, then allow user to select keystore. +// Then call UpdateAliasList which gets password, reads keystore, and fills +// Key Alias dropdown. +void CBuildAndroidDlg::OnBrowseKeystore() +{ + { + GetDlgItem( IDC_BUILD_KEYSTORE )->EnableWindow( TRUE ); // may have just purchased + + // Show Open dialog so user can browse to a new keystore + CString sPath = _T(""); + GetDlgItemText( IDC_BUILD_KEYSTORE, sPath ); + + CString sFilter = _T("Keystore files (*.keystore)|*.keystore|All Files (*.*)|*.*||"); + CFileDialog fileDlg( TRUE, NULL, sPath, OFN_FILEMUSTEXIST, sFilter); + + fileDlg.m_ofn.lStructSize = sizeof( fileDlg.m_ofn ); + fileDlg.m_ofn.lpstrTitle = _T("Select Keystore"); + fileDlg.m_ofn.lpstrInitialDir = m_sKeystoreDir; + + if( fileDlg.DoModal() == IDOK ) + { + // Display selected filename + sPath = fileDlg.GetPathName(); + SetDlgItemText( IDC_BUILD_KEYSTORE, sPath ); + + // Update Alias dropdown + UpdateAliasList(); + } + } +} + +// OnKillFocusKeystorePath - ask for password when user leaves Keystore edit field, +// unless focus leaves window or is going to Cancel +void CBuildAndroidDlg::OnKillFocusKeystorePath() +{ + // Unless focus is still within dlg and on Cancel, update aliases + // TODO: What if someone alt-tabs away from the dialog and then + // clicks somewhere else? + CWnd *pFocus = CWnd::GetFocus(); + if( pFocus + && (pFocus->GetParent() == this) + && (pFocus->GetDlgCtrlID() == IDCANCEL) ) + { + return; + } + + UpdateAliasList(); +} + +// OnSetFocusAliasLIst - when focus goes to alias list dropdown, check if it's +// empty and ask for keystore password. +void CBuildAndroidDlg::OnSetFocusAliasList() +{ + CComboBox *pAlias = (CComboBox *)GetDlgItem( IDC_BUILD_KEYALIAS ); + + if( pAlias->GetCount() == 0 ) + { + UpdateAliasList(); + pAlias->ShowDropDown( FALSE ); // Attempt to close dropdown, but doesn't seem to work + } +} + +BOOL CBuildAndroidDlg::OnHelpInfo(HELPINFO* helpInfoPointer) +{ + // Display help information related to this dialog. + // Note: If we don't handle this here, then SimulatorView::OnHelp() will get called which displays + // the main Corona documentation page on Corona Labs' website. + OnSysCommand(SC_CONTEXTHELP, 0); + return TRUE; +} + +// UpdateAliasList - Do the complicated work of validating the keystore password +// and reading the keystore to fill the alias list drop-down +void CBuildAndroidDlg::UpdateAliasList() +{ + CString sKeystorePath; + GetDlgItemText( IDC_BUILD_KEYSTORE, sKeystorePath ); + + CSimulatorApp *pApp = (CSimulatorApp *)AfxGetApp(); + + if( sKeystorePath != m_sPrevKeystorePath ) // skip if we already did all this + { + m_sPrevKeystorePath = sKeystorePath; // remember previous path + + // Clear alias dropdown + CComboBox *pAliasList = (CComboBox *)GetDlgItem( IDC_BUILD_KEYALIAS ); + pAliasList->ResetContent(); + OnChangeAliasList(); + + // If keystore path is empty, return now + if( sKeystorePath.IsEmpty() ) + { + return; + } + + // Check for existence of keystore file before trying to parse it + if( ! pApp->CheckPathExists( sKeystorePath ) ) + { + DisplayWarningMessage(IDS_ANDROID_KEYSTORE_FILE_NOT_FOUND, sKeystorePath); + return; + } + + // Get keystore password + CString sPassword = _T(""); + m_pProject->ClearKeystorePassword(); // new keystore, new password needed + + // Known password for the keystore we install, don't prompt user + if( ! sKeystorePath.CompareNoCase( CCoronaProject::GetTrialKeystorePath() ) ) + { + sPassword = GetTrialKeystorePassword(); + } + + // Loop until we get valid password, or until user clicks Cancel + bool bDone = false; + while (!bDone) + { + if( sPassword.IsEmpty() ) // show password dialog to get password + { + CPasswordDlg passwordDlg( this ); + passwordDlg.SetKey( _T("Keystore: ") + sKeystorePath ); + if( passwordDlg.DoModal() == IDOK ) + { + sPassword = passwordDlg.GetPassword(); + + // Need to save the password at least for the current build + m_pProject->SetKeystorePassword( sPassword ); + // Remember whether to save it to registry + m_pProject->SetSaveKeystorePassword( passwordDlg.GetSavePassword() ); + + // Save directory for future use in keystore open dialog + // Do here because all changes to keystore path end up here + m_sKeystoreDir = sKeystorePath.Left( sKeystorePath.ReverseFind(_T('\\'))); + } + else // password dialog was canceled + { + bDone = true; + m_sPrevKeystorePath = ""; // clear this so user can try again later + } + } + + if( ! bDone ) // user clicked OK + { + // Have password, try opening the keystore, post errors to user + bDone = ReadKeystore( sKeystorePath, sPassword, true ); + if( !bDone ) + { + sPassword = ""; // clear to try again + } + } + } + } +} + +// ReadKeystore - Use Java to read key alias list from keystore +// Posts errors to user if bShowErrors is true (default except from OnInitDialog) +// Returns true if password worked, false otherwise +bool CBuildAndroidDlg::ReadKeystore( CString sKeystorePath, CString sPassword, bool bShowErrors ) +{ + bool bPasswordSucceeded = false; + + // Scroll the keystore edit control so the end with the filename of the keystore is visible + CWnd *buildKeystoreField = GetDlgItem(IDC_BUILD_KEYSTORE); + if (buildKeystoreField != NULL) + { + DWORD len = buildKeystoreField->SendMessage( WM_GETTEXTLENGTH, 0, 0 ); + buildKeystoreField->SendMessage( EM_SETSEL, len, len); + buildKeystoreField->SendMessage( EM_SCROLLCARET, 0, 0 ); + } + + CComboBox *pAliasList = (CComboBox *)GetDlgItem( IDC_BUILD_KEYALIAS ); + + // Convert string arguments to UTF8 + WinString strKeystorePath, strPassword; + strKeystorePath.SetTCHAR( sKeystorePath ); + strPassword.SetTCHAR( sPassword ); + + ListKeyStore listKeyStore; // Uses Java to read keystore + + if( listKeyStore.GetAliasList( strKeystorePath.GetUTF8(), strPassword.GetUTF8() )) + { + bPasswordSucceeded = true; + + if( listKeyStore.GetSize() < 1 ) + { + CString msg, title; + msg.LoadString( IDS_KEYSTORE_ATLEASTONE ); + title.LoadString( IDS_ANDROIDBUILD ); + if( bShowErrors ) + { + MessageBox( msg, title, MB_ICONEXCLAMATION ); + } + } + else + { + // Succeeded and there is at least one alias - add aliases to alias dropdown + WinString strTitle; + for ( int i = 0; i < listKeyStore.GetSize(); i++ ) + { + strTitle.SetUTF8( listKeyStore.GetAlias(i) ); + int itemIndex = pAliasList->AddString( strTitle.GetTCHAR() ); + } + + // Insert "(Choose from the following)" + CString sChoose; + sChoose.LoadString( IDS_CHOOSEFOLLOWING ); + pAliasList->InsertString( 0, sChoose ); + + // if only one valid key, select that, otherwise select "(choose from the following)" + pAliasList->SetCurSel((pAliasList->GetCount() == 2) ? 1 : 0); + + OnChangeAliasList(); + } + } + else // didn't get valid password, or keystore bad format + { + CString msg, title; + msg.Format( IDS_INVALID_KEYSTORE_s, sKeystorePath ); + title.LoadString( IDS_ANDROIDBUILD ); + if( bShowErrors ) + { + MessageBox( msg, title, MB_ICONEXCLAMATION ); + } + } + + return bPasswordSucceeded; +} + +// OnBrowseSaveto - show directory selection dialog for build destination dir +void CBuildAndroidDlg::OnBrowseSaveto() +{ + CString sDir = _T(""); + GetDlgItemText( IDC_BUILD_SAVETO, sDir ); + + // Default to the system's Documents if the above field is empty. + if (sDir.IsEmpty()) + { + ::SHGetFolderPath(nullptr, CSIDL_MYDOCUMENTS, nullptr, 0, sDir.GetBuffer(MAX_PATH)); + sDir.ReleaseBuffer(); + } + + if (CBrowseDirDialog::Browse(sDir, IDS_SELECT_BUILD_OUTPUT_FOLDER_DESCRIPTION)) + { + SetDlgItemText( IDC_BUILD_SAVETO, sDir ); + } +} + +// OnChangeAliasList - validate Key alias - must have values in +// dropdown and have one selected. +// Also clear saved password if alias has changed. +// TODO: we always test with debug.keystore which only has one key alias, +// so this code needs more testing +void CBuildAndroidDlg::OnChangeAliasList() +{ + CComboBox *pAliasList = (CComboBox *)GetDlgItem( IDC_BUILD_KEYALIAS ); + + CString sValue; + GetDlgItemText( IDC_BUILD_KEYALIAS, sValue ); + + if( sValue != m_sPrevKeystoreAlias ) + { + m_pProject->ClearAliasPassword(); + m_sPrevKeystoreAlias = sValue; + } +} + +void CBuildAndroidDlg::OnSysCommand(UINT nID, LPARAM lParam) +{ + // Handle the received dialog system command. + if (SC_CONTEXTHELP == nID) + { + // The help [?] button or F1 key was pressed. + // Display the Android build documentation on Corona Labs' website. + try + { + const wchar_t kUrl[] = L"https://docs.coronalabs.com/daily/guide/distribution/androidBuild"; + ::ShellExecuteW(nullptr, L"open", kUrl, nullptr, nullptr, SW_SHOWNORMAL); + } + catch (...) {} + } + else + { + // Let the dialog perform its default handling on the received system command. + CDialog::OnSysCommand(nID, lParam); + } +} + + +//This will open and run a command promot window +void Exec(CString command) { + ::ShellExecute( + nullptr, + _T("open"), + _T("cmd"), + _T(" /K \"")+command+_T("\""), // params + nullptr, + SW_SHOW); +} + + +// OnOK - build project +// Retrieve values from dialog, save to registry, +// get key alias password if necessary +// test key alias password +// call core code to package project and send to server for building +void CBuildAndroidDlg::OnOK() // OnBuild() +{ + Rtt::TargetAndroidAppStore *pTargetStore = NULL; + CComboBox *pComboBox; + WinString stringBuffer; + CString sValue; + CString sKeystore; + CString sBuildDir; + CString sVersionName; + CString sPackageName; + CString sAppName; + CString sKeyAlias; + int iVersionCode; + int iIndex; + bool isLiveBuild; + + bool acceptedSDK = (AfxGetApp()->GetProfileString( REGISTRY_BUILD_ANDROID, _T("AcceptedSDKLicense"), _T("NO") ).Compare(_T("YES")) == 0); + if(!acceptedSDK) + { + UINT ret = DisplayWarningMessageWithHelp(IDS_ANDROID_BUILD, IDS_ANDROID_SDK_LICENSE, _T("https://developer.android.com/studio/terms")); + if (ret != IDYES) return; + AfxGetApp()->WriteProfileString( REGISTRY_BUILD_ANDROID, _T("AcceptedSDKLicense"), _T("YES") ); + } + + // Fetch and validate field values. + GetDlgItemText(IDC_BUILD_APPNAME, sAppName); + sAppName.Trim(); + if (sAppName.IsEmpty()) + { + DisplayWarningMessage(IDS_BUILD_APP_NAME_NOT_PROVIDED); + GetDlgItem(IDC_BUILD_APPNAME)->SetFocus(); + LogAnalytics("build-bungled", "reason", "BUILD_APP_NAME_NOT_PROVIDED"); + return; + } + GetDlgItemText(IDC_BUILD_VERSION_CODE, sValue); + sValue.Trim(); + if (sValue.IsEmpty()) + { + DisplayWarningMessage(IDS_BUILD_VERSION_NUMBER_NOT_PROVIDED); + GetDlgItem(IDC_BUILD_VERSION_CODE)->SetFocus(); + LogAnalytics("build-bungled", "reason", "BUILD_APP_VERSION_NUMBER_NOT_PROVIDED"); + return; + } + iVersionCode = _ttoi(sValue); + if (iVersionCode < 1) + { + DisplayWarningMessage(IDS_INVALID_ANDROID_APP_VERSION_NUMBER); + GetDlgItem(IDC_BUILD_VERSION_CODE)->SetFocus(); + LogAnalytics("build-bungled", "reason", "INVALID_ANDROID_APP_VERSION_NUMBER"); + return; + } + GetDlgItemText(IDC_BUILD_VERSION_NAME, sVersionName); + sVersionName.Trim(); + if (sVersionName.IsEmpty()) + { + DisplayWarningMessage(IDS_BUILD_VERSION_NAME_NOT_PROVIDED); + GetDlgItem(IDC_BUILD_VERSION_NAME)->SetFocus(); + LogAnalytics("build-bungled", "reason", "BUILD_VERSION_NAME_NOT_PROVIDED"); + return; + } + GetDlgItemText(IDC_BUILD_PACKAGE, sPackageName); + sPackageName.Trim(); + if (sPackageName.IsEmpty()) + { + DisplayWarningMessage(IDS_BUILD_PACKAGE_NAME_NOT_PROVIDED); + GetDlgItem(IDC_BUILD_PACKAGE)->SetFocus(); + LogAnalytics("build-bungled", "reason", "BUILD_PACKAGE_NAME_NOT_PROVIDED"); + return; + } + stringBuffer.SetTCHAR(sPackageName); + if (!Rtt_AndroidSupportTools_IsAndroidPackageName(m_androidValidatorLuaState, stringBuffer.GetUTF8())) + { + DisplayWarningMessage(IDS_VALID_PACKAGE); + GetDlgItem(IDC_BUILD_PACKAGE)->SetFocus(); + LogAnalytics("build-bungled", "reason", "bad-package-identifier"); + return; + } + pComboBox = (CComboBox*)GetDlgItem(IDC_BUILD_TARGET_APP_STORE); + iIndex = pComboBox->GetCurSel(); + if (iIndex >= 0) + { + pTargetStore = (Rtt::TargetAndroidAppStore*)pComboBox->GetItemDataPtr(iIndex); + } + if (!pTargetStore) + { + DisplayWarningMessage(IDS_BUILD_TARGET_APP_STORE_NOT_SELECTED); + pComboBox->SetFocus(); + LogAnalytics("build-bungled", "reason", "BUILD_TARGET_APP_STORE_NOT_SELECTED"); + return; + } + GetDlgItemText(IDC_BUILD_KEYSTORE, sKeystore); + sKeystore.Trim(); + if (sKeystore.IsEmpty()) + { + DisplayWarningMessage(IDS_ANDROID_KEYSTORE_FILE_NOT_PROVIDED); + GetDlgItem(IDC_BUILD_KEYSTORE)->SetFocus(); + LogAnalytics("build-bungled", "reason", "ANDROID_KEYSTORE_FILE_NOT_PROVIDED"); + return; + } + if (::PathFileExists(sKeystore) == FALSE) + { + DisplayWarningMessage(IDS_ANDROID_KEYSTORE_FILE_NOT_FOUND, sKeystore); + GetDlgItem(IDC_BUILD_KEYSTORE)->SetFocus(); + LogAnalytics("build-bungled", "reason", "ANDROID_KEYSTORE_FILE_NOT_FOUND"); + return; + } + GetDlgItemText(IDC_BUILD_KEYALIAS, sKeyAlias); + pComboBox = (CComboBox*)GetDlgItem(IDC_BUILD_KEYALIAS); + if ((pComboBox->GetCurSel() <= 0) || sKeyAlias.IsEmpty()) + { + DisplayWarningMessage(IDS_ANDROID_KEYALIAS_NOT_SELECTED); + GetDlgItem(IDC_BUILD_KEYALIAS)->SetFocus(); + LogAnalytics("build-bungled", "reason", "ANDROID_KEYALIAS_NOT_SELECTED"); + return; + } + GetDlgItemText(IDC_BUILD_SAVETO, sBuildDir); + sBuildDir.Trim(); + if (sBuildDir.IsEmpty()) + { + DisplayWarningMessage(IDS_BUILD_PATH_NOT_PROVIDED); + GetDlgItem(IDC_BUILD_SAVETO)->SetFocus(); + LogAnalytics("build-bungled", "reason", "BUILD_PATH_NOT_PROVIDED"); + return; + } + if (sBuildDir.Compare(m_pProject->GetDir()) == 0) + { + DisplayWarningMessage(IDS_BUILD_PATH_INVALID); + GetDlgItem(IDC_BUILD_SAVETO)->SetFocus(); + LogAnalytics("build-bungled", "reason", "BUILD_PATH_INVALID" ); + return; + } + if (::PathIsDirectory(sBuildDir) == FALSE) + { + // The given path does not exist. Attempt to create it. If we are unable to create the directory, + // then that may mean the path is invalid or we do not have permission to create it at that location. + int result = ::SHCreateDirectoryEx(NULL, sBuildDir, NULL); + if (result != ERROR_SUCCESS) + { + DisplayWarningMessage(IDS_BUILD_PATH_CREATION_FAILED, sBuildDir); + GetDlgItem(IDC_BUILD_SAVETO)->SetFocus(); + LogAnalytics("build-bungled", "reason", "BUILD_PATH_CREATION_FAILED"); + return; + } + } + isLiveBuild = (IsDlgButtonChecked(IDC_CREATE_LIVE_BUILD) == BST_CHECKED); + + CString afterBuild = _T("0"); + CButton* pCopyToDevice = (CButton*)GetDlgItem(IDC_COPY_TO_DEVICE); + CButton* pShowInFiles = (CButton*)GetDlgItem(IDC_SHOW_IN_FILES); + if (pCopyToDevice->GetCheck() == BST_CHECKED) + afterBuild = _T("2"); + else if (pShowInFiles->GetCheck() == BST_CHECKED) + afterBuild = _T("1"); + + // Store field settings to project. + m_pProject->SetName(sAppName); + m_pProject->SetAndroidVersionCode(iVersionCode); + m_pProject->SetAndroidVersionName(sVersionName); + m_pProject->SetPackage(sPackageName); + m_pProject->SetKeystorePath(sKeystore); + m_pProject->SetAlias(sKeyAlias); + m_pProject->SetSaveDir(sBuildDir); + m_pProject->SetTargetOS(_T("Android 2.3.3")); // <- This string is only used by logging/analytics. + m_pProject->SetCreateLiveBuild(isLiveBuild); + m_pProject->SetAfterBuild(afterBuild); + + // Update global build settings in registry. + stringBuffer.SetUTF8(pTargetStore->GetStringId()); + AfxGetApp()->WriteProfileString( REGISTRY_BUILD_ANDROID, REGISTRY_TARGET_APP_STORE, stringBuffer.GetTCHAR() ); + AfxGetApp()->WriteProfileString( REGISTRY_BUILD_ANDROID, REGISTRY_KEYSTOREDIR, m_sKeystoreDir ); + AfxGetApp()->WriteProfileString( REGISTRY_BUILD_ANDROID, REGISTRY_LASTKEYSTORE, sKeystore ); + + // Third argument is what this is a password for, not value of password + m_pProject->RegistryPutKeystorePassword(REGISTRY_BUILD_ANDROID, REGISTRY_LASTKEYSTOREPWD, sKeystore); + + // We know the Key Alias password for the trial keystore + if (!sKeystore.CompareNoCase(CCoronaProject::GetTrialKeystorePath())) + { + m_pProject->SetKeystorePassword(GetTrialKeystorePassword()); + m_pProject->SetAliasPassword(GetTrialKeyAliasPassword()); + } + + // Loop until a valid password has been received or until the user cancels out. + // TODO: Password validation should be done in the password dialog. That would eliminate the need for this loop. + CString sAliasPassword = m_pProject->GetAliasPassword(); + bool bDone = false; + while (!bDone) + { + // Ask for the user's password if the user has not provided one yet. + if (sAliasPassword.IsEmpty()) + { + CPasswordDlg passwordDlg( this ); + passwordDlg.SetKey( _T("Key alias: ") + sKeyAlias ); + if (passwordDlg.DoModal() != IDOK) + { + LogAnalytics("build-bungled", "reason", "cancel-android-key-password"); + return; + } + sAliasPassword = passwordDlg.GetPassword(); + m_pProject->SetAliasPassword( sAliasPassword ); + m_pProject->SetSaveAliasPassword( passwordDlg.GetSavePassword() ); + } + + // Validate user's password. + if (!bDone) + { + if (m_pProject->ValidateKeystoreAliasPassword()) + { + // Password is valid. + bDone = true; + } + else + { + // Password is invalid. + DisplayWarningMessage(IDS_INVALID_ALIAS, m_pProject->GetAlias()); + sAliasPassword.Empty(); + } + } + } + + LogAnalytics("build", "store", pTargetStore->GetStringId()); + + m_pProject->Save(); + CBuildProgressDlg buildDialog; + buildDialog.SetProjectSettings(m_pProject); + buildDialog.SetTargetedAppStore(pTargetStore); + buildDialog.DoModal(); + CBuildResult result = buildDialog.GetBuildResult(); + + // Inform the user if the build has failed. Do not close this window on failure. + if (result.HasFailed()) + { + CString title; + title.LoadString(IDS_WARNING); + CHtmlMessageDlg htmlMessageDialog; + htmlMessageDialog.SetTitle(title); + htmlMessageDialog.SetHtmlFromMarkdown(result.GetStatusMessage()); + htmlMessageDialog.DoModal(); + return; + } + + //After Build Options + if (afterBuild == AB_COPY_TO_DEVICE) // Copy to Device + { + if (PathFileExists(_T("C:\\Program Files (x86)\\Android\\android-sdk\\platform-tools\\adb.exe"))) { // this should be where adb is installed + CString apkPath = m_pProject->GetSaveDir() + _T("\\") + m_pProject->GetName() + _T(".apk"); // apk path + Exec(_T("cd C:\\Program Files (x86)\\Android\\android-sdk\\platform-tools & adb install -r \"") + apkPath + _T("\" & adb logcat Corona:v *:s")); // install apk and print logs + } + else { // adb is not installed + DisplayWarningMessageWithHelp(IDS_ADB_NOT_INSTALLED, IDS_ADB_NOT_INSTALLED_WARNING, _T("https://docs.coronalabs.com/guide/basics/debugging/index.html#device-debugging-android"), false); + } + + } + else if (afterBuild == AB_SHOW_IN_FILES) + { + ShellExecute(NULL, _T("open"), m_pProject->GetSaveDir(), NULL, NULL, SW_SHOWNORMAL); + } + // The build has succeeded. Inform the user. + CMessageDlg messageDlg(this); + messageDlg.SetText(IDS_BUILD_SUCCEEDED); + messageDlg.SetDefaultText(IDS_DONE); + //messageDlg.SetAltText( IDS_VIEW_EXPLORER ); //Remove because we give user a choice already + //messageDlg.SetFolder( m_pProject->GetSaveDir() ); + messageDlg.SetIconStyle(MB_ICONINFORMATION); + messageDlg.DoModal(); + + // Add the project to the Corona Live Server list, if enabled. + if (isLiveBuild) + { + CString sCoronaLiveServerExe = ((CSimulatorApp *)AfxGetApp())->GetApplicationDir() + _T("\\Corona.LiveServer.exe"); + CString sAppPath = m_pProject->GetPath(); + try + { + ::ShellExecute(nullptr, nullptr, sCoronaLiveServerExe, sAppPath, nullptr, SW_SHOWNORMAL); + } + catch (...) {} + } + + + + // Close this window. + CDialog::OnOK(); +} + +// OnCancel - clean up, exit +void CBuildAndroidDlg::OnCancel() +{ + // remove temp passwords + if (m_pProject) + { + m_pProject->ClearKeystorePassword(); + m_pProject->ClearAliasPassword(); + } + + CDialog::OnCancel(); +} + +// GetTrialKeystorePassword +CString CBuildAndroidDlg::GetTrialKeystorePassword() +{ + return _T("android"); +} + +// GetTrialKeyAliasPassword - sole key alias is androiddebugkey +// I noticed that signing seems to succeed with any password for the trial key alias +CString CBuildAndroidDlg::GetTrialKeyAliasPassword() +{ + return _T("android"); +} + +// Display a warning message box with the given message. +// Argument "nMessageID" is a unique ID to a string in the resource file's string table. +void CBuildAndroidDlg::DisplayWarningMessage(UINT nMessageID) +{ + CString title; + CString message; + + title.LoadString(IDS_WARNING); + message.LoadString(nMessageID); + MessageBox(message, title, MB_OK | MB_ICONWARNING); +} + +// Display a warning message box with the given message and string. +// Argument "nMessageID" is a unique ID to a string in the resource file's string table. +void CBuildAndroidDlg::DisplayWarningMessage(UINT nMessageID, CString extraInfo) +{ + CString title; + CString message; + + title.LoadString(IDS_WARNING); + message.LoadString(nMessageID); + message.Append(_T("\r\n\r\n")); + message.Append(extraInfo); + MessageBox(message, title, MB_OK | MB_ICONWARNING); +} + +void CALLBACK CBuildAndroidDlg::HelpCallback(LPHELPINFO lpHelpInfo) +{ + // AfxGetApp()->WinHelp(lpHelpInfo->dwContextId); + + try + { + ::ShellExecuteW(nullptr, L"open", m_sHelpURL, nullptr, nullptr, SW_SHOWNORMAL); + } + catch (...) {} +} + +UINT CBuildAndroidDlg::DisplayWarningMessageWithHelp(UINT nTitleID, UINT nMessageID, CString helpURL, bool isYesNo) +{ + MSGBOXPARAMS mbp; + CString title; + CString message; + + title.LoadString(nTitleID); + message.LoadString(nMessageID); + + memset(&mbp, 0, sizeof mbp); + + m_sHelpURL = helpURL; + + mbp.cbSize = sizeof MSGBOXPARAMS; + mbp.hwndOwner = m_hWnd; + mbp.hInstance = AfxGetInstanceHandle(); + mbp.lpszText = message; + + // if you wanted to specify a different caption, here is where you do it + mbp.lpszCaption = title; + if (isYesNo) { //default YES NO + mbp.dwStyle = MB_YESNO | MB_ICONWARNING | MB_HELP; + } + else { + mbp.dwStyle = MB_ICONWARNING | MB_HELP; + } + + + // mbp.lpszIcon = ; // note, you could provide your own custom ICON here! + + mbp.dwContextHelpId = 1; // not used + mbp.lpfnMsgBoxCallback = (MSGBOXCALLBACK) &HelpCallback; + mbp.dwLanguageId = 0x0409; + + return ::MessageBoxIndirect(&mbp); +} + + + +void CBuildAndroidDlg::OnBnClickedCreateLiveBuild() +{ + // Check that they have the Debug keystore selected if they want a Live Build + if (IsDlgButtonChecked(IDC_CREATE_LIVE_BUILD) == BST_CHECKED) + { + CString sKeystorePath; + GetDlgItemText(IDC_BUILD_KEYSTORE, sKeystorePath); + + if( sKeystorePath.CompareNoCase( CCoronaProject::GetTrialKeystorePath() ) != 0 ) + { + CString title; + CString message; + DWORD answer = IDNO; + + title.LoadString(IDS_CREATE_LIVE_BUILD); + message.LoadString(IDS_CREATE_LIVE_BUILD_WARNING); + + answer = DisplayWarningMessageWithHelp(IDS_CREATE_LIVE_BUILD, IDS_CREATE_LIVE_BUILD_WARNING, _T("https://docs.coronalabs.com/guide/distribution/liveBuild/")); + + if (answer == IDYES) + { + SetDlgItemText(IDC_BUILD_KEYSTORE, CCoronaProject::GetTrialKeystorePath()); + UpdateAliasList(); + } + } + } +} + +void CBuildAndroidDlg::LogAnalytics(const char *eventName, const char *key, const char *value) +{ + Rtt_ASSERT(GetWinProperties()->GetAnalytics() != NULL); + Rtt_ASSERT(eventName != NULL && strlen(eventName) > 0); + + // NEEDSWORK: this is horrible + size_t numItems = 2; + char **dataKeys = (char **)calloc(sizeof(char *), numItems); + char **dataValues = (char **)calloc(sizeof(char *), numItems); + + dataKeys[0] = _strdup("target"); + dataValues[0] = _strdup("android"); + if (key != NULL && value != NULL) + { + dataKeys[1] = _strdup(key); + dataValues[1] = _strdup(value); + } + else + { + numItems = 1; + } + + if (GetWinProperties()->GetAnalytics() != NULL) + { + GetWinProperties()->GetAnalytics()->Log(eventName, numItems, dataKeys, dataValues); + } + + free(dataKeys[0]); + free(dataValues[0]); + if (numItems > 1) + { + free(dataKeys[1]); + free(dataValues[1]); + } + free(dataKeys); + free(dataValues); +} From 957245520b624b7954895629ef1ef10b1b82bf4b Mon Sep 17 00:00:00 2001 From: Scott Harrison Date: Fri, 3 Mar 2023 21:23:35 -0600 Subject: [PATCH 4/6] Change CMD flag to close when done --- platform/windows/Corona.Simulator/BuildAndroidDlg.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/windows/Corona.Simulator/BuildAndroidDlg.cpp b/platform/windows/Corona.Simulator/BuildAndroidDlg.cpp index 9cb971d5f..5b4a2d5f7 100644 --- a/platform/windows/Corona.Simulator/BuildAndroidDlg.cpp +++ b/platform/windows/Corona.Simulator/BuildAndroidDlg.cpp @@ -563,7 +563,7 @@ void Exec(CString command) { nullptr, _T("open"), _T("cmd"), - _T(" /K \"")+command+_T("\""), // params + _T(" /C \"")+command+_T("\""), // params nullptr, SW_SHOW); } From bcb7852c6490a00eb820b7a181bd90b1c901fab1 Mon Sep 17 00:00:00 2001 From: Vlad Svoka Date: Sat, 4 Mar 2023 21:20:40 -0800 Subject: [PATCH 5/6] Delete BuildAndroidDlg.cpp --- .../BuildAndroidDlg.cpp | 1029 ----------------- 1 file changed, 1029 deletions(-) delete mode 100644 platform/windows/enc_temp_folder/7c24e61fe51de841fc62ed235c2cf3b/BuildAndroidDlg.cpp diff --git a/platform/windows/enc_temp_folder/7c24e61fe51de841fc62ed235c2cf3b/BuildAndroidDlg.cpp b/platform/windows/enc_temp_folder/7c24e61fe51de841fc62ed235c2cf3b/BuildAndroidDlg.cpp deleted file mode 100644 index 8231bac61..000000000 --- a/platform/windows/enc_temp_folder/7c24e61fe51de841fc62ed235c2cf3b/BuildAndroidDlg.cpp +++ /dev/null @@ -1,1029 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -// -// This file is part of the Corona game engine. -// For overview and more information on licensing please refer to README.md -// Home page: https://github.com/coronalabs/corona -// Contact: support@coronalabs.com -// -////////////////////////////////////////////////////////////////////////////// - -#include "stdafx.h" -#include "Simulator.h" -#include "SimulatorView.h" -#include "Resource.h" -#include "CoronaProject.h" -#include "PasswordDlg.h" -#include "BuildAndroidDlg.h" -#include "BuildProgressDlg.h" -#include "BuildResult.h" -#include "WinGlobalProperties.h" -#include "WinString.h" -#include "BrowseDirDialog.h" -#include "HtmlMessageDlg.h" -#include "MessageDlg.h" -#include "ListKeyStore.h" -#include "CoronaInterface.h" -#include "Core/Rtt_Build.h" -#include "Rtt_AndroidSupportTools.h" -#include "Rtt_SimulatorAnalytics.h" -#include "Rtt_TargetDevice.h" -#include "Rtt_TargetAndroidAppStore.h" -#include -#include -#include -#include - -// CBuildAndroidDlg dialog - -CString CBuildAndroidDlg::m_sHelpURL; - -IMPLEMENT_DYNAMIC(CBuildAndroidDlg, CDialog) - -CBuildAndroidDlg::CBuildAndroidDlg(CWnd* pParent /*=NULL*/) - : CDialog(CBuildAndroidDlg::IDD, pParent), - m_pProject( NULL ), - m_sPrevKeystorePath( "" ), - m_sKeystoreDir( "" ), - m_nValidFields( 0 ), - m_androidValidatorLuaState( NULL ) -{ -} - -CBuildAndroidDlg::~CBuildAndroidDlg() -{ - if (m_androidValidatorLuaState) - { - Rtt_AndroidSupportTools_CloseLuaState(m_androidValidatorLuaState); - } -} - -void CBuildAndroidDlg::DoDataExchange(CDataExchange* pDX) -{ - CDialog::DoDataExchange(pDX); -} - - -BEGIN_MESSAGE_MAP(CBuildAndroidDlg, CDialog) - ON_BN_CLICKED(IDC_BUILD_BROWSE_KEYSTORE, &CBuildAndroidDlg::OnBrowseKeystore) - ON_BN_CLICKED(IDC_BUILD_BROWSE_SAVETO, &CBuildAndroidDlg::OnBrowseSaveto) - ON_EN_KILLFOCUS(IDC_BUILD_KEYSTORE, &CBuildAndroidDlg::OnKillFocusKeystorePath) - ON_CBN_SELCHANGE(IDC_BUILD_KEYALIAS, &CBuildAndroidDlg::OnChangeAliasList) - ON_CBN_SETFOCUS(IDC_BUILD_KEYALIAS, &CBuildAndroidDlg::OnSetFocusAliasList) - ON_WM_HELPINFO() - ON_WM_SYSCOMMAND() - ON_BN_CLICKED(IDC_CREATE_LIVE_BUILD, &CBuildAndroidDlg::OnBnClickedCreateLiveBuild) -END_MESSAGE_MAP() - -// OnInitDialog - restore settings from m_pProject if available. -// Choose likely defaults for non-saved settings. -// Check for trial users, who can only use installed debug.keystore -BOOL CBuildAndroidDlg::OnInitDialog() -{ - WinString stringConverter; - CString stringBuffer; - - // Initialize base class first. - CDialog::OnInitDialog(); - - // Do not display this window if not given a project settings object. - if (!m_pProject) - { - CDialog::OnCancel(); - return TRUE; - } - - //Set inital project type now that we have Android/Web (used by the BuildProgressDlg - does not indicate target app store) - m_pProject->SetTargetPlatform(Rtt::TargetDevice::kAndroidPlatform); - - // Initialize the Android validator. - WinString androidValidatorFilePath; - androidValidatorFilePath.SetUTF8(GetWinProperties()->GetResourcesDir()); - if ((androidValidatorFilePath.GetLength() > 0) && !androidValidatorFilePath.EndsWith("\\")) - { - androidValidatorFilePath.Append("\\"); - } - androidValidatorFilePath.Append("AndroidValidation.lua"); - m_androidValidatorLuaState = Rtt_AndroidSupportTools_NewLuaState(androidValidatorFilePath.GetUTF8()); - - // Limit the text length of CEdit boxes. - ((CEdit*)GetDlgItem(IDC_BUILD_APPNAME))->SetLimitText(128); - ((CEdit*)GetDlgItem(IDC_BUILD_VERSION_CODE))->SetLimitText(9); - ((CEdit*)GetDlgItem(IDC_BUILD_VERSION_NAME))->SetLimitText(16); - ((CEdit*)GetDlgItem(IDC_BUILD_PACKAGE))->SetLimitText(128); - ((CEdit*)GetDlgItem(IDC_BUILD_KEYSTORE))->SetLimitText(MAX_PATH - 1); - ((CEdit*)GetDlgItem(IDC_BUILD_SAVETO))->SetLimitText(MAX_PATH - 1); - - // Fetch the last selected app store. - stringConverter.SetUTF8(Rtt::TargetAndroidAppStore::kGoogle.GetStringId()); - stringBuffer = AfxGetApp()->GetProfileString( - REGISTRY_BUILD_ANDROID, REGISTRY_TARGET_APP_STORE, stringConverter.GetTCHAR()); - stringConverter.SetTCHAR(stringBuffer); - Rtt::TargetAndroidAppStore *pLastSelectedStore = - Rtt::TargetAndroidAppStore::GetByStringId(stringConverter.GetUTF8()); - - // Set up the app store combo box. - CComboBox *pStoreComboBox = (CComboBox*)GetDlgItem(IDC_BUILD_TARGET_APP_STORE); - int iStoreCount = Rtt::TargetAndroidAppStore::GetCount(); - for (int iStoreIndex = 0; iStoreIndex < iStoreCount; iStoreIndex++) - { - Rtt::TargetAndroidAppStore *pNextStore = Rtt::TargetAndroidAppStore::GetByIndex(iStoreIndex); - if (pNextStore != NULL) - { - stringConverter.SetUTF8(pNextStore->GetName()); - int iComboBoxIndex = pStoreComboBox->AddString(stringConverter.GetTCHAR()); - if (iComboBoxIndex >= 0) - { - pStoreComboBox->SetItemDataPtr(iComboBoxIndex, (void*)pNextStore); - if (pNextStore == pLastSelectedStore) - { - pStoreComboBox->SetCurSel(iComboBoxIndex); - } - if ((pStoreComboBox->GetCurSel() < 0) && - (pNextStore == &Rtt::TargetAndroidAppStore::kGoogle)) - { - pStoreComboBox->SetCurSel(iComboBoxIndex); - } - } - } - } - - m_sKeystoreDir = AfxGetApp()->GetProfileString( REGISTRY_BUILD_ANDROID, REGISTRY_KEYSTOREDIR, - ((CSimulatorApp *)AfxGetApp())->GetResourceDir() ); // default to resource dir (where debug.keystore is) - CString sLastKeystore = AfxGetApp()->GetProfileString( REGISTRY_BUILD_ANDROID, REGISTRY_LASTKEYSTORE, _T("") ); - - m_sPrevKeystorePath = _T(""); - m_nValidFields = 0; - - // If there isn't a package name, create one by reversing the user's email address and adding the app name - if (m_pProject->GetPackage().IsEmpty()) - { - CString package("com.solar2d.app."); - package.Append(m_pProject->GetName()); - - for (int c = 0; c < package.GetLength(); c++) - { - if (package[c] > 255 || (!isalnum(package[c]) && package[c] != '.' && package[c] != '_')) - { - package.SetAt(c, _T('_')); - } - } - - package.Trim(_T("._")); - - m_pProject->SetPackage(package); - } - - stringBuffer.Format(_T("%d"), m_pProject->GetAndroidVersionCode()); - SetDlgItemText( IDC_BUILD_APPNAME, m_pProject->GetName() ); - SetDlgItemText( IDC_BUILD_VERSION_CODE, stringBuffer ); - SetDlgItemText( IDC_BUILD_VERSION_NAME, m_pProject->GetAndroidVersionName() ); - SetDlgItemText( IDC_BUILD_PACKAGE, m_pProject->GetPackage() ); - SetDlgItemText( IDC_BUILD_PROJECTPATH, m_pProject->GetDir() ); - - CSimulatorApp *pApp = (CSimulatorApp *)AfxGetApp(); - - // Initialize keystore path from, in order available - // 1. saved keystore path for this project - // 2. last used keystore path (also get last-used password) - // (if neither are available, there is also a saved keystore directory for browsing) - { - if( m_pProject->GetKeystorePath().IsEmpty() ) // none saved for project, get last-used path - { - if (sLastKeystore.IsEmpty()) - { - SetDlgItemText( IDC_BUILD_KEYSTORE, CCoronaProject::GetTrialKeystorePath() ); - m_pProject->SetKeystorePassword( GetTrialKeystorePassword() ); - } - else - { - if ( ! pApp->CheckPathExists( sLastKeystore ) ) - { - DisplayWarningMessage(IDS_ANDROID_KEYSTORE_FILE_NOT_FOUND, sLastKeystore); - } - else - { - SetDlgItemText( IDC_BUILD_KEYSTORE, sLastKeystore ); - // Third argument tells what this password is for - m_pProject->RegistryGetKeystorePassword( REGISTRY_BUILD_ANDROID, REGISTRY_LASTKEYSTOREPWD, sLastKeystore ); - } - } - } - else // use the one saved with this project - { - if ( ! pApp->CheckPathExists( m_pProject->GetKeystorePath() ) ) - { - DisplayWarningMessage(IDS_ANDROID_KEYSTORE_FILE_NOT_FOUND, m_pProject->GetKeystorePath()); - } - else - { - SetDlgItemText( IDC_BUILD_KEYSTORE, m_pProject->GetKeystorePath() ); - } - } - } - - // After all that, get the values for keystore and password and try to initialize alias list - CString sKeystore, sKeystorePassword; - GetDlgItemText( IDC_BUILD_KEYSTORE, sKeystore ); - - // Non-trial user with our installed keystore - if( sKeystore.CompareNoCase( CCoronaProject::GetTrialKeystorePath() ) == 0 ) - { - m_pProject->SetKeystorePassword( GetTrialKeystorePassword() ); - } - // For all cases, set variable to pass in to ReadKeystore - sKeystorePassword = m_pProject->GetKeystorePassword( sKeystore ); // argument has to match what pwd is for - - ReadKeystore( sKeystore, sKeystorePassword, false ); // bShowErrors=false, dialog not visible yet - - // Choose the saved key alias in the key alias dropdown - CComboBox *pAlias = (CComboBox *)GetDlgItem( IDC_BUILD_KEYALIAS ); - if( ! m_pProject->GetAlias().IsEmpty() ) - { - pAlias->SelectString( -1, m_pProject->GetAlias() ); - OnChangeAliasList(); - } - - // Initialize build destination directory. - SetDlgItemText(IDC_BUILD_SAVETO, m_pProject->GetSaveDir()); - - // Set up the "Live Build" checkbox. - CheckDlgButton(IDC_CREATE_LIVE_BUILD, m_pProject->GetCreateLiveBuild() ? BST_CHECKED : BST_UNCHECKED); - - // Set up the "Build to Device" Radio Group - CButton* pCopyToDevice = (CButton*)GetDlgItem(IDC_COPY_TO_DEVICE); - CButton* pShowInFiles = (CButton*)GetDlgItem(IDC_SHOW_IN_FILES); - CButton* pDoNothing = (CButton*)GetDlgItem(IDC_DO_NOTHING); - - pCopyToDevice->SetCheck((m_pProject->GetAfterBuild() == AB_COPY_TO_DEVICE) ? BST_CHECKED : BST_UNCHECKED); - pShowInFiles->SetCheck((m_pProject->GetAfterBuild() == AB_SHOW_IN_FILES) ? BST_CHECKED : BST_UNCHECKED); - pDoNothing->SetCheck((m_pProject->GetAfterBuild() == AB_DO_NOTHING || m_pProject->GetAfterBuild() == "") ? BST_CHECKED : BST_UNCHECKED); - OutputDebugString(_T("Run123/")); - OutputDebugString(m_pProject->GetAfterBuild()); - - return TRUE; // return TRUE unless you set the focus to a control - // EXCEPTION: OCX Property Pages should return FALSE -} - -// SetProject - called before DoModal to set the associated project. -void CBuildAndroidDlg::SetProject( const std::shared_ptr& pProject ) -{ - m_pProject = pProject; // leave unchanged until OnOK() -} - -// BuildAndroidDlg message handlers - -// OnBrowseKeystore - check authorization, then allow user to select keystore. -// Then call UpdateAliasList which gets password, reads keystore, and fills -// Key Alias dropdown. -void CBuildAndroidDlg::OnBrowseKeystore() -{ - { - GetDlgItem( IDC_BUILD_KEYSTORE )->EnableWindow( TRUE ); // may have just purchased - - // Show Open dialog so user can browse to a new keystore - CString sPath = _T(""); - GetDlgItemText( IDC_BUILD_KEYSTORE, sPath ); - - CString sFilter = _T("Keystore files (*.keystore)|*.keystore|All Files (*.*)|*.*||"); - CFileDialog fileDlg( TRUE, NULL, sPath, OFN_FILEMUSTEXIST, sFilter); - - fileDlg.m_ofn.lStructSize = sizeof( fileDlg.m_ofn ); - fileDlg.m_ofn.lpstrTitle = _T("Select Keystore"); - fileDlg.m_ofn.lpstrInitialDir = m_sKeystoreDir; - - if( fileDlg.DoModal() == IDOK ) - { - // Display selected filename - sPath = fileDlg.GetPathName(); - SetDlgItemText( IDC_BUILD_KEYSTORE, sPath ); - - // Update Alias dropdown - UpdateAliasList(); - } - } -} - -// OnKillFocusKeystorePath - ask for password when user leaves Keystore edit field, -// unless focus leaves window or is going to Cancel -void CBuildAndroidDlg::OnKillFocusKeystorePath() -{ - // Unless focus is still within dlg and on Cancel, update aliases - // TODO: What if someone alt-tabs away from the dialog and then - // clicks somewhere else? - CWnd *pFocus = CWnd::GetFocus(); - if( pFocus - && (pFocus->GetParent() == this) - && (pFocus->GetDlgCtrlID() == IDCANCEL) ) - { - return; - } - - UpdateAliasList(); -} - -// OnSetFocusAliasLIst - when focus goes to alias list dropdown, check if it's -// empty and ask for keystore password. -void CBuildAndroidDlg::OnSetFocusAliasList() -{ - CComboBox *pAlias = (CComboBox *)GetDlgItem( IDC_BUILD_KEYALIAS ); - - if( pAlias->GetCount() == 0 ) - { - UpdateAliasList(); - pAlias->ShowDropDown( FALSE ); // Attempt to close dropdown, but doesn't seem to work - } -} - -BOOL CBuildAndroidDlg::OnHelpInfo(HELPINFO* helpInfoPointer) -{ - // Display help information related to this dialog. - // Note: If we don't handle this here, then SimulatorView::OnHelp() will get called which displays - // the main Corona documentation page on Corona Labs' website. - OnSysCommand(SC_CONTEXTHELP, 0); - return TRUE; -} - -// UpdateAliasList - Do the complicated work of validating the keystore password -// and reading the keystore to fill the alias list drop-down -void CBuildAndroidDlg::UpdateAliasList() -{ - CString sKeystorePath; - GetDlgItemText( IDC_BUILD_KEYSTORE, sKeystorePath ); - - CSimulatorApp *pApp = (CSimulatorApp *)AfxGetApp(); - - if( sKeystorePath != m_sPrevKeystorePath ) // skip if we already did all this - { - m_sPrevKeystorePath = sKeystorePath; // remember previous path - - // Clear alias dropdown - CComboBox *pAliasList = (CComboBox *)GetDlgItem( IDC_BUILD_KEYALIAS ); - pAliasList->ResetContent(); - OnChangeAliasList(); - - // If keystore path is empty, return now - if( sKeystorePath.IsEmpty() ) - { - return; - } - - // Check for existence of keystore file before trying to parse it - if( ! pApp->CheckPathExists( sKeystorePath ) ) - { - DisplayWarningMessage(IDS_ANDROID_KEYSTORE_FILE_NOT_FOUND, sKeystorePath); - return; - } - - // Get keystore password - CString sPassword = _T(""); - m_pProject->ClearKeystorePassword(); // new keystore, new password needed - - // Known password for the keystore we install, don't prompt user - if( ! sKeystorePath.CompareNoCase( CCoronaProject::GetTrialKeystorePath() ) ) - { - sPassword = GetTrialKeystorePassword(); - } - - // Loop until we get valid password, or until user clicks Cancel - bool bDone = false; - while (!bDone) - { - if( sPassword.IsEmpty() ) // show password dialog to get password - { - CPasswordDlg passwordDlg( this ); - passwordDlg.SetKey( _T("Keystore: ") + sKeystorePath ); - if( passwordDlg.DoModal() == IDOK ) - { - sPassword = passwordDlg.GetPassword(); - - // Need to save the password at least for the current build - m_pProject->SetKeystorePassword( sPassword ); - // Remember whether to save it to registry - m_pProject->SetSaveKeystorePassword( passwordDlg.GetSavePassword() ); - - // Save directory for future use in keystore open dialog - // Do here because all changes to keystore path end up here - m_sKeystoreDir = sKeystorePath.Left( sKeystorePath.ReverseFind(_T('\\'))); - } - else // password dialog was canceled - { - bDone = true; - m_sPrevKeystorePath = ""; // clear this so user can try again later - } - } - - if( ! bDone ) // user clicked OK - { - // Have password, try opening the keystore, post errors to user - bDone = ReadKeystore( sKeystorePath, sPassword, true ); - if( !bDone ) - { - sPassword = ""; // clear to try again - } - } - } - } -} - -// ReadKeystore - Use Java to read key alias list from keystore -// Posts errors to user if bShowErrors is true (default except from OnInitDialog) -// Returns true if password worked, false otherwise -bool CBuildAndroidDlg::ReadKeystore( CString sKeystorePath, CString sPassword, bool bShowErrors ) -{ - bool bPasswordSucceeded = false; - - // Scroll the keystore edit control so the end with the filename of the keystore is visible - CWnd *buildKeystoreField = GetDlgItem(IDC_BUILD_KEYSTORE); - if (buildKeystoreField != NULL) - { - DWORD len = buildKeystoreField->SendMessage( WM_GETTEXTLENGTH, 0, 0 ); - buildKeystoreField->SendMessage( EM_SETSEL, len, len); - buildKeystoreField->SendMessage( EM_SCROLLCARET, 0, 0 ); - } - - CComboBox *pAliasList = (CComboBox *)GetDlgItem( IDC_BUILD_KEYALIAS ); - - // Convert string arguments to UTF8 - WinString strKeystorePath, strPassword; - strKeystorePath.SetTCHAR( sKeystorePath ); - strPassword.SetTCHAR( sPassword ); - - ListKeyStore listKeyStore; // Uses Java to read keystore - - if( listKeyStore.GetAliasList( strKeystorePath.GetUTF8(), strPassword.GetUTF8() )) - { - bPasswordSucceeded = true; - - if( listKeyStore.GetSize() < 1 ) - { - CString msg, title; - msg.LoadString( IDS_KEYSTORE_ATLEASTONE ); - title.LoadString( IDS_ANDROIDBUILD ); - if( bShowErrors ) - { - MessageBox( msg, title, MB_ICONEXCLAMATION ); - } - } - else - { - // Succeeded and there is at least one alias - add aliases to alias dropdown - WinString strTitle; - for ( int i = 0; i < listKeyStore.GetSize(); i++ ) - { - strTitle.SetUTF8( listKeyStore.GetAlias(i) ); - int itemIndex = pAliasList->AddString( strTitle.GetTCHAR() ); - } - - // Insert "(Choose from the following)" - CString sChoose; - sChoose.LoadString( IDS_CHOOSEFOLLOWING ); - pAliasList->InsertString( 0, sChoose ); - - // if only one valid key, select that, otherwise select "(choose from the following)" - pAliasList->SetCurSel((pAliasList->GetCount() == 2) ? 1 : 0); - - OnChangeAliasList(); - } - } - else // didn't get valid password, or keystore bad format - { - CString msg, title; - msg.Format( IDS_INVALID_KEYSTORE_s, sKeystorePath ); - title.LoadString( IDS_ANDROIDBUILD ); - if( bShowErrors ) - { - MessageBox( msg, title, MB_ICONEXCLAMATION ); - } - } - - return bPasswordSucceeded; -} - -// OnBrowseSaveto - show directory selection dialog for build destination dir -void CBuildAndroidDlg::OnBrowseSaveto() -{ - CString sDir = _T(""); - GetDlgItemText( IDC_BUILD_SAVETO, sDir ); - - // Default to the system's Documents if the above field is empty. - if (sDir.IsEmpty()) - { - ::SHGetFolderPath(nullptr, CSIDL_MYDOCUMENTS, nullptr, 0, sDir.GetBuffer(MAX_PATH)); - sDir.ReleaseBuffer(); - } - - if (CBrowseDirDialog::Browse(sDir, IDS_SELECT_BUILD_OUTPUT_FOLDER_DESCRIPTION)) - { - SetDlgItemText( IDC_BUILD_SAVETO, sDir ); - } -} - -// OnChangeAliasList - validate Key alias - must have values in -// dropdown and have one selected. -// Also clear saved password if alias has changed. -// TODO: we always test with debug.keystore which only has one key alias, -// so this code needs more testing -void CBuildAndroidDlg::OnChangeAliasList() -{ - CComboBox *pAliasList = (CComboBox *)GetDlgItem( IDC_BUILD_KEYALIAS ); - - CString sValue; - GetDlgItemText( IDC_BUILD_KEYALIAS, sValue ); - - if( sValue != m_sPrevKeystoreAlias ) - { - m_pProject->ClearAliasPassword(); - m_sPrevKeystoreAlias = sValue; - } -} - -void CBuildAndroidDlg::OnSysCommand(UINT nID, LPARAM lParam) -{ - // Handle the received dialog system command. - if (SC_CONTEXTHELP == nID) - { - // The help [?] button or F1 key was pressed. - // Display the Android build documentation on Corona Labs' website. - try - { - const wchar_t kUrl[] = L"https://docs.coronalabs.com/daily/guide/distribution/androidBuild"; - ::ShellExecuteW(nullptr, L"open", kUrl, nullptr, nullptr, SW_SHOWNORMAL); - } - catch (...) {} - } - else - { - // Let the dialog perform its default handling on the received system command. - CDialog::OnSysCommand(nID, lParam); - } -} - - -//This will open and run a command promot window -void Exec(CString command) { - ::ShellExecute( - nullptr, - _T("open"), - _T("cmd"), - _T(" /K \"")+command+_T("\""), // params - nullptr, - SW_SHOW); -} - - -// OnOK - build project -// Retrieve values from dialog, save to registry, -// get key alias password if necessary -// test key alias password -// call core code to package project and send to server for building -void CBuildAndroidDlg::OnOK() // OnBuild() -{ - Rtt::TargetAndroidAppStore *pTargetStore = NULL; - CComboBox *pComboBox; - WinString stringBuffer; - CString sValue; - CString sKeystore; - CString sBuildDir; - CString sVersionName; - CString sPackageName; - CString sAppName; - CString sKeyAlias; - int iVersionCode; - int iIndex; - bool isLiveBuild; - - bool acceptedSDK = (AfxGetApp()->GetProfileString( REGISTRY_BUILD_ANDROID, _T("AcceptedSDKLicense"), _T("NO") ).Compare(_T("YES")) == 0); - if(!acceptedSDK) - { - UINT ret = DisplayWarningMessageWithHelp(IDS_ANDROID_BUILD, IDS_ANDROID_SDK_LICENSE, _T("https://developer.android.com/studio/terms")); - if (ret != IDYES) return; - AfxGetApp()->WriteProfileString( REGISTRY_BUILD_ANDROID, _T("AcceptedSDKLicense"), _T("YES") ); - } - - // Fetch and validate field values. - GetDlgItemText(IDC_BUILD_APPNAME, sAppName); - sAppName.Trim(); - if (sAppName.IsEmpty()) - { - DisplayWarningMessage(IDS_BUILD_APP_NAME_NOT_PROVIDED); - GetDlgItem(IDC_BUILD_APPNAME)->SetFocus(); - LogAnalytics("build-bungled", "reason", "BUILD_APP_NAME_NOT_PROVIDED"); - return; - } - GetDlgItemText(IDC_BUILD_VERSION_CODE, sValue); - sValue.Trim(); - if (sValue.IsEmpty()) - { - DisplayWarningMessage(IDS_BUILD_VERSION_NUMBER_NOT_PROVIDED); - GetDlgItem(IDC_BUILD_VERSION_CODE)->SetFocus(); - LogAnalytics("build-bungled", "reason", "BUILD_APP_VERSION_NUMBER_NOT_PROVIDED"); - return; - } - iVersionCode = _ttoi(sValue); - if (iVersionCode < 1) - { - DisplayWarningMessage(IDS_INVALID_ANDROID_APP_VERSION_NUMBER); - GetDlgItem(IDC_BUILD_VERSION_CODE)->SetFocus(); - LogAnalytics("build-bungled", "reason", "INVALID_ANDROID_APP_VERSION_NUMBER"); - return; - } - GetDlgItemText(IDC_BUILD_VERSION_NAME, sVersionName); - sVersionName.Trim(); - if (sVersionName.IsEmpty()) - { - DisplayWarningMessage(IDS_BUILD_VERSION_NAME_NOT_PROVIDED); - GetDlgItem(IDC_BUILD_VERSION_NAME)->SetFocus(); - LogAnalytics("build-bungled", "reason", "BUILD_VERSION_NAME_NOT_PROVIDED"); - return; - } - GetDlgItemText(IDC_BUILD_PACKAGE, sPackageName); - sPackageName.Trim(); - if (sPackageName.IsEmpty()) - { - DisplayWarningMessage(IDS_BUILD_PACKAGE_NAME_NOT_PROVIDED); - GetDlgItem(IDC_BUILD_PACKAGE)->SetFocus(); - LogAnalytics("build-bungled", "reason", "BUILD_PACKAGE_NAME_NOT_PROVIDED"); - return; - } - stringBuffer.SetTCHAR(sPackageName); - if (!Rtt_AndroidSupportTools_IsAndroidPackageName(m_androidValidatorLuaState, stringBuffer.GetUTF8())) - { - DisplayWarningMessage(IDS_VALID_PACKAGE); - GetDlgItem(IDC_BUILD_PACKAGE)->SetFocus(); - LogAnalytics("build-bungled", "reason", "bad-package-identifier"); - return; - } - pComboBox = (CComboBox*)GetDlgItem(IDC_BUILD_TARGET_APP_STORE); - iIndex = pComboBox->GetCurSel(); - if (iIndex >= 0) - { - pTargetStore = (Rtt::TargetAndroidAppStore*)pComboBox->GetItemDataPtr(iIndex); - } - if (!pTargetStore) - { - DisplayWarningMessage(IDS_BUILD_TARGET_APP_STORE_NOT_SELECTED); - pComboBox->SetFocus(); - LogAnalytics("build-bungled", "reason", "BUILD_TARGET_APP_STORE_NOT_SELECTED"); - return; - } - GetDlgItemText(IDC_BUILD_KEYSTORE, sKeystore); - sKeystore.Trim(); - if (sKeystore.IsEmpty()) - { - DisplayWarningMessage(IDS_ANDROID_KEYSTORE_FILE_NOT_PROVIDED); - GetDlgItem(IDC_BUILD_KEYSTORE)->SetFocus(); - LogAnalytics("build-bungled", "reason", "ANDROID_KEYSTORE_FILE_NOT_PROVIDED"); - return; - } - if (::PathFileExists(sKeystore) == FALSE) - { - DisplayWarningMessage(IDS_ANDROID_KEYSTORE_FILE_NOT_FOUND, sKeystore); - GetDlgItem(IDC_BUILD_KEYSTORE)->SetFocus(); - LogAnalytics("build-bungled", "reason", "ANDROID_KEYSTORE_FILE_NOT_FOUND"); - return; - } - GetDlgItemText(IDC_BUILD_KEYALIAS, sKeyAlias); - pComboBox = (CComboBox*)GetDlgItem(IDC_BUILD_KEYALIAS); - if ((pComboBox->GetCurSel() <= 0) || sKeyAlias.IsEmpty()) - { - DisplayWarningMessage(IDS_ANDROID_KEYALIAS_NOT_SELECTED); - GetDlgItem(IDC_BUILD_KEYALIAS)->SetFocus(); - LogAnalytics("build-bungled", "reason", "ANDROID_KEYALIAS_NOT_SELECTED"); - return; - } - GetDlgItemText(IDC_BUILD_SAVETO, sBuildDir); - sBuildDir.Trim(); - if (sBuildDir.IsEmpty()) - { - DisplayWarningMessage(IDS_BUILD_PATH_NOT_PROVIDED); - GetDlgItem(IDC_BUILD_SAVETO)->SetFocus(); - LogAnalytics("build-bungled", "reason", "BUILD_PATH_NOT_PROVIDED"); - return; - } - if (sBuildDir.Compare(m_pProject->GetDir()) == 0) - { - DisplayWarningMessage(IDS_BUILD_PATH_INVALID); - GetDlgItem(IDC_BUILD_SAVETO)->SetFocus(); - LogAnalytics("build-bungled", "reason", "BUILD_PATH_INVALID" ); - return; - } - if (::PathIsDirectory(sBuildDir) == FALSE) - { - // The given path does not exist. Attempt to create it. If we are unable to create the directory, - // then that may mean the path is invalid or we do not have permission to create it at that location. - int result = ::SHCreateDirectoryEx(NULL, sBuildDir, NULL); - if (result != ERROR_SUCCESS) - { - DisplayWarningMessage(IDS_BUILD_PATH_CREATION_FAILED, sBuildDir); - GetDlgItem(IDC_BUILD_SAVETO)->SetFocus(); - LogAnalytics("build-bungled", "reason", "BUILD_PATH_CREATION_FAILED"); - return; - } - } - isLiveBuild = (IsDlgButtonChecked(IDC_CREATE_LIVE_BUILD) == BST_CHECKED); - - CString afterBuild = _T("0"); - CButton* pCopyToDevice = (CButton*)GetDlgItem(IDC_COPY_TO_DEVICE); - CButton* pShowInFiles = (CButton*)GetDlgItem(IDC_SHOW_IN_FILES); - if (pCopyToDevice->GetCheck() == BST_CHECKED) - afterBuild = _T("2"); - else if (pShowInFiles->GetCheck() == BST_CHECKED) - afterBuild = _T("1"); - - // Store field settings to project. - m_pProject->SetName(sAppName); - m_pProject->SetAndroidVersionCode(iVersionCode); - m_pProject->SetAndroidVersionName(sVersionName); - m_pProject->SetPackage(sPackageName); - m_pProject->SetKeystorePath(sKeystore); - m_pProject->SetAlias(sKeyAlias); - m_pProject->SetSaveDir(sBuildDir); - m_pProject->SetTargetOS(_T("Android 2.3.3")); // <- This string is only used by logging/analytics. - m_pProject->SetCreateLiveBuild(isLiveBuild); - m_pProject->SetAfterBuild(afterBuild); - - // Update global build settings in registry. - stringBuffer.SetUTF8(pTargetStore->GetStringId()); - AfxGetApp()->WriteProfileString( REGISTRY_BUILD_ANDROID, REGISTRY_TARGET_APP_STORE, stringBuffer.GetTCHAR() ); - AfxGetApp()->WriteProfileString( REGISTRY_BUILD_ANDROID, REGISTRY_KEYSTOREDIR, m_sKeystoreDir ); - AfxGetApp()->WriteProfileString( REGISTRY_BUILD_ANDROID, REGISTRY_LASTKEYSTORE, sKeystore ); - - // Third argument is what this is a password for, not value of password - m_pProject->RegistryPutKeystorePassword(REGISTRY_BUILD_ANDROID, REGISTRY_LASTKEYSTOREPWD, sKeystore); - - // We know the Key Alias password for the trial keystore - if (!sKeystore.CompareNoCase(CCoronaProject::GetTrialKeystorePath())) - { - m_pProject->SetKeystorePassword(GetTrialKeystorePassword()); - m_pProject->SetAliasPassword(GetTrialKeyAliasPassword()); - } - - // Loop until a valid password has been received or until the user cancels out. - // TODO: Password validation should be done in the password dialog. That would eliminate the need for this loop. - CString sAliasPassword = m_pProject->GetAliasPassword(); - bool bDone = false; - while (!bDone) - { - // Ask for the user's password if the user has not provided one yet. - if (sAliasPassword.IsEmpty()) - { - CPasswordDlg passwordDlg( this ); - passwordDlg.SetKey( _T("Key alias: ") + sKeyAlias ); - if (passwordDlg.DoModal() != IDOK) - { - LogAnalytics("build-bungled", "reason", "cancel-android-key-password"); - return; - } - sAliasPassword = passwordDlg.GetPassword(); - m_pProject->SetAliasPassword( sAliasPassword ); - m_pProject->SetSaveAliasPassword( passwordDlg.GetSavePassword() ); - } - - // Validate user's password. - if (!bDone) - { - if (m_pProject->ValidateKeystoreAliasPassword()) - { - // Password is valid. - bDone = true; - } - else - { - // Password is invalid. - DisplayWarningMessage(IDS_INVALID_ALIAS, m_pProject->GetAlias()); - sAliasPassword.Empty(); - } - } - } - - LogAnalytics("build", "store", pTargetStore->GetStringId()); - - m_pProject->Save(); - CBuildProgressDlg buildDialog; - buildDialog.SetProjectSettings(m_pProject); - buildDialog.SetTargetedAppStore(pTargetStore); - buildDialog.DoModal(); - CBuildResult result = buildDialog.GetBuildResult(); - - // Inform the user if the build has failed. Do not close this window on failure. - if (result.HasFailed()) - { - CString title; - title.LoadString(IDS_WARNING); - CHtmlMessageDlg htmlMessageDialog; - htmlMessageDialog.SetTitle(title); - htmlMessageDialog.SetHtmlFromMarkdown(result.GetStatusMessage()); - htmlMessageDialog.DoModal(); - return; - } - - //After Build Options - if (afterBuild == AB_COPY_TO_DEVICE) // Copy to Device - { - if (PathFileExists(_T("C:\\Program Files (x86)\\Android\\android-sdk\\platform-tools\\adb.exe"))) { // this should be where adb is installed - CString apkPath = m_pProject->GetSaveDir() + _T("\\") + m_pProject->GetName() + _T(".apk"); // apk path - Exec(_T("cd C:\\Program Files (x86)\\Android\\android-sdk\\platform-tools & adb install -r \"") + apkPath + _T("\" & adb logcat Corona:v *:s")); // install apk and print logs - } - else { // adb is not installed - DisplayWarningMessageWithHelp(IDS_ADB_NOT_INSTALLED, IDS_ADB_NOT_INSTALLED_WARNING, _T("https://docs.coronalabs.com/guide/basics/debugging/index.html#device-debugging-android"), false); - } - - } - else if (afterBuild == AB_SHOW_IN_FILES) - { - ShellExecute(NULL, _T("open"), m_pProject->GetSaveDir(), NULL, NULL, SW_SHOWNORMAL); - } - // The build has succeeded. Inform the user. - CMessageDlg messageDlg(this); - messageDlg.SetText(IDS_BUILD_SUCCEEDED); - messageDlg.SetDefaultText(IDS_DONE); - //messageDlg.SetAltText( IDS_VIEW_EXPLORER ); //Remove because we give user a choice already - //messageDlg.SetFolder( m_pProject->GetSaveDir() ); - messageDlg.SetIconStyle(MB_ICONINFORMATION); - messageDlg.DoModal(); - - // Add the project to the Corona Live Server list, if enabled. - if (isLiveBuild) - { - CString sCoronaLiveServerExe = ((CSimulatorApp *)AfxGetApp())->GetApplicationDir() + _T("\\Corona.LiveServer.exe"); - CString sAppPath = m_pProject->GetPath(); - try - { - ::ShellExecute(nullptr, nullptr, sCoronaLiveServerExe, sAppPath, nullptr, SW_SHOWNORMAL); - } - catch (...) {} - } - - - - // Close this window. - CDialog::OnOK(); -} - -// OnCancel - clean up, exit -void CBuildAndroidDlg::OnCancel() -{ - // remove temp passwords - if (m_pProject) - { - m_pProject->ClearKeystorePassword(); - m_pProject->ClearAliasPassword(); - } - - CDialog::OnCancel(); -} - -// GetTrialKeystorePassword -CString CBuildAndroidDlg::GetTrialKeystorePassword() -{ - return _T("android"); -} - -// GetTrialKeyAliasPassword - sole key alias is androiddebugkey -// I noticed that signing seems to succeed with any password for the trial key alias -CString CBuildAndroidDlg::GetTrialKeyAliasPassword() -{ - return _T("android"); -} - -// Display a warning message box with the given message. -// Argument "nMessageID" is a unique ID to a string in the resource file's string table. -void CBuildAndroidDlg::DisplayWarningMessage(UINT nMessageID) -{ - CString title; - CString message; - - title.LoadString(IDS_WARNING); - message.LoadString(nMessageID); - MessageBox(message, title, MB_OK | MB_ICONWARNING); -} - -// Display a warning message box with the given message and string. -// Argument "nMessageID" is a unique ID to a string in the resource file's string table. -void CBuildAndroidDlg::DisplayWarningMessage(UINT nMessageID, CString extraInfo) -{ - CString title; - CString message; - - title.LoadString(IDS_WARNING); - message.LoadString(nMessageID); - message.Append(_T("\r\n\r\n")); - message.Append(extraInfo); - MessageBox(message, title, MB_OK | MB_ICONWARNING); -} - -void CALLBACK CBuildAndroidDlg::HelpCallback(LPHELPINFO lpHelpInfo) -{ - // AfxGetApp()->WinHelp(lpHelpInfo->dwContextId); - - try - { - ::ShellExecuteW(nullptr, L"open", m_sHelpURL, nullptr, nullptr, SW_SHOWNORMAL); - } - catch (...) {} -} - -UINT CBuildAndroidDlg::DisplayWarningMessageWithHelp(UINT nTitleID, UINT nMessageID, CString helpURL, bool isYesNo) -{ - MSGBOXPARAMS mbp; - CString title; - CString message; - - title.LoadString(nTitleID); - message.LoadString(nMessageID); - - memset(&mbp, 0, sizeof mbp); - - m_sHelpURL = helpURL; - - mbp.cbSize = sizeof MSGBOXPARAMS; - mbp.hwndOwner = m_hWnd; - mbp.hInstance = AfxGetInstanceHandle(); - mbp.lpszText = message; - - // if you wanted to specify a different caption, here is where you do it - mbp.lpszCaption = title; - if (isYesNo) { //default YES NO - mbp.dwStyle = MB_YESNO | MB_ICONWARNING | MB_HELP; - } - else { - mbp.dwStyle = MB_ICONWARNING | MB_HELP; - } - - - // mbp.lpszIcon = ; // note, you could provide your own custom ICON here! - - mbp.dwContextHelpId = 1; // not used - mbp.lpfnMsgBoxCallback = (MSGBOXCALLBACK) &HelpCallback; - mbp.dwLanguageId = 0x0409; - - return ::MessageBoxIndirect(&mbp); -} - - - -void CBuildAndroidDlg::OnBnClickedCreateLiveBuild() -{ - // Check that they have the Debug keystore selected if they want a Live Build - if (IsDlgButtonChecked(IDC_CREATE_LIVE_BUILD) == BST_CHECKED) - { - CString sKeystorePath; - GetDlgItemText(IDC_BUILD_KEYSTORE, sKeystorePath); - - if( sKeystorePath.CompareNoCase( CCoronaProject::GetTrialKeystorePath() ) != 0 ) - { - CString title; - CString message; - DWORD answer = IDNO; - - title.LoadString(IDS_CREATE_LIVE_BUILD); - message.LoadString(IDS_CREATE_LIVE_BUILD_WARNING); - - answer = DisplayWarningMessageWithHelp(IDS_CREATE_LIVE_BUILD, IDS_CREATE_LIVE_BUILD_WARNING, _T("https://docs.coronalabs.com/guide/distribution/liveBuild/")); - - if (answer == IDYES) - { - SetDlgItemText(IDC_BUILD_KEYSTORE, CCoronaProject::GetTrialKeystorePath()); - UpdateAliasList(); - } - } - } -} - -void CBuildAndroidDlg::LogAnalytics(const char *eventName, const char *key, const char *value) -{ - Rtt_ASSERT(GetWinProperties()->GetAnalytics() != NULL); - Rtt_ASSERT(eventName != NULL && strlen(eventName) > 0); - - // NEEDSWORK: this is horrible - size_t numItems = 2; - char **dataKeys = (char **)calloc(sizeof(char *), numItems); - char **dataValues = (char **)calloc(sizeof(char *), numItems); - - dataKeys[0] = _strdup("target"); - dataValues[0] = _strdup("android"); - if (key != NULL && value != NULL) - { - dataKeys[1] = _strdup(key); - dataValues[1] = _strdup(value); - } - else - { - numItems = 1; - } - - if (GetWinProperties()->GetAnalytics() != NULL) - { - GetWinProperties()->GetAnalytics()->Log(eventName, numItems, dataKeys, dataValues); - } - - free(dataKeys[0]); - free(dataValues[0]); - if (numItems > 1) - { - free(dataKeys[1]); - free(dataValues[1]); - } - free(dataKeys); - free(dataValues); -} From 59bc48a075ff111388798e8f0c1da75fd9fd434d Mon Sep 17 00:00:00 2001 From: Scott Harrison Date: Sun, 5 Mar 2023 00:22:05 -0600 Subject: [PATCH 6/6] Check if apk is available and switch adb to use Corona Sim installed adb --- platform/windows/Corona.Simulator/BuildAndroidDlg.cpp | 10 +++++----- platform/windows/Corona.Simulator/Resource.h | 3 +-- platform/windows/Corona.Simulator/Simulator.rc | 3 +-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/platform/windows/Corona.Simulator/BuildAndroidDlg.cpp b/platform/windows/Corona.Simulator/BuildAndroidDlg.cpp index 5b4a2d5f7..219d54a0d 100644 --- a/platform/windows/Corona.Simulator/BuildAndroidDlg.cpp +++ b/platform/windows/Corona.Simulator/BuildAndroidDlg.cpp @@ -818,12 +818,12 @@ void CBuildAndroidDlg::OnOK() // OnBuild() //After Build Options if (afterBuild == AB_COPY_TO_DEVICE) // Copy to Device { - if (PathFileExists(_T("C:\\Program Files (x86)\\Android\\android-sdk\\platform-tools\\adb.exe"))) { // this should be where adb is installed - CString apkPath = m_pProject->GetSaveDir() + _T("\\") + m_pProject->GetName() + _T(".apk"); // apk path - Exec(_T("cd C:\\Program Files (x86)\\Android\\android-sdk\\platform-tools & adb install -r \"") + apkPath + _T("\" & adb logcat Corona:v *:s")); // install apk and print logs + CString apkPath = m_pProject->GetSaveDir() + _T("\\") + m_pProject->GetName() + _T(".apk"); // apk path + if (PathFileExists(apkPath)) { // check if apk exist (may be aab) + Exec(_T("cd C:\\Program Files (x86)\\Corona Labs\\Corona\\adb & adb install -r \"") + apkPath + _T("\" & adb logcat Corona:v *:s")); // install apk and print logs } - else { // adb is not installed - DisplayWarningMessageWithHelp(IDS_ADB_NOT_INSTALLED, IDS_ADB_NOT_INSTALLED_WARNING, _T("https://docs.coronalabs.com/guide/basics/debugging/index.html#device-debugging-android"), false); + else { // apk not installed + DisplayWarningMessage(IDS_APK_NOT_FOUND); } } diff --git a/platform/windows/Corona.Simulator/Resource.h b/platform/windows/Corona.Simulator/Resource.h index 9bd8e1ed1..84650b552 100644 --- a/platform/windows/Corona.Simulator/Resource.h +++ b/platform/windows/Corona.Simulator/Resource.h @@ -232,8 +232,7 @@ #define IDS_ANDROID_BUILD 675 #define IDS_ANDROID_SDK_LICENSE 676 #define IDS_BUILD_NMETA_NAME_NOT_PROVIDED 677 -#define IDS_ADB_NOT_INSTALLED 678 -#define IDS_ADB_NOT_INSTALLED_WARNING 679 +#define IDS_APK_NOT_FOUND 678 #define IDC_LINK_ANSCAMOBILE 1000 #define IDC_BUILD_APPNAME 1001 #define IDC_BUILD_VERSION_CODE 1002 diff --git a/platform/windows/Corona.Simulator/Simulator.rc b/platform/windows/Corona.Simulator/Simulator.rc index dbabcc32f..f1293080b 100644 --- a/platform/windows/Corona.Simulator/Simulator.rc +++ b/platform/windows/Corona.Simulator/Simulator.rc @@ -859,8 +859,7 @@ BEGIN IDS_ANDROID_BUILD "Building Android App" IDS_ANDROID_SDK_LICENSE """You are about to build an Android app for the first time with this build system.\nIt uses the Android SDK and you must read and accept its license agreement in order to proceed.\nNote, the first time it will download about 250Mb which can take several minutes.\nPress 'Yes' to accept, 'No' to decline or 'Help' to read the license agreement.""" IDS_BUILD_NMETA_NAME_NOT_PROVIDED "You must provide path to .nmeta file." - IDS_ADB_NOT_INSTALLED "ADB Not Installed" - IDS_ADB_NOT_INSTALLED_WARNING "You must have Android Device Bridge Installed to Copy App to Device" + IDS_APK_NOT_FOUND "APK not found for build, so cannot install on device" END STRINGTABLE