Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: After Build options for Android #529

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 66 additions & 70 deletions platform/windows/Corona.Simulator/BuildAndroidDlg.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
#include "Rtt_TargetDevice.h"
#include "Rtt_TargetAndroidAppStore.h"
#include <Shlwapi.h>

#include <iostream>
#include <windows.h>
#include <fstream>

// CBuildAndroidDlg dialog

Expand Down Expand Up @@ -67,9 +69,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)
Expand Down Expand Up @@ -250,32 +249,14 @@ 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);
// 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);

#endif // AUTO_INCLUDE_MONETIZATION_PLUGIN
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
Expand Down Expand Up @@ -575,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(" /C \"")+command+_T("\""), // params
nullptr,
SW_SHOW);
}


// OnOK - build project
// Retrieve values from dialog, save to registry,
// get key alias password if necessary
Expand Down Expand Up @@ -603,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();
Expand Down Expand Up @@ -726,6 +720,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);
Expand All @@ -736,6 +738,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());
Expand Down Expand Up @@ -812,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
scottrules44 marked this conversation as resolved.
Show resolved Hide resolved
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)
Expand All @@ -833,6 +852,8 @@ void CBuildAndroidDlg::OnOK() // OnBuild()
catch (...) {}
}



// Close this window.
CDialog::OnOK();
}
Expand Down Expand Up @@ -900,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;
Expand All @@ -920,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!

Expand All @@ -932,36 +958,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()
Expand Down
6 changes: 1 addition & 5 deletions platform/windows/Corona.Simulator/BuildAndroidDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,8 @@ 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);
#ifdef AUTO_INCLUDE_MONETIZATION_PLUGIN
public:
afx_msg void OnBnClickedEnableMonetization();
#endif
afx_msg void OnBnClickedCreateLiveBuild();
void LogAnalytics(const char *eventName, const char *key = NULL, const char *value = NULL);

Expand Down
30 changes: 21 additions & 9 deletions platform/windows/Corona.Simulator/CoronaProject.cpp
Original file line number Diff line number Diff line change
@@ -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: [email protected]
//
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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 );
}
Expand Down Expand Up @@ -716,7 +728,7 @@ CEncryptedKeeper::ClearSaved()
}

// ClearAll - clear both current and saved data
void
void
CEncryptedKeeper::ClearAll()
{
ClearCurrent();
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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);

Expand Down
10 changes: 7 additions & 3 deletions platform/windows/Corona.Simulator/CoronaProject.h
Original file line number Diff line number Diff line change
@@ -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: [email protected]
//
Expand Down Expand Up @@ -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")

///////////////////////////////////////////////////////////////////////////////
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -219,10 +222,11 @@ class CCoronaProject :

bool m_CreateLiveBuild;

CString m_sAfterBuild;

#ifdef AUTO_INCLUDE_MONETIZATION_PLUGIN
bool m_EnableMonetization;
#endif

bool m_sCreateFBInstantArchive;
};

Loading