big File Copy respond

Post

Posted
Rating:
#1 (In Topic #1803)
Avatar
Enthusiast
Yogi is in the usergroup ‘Enthusiast’

system recognises App as possibly crashed

Hi again,

Using an online TV Recorder I download some GB of video files per week.
After downloading the commercials are cut out and then the Gambas app
shows in a listbox the available files for sorting them in folders.

The app works as expected but the system (Ubuntu 24.04.3 LTS) is
somehow moaning if it lasts longer to copy a file it shows a message like
"App does not respond, wait or close app"

if I choose to wait and the copying is finished, all well.

Ok, I think it is not a Gambas problem (?) to report back to the system.
This waiting or closing message is somehow annoying.

So using the copy command with big files

Code (gambas)

Try Copy cSource To cTar
is the problem.

Any chance to get rid of this message?

I thought to make a copy sub with

Code (gambas)

src = Open sFile For Input target = Open sTarget For Write Create
and a window with progressbar etc.
That should do the trick also.

Btw. the read takes the bytes to get,

Code (gambas)

Read #src, sLine, -iBlock
is there a ideal value for the bytes to read in?
Or using a value depending on the filesize to be copied?

Thanks &
Regards,
Yogi
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Enthusiast
Yogi is in the usergroup ‘Enthusiast’
Just played around with the idea and here is the result:

Code (gambas)

  1. ' Gambas class file
  2.  
  3.  
  4. Private hCancel As Button
  5. Private bIscanceled As Boolean = False
  6.  
  7. '' Init
  8. Public Sub _new()
  9. hwin = New Window
  10. hwin.Width = 700
  11. hwin.Height = 300
  12. hwin.Border = False
  13. hwin.TopOnly = True
  14. p = New ProgressBar(hwin)
  15. p.Width = hwin.Width - 20
  16. p.Height = 20
  17. p.Top = 10
  18. p.Left = 10
  19. '' Arguments Source and Target
  20. Public Function Filecopy(sSource As String, sTarget As String) As Boolean
  21. Dim lReturn As Boolean = False
  22. Dim progress, fsize As Float
  23. Dim hSrc, hTar As Stream
  24. Dim iBlock, iAsize As Integer
  25. Dim sBytes As String
  26. sLabel = New TextLabel(hwin)
  27. sLabel.Width = hwin.Width - 20
  28. sLabel.Height = 150
  29. sLabel.Wrap = True
  30. sLabel.Top = p.Top + p.Height + 20
  31. sLabel.Left = 10
  32. sLabel.Text = "<b>Source:</b><br>" & sSource & "<br><br>" & "<b>Target:</b><br>" & sTarget
  33. sLabel.Border = Border.Solid
  34.  
  35. hCancel = New Button(hwin) As "hCancel"
  36. hCancel.Text = "Cancel"
  37. hCancel.Top = sLabel.Top + p.Top + p.Height + 20 + 150
  38. hCancel.Left = 10
  39. hCancel.Cancel = True
  40. hCancel.Width = hWin.Font.TextWidth(hCancel.Text) + 20
  41. hCancel.Height = hwin.Font.Height + 20
  42. hwin.Show
  43.  
  44. 'necessary?
  45. fsize = Stat(sSource).Size
  46. If fsize < 100000 Then
  47.   iBlock = 10000
  48. Else If fsize < 1000000
  49.   iBlock = 100000
  50.   iBlock = 500000
  51.  
  52. hSrc = Open sSource For Input
  53. hTar = Open sTarget For Write Create
  54. p.Value = 0
  55. iAsize = 0
  56. While Not Eof(hSrc)
  57.       Read #hSrc, sBytes, -iBlock '1024
  58.       iAsize += iBlock
  59.       progress = 100 / fsize * iAsize / 100
  60.       If bIscanceled Then
  61.         Break
  62.       Endif
  63.       p.Value = progress
  64.       Write #hTar, sBytes
  65.       Wait 0
  66. hSrc.Close
  67. hTar.Close
  68. Try hwin.Close
  69. If bIscanceled Then
  70.   Try Kill sTarget
  71.   lReturn = False
  72.   lReturn = True
  73. Return lReturn
  74. Public Sub hCancel_Click()
  75.  
  76.   If Message.Question("Abort copy?", "yes", "no") = 1 Then
  77.     bIscanceled = True
  78.  
  79.  

and with that copy class there is no system message "Wait or abort" or something similar.
Neither validation nor beauty of the GUI is made.

Suggestions for improvement are welcome.

Regards
Yogi
Online now: No Back to the top

Post

Posted
Rating:
Item has a rating of 5 (Liked by Yogi)
#3
Guru
BruceSteers is in the usergroup ‘Guru’
Cool, you got the idea.

Tip: A ProgressBar.Value float Is more simply done by dividing the other way round, ie, the bytes copied divided by the total number bytes…

Ie.

      progress = iAsize / fSize

Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Enthusiast
Yogi is in the usergroup ‘Enthusiast’

BruceSteers said

Cool, you got the idea.

Tip: A ProgressBar.Value float Is more simply done by dividing the other way round, ie, the bytes copied divided by the total number bytes…

Ie.

      progress = iAsize / fSize



Yes, mathematics and I šŸ™ˆ
Thanks!
Online now: No Back to the top

Post

Posted
Rating:
Item has a rating of 5 (Liked by gbWilly)
#5
Guru
BruceSteers is in the usergroup ‘Guru’

Yogi said


Yes, mathematics and I šŸ™ˆ
Thanks!

No worries.

Believe me I used to do exactly the same kind of thing :D

Your understanding of this Copy problem seems to be top notch and you pretty much answered your own questions in your first post.

So just to confirm, yes using the gambas Copy command on large files is not a great idea as your program code will be locked while it's operating that single command.
The answer as you correctly concluded was to break the command into multiple read/write pieces that allows the code to continue to run, lets the event loop cycle (using Wait) and let you do things like show progress/catch cancellations/etc.

Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Enthusiast
Yogi is in the usergroup ‘Enthusiast’

BruceSteers said


Your understanding of this Copy problem seems to be top notch and you pretty much answered your own questions in your first post.

So just to confirm, yes using the gambas Copy command on large files is not a great idea as your program code will be locked while it's operating that single command.
The answer as you correctly concluded was to break the command into multiple read/write pieces that allows the code to continue to run, lets the event loop cycle (using Wait) and let you do things like show progress/catch cancellations/etc.



From the beginning in 1980s I was enthusiastic to programming (VC20?, C64) till working with Clipper (dBase Compiler).
But from this time there is a little understanding for programming, but saw also that I never will do some Assembler, C,
C++, C#, Pascal etc. Using a high level language where you never get problems with memory, storage, pointers etc and
get some apps running in short time that is the point for me.
To get some things running which make day life easier is the thing today. Nice to find Gambas.

So the biggest problem is my brain forgetting things in short time - even after a view days not looking to the
source code I ask myself: what the heck have I done here? šŸ˜‚

So good decision at the end of the 1990s to quit the profession programming (no education, just learning by doing).

Thanks and kind regards,
Yogi
Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Administrator
gbWilly is in the usergroup ‘unknown’

BruceSteers said

Your understanding of this Copy problem seems to be top notch and you pretty much answered your own questions in your first post.
I have to 100% agree with Bruce.

I read your first post thinking, you already solved the problem in you head and the second post confirmed your thought pattern send you right where you needed be.
So, I saw absolute no need to react and had a smile on my face as it reminded me of my first period on the long gone gambas guru forum back in the Gambas 2 days.

So, keep on doing you, it's perfect for learning anything  :thumbs:
I enjoy reading it  ;)

gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories


… there is always a Catch if things go wrong!
Online now: No Back to the top

Post

Posted
Rating:
#8
Avatar
Enthusiast
Yogi is in the usergroup ‘Enthusiast’

gbWilly said

BruceSteers said

Your understanding of this Copy problem seems to be top notch and you pretty much answered your own questions in your first post.
I have to 100% agree with Bruce.

I read your first post thinking, you already solved the problem in you head and the second post confirmed your thought pattern send you right where you needed be.
So, I saw absolute no need to react and had a smile on my face as it reminded me of my first period on the long gone gambas guru forum back in the Gambas 2 days.

So, keep on doing you, it's perfect for learning anything  :thumbs:
I enjoy reading it  ;)


Thanks for your kind words.
And yes, we should enjoy more. That's what I've learned through Yoga…

Kind regards,
Yogi
Online now: No Back to the top
1 guest and 0 members have just viewed this.