Baby's first autohotkey meta release. Github repository downloader, object based. Very basic.

Post your working scripts, libraries and tools for AHK v1.1 and older
sashaatx
Posts: 333
Joined: 27 May 2021, 08:27
Contact:

Baby's first autohotkey meta release. Github repository downloader, object based. Very basic.

Post by sashaatx » 05 Oct 2022, 16:00

https://github.com/samfisherirl/github.ahk

I've released a bunch for other ahk stuff, but never an ahk 'lib'. doubt this would be considered but nonetheless.

Download latest releases from github, Object based.
example.ahk

Code: Select all

#Include Json.ahk
#Include github.ahk
setworkingdir, %A_ScriptDir%
#SingleInstance, force
    #NoEnv

; credit to https://github.com/clangremlini/OTA.ahk 
; credit to https://github.com/kurtmckee/ahk_json

;download the latest release from github with "git := new Github(rep)"

git := new Github("samfisherirl/Geo3D_Manager")
;objectname :=  new Github(username"/"repository)

;alternately
rep := "samfisherirl/Geo3D_Manager"
;        username   /   repository
git := new Github(rep)

git.DL("geo") ; downloads the latest release, 
;saving to "geo.zip" relative path

; alternately
;

log := A_ScriptDir "\log.txt"
;designate a log location, 
;otherwise the script will 
;send log.txt to appdata   

git.upd(log)
;if log.txt is not empty, 
;and if version in log (v1.2) < (v1.3)
;downloads latest release  

;only check for update
if (git.checkupd(log)=1)
{
    msgbox you need an update! `nI will store version in %log% for when you check`n for an update, next time! 
    git.dlupdate(log)
}
; alternately
;git.upd("")

; "geo" is the file e latest release, extension is grabbed after download and push to working dir.name of th

; optional: choose local directory with next example

releasename := git.name()   

file_to_Save := A_AppDataCommon "\" releasename
;same as git.DL("geo") except choose the directory, using the git.name() object to grab the release file name, including extension and version data like "geo.v1.1.zip"  

git.DL(file_to_Save)
;git.DL("geo") 

;Function example
path := A_DesktopCommon
GitDownload("samfisherirl","Geo3D_Manager", Path)
; msgbox % file_to_Save
; returns file name

;    Return URL of Latest Release Version
msgbox % git.release()

;    return version of latest release tag
msgbox % git.tag()

msgbox % git.name()

github.ahk

Code: Select all

; credit to https://github.com/clangremlini/OTA.ahk 
; credit to https://github.com/kurtmckee/ahk_json 
class Github {
    __New(Repo) {
        Ar := []
        Ar := StrSplit(Repo, "/")
        
        url := "https://api.github.com/repos/" Repo "/releases/latest"
        urlDownloadToFile, %url%, 1.json
        sleep, 50
        FileRead, Jsn, 1.json
        data := json_load(Jsn)
        ;filedelete, 1.json
        this.DLUrl := data["assets"][1]["browser_download_url"]
        this.Asset := data["assets"][1]["name"]
        this.Vers := data["html_url"]
        ;this.Filetype := data["assets"][1]["browser_download_url"]
    }
    release() {
        return this.DLUrl
    }
    name() {
        return this.asset
    }
    zipORexe() {
        Array := StrSplit(this.DLUrl, ".")
        indx:=Array.MaxIndex()
        filetype:=Array[indx]
        return filetype
    }
    tag() {
        url := StrSplit(this.Vers,"/")
        tag := url[8]
        return tag
        ; msgbox % this.j[1].assets.name
        ; return this.j[1].assets.name
    }
    DL(Name) {
        x := this.zipORexe()
        ext := Name "." x
        url := this.release()
        UrlDownloadToFile, %url%, %ext%
        if !InStr(ext, ":\")
            ext := A_ScriptDir . "\" . ext
        return ext
    }
}

GitDownload(Username, Repository_Name, Path_To_Save_DL)
{
    ;GitDownload("samfisherirl","Geo3D_Manager", Path)
    UR := Username "\" Repository_Name
    Path_To_Save_DL := Path_To_Save_DL "\" git.name()
    gitfunc := new Github(UR)
    gitfunc.DL(Path_To_Save_DL)
}




CODE-GENERATING-GUI

Image


Code: Select all

; Generated by Auto-GUI 3.0.1
#SingleInstance Force
    #NoEnv 
SetWorkingDir %A_ScriptDir%
SetBatchLines -1

Gui Font, s9, Segoe UI
Gui Add, Button, ggo x184 y296 w120 h22, Give me code
Gui Add, Edit, vusername  x32 y144 w120 h21, github_username
Gui Add, Edit, vrepository x32 y192 w120 h21, github_repository

Gui Add, Edit, vFile x32 y240 w122 h21, File_DL_Name
Gui Add, Text, x184 y240 w186 h23 +0x200, Choose a name for saving locally
Gui Add, Button, grun x32 y296 w80 h22, Test / DL
Gui Add, CheckBox, vCheck x184 y144 w195 h23 +Checked, Check Update + Store Version
Gui Add, Text, x40 y8 w289 h79, Generate code that will: `n-Download latest releases from Github`,  `n-Store Version data Locally`,`n-Get info on version and changes, `n-Prompt for update only on vers=/=vers 

Gui Show, w369 h350, Use AHK to download Github Latest Releases 
Return

go:
    loop, 5
    {
      getcontrol()
      if (obj.full()="")
      {
        sleep 500
        continue
      }
      else        
          DisplayLog(obj.full(), obj.req())  
    }
Return

run:
    getcontrol() 
    txt := obj.full()
    FileAppend, 
    (C LTrim
    
    %txt%
    
    ), run.txt 
    filemove, run.txt, run.ahk, 1
    run, run.ahk, %A_ScriptDir%
    reload
Return

getcontrol()
{
    global
    GuiControlGet, repository
    GuiControlGet, username
    GuiControlGet, file
    GuiControlGet, drop
    GuiControlGet, check
    array := [repository, username, drop, file, check]
    obj := new Code(array)
}

Class Code {
    __New(array) {
        this.repo := array[1]
        this.user := array[2]
        this.drop := array[3]
        this.file := array[4]
        this.updt := array[5]
    }
    combine() {
        rep := `"""" this.user "/" this.repo `"""" 
        return rep
    } 
    
    baseline() {
        val=
        (C LTrim
        #Include Json.ahk    ;place in same dir as code
        #Include github.ahk  ;place in same dir as code 
        #SingleInstance, force
            #NoEnv
        
        )
        return val 
    }
    update() {
        if (this.updt=1)
        {
            scriptupdater=
            (C LTrim                
                        
            log := A_Appdatacommon "\log.txt"
            ;designate a log location, otherwise the script will send log.txt to appdata   
            
            ;stores log info, only downloads if log has vers < latest
            git.upd(log)
            )
        }
        else
        {
            script:=this.file
            scriptupdater=
            (C LTrim              
            git.DL("%script%") 
            )
        }
        return scriptupdater
    }
    
    req() {
        file :=  this.combine()
        script := this.file()
        log := this.update()
        necessary= 
        (C LTrim
        
        ;keep this above download object
        repos := %File%
        git := new Github(repos)
        
        %log%
        )
        return necessary 
    }
    
    full() {
        code := this.baseline() "`n" this.req()
        return code
    }
    
}

DisplayLog(FullCode, Partial) {
    
    global
    Gui new, hwndOne 
    Gui show, w364 h291, Code
    Gui Font, s9, Segoe UI
    Gui Add, Edit, vfull x16 y40 w143 h183
    Gui Add, Edit, vpatrial x176 y40 w143 h183
    Gui Add, Text, x25 y8 w120 h23 +0x200, Full
    Gui Add, Text, x176 y8 w120 h23 +0x200, Partial
    Gui Add, Button, gfuller x48 y240 w80 h23, Copy
    Gui Add, Button, gpatrialer x208 y240 w80 h23, Copy
    GuiControl,, full, %fullcode%
    GuiControl,, patrial, %Partial%
Return

fuller:
    clipboard := obj.full()
return

patrialer:
    clipboard := obj.req()
return

}

GuiEscape:
GuiClose:
    ExitApp
    
Last edited by sashaatx on 08 Oct 2022, 12:26, edited 5 times in total.


sashaatx
Posts: 333
Joined: 27 May 2021, 08:27
Contact:

Re: Baby's first autohotkey meta release. Github repository downloader, object based. Very basic.

Post by sashaatx » 07 Oct 2022, 14:01

added log feature

Image
https://github.com/samfisherirl
? /Easy-Auto-GUI-for-AHK-v2 ? /Useful-AHK-v2-Libraries-and-Classes : /Pulovers-Macro-Creator-for-AHKv2 :

Post Reply

Return to “Scripts and Functions (v1)”