Share My Creation Network File Manager

Hi all i have been playing with the SMB library and have managed to get it to connect and list my network drive contents (eventually i want it to be a media type device).

do listviews have a maximum number of entries, as some of my directories have 1000 documents, or is it because i am loading a picture into the listview and thus this uses more memory as i keep getting out of memory in the debug window when there are 70+ files or directories. below this it seems to work ok as you can see from the screen shot.

I have uploaded the code so anyone with a networked drive and have a look and any advice would be appreciated.

If i don't use a listview to hold the files/directories what would be a good replacement

Thanks

Stu
 

Attachments

  • screen.png
    screen.png
    71.8 KB · Views: 5,098
  • Explorer.zip
    58.9 KB · Views: 1,095
Last edited:

Stulish

Active Member
Licensed User
Longtime User
i have now added the source zip (i must have missed it on the first post)
 

Stulish

Active Member
Licensed User
Longtime User
I have a couple of questions/thoughts

does anyone has a better way of iterating through what files are on the device and then adding them to the listbox it would be nice to see how you do it, as looping through each items seems to take a while (but it could just be because its on a network drive not native SD card)

i also think the out of memory is due to loading the listview with so many pictures, is there a way to reference the bitmap to one instance of the picture so it isn't creating a new instance for each listview item (so if there are 10 files that have the extension .txt then the txt picture is loaded once and the imageviews then refer too this, just thinking it might save memory.


Thanks
 

Stulish

Active Member
Licensed User
Longtime User
It is definatly the picture files causing out of memory, i changed the sub SMB1_ListCompleted to the code below without bitmaps and a directory with over 1000 entries displayed really quickly and all of the entries.

B4X:
Sub SMB1_ListCompleted(Url As String, Success As Boolean, Entries() As SMBFile)
Dim bmp As Bitmap,fileEx As String, x As Int, title As String 
    If Not(Success) Then 
        Log(LastException)
    Else
      Files.Clear ' clear listview of old files
        For i = 0 To Entries.Length - 1         'loop through entries
         If Entries(i).Directory = True Then             'if the entry is a directory
            title = Entries(i).Name.SubString2(0, Entries(i).Name.Length-1) ' get the name of the directory minus the last "/"
         Else                                    'if the entry is a file
            x=Entries(i).name.Length-1
            Do While Entries(i).name.charat(x)<>"." AND x>0 
               x=x-1                               'x decrements to find the first full stop to the end of the filename
            Loop
            title = Entries(i).name.SubString2(0,x)         'get the name of the file minus the file extension
         End If   
         Files.AddSingleLine2(title,Url & Entries(i).name) 
        Next
    End If
End Sub

any ideas??
 

Stulish

Active Member
Licensed User
Longtime User
i think i have sorted the problem, i am now using a map with the key as the file extension and the value as the image.

not to put it into neater code
 

Stulish

Active Member
Licensed User
Longtime User
Finally got it working and not running out of memory, also loads a hell of a lot quicker, the code below can be pasted over the original:

B4X:
Sub Process_Globals
    Dim SMB1 As SMB
   Dim lstDir As String 
   Dim route As Map 
   Dim r As Int 
   Dim images As Map 
   Dim picfiles As MLfiles 
   Dim m As List 
End Sub
Sub Globals
   Dim Files As ListView
   Dim BackButton As ImageView
   Dim iTent As Intent 
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim fType As String 
    If FirstTime Then
        SMB1.Initialize("SMB1")
      Activity.LoadLayout("main")
      route.Initialize
       lstDir = "smb://networkdrive/" ' my network drive
      r = 0
      route.Put(r,lstDir)    
      images.Initialize 
      m = File.ListFiles(File.DirAssets)
      For a=0 To m.Size-1
         fType = m.Get(a)
         If fType.SubString(fType.Length-3) ="png" Then
            fType = fType.SubString2(0,fType.Length-4)
            images.Put(fType,LoadBitmap(File.DirAssets,m.get(a)))
         End If
      Next

   End If
   SMB1.ListFiles(lstDir,"")
End Sub
Sub SMB1_ListCompleted(Url As String, Success As Boolean, Entries() As SMBFile)
Dim bmp As Bitmap,fileEx As String, x As Int, title As String, bFile As String 
    If Not(Success) Then 
        Log(LastException)
    Else
      Files.Clear ' clear listview of old files
        For i = 0 To Entries.Length - 1         'loop through entries
         If Entries(i).Directory = True Then    
         'if the entry is a directory
            bFile = "dir"
            'bmp = LoadBitmap(File.DirAssets,"dir.png")      'put the directory PNG into the bitmap holder
            title = Entries(i).Name.SubString2(0, Entries(i).Name.Length-1) ' get the name of the directory minus the last "/"
         Else   'if the entry is a file
            bFile=""
            x=Entries(i).name.Length-1
            Do While Entries(i).name.charat(x)<>"." AND x>0 
               x=x-1                               'x decrements to find the first full stop to the end of the filename
            Loop
            fileEx = Entries(i).name.SubString(x+1)         'get the file extension
            title = Entries(i).name.SubString2(0,x)   
            bFile = fileEx
         End If   
      bmp = images.Getdefault(bFile,images.Get("default"))
      Files.AddTwoLinesAndBitmap2(title,"",bmp,Url & Entries(i).name)   ' add the name of the file/directoy and the bitmap along with its network filename/url
        Next
    End If
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Files_ItemClick (Position As Int, Value As String)
If Value.charat(Value.Length-1)="/" Then 
   lstDir = Value 
   r = r + 1
   route.Put(r, lstDir)
      SMB1.ListFiles(lstDir,"")
End If
End Sub
Sub BackButton_Click
   If r>0 Then 
      SMB1.ListFiles(route.Get(r-1),"")
      lstDir = route.Get(r-1)
      route.Remove(r)
      r=r-1
   End If
End Sub

again if anyone has comments or thoughts please let me know, i will continue with the project now :)
 
Top