Include exe and copy the file

Just starting out? Need help? Post your questions and find answers here.
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Include exe and copy the file

Post by GeoTrail »

I'm trying to make a simple update program for a project.
So I need to inlclude an updated exe file in the update program and then be able to copy the file to it's destination.

Code: Select all

CopyFile(?file,"C:\filename.exe")


DataSection 
file:
IncludeBinary "filename.exe" 
fileend: 
EndDataSection
That is what I got so far.
Could someone please help me with this?
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post by GPI »

Try CreateFile(), WriteData(),CloseFile()...
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

Could you please give me an example how those functions could be used with my code?

I tried this but it only makes an empty file:

Code: Select all

Result = CreateFile(0, "filename.exe")
WriteData(*MemoryBuffer, ?File)
CloseFile(0)


DataSection 
File:
IncludeBinary "filename.exe" 
fileend: 
EndDataSection
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

Anyone? Please?

Code: Select all

CreateFile(0, "filename.exe")

WriteData(?File,Length)
CloseFile(0)


DataSection 
File:
IncludeBinary "filename.exe" 
Fileend: 
EndDataSection
The include thing works, I see that the compiled exe gets alittle bigger than the included file. But I can't seem to write the file to disk.

Anyone?
PLEASE??
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

not sure, but you haven't defined length.
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

I know, I don't know how to do that.
I've tried Lof() but it only returns 0 as the file has no content after CreateFile()
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

Code: Select all

a=OpenFile(#PB_ANY, ?File)
Length=Lof()
CloseFile(a)


CreateFile(0, "filename.exe") 

WriteData(?File,Length) 
CloseFile(0) 


DataSection 
File: 
IncludeBinary "filename.exe" 
Fileend: 
EndDataSection
I haven't checked if it works, but it's supposed to :wink:
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post by GPI »

Try:

Code: Select all

CreateFile(0, "filename.exe")

WriteData(?File,?fileend-?file)
CloseFile(0)


DataSection 
File:
IncludeBinary "filename.exe" 
Fileend: 
EndDataSection
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

Polo wrote:

Code: Select all

a=OpenFile(#PB_ANY, ?File)
Length=Lof()
CloseFile(a)


CreateFile(0, "filename.exe") 

WriteData(?File,Length) 
CloseFile(0) 


DataSection 
File: 
IncludeBinary "filename.exe" 
Fileend: 
EndDataSection
I haven't checked if it works, but it's supposed to :wink:
I get this errormessage when trying to compile:
Bad parameter type: a string is extected.
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

GPI wrote:Try:

Code: Select all

CreateFile(0, "filename.exe")

WriteData(?File,?fileend-?file)
CloseFile(0)


DataSection 
File:
IncludeBinary "filename.exe" 
Fileend: 
EndDataSection
That worked great :) Thanks.
Only thing is, it generates a Windows error while running the program.
The filename.exe file works great.
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
eriksradio
User
User
Posts: 30
Joined: Tue Sep 09, 2003 11:44 pm
Location: Queensland, Australia

Post by eriksradio »

This works for me if it is any help


If CreateFile(1, "filename.exe")
UseFile(1)
L1 = ?ExitProc - ?Inc
WriteData(?Inc, L1)
CloseFile(1)
Goto BeginProgram1
Inc :
IncludeBinary "filename.exe"
exitProc:
EndIf

BeginProgram1:
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

Thanks eriksradio.
That worked great. No error :)

Any idea why

Code: Select all

CreateFile(0, "filename.exe") 

WriteData(?File,?fileend-?file) 
CloseFile(0) 


DataSection 
File: 
IncludeBinary "filename.exe" 
Fileend: 
EndDataSection
causes an error? I've tried it on both Win2000 and WinXP, both reports an error.
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
eriksradio
User
User
Posts: 30
Joined: Tue Sep 09, 2003 11:44 pm
Location: Queensland, Australia

Post by eriksradio »

Sorry Geo, I don't really know.

I got this example from the PURE AREA site.
I downloaded the complete Code Archive
There is a wealth of info and examples there, a must have
for newbies like me.

I program mostly in VB.
When I can't do it in VB, I can usually do it and more in PB

Have fun
filperj
User
User
Posts: 77
Joined: Tue Sep 16, 2003 8:53 pm
Location: Nevers(France)

Post by filperj »

No error for me, with xp home and PB 3.90. :roll:
Wich PB version do you use?
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

I use v3.91 beta and jaPBe for 3.91b
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
Post Reply