Retrieve volumes list

Discuss any general programming issues here
Post Reply
ilbarbax
Posts: 155
Joined: Thu Apr 01, 2010 6:41 pm

Retrieve volumes list

Post by ilbarbax »

How can I retrieve the list of the system volumes and in case of amiga os the list of the assignes too
Thanks
User avatar
Redlion
Posts: 125
Joined: Sun Jul 10, 2011 5:05 am
Location: Perth, Western Australia

Re: Retrieve volumes list

Post by Redlion »

@ ilbarbax

The simplest way in windows is
For V = 1 To 26 ; Go Through All Drive Letters
If Exists(Chr(64 + V) .. ":")
DebugPrint(Chr(64 + V) .. " Drive")
EndIf
Next
It is quite quick and simple.

For the Amiga side of things
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; * Find all devices ** ( No assigns ) *************************************** Non Mui Royale ***********
devices = {}
harddisks = {}
optical = {}
usb = {}
ram = {}
Devs = {}


Function ListDrives()
Execute("info devices sort volume >TEXTCLIP:")
type, data = GetClipboard()
h = 0
o = 0
u = 0
r = 0
devices, noofdevices = SplitStr(data,"\n")
For Local x = 1 To noofdevices-1
Line = devices[x-1]
If FindStr(Line,"DH",False) = 0
harddisks[h] = MidStr(Line,0, FindStr(Line,":"))
h = h +1
ElseIf FindStr(Line,"CD",False) = 0
optical[o] = MidStr(Line,0, FindStr(Line,":"))
o = o +1
ElseIf FindStr(Line,"USB",False) = 0
usb = MidStr(Line,0, FindStr(Line,":"))
u = u +1
ElseIf FindStr(Line,"RAM",False) = 0
ram[r] = MidStr(Line,0, FindStr(Line,":"))
r = r +1
EndIf
Next
L=1
For Local d = 0 To h-1
TextOut(5,L*14,Harddisks[d])
Devs[l] = Harddisks[d]
L = L +1
Next
For Local d = 0 To o-1
TextOut(5,L*14,Optical[d])
Devs[l] = Optical[d]
L = L +1
Next
For Local d = 0 To u-1
TextOut(5,L*14,Usb[d])
Devs[l] = Usb[d]
L = L +1
Next
For Local d = 0 To r-1
TextOut(5,L*14,ram[d])
Devs[l] = ram[d]
L = L +1
Next
EndFunction
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


This is kind off what I used, to get a list of devices.

Next Reply will be Royale Code.

Cheers
Leo
----------------------------------------------------------------------------------------
Redlion
Sam460 Lite
A4000 A3000 A2000 A1200 A1000 A600 A500 CD32
User avatar
Redlion
Posts: 125
Joined: Sun Jul 10, 2011 5:05 am
Location: Perth, Western Australia

Re: Retrieve volumes list

Post by Redlion »

Here is the Royale Code
/*** Make sure we have at least Hollywood 9.0! ****************************************************/
@VERSION 5,2

/*** Enable DPI-awareness so that our GUI looks sharp even on high DPI monitors *******************/
@OPTIONS {DPIAware = True}

/*** This script requires the RapaGUI plugin ******************************************************/
@REQUIRE "MUIRoyale"

/*** Information about this app *******************************************************************/
@APPTITLE "Simple DIRLook"
@APPVERSION "$VER: 1.0.0 (16.07.20)"
@APPCOPYRIGHT "George Leo den Hollander 2020"
@APPAUTHOR "Leo den Hollander"
@APPDESCRIPTION "Simple DIR Program"

@DISPLAY {Hidden = True}

EscapeQuit(True)

activelist = 2

/*** setup GUI ***********************************************************************************/
MUI.CREATEGUI([[
<?xml version="1.0" encoding="iso-8859-1"?>
<application base="TEST">
<window title="DIR LOOK - Directory Program" id="window" notify="closerequest" width="1280" height="600">
<vgroup background="pre_ShadowFill">
<hgroup>
<vgroup>
<button id="leftpanel" notify="Pressed" BackGroundRGB="#B0B0B0"></button>
<dirlist id="lv1_directory" notify="Active; Doubleclick" directory="DH0:" multiselect="default" title="true" fixheight="800" fixwidth="550">
<column/>
<column/>
<column/>
<column/>
<column/>
<column/>
</dirlist>
<string id="lv1" contents="DH0:"/>
</vgroup>
<vgroup weight="70">
<vgroup id = "container" font="Big" >
<vspace height="1"/>
<label centered="true">\333\33bDRIVES</label>
<volumelist id="vol" notify="DoubleClick" fixwidth="150">
<column/>
<column/>
</volumelist>
</vgroup>
<vgroup font="Big">
<label centered="true">\333\33bFUNCTIONS</label>
<button id ="parent" notify="pressed" fixwidth="100">\33b Parent Dir </button>
<button id ="copy" notify="pressed" fixwidth="100">\33b Copy File </button>
<button id ="rename" notify="pressed" fixwidth="100">\33b Rename File</button>
<button id ="delete" notify="pressed" fixwidth="100">\33b Delete File </button>
<button id ="find" notify="pressed" fixwidth="100">\33b Find File </button>
<button id ="makedir" notify="pressed" fixwidth="100">\33b Make Dir </button>
<button id ="comment" notify="pressed" fixwidth="100">\33b File Comment </button>
</vgroup>
<vgroup>
<button id ="quit" notify="pressed" fixwidth="100">\33b Quit </button>
</vgroup>
</vgroup>
<vgroup>
<button id="rightpanel" Notify="Pressed" BackGroundRGB="#80AAFF"></button>
<dirlist id="lv2_directory" notify="Active; DoubleClick" directory="RAM:" multiselect="default" title="TRUE" fixheight="800" fixwidth="550">
<column/>
<column/>
<column/>
<column/>
<column/>
<column/>
</dirlist>
<string id="lv2" contents="RAM:"/>
</vgroup>
</hgroup>
</vgroup>
</window>
</application>
]])

;*** Handler for all incoming events **************************************************************
Function p_EventFunc(msg)
Switch msg.action

Case "MUIRoyale":

Switch msg.attribute

Case "CloseRequest":
End

Case "Pressed":
Switch msg.id
Case "rightpanel"
mui.Set("leftpanel", "BackGroundRGB", RGB(176, 176, 176))
mui.Set("rightpanel", "BackGroundRGB", RGB(128, 170, 255))
Activelist = 2

Case "leftpanel"
mui.Set("rightpanel", "BackGroundRGB", RGB(176, 176, 176))
mui.Set("leftpanel", "BackGroundRGB", RGB(128, 170, 255))
Activelist = 1

Case "parent":
If activelist = 1
newpar1$ = MUI.GET("lv" .. Activelist,"contents")
len = StrLen(newpar1$)
newpar1$ = LeftStr(newpar1$,len-1)
For Local t = len-1 To 0 Step -1
var = FindStr(newpar1$,"/",False,t)
If var > -1
newpar1$ = LeftStr(newpar1$,var+1)
Break
EndIf
Next
If var = -1
newpar1$ = MUI.GET("lv" .. Activelist,"contents")
len = StrLen(newpar1$)-1
For Local t = len To 0 Step -1
var = FindStr(newpar1$,":",False,t)
If var > -1
newpar1$ = LeftStr(newpar1$,var+1)
Break
EndIf
Next
EndIf
MUI.SET("lv" .. Activelist,"contents",newpar1$)
MUI.SET("lv" .. Activelist .. "_directory","directory",newpar1$)
ElseIf activelist = 2
newpar2$ = MUI.GET("lv" .. Activelist,"contents")
len = StrLen(newpar2$)
newpar2$ = LeftStr(newpar2$,len-1)
For t = len-1 To 0 Step -1
var = FindStr(newpar2$,"/",False,t)
If var > -1
newpar2$ = LeftStr(newpar2$,var+1)
Break
EndIf
Next
If var = -1
newpar2$ = MUI.GET("lv" .. Activelist,"contents")
len = StrLen(newpar2$)-1
For Local t = len To 0 Step -1
var = FindStr(newpar2$,":",False,t)
If var > -1
newpar2$ = LeftStr(newpar2$,var+1)
Break
EndIf
Next
EndIf
MUI.SET("lv" .. Activelist,"contents",newpar2$)
MUI.SET("lv" .. Activelist .. "_directory","directory",newpar2$)
EndIf

EndSwitch

Case "DoubleClick":
Switch msg.id
Case "vol"
Col1$ = mui.DoMethod("vol", "GetEntry", "Active")
mui.Set("lv" .. Activelist .. "_directory", "Directory", Col1$)

Case "lv1_directory"
newdir1$ = mui.Get("lv1","contents")
Column1$,Column2 = mui.DoMethod("lv1_directory","GetEntry","Active")
If Column2 = -1
mui.Set("lv" .. Activelist .. "_directory", "directory", newdir1$ .. Column1$)
mui.Set("lv" .. Activelist, "contents", newdir1$ .. Column1$ .. "/")
Else
Execute("DH0:Utilities/MultiView ")
EndIf

Case "lv2_directory"
newdir2$ = MUI.GET("lv2","contents")
Column1$,Column2 = mui.DoMethod("lv2_directory","GetEntry","Active")
If Column2 = -1
MUI.Set("lv" .. Activelist .. "_directory","directory",newdir2$..Column1$)
MUI.Set("lv" .. Activelist, "contents",newdir2$..Column1$.."/")
Else
Execute("DH0:Utilities/MultiView ")
EndIf

EndSwitch

EndSwitch

Case "HideWindow":
mui.Set("app", "iconified", True)

Case "ShowWindow":
mui.Set("app", "iconified", False)

EndSwitch

EndFunction

;*** listen to these events ***********************************************************************
InstallEventHandler({MUIRoyale = p_EventFunc, HideWindow = p_EventFunc, ShowWindow = p_EventFunc})


;*** main loop ***********************************************************************************
Repeat
WaitEvent
Forever
Hope that helps

Cheers
Leo
----------------------------------------------------------------------------------------
Redlion
Sam460 Lite
A4000 A3000 A2000 A1200 A1000 A600 A500 CD32
ilbarbax
Posts: 155
Joined: Thu Apr 01, 2010 6:41 pm

Re: Retrieve volumes list

Post by ilbarbax »

Thanks for the hint.
I did not think to use dos commands thinking there could be some tricky in some Hollywood command.
However I m using plain Hollywood
plouf
Posts: 666
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Retrieve volumes list

Post by plouf »

but hollywood do NOT have enought internal commands to do it
and its impossible to have commands for eveything.

Some things must be done external,....

in Windows is relative easy to scan as, said, with HaveVolume() every letter (its just 26) in unix you can use DirectoryItems() in /dev
but in Oses like AmigaOS where EVERYTHING can be a volume entry... best is above approach
Christos
User avatar
jPV
Posts: 734
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Retrieve volumes list

Post by jPV »

Here's my (quick) take for Amiga compatibles:

Code: Select all

Function p_GetAssign()
	Local table = {volumes = {}, assigns = {}, devices = {}}
	If Exists("C:Assign")
		Local file$ = "T:AssignList.txt"
		Execute("C:Assign > " .. file$)
		Local vols$, dirs$, devs$ = PatternFindStrShort(FileToString(file$), "Volumes:\n(.*)Directories:\n(.*)Devices:\n(.*)")
		DeleteFile(file$)
		For name$ In PatternFindStr(vols$, "(.-) %[Mounted%]") Do InsertItem(table.volumes, name$)
		For name$ In PatternFindStr(dirs$, "(.-) .-\n") Do InsertItem(table.assigns, name$)
		For name$ In PatternFindStr(devs$, "%g+") Do InsertItem(table.devices, name$)
	EndIf
	Return(table)
EndFunction

t = p_GetAssign()

DebugPrint("--- Volumes ---")
For Local i = 0 To ListItems(t.volumes) - 1
	DebugPrint(t.volumes[i])
Next

DebugPrint("--- Assigns ---")
For Local i = 0 To ListItems(t.assigns) - 1
	DebugPrint(t.assigns[i])
Next

DebugPrint("--- Devices ---")
For Local i = 0 To ListItems(t.devices) - 1
	DebugPrint(t.devices[i])
Next
ilbarbax
Posts: 155
Joined: Thu Apr 01, 2010 6:41 pm

Re: Retrieve volumes list

Post by ilbarbax »

@jpv,

very elegant solution, but assign is catalog sensible, then I have to use assign switches to have something catalog indipendent.
Hope assign has the same syntax in OS4,Aros and Mos
User avatar
jPV
Posts: 734
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Retrieve volumes list

Post by jPV »

Argh, didn't remember Assign output depends on locale on some systems.

And it seems that on OS4 it's quite sloppy.. different catalogs have little bit different formatting :D

For example German looks like this:

Code: Select all

Datenträger:
RAM Disk[Angemeldet]
No space after name!

French:

Code: Select all

Volumes :
RAM Disk [Monté]
Space before ":" !

And then OS 3.2 seems to have extra info at the end... there's "Denied volume requests:" section there.

A quick fix for my script.. not so elegant anymore :P Should tinker the patterns with better time. At least it works now on MorphOS, OS3.1, OS3.2, and OS4 in my tests.

Code: Select all

Function p_GetAssign()
    Local table = {volumes = {}, assigns = {}, devices = {}}
	If Exists("C:Assign")
		Local file$ = "T:AssignList.txt"
		Execute("C:Assign > " .. file$)
		Local list$ = FileToString(file$)
		If Not ValidateStr(list$) Then list$ = ConvertStr(list$, #ENCODING_AMIGA, #ENCODING_UTF8)
		Local vols$, dirs$, devs$ = PatternFindStrShort(list$, "^%g-%s?:\n(.*)\n%g-%s?:\n(.*)\n%g-%s?:\n(.*)")
		DeleteFile(file$)
		For name$ In PatternFindStr(vols$, "(.-)%s?%[.-%]") Do InsertItem(table.volumes, name$)
		For name$ In PatternFindStr(dirs$, "(.-)%s.-\n") Do InsertItem(table.assigns, name$)
		If FindStr(devs$, ":") > -1 Then devs$ = PatternFindStrShort(devs$, "(.-)\n\n") ; For OS 3.2 (Denied volume requests:)
		For name$ In PatternFindStr(devs$, "%g+") Do InsertItem(table.devices, name$)
	EndIf
    Return(table)
EndFunction

t = p_GetAssign()

DebugPrint("--- Volumes ---")
For Local i = 0 To ListItems(t.volumes) - 1
	DebugPrint(t.volumes[i])
Next

DebugPrint("--- Assigns ---")
For Local i = 0 To ListItems(t.assigns) - 1
	DebugPrint(t.assigns[i])
Next

DebugPrint("--- Devices ---")
For Local i = 0 To ListItems(t.devices) - 1
	DebugPrint(t.devices[i])
Next
ilbarbax
Posts: 155
Joined: Thu Apr 01, 2010 6:41 pm

Re: Retrieve volumes list

Post by ilbarbax »

tested on mos and works fine. Just for the records the volume names were causing an assign/mount request because a chr(10) was hodden at the beginning of the vol name.

tanks
User avatar
jPV
Posts: 734
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Retrieve volumes list

Post by jPV »

Oh, right, the first one didn't have it, but the rest did.

Here's fixed version:

Code: Select all

Function p_GetAssign()
    Local table = {volumes = {}, assigns = {}, devices = {}}
	If Exists("C:Assign")
		Local file$ = "T:AssignList.txt"
		Execute("C:Assign > " .. file$)
		Local list$ = FileToString(file$)
		If Not ValidateStr(list$) Then list$ = ConvertStr(list$, #ENCODING_AMIGA, #ENCODING_UTF8)
		Local vols$, dirs$, devs$ = PatternFindStrShort(list$, "^%g-%s?:\n(.*)\n%g-%s?:\n(.*)\n%g-%s?:\n(.*)")
		DeleteFile(file$)
		For name$ In PatternFindStr(vols$, "(.-)%s?%[.-%]\n") Do InsertItem(table.volumes, name$)
		For name$ In PatternFindStr(dirs$, "(.-)%s.-\n") Do InsertItem(table.assigns, name$)
		If FindStr(devs$, ":") > -1 Then devs$ = PatternFindStrShort(devs$, "(.-)\n\n") ; For OS 3.2 (Denied volume requests:)
		For name$ In PatternFindStr(devs$, "%g+") Do InsertItem(table.devices, name$)
	Else
		ConsolePrint("The C:Assign command not found.") 
	EndIf
    Return(table)
EndFunction

t = p_GetAssign()

DebugPrint("--- Volumes ---")
For Local i = 0 To ListItems(t.volumes) - 1
	DebugPrint(t.volumes[i], HaveVolume(t.volumes[i] .. ":"))
Next

DebugPrint("--- Assigns ---")
For Local i = 0 To ListItems(t.assigns) - 1
	DebugPrint(t.assigns[i])
Next

DebugPrint("--- Devices ---")
For Local i = 0 To ListItems(t.devices) - 1
	DebugPrint(t.devices[i])
Next
Post Reply