Skip to content

Commit

Permalink
InstallMode updates and bugfixes
Browse files Browse the repository at this point in the history
updated rHandler see #10, bugfix in Settings_Validate(), PackRemover was working incorrectly, PackCache installing and local repo managing still needs to be worked on.
  • Loading branch information
joedf committed Jun 24, 2016
1 parent dd5e205 commit 659be11
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 35 deletions.
8 changes: 5 additions & 3 deletions Local-Client/Lib/Settings.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Settings_Get() {

Settings_Validate(j) {
j_default:=Settings_Default()
vars:="stdlib_folder|userlib_folder|customlib_folder|local_repo|local_archive|hide_installed|Show_AllPackSources|only_show_stdlib|package_source|package_sources|Check_ClientUpdates|ContentSensitiveSearch"
vars:="stdlib_folder|userlib_folder|customlib_folder|local_repo|local_archive|hide_installed|Show_AllPackSources|only_show_stdlib|package_source|package_sources|Check_ClientUpdates|ContentSensitiveSearch|DefaultLibMode|RememberLibMode"
loop,Parse,vars,`|
if (!j.Haskey(A_LoopField))
j[A_LoopField]:=j_default[A_LoopField]
Expand All @@ -38,8 +38,10 @@ Settings_Default(key="") {
,package_source: "aspdm.ahkscript.org"
,package_sources: ["aspdm.ahkscript.org","aspdm.2fh.co","aspdm.1eko.com"]
,Check_ClientUpdates: true
,ContentSensitiveSearch: true}
if (k=="")
,ContentSensitiveSearch: true
,DefaultLibMode: "Global"
,RememberLibMode: false}
if (key=="")
return j
return j[key]
}
Expand Down
18 changes: 16 additions & 2 deletions Local-Client/Package_Installer.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,21 @@ FileCreateDir, % Local_Archive:=Settings.Local_Archive
if ErrorLevel
ExitApp, % Install.Error_CreateArchiveDir

InstallationFolder:=Settings.StdLib_Folder ;Should be fetched from "settings/Config" file
InstallMode:="NULL"
if (SubStr(args[1],1,2) == "--") {
InstallMode := SubStr(args[1],3)
pList := args[2]
} else {
pList := args[1]
}

if Instr(InstallMode,"User") {
InstallationFolder := Settings.userlib_folder
} else if Instr(InstallMode,"Custom") {
InstallationFolder := Settings.customlib_folder
} else { ;/ "Global"
InstallationFolder:=Settings.StdLib_Folder ;Should be fetched from "settings/Config" file
}
/* Possible Lib\ Folders:
%A_ScriptDir%\Lib\ ; Local library - requires AHK_L 42+.
Expand All @@ -33,7 +47,7 @@ InstallationFolder:=Settings.StdLib_Folder ;Should be fetched from "settings/Con
*/
InstallIndex := Settings_InstallGet(InstallationFolder)

packs:=StrSplit(args[1],"|")
packs:=StrSplit(pList,"|")
if (!IsObject(packs))
ExitApp, % Install.Error_NoAction
TotalItems:=packs.MaxIndex()
Expand Down
73 changes: 52 additions & 21 deletions Local-Client/Package_Lister.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ if (args) {
continue
i+=1
}
else if (SubStr(args[i],1,2) == "-L") {
if (StrLen(_t:=SubStr(args[i],3))>2) {
if InStr(_t,"User")
Start_LibMode:="User"
else if InStr(_t,"Custom")
Start_LibMode:="Custom"
else
Start_LibMode:="Global"
}
}
else if SubStr(args[i],-4) = .ahkp
Start_select_pack:=args[i]
}
Expand All @@ -60,7 +70,17 @@ if !StrLen(Start_Package_Source)
Start_Package_Source:=Package_Source

;get settings & InstallIndex
gosub,LoadLocalMetadata
;get settings
Settings:=Settings_Get()
;get InstallationFolder
INSTALLDIR_MODE:=Settings.DefaultLibMode
if (Settings.RememberLibMode)
INSTALLDIR_MODE:=Settings.RememberLibMode
if (StrLen(Start_LibMode)>3)
INSTALLDIR_MODE:=Start_LibMode
InstallationFolder:=LibMode_Dir(INSTALLDIR_MODE,Settings)
;get InstallIndex
InstallIndex := Settings_InstallGet(InstallationFolder)

AppVersion:="1.0.0.0"
if (Settings.Check_ClientUpdates)
Expand Down Expand Up @@ -117,11 +137,13 @@ Gui, Tab, Settings
Gui, Add, Checkbox, y+4 xp vOnly_Show_StdLib Disabled, Only show StdLib Packages
Gui, Add, Checkbox, y+4 xp vCheck_ClientUpdates, Check for ASPDM client updates
Gui, Add, Checkbox, y+4 xp vContentSensitiveSearch, Content-Sensitive Search (Uncheck to search tags only)
Gui, Add, Checkbox, y+4 xp vRememberLibMode, Remember StdLib Mode (on settings save)
GuiControl,,Hide_Installed, % (!(!(Settings.hide_installed)))+0
GuiControl,,Show_AllPackSources, % (!(!(Settings.Show_AllPackSources)))+0
GuiControl,,Only_Show_StdLib, % (!(!(Settings.only_show_stdlib)))+0
GuiControl,,Check_ClientUpdates, % (!(!(Settings.Check_ClientUpdates)))+0
GuiControl,,ContentSensitiveSearch, % (!(!(Settings.ContentSensitiveSearch)))+0
GuiControl,,RememberLibMode, % (Strlen(Settings.RememberLibMode)>1)
Gui, Add, Text, y+10 xp, Package source
Gui, Add, Button, yp-5 x+4 vPackSource_AddButton gPackSource_Add, Add...
Gui, Add, Button, yp x+2 vPackSource_RemoveButton gPackSource_Remove, Remove
Expand All @@ -145,8 +167,8 @@ Gui, Tab,
Gui, Add, Edit, vSearchBar gSearch y44 x222 w300,
SetEditPlaceholder("SearchBar","Search...")
Gui, Add, Text, y7 x484 vDDL_StdLibT, StdLib Mode
Gui, Add, DropDownList, y21 x482 w70 -Multi vDDL_StdLib gDDL_StdLibEvent Choose1, Global|User|Custom
GuiControl, ChooseString, DDL_StdLib, Global
Gui, Add, DropDownList, y21 x482 w70 -Multi vDDL_StdLib gDDL_StdLibEvent, Global|User|Custom
GuiControl, ChooseString, DDL_StdLib, % INSTALLDIR_MODE

Gui, Add, StatusBar,, Loading...
SB_SetParts(264)
Expand Down Expand Up @@ -648,10 +670,16 @@ SaveSettings: ;{
Settings[A_LoopField] := (%A_LoopField%)
}

GuiControlGet, RememberLibMode
if (RememberLibMode) {
gosub,GetCurrentInstallationFolder
Settings.RememberLibMode := INSTALLDIR_MODE
} else
Settings.RememberLibMode := false
GuiControlGet,PackSource_ListSelected,,PackSource_List
Settings.package_source := PackSource_ListSelected
Settings.package_source := PackSource_ListSelected
ControlGet, PackSource_PipeList, List,, ComboBox1, ahk_pid %SelfPID%
Settings.package_sources := StrSplit(PackSource_PipeList,"`n")
Settings.package_sources := StrSplit(PackSource_PipeList,"`n")

gosub,_SaveSettings
}
Expand Down Expand Up @@ -747,13 +775,13 @@ Install: ;{

;Changing Install folder will added in the future
if (isAdminRunAs_Needed(InstallationFolder)) {
ecode:=Admin_run("Package_Installer.ahk",Install_packs)
ecode:=Admin_run("Package_Installer.ahk","--" INSTALLDIR_MODE " " Install_packs)
if (ecode=="NOT_ADMIN") {
Gui -Disabled
return
}
} else {
Runwait "Package_Installer.ahk" "%Install_packs%",,UseErrorLevel
Runwait "Package_Installer.ahk" --%INSTALLDIR_MODE% "%Install_packs%",,UseErrorLevel
ecode := ErrorLevel
}

Expand Down Expand Up @@ -848,13 +876,13 @@ Remove: ;{

;Changing Install folder will added in the future
if (isAdminRunAs_Needed(InstallationFolder)) {
ecode:=Admin_run("Package_Remover.ahk",Remove_packs)
ecode:=Admin_run("Package_Remover.ahk","--" INSTALLDIR_MODE " " Remove_packs)
if (ecode=="NOT_ADMIN") {
Gui -Disabled
return
}
} else {
Runwait "Package_Remover.ahk" "%Remove_packs%",,UseErrorLevel
Runwait "Package_Remover.ahk" --%INSTALLDIR_MODE% "%Remove_packs%",,UseErrorLevel
ecode := ErrorLevel
}

Expand Down Expand Up @@ -902,15 +930,9 @@ return
GetCurrentInstallationFolder:
GuiControlGet,DDL_StdLibSelected,,DDL_StdLib
if DDL_StdLibSelected =
InstallationFolder:=Settings.StdLib_Folder
else {
if InStr(DDL_StdLibSelected,"User")
InstallationFolder:=Settings.userlib_folder
else if InStr(DDL_StdLibSelected,"Custom")
InstallationFolder:=Settings.customlib_folder
else ;Default/Global
InstallationFolder:=Settings.StdLib_Folder
}
DDL_StdLibSelected:="Global"
InstallationFolder:=LibMode_Dir(DDL_StdLibSelected,Settings)
INSTALLDIR_MODE := DDL_StdLibSelected
return

DDL_StdLibEvent:
Expand All @@ -919,6 +941,15 @@ DDL_StdLibEvent:
return

;{ Utility Functions and Misc.
LibMode_Dir(x,z) {
if InStr(x,"User")
return z.userlib_folder
else if InStr(x,"Custom")
return z.customlib_folder
else ;Default/Global
return z.StdLib_Folder
}

array_has_value(arr,value) {
for each, item in arr
if (item=value)
Expand All @@ -937,20 +968,20 @@ LV_GetCheckedCount() {
return (A_Index-1)
}

Admin_run(program, argument) {
Admin_run(program, arguments) {
;AutoHotkey Supported OS Versions: WIN_7, WIN_8, WIN_8.1, WIN_VISTA, WIN_2003, WIN_XP, WIN_2000
if A_OSVersion in WIN_2003,WIN_XP,WIN_2000
{
if (A_IsAdmin)
Runwait "%program%" "%argument%",,UseErrorLevel
Runwait "%program%" %arguments%,,UseErrorLevel
else {
MsgBox, 48, , Sorry`, an error has occured.`n`nYou need administrator rights.`nPlease contact your administrator for help.
Gui -Disabled
return "NOT_ADMIN"
}
}
else
Runwait *RunAs "%program%" "%argument%",,UseErrorLevel
Runwait *RunAs "%program%" %arguments%,,UseErrorLevel
return ErrorLevel
}

Expand Down
37 changes: 29 additions & 8 deletions Local-Client/Package_Remover.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,30 @@ FileCreateDir, % Local_Archive:=Settings.Local_Archive
if ErrorLevel
ExitApp, % Install.Error_CreateArchiveDir

InstallationFolder:=Settings.StdLib_Folder ;Should be fetched from "settings/Config" file
InstallMode:="NULL"
if (SubStr(args[1],1,2) == "--") {
InstallMode := SubStr(args[1],3)
pList := args[2]
} else {
pList := args[1]
}

if Instr(InstallMode,"User") {
InstallationFolder := Settings.userlib_folder
} else if Instr(InstallMode,"Custom") {
InstallationFolder := Settings.customlib_folder
} else { ;/ "Global"
InstallationFolder:=Settings.StdLib_Folder ;Should be fetched from "settings/Config" file
}
/* Possible Lib\ Folders:
%A_ScriptDir%\Lib\ ; Local library - requires AHK_L 42+.
%A_MyDocuments%\AutoHotkey\Lib\ ; User library.
path-to-the-currently-running-AutoHotkey.exe\Lib\ ; Standard library.
*/
InstallIndex := Settings_InstallGet(InstallationFolder)

packs:=StrSplit(args[1],"|")
packs:=StrSplit(pList,"|")
if (!IsObject(packs))
ExitApp, % Install.Error_NoAction
TotalItems:=packs.MaxIndex()
Expand Down Expand Up @@ -96,18 +111,23 @@ for Current, id_akhp in packs
}
}

/* comment out for now, because of deletion of local repo
* should not happen when still installed in other Lib dirs
;Delete data in local repo "[ID]\"
FileRemoveDir,%RepoSubDir%,1
if ErrorLevel
ExitApp, % Install.Error_DeleteRepoSubDir
if FileExist(RepoSubDir) {
FileRemoveDir,%RepoSubDir%,1
if ErrorLevel
ExitApp, % Install.Error_DeleteRepoSubDir
}
*/

;Remove Package ID from "Installed" in Settings
for x, installed in Settings.installed
for x, installed in InstallIndex.installed
if (installed==mdata["id"])
Settings.installed.Remove(x)
InstallIndex.installed.Remove(x)

;Save settings right-away in case of error-exit
Settings_Save(Settings)
Settings_InstallSave(InstallationFolder,InstallIndex)

;Increment progress bar
load_progress(mdata["id"],Current,TotalItems)
Expand All @@ -117,6 +137,7 @@ for Current, id_akhp in packs

;Save Settings & Exit Success
Settings_Save(Settings)
Settings_InstallSave(InstallationFolder,InstallIndex)
ExitApp, % Install.Success

load_progress(t,c,f) {
Expand Down
6 changes: 5 additions & 1 deletion Local-Client/rHandler.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ URL_MODE:
URI_:=StrSplit(URI_str,"/")
URI_Source:=Trim(URI_[1])
URI_PackID:=Trim(URI_[2])
URI_LIBDIR:=Trim(URI_[3])

if !URI_PackID
{
Expand Down Expand Up @@ -101,7 +102,10 @@ URL_MODE:
MsgBox, 16, , Error: Non existent Package ("%URI_PackID%.ahkp")?
ExitApp
}
run Package_Lister.ahk "--source" "%URI_Source%" "%pack_id%.ahkp",,UseErrorLevel
LIBMODE := ""
if StrLen(URI_LIBDIR)>1
LIBMODE := "-L" URI_LIBDIR
run Package_Lister.ahk %LIBMODE% "--source" "%URI_Source%" "%pack_id%.ahkp",,UseErrorLevel
if ErrorLevel
MsgBox, 48, , ASPDM could not start properly.`nError: (%ErrorLevel%)[%A_LastError%]
return
Expand Down

0 comments on commit 659be11

Please sign in to comment.