"Save as" dialog box

Just starting out? Need help? Post your questions and find answers here.
jak64
Enthusiast
Enthusiast
Posts: 625
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

"Save as" dialog box

Post by jak64 »

Hello all,
In a Purebasic program, upon clicking a button, I want the "Save As" dialog box to appear in order to choose where I want to save a file.
I couldn't find a matching gadget!

Thank you for your help
Axolotl
Addict
Addict
Posts: 841
Joined: Wed Dec 31, 2008 3:36 pm

Re: "Save as" dialog box

Post by Axolotl »

what about SaveFileRequester()

Code: Select all

  StandardFile$ = "C:\autoexec.bat"   ; set initial file+path to display
  ; With next string we will set the search patterns ("|" as separator) for file displaying:
  ;  1st: "Text (*.txt)" as name, ".txt" and ".bat" as allowed extension
  ;  2nd: "PureBasic (*.pb)" as name, ".pb" as allowed extension
  ;  3rd: "All files (*.*) as name, "*.*" as allowed extension, valid for all files
  Pattern$ = "Text (*.txt)|*.txt;*.bat|PureBasic (*.pb)|*.pb|All files (*.*)|*.*"
  Pattern = 0    ; use the first of the three possible patterns as standard
  File$ = SaveFileRequester("Please choose file to save", StandardFile$, Pattern$, Pattern)
  If File$
    MessageRequester("Information", "You have selected following file:"+Chr(10)+File$, 0)
  Else
    MessageRequester("Information", "The requester was canceled.", 0) 
  EndIf

Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
jak64
Enthusiast
Enthusiast
Posts: 625
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: "Save as" dialog box

Post by jak64 »

Hello Axolotl,
Actually, I expressed myself badly:
I have a lot of videos on an external drive. I wrote a program that allows you to display them, search them, read them, etc., and I want, when I select one in a ListIconGadget, to be able to copy it to a USB stick or other external disk, etc...
Quin
Addict
Addict
Posts: 1134
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: "Save as" dialog box

Post by Quin »

Use PathRequester() and CopyFile().
jak64
Enthusiast
Enthusiast
Posts: 625
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: "Save as" dialog box

Post by jak64 »

Hello Quin,

I applied what you wrote and it's exactly what I wanted.

Thank you all for your help
jak64
Enthusiast
Enthusiast
Posts: 625
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: "Save as" dialog box

Post by jak64 »

Hello everyone,
I applied the instructions given by Quin in my program and it works as I want.

But, for copying a video it can take a while (especially if it's on a USB stick), I would like to show a copy progress bar. However, I don't know how to know how long the copy will take!
To do this, I need to know the size of the video but also the data transfer rate when copying!

Do you know if this is possible?

Thank you for your help
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 460
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: "Save as" dialog box

Post by Mindphazer »

You can check this thread : viewtopic.php?t=74835
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
User avatar
Janni
Enthusiast
Enthusiast
Posts: 127
Joined: Mon Feb 21, 2022 5:58 pm
Location: Norway

Re: "Save as" dialog box

Post by Janni »

The precision level on most progress bars is about as accurate as a weather forecast from a fortune cookie.

If task cannot be done in the background, one advice is to have simple animated spinner just showing "please wait"

Image
Spec: Linux Mint 20.3 Cinnamon, i7-3770K, 16GB RAM, RTX 2070 Super
Quin
Addict
Addict
Posts: 1134
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: "Save as" dialog box

Post by Quin »

Yeah, honestly don't worry about accuracy too much, as long as the users know something is happening. A really simple solution would just be to divide the file size by 100, and use that to tell when to increase your progress bar.
jak64
Enthusiast
Enthusiast
Posts: 625
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: "Save as" dialog box

Post by jak64 »

Thank you all, I will test the different codes that I found with the link that Mindphazer gave me

See you
jak64
Enthusiast
Enthusiast
Posts: 625
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: "Save as" dialog box

Post by jak64 »

Hello everyone,
I adapted the netmaestro code that I found with the link Mindphazer gave me and integrated it into my program. It works really well:
I'll try to write a little example code and post it on the forum.

Now I have another question:

When I copy videos to a USB stick (with the netmaestro code), when the stick does not have enough space, the code only copies part of the video, which is not correct and does not 'indicates no error!

Question: can we, with Purebasic or an API, know the available space on a USB key (or an external disk)?

Thank you for your help
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: "Save as" dialog box

Post by Marc56us »

jak64 wrote: Sun Oct 01, 2023 1:21 pm Question: can we, with Purebasic or an API, know the available space on a USB key (or an external disk)?
From RSBasic API list (Strings translated)

Code: Select all

EnableExplicit
Define lpFreeBytesAvailable.q
Define lpTotalNumberOfBytes.q
Define lpTotalNumberOfFreeBytes.q
GetDiskFreeSpaceEx_("C:\", @lpFreeBytesAvailable, @lpTotalNumberOfBytes, @lpTotalNumberOfFreeBytes)
Debug "Free space  : " + Str(lpFreeBytesAvailable/1024/1024/1024) + " GB"
Debug "Space used  : " + Str((lpTotalNumberOfBytes-lpFreeBytesAvailable)/1024/1024/1024) + " GB"
Debug "Total space : " + Str(lpTotalNumberOfBytes/1024/1024/1024) + " GB"
:wink:
User avatar
blueb
Addict
Addict
Posts: 1116
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: "Save as" dialog box

Post by blueb »

Question: can we, with Purebasic or an API, know the available space on a USB key (or an external disk)?

This is very old, but maybe this will help...

Code: Select all

Procedure.s GetDiskSpace(DriveLetter.s)
; ------------ Get Disk Space by Timo Harter (Freak) -------
; 
; Works even with high values (up to 2097152 GB) 
; Returns values in MegaByte
;
; Useage: GetDiskSpace("c:\")
; ----------------------------------------------------------

drive.s = DriveLetter

Structure Quad2
  L1.l  
  L2.l
EndStructure 

GetDiskFreeSpaceEx_(@drive, FB.Quad2, TB.Quad2, TFB.Quad2)

TB.Quad2\L1>>20
TB.Quad2\L2<<12
TotalMB.l = TB.Quad2\L1 + TB.Quad2\L2

TFB.Quad2\L1>>20
TFB.Quad2\L2<<12
FreeMB.l = TFB.Quad2\L1 + TFB.Quad2\L2

UsedMB.l = TotalMB - FreeMB


MessageRequester("Disk Size","Space Total: "+Str(TotalMB)+" MB"+Chr(13)+"Space Free: "+Str(FreeMB)+" MB"+Chr(13)+"Space Used: "+Str(UsedMB)+" MB",0)
;End
EndProcedure
;===================================================================
DriveLetter.s = "c:\"
Debug GetDiskSpace(DriveLetter.s)
- It was too lonely at the top.

System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
jak64
Enthusiast
Enthusiast
Posts: 625
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: "Save as" dialog box

Post by jak64 »

Thank you Marc56us and blueb for your help.
I used Marc56us' code and it works great.
See you
Post Reply