alien4u

Android APK Installer with Include ADB Files, no need Android SDK

11 posts in this topic

#1 ·  Posted (edited)

Im new to the Forum, but I has been using AutoIt for a while for simple tasks.

Now I want to share this Android Installer.
Any advise will be great, also any idea to make the ProgressBar more accurate and with not Stops.

Kind Regards
Alien.

Here the code With comment in English:

#Region
#AutoIt3Wrapper_Icon=drmobileico.ico
#EndRegion
#NoTrayIcon
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <String.au3>
#include <ProgressConstants.au3>


; Adding Files inside final EXE and Copy that files to Windows Temp Dir if Needed.
If Not FileExists(@TempDir & "\adb.exe") Then
    FileInstall("adb.exe", @TempDir & "\adb.exe", 1)
EndIf
If Not FileExists(@TempDir & "\AdbWinApi.dll") Then
    FileInstall("AdbWinApi.dll", @TempDir & "\AdbWinApi.dll", 1)
EndIf
If Not FileExists(@TempDir & "\AdbWinUsbApi.dll") Then
    FileInstall("AdbWinUsbApi.dll", @TempDir & "\AdbWinUsbApi.dll", 1)
EndIf
If Not FileExists(@TempDir & "\logo.jpg") Then
    FileInstall("logo.jpg", @TempDir & "\logo.jpg", 1)
EndIf


;Declare the variables I will use with global scope
Global $quot = Chr(34), $gaDropFiles[1], $toInstall[1], $data2show = ""
;Declare a Constant for FileOpenDialog Func.
Global Const $sMessage = "Select the APK files you want to install"

; The GUI Stuff
#Region ### START Koda GUI section ###
$Form1_1 = GUICreate("DrMobile", 486, 320, 353, 229, -1, $WS_EX_ACCEPTFILES)
GUISetBkColor(0xFFFFFF)
$Pic1 = GUICtrlCreatePic(@TempDir & "\logo.jpg", 17, 25, 250, 50)
$List1 = GUICtrlCreateList("", 16, 120, 340, 170)
GUICtrlSetState($List1, $GUI_DROPACCEPTED)
GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES_FUNC")
$Button1 = GUICtrlCreateButton("Install", 368, 240, 100, 40)
$Button2 = GUICtrlCreateButton("Add Files", 368, 120, 100, 40)
$Button3 = GUICtrlCreateButton("Delete All", 368, 165, 100, 40)
$Label1 = GUICtrlCreateLabel("Add or Drop the files you want to install", 17, 101, 327, 17)

$Label2 = GUICtrlCreateLabel("Progress:", 16, 293, 327, 17)
$pgres = GUICtrlCreateProgress(66, 290, 290, 20, $PBS_SMOOTH)

GUICtrlSetBkColor(-1, 0xFFFBF0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ;Check if this File exist what means server probably running so I shutdown the server.
            ;I do this because if you have another instance of ADB running sometime when ADB try to start again cant kill the old server instance.
            If FileExists(@TempDir & "\adb.exe") Then
                    Run(@ComSpec & " /c " & @TempDir & "\adb.exe " & "kill-server", "", @SW_HIDE)
                Exit
            Else
                Exit
            EndIf

        Case $GUI_EVENT_DROPPED
            ;Check if the Array have an empty value and delete it, otherwise I got empty string in position [0] of the array.
            If $toInstall[0] == "" Then
                _ArrayDelete($toInstall, 0)
            EndIf
            ;StringExplode and ArrayPop here is to get Filename only, because DllStructGetData() return a full path of the droped file.
            For $i = 0 To UBound($gaDropFiles) - 1
                $splo = _StringExplode($gaDropFiles[$i], "\", 0)
                $endrray = _ArrayPop($splo)
                $filename = $endrray
                $data2show &= "|" & $filename ; Populate $data2show with FileNames only because that is what I want to show.
                _ArrayAdd($toInstall, $gaDropFiles[$i])
            Next
            GUICtrlSetData($List1, $data2show)

        Case $Button1 ; Button "Install"
            If $data2show == "" Then
                MsgBox($MB_ICONERROR, "Error", "The list is empty, please add files to install")
            Else
                $installcount = UBound($toInstall)
                For $i = 0 To UBound($toInstall) - 1
                    If StringInStr($toInstall[$i], " ") Then
                        ;Using Run here and not RunWait because I will use $STDOUT_CHILD in the future for error handling base on the final output.
                        $instpid = Run(@ComSpec & " /c " & @TempDir & "\adb.exe install -r " & $quot & $toInstall[$i] & $quot, "", @SW_HIDE)
                        ;Here The Progress Bar, I want to improve this, maybe: (100 / $installcount) then that result will be 100 for that cycle and then
                        ;increment that with base 10 so the Progress dont stop moving during one element install.
                        While ProcessExists($instpid)
                            Sleep(500)
                        WEnd
                        GUICtrlSetData($pgres, GUICtrlRead($pgres) + (100 / $installcount))
                    Else
                        $instpid = Run(@ComSpec & " /c " & @TempDir & "\adb.exe install -r " & $toInstall[$i], "", @SW_HIDE)
                        While ProcessExists($instpid)
                            Sleep(500)
                        WEnd
                        GUICtrlSetData($pgres, GUICtrlRead($pgres) + (100 / $installcount))
                    EndIf
                Next
                    MsgBox($MB_ICONINFORMATION, "Listo", "Process Done")
            EndIf

        Case $Button2 ; Button "Add Files":
            Local $sFileOpenDialog = FileOpenDialog($sMessage, @WindowsDir & "\", "APK Files (*.apk)", $FD_FILEMUSTEXIST + $FD_MULTISELECT)
            $split = StringSplit($sFileOpenDialog,"|")
            ;Here I check if the Array only have two element because that mean we only add one file
            ;Array[0] have number of element on the array,Array[1] Full path to file so I need to do StringExplode and ArrayPop again to get FileName
            If UBound($split) == 2 Then
                If $toInstall[0] == "" Then
                    _ArrayDelete($toInstall, 0)
                    _ArrayAdd($toInstall,$split[1])
                    $split2 = _StringExplode($split[1],"\")
                    $endarray = _ArrayPop($split2)
                    $data2show &= "|" & $endarray
                Else
                    _ArrayAdd($toInstall,$split[1])
                    $split2 = _StringExplode($split[1],"\")
                    $endarray = _ArrayPop($split2)
                    $data2show &= "|" & $endarray
                EndIf

            Else
                ; Here I only need to get FullPath because the file names come in next elements is how FileOpenDialog() do it.
                $tpath = $split[1]
                If $toInstall[0] == "" Then
                    _ArrayDelete($toInstall, 0)
                EndIf

            EndIf
            ; Like I said from array[2] to the end are the File names.
            For $i = 2 to UBound($split) -1
                _ArrayAdd($toInstall, $tpath & "\" & $split[$i])
                $data2show &= "|" & $split[$i]
            Next
                GUICtrlSetData($List1, $data2show)

        Case $Button3 ;Button "Delete All"
            ; I clear all the Variables and the List in the Gui too
            $toInstall = 0
            Global $toInstall[1]
            $data2show = ""
            GUICtrlSetData($pgres,0)
            GUICtrlSetData($List1, $data2show)

    EndSwitch
WEnd

;Func _IsValidExt($sPath)
;   For $i = 1 To $FilesAllowedMask[0]
;      If StringRight($sPath, 4) = $FilesAllowedMask[$i] And _
;          Not StringInStr(FileGetAttrib($sPath), $FilesAllowedMask[$i]) Then Return True
; Next
;Return False
;EndFunc

; This Func is from the Forum and I need to improve it to support Unicode Char for example file names with Accute,
; I think there is another func arround the forum that support Unicode characters.
Func WM_DROPFILES_FUNC($hWnd, $msgID, $wParam, $lParam)
    Local $nSize, $pFileName
    Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)
    For $i = 0 To $nAmt[0] - 1
        $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
        $nSize = $nSize[0] + 1
        $pFileName = DllStructCreate("char[" & $nSize & "]")
        DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", DllStructGetPtr($pFileName), "int", $nSize)
        ReDim $gaDropFiles[$i + 1]
        $gaDropFiles[$i] = DllStructGetData($pFileName, 1)
        $pFileName = 0
    Next
EndFunc   ;==>WM_DROPFILES_FUNC


 

Edited by alien4u
Code Fix and Comments in English

Share this post


Link to post
Share on other sites



First bit of code looks a bit strange, not sure if there is a reason for the way you wrote it, but if not, here is a more clear way.

If Not FileExists(@TempDir & "\adb.exe") Then
    FileInstall("adb.exe", @TempDir & "\adb.exe", 1)
EndIf
If Not FileExists(@TempDir & "\AdbWinApi.dll") Then
    FileInstall("AdbWinApi.dll", @TempDir & "\AdbWinApi.dll", 1)
EndIf
If Not FileExists(@TempDir & "\AdbWinUsbApi.dll") Then
    FileInstall("AdbWinUsbApi.dll", @TempDir & "\AdbWinUsbApi.dll", 1)
EndIf
If Not FileExists(@TempDir & "\logo.jpg") Then
    FileInstall("logo.jpg", @TempDir & "\logo.jpg", 1)
EndIf

 


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
10 hours ago, JohnOne said:

First bit of code looks a bit strange, not sure if there is a reason for the way you wrote it, but if not, here is a more clear way.

If Not FileExists(@TempDir & "\adb.exe") Then
    FileInstall("adb.exe", @TempDir & "\adb.exe", 1)
EndIf
If Not FileExists(@TempDir & "\AdbWinApi.dll") Then
    FileInstall("AdbWinApi.dll", @TempDir & "\AdbWinApi.dll", 1)
EndIf
If Not FileExists(@TempDir & "\AdbWinUsbApi.dll") Then
    FileInstall("AdbWinUsbApi.dll", @TempDir & "\AdbWinUsbApi.dll", 1)
EndIf
If Not FileExists(@TempDir & "\logo.jpg") Then
    FileInstall("logo.jpg", @TempDir & "\logo.jpg", 1)
EndIf

 

You are right, seem that my logic don't reach that obvious point, I don't think in "NOT" operator.
Thank you so much, feel free to point more things, I will appreciate that because I want to learn.

Kind Regards
Alien.

Share this post


Link to post
Share on other sites

Hi alien, welcome to the forum. :D

My first bit of advice, is that you use Google Translate with the relevant sections of your code, to make life easier for the rest of us ... especially if wanting advice from the predominantly English speaking and writing members here. ;)

Be proud of your language by all means, but assist the volunteer helpers here. :)

Many like me, won't look at it otherwise, which is a shame. :'(


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox

userbar.png

Share this post


Link to post
Share on other sites
9 hours ago, TheSaint said:

Hi alien, welcome to the forum. :D

My first bit of advice, is that you use Google Translate with the relevant sections of your code, to make life easier for the rest of us ... especially if wanting advice from the predominantly English speaking and writing members here. ;)

Be proud of your language by all means, but assist the volunteer helpers here. :)

Many like me, won't look at it otherwise, which is a shame. :'(

That is quite an offensive post, I'm surprised anyone still holds these kind of prejudices.

alien4u, Most people here do not feel that way, and please accept my apologies.

Your code is not difficult at all to read and understand.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
8 minutes ago, JohnOne said:

That is quite an offensive post, I'm surprised anyone still holds these kind of prejudices.

alien4u, Most people here do not feel that way, and please accept my apologies.

Your code is not difficult at all to read and understand.

So JohnOne, you are gonna take our dispute out into the wider forum. Very mature of you.

Losing the battle were you., so you decided to ramp it up another notch.

My apologies alien for his behavior, I'm sure you understood the logic and reality of what I was saying.

JohnOne really struggles with Logic ... amongst other things.

Like I said, be proud of your language, just as I am of mine. I only really know the one, you probably know more.

Most of us volunteers work here under the principal, that we help others to help themselves, so taking the extra time to translate your language first, before we can fully understand your code, is not an incentive to give help.

When working with other people's code, it is not just a matter of studying the commands used. We need context too, which is where Comments and naming of controls etc comes into the picture.

Sure, I could be a super kind guy and go and translate every instance of your language, but not knowing your language at all, and just relying on Google Translate to get it right, would be foolish in my estimation. If you have a smattering of English, you would definitely be the better one to translate with Google, especially as it is more in your interest to do so.

Please note, that I only suggested you translate for obtaining advice from those of us (many) who don't know your language. If you hadn't asked for advice, I would not have suggested translating, and never have in the more than 10 years I have been here. And it is ironic, because I have indeed seen where JohnOne has done that in the past.

JohnOne lives by a double standard, where he will say one thing to your face on one occasion, but an entirely different thing on another, depending on his whims.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox

userbar.png

Share this post


Link to post
Share on other sites
2 minutes ago, TheSaint said:

So JohnOne, you are gonna take our dispute out into the wider forum. Very mature of you.

Losing the battle were you., so you decided to ramp it up another notch.

My apologies alien for his behavior, I'm sure you understood the logic and reality of what I was saying.

JohnOne really struggles with Logic ... amongst other things.

Like I said, be proud of your language, just as I am of mine. I only really know the one, you probably know more.

Most of us volunteers work here under the principal, that we help others to help themselves, so taking the extra time to translate your language first, before we can fully understand your code, is not an incentive to give help.

When working with other people's code, it is not just a matter of studying the commands used. We need context too, which is where Comments and naming of controls etc comes into the picture.

Sure, I could be a super kind guy and go and translate every instance of your language, but not knowing your language at all, and just relying on Google Translate to get it right, would be foolish in my estimation. If you have a smattering of English, you would definitely be the better one to translate with Google, especially as it is more in your interest to do so.

Please note, that I only suggested you translate for obtaining advice from those of us (many) who don't know your language. If you hadn't asked for advice, I would not have suggested translating, and never have in the more than 10 years I have been here. And it is ironic, because I have indeed seen where JohnOne has done that in the past.

JohnOne lives by a double standard, where he will say one thing to your face on one occasion, but an entirely different thing on another, depending on his whims.

Quoted for posterity.

I have no desire to ruin this persons thread with a conversation about your ego.

You made an awfully offensive post, please do not project that onto me.

Over and out.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Seriously Guys... take it offline or you will be taken offline.  (jeezz what a bunch of childish behavior and even one reporting the other... go play outside please and cool off.)

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Hi everyone and thanks for the comments.

I edit my post and I add the code fixed with JohnOne's fix and also with English Comments, I don't need to use Google Translator to do that so you maybe will find some Grammar mistakes or something like that.
Here in Cuba Google Translator among other things are a Luxury Option for an insanely expensive and slow Dial-Up internet connection.
So here we code without searching in Google(and there I think a lot of self named "coders" copy and paste from Internet) I don't mean to offend or harm to anyone is that clear?

Kind Regards
Alien.
 

 

1 person likes this

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

On ‎3‎/‎10‎/‎2016 at 0:50 AM, alien4u said:

Im new to the Forum, but I have been using AutoIt for a while for simple tasks.

Now I want to share this Android Installer.
Any advise will be great, also any idea to make the ProgressBar more accurate and with not Stops.

; This Func is from the Forum and I need to improve it to support Unicode Char for example file names with Accute,
; I think there is another func arround the forum that support Unicode characters.


 

These things are interesting to me:  Accute? - también what are you thinking about, in terms of the Func?

https://www.autoitscript.com/forum/topic/181273-click-my-utf8-ansi-quiztest/#comment-1301796

Like this idea of offline when you want, no SDK install idea.  Sounds good and Cuban to me.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Semi Cultural Baseball  "Big Papi Redsox - Smidgon of Pigeon - pica pollo con wasakaka

SNL https://www.youtube.com/watch?v=4vi1mjp3PTw (Very Funny at 2:14)

Edited by MaxPlankpar
typo

Share this post


Link to post
Share on other sites
1 hour ago, MaxPlankpar said:

These things are interesting to me:  Accute? - también what are you thinking about, in terms of the Func?

https://www.autoitscript.com/forum/topic/181273-click-my-utf8-ansi-quiztest/#comment-1301796

Like this idea of offline when you want, no SDK install idea.  Sounds good and Cuban to me.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Semi Cultural Baseball  "Big Papi Redsox - Smidgon of Pigeon - pica pollo con wasakaka

SNL https://www.youtube.com/watch?v=4vi1mjp3PTw (Very Funny at 2:14)

Is Cuban and also something that could be useful on places with really slow internet connection.
And I don't like to depend of some android daemon to make things that adb can do in a native way.

About the UTF, Accute(accents) is something we refer like that sometimes.
I was talking about this:

Kind Regards
Alien.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now